mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
Remove unnecessary access to gamestate
This commit is contained in:
@@ -650,7 +650,7 @@ const CMapHeader * CGameInfoCallback::getMapHeader() const
|
||||
|
||||
bool CGameInfoCallback::hasAccess(std::optional<PlayerColor> playerId) const
|
||||
{
|
||||
return !getPlayerID() || getPlayerID()->isSpectator() || gameState().getPlayerRelations(*playerId, *getPlayerID()) != PlayerRelations::ENEMIES;
|
||||
return !getPlayerID() || getPlayerID()->isSpectator() || getPlayerRelations(*playerId, *getPlayerID()) != PlayerRelations::ENEMIES;
|
||||
}
|
||||
|
||||
EPlayerStatus CGameInfoCallback::getPlayerStatus(PlayerColor player, bool verbose) const
|
||||
|
||||
@@ -223,7 +223,7 @@ void CGDwelling::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstan
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerRelations relations = cb->gameState().getPlayerRelations( h->tempOwner, tempOwner );
|
||||
PlayerRelations relations = cb->getPlayerRelations( h->tempOwner, tempOwner );
|
||||
|
||||
if ( relations == PlayerRelations::ALLIES )
|
||||
return;//do not allow recruiting or capturing
|
||||
|
||||
@@ -370,7 +370,7 @@ TObjectTypeHandler CGHeroInstance::getObjectHandler() const
|
||||
void CGHeroInstance::updateAppearance()
|
||||
{
|
||||
auto handler = LIBRARY->objtypeh->getHandlerFor(Obj::HERO, getHeroClass()->getIndex());
|
||||
auto terrain = cb->gameState().getTile(visitablePos())->getTerrainID();
|
||||
auto terrain = cb->getTile(visitablePos())->getTerrainID();
|
||||
auto app = handler->getOverride(terrain, this);
|
||||
if (app)
|
||||
appearance = app;
|
||||
@@ -556,7 +556,7 @@ void CGHeroInstance::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroIn
|
||||
|
||||
if (ID == Obj::HERO)
|
||||
{
|
||||
if( cb->gameState().getPlayerRelations(tempOwner, h->tempOwner) != PlayerRelations::ENEMIES)
|
||||
if( cb->getPlayerRelations(tempOwner, h->tempOwner) != PlayerRelations::ENEMIES)
|
||||
{
|
||||
//exchange
|
||||
gameEvents.heroExchange(h->id, id);
|
||||
@@ -581,7 +581,7 @@ void CGHeroInstance::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroIn
|
||||
|
||||
ObjectInstanceID boatId;
|
||||
const auto boatPos = visitablePos();
|
||||
if (cb->gameState().getMap().getTile(boatPos).isWater())
|
||||
if (cb->getTile(boatPos)->isWater())
|
||||
{
|
||||
smp.val = movementPointsLimit(false);
|
||||
if (!inBoat())
|
||||
|
||||
@@ -123,19 +123,19 @@ void CGObjectInstance::setType(MapObjectID newID, MapObjectSubID newSubID)
|
||||
{
|
||||
auto position = visitablePos();
|
||||
auto oldOffset = appearance->getCornerOffset();
|
||||
auto &tile = cb->gameState().getMap().getTile(position);
|
||||
const auto * tile = cb->getTile(position);
|
||||
|
||||
//recalculate blockvis tiles - new appearance might have different blockmap than before
|
||||
cb->gameState().getMap().hideObject(this);
|
||||
auto handler = LIBRARY->objtypeh->getHandlerFor(newID, newSubID);
|
||||
|
||||
if(!handler->getTemplates(tile.getTerrainID()).empty())
|
||||
if(!handler->getTemplates(tile->getTerrainID()).empty())
|
||||
{
|
||||
appearance = handler->getTemplates(tile.getTerrainID())[0];
|
||||
appearance = handler->getTemplates(tile->getTerrainID())[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
logGlobal->warn("Object %d:%d at %s has no templates suitable for terrain %s", newID, newSubID, visitablePos().toString(), tile.getTerrain()->getNameTranslated());
|
||||
logGlobal->warn("Object %d:%d at %s has no templates suitable for terrain %s", newID, newSubID, visitablePos().toString(), tile->getTerrain()->getNameTranslated());
|
||||
appearance = handler->getTemplates()[0]; // get at least some appearance since alternative is crash
|
||||
}
|
||||
|
||||
|
||||
@@ -306,7 +306,7 @@ void CGTownInstance::setOwner(IGameEventCallback & gameEvents, const PlayerColor
|
||||
|
||||
void CGTownInstance::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
|
||||
{
|
||||
if(cb->gameState().getPlayerRelations( getOwner(), h->getOwner() ) == PlayerRelations::ENEMIES)
|
||||
if(cb->getPlayerRelations( getOwner(), h->getOwner() ) == PlayerRelations::ENEMIES)
|
||||
{
|
||||
if(armedGarrison() || getVisitingHero())
|
||||
{
|
||||
@@ -625,7 +625,7 @@ void CGTownInstance::removeCapitols(IGameEventCallback & gameEvents, const Playe
|
||||
{
|
||||
if (hasCapitol()) // search if there's an older capitol
|
||||
{
|
||||
PlayerState* state = cb->gameState().getPlayerState(owner); //get all towns owned by player
|
||||
const PlayerState* state = cb->getPlayerState(owner); //get all towns owned by player
|
||||
for (const auto & otherTown : state->getTowns())
|
||||
{
|
||||
if (otherTown != this && otherTown->hasCapitol())
|
||||
@@ -695,7 +695,7 @@ ObjectInstanceID CGTownInstance::getObjInstanceID() const
|
||||
|
||||
void CGTownInstance::updateAppearance()
|
||||
{
|
||||
auto terrain = cb->gameState().getTile(visitablePos())->getTerrainID();
|
||||
auto terrain = cb->getTile(visitablePos())->getTerrainID();
|
||||
//FIXME: not the best way to do this
|
||||
auto app = getObjectHandler()->getOverride(terrain, this);
|
||||
if (app)
|
||||
|
||||
@@ -76,7 +76,7 @@ bool CTeamVisited::wasVisited(const TeamID & team) const
|
||||
//CGMine
|
||||
void CGMine::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
|
||||
{
|
||||
auto relations = cb->gameState().getPlayerRelations(h->tempOwner, tempOwner);
|
||||
auto relations = cb->getPlayerRelations(h->tempOwner, tempOwner);
|
||||
|
||||
if(relations == PlayerRelations::SAME_PLAYER) //we're visiting our mine
|
||||
{
|
||||
@@ -878,7 +878,7 @@ std::vector<CreatureID> CGGarrison::providedCreatures() const
|
||||
|
||||
void CGGarrison::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
|
||||
{
|
||||
auto relations = cb->gameState().getPlayerRelations(h->tempOwner, tempOwner);
|
||||
auto relations = cb->getPlayerRelations(h->tempOwner, tempOwner);
|
||||
if (relations == PlayerRelations::ENEMIES && stacksCount() > 0) {
|
||||
//TODO: Find a way to apply magic garrison effects in battle.
|
||||
gameEvents.startBattle(h, this);
|
||||
@@ -1097,7 +1097,7 @@ const IObjectInterface * CGShipyard::getObject() const
|
||||
|
||||
void CGShipyard::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
|
||||
{
|
||||
if(cb->gameState().getPlayerRelations(tempOwner, h->tempOwner) == PlayerRelations::ENEMIES)
|
||||
if(cb->getPlayerRelations(tempOwner, h->tempOwner) == PlayerRelations::ENEMIES)
|
||||
gameEvents.setOwner(this, h->tempOwner);
|
||||
|
||||
if(shipyardStatus() != IBoatGenerator::GOOD)
|
||||
@@ -1149,7 +1149,7 @@ void CGObelisk::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstanc
|
||||
InfoWindow iw;
|
||||
iw.type = EInfoWindowMode::AUTO;
|
||||
iw.player = h->tempOwner;
|
||||
TeamState *ts = cb->gameState().getPlayerTeam(h->tempOwner);
|
||||
const TeamState *ts = cb->getPlayerTeam(h->tempOwner);
|
||||
assert(ts);
|
||||
TeamID team = ts->id;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user