|
|
@@ -53,22 +53,22 @@ int CGameInfoCallback::getResource(PlayerColor Player, GameResID which) const
|
|
|
|
|
|
const PlayerSettings * CGameInfoCallback::getPlayerSettings(PlayerColor color) const
|
|
|
{
|
|
|
- return &gs->getStartInfo()->getIthPlayersSettings(color);
|
|
|
+ return &gameState()->getStartInfo()->getIthPlayersSettings(color);
|
|
|
}
|
|
|
|
|
|
bool CGameInfoCallback::isAllowed(SpellID id) const
|
|
|
{
|
|
|
- return gs->getMap().allowedSpells.count(id) != 0;
|
|
|
+ return gameState()->getMap().allowedSpells.count(id) != 0;
|
|
|
}
|
|
|
|
|
|
bool CGameInfoCallback::isAllowed(ArtifactID id) const
|
|
|
{
|
|
|
- return gs->getMap().allowedArtifact.count(id) != 0;
|
|
|
+ return gameState()->getMap().allowedArtifact.count(id) != 0;
|
|
|
}
|
|
|
|
|
|
bool CGameInfoCallback::isAllowed(SecondarySkill id) const
|
|
|
{
|
|
|
- return gs->getMap().allowedAbilities.count(id) != 0;
|
|
|
+ return gameState()->getMap().allowedAbilities.count(id) != 0;
|
|
|
}
|
|
|
|
|
|
std::optional<PlayerColor> CGameInfoCallback::getPlayerID() const
|
|
|
@@ -89,8 +89,8 @@ const PlayerState * CGameInfoCallback::getPlayerState(PlayerColor color, bool ve
|
|
|
{
|
|
|
return nullptr;
|
|
|
}
|
|
|
- auto player = gs->players.find(color);
|
|
|
- if (player != gs->players.end())
|
|
|
+ auto player = gameState()->players.find(color);
|
|
|
+ if (player != gameState()->players.end())
|
|
|
{
|
|
|
if (hasAccess(color))
|
|
|
return &player->second;
|
|
|
@@ -116,8 +116,8 @@ TurnTimerInfo CGameInfoCallback::getPlayerTurnTime(PlayerColor color) const
|
|
|
return TurnTimerInfo{};
|
|
|
}
|
|
|
|
|
|
- auto player = gs->players.find(color);
|
|
|
- if(player != gs->players.end())
|
|
|
+ auto player = gameState()->players.find(color);
|
|
|
+ if(player != gameState()->players.end())
|
|
|
{
|
|
|
return player->second.turnTimer;
|
|
|
}
|
|
|
@@ -131,7 +131,7 @@ TurnTimerInfo CGameInfoCallback::getPlayerTurnTime(PlayerColor color) const
|
|
|
|
|
|
const CGObjectInstance* CGameInfoCallback::getObj(ObjectInstanceID objid, bool verbose) const
|
|
|
{
|
|
|
- const CGObjectInstance *ret = gs->getMap().getObject(objid);
|
|
|
+ const CGObjectInstance *ret = gameState()->getMap().getObject(objid);
|
|
|
if(!ret)
|
|
|
{
|
|
|
if(verbose)
|
|
|
@@ -177,29 +177,29 @@ const IMarket * CGameInfoCallback::getMarket(ObjectInstanceID objid) const
|
|
|
|
|
|
void CGameInfoCallback::fillUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo & out) const
|
|
|
{
|
|
|
- //std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
|
|
+ //std::shared_lock<std::shared_mutex> lock(*gameState()->mx);
|
|
|
ERROR_RET_IF(!canGetFullInfo(obj), "Cannot get info about not owned object!");
|
|
|
ERROR_RET_IF(!obj->hasStackAtSlot(stackPos), "There is no such stack!");
|
|
|
- gs->fillUpgradeInfo(obj, stackPos, out);
|
|
|
- //return gs->fillUpgradeInfo(obj->getStack(stackPos));
|
|
|
+ gameState()->fillUpgradeInfo(obj, stackPos, out);
|
|
|
+ //return gameState()->fillUpgradeInfo(obj->getStack(stackPos));
|
|
|
}
|
|
|
|
|
|
const StartInfo * CGameInfoCallback::getStartInfo() const
|
|
|
{
|
|
|
- return gs->getStartInfo();
|
|
|
+ return gameState()->getStartInfo();
|
|
|
}
|
|
|
|
|
|
const StartInfo * CGameInfoCallback::getInitialStartInfo() const
|
|
|
{
|
|
|
- return gs->getInitialStartInfo();
|
|
|
+ return gameState()->getInitialStartInfo();
|
|
|
}
|
|
|
|
|
|
int32_t CGameInfoCallback::getSpellCost(const spells::Spell * sp, const CGHeroInstance * caster) const
|
|
|
{
|
|
|
- //std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
|
|
+ //std::shared_lock<std::shared_mutex> lock(*gameState()->mx);
|
|
|
ERROR_RET_VAL_IF(!canGetFullInfo(caster), "Cannot get info about caster!", -1);
|
|
|
//if there is a battle
|
|
|
- auto casterBattle = gs->getBattle(caster->getOwner());
|
|
|
+ auto casterBattle = gameState()->getBattle(caster->getOwner());
|
|
|
|
|
|
if(casterBattle)
|
|
|
return casterBattle->battleGetSpellCost(sp, caster);
|
|
|
@@ -210,7 +210,7 @@ int32_t CGameInfoCallback::getSpellCost(const spells::Spell * sp, const CGHeroIn
|
|
|
|
|
|
int64_t CGameInfoCallback::estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const
|
|
|
{
|
|
|
- //std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
|
|
+ //std::shared_lock<std::shared_mutex> lock(*gameState()->mx);
|
|
|
|
|
|
ERROR_RET_VAL_IF(hero && !canGetFullInfo(hero), "Cannot get info about caster!", -1);
|
|
|
|
|
|
@@ -222,26 +222,26 @@ int64_t CGameInfoCallback::estimateSpellDamage(const CSpell * sp, const CGHeroIn
|
|
|
|
|
|
void CGameInfoCallback::getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj)
|
|
|
{
|
|
|
- //std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
|
|
+ //std::shared_lock<std::shared_mutex> lock(*gameState()->mx);
|
|
|
ERROR_RET_IF(!obj, "No guild object!");
|
|
|
ERROR_RET_IF(obj->ID == Obj::TOWN && !canGetFullInfo(obj), "Cannot get info about town guild object!");
|
|
|
//TODO: advmap object -> check if they're visited by our hero
|
|
|
|
|
|
if(obj->ID == Obj::TOWN || obj->ID == Obj::TAVERN)
|
|
|
{
|
|
|
- int taverns = gs->players[*getPlayerID()].valOfBonuses(BonusType::THIEVES_GUILD_ACCESS);
|
|
|
- gs->obtainPlayersStats(thi, taverns);
|
|
|
+ int taverns = gameState()->players[*getPlayerID()].valOfBonuses(BonusType::THIEVES_GUILD_ACCESS);
|
|
|
+ gameState()->obtainPlayersStats(thi, taverns);
|
|
|
}
|
|
|
else if(obj->ID == Obj::DEN_OF_THIEVES)
|
|
|
{
|
|
|
- gs->obtainPlayersStats(thi, 20);
|
|
|
+ gameState()->obtainPlayersStats(thi, 20);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int CGameInfoCallback::howManyTowns(PlayerColor Player) const
|
|
|
{
|
|
|
ERROR_RET_VAL_IF(!hasAccess(Player), "Access forbidden!", -1);
|
|
|
- return static_cast<int>(gs->players[Player].getTowns().size());
|
|
|
+ return static_cast<int>(gameState()->players.at(Player).getTowns().size());
|
|
|
}
|
|
|
|
|
|
bool CGameInfoCallback::getTownInfo(const CGObjectInstance * town, InfoAboutTown & dest, const CGObjectInstance * selectedObject) const
|
|
|
@@ -269,20 +269,20 @@ bool CGameInfoCallback::getTownInfo(const CGObjectInstance * town, InfoAboutTown
|
|
|
|
|
|
const IGameSettings & CGameInfoCallback::getSettings() const
|
|
|
{
|
|
|
- return gs->getSettings();
|
|
|
+ return gameState()->getSettings();
|
|
|
}
|
|
|
|
|
|
int3 CGameInfoCallback::guardingCreaturePosition (int3 pos) const //FIXME: redundant?
|
|
|
{
|
|
|
ERROR_RET_VAL_IF(!isVisible(pos), "Tile is not visible!", int3(-1,-1,-1));
|
|
|
- return gs->guardingCreaturePosition(pos);
|
|
|
+ return gameState()->guardingCreaturePosition(pos);
|
|
|
}
|
|
|
|
|
|
std::vector<const CGObjectInstance*> CGameInfoCallback::getGuardingCreatures (int3 pos) const
|
|
|
{
|
|
|
ERROR_RET_VAL_IF(!isVisible(pos), "Tile is not visible!", std::vector<const CGObjectInstance*>());
|
|
|
std::vector<const CGObjectInstance*> ret;
|
|
|
- for(auto * cr : gs->guardingCreatures(pos))
|
|
|
+ for(auto * cr : gameState()->guardingCreatures(pos))
|
|
|
{
|
|
|
ret.push_back(cr);
|
|
|
}
|
|
|
@@ -291,7 +291,7 @@ std::vector<const CGObjectInstance*> CGameInfoCallback::getGuardingCreatures (in
|
|
|
|
|
|
bool CGameInfoCallback::isTileGuardedUnchecked(int3 tile) const
|
|
|
{
|
|
|
- return !gs->guardingCreatures(tile).empty();
|
|
|
+ return !gameState()->guardingCreatures(tile).empty();
|
|
|
}
|
|
|
|
|
|
bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero & dest, const CGObjectInstance * selectedObject) const
|
|
|
@@ -307,7 +307,7 @@ bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero
|
|
|
|
|
|
if (infoLevel == InfoAboutHero::EInfoLevel::BASIC)
|
|
|
{
|
|
|
- auto ourBattle = gs->getBattle(*getPlayerID());
|
|
|
+ auto ourBattle = gameState()->getBattle(*getPlayerID());
|
|
|
|
|
|
if(ourBattle && ourBattle->playerHasAccessToHeroInfo(*getPlayerID(), h)) //if it's battle we can get enemy hero full data
|
|
|
infoLevel = InfoAboutHero::EInfoLevel::INBATTLE;
|
|
|
@@ -412,14 +412,14 @@ bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero
|
|
|
|
|
|
int CGameInfoCallback::getDate(Date mode) const
|
|
|
{
|
|
|
- //std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
|
|
- return gs->getDate(mode);
|
|
|
+ //std::shared_lock<std::shared_mutex> lock(*gameState()->mx);
|
|
|
+ return gameState()->getDate(mode);
|
|
|
}
|
|
|
|
|
|
bool CGameInfoCallback::isVisible(int3 pos, const std::optional<PlayerColor> & Player) const
|
|
|
{
|
|
|
- //std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
|
|
- return gs->isVisible(pos, Player);
|
|
|
+ //std::shared_lock<std::shared_mutex> lock(*gameState()->mx);
|
|
|
+ return gameState()->isVisible(pos, Player);
|
|
|
}
|
|
|
|
|
|
bool CGameInfoCallback::isVisible(int3 pos) const
|
|
|
@@ -429,7 +429,7 @@ bool CGameInfoCallback::isVisible(int3 pos) const
|
|
|
|
|
|
bool CGameInfoCallback::isVisible(const CGObjectInstance * obj, const std::optional<PlayerColor> & Player) const
|
|
|
{
|
|
|
- return gs->isVisible(obj, Player);
|
|
|
+ return gameState()->isVisible(obj, Player);
|
|
|
}
|
|
|
|
|
|
bool CGameInfoCallback::isVisible(const CGObjectInstance *obj) const
|
|
|
@@ -438,7 +438,7 @@ bool CGameInfoCallback::isVisible(const CGObjectInstance *obj) const
|
|
|
}
|
|
|
// const CCreatureSet* CInfoCallback::getGarrison(const CGObjectInstance *obj) const
|
|
|
// {
|
|
|
-// //std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
|
|
+// //std::shared_lock<std::shared_mutex> lock(*gameState()->mx);
|
|
|
// if()
|
|
|
// const CArmedInstance *armi = dynamic_cast<const CArmedInstance*>(obj);
|
|
|
// if(!armi)
|
|
|
@@ -477,7 +477,7 @@ std::vector <const CGObjectInstance *> CGameInfoCallback::getVisitableObjs(int3
|
|
|
std::vector<const CGObjectInstance *> CGameInfoCallback::getAllVisitableObjs() const
|
|
|
{
|
|
|
std::vector<const CGObjectInstance *> ret;
|
|
|
- for(auto & obj : gs->getMap().getObjects())
|
|
|
+ for(auto & obj : gameState()->getMap().getObjects())
|
|
|
if(obj->isVisitable() && obj->ID != Obj::EVENT && isVisible(obj))
|
|
|
ret.push_back(obj);
|
|
|
|
|
|
@@ -505,7 +505,7 @@ std::vector <const CGObjectInstance *> CGameInfoCallback::getFlaggableObjects(in
|
|
|
|
|
|
int3 CGameInfoCallback::getMapSize() const
|
|
|
{
|
|
|
- return int3(gs->getMap().width, gs->getMap().height, gs->getMap().twoLevel ? 2 : 1);
|
|
|
+ return int3(gameState()->getMap().width, gameState()->getMap().height, gameState()->getMap().twoLevel ? 2 : 1);
|
|
|
}
|
|
|
|
|
|
std::vector<const CGHeroInstance *> CGameInfoCallback::getAvailableHeroes(const CGObjectInstance * townOrTavern) const
|
|
|
@@ -517,7 +517,7 @@ std::vector<const CGHeroInstance *> CGameInfoCallback::getAvailableHeroes(const
|
|
|
const CGTownInstance * town = getTown(townOrTavern->id);
|
|
|
|
|
|
if(townOrTavern->ID == Obj::TAVERN || (town && town->hasBuilt(BuildingID::TAVERN)))
|
|
|
- return gs->heroesPool->getHeroesFor(*getPlayerID());
|
|
|
+ return gameState()->heroesPool->getHeroesFor(*getPlayerID());
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
|
@@ -525,7 +525,7 @@ std::vector<const CGHeroInstance *> CGameInfoCallback::getAvailableHeroes(const
|
|
|
const TerrainTile * CGameInfoCallback::getTile(int3 tile, bool verbose) const
|
|
|
{
|
|
|
if(isVisible(tile))
|
|
|
- return &gs->getMap().getTile(tile);
|
|
|
+ return &gameState()->getMap().getTile(tile);
|
|
|
|
|
|
if(verbose)
|
|
|
logGlobal->error("\r\n%s: %s\r\n", BOOST_CURRENT_FUNCTION, tile.toString() + " is not visible!");
|
|
|
@@ -535,7 +535,7 @@ const TerrainTile * CGameInfoCallback::getTile(int3 tile, bool verbose) const
|
|
|
const TerrainTile * CGameInfoCallback::getTileUnchecked(int3 tile) const
|
|
|
{
|
|
|
if (isInTheMap(tile))
|
|
|
- return &gs->getMap().getTile(tile);
|
|
|
+ return &gameState()->getMap().getTile(tile);
|
|
|
|
|
|
return nullptr;
|
|
|
}
|
|
|
@@ -545,7 +545,7 @@ EDiggingStatus CGameInfoCallback::getTileDigStatus(int3 tile, bool verbose) cons
|
|
|
if(!isVisible(tile))
|
|
|
return EDiggingStatus::UNKNOWN;
|
|
|
|
|
|
- for(const auto & object : gs->getMap().getObjects())
|
|
|
+ for(const auto & object : gameState()->getMap().getObjects())
|
|
|
{
|
|
|
if(object->ID == Obj::HOLE && object->anchorPos() == tile)
|
|
|
return EDiggingStatus::TILE_OCCUPIED;
|
|
|
@@ -553,32 +553,6 @@ EDiggingStatus CGameInfoCallback::getTileDigStatus(int3 tile, bool verbose) cons
|
|
|
return getTile(tile)->getDiggingStatus();
|
|
|
}
|
|
|
|
|
|
-//TODO: typedef?
|
|
|
-std::shared_ptr<const boost::multi_array<TerrainTile*, 3>> CGameInfoCallback::getAllVisibleTiles() const
|
|
|
-{
|
|
|
- assert(getPlayerID().has_value());
|
|
|
- const auto * team = getPlayerTeam(getPlayerID().value());
|
|
|
-
|
|
|
- size_t width = gs->getMap().width;
|
|
|
- size_t height = gs->getMap().height;
|
|
|
- size_t levels = gs->getMap().levels();
|
|
|
-
|
|
|
- auto * ptr = new boost::multi_array<TerrainTile *, 3>(boost::extents[levels][width][height]);
|
|
|
-
|
|
|
- int3 tile;
|
|
|
- for(tile.z = 0; tile.z < levels; tile.z++)
|
|
|
- for(tile.x = 0; tile.x < width; tile.x++)
|
|
|
- for(tile.y = 0; tile.y < height; tile.y++)
|
|
|
- {
|
|
|
- if (team->fogOfWarMap[tile.z][tile.x][tile.y])
|
|
|
- (*ptr)[tile.z][tile.x][tile.y] = &gs->getMap().getTile(tile);
|
|
|
- else
|
|
|
- (*ptr)[tile.z][tile.x][tile.y] = nullptr;
|
|
|
- }
|
|
|
-
|
|
|
- return std::shared_ptr<const boost::multi_array<TerrainTile*, 3>>(ptr);
|
|
|
-}
|
|
|
-
|
|
|
EBuildingState CGameInfoCallback::canBuildStructure( const CGTownInstance *t, BuildingID ID )
|
|
|
{
|
|
|
ERROR_RET_VAL_IF(!canGetFullInfo(t), "Town is not owned!", EBuildingState::TOWN_NOT_OWNED);
|
|
|
@@ -650,17 +624,17 @@ EBuildingState CGameInfoCallback::canBuildStructure( const CGTownInstance *t, Bu
|
|
|
|
|
|
const CMapHeader * CGameInfoCallback::getMapHeader() const
|
|
|
{
|
|
|
- return &gs->getMap();
|
|
|
+ return &gameState()->getMap();
|
|
|
}
|
|
|
|
|
|
bool CGameInfoCallback::hasAccess(std::optional<PlayerColor> playerId) const
|
|
|
{
|
|
|
- return !getPlayerID() || getPlayerID()->isSpectator() || gs->getPlayerRelations(*playerId, *getPlayerID()) != PlayerRelations::ENEMIES;
|
|
|
+ return !getPlayerID() || getPlayerID()->isSpectator() || gameState()->getPlayerRelations(*playerId, *getPlayerID()) != PlayerRelations::ENEMIES;
|
|
|
}
|
|
|
|
|
|
EPlayerStatus CGameInfoCallback::getPlayerStatus(PlayerColor player, bool verbose) const
|
|
|
{
|
|
|
- const PlayerState *ps = gs->getPlayerState(player, verbose);
|
|
|
+ const PlayerState *ps = gameState()->getPlayerState(player, verbose);
|
|
|
ERROR_VERBOSE_OR_NOT_RET_VAL_IF(!ps, verbose, "No such player!", EPlayerStatus::WRONG);
|
|
|
|
|
|
return ps->status;
|
|
|
@@ -672,11 +646,11 @@ std::string CGameInfoCallback::getTavernRumor(const CGObjectInstance * townOrTav
|
|
|
text.appendLocalString(EMetaText::GENERAL_TXT, 216);
|
|
|
|
|
|
std::string extraText;
|
|
|
- if(gs->currentRumor.type == RumorState::TYPE_NONE)
|
|
|
+ if(gameState()->currentRumor.type == RumorState::TYPE_NONE)
|
|
|
return text.toString();
|
|
|
|
|
|
- auto rumor = gs->currentRumor.last[gs->currentRumor.type];
|
|
|
- switch(gs->currentRumor.type)
|
|
|
+ auto rumor = gameState()->currentRumor.last.at(gameState()->currentRumor.type);
|
|
|
+ switch(gameState()->currentRumor.type)
|
|
|
{
|
|
|
case RumorState::TYPE_SPECIAL:
|
|
|
text.replaceLocalString(EMetaText::GENERAL_TXT, rumor.first);
|
|
|
@@ -687,7 +661,7 @@ std::string CGameInfoCallback::getTavernRumor(const CGObjectInstance * townOrTav
|
|
|
|
|
|
break;
|
|
|
case RumorState::TYPE_MAP:
|
|
|
- text.replaceRawString(gs->getMap().rumors[rumor.first].text.toString());
|
|
|
+ text.replaceRawString(gameState()->getMap().rumors[rumor.first].text.toString());
|
|
|
break;
|
|
|
|
|
|
case RumorState::TYPE_RAND:
|
|
|
@@ -700,7 +674,7 @@ std::string CGameInfoCallback::getTavernRumor(const CGObjectInstance * townOrTav
|
|
|
|
|
|
PlayerRelations CGameInfoCallback::getPlayerRelations( PlayerColor color1, PlayerColor color2 ) const
|
|
|
{
|
|
|
- return gs->getPlayerRelations(color1, color2);
|
|
|
+ return gameState()->getPlayerRelations(color1, color2);
|
|
|
}
|
|
|
|
|
|
bool CGameInfoCallback::canGetFullInfo(const CGObjectInstance *obj) const
|
|
|
@@ -711,7 +685,7 @@ bool CGameInfoCallback::canGetFullInfo(const CGObjectInstance *obj) const
|
|
|
int CGameInfoCallback::getHeroCount( PlayerColor player, bool includeGarrisoned ) const
|
|
|
{
|
|
|
int ret = 0;
|
|
|
- const PlayerState *p = gs->getPlayerState(player);
|
|
|
+ const PlayerState *p = gameState()->getPlayerState(player);
|
|
|
ERROR_RET_VAL_IF(!p, "No such player!", -1);
|
|
|
|
|
|
if(includeGarrisoned)
|
|
|
@@ -736,31 +710,21 @@ bool CGameInfoCallback::isOwnedOrVisited(const CGObjectInstance *obj) const
|
|
|
|
|
|
bool CGameInfoCallback::isPlayerMakingTurn(PlayerColor player) const
|
|
|
{
|
|
|
- return gs->actingPlayers.count(player);
|
|
|
-}
|
|
|
-
|
|
|
-CGameInfoCallback::CGameInfoCallback():
|
|
|
- gs(nullptr)
|
|
|
-{
|
|
|
-}
|
|
|
-
|
|
|
-CGameInfoCallback::CGameInfoCallback(CGameState * GS):
|
|
|
- gs(GS)
|
|
|
-{
|
|
|
+ return gameState()->actingPlayers.count(player);
|
|
|
}
|
|
|
|
|
|
int CPlayerSpecificInfoCallback::howManyTowns() const
|
|
|
{
|
|
|
- //std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
|
|
+ //std::shared_lock<std::shared_mutex> lock(*gameState()->mx);
|
|
|
ERROR_RET_VAL_IF(!getPlayerID(), "Applicable only for player callbacks", -1);
|
|
|
return CGameInfoCallback::howManyTowns(*getPlayerID());
|
|
|
}
|
|
|
|
|
|
std::vector < const CGTownInstance *> CPlayerSpecificInfoCallback::getTownsInfo(bool onlyOur) const
|
|
|
{
|
|
|
- //std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
|
|
+ //std::shared_lock<std::shared_mutex> lock(*gameState()->mx);
|
|
|
auto ret = std::vector < const CGTownInstance *>();
|
|
|
- for(const auto & i : gs->players)
|
|
|
+ for(const auto & i : gameState()->players)
|
|
|
{
|
|
|
for(const auto & town : i.second.getTowns())
|
|
|
{
|
|
|
@@ -769,12 +733,12 @@ std::vector < const CGTownInstance *> CPlayerSpecificInfoCallback::getTownsInfo(
|
|
|
ret.push_back(town);
|
|
|
}
|
|
|
}
|
|
|
- } // for ( std::map<int, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
|
|
|
+ } // for ( std::map<int, PlayerState>::iterator i=gameState()->players.begin() ; i!=gameState()->players.end();i++)
|
|
|
return ret;
|
|
|
}
|
|
|
std::vector < const CGHeroInstance *> CPlayerSpecificInfoCallback::getHeroesInfo() const
|
|
|
{
|
|
|
- const auto * playerState = gs->getPlayerState(*getPlayerID());
|
|
|
+ const auto * playerState = gameState()->getPlayerState(*getPlayerID());
|
|
|
return playerState->getHeroes();
|
|
|
}
|
|
|
|
|
|
@@ -784,7 +748,7 @@ int CPlayerSpecificInfoCallback::getHeroSerial(const CGHeroInstance * hero, bool
|
|
|
return -1;
|
|
|
|
|
|
size_t index = 0;
|
|
|
- const auto & heroes = gs->players[*getPlayerID()].getHeroes();
|
|
|
+ const auto & heroes = gameState()->players.at(*getPlayerID()).getHeroes();
|
|
|
|
|
|
for (auto & possibleHero : heroes)
|
|
|
{
|
|
|
@@ -799,35 +763,35 @@ int CPlayerSpecificInfoCallback::getHeroSerial(const CGHeroInstance * hero, bool
|
|
|
|
|
|
int3 CPlayerSpecificInfoCallback::getGrailPos( double *outKnownRatio )
|
|
|
{
|
|
|
- if (!getPlayerID() || gs->getMap().obeliskCount == 0)
|
|
|
+ if (!getPlayerID() || gameState()->getMap().obeliskCount == 0)
|
|
|
{
|
|
|
*outKnownRatio = 0.0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- TeamID t = gs->getPlayerTeam(*getPlayerID())->id;
|
|
|
+ TeamID t = gameState()->getPlayerTeam(*getPlayerID())->id;
|
|
|
double visited = 0.0;
|
|
|
- if(gs->getMap().obelisksVisited.count(t))
|
|
|
- visited = static_cast<double>(gs->getMap().obelisksVisited[t]);
|
|
|
+ if(gameState()->getMap().obelisksVisited.count(t))
|
|
|
+ visited = static_cast<double>(gameState()->getMap().obelisksVisited[t]);
|
|
|
|
|
|
- *outKnownRatio = visited / gs->getMap().obeliskCount;
|
|
|
+ *outKnownRatio = visited / gameState()->getMap().obeliskCount;
|
|
|
}
|
|
|
- return gs->getMap().grailPos;
|
|
|
+ return gameState()->getMap().grailPos;
|
|
|
}
|
|
|
|
|
|
std::vector < const CGObjectInstance * > CPlayerSpecificInfoCallback::getMyObjects() const
|
|
|
{
|
|
|
- return gs->getPlayerState(*getPlayerID())->getOwnedObjects();
|
|
|
+ return gameState()->getPlayerState(*getPlayerID())->getOwnedObjects();
|
|
|
}
|
|
|
|
|
|
std::vector <QuestInfo> CPlayerSpecificInfoCallback::getMyQuests() const
|
|
|
{
|
|
|
- return gs->getPlayerState(*getPlayerID())->quests;
|
|
|
+ return gameState()->getPlayerState(*getPlayerID())->quests;
|
|
|
}
|
|
|
|
|
|
int CPlayerSpecificInfoCallback::howManyHeroes(bool includeGarrisoned) const
|
|
|
{
|
|
|
- //std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
|
|
+ //std::shared_lock<std::shared_mutex> lock(*gameState()->mx);
|
|
|
ERROR_RET_VAL_IF(!getPlayerID(), "Applicable only for player callbacks", -1);
|
|
|
return getHeroCount(*getPlayerID(), includeGarrisoned);
|
|
|
}
|
|
|
@@ -859,24 +823,24 @@ const CGTownInstance* CPlayerSpecificInfoCallback::getTownBySerial(int serialId)
|
|
|
|
|
|
int CPlayerSpecificInfoCallback::getResourceAmount(GameResID type) const
|
|
|
{
|
|
|
- //std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
|
|
+ //std::shared_lock<std::shared_mutex> lock(*gameState()->mx);
|
|
|
ERROR_RET_VAL_IF(!getPlayerID(), "Applicable only for player callbacks", -1);
|
|
|
return getResource(*getPlayerID(), type);
|
|
|
}
|
|
|
|
|
|
TResources CPlayerSpecificInfoCallback::getResourceAmount() const
|
|
|
{
|
|
|
- //std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
|
|
+ //std::shared_lock<std::shared_mutex> lock(*gameState()->mx);
|
|
|
ERROR_RET_VAL_IF(!getPlayerID(), "Applicable only for player callbacks", TResources());
|
|
|
- return gs->players[*getPlayerID()].resources;
|
|
|
+ return gameState()->players.at(*getPlayerID()).resources;
|
|
|
}
|
|
|
|
|
|
const TeamState * CGameInfoCallback::getTeam( TeamID teamID ) const
|
|
|
{
|
|
|
//rewritten by hand, AI calls this function a lot
|
|
|
|
|
|
- auto team = gs->teams.find(teamID);
|
|
|
- if (team != gs->teams.end())
|
|
|
+ auto team = gameState()->teams.find(teamID);
|
|
|
+ if (team != gameState()->teams.end())
|
|
|
{
|
|
|
const TeamState *ret = &team->second;
|
|
|
if(!getPlayerID().has_value()) //neutral (or invalid) player
|
|
|
@@ -901,8 +865,8 @@ const TeamState * CGameInfoCallback::getTeam( TeamID teamID ) const
|
|
|
|
|
|
const TeamState * CGameInfoCallback::getPlayerTeam( PlayerColor color ) const
|
|
|
{
|
|
|
- auto player = gs->players.find(color);
|
|
|
- if (player != gs->players.end())
|
|
|
+ auto player = gameState()->players.find(color);
|
|
|
+ if (player != gameState()->players.end())
|
|
|
{
|
|
|
return getTeam (player->second.team);
|
|
|
}
|
|
|
@@ -914,32 +878,32 @@ const TeamState * CGameInfoCallback::getPlayerTeam( PlayerColor color ) const
|
|
|
|
|
|
bool CGameInfoCallback::isInTheMap(const int3 &pos) const
|
|
|
{
|
|
|
- return gs->getMap().isInTheMap(pos);
|
|
|
+ return gameState()->getMap().isInTheMap(pos);
|
|
|
}
|
|
|
|
|
|
void CGameInfoCallback::getVisibleTilesInRange(std::unordered_set<int3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula) const
|
|
|
{
|
|
|
- gs->getTilesInRange(tiles, pos, radious, ETileVisibility::REVEALED, *getPlayerID(), distanceFormula);
|
|
|
+ gameState()->getTilesInRange(tiles, pos, radious, ETileVisibility::REVEALED, *getPlayerID(), distanceFormula);
|
|
|
}
|
|
|
|
|
|
void CGameInfoCallback::calculatePaths(const std::shared_ptr<PathfinderConfig> & config) const
|
|
|
{
|
|
|
- gs->calculatePaths(config);
|
|
|
+ gameState()->calculatePaths(config);
|
|
|
}
|
|
|
|
|
|
const CArtifactInstance * CGameInfoCallback::getArtInstance( ArtifactInstanceID aid ) const
|
|
|
{
|
|
|
- return gs->getMap().getArtifactInstance(aid);
|
|
|
+ return gameState()->getMap().getArtifactInstance(aid);
|
|
|
}
|
|
|
|
|
|
const CGObjectInstance * CGameInfoCallback::getObjInstance( ObjectInstanceID oid ) const
|
|
|
{
|
|
|
- return gs->getMap().getObject((oid));
|
|
|
+ return gameState()->getMap().getObject((oid));
|
|
|
}
|
|
|
|
|
|
const CArtifactSet * CGameInfoCallback::getArtSet(const ArtifactLocation & loc) const
|
|
|
{
|
|
|
- return gs->getArtSet(loc);
|
|
|
+ return gameState()->getArtSet(loc);
|
|
|
}
|
|
|
|
|
|
std::vector<ObjectInstanceID> CGameInfoCallback::getVisibleTeleportObjects(std::vector<ObjectInstanceID> ids, PlayerColor player) const
|
|
|
@@ -954,12 +918,12 @@ std::vector<ObjectInstanceID> CGameInfoCallback::getVisibleTeleportObjects(std::
|
|
|
|
|
|
std::vector<ObjectInstanceID> CGameInfoCallback::getTeleportChannelEntrances(TeleportChannelID id, PlayerColor player) const
|
|
|
{
|
|
|
- return getVisibleTeleportObjects(gs->getMap().teleportChannels[id]->entrances, player);
|
|
|
+ return getVisibleTeleportObjects(gameState()->getMap().teleportChannels.at(id)->entrances, player);
|
|
|
}
|
|
|
|
|
|
std::vector<ObjectInstanceID> CGameInfoCallback::getTeleportChannelExits(TeleportChannelID id, PlayerColor player) const
|
|
|
{
|
|
|
- return getVisibleTeleportObjects(gs->getMap().teleportChannels[id]->exits, player);
|
|
|
+ return getVisibleTeleportObjects(gameState()->getMap().teleportChannels.at(id)->exits, player);
|
|
|
}
|
|
|
|
|
|
ETeleportChannelType CGameInfoCallback::getTeleportChannelType(TeleportChannelID id, PlayerColor player) const
|