2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* CCreatureSet.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2010-04-02 05:23:22 +03:00
|
|
|
#include "CCreatureSet.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2023-01-14 16:55:08 +02:00
|
|
|
#include "CConfigHandler.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "CCreatureHandler.h"
|
2010-04-02 05:23:22 +03:00
|
|
|
#include "VCMI_Lib.h"
|
2012-08-24 12:37:52 +03:00
|
|
|
#include "CModHandler.h"
|
2023-03-15 21:34:29 +02:00
|
|
|
#include "GameSettings.h"
|
2014-06-05 19:52:14 +03:00
|
|
|
#include "mapObjects/CGHeroInstance.h"
|
2010-05-02 21:20:26 +03:00
|
|
|
#include "IGameCallback.h"
|
|
|
|
#include "CGameState.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "CGeneralTextHandler.h"
|
2015-02-02 10:25:26 +02:00
|
|
|
#include "spells/CSpellHandler.h"
|
2012-05-07 15:54:22 +03:00
|
|
|
#include "CHeroHandler.h"
|
2013-03-06 21:49:56 +03:00
|
|
|
#include "IBonusTypeHandler.h"
|
2016-02-22 01:37:19 +02:00
|
|
|
#include "serializer/JsonSerializeFormat.h"
|
2016-11-13 12:38:42 +02:00
|
|
|
#include "NetPacksBase.h"
|
2010-04-02 05:23:22 +03:00
|
|
|
|
2023-04-05 17:56:28 +02:00
|
|
|
#include <vcmi/FactionService.h>
|
|
|
|
#include <vcmi/Faction.h>
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2021-11-28 14:57:38 +02:00
|
|
|
|
|
|
|
bool CreatureSlotComparer::operator()(const TPairCreatureSlot & lhs, const TPairCreatureSlot & rhs)
|
|
|
|
{
|
|
|
|
return lhs.first->getAIValue() < rhs.first->getAIValue(); // Descendant order sorting
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
const CStackInstance & CCreatureSet::operator[](const SlotID & slot) const
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
auto i = stacks.find(slot);
|
2011-01-21 04:36:30 +02:00
|
|
|
if (i != stacks.end())
|
2010-11-22 02:34:46 +02:00
|
|
|
return *i->second;
|
2010-04-02 05:23:22 +03:00
|
|
|
else
|
2012-04-22 10:32:45 +03:00
|
|
|
throw std::runtime_error("That slot is empty!");
|
2010-04-02 05:23:22 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
const CCreature * CCreatureSet::getCreature(const SlotID & slot) const
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
auto i = stacks.find(slot);
|
2011-01-21 04:36:30 +02:00
|
|
|
if (i != stacks.end())
|
2010-11-22 02:34:46 +02:00
|
|
|
return i->second->type;
|
2010-04-02 05:23:22 +03:00
|
|
|
else
|
2013-06-26 14:18:27 +03:00
|
|
|
return nullptr;
|
2010-04-02 05:23:22 +03:00
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
bool CCreatureSet::setCreature(SlotID slot, CreatureID type, TQuantity quantity) /*slots 0 to 6 */
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2013-02-16 17:03:47 +03:00
|
|
|
if(!slot.validSlot())
|
2010-11-22 02:34:46 +02:00
|
|
|
{
|
2017-08-11 19:03:05 +02:00
|
|
|
logGlobal->error("Cannot set slot %d", slot.getNum());
|
2010-04-02 05:23:22 +03:00
|
|
|
return false;
|
2010-11-22 02:34:46 +02:00
|
|
|
}
|
|
|
|
if(!quantity)
|
|
|
|
{
|
2017-08-10 18:39:27 +02:00
|
|
|
logGlobal->warn("Using set creature to delete stack?");
|
2010-11-22 02:34:46 +02:00
|
|
|
eraseStack(slot);
|
2010-11-27 03:46:19 +02:00
|
|
|
return true;
|
2010-11-22 02:34:46 +02:00
|
|
|
}
|
|
|
|
|
2011-02-04 16:58:14 +02:00
|
|
|
if(hasStackAtSlot(slot)) //remove old creature
|
2010-11-22 02:34:46 +02:00
|
|
|
eraseStack(slot);
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
auto * armyObj = castToArmyObj();
|
2021-03-01 21:38:50 +02:00
|
|
|
bool isHypotheticArmy = armyObj ? armyObj->isHypothetic() : false;
|
|
|
|
|
|
|
|
putStack(slot, new CStackInstance(type, quantity, isHypotheticArmy));
|
2010-11-27 03:46:19 +02:00
|
|
|
return true;
|
2010-04-02 05:23:22 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
SlotID CCreatureSet::getSlotFor(const CreatureID & creature, ui32 slotsAmount) const /*returns -1 if no slot available */
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
return getSlotFor(VLC->creh->objects[creature], slotsAmount);
|
2010-11-27 22:17:28 +02:00
|
|
|
}
|
|
|
|
|
2017-07-15 13:08:20 +02:00
|
|
|
SlotID CCreatureSet::getSlotFor(const CCreature *c, ui32 slotsAmount) const
|
2010-11-27 22:17:28 +02:00
|
|
|
{
|
2021-11-28 14:57:38 +02:00
|
|
|
assert(c && c->valid());
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & elem : stacks)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
assert(elem.second->type->valid());
|
|
|
|
if(elem.second->type == c)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
return elem.first; //if there is already such creature we return its slot id
|
2010-04-02 05:23:22 +03:00
|
|
|
}
|
|
|
|
}
|
2013-02-16 17:03:47 +03:00
|
|
|
return getFreeSlot(slotsAmount);
|
2010-04-02 05:23:22 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
bool CCreatureSet::hasCreatureSlots(const CCreature * c, const SlotID & exclude) const
|
2021-11-28 14:57:38 +02:00
|
|
|
{
|
|
|
|
assert(c && c->valid());
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & elem : stacks) // elem is const
|
2021-11-28 14:57:38 +02:00
|
|
|
{
|
|
|
|
if(elem.first == exclude) // Check slot
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(!elem.second || !elem.second->type) // Check creature
|
|
|
|
continue;
|
|
|
|
|
|
|
|
assert(elem.second->type->valid());
|
|
|
|
|
|
|
|
if(elem.second->type == c)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
std::vector<SlotID> CCreatureSet::getCreatureSlots(const CCreature * c, const SlotID & exclude, TQuantity ignoreAmount) const
|
2021-11-28 14:57:38 +02:00
|
|
|
{
|
|
|
|
assert(c && c->valid());
|
|
|
|
std::vector<SlotID> result;
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & elem : stacks)
|
2021-11-28 14:57:38 +02:00
|
|
|
{
|
|
|
|
if(elem.first == exclude)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(!elem.second || !elem.second->type || elem.second->type != c)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(elem.second->count == ignoreAmount || elem.second->count < 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
assert(elem.second->type->valid());
|
|
|
|
result.push_back(elem.first);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCreatureSet::isCreatureBalanced(const CCreature * c, TQuantity ignoreAmount) const
|
|
|
|
{
|
|
|
|
assert(c && c->valid());
|
|
|
|
TQuantity max = 0;
|
|
|
|
TQuantity min = std::numeric_limits<TQuantity>::max();
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & elem : stacks)
|
2021-11-28 14:57:38 +02:00
|
|
|
{
|
|
|
|
if(!elem.second || !elem.second->type || elem.second->type != c)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const auto count = elem.second->count;
|
|
|
|
|
|
|
|
if(count == ignoreAmount || count < 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
assert(elem.second->type->valid());
|
|
|
|
|
|
|
|
if(count > max)
|
|
|
|
max = count;
|
|
|
|
if(count < min)
|
|
|
|
min = count;
|
|
|
|
if(max - min > 1)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-15 13:08:20 +02:00
|
|
|
SlotID CCreatureSet::getFreeSlot(ui32 slotsAmount) const
|
2011-04-10 11:33:53 +03:00
|
|
|
{
|
2013-02-16 17:03:47 +03:00
|
|
|
for(ui32 i=0; i<slotsAmount; i++)
|
2011-04-10 11:33:53 +03:00
|
|
|
{
|
2013-02-16 17:03:47 +03:00
|
|
|
if(!vstd::contains(stacks, SlotID(i)))
|
2011-04-10 11:33:53 +03:00
|
|
|
{
|
2013-02-16 17:03:47 +03:00
|
|
|
return SlotID(i); //return first free slot
|
2011-04-10 11:33:53 +03:00
|
|
|
}
|
|
|
|
}
|
2013-02-16 17:03:47 +03:00
|
|
|
return SlotID(); //no slot available
|
2011-04-10 11:33:53 +03:00
|
|
|
}
|
|
|
|
|
2021-11-28 14:57:38 +02:00
|
|
|
std::vector<SlotID> CCreatureSet::getFreeSlots(ui32 slotsAmount) const
|
|
|
|
{
|
|
|
|
std::vector<SlotID> freeSlots;
|
|
|
|
|
|
|
|
for(ui32 i = 0; i < slotsAmount; i++)
|
|
|
|
{
|
|
|
|
auto slot = SlotID(i);
|
|
|
|
|
|
|
|
if(!vstd::contains(stacks, slot))
|
|
|
|
freeSlots.push_back(slot);
|
|
|
|
}
|
|
|
|
return freeSlots;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::queue<SlotID> CCreatureSet::getFreeSlotsQueue(ui32 slotsAmount) const
|
|
|
|
{
|
|
|
|
std::queue<SlotID> freeSlots;
|
|
|
|
|
|
|
|
for (ui32 i = 0; i < slotsAmount; i++)
|
|
|
|
{
|
|
|
|
auto slot = SlotID(i);
|
|
|
|
|
|
|
|
if(!vstd::contains(stacks, slot))
|
|
|
|
freeSlots.push(slot);
|
|
|
|
}
|
|
|
|
return freeSlots;
|
|
|
|
}
|
|
|
|
|
|
|
|
TMapCreatureSlot CCreatureSet::getCreatureMap() const
|
|
|
|
{
|
|
|
|
TMapCreatureSlot creatureMap;
|
|
|
|
TMapCreatureSlot::key_compare keyComp = creatureMap.key_comp();
|
|
|
|
|
|
|
|
// https://stackoverflow.com/questions/97050/stdmap-insert-or-stdmap-find
|
|
|
|
// https://www.cplusplus.com/reference/map/map/key_comp/
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & pair : stacks)
|
2021-11-28 14:57:38 +02:00
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
const auto * creature = pair.second->type;
|
2021-11-28 14:57:38 +02:00
|
|
|
auto slot = pair.first;
|
2023-03-13 23:26:44 +02:00
|
|
|
auto lb = creatureMap.lower_bound(creature);
|
2021-11-28 14:57:38 +02:00
|
|
|
|
|
|
|
if(lb != creatureMap.end() && !(keyComp(creature, lb->first)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
creatureMap.insert(lb, TMapCreatureSlot::value_type(creature, slot));
|
|
|
|
}
|
|
|
|
return creatureMap;
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
TCreatureQueue CCreatureSet::getCreatureQueue(const SlotID & exclude) const
|
2021-11-28 14:57:38 +02:00
|
|
|
{
|
|
|
|
TCreatureQueue creatureQueue;
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & pair : stacks)
|
2021-11-28 14:57:38 +02:00
|
|
|
{
|
|
|
|
if(pair.first == exclude)
|
|
|
|
continue;
|
|
|
|
creatureQueue.push(std::make_pair(pair.second->type, pair.first));
|
|
|
|
}
|
|
|
|
return creatureQueue;
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
TQuantity CCreatureSet::getStackCount(const SlotID & slot) const
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
auto i = stacks.find(slot);
|
2011-01-21 04:36:30 +02:00
|
|
|
if (i != stacks.end())
|
2010-11-22 02:34:46 +02:00
|
|
|
return i->second->count;
|
2010-04-02 05:23:22 +03:00
|
|
|
else
|
|
|
|
return 0; //TODO? consider issuing a warning
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
TExpType CCreatureSet::getStackExperience(const SlotID & slot) const
|
2011-03-27 12:31:14 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
auto i = stacks.find(slot);
|
2011-03-27 12:31:14 +03:00
|
|
|
if (i != stacks.end())
|
|
|
|
return i->second->experience;
|
|
|
|
else
|
|
|
|
return 0; //TODO? consider issuing a warning
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
bool CCreatureSet::mergableStacks(std::pair<SlotID, SlotID> & out, const SlotID & preferable) const /*looks for two same stacks, returns slot positions */
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
|
|
|
//try to match creature to our preferred stack
|
2013-02-16 17:03:47 +03:00
|
|
|
if(preferable.validSlot() && vstd::contains(stacks, preferable))
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2011-01-21 04:36:30 +02:00
|
|
|
const CCreature *cr = stacks.find(preferable)->second->type;
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & elem : stacks)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
if(cr == elem.second->type && elem.first != preferable)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
|
|
|
out.first = preferable;
|
2013-06-29 16:05:48 +03:00
|
|
|
out.second = elem.first;
|
2010-04-02 05:23:22 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & stack : stacks)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & elem : stacks)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
if(stack.second->type == elem.second->type && stack.first != elem.first)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
out.first = stack.first;
|
2013-06-29 16:05:48 +03:00
|
|
|
out.second = elem.first;
|
2010-04-02 05:23:22 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureSet::sweep()
|
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto i=stacks.begin(); i!=stacks.end(); ++i)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2010-11-22 02:34:46 +02:00
|
|
|
if(!i->second->count)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2011-01-21 04:36:30 +02:00
|
|
|
stacks.erase(i);
|
2010-04-02 05:23:22 +03:00
|
|
|
sweep();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
void CCreatureSet::addToSlot(const SlotID & slot, const CreatureID & cre, TQuantity count, bool allowMerging)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
const CCreature *c = VLC->creh->objects[cre];
|
2010-05-02 21:20:26 +03:00
|
|
|
|
2011-02-04 16:58:14 +02:00
|
|
|
if(!hasStackAtSlot(slot))
|
2010-11-22 02:34:46 +02:00
|
|
|
{
|
|
|
|
setCreature(slot, cre, count);
|
|
|
|
}
|
2010-11-27 03:46:19 +02:00
|
|
|
else if(getCreature(slot) == c && allowMerging) //that slot was empty or contained same type creature
|
2010-11-22 02:34:46 +02:00
|
|
|
{
|
2010-11-27 03:46:19 +02:00
|
|
|
setStackCount(slot, getStackCount(slot) + count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-10 18:39:27 +02:00
|
|
|
logGlobal->error("Failed adding to slot!");
|
2010-11-22 02:34:46 +02:00
|
|
|
}
|
2010-04-02 05:23:22 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
void CCreatureSet::addToSlot(const SlotID & slot, CStackInstance * stack, bool allowMerging)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2010-11-27 03:46:19 +02:00
|
|
|
assert(stack->valid(true));
|
2010-11-22 02:34:46 +02:00
|
|
|
|
2011-02-04 16:58:14 +02:00
|
|
|
if(!hasStackAtSlot(slot))
|
2010-11-22 02:34:46 +02:00
|
|
|
{
|
2010-11-27 03:46:19 +02:00
|
|
|
putStack(slot, stack);
|
|
|
|
}
|
|
|
|
else if(allowMerging && stack->type == getCreature(slot))
|
|
|
|
{
|
|
|
|
joinStack(slot, stack);
|
2010-11-22 02:34:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-11 19:03:05 +02:00
|
|
|
logGlobal->error("Cannot add to slot %d stack %s", slot.getNum(), stack->nodeName());
|
2010-11-22 02:34:46 +02:00
|
|
|
}
|
2010-04-02 05:23:22 +03:00
|
|
|
}
|
|
|
|
|
2017-07-15 13:08:20 +02:00
|
|
|
bool CCreatureSet::validTypes(bool allowUnrandomized) const
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & elem : stacks)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
if(!elem.second->valid(allowUnrandomized))
|
2010-11-27 03:46:19 +02:00
|
|
|
return false;
|
2010-04-02 05:23:22 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
bool CCreatureSet::slotEmpty(const SlotID & slot) const
|
2010-05-02 21:20:26 +03:00
|
|
|
{
|
2011-02-04 16:58:14 +02:00
|
|
|
return !hasStackAtSlot(slot);
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CCreatureSet::needsLastStack() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-21 12:31:08 +03:00
|
|
|
ui64 CCreatureSet::getArmyStrength() const
|
2010-05-02 21:20:26 +03:00
|
|
|
{
|
2011-06-21 12:31:08 +03:00
|
|
|
ui64 ret = 0;
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & elem : stacks)
|
2013-06-29 16:05:48 +03:00
|
|
|
ret += elem.second->getPower();
|
2010-05-02 21:20:26 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
ui64 CCreatureSet::getPower(const SlotID & slot) const
|
2010-05-02 21:20:26 +03:00
|
|
|
{
|
2012-01-03 04:55:26 +03:00
|
|
|
return getStack(slot).getPower();
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
2014-06-24 20:39:36 +03:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
std::string CCreatureSet::getRoughAmount(const SlotID & slot, int mode) const
|
2010-05-02 21:20:26 +03:00
|
|
|
{
|
2015-12-24 20:03:51 +02:00
|
|
|
/// Mode represent return string format
|
|
|
|
/// "Pack" - 0, "A pack of" - 1, "a pack of" - 2
|
2023-01-14 16:55:08 +02:00
|
|
|
CCreature::CreatureQuantityId quantity = CCreature::getQuantityID(getStackCount(slot));
|
|
|
|
|
|
|
|
if((int)quantity)
|
|
|
|
{
|
2023-02-16 00:36:09 +02:00
|
|
|
if(settings["gameTweaks"]["numericCreaturesQuantities"].Bool())
|
2023-01-14 16:55:08 +02:00
|
|
|
return CCreature::getQuantityRangeStringForId(quantity);
|
|
|
|
|
|
|
|
return VLC->generaltexth->arraytxt[(174 + mode) + 3*(int)quantity];
|
|
|
|
}
|
2012-06-13 16:04:06 +03:00
|
|
|
return "";
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
|
|
|
|
2015-12-24 20:03:51 +02:00
|
|
|
std::string CCreatureSet::getArmyDescription() const
|
|
|
|
{
|
|
|
|
std::string text;
|
|
|
|
std::vector<std::string> guards;
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & elem : stacks)
|
2015-12-24 20:03:51 +02:00
|
|
|
{
|
2023-01-02 18:00:51 +02:00
|
|
|
auto str = boost::str(boost::format("%s %s") % getRoughAmount(elem.first, 2) % getCreature(elem.first)->getNamePluralTranslated());
|
2015-12-24 20:03:51 +02:00
|
|
|
guards.push_back(str);
|
|
|
|
}
|
2023-03-13 23:26:44 +02:00
|
|
|
if(!guards.empty())
|
2015-12-24 20:03:51 +02:00
|
|
|
{
|
|
|
|
for(int i = 0; i < guards.size(); i++)
|
|
|
|
{
|
|
|
|
text += guards[i];
|
|
|
|
if(i + 2 < guards.size())
|
|
|
|
text += ", ";
|
|
|
|
else if(i + 2 == guards.size())
|
|
|
|
text += VLC->generaltexth->allTexts[237];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2010-05-02 21:20:26 +03:00
|
|
|
int CCreatureSet::stacksCount() const
|
|
|
|
{
|
2020-10-01 10:38:06 +02:00
|
|
|
return static_cast<int>(stacks.size());
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureSet::setFormation(bool tight)
|
|
|
|
{
|
2023-04-02 18:56:10 +02:00
|
|
|
if (tight)
|
|
|
|
formation = EArmyFormation::TIGHT;
|
|
|
|
else
|
2023-04-10 13:00:34 +02:00
|
|
|
formation = EArmyFormation::LOOSE;
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
void CCreatureSet::setStackCount(const SlotID & slot, TQuantity count)
|
2010-05-02 21:20:26 +03:00
|
|
|
{
|
2011-02-04 16:58:14 +02:00
|
|
|
assert(hasStackAtSlot(slot));
|
2011-04-10 11:33:53 +03:00
|
|
|
assert(stacks[slot]->count + count > 0);
|
2023-03-15 21:34:29 +02:00
|
|
|
if (VLC->settings()->getBoolean(EGameSettings::MODULE_STACK_EXPERIENCE) && count > stacks[slot]->count)
|
2020-10-01 10:38:06 +02:00
|
|
|
stacks[slot]->experience = static_cast<TExpType>(stacks[slot]->experience * (count / static_cast<double>(stacks[slot]->count)));
|
2011-01-21 04:36:30 +02:00
|
|
|
stacks[slot]->count = count;
|
2011-02-04 16:58:14 +02:00
|
|
|
armyChanged();
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
|
|
|
|
2012-09-23 21:01:04 +03:00
|
|
|
void CCreatureSet::giveStackExp(TExpType exp)
|
2011-02-12 20:48:11 +02:00
|
|
|
{
|
|
|
|
for(TSlots::const_iterator i = stacks.begin(); i != stacks.end(); i++)
|
|
|
|
i->second->giveStackExp(exp);
|
|
|
|
}
|
2023-03-13 23:26:44 +02:00
|
|
|
void CCreatureSet::setStackExp(const SlotID & slot, TExpType exp)
|
2011-03-27 12:31:14 +03:00
|
|
|
{
|
|
|
|
assert(hasStackAtSlot(slot));
|
|
|
|
stacks[slot]->experience = exp;
|
|
|
|
}
|
2011-02-12 20:48:11 +02:00
|
|
|
|
2010-05-02 21:20:26 +03:00
|
|
|
void CCreatureSet::clear()
|
|
|
|
{
|
2011-01-21 04:36:30 +02:00
|
|
|
while(!stacks.empty())
|
2010-11-27 03:46:19 +02:00
|
|
|
{
|
2011-01-21 04:36:30 +02:00
|
|
|
eraseStack(stacks.begin()->first);
|
2010-11-27 03:46:19 +02:00
|
|
|
}
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
const CStackInstance & CCreatureSet::getStack(const SlotID & slot) const
|
2010-05-02 21:20:26 +03:00
|
|
|
{
|
2011-02-04 16:58:14 +02:00
|
|
|
assert(hasStackAtSlot(slot));
|
2011-06-20 14:41:04 +03:00
|
|
|
return *getStackPtr(slot);
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
const CStackInstance * CCreatureSet::getStackPtr(const SlotID & slot) const
|
2011-06-20 14:41:04 +03:00
|
|
|
{
|
|
|
|
if(hasStackAtSlot(slot))
|
|
|
|
return stacks.find(slot)->second;
|
2013-06-26 14:18:27 +03:00
|
|
|
else return nullptr;
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
void CCreatureSet::eraseStack(const SlotID & slot)
|
2010-05-02 21:20:26 +03:00
|
|
|
{
|
2011-02-04 16:58:14 +02:00
|
|
|
assert(hasStackAtSlot(slot));
|
|
|
|
CStackInstance *toErase = detachStack(slot);
|
2011-12-14 00:23:17 +03:00
|
|
|
vstd::clear_pointer(toErase);
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CCreatureSet::contains(const CStackInstance *stack) const
|
|
|
|
{
|
2013-02-13 22:35:43 +03:00
|
|
|
if(!stack)
|
2010-05-02 21:20:26 +03:00
|
|
|
return false;
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & elem : stacks)
|
2013-06-29 16:05:48 +03:00
|
|
|
if(elem.second == stack)
|
2010-05-02 21:20:26 +03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
SlotID CCreatureSet::findStack(const CStackInstance *stack) const
|
2010-11-20 19:36:02 +02:00
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
const auto * h = dynamic_cast<const CGHeroInstance *>(this);
|
2012-08-20 19:10:50 +03:00
|
|
|
if (h && h->commander == stack)
|
2013-02-16 17:03:47 +03:00
|
|
|
return SlotID::COMMANDER_SLOT_PLACEHOLDER;
|
2012-08-20 19:10:50 +03:00
|
|
|
|
2013-02-13 22:35:43 +03:00
|
|
|
if(!stack)
|
2013-02-16 17:03:47 +03:00
|
|
|
return SlotID();
|
2010-11-20 19:36:02 +02:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & elem : stacks)
|
2013-06-29 16:05:48 +03:00
|
|
|
if(elem.second == stack)
|
|
|
|
return elem.first;
|
2010-11-20 19:36:02 +02:00
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
return SlotID();
|
2010-11-20 19:36:02 +02:00
|
|
|
}
|
|
|
|
|
2010-11-22 02:34:46 +02:00
|
|
|
CArmedInstance * CCreatureSet::castToArmyObj()
|
|
|
|
{
|
|
|
|
return dynamic_cast<CArmedInstance *>(this);
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
void CCreatureSet::putStack(const SlotID & slot, CStackInstance * stack)
|
2010-11-27 03:46:19 +02:00
|
|
|
{
|
2013-02-16 17:03:47 +03:00
|
|
|
assert(slot.getNum() < GameConstants::ARMY_SIZE);
|
2011-02-04 16:58:14 +02:00
|
|
|
assert(!hasStackAtSlot(slot));
|
2011-01-21 04:36:30 +02:00
|
|
|
stacks[slot] = stack;
|
2010-11-27 03:46:19 +02:00
|
|
|
stack->setArmyObj(castToArmyObj());
|
2011-02-04 16:58:14 +02:00
|
|
|
armyChanged();
|
2010-11-27 03:46:19 +02:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
void CCreatureSet::joinStack(const SlotID & slot, CStackInstance * stack)
|
2010-11-27 03:46:19 +02:00
|
|
|
{
|
2023-04-10 16:44:41 +02:00
|
|
|
[[maybe_unused]] const CCreature *c = getCreature(slot);
|
2010-11-27 03:46:19 +02:00
|
|
|
assert(c == stack->type);
|
|
|
|
assert(c);
|
|
|
|
|
2013-02-13 22:35:43 +03:00
|
|
|
//TODO move stuff
|
2010-11-27 03:46:19 +02:00
|
|
|
changeStackCount(slot, stack->count);
|
2011-12-14 00:23:17 +03:00
|
|
|
vstd::clear_pointer(stack);
|
2010-11-27 03:46:19 +02:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
void CCreatureSet::changeStackCount(const SlotID & slot, TQuantity toAdd)
|
2010-11-27 03:46:19 +02:00
|
|
|
{
|
|
|
|
setStackCount(slot, getStackCount(slot) + toAdd);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCreatureSet::~CCreatureSet()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2011-01-28 04:11:58 +02:00
|
|
|
void CCreatureSet::setToArmy(CSimpleArmy &src)
|
2010-11-27 03:46:19 +02:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
while(src)
|
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
auto i = src.army.begin();
|
2010-11-27 03:46:19 +02:00
|
|
|
|
2018-03-11 17:56:33 +02:00
|
|
|
putStack(i->first, new CStackInstance(i->second.first, i->second.second));
|
2011-01-28 04:11:58 +02:00
|
|
|
src.army.erase(i);
|
2010-11-27 03:46:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
CStackInstance * CCreatureSet::detachStack(const SlotID & slot)
|
2010-11-27 03:46:19 +02:00
|
|
|
{
|
2011-02-04 16:58:14 +02:00
|
|
|
assert(hasStackAtSlot(slot));
|
2011-01-21 04:36:30 +02:00
|
|
|
CStackInstance *ret = stacks[slot];
|
2010-11-27 03:46:19 +02:00
|
|
|
|
2011-02-05 15:39:10 +02:00
|
|
|
//if(CArmedInstance *armedObj = castToArmyObj())
|
2016-03-12 03:41:27 +02:00
|
|
|
if(ret)
|
2010-12-06 01:10:02 +02:00
|
|
|
{
|
2013-06-26 14:18:27 +03:00
|
|
|
ret->setArmyObj(nullptr); //detaches from current armyobj
|
2016-03-12 03:41:27 +02:00
|
|
|
assert(!ret->armyObj); //we failed detaching?
|
2010-12-06 01:10:02 +02:00
|
|
|
}
|
|
|
|
|
2011-01-21 04:36:30 +02:00
|
|
|
stacks.erase(slot);
|
2011-02-04 16:58:14 +02:00
|
|
|
armyChanged();
|
2010-11-27 03:46:19 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
void CCreatureSet::setStackType(const SlotID & slot, const CreatureID & type)
|
2010-11-27 03:46:19 +02:00
|
|
|
{
|
2011-02-04 16:58:14 +02:00
|
|
|
assert(hasStackAtSlot(slot));
|
2011-01-21 04:36:30 +02:00
|
|
|
CStackInstance *s = stacks[slot];
|
2018-03-10 23:19:36 +02:00
|
|
|
s->setType(type);
|
2011-02-04 16:58:14 +02:00
|
|
|
armyChanged();
|
2010-11-27 03:46:19 +02:00
|
|
|
}
|
|
|
|
|
2010-12-13 01:44:16 +02:00
|
|
|
bool CCreatureSet::canBeMergedWith(const CCreatureSet &cs, bool allowMergingStacks) const
|
2010-11-27 22:17:28 +02:00
|
|
|
{
|
2010-12-13 01:44:16 +02:00
|
|
|
if(!allowMergingStacks)
|
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
int freeSlots = stacksCount() - GameConstants::ARMY_SIZE;
|
2010-12-13 01:44:16 +02:00
|
|
|
std::set<const CCreature*> cresToAdd;
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & elem : cs.stacks)
|
2010-12-13 01:44:16 +02:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
SlotID dest = getSlotFor(elem.second->type);
|
2013-02-16 17:03:47 +03:00
|
|
|
if(!dest.validSlot() || hasStackAtSlot(dest))
|
2013-06-29 16:05:48 +03:00
|
|
|
cresToAdd.insert(elem.second->type);
|
2010-12-13 01:44:16 +02:00
|
|
|
}
|
|
|
|
return cresToAdd.size() <= freeSlots;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-08 15:27:32 +02:00
|
|
|
CCreatureSet cres;
|
2013-09-28 15:31:06 +03:00
|
|
|
SlotID j;
|
2010-11-27 22:17:28 +02:00
|
|
|
|
2010-12-13 01:44:16 +02:00
|
|
|
//get types of creatures that need their own slot
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & elem : cs.stacks)
|
2013-09-28 15:31:06 +03:00
|
|
|
if ((j = cres.getSlotFor(elem.second->type)).validSlot())
|
2023-04-05 02:26:29 +02:00
|
|
|
cres.addToSlot(j, elem.second->type->getId(), 1, true); //merge if possible
|
|
|
|
//cres.addToSlot(elem.first, elem.second->type->getId(), 1, true);
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & elem : stacks)
|
2011-03-08 15:27:32 +02:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
if ((j = cres.getSlotFor(elem.second->type)).validSlot())
|
2023-04-05 02:26:29 +02:00
|
|
|
cres.addToSlot(j, elem.second->type->getId(), 1, true); //merge if possible
|
2011-03-08 15:27:32 +02:00
|
|
|
else
|
|
|
|
return false; //no place found
|
|
|
|
}
|
|
|
|
return true; //all stacks found their slots
|
2010-12-13 01:44:16 +02:00
|
|
|
}
|
2010-11-27 22:17:28 +02:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
bool CCreatureSet::hasStackAtSlot(const SlotID & slot) const
|
2010-11-27 22:17:28 +02:00
|
|
|
{
|
2011-01-21 04:36:30 +02:00
|
|
|
return vstd::contains(stacks, slot);
|
2010-11-27 22:17:28 +02:00
|
|
|
}
|
|
|
|
|
2010-12-06 01:10:02 +02:00
|
|
|
CCreatureSet & CCreatureSet::operator=(const CCreatureSet&cs)
|
|
|
|
{
|
|
|
|
assert(0);
|
2010-12-06 01:26:56 +02:00
|
|
|
return *this;
|
2010-12-06 01:10:02 +02:00
|
|
|
}
|
|
|
|
|
2011-02-04 16:58:14 +02:00
|
|
|
void CCreatureSet::armyChanged()
|
|
|
|
{
|
2016-02-22 01:37:19 +02:00
|
|
|
|
2011-02-04 16:58:14 +02:00
|
|
|
}
|
|
|
|
|
2023-04-16 19:42:56 +02:00
|
|
|
void CCreatureSet::serializeJson(JsonSerializeFormat & handler, const std::string & fieldName, const std::optional<int> fixedSize)
|
2016-01-15 19:24:17 +02:00
|
|
|
{
|
2016-02-22 01:37:19 +02:00
|
|
|
if(handler.saving && stacks.empty())
|
|
|
|
return;
|
2016-11-13 12:38:42 +02:00
|
|
|
|
|
|
|
auto a = handler.enterArray(fieldName);
|
|
|
|
|
2016-02-22 01:37:19 +02:00
|
|
|
|
|
|
|
if(handler.saving)
|
2016-01-15 19:24:17 +02:00
|
|
|
{
|
2016-11-13 12:38:42 +02:00
|
|
|
size_t sz = 0;
|
|
|
|
|
|
|
|
for(const auto & p : stacks)
|
|
|
|
vstd::amax(sz, p.first.getNum()+1);
|
|
|
|
|
|
|
|
if(fixedSize)
|
2023-04-16 19:42:56 +02:00
|
|
|
vstd::amax(sz, fixedSize.value());
|
2016-11-13 12:38:42 +02:00
|
|
|
|
2017-11-26 23:18:18 +02:00
|
|
|
a.resize(sz, JsonNode::JsonType::DATA_STRUCT);
|
2016-11-13 12:38:42 +02:00
|
|
|
|
2016-02-22 01:37:19 +02:00
|
|
|
for(const auto & p : stacks)
|
|
|
|
{
|
2016-11-13 12:38:42 +02:00
|
|
|
auto s = a.enterStruct(p.first.getNum());
|
|
|
|
p.second->serializeJson(handler);
|
2016-02-22 01:37:19 +02:00
|
|
|
}
|
2016-01-15 19:24:17 +02:00
|
|
|
}
|
2016-02-22 01:37:19 +02:00
|
|
|
else
|
2016-01-15 19:24:17 +02:00
|
|
|
{
|
2016-11-13 12:38:42 +02:00
|
|
|
for(size_t idx = 0; idx < a.size(); idx++)
|
2016-02-22 01:37:19 +02:00
|
|
|
{
|
2016-11-13 12:38:42 +02:00
|
|
|
auto s = a.enterStruct(idx);
|
|
|
|
|
|
|
|
TQuantity amount = 0;
|
2016-01-15 19:24:17 +02:00
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
handler.serializeInt("amount", amount);
|
2016-01-15 19:24:17 +02:00
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
if(amount > 0)
|
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
auto * new_stack = new CStackInstance();
|
2016-11-13 12:38:42 +02:00
|
|
|
new_stack->serializeJson(handler);
|
2023-03-13 23:26:44 +02:00
|
|
|
putStack(SlotID(static_cast<si32>(idx)), new_stack);
|
2016-02-26 01:35:30 +02:00
|
|
|
}
|
2016-02-22 01:37:19 +02:00
|
|
|
}
|
2016-01-15 19:24:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-02 05:23:22 +03:00
|
|
|
CStackInstance::CStackInstance()
|
2010-11-27 03:46:19 +02:00
|
|
|
: armyObj(_armyObj)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
CStackInstance::CStackInstance(const CreatureID & id, TQuantity Count, bool isHypothetic):
|
|
|
|
CBonusSystemNode(isHypothetic), armyObj(_armyObj)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
setType(id);
|
|
|
|
count = Count;
|
|
|
|
}
|
|
|
|
|
2021-03-01 21:38:50 +02:00
|
|
|
CStackInstance::CStackInstance(const CCreature *cre, TQuantity Count, bool isHypothetic)
|
2021-05-23 13:28:43 +02:00
|
|
|
: CBonusSystemNode(isHypothetic), armyObj(_armyObj)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
|
|
|
init();
|
2011-01-21 12:37:19 +02:00
|
|
|
setType(cre);
|
2010-04-02 05:23:22 +03:00
|
|
|
count = Count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStackInstance::init()
|
|
|
|
{
|
|
|
|
experience = 0;
|
|
|
|
count = 0;
|
2013-06-26 14:18:27 +03:00
|
|
|
type = nullptr;
|
|
|
|
_armyObj = nullptr;
|
2013-02-13 22:35:43 +03:00
|
|
|
setNodeType(STACK_INSTANCE);
|
2010-04-02 05:23:22 +03:00
|
|
|
}
|
|
|
|
|
2023-01-14 16:55:08 +02:00
|
|
|
CCreature::CreatureQuantityId CStackInstance::getQuantityID() const
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
|
|
|
return CCreature::getQuantityID(count);
|
|
|
|
}
|
|
|
|
|
2011-02-11 10:20:26 +02:00
|
|
|
int CStackInstance::getExpRank() const
|
|
|
|
{
|
2023-03-15 21:34:29 +02:00
|
|
|
if (!VLC->settings()->getBoolean(EGameSettings::MODULE_STACK_EXPERIENCE))
|
2012-09-26 08:13:47 +03:00
|
|
|
return 0;
|
2023-04-05 02:26:29 +02:00
|
|
|
int tier = type->getLevel();
|
2011-12-14 00:23:17 +03:00
|
|
|
if (vstd::iswithin(tier, 1, 7))
|
2011-02-11 10:20:26 +02:00
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
for(int i = static_cast<int>(VLC->creh->expRanks[tier].size()) - 2; i > -1; --i) //sic!
|
2011-02-11 10:20:26 +02:00
|
|
|
{ //exp values vary from 1st level to max exp at 11th level
|
|
|
|
if (experience >= VLC->creh->expRanks[tier][i])
|
|
|
|
return ++i; //faster, but confusing - 0 index mean 1st level of experience
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else //higher tier
|
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
for(int i = static_cast<int>(VLC->creh->expRanks[0].size()) - 2; i > -1; --i)
|
2011-02-11 10:20:26 +02:00
|
|
|
{
|
|
|
|
if (experience >= VLC->creh->expRanks[0][i])
|
|
|
|
return ++i;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-30 23:09:50 +03:00
|
|
|
int CStackInstance::getLevel() const
|
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
return std::max(1, static_cast<int>(type->getLevel()));
|
2013-03-30 23:09:50 +03:00
|
|
|
}
|
|
|
|
|
2011-05-29 21:28:50 +03:00
|
|
|
si32 CStackInstance::magicResistance() const
|
|
|
|
{
|
2020-11-11 21:43:40 +02:00
|
|
|
si32 val = valOfBonuses(Selector::type()(Bonus::MAGIC_RESISTANCE));
|
2011-12-14 00:23:17 +03:00
|
|
|
vstd::amin (val, 100);
|
2011-05-29 21:28:50 +03:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2012-09-23 21:01:04 +03:00
|
|
|
void CStackInstance::giveStackExp(TExpType exp)
|
2011-02-12 20:48:11 +02:00
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
int level = type->getLevel();
|
2011-12-14 00:23:17 +03:00
|
|
|
if (!vstd::iswithin(level, 1, 7))
|
2011-02-12 20:48:11 +02:00
|
|
|
level = 0;
|
|
|
|
|
|
|
|
CCreatureHandler * creh = VLC->creh;
|
2011-02-13 21:46:16 +02:00
|
|
|
ui32 maxExp = creh->expRanks[level].back();
|
2011-02-12 20:48:11 +02:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
vstd::amin(exp, static_cast<TExpType>(maxExp)); //prevent exp overflow due to different types
|
2011-12-14 00:23:17 +03:00
|
|
|
vstd::amin(exp, (maxExp * creh->maxExpPerBattle[level])/100);
|
|
|
|
vstd::amin(experience += exp, maxExp); //can't get more exp than this limit
|
2011-02-12 20:48:11 +02:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
void CStackInstance::setType(const CreatureID & creID)
|
2010-11-27 03:46:19 +02:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
if(creID >= 0 && creID < VLC->creh->objects.size())
|
|
|
|
setType(VLC->creh->objects[creID]);
|
2011-05-28 04:02:28 +03:00
|
|
|
else
|
2013-06-26 14:18:27 +03:00
|
|
|
setType((const CCreature*)nullptr);
|
2010-11-27 03:46:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CStackInstance::setType(const CCreature *c)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2010-11-22 02:34:46 +02:00
|
|
|
if(type)
|
2011-02-12 20:48:11 +02:00
|
|
|
{
|
2022-11-06 01:26:13 +02:00
|
|
|
detachFrom(const_cast<CCreature&>(*type));
|
2023-03-15 21:34:29 +02:00
|
|
|
if (type->isMyUpgrade(c) && VLC->settings()->getBoolean(EGameSettings::MODULE_STACK_EXPERIENCE))
|
2020-10-01 10:38:06 +02:00
|
|
|
experience = static_cast<TExpType>(experience * VLC->creh->expAfterUpgrade / 100.0);
|
2011-02-12 20:48:11 +02:00
|
|
|
}
|
2010-11-22 02:34:46 +02:00
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
CStackBasicDescriptor::setType(c);
|
|
|
|
|
2011-05-29 17:06:52 +03:00
|
|
|
if(type)
|
2022-11-06 01:26:13 +02:00
|
|
|
attachTo(const_cast<CCreature&>(*type));
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
2016-09-19 23:36:35 +02:00
|
|
|
std::string CStackInstance::bonusToString(const std::shared_ptr<Bonus>& bonus, bool description) const
|
2011-02-01 20:10:43 +02:00
|
|
|
{
|
2023-02-17 00:19:43 +02:00
|
|
|
return VLC->getBth()->bonusToString(bonus, this, description);
|
2011-02-01 20:10:43 +02:00
|
|
|
}
|
2010-05-02 21:20:26 +03:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
std::string CStackInstance::bonusToGraphics(const std::shared_ptr<Bonus> & bonus) const
|
2011-03-20 10:45:05 +02:00
|
|
|
{
|
2013-03-06 21:49:56 +03:00
|
|
|
return VLC->getBth()->bonusToGraphics(bonus);
|
2011-03-20 10:45:05 +02:00
|
|
|
}
|
|
|
|
|
2021-03-23 16:47:07 +02:00
|
|
|
void CStackInstance::setArmyObj(const CArmedInstance * ArmyObj)
|
2010-11-22 02:34:46 +02:00
|
|
|
{
|
2010-11-27 03:46:19 +02:00
|
|
|
if(_armyObj)
|
2022-11-06 01:26:13 +02:00
|
|
|
detachFrom(const_cast<CArmedInstance&>(*_armyObj));
|
2010-11-22 02:34:46 +02:00
|
|
|
|
2010-12-06 01:10:02 +02:00
|
|
|
_armyObj = ArmyObj;
|
2021-03-23 16:47:07 +02:00
|
|
|
|
2021-09-12 13:30:54 +02:00
|
|
|
if(ArmyObj)
|
2022-11-06 01:26:13 +02:00
|
|
|
attachTo(const_cast<CArmedInstance&>(*_armyObj));
|
2010-11-22 02:34:46 +02:00
|
|
|
}
|
2010-07-16 09:18:41 +03:00
|
|
|
|
2017-07-15 13:08:20 +02:00
|
|
|
std::string CStackInstance::getQuantityTXT(bool capitalized) const
|
2010-07-31 03:26:34 +03:00
|
|
|
{
|
2023-01-14 16:55:08 +02:00
|
|
|
CCreature::CreatureQuantityId quantity = getQuantityID();
|
2012-06-13 16:04:06 +03:00
|
|
|
|
2023-01-14 16:55:08 +02:00
|
|
|
if ((int)quantity)
|
|
|
|
{
|
2023-02-16 00:36:09 +02:00
|
|
|
if(settings["gameTweaks"]["numericCreaturesQuantities"].Bool())
|
2023-01-14 16:55:08 +02:00
|
|
|
return CCreature::getQuantityRangeStringForId(quantity);
|
|
|
|
|
|
|
|
return VLC->generaltexth->arraytxt[174 + (int)quantity*3 - 1 - capitalized];
|
|
|
|
}
|
2012-06-13 16:04:06 +03:00
|
|
|
else
|
|
|
|
return "";
|
2010-11-22 02:34:46 +02:00
|
|
|
}
|
|
|
|
|
2010-11-27 03:46:19 +02:00
|
|
|
bool CStackInstance::valid(bool allowUnrandomized) const
|
|
|
|
{
|
2023-04-02 18:56:10 +02:00
|
|
|
if(!randomStack)
|
2010-11-27 03:46:19 +02:00
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
return (type && type == VLC->creh->objects[type->getId()]);
|
2010-11-27 03:46:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return allowUnrandomized;
|
|
|
|
}
|
|
|
|
|
2010-12-12 01:11:26 +02:00
|
|
|
std::string CStackInstance::nodeName() const
|
|
|
|
{
|
|
|
|
std::ostringstream oss;
|
2011-02-10 15:12:53 +02:00
|
|
|
oss << "Stack of " << count << " of ";
|
2010-12-12 01:11:26 +02:00
|
|
|
if(type)
|
2023-01-02 18:00:51 +02:00
|
|
|
oss << type->getNamePluralTextID();
|
2010-12-12 01:11:26 +02:00
|
|
|
else
|
|
|
|
oss << "[UNDEFINED TYPE]";
|
|
|
|
|
|
|
|
return oss.str();
|
|
|
|
}
|
|
|
|
|
2021-09-12 13:30:54 +02:00
|
|
|
PlayerColor CStackInstance::getOwner() const
|
|
|
|
{
|
|
|
|
return _armyObj ? _armyObj->getOwner() : PlayerColor::NEUTRAL;
|
|
|
|
}
|
|
|
|
|
2011-02-04 16:58:14 +02:00
|
|
|
void CStackInstance::deserializationFix()
|
|
|
|
{
|
2011-02-22 11:47:25 +02:00
|
|
|
const CArmedInstance *armyBackup = _armyObj;
|
2013-06-26 14:18:27 +03:00
|
|
|
_armyObj = nullptr;
|
2011-02-22 11:47:25 +02:00
|
|
|
setArmyObj(armyBackup);
|
2012-04-14 05:20:22 +03:00
|
|
|
artDeserializationFix(this);
|
2011-02-04 16:58:14 +02:00
|
|
|
}
|
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
CreatureID CStackInstance::getCreatureID() const
|
2011-06-20 14:41:04 +03:00
|
|
|
{
|
|
|
|
if(type)
|
2023-04-05 02:26:29 +02:00
|
|
|
return type->getId();
|
2013-02-13 22:35:43 +03:00
|
|
|
else
|
2013-02-07 20:34:50 +03:00
|
|
|
return CreatureID::NONE;
|
2011-06-20 14:41:04 +03:00
|
|
|
}
|
|
|
|
|
2011-10-22 10:05:57 +03:00
|
|
|
std::string CStackInstance::getName() const
|
|
|
|
{
|
2023-01-02 18:00:51 +02:00
|
|
|
return (count > 1) ? type->getNamePluralTranslated() : type->getNameSingularTranslated();
|
2011-10-22 10:05:57 +03:00
|
|
|
}
|
|
|
|
|
2012-01-03 04:55:26 +03:00
|
|
|
ui64 CStackInstance::getPower() const
|
|
|
|
{
|
|
|
|
assert(type);
|
2023-04-05 02:26:29 +02:00
|
|
|
return type->getAIValue() * count;
|
2012-01-03 04:55:26 +03:00
|
|
|
}
|
|
|
|
|
2013-02-07 20:34:50 +03:00
|
|
|
ArtBearer::ArtBearer CStackInstance::bearerType() const
|
2012-04-14 05:20:22 +03:00
|
|
|
{
|
|
|
|
return ArtBearer::CREATURE;
|
|
|
|
}
|
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
void CStackInstance::putArtifact(ArtifactPosition pos, CArtifactInstance * art)
|
2016-01-15 19:24:17 +02:00
|
|
|
{
|
2016-11-13 12:38:42 +02:00
|
|
|
assert(!getArt(pos));
|
|
|
|
art->putAt(ArtifactLocation(this, pos));
|
2016-01-15 19:24:17 +02:00
|
|
|
}
|
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
void CStackInstance::serializeJson(JsonSerializeFormat & handler)
|
2016-01-15 19:24:17 +02:00
|
|
|
{
|
2016-11-13 12:38:42 +02:00
|
|
|
//todo: artifacts
|
|
|
|
CStackBasicDescriptor::serializeJson(handler);//must be first
|
|
|
|
|
|
|
|
if(handler.saving)
|
|
|
|
{
|
2023-04-02 18:56:10 +02:00
|
|
|
if(randomStack)
|
2016-11-13 12:38:42 +02:00
|
|
|
{
|
2023-04-02 18:56:10 +02:00
|
|
|
int level = randomStack->level;
|
|
|
|
int upgrade = randomStack->upgrade;
|
2016-11-13 12:38:42 +02:00
|
|
|
|
|
|
|
handler.serializeInt("level", level, 0);
|
2023-04-02 18:56:10 +02:00
|
|
|
handler.serializeInt("upgraded", upgrade, 0);
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-01-15 19:24:17 +02:00
|
|
|
{
|
2016-11-13 12:38:42 +02:00
|
|
|
//type set by CStackBasicDescriptor::serializeJson
|
|
|
|
if(type == nullptr)
|
|
|
|
{
|
2023-04-02 18:56:10 +02:00
|
|
|
uint8_t level = 0;
|
|
|
|
uint8_t upgrade = 0;
|
2016-11-13 12:38:42 +02:00
|
|
|
|
|
|
|
handler.serializeInt("level", level, 0);
|
2023-04-02 18:56:10 +02:00
|
|
|
handler.serializeInt("upgrade", upgrade, 0);
|
2016-11-13 12:38:42 +02:00
|
|
|
|
2023-04-02 18:56:10 +02:00
|
|
|
randomStack = RandomStackInfo{ level, upgrade };
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
2016-01-15 19:24:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-05 17:56:28 +02:00
|
|
|
FactionID CStackInstance::getFaction() const
|
|
|
|
{
|
|
|
|
if(type)
|
|
|
|
return type->getFaction();
|
|
|
|
|
|
|
|
return FactionID::NEUTRAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const IBonusBearer* CStackInstance::getBonusBearer() const
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2012-04-22 20:38:36 +03:00
|
|
|
CCommanderInstance::CCommanderInstance()
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
CCommanderInstance::CCommanderInstance(const CreatureID & id): name("Commando")
|
2012-04-22 20:38:36 +03:00
|
|
|
{
|
|
|
|
init();
|
2012-04-28 14:41:20 +03:00
|
|
|
setType(id);
|
2023-03-13 23:26:44 +02:00
|
|
|
//TODO - parse them
|
2012-04-22 20:38:36 +03:00
|
|
|
}
|
|
|
|
|
2012-04-28 16:01:39 +03:00
|
|
|
void CCommanderInstance::init()
|
2012-04-22 20:38:36 +03:00
|
|
|
{
|
|
|
|
alive = true;
|
|
|
|
experience = 0;
|
2012-05-18 17:02:27 +03:00
|
|
|
level = 1;
|
2012-04-28 14:41:20 +03:00
|
|
|
count = 1;
|
2013-06-26 14:18:27 +03:00
|
|
|
type = nullptr;
|
|
|
|
_armyObj = nullptr;
|
2013-02-02 22:28:39 +03:00
|
|
|
setNodeType (CBonusSystemNode::COMMANDER);
|
2012-05-18 17:02:27 +03:00
|
|
|
secondarySkills.resize (ECommander::SPELL_POWER + 1);
|
2012-04-22 20:38:36 +03:00
|
|
|
}
|
|
|
|
|
2012-05-01 11:52:22 +03:00
|
|
|
void CCommanderInstance::setAlive (bool Alive)
|
|
|
|
{
|
2012-05-07 15:54:22 +03:00
|
|
|
//TODO: helm of immortality
|
2012-05-01 11:52:22 +03:00
|
|
|
alive = Alive;
|
2012-05-07 15:54:22 +03:00
|
|
|
if (!alive)
|
|
|
|
{
|
2018-03-05 08:51:35 +02:00
|
|
|
removeBonusesRecursive(Bonus::UntilCommanderKilled);
|
2012-05-07 15:54:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-23 21:01:04 +03:00
|
|
|
void CCommanderInstance::giveStackExp (TExpType exp)
|
2012-05-07 15:54:22 +03:00
|
|
|
{
|
|
|
|
if (alive)
|
|
|
|
experience += exp;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCommanderInstance::getExpRank() const
|
|
|
|
{
|
|
|
|
return VLC->heroh->level (experience);
|
|
|
|
}
|
|
|
|
|
2013-03-30 23:09:50 +03:00
|
|
|
int CCommanderInstance::getLevel() const
|
|
|
|
{
|
|
|
|
return std::max (1, getExpRank());
|
|
|
|
}
|
|
|
|
|
2012-05-07 15:54:22 +03:00
|
|
|
void CCommanderInstance::levelUp ()
|
|
|
|
{
|
2012-05-18 17:02:27 +03:00
|
|
|
level++;
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & bonus : VLC->creh->commanderLevelPremy)
|
2012-05-07 15:54:22 +03:00
|
|
|
{ //grant all regular level-up bonuses
|
2016-09-19 23:36:35 +02:00
|
|
|
accumulateBonus(bonus);
|
2012-05-07 15:54:22 +03:00
|
|
|
}
|
2012-05-01 11:52:22 +03:00
|
|
|
}
|
|
|
|
|
2013-02-07 20:34:50 +03:00
|
|
|
ArtBearer::ArtBearer CCommanderInstance::bearerType() const
|
2012-05-19 21:27:23 +03:00
|
|
|
{
|
|
|
|
return ArtBearer::COMMANDER;
|
|
|
|
}
|
|
|
|
|
2013-04-20 14:34:01 +03:00
|
|
|
bool CCommanderInstance::gainsLevel() const
|
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
return experience >= static_cast<TExpType>(VLC->heroh->reqExp(level + 1));
|
2013-04-20 14:34:01 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
//This constructor should be placed here to avoid side effects
|
|
|
|
CStackBasicDescriptor::CStackBasicDescriptor() = default;
|
2010-11-22 02:34:46 +02:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
CStackBasicDescriptor::CStackBasicDescriptor(const CreatureID & id, TQuantity Count):
|
|
|
|
type(VLC->creh->objects[id]),
|
|
|
|
count(Count)
|
2010-11-22 02:34:46 +02:00
|
|
|
{
|
2010-11-27 03:46:19 +02:00
|
|
|
}
|
|
|
|
|
2010-12-06 01:10:02 +02:00
|
|
|
CStackBasicDescriptor::CStackBasicDescriptor(const CCreature *c, TQuantity Count)
|
|
|
|
: type(c), count(Count)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
const Creature * CStackBasicDescriptor::getType() const
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
TQuantity CStackBasicDescriptor::getCount() const
|
|
|
|
{
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
void CStackBasicDescriptor::setType(const CCreature * c)
|
2016-01-15 19:24:17 +02:00
|
|
|
{
|
2016-11-13 12:38:42 +02:00
|
|
|
type = c;
|
2016-01-15 19:24:17 +02:00
|
|
|
}
|
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
void CStackBasicDescriptor::serializeJson(JsonSerializeFormat & handler)
|
2016-01-15 19:24:17 +02:00
|
|
|
{
|
2016-11-13 12:38:42 +02:00
|
|
|
handler.serializeInt("amount", count);
|
|
|
|
|
|
|
|
if(handler.saving)
|
|
|
|
{
|
|
|
|
if(type)
|
|
|
|
{
|
2023-01-02 18:00:51 +02:00
|
|
|
std::string typeName = type->getJsonKey();
|
2016-11-13 12:38:42 +02:00
|
|
|
handler.serializeString("type", typeName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
std::string typeName;
|
2016-11-13 12:38:42 +02:00
|
|
|
handler.serializeString("type", typeName);
|
2022-11-15 02:20:55 +02:00
|
|
|
if(!typeName.empty())
|
2022-12-21 19:00:36 +02:00
|
|
|
setType(VLC->creh->getCreature(CModHandler::scopeMap(), typeName));
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
2016-01-15 19:24:17 +02:00
|
|
|
}
|
|
|
|
|
2011-01-28 04:11:58 +02:00
|
|
|
void CSimpleArmy::clear()
|
|
|
|
{
|
|
|
|
army.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
CSimpleArmy::operator bool() const
|
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
return !army.empty();
|
2011-01-28 04:11:58 +02:00
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
bool CSimpleArmy::setCreature(SlotID slot, CreatureID cre, TQuantity count)
|
2011-01-28 04:11:58 +02:00
|
|
|
{
|
|
|
|
assert(!vstd::contains(army, slot));
|
2018-03-11 17:56:33 +02:00
|
|
|
army[slot] = std::make_pair(cre, count);
|
2011-01-28 04:11:58 +02:00
|
|
|
return true;
|
2011-02-06 19:26:27 +02:00
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|