1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

CGameHandler no longer inherits CGameInfoCallback, reduce direct access

to gamestate
This commit is contained in:
Ivan Savenko
2025-05-20 19:01:25 +03:00
parent 25e57542be
commit 8255a4b9ae
30 changed files with 271 additions and 295 deletions

View File

@@ -33,14 +33,14 @@ int TurnOrderProcessor::simturnsTurnsMaxLimit() const
{
if (simturnsMaxDurationDays)
return *simturnsMaxDurationDays;
return gameHandler->getStartInfo()->simturnsInfo.optionalTurns;
return gameHandler->gameInfo().getStartInfo()->simturnsInfo.optionalTurns;
}
int TurnOrderProcessor::simturnsTurnsMinLimit() const
{
if (simturnsMinDurationDays)
return *simturnsMinDurationDays;
return gameHandler->getStartInfo()->simturnsInfo.requiredTurns;
return gameHandler->gameInfo().getStartInfo()->simturnsInfo.requiredTurns;
}
std::vector<TurnOrderProcessor::PlayerPair> TurnOrderProcessor::computeContactStatus() const
@@ -101,13 +101,13 @@ bool TurnOrderProcessor::playersInContact(PlayerColor left, PlayerColor right) c
boost::multi_array<bool, 3> leftReachability;
boost::multi_array<bool, 3> rightReachability;
int3 mapSize = gameHandler->getMapSize();
int3 mapSize = gameHandler->gameInfo().getMapSize();
leftReachability.resize(boost::extents[mapSize.z][mapSize.x][mapSize.y]);
rightReachability.resize(boost::extents[mapSize.z][mapSize.x][mapSize.y]);
const auto * leftInfo = gameHandler->getPlayerState(left, false);
const auto * rightInfo = gameHandler->getPlayerState(right, false);
const auto * leftInfo = gameHandler->gameInfo().getPlayerState(left, false);
const auto * rightInfo = gameHandler->gameInfo().getPlayerState(right, false);
for (auto obj : gameHandler->gameState().getMap().getObjects())
{
@@ -170,8 +170,8 @@ bool TurnOrderProcessor::isContactAllowed(PlayerColor active, PlayerColor waitin
bool TurnOrderProcessor::computeCanActSimultaneously(PlayerColor active, PlayerColor waiting) const
{
const auto * activeInfo = gameHandler->getPlayerState(active, false);
const auto * waitingInfo = gameHandler->getPlayerState(waiting, false);
const auto * activeInfo = gameHandler->gameInfo().getPlayerState(active, false);
const auto * waitingInfo = gameHandler->gameInfo().getPlayerState(waiting, false);
assert(active != waiting);
assert(activeInfo);
@@ -180,7 +180,7 @@ bool TurnOrderProcessor::computeCanActSimultaneously(PlayerColor active, PlayerC
if (activeInfo->human != waitingInfo->human)
{
// only one AI and one human can play simultaneously from single connection
if (!gameHandler->getStartInfo()->simturnsInfo.allowHumanWithAI)
if (!gameHandler->gameInfo().getStartInfo()->simturnsInfo.allowHumanWithAI)
return false;
}
else
@@ -190,13 +190,13 @@ bool TurnOrderProcessor::computeCanActSimultaneously(PlayerColor active, PlayerC
return false;
}
if (gameHandler->getDate(Date::DAY) < simturnsTurnsMinLimit())
if (gameHandler->gameInfo().getDate(Date::DAY) < simturnsTurnsMinLimit())
return true;
if (gameHandler->getDate(Date::DAY) > simturnsTurnsMaxLimit())
if (gameHandler->gameInfo().getDate(Date::DAY) > simturnsTurnsMaxLimit())
return false;
if (gameHandler->getStartInfo()->simturnsInfo.ignoreAlliedContacts && activeInfo->team == waitingInfo->team)
if (gameHandler->gameInfo().getStartInfo()->simturnsInfo.ignoreAlliedContacts && activeInfo->team == waitingInfo->team)
return true;
if (playersInContact(active, waiting))
@@ -207,8 +207,8 @@ bool TurnOrderProcessor::computeCanActSimultaneously(PlayerColor active, PlayerC
bool TurnOrderProcessor::mustActBefore(PlayerColor left, PlayerColor right) const
{
const auto * leftInfo = gameHandler->getPlayerState(left, false);
const auto * rightInfo = gameHandler->getPlayerState(right, false);
const auto * leftInfo = gameHandler->gameInfo().getPlayerState(left, false);
const auto * rightInfo = gameHandler->gameInfo().getPlayerState(right, false);
assert(left != right);
assert(leftInfo && rightInfo);
@@ -254,7 +254,7 @@ void TurnOrderProcessor::doStartNewDay()
bool activePlayer = false;
for (auto player : actedPlayers)
{
if (gameHandler->getPlayerState(player)->status == EPlayerStatus::INGAME)
if (gameHandler->gameInfo().getPlayerState(player)->status == EPlayerStatus::INGAME)
activePlayer = true;
}
@@ -272,8 +272,8 @@ void TurnOrderProcessor::doStartNewDay()
void TurnOrderProcessor::doStartPlayerTurn(PlayerColor which)
{
assert(gameHandler->getPlayerState(which));
assert(gameHandler->getPlayerState(which)->status == EPlayerStatus::INGAME);
assert(gameHandler->gameInfo().getPlayerState(which));
assert(gameHandler->gameInfo().getPlayerState(which)->status == EPlayerStatus::INGAME);
// Only if player is actually starting his turn (and not loading from save)
if (!actingPlayers.count(which))
@@ -296,7 +296,7 @@ void TurnOrderProcessor::doStartPlayerTurn(PlayerColor which)
void TurnOrderProcessor::doEndPlayerTurn(PlayerColor which)
{
assert(isPlayerMakingTurn(which));
assert(gameHandler->getPlayerStatus(which) == EPlayerStatus::INGAME);
assert(gameHandler->gameInfo().getPlayerStatus(which) == EPlayerStatus::INGAME);
actingPlayers.erase(which);
actedPlayers.insert(which);
@@ -340,7 +340,7 @@ bool TurnOrderProcessor::onPlayerEndsTurn(PlayerColor which)
return false;
}
if(gameHandler->getPlayerStatus(which) != EPlayerStatus::INGAME)
if(gameHandler->gameInfo().getPlayerStatus(which) != EPlayerStatus::INGAME)
{
gameHandler->complain("Can not end turn for player that is not in game!");
return false;
@@ -356,7 +356,7 @@ bool TurnOrderProcessor::onPlayerEndsTurn(PlayerColor which)
// it is possible that player have lost - e.g. spent 7 days without town
// in this case - don't call doEndPlayerTurn - turn transfer was already handled by onPlayerEndsGame
if(gameHandler->getPlayerStatus(which) == EPlayerStatus::INGAME)
if(gameHandler->gameInfo().getPlayerStatus(which) == EPlayerStatus::INGAME)
doEndPlayerTurn(which);
return true;
@@ -402,10 +402,10 @@ bool TurnOrderProcessor::isPlayerAwaitsNewDay(PlayerColor which) const
void TurnOrderProcessor::setMinSimturnsDuration(int days)
{
simturnsMinDurationDays = gameHandler->getDate(Date::DAY) + days;
simturnsMinDurationDays = gameHandler->gameInfo().getDate(Date::DAY) + days;
}
void TurnOrderProcessor::setMaxSimturnsDuration(int days)
{
simturnsMaxDurationDays = gameHandler->getDate(Date::DAY) + days;
simturnsMaxDurationDays = gameHandler->gameInfo().getDate(Date::DAY) + days;
}