1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-15 01:24:45 +02:00

Neutral creatures are now correctly split into stacks & merged after a battle.

TODO: find relation to adventure map tile
This commit is contained in:
DjWarmonger
2011-04-14 07:58:19 +00:00
parent d6bd8514e7
commit 6a8e3f1b57
2 changed files with 36 additions and 4 deletions

View File

@ -2943,6 +2943,27 @@ void CGCreature::endBattle( BattleResult *result ) const
cb->setHoverName(id,&ms); cb->setHoverName(id,&ms);
cb->setObjProperty(id, 11, slots.begin()->second.count * 1000); cb->setObjProperty(id, 11, slots.begin()->second.count * 1000);
*/ */
//merge stacks into one
TSlots::const_iterator i;
CCreature * cre = VLC->creh->creatures[restore.basicType];
for (i = stacks.begin(); i != stacks.end(); i++)
{
if (cre->isMyUpgrade(i->second->type))
{
cb->changeStackType (StackLocation(this, i->first), cre); //un-upgrade creatures
}
}
while (stacks.size() > 1) //hopefully that's enough
{
i = stacks.end();
i--;
TSlot slot = getSlotFor(i->second->type);
if (slot == i->first) //no reason to move stack to its own slot
break;
else
cb->moveStack (StackLocation(this, i->first), StackLocation(this, slot), i->second->count);
}
} }
} }
@ -3005,6 +3026,9 @@ void CGCreature::setPropertyDer(ui8 what, ui32 val)
case 12: case 12:
giveStackExp(val); giveStackExp(val);
break; break;
case 13:
restore.basicType = val;
break;
} }
} }
@ -3134,6 +3158,7 @@ void CGCreature::fight( const CGHeroInstance *h ) const
//split stacks //split stacks
int totalCount; //TODO: multiple creature types in a stack? int totalCount; //TODO: multiple creature types in a stack?
int basicType = stacks.begin()->second->type->idNumber; int basicType = stacks.begin()->second->type->idNumber;
cb->setObjProperty(id, 13, basicType); //store info about creature stack
float relativePower = ((float)h->getTotalStrength() / getArmyStrength()); float relativePower = ((float)h->getTotalStrength() / getArmyStrength());
int stacksCount; int stacksCount;
@ -3182,7 +3207,7 @@ void CGCreature::fight( const CGHeroInstance *h ) const
} }
if (stacksCount > 1) if (stacksCount > 1)
{ {
if (rand()%100 > 50) //upgrade if (rand()%100 < 50) //upgrade
{ {
TSlot slotId = (stacks.size() / 2); TSlot slotId = (stacks.size() / 2);
if(ui32 upgradesSize = getStack(slotId).type->upgrades.size()) if(ui32 upgradesSize = getStack(slotId).type->upgrades.size())
@ -3196,8 +3221,6 @@ void CGCreature::fight( const CGHeroInstance *h ) const
cb->startBattleI(h, this, boost::bind(&CGCreature::endBattle,this,_1)); cb->startBattleI(h, this, boost::bind(&CGCreature::endBattle,this,_1));
//stacks.clear();
//stacks.insert(
} }
void CGCreature::flee( const CGHeroInstance * h ) const void CGCreature::flee( const CGHeroInstance * h ) const

View File

@ -728,10 +728,19 @@ public:
void setPropertyDer(ui8 what, ui32 val); void setPropertyDer(ui8 what, ui32 val);
int takenAction(const CGHeroInstance *h, bool allowJoin=true) const; //action on confrontation: -2 - fight, -1 - flee, >=0 - will join for given value of gold (may be 0) int takenAction(const CGHeroInstance *h, bool allowJoin=true) const; //action on confrontation: -2 - fight, -1 - flee, >=0 - will join for given value of gold (may be 0)
struct DLL_EXPORT RestoredCreature // info about merging stacks after battle back into one
{
si32 basicType;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & basicType;
}
} restore;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & static_cast<CArmedInstance&>(*this); h & static_cast<CArmedInstance&>(*this);
h & identifier & character & message & resources & gainedArtifact & neverFlees & notGrowingTeam & temppower; h & identifier & character & message & resources & gainedArtifact & neverFlees & notGrowingTeam & temppower & restore;
} }
}; };