1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Fix 2406 reset potentially available heroes

This commit is contained in:
Vadim Markovtsev 2016-01-28 22:48:51 +03:00
parent a7059fe681
commit 22fc4fd3e9
2 changed files with 38 additions and 0 deletions

View File

@ -1057,6 +1057,23 @@ DLL_LINKAGE void NewTurn::applyGs( CGameState *gs )
for(NewTurn::Hero h : heroes) //give mana/movement point
{
CGHeroInstance *hero = gs->getHero(h.id);
if(!hero)
{
// retreated or surrendered hero who has not been reset yet
for(auto& hp : gs->hpool.heroesPool)
{
if(hp.second->id == h.id)
{
hero = hp.second;
break;
}
}
}
if(!hero)
{
logGlobal->errorStream() << "Hero " << h.id << " not found in NewTurn::applyGs";
continue;
}
hero->movement = h.move;
hero->mana = h.mana;
}

View File

@ -1324,6 +1324,25 @@ void CGameHandler::newTurn()
std::map<ui32, ConstTransitivePtr<CGHeroInstance> > pool = gs->hpool.heroesPool;
for(auto& hp : pool)
{
auto hero = hp.second;
if(hero->isInitialized() && hero->stacks.size())
{
// reset retreated or surrendered heroes
auto maxmove = hero->maxMovePoints(true);
// if movement is greater than maxmove, we should decrease it
if(hero->movement != maxmove || hero->mana < hero->manaLimit())
{
NewTurn::Hero hth;
hth.id = hero->id;
hth.move = maxmove;
hth.mana = std::max((si32)(0), std::max(hero->mana, std::min((si32)(hero->mana + hero->manaRegain()), hero->manaLimit())));
n.heroes.insert(hth);
}
}
}
for (auto & elem : gs->players)
{
if(elem.first == PlayerColor::NEUTRAL)
@ -1351,7 +1370,9 @@ void CGameHandler::newTurn()
banned = h->type->heroClass;
}
else
{
sah.hid[j] = -1;
}
}
sendAndApply(&sah);