1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

CGameHandler refactoring: when possible only use const data

We only change gamestate via netpacks so there is absolutely no reason to use non-const pointers and functions in GH.
This commit is contained in:
Arseniy Shestakov 2016-09-18 11:53:51 +03:00
parent 635c48f889
commit 1d45d214e5

View File

@ -1356,7 +1356,7 @@ static bool evntCmp(const CMapEvent &a, const CMapEvent &b)
void CGameHandler::setPortalDwelling(const CGTownInstance * town, bool forced=false, bool clear = false) void CGameHandler::setPortalDwelling(const CGTownInstance * town, bool forced=false, bool clear = false)
{// bool forced = true - if creature should be replaced, if false - only if no creature was set {// bool forced = true - if creature should be replaced, if false - only if no creature was set
const PlayerState *p = gs->getPlayer(town->tempOwner); const PlayerState * p = getPlayer(town->tempOwner);
if(!p) if(!p)
{ {
logGlobal->warn("There is no player owner of town %s at %s", town->name, town->pos()); logGlobal->warn("There is no player owner of town %s at %s", town->name, town->pos());
@ -1626,7 +1626,7 @@ void CGameHandler::newTurn()
fw.mode = 1; fw.mode = 1;
fw.player = player; fw.player = player;
// find all hidden tiles // find all hidden tiles
const auto & fow = gs->getPlayerTeam(player)->fogOfWarMap; const auto & fow = getPlayerTeam(player)->fogOfWarMap;
for (size_t i=0; i<fow.size(); i++) for (size_t i=0; i<fow.size(); i++)
for (size_t j=0; j<fow.at(i).size(); j++) for (size_t j=0; j<fow.at(i).size(); j++)
for (size_t k=0; k<fow.at(i).at(j).size(); k++) for (size_t k=0; k<fow.at(i).at(j).size(); k++)
@ -1638,7 +1638,7 @@ void CGameHandler::newTurn()
} }
if (t->hasBonusOfType (Bonus::DARKNESS)) if (t->hasBonusOfType (Bonus::DARKNESS))
{ {
for (auto & player : gameState()->players) for(auto & player : gs->players)
{ {
if (getPlayerStatus(player.first) == EPlayerStatus::INGAME && if (getPlayerStatus(player.first) == EPlayerStatus::INGAME &&
getPlayerRelations(player.first, t->tempOwner) == PlayerRelations::ENEMIES) getPlayerRelations(player.first, t->tempOwner) == PlayerRelations::ENEMIES)
@ -1863,7 +1863,7 @@ void CGameHandler::setupBattle( int3 tile, const CArmedInstance *armies[2], cons
{ {
battleResult.set(nullptr); battleResult.set(nullptr);
const auto t = gs->getTile(tile); const auto t = getTile(tile);
ETerrainType terrain = t->terType; ETerrainType terrain = t->terType;
if(gs->map->isCoastalTile(tile)) //coastal tile is always ground if(gs->map->isCoastalTile(tile)) //coastal tile is always ground
terrain = ETerrainType::SAND; terrain = ETerrainType::SAND;
@ -1972,7 +1972,7 @@ bool CGameHandler::moveHero( ObjectInstanceID hid, int3 dst, ui8 teleporting, bo
return false; return false;
} }
const TerrainTile t = *gs->getTile(hmpos); const TerrainTile t = *getTile(hmpos);
const int3 guardPos = gs->guardingCreaturePosition(hmpos); const int3 guardPos = gs->guardingCreaturePosition(hmpos);
const bool embarking = !h->boat && !t.visitableObjects.empty() && t.visitableObjects.back()->ID == Obj::BOAT; const bool embarking = !h->boat && !t.visitableObjects.empty() && t.visitableObjects.back()->ID == Obj::BOAT;
@ -2181,7 +2181,7 @@ void CGameHandler::setOwner(const CGObjectInstance * obj, PlayerColor owner)
if (oldOwner < PlayerColor::PLAYER_LIMIT) //old owner is real player if (oldOwner < PlayerColor::PLAYER_LIMIT) //old owner is real player
{ {
if (gs->getPlayer(oldOwner)->towns.empty())//previous player lost last last town if(getPlayer(oldOwner)->towns.empty()) //previous player lost last last town
{ {
InfoWindow iw; InfoWindow iw;
iw.player = oldOwner; iw.player = oldOwner;
@ -2192,11 +2192,11 @@ void CGameHandler::setOwner(const CGObjectInstance * obj, PlayerColor owner)
} }
} }
const PlayerState * p = gs->getPlayer(owner); const PlayerState * p = getPlayer(owner);
if((obj->ID == Obj::CREATURE_GENERATOR1 || obj->ID == Obj::CREATURE_GENERATOR4 ) && p && p->dwellings.size()==1)//first dwelling captured if((obj->ID == Obj::CREATURE_GENERATOR1 || obj->ID == Obj::CREATURE_GENERATOR4 ) && p && p->dwellings.size()==1)//first dwelling captured
{ {
for(const CGTownInstance *t : gs->getPlayer(owner)->towns) for(const CGTownInstance * t : getPlayer(owner)->towns)
{ {
if (t->hasBuilt(BuildingID::PORTAL_OF_SUMMON, ETownType::DUNGEON)) if (t->hasBuilt(BuildingID::PORTAL_OF_SUMMON, ETownType::DUNGEON))
setPortalDwelling(t);//set initial creatures for all portals of summoning setPortalDwelling(t);//set initial creatures for all portals of summoning
@ -2226,7 +2226,7 @@ void CGameHandler::giveResource(PlayerColor player, Res::ERes which, int val) //
SetResource sr; SetResource sr;
sr.player = player; sr.player = player;
sr.resid = which; sr.resid = which;
sr.val = gs->players.find(player)->second.resources.at(which) + val; sr.val = getPlayer(player)->resources.at(which) + val;
sendAndApply(&sr); sendAndApply(&sr);
} }
@ -2505,7 +2505,7 @@ void CGameHandler::heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2)
{ {
auto h1 = getHero(hero1), h2 = getHero(hero2); auto h1 = getHero(hero1), h2 = getHero(hero2);
if( gameState()->getPlayerRelations(h1->getOwner(), h2->getOwner())) if(getPlayerRelations(h1->getOwner(), h2->getOwner()))
{ {
auto exchange = std::make_shared<CGarrisonDialogQuery>(h1, h2); auto exchange = std::make_shared<CGarrisonDialogQuery>(h1, h2);
ExchangeDialog hex; ExchangeDialog hex;
@ -2610,8 +2610,8 @@ void CGameHandler::close()
bool CGameHandler::arrangeStacks( ObjectInstanceID id1, ObjectInstanceID id2, ui8 what, SlotID p1, SlotID p2, si32 val, PlayerColor player ) bool CGameHandler::arrangeStacks( ObjectInstanceID id1, ObjectInstanceID id2, ui8 what, SlotID p1, SlotID p2, si32 val, PlayerColor player )
{ {
const CArmedInstance *s1 = static_cast<CArmedInstance*>(gs->getObjInstance(id1)), const CArmedInstance * s1 = static_cast<const CArmedInstance *>(getObjInstance(id1)),
*s2 = static_cast<CArmedInstance*>(gs->getObjInstance(id2)); * s2 = static_cast<const CArmedInstance *>(getObjInstance(id2));
const CCreatureSet &S1 = *s1, &S2 = *s2; const CCreatureSet &S1 = *s1, &S2 = *s2;
StackLocation sl1(s1, p1), sl2(s2, p2); StackLocation sl1(s1, p1), sl2(s2, p2);
if(!sl1.slot.validSlot() || !sl2.slot.validSlot()) if(!sl1.slot.validSlot() || !sl2.slot.validSlot())
@ -2727,7 +2727,7 @@ PlayerColor CGameHandler::getPlayerAt( CConnection *c ) const
bool CGameHandler::disbandCreature( ObjectInstanceID id, SlotID pos ) bool CGameHandler::disbandCreature( ObjectInstanceID id, SlotID pos )
{ {
CArmedInstance *s1 = static_cast<CArmedInstance*>(gs->getObjInstance(id)); const CArmedInstance * s1 = static_cast<const CArmedInstance *>(getObjInstance(id));
if(!vstd::contains(s1->stacks,pos)) if(!vstd::contains(s1->stacks,pos))
{ {
complain("Illegal call to disbandCreature - no such stack in army!"); complain("Illegal call to disbandCreature - no such stack in army!");
@ -2760,7 +2760,7 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID,
switch (requestedBuilding->mode) switch (requestedBuilding->mode)
{ {
case CBuilding::BUILD_NORMAL : case CBuilding::BUILD_NORMAL :
if (gs->canBuildStructure(t, requestedID) != EBuildingState::ALLOWED) if(canBuildStructure(t, requestedID) != EBuildingState::ALLOWED)
COMPLAIN_RET("Cannot build that building!"); COMPLAIN_RET("Cannot build that building!");
break; break;
@ -2877,7 +2877,7 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID,
{ {
SetResources sr; SetResources sr;
sr.player = t->tempOwner; sr.player = t->tempOwner;
sr.res = gs->getPlayer(t->tempOwner)->resources - requestedBuilding->resources; sr.res = getPlayer(t->tempOwner)->resources - requestedBuilding->resources;
sendAndApply(&sr); sendAndApply(&sr);
} }
@ -2935,7 +2935,7 @@ void CGameHandler::sendMessageToAll( const std::string &message )
bool CGameHandler::recruitCreatures(ObjectInstanceID objid, ObjectInstanceID dstid, CreatureID crid, ui32 cram, si32 fromLvl ) bool CGameHandler::recruitCreatures(ObjectInstanceID objid, ObjectInstanceID dstid, CreatureID crid, ui32 cram, si32 fromLvl )
{ {
const CGDwelling *dw = static_cast<const CGDwelling*>(gs->getObj(objid)); const CGDwelling * dw = static_cast<const CGDwelling *>(getObj(objid));
const CArmedInstance *dst = nullptr; const CArmedInstance *dst = nullptr;
const CCreature *c = VLC->creh->creatures.at(crid); const CCreature *c = VLC->creh->creatures.at(crid);
bool warMachine = c->hasBonusOfType(Bonus::SIEGE_WEAPON); bool warMachine = c->hasBonusOfType(Bonus::SIEGE_WEAPON);
@ -2970,7 +2970,7 @@ bool CGameHandler::recruitCreatures(ObjectInstanceID objid, ObjectInstanceID dst
SlotID slot = dst->getSlotFor(crid); SlotID slot = dst->getSlotFor(crid);
if( (!found && complain("Cannot recruit: no such creatures!")) if( (!found && complain("Cannot recruit: no such creatures!"))
|| (cram > VLC->creh->creatures.at(crid)->maxAmount(gs->getPlayer(dst->tempOwner)->resources) && complain("Cannot recruit: lack of resources!")) || (cram > VLC->creh->creatures.at(crid)->maxAmount(getPlayer(dst->tempOwner)->resources) && complain("Cannot recruit: lack of resources!"))
|| (cram<=0 && complain("Cannot recruit: cram <= 0!")) || (cram<=0 && complain("Cannot recruit: cram <= 0!"))
|| (!slot.validSlot() && !warMachine && complain("Cannot recruit: no available slot!"))) || (!slot.validSlot() && !warMachine && complain("Cannot recruit: no available slot!")))
{ {
@ -2980,7 +2980,7 @@ bool CGameHandler::recruitCreatures(ObjectInstanceID objid, ObjectInstanceID dst
//recruit //recruit
SetResources sr; SetResources sr;
sr.player = dst->tempOwner; sr.player = dst->tempOwner;
sr.res = gs->getPlayer(dst->tempOwner)->resources - (c->cost * cram); sr.res = getPlayer(dst->tempOwner)->resources - (c->cost * cram);
SetAvailableCreatures sac; SetAvailableCreatures sac;
sac.tid = objid; sac.tid = objid;
@ -3021,12 +3021,13 @@ bool CGameHandler::recruitCreatures(ObjectInstanceID objid, ObjectInstanceID dst
bool CGameHandler::upgradeCreature( ObjectInstanceID objid, SlotID pos, CreatureID upgID ) bool CGameHandler::upgradeCreature( ObjectInstanceID objid, SlotID pos, CreatureID upgID )
{ {
CArmedInstance *obj = static_cast<CArmedInstance*>(gs->getObjInstance(objid)); const CArmedInstance * obj = static_cast<const CArmedInstance *>(getObjInstance(objid));
if (!obj->hasStackAtSlot(pos)) if (!obj->hasStackAtSlot(pos))
{ {
COMPLAIN_RET("Cannot upgrade, no stack at slot " + boost::to_string(pos)); COMPLAIN_RET("Cannot upgrade, no stack at slot " + boost::to_string(pos));
} }
UpgradeInfo ui = gs->getUpgradeInfo(obj->getStack(pos)); UpgradeInfo ui;
getUpgradeInfo(obj, pos, ui);
PlayerColor player = obj->tempOwner; PlayerColor player = obj->tempOwner;
const PlayerState *p = getPlayer(player); const PlayerState *p = getPlayer(player);
int crQuantity = obj->stacks.at(pos)->count; int crQuantity = obj->stacks.at(pos)->count;
@ -3100,7 +3101,7 @@ void CGameHandler::moveArmy(const CArmedInstance *src, const CArmedInstance *dst
bool CGameHandler::garrisonSwap( ObjectInstanceID tid ) bool CGameHandler::garrisonSwap( ObjectInstanceID tid )
{ {
CGTownInstance *town = gs->getTown(tid); const CGTownInstance * town = getTown(tid);
if(!town->garrisonHero && town->visitingHero) //visiting => garrison, merge armies: town army => hero army if(!town->garrisonHero && town->visitingHero) //visiting => garrison, merge armies: town army => hero army
{ {
@ -3218,8 +3219,7 @@ bool CGameHandler::moveArtifact(const ArtifactLocation &al1, const ArtifactLocat
*/ */
bool CGameHandler::assembleArtifacts (ObjectInstanceID heroID, ArtifactPosition artifactSlot, bool assemble, ArtifactID assembleTo) bool CGameHandler::assembleArtifacts (ObjectInstanceID heroID, ArtifactPosition artifactSlot, bool assemble, ArtifactID assembleTo)
{ {
const CGHeroInstance * hero = getHero(heroID);
CGHeroInstance *hero = gs->getHero(heroID);
const CArtifactInstance *destArtifact = hero->getArt(artifactSlot); const CArtifactInstance *destArtifact = hero->getArt(artifactSlot);
if(!destArtifact) if(!destArtifact)
@ -3253,8 +3253,8 @@ bool CGameHandler::assembleArtifacts (ObjectInstanceID heroID, ArtifactPosition
bool CGameHandler::buyArtifact( ObjectInstanceID hid, ArtifactID aid ) bool CGameHandler::buyArtifact( ObjectInstanceID hid, ArtifactID aid )
{ {
CGHeroInstance *hero = gs->getHero(hid); const CGHeroInstance * hero = getHero(hid);
CGTownInstance *town = hero->visitedTown; const CGTownInstance * town = hero->visitedTown;
if(aid==ArtifactID::SPELLBOOK) if(aid==ArtifactID::SPELLBOOK)
{ {
if((!town->hasBuilt(BuildingID::MAGES_GUILD_1) && complain("Cannot buy a spellbook, no mage guild in the town!")) if((!town->hasBuilt(BuildingID::MAGES_GUILD_1) && complain("Cannot buy a spellbook, no mage guild in the town!"))
@ -3274,7 +3274,7 @@ bool CGameHandler::buyArtifact( ObjectInstanceID hid, ArtifactID aid )
int price = VLC->arth->artifacts[aid]->price; int price = VLC->arth->artifacts[aid]->price;
if(( hero->getArt(ArtifactPosition(9+aid)) && complain("Hero already has this machine!")) if(( hero->getArt(ArtifactPosition(9+aid)) && complain("Hero already has this machine!"))
|| (gs->getPlayer(hero->getOwner())->resources.at(Res::GOLD) < price && complain("Not enough gold!"))) || (getPlayer(hero->getOwner())->resources.at(Res::GOLD) < price && complain("Not enough gold!")))
{ {
return false; return false;
} }
@ -3399,8 +3399,8 @@ bool CGameHandler::buySecSkill( const IMarket *m, const CGHeroInstance *h, Secon
bool CGameHandler::tradeResources(const IMarket *market, ui32 val, PlayerColor player, ui32 id1, ui32 id2) bool CGameHandler::tradeResources(const IMarket *market, ui32 val, PlayerColor player, ui32 id1, ui32 id2)
{ {
int r1 = gs->getPlayer(player)->resources.at(id1), int r1 = getPlayer(player)->resources.at(id1),
r2 = gs->getPlayer(player)->resources.at(id2); r2 = getPlayer(player)->resources.at(id2);
vstd::amin(val, r1); //can't trade more resources than have vstd::amin(val, r1); //can't trade more resources than have
@ -3490,15 +3490,15 @@ bool CGameHandler::transformInUndead(const IMarket *market, const CGHeroInstance
bool CGameHandler::sendResources(ui32 val, PlayerColor player, Res::ERes r1, PlayerColor r2) bool CGameHandler::sendResources(ui32 val, PlayerColor player, Res::ERes r1, PlayerColor r2)
{ {
const PlayerState *p2 = gs->getPlayer(r2, false); const PlayerState *p2 = getPlayer(r2, false);
if(!p2 || p2->status != EPlayerStatus::INGAME) if(!p2 || p2->status != EPlayerStatus::INGAME)
{ {
complain("Dest player must be in game!"); complain("Dest player must be in game!");
return false; return false;
} }
si32 curRes1 = gs->getPlayer(player)->resources.at(r1), si32 curRes1 = getPlayer(player)->resources.at(r1),
curRes2 = gs->getPlayer(r2)->resources.at(r1); curRes2 = getPlayer(r2)->resources.at(r1);
val = std::min(si32(val),curRes1); val = std::min(si32(val),curRes1);
SetResource sr; SetResource sr;
@ -3533,8 +3533,8 @@ bool CGameHandler::setFormation(ObjectInstanceID hid, ui8 formation)
bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, PlayerColor player) bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, PlayerColor player)
{ {
const PlayerState *p = gs->getPlayer(player); const PlayerState * p = getPlayer(player);
const CGTownInstance *t = gs->getTown(obj->id); const CGTownInstance * t = getTown(obj->id);
//common preconditions //common preconditions
// if( (p->resources.at(Res::GOLD)<GOLD_NEEDED && complain("Not enough gold for buying hero!")) // if( (p->resources.at(Res::GOLD)<GOLD_NEEDED && complain("Not enough gold for buying hero!"))
@ -4218,7 +4218,7 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message
SetMana sm; SetMana sm;
GiveBonus giveBonus(GiveBonus::HERO); GiveBonus giveBonus(GiveBonus::HERO);
CGHeroInstance *h = gs->getHero(currObj); const CGHeroInstance * h = getHero(currObj);
if(!h && complain("Cannot realize cheat, no hero selected!")) return; if(!h && complain("Cannot realize cheat, no hero selected!")) return;
sm.hid = h->id; sm.hid = h->id;
@ -4244,13 +4244,13 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message
} }
else if (message == "vcmiarmenelos") //build all buildings in selected town else if (message == "vcmiarmenelos") //build all buildings in selected town
{ {
CGHeroInstance *hero = gs->getHero(currObj); const CGHeroInstance * hero = getHero(currObj);
CGTownInstance *town; const CGTownInstance * town;
if (hero) if (hero)
town = hero->visitedTown; town = hero->visitedTown;
else else
town = gs->getTown(currObj); town = getTown(currObj);
if (town) if (town)
{ {
@ -4267,7 +4267,7 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message
} }
else if(message == "vcmiainur") //gives 5 archangels into each slot else if(message == "vcmiainur") //gives 5 archangels into each slot
{ {
CGHeroInstance *hero = gs->getHero(currObj); const CGHeroInstance * hero = getHero(currObj);
const CCreature *archangel = VLC->creh->creatures.at(13); const CCreature *archangel = VLC->creh->creatures.at(13);
if(!hero) return; if(!hero) return;
@ -4277,7 +4277,7 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message
} }
else if(message == "vcmiangband") //gives 10 black knight into each slot else if(message == "vcmiangband") //gives 10 black knight into each slot
{ {
CGHeroInstance *hero = gs->getHero(currObj); const CGHeroInstance * hero = getHero(currObj);
const CCreature *blackKnight = VLC->creh->creatures.at(66); const CCreature *blackKnight = VLC->creh->creatures.at(66);
if(!hero) return; if(!hero) return;
@ -4287,7 +4287,7 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message
} }
else if(message == "vcmiglaurung") //gives 5000 crystal dragons into each slot else if(message == "vcmiglaurung") //gives 5000 crystal dragons into each slot
{ {
CGHeroInstance *hero = gs->getHero(currObj); const CGHeroInstance * hero = getHero(currObj);
const CCreature *crystalDragon = VLC->creh->creatures.at(133); const CCreature *crystalDragon = VLC->creh->creatures.at(133);
if(!hero) return; if(!hero) return;
@ -4297,7 +4297,7 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message
} }
else if(message == "vcminoldor") //all war machines else if(message == "vcminoldor") //all war machines
{ {
CGHeroInstance *hero = gs->getHero(currObj); const CGHeroInstance * hero = getHero(currObj);
if(!hero) return; if(!hero) return;
if(!hero->getArt(ArtifactPosition::MACH1)) if(!hero->getArt(ArtifactPosition::MACH1))
@ -4309,7 +4309,7 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message
} }
else if (message == "vcmiforgeofnoldorking") //hero gets all artifacts except war machines, spell scrolls and spell book else if (message == "vcmiforgeofnoldorking") //hero gets all artifacts except war machines, spell scrolls and spell book
{ {
CGHeroInstance *hero = gs->getHero(currObj); const CGHeroInstance *hero = gs->getHero(currObj);
if(!hero) return; if(!hero) return;
for (int g = 7; g < VLC->arth->artifacts.size(); ++g) //including artifacts from mods for (int g = 7; g < VLC->arth->artifacts.size(); ++g) //including artifacts from mods
giveHeroNewArtifact(hero, VLC->arth->artifacts[g], ArtifactPosition::PRE_FIRST); giveHeroNewArtifact(hero, VLC->arth->artifacts[g], ArtifactPosition::PRE_FIRST);
@ -4332,7 +4332,7 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message
{ {
SetResources sr; SetResources sr;
sr.player = player; sr.player = player;
sr.res = gs->getPlayer(player)->resources; sr.res = getPlayer(player)->resources;
for(int i=0;i<Res::GOLD;i++) for(int i=0;i<Res::GOLD;i++)
sr.res[i] += 100; sr.res[i] += 100;
sr.res[Res::GOLD] += 100000; //100k sr.res[Res::GOLD] += 100000; //100k
@ -4670,7 +4670,7 @@ void CGameHandler::handleTimeEvents()
{ {
auto color = PlayerColor(player); auto color = PlayerColor(player);
PlayerState *pinfo = gs->getPlayer(color, false); //do not output error if player does not exist const PlayerState * pinfo = getPlayer(color, false); //do not output error if player does not exist
if( pinfo //player exists if( pinfo //player exists
&& (ev.players & 1<<player) //event is enabled to this player && (ev.players & 1<<player) //event is enabled to this player
@ -4734,7 +4734,7 @@ void CGameHandler::handleTownEvents(CGTownInstance * town, NewTurn &n)
{ {
PlayerColor player = town->tempOwner; PlayerColor player = town->tempOwner;
CCastleEvent ev = town->events.front(); CCastleEvent ev = town->events.front();
PlayerState *pinfo = gs->getPlayer(player, false); const PlayerState * pinfo = getPlayer(player, false);
if( pinfo //player exists if( pinfo //player exists
&& (ev.players & 1<<player.getNum()) //event is enabled to this player && (ev.players & 1<<player.getNum()) //event is enabled to this player
@ -4945,7 +4945,7 @@ bool CGameHandler::buildBoat( ObjectInstanceID objid )
const PlayerColor playerID = obj->o->tempOwner; const PlayerColor playerID = obj->o->tempOwner;
TResources boatCost; TResources boatCost;
obj->getBoatCost(boatCost); obj->getBoatCost(boatCost);
TResources aviable = gs->getPlayer(playerID)->resources; TResources aviable = getPlayer(playerID)->resources;
if (!aviable.canAfford(boatCost)) if (!aviable.canAfford(boatCost))
{ {
@ -4990,7 +4990,7 @@ void CGameHandler::checkVictoryLossConditions(const std::set<PlayerColor> & play
{ {
for(auto playerColor : playerColors) for(auto playerColor : playerColors)
{ {
if(gs->getPlayer(playerColor, false)) if(getPlayer(playerColor, false))
checkVictoryLossConditionsForPlayer(playerColor); checkVictoryLossConditionsForPlayer(playerColor);
} }
} }
@ -5007,7 +5007,7 @@ void CGameHandler::checkVictoryLossConditionsForAll()
void CGameHandler::checkVictoryLossConditionsForPlayer(PlayerColor player) void CGameHandler::checkVictoryLossConditionsForPlayer(PlayerColor player)
{ {
const PlayerState *p = gs->getPlayer(player); const PlayerState * p = getPlayer(player);
if(p->status != EPlayerStatus::INGAME) return; if(p->status != EPlayerStatus::INGAME) return;
auto victoryLossCheckResult = gs->checkForVictoryAndLoss(player); auto victoryLossCheckResult = gs->checkForVictoryAndLoss(player);
@ -5028,10 +5028,10 @@ void CGameHandler::checkVictoryLossConditionsForPlayer(PlayerColor player)
//one player won -> all enemies lost //one player won -> all enemies lost
for (auto i = gs->players.cbegin(); i!=gs->players.cend(); i++) for (auto i = gs->players.cbegin(); i!=gs->players.cend(); i++)
{ {
if(i->first != player && gs->getPlayer(i->first)->status == EPlayerStatus::INGAME) if(i->first != player && getPlayer(i->first)->status == EPlayerStatus::INGAME)
{ {
peg.player = i->first; peg.player = i->first;
peg.victoryLossCheckResult = gameState()->getPlayerRelations(player, i->first) == PlayerRelations::ALLIES ? peg.victoryLossCheckResult = getPlayerRelations(player, i->first) == PlayerRelations::ALLIES ?
victoryLossCheckResult : victoryLossCheckResult.invert(); // ally of winner victoryLossCheckResult : victoryLossCheckResult.invert(); // ally of winner
InfoWindow iw; InfoWindow iw;
@ -5120,7 +5120,7 @@ void CGameHandler::checkVictoryLossConditionsForPlayer(PlayerColor player)
//notify all players //notify all players
for (auto pc : playerColors) for (auto pc : playerColors)
{ {
if (gs->getPlayer(pc)->status == EPlayerStatus::INGAME) if(getPlayer(pc)->status == EPlayerStatus::INGAME)
{ {
InfoWindow iw; InfoWindow iw;
getVictoryLossMessage(player, victoryLossCheckResult.invert(), iw); getVictoryLossMessage(player, victoryLossCheckResult.invert(), iw);
@ -5131,7 +5131,7 @@ void CGameHandler::checkVictoryLossConditionsForPlayer(PlayerColor player)
checkVictoryLossConditions(playerColors); checkVictoryLossConditions(playerColors);
} }
auto playerInfo = gs->getPlayer(gs->currentPlayer, false); auto playerInfo = getPlayer(gs->currentPlayer, false);
// If we are called before the actual game start, there might be no current player // If we are called before the actual game start, there might be no current player
if (playerInfo && playerInfo->status != EPlayerStatus::INGAME) if (playerInfo && playerInfo->status != EPlayerStatus::INGAME)
{ {
@ -6019,7 +6019,7 @@ void CGameHandler::changeFogOfWar(int3 center, ui32 radius, PlayerColor player,
if (hide) if (hide)
{ {
std::unordered_set<int3, ShashInt3> observedTiles; //do not hide tiles observed by heroes. May lead to disastrous AI problems std::unordered_set<int3, ShashInt3> observedTiles; //do not hide tiles observed by heroes. May lead to disastrous AI problems
auto p = gs->getPlayer(player); auto p = getPlayer(player);
for (auto h : p->heroes) for (auto h : p->heroes)
{ {
getTilesInRange(observedTiles, h->getSightCenter(), h->getSightRadius(), h->tempOwner, -1); getTilesInRange(observedTiles, h->getSightCenter(), h->getSightRadius(), h->tempOwner, -1);