1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

- Refactoring legacy code

- Some checks for #2311
This commit is contained in:
DjWarmonger 2015-10-24 15:09:46 +02:00
parent 86e1ae928e
commit abe88ea890
2 changed files with 19 additions and 14 deletions

View File

@ -468,6 +468,12 @@ static int getDir(int3 src, int3 dst)
void TryMoveHero::applyGs( CGameState *gs )
{
CGHeroInstance *h = gs->getHero(id);
if (!h)
{
logGlobal->errorStream() << "Attempt ot move unavailable hero " << id;
return;
}
h->movement = movePoints;
if((result == SUCCESS || result == BLOCKING_VISIT || result == EMBARK || result == DISEMBARK) && start != end)

View File

@ -4772,36 +4772,35 @@ void CGameHandler::checkVictoryLossConditionsForPlayer(PlayerColor player)
else
{
//player lost -> all his objects become unflagged (neutral)
auto hlp = p->heroes;
for (auto i = hlp.cbegin(); i != hlp.cend(); i++) //eliminate heroes
removeObject(*i);
for (auto h : p->heroes) //eliminate heroes
if (h.get())
removeObject(h);
for (auto i = gs->map->objects.cbegin(); i != gs->map->objects.cend(); i++) //unflag objs
for (auto obj : gs->map->objects) //unflag objs
{
if(*i && (*i)->tempOwner == player)
setOwner(*i,PlayerColor::NEUTRAL);
if(obj.get() && obj->tempOwner == player)
setOwner(obj, PlayerColor::NEUTRAL);
}
//eliminating one player may cause victory of another:
std::set<PlayerColor> playerColors;
for(int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i)
for (auto p : gs->players) //FIXME: players may have different colors, iterate by over players and not integers
{
if(player.getNum() != i) playerColors.insert(PlayerColor(i));
if (p.first != player)
playerColors.insert(p.first);
}
//notify all players
for (auto i = gs->players.cbegin(); i!=gs->players.cend(); i++)
for (auto pc : playerColors)
{
if(i->first != player && gs->getPlayer(i->first)->status == EPlayerStatus::INGAME)
if (gs->getPlayer(pc)->status == EPlayerStatus::INGAME)
{
InfoWindow iw;
getVictoryLossMessage(player, victoryLossCheckResult.invert(), iw);
iw.player = i->first;
iw.player = pc;
sendAndApply(&iw);
}
}
checkVictoryLossConditions(playerColors);
}