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
|
|
|
|
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"
|
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"
|
2011-02-06 10:32:05 +02:00
|
|
|
#include "CSpellHandler.h"
|
2012-05-07 15:54:22 +03:00
|
|
|
#include "CHeroHandler.h"
|
2013-03-06 21:49:56 +03:00
|
|
|
#include "IBonusTypeHandler.h"
|
2010-04-02 05:23:22 +03:00
|
|
|
|
2012-12-19 17:54:10 +03: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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
const CStackInstance &CCreatureSet::operator[](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
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
const CCreature* CCreatureSet::getCreature(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
|
|
|
{
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->errorStream() << "Cannot set slot " << slot;
|
2010-04-02 05:23:22 +03:00
|
|
|
return false;
|
2010-11-22 02:34:46 +02:00
|
|
|
}
|
|
|
|
if(!quantity)
|
|
|
|
{
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->warnStream() << "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);
|
|
|
|
|
2010-11-27 03:46:19 +02:00
|
|
|
putStack(slot, new CStackInstance(type, quantity));
|
|
|
|
return true;
|
2010-04-02 05:23:22 +03:00
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
SlotID CCreatureSet::getSlotFor(CreatureID creature, ui32 slotsAmount/*=7*/) const /*returns -1 if no slot available */
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2010-11-27 22:17:28 +02:00
|
|
|
return getSlotFor(VLC->creh->creatures[creature], slotsAmount);
|
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
SlotID CCreatureSet::getSlotFor(const CCreature *c, ui32 slotsAmount/*=ARMY_SIZE*/) const
|
2010-11-27 22:17:28 +02:00
|
|
|
{
|
|
|
|
assert(c->valid());
|
2013-06-29 16:05:48 +03:00
|
|
|
for(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
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
SlotID CCreatureSet::getFreeSlot(ui32 slotsAmount/*=ARMY_SIZE*/) 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
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
int CCreatureSet::getStackCount(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
|
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
TExpType CCreatureSet::getStackExperience(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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
bool CCreatureSet::mergableStacks(std::pair<SlotID, SlotID> &out, SlotID preferable /*= -1*/) 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;
|
2013-06-29 16:05:48 +03:00
|
|
|
for(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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : stacks)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
if(i->second->type == elem.second->type && i->first != elem.first)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
|
|
|
out.first = i->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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
void CCreatureSet::addToSlot(SlotID slot, CreatureID cre, TQuantity count, bool allowMerging/* = true*/)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2010-05-02 21:20:26 +03:00
|
|
|
const CCreature *c = VLC->creh->creatures[cre];
|
|
|
|
|
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
|
|
|
|
{
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->errorStream() << "Failed adding to slot!";
|
2010-11-22 02:34:46 +02:00
|
|
|
}
|
2010-04-02 05:23:22 +03:00
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
void CCreatureSet::addToSlot(SlotID slot, CStackInstance *stack, bool allowMerging/* = true*/)
|
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
|
|
|
|
{
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->errorStream() << "Cannot add to slot " << slot << " stack " << *stack;
|
2010-11-22 02:34:46 +02:00
|
|
|
}
|
2010-04-02 05:23:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CCreatureSet::validTypes(bool allowUnrandomized /*= false*/) const
|
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for(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;
|
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
bool CCreatureSet::slotEmpty(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;
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : stacks)
|
|
|
|
ret += elem.second->getPower();
|
2010-05-02 21:20:26 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
ui64 CCreatureSet::getPower (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
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
std::string CCreatureSet::getRoughAmount (SlotID slot) const
|
2010-05-02 21:20:26 +03:00
|
|
|
{
|
2012-06-13 16:04:06 +03:00
|
|
|
int quantity = CCreature::getQuantityID(getStackCount(slot));
|
|
|
|
if (quantity)
|
|
|
|
return VLC->generaltexth->arraytxt[174 + 3*CCreature::getQuantityID(getStackCount(slot))];
|
|
|
|
return "";
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int CCreatureSet::stacksCount() const
|
|
|
|
{
|
2011-01-21 04:36:30 +02:00
|
|
|
return stacks.size();
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureSet::setFormation(bool tight)
|
|
|
|
{
|
|
|
|
formation = tight;
|
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
void CCreatureSet::setStackCount(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);
|
2012-08-24 12:37:52 +03:00
|
|
|
if (VLC->modh->modules.STACK_EXP && count > stacks[slot]->count)
|
2011-12-14 00:23:17 +03:00
|
|
|
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);
|
|
|
|
}
|
2013-02-16 17:03:47 +03:00
|
|
|
void CCreatureSet::setStackExp(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
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
const CStackInstance& CCreatureSet::getStack(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);
|
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
const CStackInstance* CCreatureSet::getStackPtr(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
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
void CCreatureSet::eraseStack(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;
|
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : stacks)
|
|
|
|
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
|
|
|
{
|
2012-08-20 19:10:50 +03:00
|
|
|
auto h = dynamic_cast<const CGHeroInstance *>(this);
|
|
|
|
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
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : stacks)
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
void CCreatureSet::putStack(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
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
void CCreatureSet::joinStack(SlotID slot, CStackInstance * stack)
|
2010-11-27 03:46:19 +02:00
|
|
|
{
|
|
|
|
const CCreature *c = getCreature(slot);
|
|
|
|
assert(c == stack->type);
|
|
|
|
assert(c);
|
2013-11-09 16:49:36 +03:00
|
|
|
UNUSED(c);
|
2010-11-27 03:46:19 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
void CCreatureSet::changeStackCount(SlotID slot, TQuantity toAdd)
|
2010-11-27 03:46:19 +02:00
|
|
|
{
|
|
|
|
setStackCount(slot, getStackCount(slot) + toAdd);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCreatureSet::CCreatureSet()
|
|
|
|
{
|
|
|
|
formation = false;
|
|
|
|
}
|
|
|
|
|
2010-12-06 01:10:02 +02:00
|
|
|
CCreatureSet::CCreatureSet(const CCreatureSet&)
|
|
|
|
{
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
2010-11-27 03:46:19 +02:00
|
|
|
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
|
|
|
|
2011-01-28 04:11:58 +02:00
|
|
|
assert(i->second.type);
|
|
|
|
assert(i->second.count);
|
2010-11-27 03:46:19 +02:00
|
|
|
|
2011-01-28 04:11:58 +02:00
|
|
|
putStack(i->first, new CStackInstance(i->second.type, i->second.count));
|
|
|
|
src.army.erase(i);
|
2010-11-27 03:46:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
CStackInstance * CCreatureSet::detachStack(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())
|
2014-10-19 14:47:09 +03: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
|
2014-10-19 14:47:09 +03: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;
|
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
void CCreatureSet::setStackType(SlotID slot, const CCreature *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];
|
2010-11-27 03:46:19 +02:00
|
|
|
s->setType(type->idNumber);
|
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;
|
2013-06-29 16:05:48 +03:00
|
|
|
for(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
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : cs.stacks)
|
2013-09-28 15:31:06 +03:00
|
|
|
if ((j = cres.getSlotFor(elem.second->type)).validSlot())
|
|
|
|
cres.addToSlot(j, elem.second->type->idNumber, 1, true); //merge if possible
|
|
|
|
//cres.addToSlot(elem.first, elem.second->type->idNumber, 1, true);
|
2013-06-29 16:05:48 +03:00
|
|
|
for(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())
|
|
|
|
cres.addToSlot(j, elem.second->type->idNumber, 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
|
|
|
}
|
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
bool CCreatureSet::hasStackAtSlot(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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
CStackInstance::CStackInstance(CreatureID id, TQuantity Count)
|
2010-11-27 03:46:19 +02:00
|
|
|
: armyObj(_armyObj)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
setType(id);
|
|
|
|
count = Count;
|
|
|
|
}
|
|
|
|
|
|
|
|
CStackInstance::CStackInstance(const CCreature *cre, TQuantity Count)
|
2010-11-27 03:46:19 +02:00
|
|
|
: 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;
|
2010-04-02 05:23:22 +03:00
|
|
|
idRand = -1;
|
2013-06-26 14:18:27 +03:00
|
|
|
_armyObj = nullptr;
|
2013-02-13 22:35:43 +03:00
|
|
|
setNodeType(STACK_INSTANCE);
|
2010-04-02 05:23:22 +03:00
|
|
|
}
|
|
|
|
|
2013-02-13 22:35:43 +03:00
|
|
|
int 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
|
|
|
|
{
|
2012-09-26 08:13:47 +03:00
|
|
|
if (!VLC->modh->modules.STACK_EXP)
|
|
|
|
return 0;
|
2011-02-11 10:20:26 +02:00
|
|
|
int tier = type->level;
|
2011-12-14 00:23:17 +03:00
|
|
|
if (vstd::iswithin(tier, 1, 7))
|
2011-02-11 10:20:26 +02:00
|
|
|
{
|
|
|
|
for (int i = VLC->creh->expRanks[tier].size()-2; i >-1; --i)//sic!
|
|
|
|
{ //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
|
|
|
|
{
|
2011-02-13 21:46:16 +02:00
|
|
|
for (int i = 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
|
|
|
|
{
|
|
|
|
return std::max (1, (int)type->level);
|
|
|
|
}
|
|
|
|
|
2011-05-29 21:28:50 +03:00
|
|
|
si32 CStackInstance::magicResistance() const
|
|
|
|
{
|
|
|
|
si32 val = valOfBonuses(Selector::type(Bonus::MAGIC_RESISTANCE));
|
|
|
|
if (const CGHeroInstance * hero = dynamic_cast<const CGHeroInstance *>(_armyObj))
|
|
|
|
{
|
|
|
|
//resistance skill
|
2013-02-04 22:43:16 +03:00
|
|
|
val += hero->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, SecondarySkill::RESISTANCE);
|
2011-05-29 21:28:50 +03:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
int level = type->level;
|
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
|
|
|
|
2012-09-23 21:01:04 +03:00
|
|
|
vstd::amin(exp, (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
|
|
|
}
|
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
void CStackInstance::setType(CreatureID creID)
|
2010-11-27 03:46:19 +02:00
|
|
|
{
|
2011-05-28 04:02:28 +03:00
|
|
|
if(creID >= 0 && creID < VLC->creh->creatures.size())
|
|
|
|
setType(VLC->creh->creatures[creID]);
|
|
|
|
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
|
|
|
{
|
2010-11-22 02:34:46 +02:00
|
|
|
detachFrom(const_cast<CCreature*>(type));
|
2012-08-24 12:37:52 +03:00
|
|
|
if (type->isMyUpgrade(c) && VLC->modh->modules.STACK_EXP)
|
2011-12-14 00:23:17 +03:00
|
|
|
experience *= VLC->creh->expAfterUpgrade / 100.0;
|
2011-02-12 20:48:11 +02:00
|
|
|
}
|
2010-11-22 02:34:46 +02:00
|
|
|
|
2010-11-27 03:46:19 +02:00
|
|
|
type = c;
|
2011-05-29 17:06:52 +03:00
|
|
|
if(type)
|
|
|
|
attachTo(const_cast<CCreature*>(type));
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
2013-06-17 18:45:55 +03:00
|
|
|
std::string CStackInstance::bonusToString(const Bonus *bonus, bool description) const
|
2011-02-01 20:10:43 +02:00
|
|
|
{
|
2013-03-06 21:49:56 +03:00
|
|
|
if(Bonus::MAGIC_RESISTANCE == bonus->type)
|
2011-02-01 20:10:43 +02:00
|
|
|
{
|
2013-03-06 21:49:56 +03:00
|
|
|
return "";
|
2011-02-01 20:10:43 +02:00
|
|
|
}
|
|
|
|
else
|
2013-03-06 21:49:56 +03:00
|
|
|
{
|
|
|
|
return VLC->getBth()->bonusToString(bonus, this, description);
|
|
|
|
}
|
|
|
|
|
2011-02-01 20:10:43 +02:00
|
|
|
}
|
2010-05-02 21:20:26 +03:00
|
|
|
|
2013-06-17 18:45:55 +03:00
|
|
|
std::string CStackInstance::bonusToGraphics(const 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
|
|
|
}
|
|
|
|
|
2010-11-22 02:34:46 +02:00
|
|
|
void CStackInstance::setArmyObj(const CArmedInstance *ArmyObj)
|
|
|
|
{
|
2010-11-27 03:46:19 +02:00
|
|
|
if(_armyObj)
|
|
|
|
detachFrom(const_cast<CArmedInstance*>(_armyObj));
|
2010-11-22 02:34:46 +02:00
|
|
|
|
2010-12-06 01:10:02 +02:00
|
|
|
_armyObj = ArmyObj;
|
2010-11-27 03:46:19 +02:00
|
|
|
if(ArmyObj)
|
|
|
|
{
|
|
|
|
attachTo(const_cast<CArmedInstance*>(_armyObj));
|
|
|
|
}
|
2010-11-22 02:34:46 +02:00
|
|
|
}
|
2010-07-16 09:18:41 +03:00
|
|
|
|
2010-07-31 03:26:34 +03:00
|
|
|
std::string CStackInstance::getQuantityTXT(bool capitalized /*= true*/) const
|
|
|
|
{
|
2012-06-13 16:04:06 +03:00
|
|
|
int quantity = getQuantityID();
|
|
|
|
|
|
|
|
if (quantity)
|
|
|
|
return VLC->generaltexth->arraytxt[174 + quantity*3 - 1 - capitalized];
|
|
|
|
else
|
|
|
|
return "";
|
2010-11-22 02:34:46 +02:00
|
|
|
}
|
|
|
|
|
2010-11-27 03:46:19 +02:00
|
|
|
bool CStackInstance::valid(bool allowUnrandomized) const
|
|
|
|
{
|
|
|
|
bool isRand = (idRand != -1);
|
|
|
|
if(!isRand)
|
|
|
|
{
|
|
|
|
return (type && type == VLC->creh->creatures[type->idNumber]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return allowUnrandomized;
|
|
|
|
}
|
|
|
|
|
2010-12-06 01:10:02 +02:00
|
|
|
CStackInstance::~CStackInstance()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
oss << type->namePl;
|
2014-02-09 15:10:02 +03:00
|
|
|
else if(idRand >= 0)
|
2010-12-12 01:11:26 +02:00
|
|
|
oss << "[no type, idRand=" << idRand << "]";
|
|
|
|
else
|
|
|
|
oss << "[UNDEFINED TYPE]";
|
|
|
|
|
|
|
|
return oss.str();
|
|
|
|
}
|
|
|
|
|
2011-02-04 16:58:14 +02:00
|
|
|
void CStackInstance::deserializationFix()
|
|
|
|
{
|
2011-02-22 11:47:25 +02:00
|
|
|
const CCreature *backup = type;
|
2013-06-26 14:18:27 +03:00
|
|
|
type = nullptr;
|
2012-04-23 22:56:37 +03:00
|
|
|
setType(backup);
|
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)
|
|
|
|
return type->idNumber;
|
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
|
|
|
|
{
|
|
|
|
return (count > 1) ? type->namePl : type->nameSing;
|
|
|
|
}
|
|
|
|
|
2012-01-03 04:55:26 +03:00
|
|
|
ui64 CStackInstance::getPower() const
|
|
|
|
{
|
|
|
|
assert(type);
|
|
|
|
return type->AIValue * count;
|
|
|
|
}
|
|
|
|
|
2013-02-07 20:34:50 +03:00
|
|
|
ArtBearer::ArtBearer CStackInstance::bearerType() const
|
2012-04-14 05:20:22 +03:00
|
|
|
{
|
|
|
|
return ArtBearer::CREATURE;
|
|
|
|
}
|
|
|
|
|
2012-04-22 20:38:36 +03:00
|
|
|
CCommanderInstance::CCommanderInstance()
|
|
|
|
{
|
|
|
|
init();
|
2012-04-28 14:41:20 +03:00
|
|
|
name = "Unnamed";
|
2012-04-22 20:38:36 +03:00
|
|
|
}
|
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
CCommanderInstance::CCommanderInstance (CreatureID id)
|
2012-04-22 20:38:36 +03:00
|
|
|
{
|
|
|
|
init();
|
2012-04-28 14:41:20 +03:00
|
|
|
setType(id);
|
2012-04-22 20:38:36 +03:00
|
|
|
name = "Commando"; //TODO - parse them
|
|
|
|
}
|
|
|
|
|
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;
|
2012-04-22 20:38:36 +03:00
|
|
|
idRand = -1;
|
2013-06-26 14:18:27 +03:00
|
|
|
_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
|
|
|
}
|
|
|
|
|
|
|
|
CCommanderInstance::~CCommanderInstance()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2012-07-16 19:18:02 +03:00
|
|
|
getBonusList().remove_if (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++;
|
2013-06-29 16:05:48 +03:00
|
|
|
for (auto bonus : VLC->creh->commanderLevelPremy)
|
2012-05-07 15:54:22 +03:00
|
|
|
{ //grant all regular level-up bonuses
|
|
|
|
accumulateBonus (*bonus);
|
|
|
|
}
|
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
|
|
|
|
{
|
|
|
|
return experience >= VLC->heroh->reqExp(level+1);
|
|
|
|
}
|
|
|
|
|
2010-11-22 02:34:46 +02:00
|
|
|
CStackBasicDescriptor::CStackBasicDescriptor()
|
|
|
|
{
|
2013-06-26 14:18:27 +03:00
|
|
|
type = nullptr;
|
2010-11-22 02:34:46 +02:00
|
|
|
count = -1;
|
|
|
|
}
|
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
CStackBasicDescriptor::CStackBasicDescriptor(CreatureID id, TQuantity Count)
|
2010-11-22 02:34:46 +02:00
|
|
|
: type (VLC->creh->creatures[id]), count(Count)
|
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
DLL_LINKAGE std::ostream & operator<<(std::ostream & str, const CStackInstance & sth)
|
2010-11-27 03:46:19 +02:00
|
|
|
{
|
|
|
|
if(!sth.valid(true))
|
|
|
|
str << "an invalid stack!";
|
|
|
|
|
|
|
|
str << "stack with " << sth.count << " of ";
|
|
|
|
if(sth.type)
|
|
|
|
str << sth.type->namePl;
|
|
|
|
else
|
|
|
|
str << sth.idRand;
|
|
|
|
|
|
|
|
return str;
|
2011-01-28 04:11:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSimpleArmy::clear()
|
|
|
|
{
|
|
|
|
army.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
CSimpleArmy::operator bool() const
|
|
|
|
{
|
|
|
|
return army.size();
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
army[slot] = CStackBasicDescriptor(cre, count);
|
|
|
|
return true;
|
2011-02-06 19:26:27 +02:00
|
|
|
}
|