2010-04-02 05:23:22 +03:00
|
|
|
#define VCMI_DLL
|
|
|
|
#include "CCreatureSet.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "CCreatureHandler.h"
|
2010-04-02 05:23:22 +03:00
|
|
|
#include "VCMI_Lib.h"
|
|
|
|
#include <assert.h>
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "CObjectHandler.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"
|
2010-12-12 01:11:26 +02:00
|
|
|
#include <sstream>
|
2011-02-06 10:32:05 +02:00
|
|
|
#include "CSpellHandler.h"
|
2011-02-02 20:49:48 +02:00
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
2010-04-02 05:23:22 +03:00
|
|
|
|
2010-11-22 02:34:46 +02:00
|
|
|
const CStackInstance &CCreatureSet::operator[](TSlot slot) const
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2011-01-21 04:36:30 +02:00
|
|
|
TSlots::const_iterator i = stacks.find(slot);
|
|
|
|
if (i != stacks.end())
|
2010-11-22 02:34:46 +02:00
|
|
|
return *i->second;
|
2010-04-02 05:23:22 +03:00
|
|
|
else
|
|
|
|
throw std::string("That slot is empty!");
|
|
|
|
}
|
|
|
|
|
2010-11-27 03:46:19 +02:00
|
|
|
const CCreature* CCreatureSet::getCreature(TSlot slot) const
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2011-01-21 04:36:30 +02:00
|
|
|
TSlots::const_iterator i = stacks.find(slot);
|
|
|
|
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
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCreatureSet::setCreature(TSlot slot, TCreature type, TQuantity quantity) /*slots 0 to 6 */
|
|
|
|
{
|
2010-11-22 02:34:46 +02:00
|
|
|
if(slot > 6 || slot < 0)
|
|
|
|
{
|
|
|
|
tlog1 << "Cannot set slot " << slot << std::endl;
|
2010-04-02 05:23:22 +03:00
|
|
|
return false;
|
2010-11-22 02:34:46 +02:00
|
|
|
}
|
|
|
|
if(!quantity)
|
|
|
|
{
|
|
|
|
tlog2 << "Using set creature to delete stack?\n";
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
TSlot CCreatureSet::getSlotFor(TCreature creature, ui32 slotsAmount/*=7*/) const /*returns -1 if no slot available */
|
|
|
|
{
|
2010-11-27 22:17:28 +02:00
|
|
|
return getSlotFor(VLC->creh->creatures[creature], slotsAmount);
|
|
|
|
}
|
|
|
|
|
|
|
|
TSlot CCreatureSet::getSlotFor(const CCreature *c, ui32 slotsAmount/*=ARMY_SIZE*/) const
|
|
|
|
{
|
|
|
|
assert(c->valid());
|
2011-01-21 04:36:30 +02:00
|
|
|
for(TSlots::const_iterator i=stacks.begin(); i!=stacks.end(); ++i)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2010-11-27 22:17:28 +02:00
|
|
|
assert(i->second->type->valid());
|
|
|
|
if(i->second->type == c)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
|
|
|
return i->first; //if there is already such creature we return its slot id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(ui32 i=0; i<slotsAmount; i++)
|
|
|
|
{
|
2011-01-21 04:36:30 +02:00
|
|
|
if(stacks.find(i) == stacks.end())
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
|
|
|
return i; //return first free slot
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1; //no slot available
|
|
|
|
}
|
|
|
|
|
2011-04-10 11:33:53 +03:00
|
|
|
TSlot CCreatureSet::getFreeSlot(ui32 slotsAmount/*=ARMY_SIZE*/) const
|
|
|
|
{
|
|
|
|
for (ui32 i = 0; i < slotsAmount; i++)
|
|
|
|
{
|
|
|
|
if(stacks.find(i) == stacks.end())
|
|
|
|
{
|
|
|
|
return i; //return first free slot
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1; //no slot available
|
|
|
|
}
|
|
|
|
|
2010-11-27 03:46:19 +02:00
|
|
|
int CCreatureSet::getStackCount(TSlot slot) const
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2011-01-21 04:36:30 +02:00
|
|
|
TSlots::const_iterator i = stacks.find(slot);
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2011-03-27 12:31:14 +03:00
|
|
|
expType CCreatureSet::getStackExperience(TSlot slot) const
|
|
|
|
{
|
|
|
|
TSlots::const_iterator i = stacks.find(slot);
|
|
|
|
if (i != stacks.end())
|
|
|
|
return i->second->experience;
|
|
|
|
else
|
|
|
|
return 0; //TODO? consider issuing a warning
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-02 21:20:26 +03:00
|
|
|
bool CCreatureSet::mergableStacks(std::pair<TSlot, TSlot> &out, TSlot 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
|
2011-01-21 04:36:30 +02:00
|
|
|
if(preferable >= 0 && 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;
|
|
|
|
for(TSlots::const_iterator j=stacks.begin(); j!=stacks.end(); ++j)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2010-11-22 02:34:46 +02:00
|
|
|
if(cr == j->second->type && j->first != preferable)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
|
|
|
out.first = preferable;
|
|
|
|
out.second = j->first;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-21 04:36:30 +02:00
|
|
|
for(TSlots::const_iterator i=stacks.begin(); i!=stacks.end(); ++i)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2011-01-21 04:36:30 +02:00
|
|
|
for(TSlots::const_iterator j=stacks.begin(); j!=stacks.end(); ++j)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2010-11-22 02:34:46 +02:00
|
|
|
if(i->second->type == j->second->type && i->first != j->first)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
|
|
|
out.first = i->first;
|
|
|
|
out.second = j->first;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureSet::sweep()
|
|
|
|
{
|
2011-01-21 04:36:30 +02:00
|
|
|
for(TSlots::iterator 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-02 21:20:26 +03:00
|
|
|
void CCreatureSet::addToSlot(TSlot slot, TCreature 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
|
|
|
|
{
|
|
|
|
tlog1 << "Failed adding to slot!\n";
|
2010-11-22 02:34:46 +02:00
|
|
|
}
|
2010-04-02 05:23:22 +03:00
|
|
|
}
|
|
|
|
|
2010-11-22 02:34:46 +02:00
|
|
|
void CCreatureSet::addToSlot(TSlot 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
|
|
|
|
{
|
2010-11-27 03:46:19 +02:00
|
|
|
tlog1 << "Cannot add to slot " << slot << " stack " << *stack << std::endl;
|
2010-11-22 02:34:46 +02:00
|
|
|
}
|
2010-04-02 05:23:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CCreatureSet::validTypes(bool allowUnrandomized /*= false*/) const
|
|
|
|
{
|
2011-01-21 04:36:30 +02:00
|
|
|
for(TSlots::const_iterator i=stacks.begin(); i!=stacks.end(); ++i)
|
2010-04-02 05:23:22 +03:00
|
|
|
{
|
2010-11-27 03:46:19 +02:00
|
|
|
if(!i->second->valid(allowUnrandomized))
|
|
|
|
return false;
|
2010-04-02 05:23:22 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-02 21:20:26 +03:00
|
|
|
bool CCreatureSet::slotEmpty(TSlot slot) const
|
|
|
|
{
|
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;
|
2011-01-21 04:36:30 +02:00
|
|
|
for(TSlots::const_iterator i = stacks.begin(); i != stacks.end(); i++)
|
2010-11-22 02:34:46 +02:00
|
|
|
ret += i->second->type->AIValue * i->second->count;
|
2010-05-02 21:20:26 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui64 CCreatureSet::getPower (TSlot slot) const
|
|
|
|
{
|
2010-11-27 03:46:19 +02:00
|
|
|
return getCreature(slot)->AIValue * getStackCount(slot);
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
|
|
|
std::string CCreatureSet::getRoughAmount (TSlot slot) const
|
|
|
|
{
|
2010-11-27 03:46:19 +02:00
|
|
|
return VLC->generaltexth->arraytxt[174 + 3*CCreature::getQuantityID(getStackCount(slot))];
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureSet::setStackCount(TSlot slot, TQuantity count)
|
|
|
|
{
|
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);
|
2011-03-27 12:31:14 +03:00
|
|
|
if (STACK_EXP && count > stacks[slot]->count)
|
|
|
|
stacks[slot]->experience *= (count/(float)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
|
|
|
}
|
|
|
|
|
2011-02-12 20:48:11 +02:00
|
|
|
void CCreatureSet::giveStackExp(expType exp)
|
|
|
|
{
|
|
|
|
for(TSlots::const_iterator i = stacks.begin(); i != stacks.end(); i++)
|
|
|
|
i->second->giveStackExp(exp);
|
|
|
|
}
|
2011-03-27 12:31:14 +03:00
|
|
|
void CCreatureSet::setStackExp(TSlot slot, expType exp)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
const CStackInstance& CCreatureSet::getStack(TSlot slot) const
|
|
|
|
{
|
2011-02-04 16:58:14 +02:00
|
|
|
assert(hasStackAtSlot(slot));
|
2011-06-20 14:41:04 +03:00
|
|
|
return *getStackPtr(slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
const CStackInstance* CCreatureSet::getStackPtr(TSlot slot) const
|
|
|
|
{
|
|
|
|
if(hasStackAtSlot(slot))
|
|
|
|
return stacks.find(slot)->second;
|
|
|
|
else return NULL;
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureSet::eraseStack(TSlot slot)
|
|
|
|
{
|
2011-02-04 16:58:14 +02:00
|
|
|
assert(hasStackAtSlot(slot));
|
|
|
|
CStackInstance *toErase = detachStack(slot);
|
|
|
|
delNull(toErase);
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CCreatureSet::contains(const CStackInstance *stack) const
|
|
|
|
{
|
|
|
|
if(!stack)
|
|
|
|
return false;
|
|
|
|
|
2011-01-21 04:36:30 +02:00
|
|
|
for(TSlots::const_iterator i = stacks.begin(); i != stacks.end(); ++i)
|
2010-11-22 02:34:46 +02:00
|
|
|
if(i->second == stack)
|
2010-05-02 21:20:26 +03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-20 19:36:02 +02:00
|
|
|
TSlot CCreatureSet::findStack(const CStackInstance *stack) const
|
|
|
|
{
|
|
|
|
if(!stack)
|
|
|
|
return -1;
|
|
|
|
|
2011-01-21 04:36:30 +02:00
|
|
|
for(TSlots::const_iterator i = stacks.begin(); i != stacks.end(); ++i)
|
2010-11-22 02:34:46 +02:00
|
|
|
if(i->second == stack)
|
2010-11-20 19:36:02 +02:00
|
|
|
return i->first;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-11-22 02:34:46 +02:00
|
|
|
CArmedInstance * CCreatureSet::castToArmyObj()
|
|
|
|
{
|
|
|
|
return dynamic_cast<CArmedInstance *>(this);
|
|
|
|
}
|
|
|
|
|
2010-11-27 03:46:19 +02:00
|
|
|
void CCreatureSet::putStack(TSlot slot, CStackInstance *stack)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureSet::joinStack(TSlot slot, CStackInstance * stack)
|
|
|
|
{
|
|
|
|
const CCreature *c = getCreature(slot);
|
|
|
|
assert(c == stack->type);
|
|
|
|
assert(c);
|
|
|
|
|
|
|
|
//TODO move stuff
|
|
|
|
changeStackCount(slot, stack->count);
|
|
|
|
delNull(stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureSet::changeStackCount(TSlot slot, TQuantity toAdd)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2011-01-28 04:11:58 +02:00
|
|
|
TSimpleSlots::iterator 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CStackInstance * CCreatureSet::detachStack(TSlot slot)
|
|
|
|
{
|
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())
|
2010-12-06 01:10:02 +02:00
|
|
|
{
|
|
|
|
ret->setArmyObj(NULL); //detaches from current armyobj
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(!ret->armyObj); //we failed detaching?
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureSet::setStackType(TSlot slot, const CCreature *type)
|
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
int freeSlots = stacksCount() - ARMY_SIZE;
|
|
|
|
std::set<const CCreature*> cresToAdd;
|
2011-01-21 04:36:30 +02:00
|
|
|
for(TSlots::const_iterator i = cs.stacks.begin(); i != cs.stacks.end(); i++)
|
2010-12-13 01:44:16 +02:00
|
|
|
{
|
|
|
|
TSlot dest = getSlotFor(i->second->type);
|
|
|
|
if(dest < 0 || hasStackAtSlot(dest))
|
|
|
|
cresToAdd.insert(i->second->type);
|
|
|
|
}
|
|
|
|
return cresToAdd.size() <= freeSlots;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-08 15:27:32 +02:00
|
|
|
CCreatureSet cres;
|
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
|
2011-01-21 04:36:30 +02:00
|
|
|
for(TSlots::const_iterator i = cs.stacks.begin(); i != cs.stacks.end(); i++)
|
2011-03-08 15:27:32 +02:00
|
|
|
cres.addToSlot(i->first, i->second->type->idNumber, 1, true);
|
|
|
|
TSlot j;
|
2011-01-21 04:36:30 +02:00
|
|
|
for(TSlots::const_iterator i = stacks.begin(); i != stacks.end(); i++)
|
2011-03-08 15:27:32 +02:00
|
|
|
{
|
|
|
|
if ((j = cres.getSlotFor(i->second->type)) >= 0)
|
|
|
|
cres.addToSlot(j, i->second->type->idNumber, 1, true); //merge if possible
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool CCreatureSet::hasStackAtSlot(TSlot slot) const
|
|
|
|
{
|
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();
|
|
|
|
}
|
|
|
|
|
2010-11-27 03:46:19 +02:00
|
|
|
CStackInstance::CStackInstance(TCreature id, TQuantity Count)
|
|
|
|
: 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;
|
|
|
|
type = NULL;
|
|
|
|
idRand = -1;
|
2010-11-27 03:46:19 +02:00
|
|
|
_armyObj = NULL;
|
2011-07-13 21:39:02 +03:00
|
|
|
setNodeType(STACK_INSTANCE);
|
2010-04-02 05:23:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int CStackInstance::getQuantityID() const
|
|
|
|
{
|
|
|
|
return CCreature::getQuantityID(count);
|
|
|
|
}
|
|
|
|
|
2011-02-11 10:20:26 +02:00
|
|
|
int CStackInstance::getExpRank() const
|
|
|
|
{
|
|
|
|
int tier = type->level;
|
2011-02-13 15:11:09 +02:00
|
|
|
if (iswith(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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
val += hero->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, CGHeroInstance::RESISTANCE);
|
|
|
|
}
|
|
|
|
amin (val, 100);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2011-02-12 20:48:11 +02:00
|
|
|
void CStackInstance::giveStackExp(expType exp)
|
|
|
|
{
|
|
|
|
int level = type->level;
|
|
|
|
if (!iswith(level, 1, 7))
|
|
|
|
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
|
|
|
|
2011-02-13 21:46:16 +02:00
|
|
|
amin(exp, (expType)maxExp); //prevent exp overflow due to different types
|
|
|
|
amin(exp, (maxExp * creh->maxExpPerBattle[level])/100);
|
|
|
|
amin(experience += exp, maxExp); //can't get more exp than this limit
|
2011-02-12 20:48:11 +02:00
|
|
|
}
|
|
|
|
|
2010-04-02 05:23:22 +03:00
|
|
|
void CStackInstance::setType(int 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
|
2011-05-28 08:09:06 +03:00
|
|
|
setType((const CCreature*)NULL);
|
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));
|
2011-02-12 20:48:11 +02:00
|
|
|
if (type->isMyUpgrade(c) && STACK_EXP)
|
|
|
|
experience *= VLC->creh->expAfterUpgrade / 100.0f;
|
|
|
|
}
|
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
|
|
|
}
|
2011-02-01 20:10:43 +02:00
|
|
|
std::string CStackInstance::bonusToString(Bonus *bonus, bool description) const
|
|
|
|
{
|
2011-02-06 19:26:27 +02:00
|
|
|
std::map<TBonusType, std::pair<std::string, std::string> >::iterator it = VLC->creh->stackBonuses.find(bonus->type);
|
2011-02-02 20:49:48 +02:00
|
|
|
if (it != VLC->creh->stackBonuses.end())
|
2011-02-01 20:10:43 +02:00
|
|
|
{
|
|
|
|
std::string text;
|
2011-02-02 20:49:48 +02:00
|
|
|
if (description) //long ability description
|
2011-02-01 20:10:43 +02:00
|
|
|
{
|
|
|
|
text = it->second.second;
|
|
|
|
switch (bonus->type)
|
|
|
|
{
|
|
|
|
//no additional modifiers needed
|
|
|
|
case Bonus::FLYING:
|
|
|
|
case Bonus::UNLIMITED_RETALIATIONS:
|
|
|
|
case Bonus::SHOOTER:
|
|
|
|
case Bonus::FREE_SHOOTING:
|
|
|
|
case Bonus::NO_MELEE_PENALTY:
|
|
|
|
case Bonus::NO_DISTANCE_PENALTY:
|
|
|
|
case Bonus::NO_OBSTACLES_PENALTY:
|
|
|
|
case Bonus::JOUSTING: //TODO: percent bonus?
|
|
|
|
case Bonus::RETURN_AFTER_STRIKE:
|
|
|
|
case Bonus::BLOCKS_RETALIATION:
|
|
|
|
case Bonus::TWO_HEX_ATTACK_BREATH:
|
|
|
|
case Bonus::THREE_HEADED_ATTACK:
|
|
|
|
case Bonus::ATTACKS_ALL_ADJACENT:
|
2011-03-06 14:12:22 +02:00
|
|
|
case Bonus::ADDITIONAL_ATTACK: //TODO: what with more than one attack? Axe of Ferocity for example
|
2011-02-01 20:10:43 +02:00
|
|
|
case Bonus::FULL_HP_REGENERATION:
|
2011-07-10 12:03:46 +03:00
|
|
|
case Bonus::REBIRTH:
|
2011-02-01 20:10:43 +02:00
|
|
|
case Bonus::LIFE_DRAIN: //TODO: chance, hp percentage?
|
|
|
|
case Bonus::SELF_MORALE:
|
|
|
|
case Bonus::SELF_LUCK:
|
|
|
|
case Bonus::FEAR:
|
|
|
|
case Bonus::FEARLESS:
|
|
|
|
case Bonus::CHARGE_IMMUNITY:
|
|
|
|
case Bonus::HEALER:
|
|
|
|
case Bonus::CATAPULT:
|
|
|
|
case Bonus::DRAGON_NATURE:
|
|
|
|
case Bonus::NON_LIVING:
|
|
|
|
case Bonus::UNDEAD:
|
2011-05-21 19:10:14 +03:00
|
|
|
case Bonus::FIRE_IMMUNITY: //TODO: what about direct, hostile and total immunity?
|
|
|
|
case Bonus::WATER_IMMUNITY:
|
|
|
|
case Bonus::AIR_IMMUNITY:
|
|
|
|
case Bonus::EARTH_IMMUNITY:
|
|
|
|
case Bonus::RECEPTIVE:
|
|
|
|
case Bonus::DIRECT_DAMAGE_IMMUNITY:
|
2011-02-01 20:10:43 +02:00
|
|
|
break;
|
2011-05-29 21:28:50 +03:00
|
|
|
//One numeric value. magic resistance handled separately
|
2011-03-06 14:12:22 +02:00
|
|
|
case Bonus::SPELL_RESISTANCE_AURA:
|
2011-02-02 20:49:48 +02:00
|
|
|
case Bonus::SPELL_DAMAGE_REDUCTION:
|
|
|
|
case Bonus::LEVEL_SPELL_IMMUNITY:
|
|
|
|
case Bonus::MANA_DRAIN:
|
|
|
|
case Bonus::HP_REGENERATION:
|
|
|
|
case Bonus::ADDITIONAL_RETALIATION:
|
2011-07-16 19:40:38 +03:00
|
|
|
case Bonus::DEFENSIVE_STANCE:
|
2011-02-02 20:49:48 +02:00
|
|
|
case Bonus::DOUBLE_DAMAGE_CHANCE:
|
|
|
|
case Bonus::DARKNESS: //Darkness Dragons any1?
|
2011-06-24 20:43:02 +03:00
|
|
|
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(valOfBonuses(Selector::typeSubtype(bonus->type, bonus->subtype))));
|
2011-02-02 20:49:48 +02:00
|
|
|
break;
|
|
|
|
//Complex descriptions
|
2011-06-18 13:58:46 +03:00
|
|
|
case Bonus::SECONDARY_SKILL_PREMY: //only if there's no simple MR
|
|
|
|
if (bonus->subtype == CGHeroInstance::RESISTANCE)
|
|
|
|
{
|
|
|
|
if (!hasBonusOfType(Bonus::MAGIC_RESISTANCE))
|
|
|
|
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>( magicResistance() ));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Bonus::MAGIC_RESISTANCE:
|
|
|
|
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>( magicResistance() ));
|
|
|
|
break;
|
2011-02-09 16:58:15 +02:00
|
|
|
case Bonus::HATE:
|
2011-06-24 20:43:02 +03:00
|
|
|
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(valOfBonuses(Selector::typeSubtype(bonus->type, bonus->subtype))));
|
2011-02-02 20:49:48 +02:00
|
|
|
boost::algorithm::replace_first(text, "%s", VLC->creh->creatures[bonus->subtype]->namePl);
|
|
|
|
break;
|
|
|
|
case Bonus::SPELL_AFTER_ATTACK:
|
2011-07-16 09:42:44 +03:00
|
|
|
case Bonus::SPELL_BEFORE_ATTACK:
|
2011-04-25 12:03:13 +03:00
|
|
|
{
|
2011-06-24 20:43:02 +03:00
|
|
|
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(valOfBonuses(Selector::typeSubtype(bonus->type, bonus->subtype))));
|
2011-02-06 10:32:05 +02:00
|
|
|
boost::algorithm::replace_first(text, "%s", VLC->spellh->spells[bonus->subtype]->name);
|
2011-02-02 20:49:48 +02:00
|
|
|
break;
|
2011-04-25 12:03:13 +03:00
|
|
|
}
|
2011-02-02 20:49:48 +02:00
|
|
|
default:
|
|
|
|
{}//TODO: allow custom bonus types... someday, somehow
|
2011-02-01 20:10:43 +02:00
|
|
|
}
|
|
|
|
}
|
2011-02-02 20:49:48 +02:00
|
|
|
else //short name
|
2011-02-01 20:10:43 +02:00
|
|
|
{
|
|
|
|
text = it->second.first;
|
2011-02-02 20:49:48 +02:00
|
|
|
switch (bonus->type)
|
|
|
|
{
|
2011-03-06 14:12:22 +02:00
|
|
|
case Bonus::MANA_CHANNELING:
|
|
|
|
case Bonus::MAGIC_MIRROR:
|
|
|
|
case Bonus::CHANGES_SPELL_COST_FOR_ALLY:
|
|
|
|
case Bonus::CHANGES_SPELL_COST_FOR_ENEMY:
|
|
|
|
case Bonus::ENEMY_DEFENCE_REDUCTION:
|
2011-07-10 12:03:46 +03:00
|
|
|
case Bonus::REBIRTH:
|
2011-04-23 20:10:54 +03:00
|
|
|
case Bonus::DEATH_STARE:
|
2011-06-24 20:43:02 +03:00
|
|
|
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(valOfBonuses(Selector::typeSubtype(bonus->type, bonus->subtype))));
|
2011-03-06 14:12:22 +02:00
|
|
|
break;
|
2011-02-02 20:49:48 +02:00
|
|
|
case Bonus::HATE:
|
|
|
|
boost::algorithm::replace_first(text, "%s", VLC->creh->creatures[bonus->subtype]->namePl);
|
|
|
|
break;
|
|
|
|
case Bonus::LEVEL_SPELL_IMMUNITY:
|
|
|
|
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(bonus->val));
|
|
|
|
break;
|
|
|
|
case Bonus::SPELL_AFTER_ATTACK:
|
2011-07-16 09:42:44 +03:00
|
|
|
case Bonus::SPELL_BEFORE_ATTACK:
|
2011-02-06 10:32:05 +02:00
|
|
|
boost::algorithm::replace_first(text, "%s", VLC->spellh->spells[bonus->subtype]->name);
|
2011-02-02 20:49:48 +02:00
|
|
|
break;
|
2011-03-06 16:22:54 +02:00
|
|
|
case Bonus::SPELL_IMMUNITY:
|
|
|
|
boost::algorithm::replace_first(text, "%s", VLC->spellh->spells[bonus->subtype]->name);
|
|
|
|
break;
|
2011-06-18 13:58:46 +03:00
|
|
|
case Bonus::SECONDARY_SKILL_PREMY:
|
|
|
|
if (bonus->subtype != CGHeroInstance::RESISTANCE || hasBonusOfType(Bonus::MAGIC_RESISTANCE)) //handle it there
|
|
|
|
text = "";
|
2011-05-29 21:28:50 +03:00
|
|
|
break;
|
2011-02-02 20:49:48 +02:00
|
|
|
}
|
2011-02-01 20:10:43 +02:00
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return "";
|
|
|
|
}
|
2010-05-02 21:20:26 +03:00
|
|
|
|
2011-03-20 10:45:05 +02:00
|
|
|
std::string CStackInstance::bonusToGraphics(Bonus *bonus) const
|
|
|
|
{
|
|
|
|
std::string fileName;
|
|
|
|
switch (bonus->type)
|
|
|
|
{
|
|
|
|
//"E_ALIVE.bmp"
|
|
|
|
//"E_ART.bmp"
|
|
|
|
//"E_BLESS.bmp"
|
|
|
|
//"E_BLOCK.bmp"
|
|
|
|
//"E_BLOCK1.bmp"
|
|
|
|
//"E_BLOCK2.bmp"
|
|
|
|
case Bonus::TWO_HEX_ATTACK_BREATH:
|
|
|
|
fileName = "E_BREATH.bmp"; break;
|
|
|
|
case Bonus::SPELL_AFTER_ATTACK:
|
|
|
|
fileName = "E_CAST.bmp"; break;
|
|
|
|
//"E_CAST1.bmp"
|
2011-07-16 09:42:44 +03:00
|
|
|
case Bonus::SPELL_BEFORE_ATTACK:
|
|
|
|
fileName ="E_CAST2.bmp"; break;
|
2011-03-20 10:45:05 +02:00
|
|
|
//"E_CASTER.bmp"
|
|
|
|
case Bonus::JOUSTING:
|
|
|
|
fileName = "E_CHAMP.bmp"; break;
|
|
|
|
case Bonus::DOUBLE_DAMAGE_CHANCE:
|
|
|
|
fileName = "E_DBLOW.bmp"; break;
|
2011-04-23 20:10:54 +03:00
|
|
|
case Bonus::DEATH_STARE:
|
|
|
|
fileName = "E_DEATH.bmp"; break;
|
2011-07-16 19:40:38 +03:00
|
|
|
case Bonus::DEFENSIVE_STANCE:
|
|
|
|
fileName = "E_DEFBON.bmp"; break;
|
2011-03-20 10:45:05 +02:00
|
|
|
case Bonus::NO_DISTANCE_PENALTY:
|
|
|
|
fileName = "E_DIST.bmp"; break;
|
|
|
|
case Bonus::ADDITIONAL_ATTACK:
|
|
|
|
fileName = "E_DOUBLE.bmp"; break;
|
|
|
|
case Bonus::DRAGON_NATURE:
|
|
|
|
fileName = "E_DRAGON.bmp"; break;
|
|
|
|
case Bonus::MAGIC_RESISTANCE:
|
|
|
|
fileName = "E_DWARF.bmp"; break;
|
2011-06-18 13:58:46 +03:00
|
|
|
case Bonus::SECONDARY_SKILL_PREMY:
|
2011-06-19 02:56:48 +03:00
|
|
|
if (bonus->subtype == CGHeroInstance::RESISTANCE)
|
2011-06-18 13:58:46 +03:00
|
|
|
{
|
|
|
|
fileName = "E_DWARF.bmp";
|
|
|
|
}
|
|
|
|
break;
|
2011-03-20 10:45:05 +02:00
|
|
|
case Bonus::FEAR:
|
|
|
|
fileName = "E_FEAR.bmp"; break;
|
|
|
|
case Bonus::FEARLESS:
|
|
|
|
fileName = "E_FEARL.bmp"; break;
|
|
|
|
case Bonus::FLYING:
|
|
|
|
fileName = "E_FLY.bmp"; break;
|
|
|
|
case Bonus::SPELL_DAMAGE_REDUCTION:
|
|
|
|
fileName = "E_GOLEM.bmp"; break;
|
|
|
|
case Bonus::RETURN_AFTER_STRIKE:
|
|
|
|
fileName = "E_HARPY.bmp"; break;
|
|
|
|
case Bonus::HATE:
|
|
|
|
fileName = "E_HATE.bmp"; break;
|
|
|
|
case Bonus::KING1:
|
|
|
|
fileName = "E_KING1.bmp"; break;
|
|
|
|
case Bonus::KING2:
|
|
|
|
fileName = "E_KING2.bmp"; break;
|
|
|
|
case Bonus::KING3:
|
|
|
|
fileName = "E_KING3.bmp"; break;
|
|
|
|
case Bonus::CHANGES_SPELL_COST_FOR_ALLY:
|
|
|
|
fileName = "E_MANA.bmp"; break;
|
|
|
|
case Bonus::NO_MELEE_PENALTY:
|
|
|
|
fileName = "E_MELEE.bmp"; break;
|
|
|
|
//"E_MIND.bmp"
|
|
|
|
case Bonus::SELF_MORALE:
|
|
|
|
fileName = "E_MINOT.bmp"; break;
|
|
|
|
case Bonus::NO_MORALE:
|
|
|
|
fileName = "E_MORAL.bmp"; break;
|
2011-05-21 19:10:14 +03:00
|
|
|
case Bonus::RECEPTIVE:
|
|
|
|
fileName = "E_NOFRIM.bmp"; break;
|
2011-03-20 10:45:05 +02:00
|
|
|
case Bonus::NO_OBSTACLES_PENALTY:
|
|
|
|
fileName = "E_OBST.bmp"; break;
|
|
|
|
case Bonus::ENEMY_DEFENCE_REDUCTION:
|
|
|
|
fileName = "E_RDEF.bmp"; break;
|
2011-07-10 12:03:46 +03:00
|
|
|
case Bonus::REBIRTH:
|
|
|
|
fileName = "E_REBIRTH.bmp"; break;
|
2011-03-20 10:45:05 +02:00
|
|
|
case Bonus::BLOCKS_RETALIATION:
|
|
|
|
fileName = "E_RETAIL.bmp"; break;
|
|
|
|
case Bonus::ADDITIONAL_RETALIATION:
|
|
|
|
fileName = "E_RETAIL1.bmp"; break;
|
|
|
|
case Bonus::ATTACKS_ALL_ADJACENT:
|
|
|
|
fileName = "E_ROUND.bmp"; break;
|
|
|
|
//"E_SGNUM.bmp"
|
|
|
|
//"E_SGTYPE.bmp"
|
|
|
|
case Bonus::SHOOTER:
|
|
|
|
fileName = "E_SHOOT.bmp"; break;
|
|
|
|
case Bonus::FREE_SHOOTING: //shooter is not blocked by enemy
|
|
|
|
fileName = "E_SHOOTA.bmp"; break;
|
|
|
|
//"E_SHOOTN.bmp"
|
|
|
|
case Bonus::SPELL_IMMUNITY:
|
|
|
|
{
|
|
|
|
switch (bonus->subtype)
|
|
|
|
{
|
2011-03-21 10:14:23 +02:00
|
|
|
case 62: //Blind
|
2011-03-20 10:45:05 +02:00
|
|
|
fileName = "E_SPBLIND.bmp"; break;
|
2011-05-28 08:34:40 +03:00
|
|
|
case 35: // Dispell
|
|
|
|
fileName = "E_SPDISP.bmp"; break;
|
|
|
|
case 78: // Dispell beneficial spells
|
|
|
|
fileName = "E_SPDISB.bmp"; break;
|
2011-03-20 10:45:05 +02:00
|
|
|
case 60: //Hypnotize
|
|
|
|
fileName = "E_SPHYPN.bmp"; break;
|
|
|
|
case 18: //Implosion
|
|
|
|
fileName = "E_SPIMP.bmp"; break;
|
|
|
|
case 59: //Berserk
|
|
|
|
fileName = "E_SPBERS.bmp"; break;
|
|
|
|
case 23: //Meteor Shower
|
|
|
|
fileName = "E_SPMET.bmp"; break;
|
|
|
|
case 26: //Armageddon
|
|
|
|
fileName = "E_SPARM.bmp"; break;
|
|
|
|
case 54: //Slow
|
|
|
|
fileName = "E_SPSLOW.bmp"; break;
|
|
|
|
//TODO: some generic spell handling?
|
|
|
|
}
|
2011-05-28 08:34:40 +03:00
|
|
|
break;
|
2011-03-20 10:45:05 +02:00
|
|
|
}
|
|
|
|
//"E_SPAWILL.bmp"
|
2011-05-21 19:10:14 +03:00
|
|
|
case Bonus::DIRECT_DAMAGE_IMMUNITY:
|
|
|
|
fileName = "E_SPDIR.bmp"; break;
|
2011-03-20 10:45:05 +02:00
|
|
|
//"E_SPDISB.bmp"
|
|
|
|
//"E_SPDISP.bmp"
|
|
|
|
//"E_SPEATH.bmp"
|
|
|
|
//"E_SPEATH1.bmp"
|
2011-05-21 19:10:14 +03:00
|
|
|
case Bonus::FIRE_IMMUNITY:
|
|
|
|
switch (bonus->subtype)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
fileName = "E_SPFIRE.bmp"; break; //all
|
|
|
|
case 1:
|
|
|
|
fileName = "E_SPFIRE1.bmp"; break; //not positive
|
|
|
|
case 2:
|
|
|
|
fileName = "E_FIRE.bmp"; break; //direct damage
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Bonus::WATER_IMMUNITY:
|
|
|
|
switch (bonus->subtype)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
fileName = "E_SPWATER.bmp"; break; //all
|
|
|
|
case 1:
|
|
|
|
fileName = "E_SPWATER1.bmp"; break; //not positive
|
|
|
|
case 2:
|
|
|
|
fileName = "E_SPCOLD.bmp"; break; //direct damage
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Bonus::AIR_IMMUNITY:
|
|
|
|
switch (bonus->subtype)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
fileName = "E_SPAIR.bmp"; break; //all
|
|
|
|
case 1:
|
|
|
|
fileName = "E_SPAIR1.bmp"; break; //not positive
|
|
|
|
case 2:
|
|
|
|
fileName = "E_LIGHT.bmp"; break;//direct damage
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Bonus::EARTH_IMMUNITY:
|
|
|
|
switch (bonus->subtype)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
fileName = "E_SPEATH.bmp"; break; //all
|
|
|
|
case 1:
|
|
|
|
case 2: //no specific icon for direct damage immunity
|
|
|
|
fileName = "E_SPEATH1.bmp"; break; //not positive
|
|
|
|
}
|
|
|
|
break;
|
2011-03-20 10:45:05 +02:00
|
|
|
case Bonus::LEVEL_SPELL_IMMUNITY:
|
|
|
|
{
|
|
|
|
if (iswith(bonus->val, 1 , 5))
|
|
|
|
{
|
|
|
|
fileName = "E_SPLVL" + boost::lexical_cast<std::string>(bonus->val) + ".bmp";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//"E_SPWATER.bmp"
|
|
|
|
//"E_SPWATER1.bmp"
|
|
|
|
//"E_SUMMON.bmp"
|
|
|
|
//"E_SUMMON1.bmp"
|
|
|
|
//"E_SUMMON2.bmp"
|
|
|
|
case Bonus::FULL_HP_REGENERATION:
|
|
|
|
fileName = "E_TROLL.bmp"; break;
|
|
|
|
case Bonus::UNDEAD:
|
|
|
|
fileName = "E_UNDEAD.bmp"; break;
|
|
|
|
case Bonus::SPELL_RESISTANCE_AURA:
|
|
|
|
fileName = "E_UNIC.bmp"; break;
|
|
|
|
}
|
2011-04-23 13:27:44 +03:00
|
|
|
if(!fileName.empty())
|
2011-09-14 08:27:49 +03:00
|
|
|
fileName = "zvs/Lib1.res/" + fileName;
|
2011-03-20 10:45:05 +02:00
|
|
|
return fileName;
|
|
|
|
}
|
|
|
|
|
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-11-13 22:26:15 +02:00
|
|
|
// void CStackInstance::getParents(TCNodes &out, const CBonusSystemNode *source /*= NULL*/) const
|
|
|
|
// {
|
|
|
|
// out.insert(type);
|
|
|
|
//
|
|
|
|
// if(source && source != this) //we should be root, if not - do not inherit anything
|
|
|
|
// return;
|
|
|
|
//
|
|
|
|
// if(armyObj)
|
|
|
|
// out.insert(armyObj);
|
|
|
|
// else
|
|
|
|
// out.insert(&IObjectInterface::cb->gameState()->globalEffects);
|
|
|
|
// }
|
2010-07-16 09:18:41 +03:00
|
|
|
|
2010-07-31 03:26:34 +03:00
|
|
|
std::string CStackInstance::getQuantityTXT(bool capitalized /*= true*/) const
|
|
|
|
{
|
|
|
|
return VLC->generaltexth->arraytxt[174 + getQuantityID()*3 + 2 - capitalized];
|
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;
|
|
|
|
else if(idRand)
|
|
|
|
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;
|
|
|
|
type = NULL;
|
|
|
|
setType(backup);
|
|
|
|
const CArmedInstance *armyBackup = _armyObj;
|
|
|
|
_armyObj = NULL;
|
|
|
|
setArmyObj(armyBackup);
|
2011-02-04 16:58:14 +02:00
|
|
|
}
|
|
|
|
|
2011-06-20 14:41:04 +03:00
|
|
|
int CStackInstance::getCreatureID() const
|
|
|
|
{
|
|
|
|
if(type)
|
|
|
|
return type->idNumber;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-11-22 02:34:46 +02:00
|
|
|
CStackBasicDescriptor::CStackBasicDescriptor()
|
|
|
|
{
|
|
|
|
type = NULL;
|
|
|
|
count = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CStackBasicDescriptor::CStackBasicDescriptor(TCreature id, TQuantity Count)
|
|
|
|
: 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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-27 03:46:19 +02:00
|
|
|
DLL_EXPORT std::ostream & operator<<(std::ostream & str, const CStackInstance & sth)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CSimpleArmy::setCreature(TSlot slot, TCreature cre, TQuantity count)
|
|
|
|
{
|
|
|
|
assert(!vstd::contains(army, slot));
|
|
|
|
army[slot] = CStackBasicDescriptor(cre, count);
|
|
|
|
return true;
|
2011-02-06 19:26:27 +02:00
|
|
|
}
|