1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

Correct handling of merging & moving stacks with experience.

This commit is contained in:
DjWarmonger
2011-03-27 09:31:14 +00:00
parent caf50fc278
commit 15d80d040f
3 changed files with 46 additions and 7 deletions

View File

@@ -86,6 +86,16 @@ int CCreatureSet::getStackCount(TSlot slot) const
return 0; //TODO? consider issuing a warning
}
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
}
bool CCreatureSet::mergableStacks(std::pair<TSlot, TSlot> &out, TSlot preferable /*= -1*/) const /*looks for two same stacks, returns slot positions */
{
//try to match creature to our preferred stack
@@ -218,8 +228,8 @@ void CCreatureSet::setStackCount(TSlot slot, TQuantity count)
{
assert(hasStackAtSlot(slot));
assert(count > 0);
if (STACK_EXP)
stacks[slot]->experience *= ((stacks[slot]->count + count)/(float)stacks[slot]->count);
if (STACK_EXP && count > stacks[slot]->count)
stacks[slot]->experience *= (count/(float)stacks[slot]->count);
stacks[slot]->count = count;
armyChanged();
}
@@ -229,6 +239,11 @@ void CCreatureSet::giveStackExp(expType exp)
for(TSlots::const_iterator i = stacks.begin(); i != stacks.end(); i++)
i->second->giveStackExp(exp);
}
void CCreatureSet::setStackExp(TSlot slot, expType exp)
{
assert(hasStackAtSlot(slot));
stacks[slot]->experience = exp;
}
void CCreatureSet::clear()
{