mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-17 01:32:21 +02:00
Prefer to pass CGameState as reference instead of pointer
This commit is contained in:
@ -41,9 +41,9 @@ NewTurnProcessor::NewTurnProcessor(CGameHandler * gameHandler)
|
||||
|
||||
void NewTurnProcessor::handleTimeEvents(PlayerColor color)
|
||||
{
|
||||
for (auto const & event : gameHandler->gameState()->getMap().events)
|
||||
for (auto const & event : gameHandler->gameState().getMap().events)
|
||||
{
|
||||
if (!event.occursToday(gameHandler->gameState()->day))
|
||||
if (!event.occursToday(gameHandler->gameState().day))
|
||||
continue;
|
||||
|
||||
if (!event.affectsPlayer(color, gameHandler->getPlayerState(color)->isHuman()))
|
||||
@ -77,7 +77,7 @@ void NewTurnProcessor::handleTownEvents(const CGTownInstance * town)
|
||||
{
|
||||
for (auto const & event : town->events)
|
||||
{
|
||||
if (!event.occursToday(gameHandler->gameState()->day))
|
||||
if (!event.occursToday(gameHandler->gameState().day))
|
||||
continue;
|
||||
|
||||
PlayerColor player = town->getOwner();
|
||||
@ -134,7 +134,7 @@ void NewTurnProcessor::handleTownEvents(const CGTownInstance * town)
|
||||
|
||||
void NewTurnProcessor::onPlayerTurnStarted(PlayerColor which)
|
||||
{
|
||||
const auto * playerState = gameHandler->gameState()->getPlayerState(which);
|
||||
const auto * playerState = gameHandler->gameState().getPlayerState(which);
|
||||
|
||||
handleTimeEvents(which);
|
||||
for (const auto * t : playerState->getTowns())
|
||||
@ -153,7 +153,7 @@ void NewTurnProcessor::onPlayerTurnStarted(PlayerColor which)
|
||||
|
||||
void NewTurnProcessor::onPlayerTurnEnded(PlayerColor which)
|
||||
{
|
||||
const auto * playerState = gameHandler->gameState()->getPlayerState(which);
|
||||
const auto * playerState = gameHandler->gameState().getPlayerState(which);
|
||||
assert(playerState->status == EPlayerStatus::INGAME);
|
||||
|
||||
if (playerState->getTowns().empty())
|
||||
@ -186,7 +186,7 @@ void NewTurnProcessor::onPlayerTurnEnded(PlayerColor which)
|
||||
ResourceSet NewTurnProcessor::generatePlayerIncome(PlayerColor playerID, bool newWeek)
|
||||
{
|
||||
const auto & playerSettings = gameHandler->getPlayerSettings(playerID);
|
||||
const PlayerState & state = gameHandler->gameState()->players.at(playerID);
|
||||
const PlayerState & state = gameHandler->gameState().players.at(playerID);
|
||||
ResourceSet income;
|
||||
|
||||
for (const auto & town : state.getTowns())
|
||||
@ -249,9 +249,9 @@ ResourceSet NewTurnProcessor::generatePlayerIncome(PlayerColor playerID, bool ne
|
||||
if (!state.isHuman())
|
||||
{
|
||||
// Initialize bonuses for different resources
|
||||
int difficultyIndex = gameHandler->gameState()->getStartInfo()->difficulty;
|
||||
int difficultyIndex = gameHandler->gameState().getStartInfo()->difficulty;
|
||||
const std::string & difficultyName = GameConstants::DIFFICULTY_NAMES[difficultyIndex];
|
||||
const JsonNode & weeklyBonusesConfig = gameHandler->gameState()->getSettings().getValue(EGameSettings::RESOURCES_WEEKLY_BONUSES_AI);
|
||||
const JsonNode & weeklyBonusesConfig = gameHandler->gameState().getSettings().getValue(EGameSettings::RESOURCES_WEEKLY_BONUSES_AI);
|
||||
const JsonNode & difficultyConfig = weeklyBonusesConfig[difficultyName];
|
||||
|
||||
// Distribute weekly bonuses over 7 days, depending on the current day of the week
|
||||
@ -259,7 +259,7 @@ ResourceSet NewTurnProcessor::generatePlayerIncome(PlayerColor playerID, bool ne
|
||||
{
|
||||
const std::string & name = GameConstants::RESOURCE_NAMES[i];
|
||||
int64_t weeklyBonus = difficultyConfig[name].Integer();
|
||||
int64_t dayOfWeek = gameHandler->gameState()->getDate(Date::DAY_OF_WEEK);
|
||||
int64_t dayOfWeek = gameHandler->gameState().getDate(Date::DAY_OF_WEEK);
|
||||
int64_t dailyIncome = incomeHandicapped[i];
|
||||
int64_t amountTillToday = dailyIncome * weeklyBonus * (dayOfWeek-1) / 7 / 100;
|
||||
int64_t amountAfterToday = dailyIncome * weeklyBonus * dayOfWeek / 7 / 100;
|
||||
@ -436,7 +436,7 @@ RumorState NewTurnProcessor::pickNewRumor()
|
||||
static const std::vector<RumorState::ERumorType> rumorTypes = {RumorState::TYPE_MAP, RumorState::TYPE_SPECIAL, RumorState::TYPE_RAND, RumorState::TYPE_RAND};
|
||||
std::vector<RumorState::ERumorTypeSpecial> sRumorTypes = {
|
||||
RumorState::RUMOR_OBELISKS, RumorState::RUMOR_ARTIFACTS, RumorState::RUMOR_ARMY, RumorState::RUMOR_INCOME};
|
||||
if(gameHandler->gameState()->getMap().grailPos.isValid()) // Grail should always be on map, but I had related crash I didn't manage to reproduce
|
||||
if(gameHandler->gameState().getMap().grailPos.isValid()) // Grail should always be on map, but I had related crash I didn't manage to reproduce
|
||||
sRumorTypes.push_back(RumorState::RUMOR_GRAIL);
|
||||
|
||||
int rumorId = -1;
|
||||
@ -451,11 +451,11 @@ RumorState NewTurnProcessor::pickNewRumor()
|
||||
case RumorState::TYPE_SPECIAL:
|
||||
{
|
||||
SThievesGuildInfo tgi;
|
||||
gameHandler->gameState()->obtainPlayersStats(tgi, 20);
|
||||
gameHandler->gameState().obtainPlayersStats(tgi, 20);
|
||||
rumorId = *RandomGeneratorUtil::nextItem(sRumorTypes, rand);
|
||||
if(rumorId == RumorState::RUMOR_GRAIL)
|
||||
{
|
||||
rumorExtra = gameHandler->gameState()->getTile(gameHandler->gameState()->getMap().grailPos)->getTerrainID().getNum();
|
||||
rumorExtra = gameHandler->gameState().getTile(gameHandler->gameState().getMap().grailPos)->getTerrainID().getNum();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -484,9 +484,9 @@ RumorState NewTurnProcessor::pickNewRumor()
|
||||
}
|
||||
case RumorState::TYPE_MAP:
|
||||
// Makes sure that map rumors only used if there enough rumors too choose from
|
||||
if(!gameHandler->gameState()->getMap().rumors.empty() && (gameHandler->gameState()->getMap().rumors.size() > 1 || !gameHandler->gameState()->currentRumor.last.count(RumorState::TYPE_MAP)))
|
||||
if(!gameHandler->gameState().getMap().rumors.empty() && (gameHandler->gameState().getMap().rumors.size() > 1 || !gameHandler->gameState().currentRumor.last.count(RumorState::TYPE_MAP)))
|
||||
{
|
||||
rumorId = rand.nextInt(gameHandler->gameState()->getMap().rumors.size() - 1);
|
||||
rumorId = rand.nextInt(gameHandler->gameState().getMap().rumors.size() - 1);
|
||||
break;
|
||||
}
|
||||
else
|
||||
@ -507,9 +507,9 @@ RumorState NewTurnProcessor::pickNewRumor()
|
||||
|
||||
std::tuple<EWeekType, CreatureID> NewTurnProcessor::pickWeekType(bool newMonth)
|
||||
{
|
||||
for (const auto & townID : gameHandler->gameState()->getMap().getAllTowns())
|
||||
for (const auto & townID : gameHandler->gameState().getMap().getAllTowns())
|
||||
{
|
||||
auto t = gameHandler->gameState()->getTown(townID);
|
||||
auto t = gameHandler->gameState().getTown(townID);
|
||||
if (t->hasBuilt(BuildingID::GRAIL, ETownType::INFERNO))
|
||||
return { EWeekType::DEITYOFFIRE, CreatureID::IMP };
|
||||
}
|
||||
@ -565,7 +565,7 @@ std::vector<SetMana> NewTurnProcessor::updateHeroesManaPoints()
|
||||
{
|
||||
std::vector<SetMana> result;
|
||||
|
||||
for (auto & elem : gameHandler->gameState()->players)
|
||||
for (auto & elem : gameHandler->gameState().players)
|
||||
{
|
||||
for (CGHeroInstance *h : elem.second.getHeroes())
|
||||
{
|
||||
@ -582,13 +582,13 @@ std::vector<SetMovePoints> NewTurnProcessor::updateHeroesMovementPoints()
|
||||
{
|
||||
std::vector<SetMovePoints> result;
|
||||
|
||||
for (auto & elem : gameHandler->gameState()->players)
|
||||
for (auto & elem : gameHandler->gameState().players)
|
||||
{
|
||||
for (CGHeroInstance *h : elem.second.getHeroes())
|
||||
{
|
||||
auto ti = h->getTurnInfo(1);
|
||||
// NOTE: this code executed when bonuses of previous day not yet updated (this happen in NewTurn::applyGs). See issue 2356
|
||||
int32_t newMovementPoints = h->movementPointsLimitCached(gameHandler->gameState()->getMap().getTile(h->visitablePos()).isLand(), ti.get());
|
||||
int32_t newMovementPoints = h->movementPointsLimitCached(gameHandler->gameState().getMap().getTile(h->visitablePos()).isLand(), ti.get());
|
||||
|
||||
if (newMovementPoints != h->movementPointsRemaining())
|
||||
result.emplace_back(h->id, newMovementPoints, true);
|
||||
@ -643,7 +643,7 @@ NewTurn NewTurnProcessor::generateNewTurnPack()
|
||||
NewTurn n;
|
||||
n.specialWeek = EWeekType::FIRST_WEEK;
|
||||
n.creatureid = CreatureID::NONE;
|
||||
n.day = gameHandler->gameState()->day + 1;
|
||||
n.day = gameHandler->gameState().day + 1;
|
||||
|
||||
bool firstTurn = !gameHandler->getDate(Date::DAY);
|
||||
bool newWeek = gameHandler->getDate(Date::DAY_OF_WEEK) == 7; //day numbers are confusing, as day was not yet switched
|
||||
@ -651,7 +651,7 @@ NewTurn NewTurnProcessor::generateNewTurnPack()
|
||||
|
||||
if (!firstTurn)
|
||||
{
|
||||
for (const auto & player : gameHandler->gameState()->players)
|
||||
for (const auto & player : gameHandler->gameState().players)
|
||||
n.playerIncome[player.first] = generatePlayerIncome(player.first, newWeek);
|
||||
}
|
||||
|
||||
@ -667,9 +667,9 @@ NewTurn NewTurnProcessor::generateNewTurnPack()
|
||||
|
||||
if (newWeek)
|
||||
{
|
||||
for (const auto & townID : gameHandler->gameState()->getMap().getAllTowns())
|
||||
for (const auto & townID : gameHandler->gameState().getMap().getAllTowns())
|
||||
{
|
||||
auto t = gameHandler->gameState()->getTown(townID);
|
||||
auto t = gameHandler->gameState().getTown(townID);
|
||||
n.availableCreatures.push_back(generateTownGrowth(t, n.specialWeek, n.creatureid, firstTurn));
|
||||
}
|
||||
}
|
||||
@ -699,9 +699,9 @@ void NewTurnProcessor::onNewTurn()
|
||||
|
||||
if (newWeek)
|
||||
{
|
||||
for (const auto & townID : gameHandler->gameState()->getMap().getAllTowns())
|
||||
for (const auto & townID : gameHandler->gameState().getMap().getAllTowns())
|
||||
{
|
||||
auto t = gameHandler->gameState()->getTown(townID);
|
||||
auto t = gameHandler->gameState().getTown(townID);
|
||||
if (t->hasBuilt(BuildingSubID::PORTAL_OF_SUMMONING))
|
||||
gameHandler->setPortalDwelling(t, true, (n.specialWeek == EWeekType::PLAGUE ? true : false)); //set creatures for Portal of Summoning
|
||||
}
|
||||
@ -709,9 +709,9 @@ void NewTurnProcessor::onNewTurn()
|
||||
|
||||
if (newWeek && !firstTurn)
|
||||
{
|
||||
for (const auto & townID : gameHandler->gameState()->getMap().getAllTowns())
|
||||
for (const auto & townID : gameHandler->gameState().getMap().getAllTowns())
|
||||
{
|
||||
auto t = gameHandler->gameState()->getTown(townID);
|
||||
auto t = gameHandler->gameState().getTown(townID);
|
||||
if (!t->getOwner().isValidPlayer())
|
||||
updateNeutralTownGarrison(t, 1 + gameHandler->getDate(Date::DAY) / 7);
|
||||
}
|
||||
|
Reference in New Issue
Block a user