mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-23 00:28:08 +02:00
Stacks #5: giving creatures, practically finished (many fixes needed).
This commit is contained in:
@ -345,17 +345,32 @@ void CCreatureSet::setStackType(TSlot slot, const CCreature *type)
|
||||
s->setType(type->idNumber);
|
||||
}
|
||||
|
||||
bool CCreatureSet::canBeMergedWith(const CCreatureSet &cs) const
|
||||
bool CCreatureSet::canBeMergedWith(const CCreatureSet &cs, bool allowMergingStacks) const
|
||||
{
|
||||
std::set<const CCreature*> cres;
|
||||
if(!allowMergingStacks)
|
||||
{
|
||||
int freeSlots = stacksCount() - ARMY_SIZE;
|
||||
std::set<const CCreature*> cresToAdd;
|
||||
for(TSlots::const_iterator i = cs.slots.begin(); i != cs.slots.end(); i++)
|
||||
{
|
||||
TSlot dest = getSlotFor(i->second->type);
|
||||
if(dest < 0 || hasStackAtSlot(dest))
|
||||
cresToAdd.insert(i->second->type);
|
||||
}
|
||||
return cresToAdd.size() <= freeSlots;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::set<const CCreature*> cres;
|
||||
|
||||
//get types of creatures that need their own slot
|
||||
for(TSlots::const_iterator i = cs.slots.begin(); i != cs.slots.end(); i++)
|
||||
cres.insert(i->second->type);
|
||||
for(TSlots::const_iterator i = slots.begin(); i != slots.end(); i++)
|
||||
cres.insert(i->second->type);
|
||||
//get types of creatures that need their own slot
|
||||
for(TSlots::const_iterator i = cs.slots.begin(); i != cs.slots.end(); i++)
|
||||
cres.insert(i->second->type);
|
||||
for(TSlots::const_iterator i = slots.begin(); i != slots.end(); i++)
|
||||
cres.insert(i->second->type);
|
||||
|
||||
return cres.size() <= ARMY_SIZE;
|
||||
return cres.size() <= ARMY_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
bool CCreatureSet::hasStackAtSlot(TSlot slot) const
|
||||
|
@ -124,7 +124,7 @@ public:
|
||||
bool hasStackAtSlot(TSlot slot) const;
|
||||
|
||||
bool contains(const CStackInstance *stack) const;
|
||||
bool canBeMergedWith(const CCreatureSet &cs) const;
|
||||
bool canBeMergedWith(const CCreatureSet &cs, bool allowMergingStacks = true) const;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
|
@ -87,7 +87,7 @@ public:
|
||||
virtual void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb) =0; //cb will be called when player closes garrison window
|
||||
virtual void showThievesGuildWindow(int requestingObjId) =0;
|
||||
virtual void giveResource(int player, int which, int val)=0;
|
||||
virtual void giveCreatures (int objid, const CGHeroInstance * h, const CCreatureSet &creatures, bool remove) =0;
|
||||
virtual void giveCreatures (const CArmedInstance *objid, const CGHeroInstance * h, const CCreatureSet &creatures, bool remove) =0;
|
||||
//virtual void takeCreatures (int objid, TSlots creatures) =0;
|
||||
virtual void takeCreatures (int objid, std::vector<CStackBasicDescriptor> creatures) =0;
|
||||
virtual bool changeStackCount(const StackLocation &sl, TQuantity count, bool absoluteValue = false) =0;
|
||||
@ -96,7 +96,7 @@ public:
|
||||
virtual bool eraseStack(const StackLocation &sl, bool forceRemoval = false) =0;
|
||||
virtual bool swapStacks(const StackLocation &sl1, const StackLocation &sl2) =0;
|
||||
virtual bool addToSlot(const StackLocation &sl, const CCreature *c, TQuantity count) =0; //makes new stack or increases count of already existing
|
||||
virtual void tryJoiningArmy(const CArmedInstance *src, const CArmedInstance *dst, bool removeObjWhenFinished) =0; //merges army from src do dst or opens a garrison window
|
||||
virtual void tryJoiningArmy(const CArmedInstance *src, const CArmedInstance *dst, bool removeObjWhenFinished, bool allowMerging) =0; //merges army from src do dst or opens a garrison window
|
||||
virtual bool moveStack(const StackLocation &src, const StackLocation &dst, TQuantity count) = 0;
|
||||
virtual void showCompInfo(ShowInInfobox * comp)=0;
|
||||
virtual void heroVisitCastle(int obj, int heroID)=0;
|
||||
|
@ -1439,7 +1439,7 @@ void Mapa::readObjects( const unsigned char * bufor, int &i)
|
||||
CStackInstance *hlp = new CStackInstance();
|
||||
hlp->count = readNormalNr(bufor,i, 2); i+=2;
|
||||
//type will be set during initialization
|
||||
cre->slots[0] = hlp;
|
||||
cre->putStack(0, hlp);
|
||||
|
||||
cre->character = bufor[i]; ++i;
|
||||
bool isMesTre = bufor[i]; ++i; //true if there is message or treasury
|
||||
|
Reference in New Issue
Block a user