mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-23 00:28:08 +02:00
StartInfo in gamestate now use unique_ptr
This commit is contained in:
@ -49,7 +49,6 @@
|
||||
#include "../lib/rmg/CMapGenOptions.h"
|
||||
#include "../lib/serializer/Connection.h"
|
||||
#include "../lib/filesystem/Filesystem.h"
|
||||
#include "../lib/serializer/CMemorySerializer.h"
|
||||
#include "../lib/UnlockGuard.h"
|
||||
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
|
@ -254,7 +254,7 @@ void CClient::initPlayerEnvironments()
|
||||
|
||||
void CClient::initPlayerInterfaces()
|
||||
{
|
||||
for(auto & playerInfo : gs->scenarioOps->playerInfos)
|
||||
for(auto & playerInfo : gs->getStartInfo()->playerInfos)
|
||||
{
|
||||
PlayerColor color = playerInfo.first;
|
||||
if(!vstd::contains(GAME->server().getAllClientPlayers(GAME->server().logicConnection->connectionID), color))
|
||||
@ -266,7 +266,7 @@ void CClient::initPlayerInterfaces()
|
||||
if(playerInfo.second.isControlledByAI() || settings["session"]["onlyai"].Bool())
|
||||
{
|
||||
bool alliedToHuman = false;
|
||||
for(auto & allyInfo : gs->scenarioOps->playerInfos)
|
||||
for(auto & allyInfo : gs->getStartInfo()->playerInfos)
|
||||
if (gs->getPlayerTeam(allyInfo.first) == gs->getPlayerTeam(playerInfo.first) && allyInfo.second.isControlledByHuman())
|
||||
alliedToHuman = true;
|
||||
|
||||
|
@ -53,7 +53,7 @@ int CGameInfoCallback::getResource(PlayerColor Player, GameResID which) const
|
||||
|
||||
const PlayerSettings * CGameInfoCallback::getPlayerSettings(PlayerColor color) const
|
||||
{
|
||||
return &gs->scenarioOps->getIthPlayersSettings(color);
|
||||
return &gs->getStartInfo()->getIthPlayersSettings(color);
|
||||
}
|
||||
|
||||
bool CGameInfoCallback::isAllowed(SpellID id) const
|
||||
@ -192,13 +192,14 @@ void CGameInfoCallback::fillUpgradeInfo(const CArmedInstance *obj, SlotID stackP
|
||||
//return gs->fillUpgradeInfo(obj->getStack(stackPos));
|
||||
}
|
||||
|
||||
const StartInfo * CGameInfoCallback::getStartInfo(bool beforeRandomization) const
|
||||
const StartInfo * CGameInfoCallback::getStartInfo() const
|
||||
{
|
||||
//std::shared_lock<std::shared_mutex> lock(*gs->mx);
|
||||
if(beforeRandomization)
|
||||
return gs->initialOpts;
|
||||
else
|
||||
return gs->scenarioOps;
|
||||
return gs->getStartInfo();
|
||||
}
|
||||
|
||||
const StartInfo * CGameInfoCallback::getInitialStartInfo() const
|
||||
{
|
||||
return gs->getInitialStartInfo();
|
||||
}
|
||||
|
||||
int32_t CGameInfoCallback::getSpellCost(const spells::Spell * sp, const CGHeroInstance * caster) const
|
||||
@ -374,7 +375,7 @@ bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero
|
||||
for(auto & elem : info.army)
|
||||
elem.second.count = 0;
|
||||
|
||||
const auto factionIndex = getStartInfo(false)->playerInfos.at(h->tempOwner).castle;
|
||||
const auto factionIndex = getStartInfo()->playerInfos.at(h->tempOwner).castle;
|
||||
|
||||
int maxAIValue = 0;
|
||||
const CCreature * mostStrong = nullptr;
|
||||
|
@ -58,7 +58,8 @@ public:
|
||||
|
||||
// //various
|
||||
virtual int getDate(Date mode=Date::DAY) const = 0; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
||||
virtual const StartInfo * getStartInfo(bool beforeRandomization = false) const = 0;
|
||||
virtual const StartInfo * getStartInfo() const = 0;
|
||||
virtual const StartInfo * getInitialStartInfo() const = 0;
|
||||
virtual bool isAllowed(SpellID id) const = 0;
|
||||
virtual bool isAllowed(ArtifactID id) const = 0;
|
||||
virtual bool isAllowed(SecondarySkill id) const = 0;
|
||||
@ -145,7 +146,8 @@ protected:
|
||||
public:
|
||||
//various
|
||||
int getDate(Date mode=Date::DAY)const override; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
||||
const StartInfo * getStartInfo(bool beforeRandomization = false) const override;
|
||||
const StartInfo * getStartInfo() const override;
|
||||
const StartInfo * getInitialStartInfo() const override;
|
||||
bool isAllowed(SpellID id) const override;
|
||||
bool isAllowed(ArtifactID id) const override;
|
||||
bool isAllowed(SecondarySkill id) const override;
|
||||
|
@ -210,7 +210,7 @@ void CPrivilegedInfoCallback::saveCommonState(CSaveFile & out) const
|
||||
logGlobal->info("\tSaving header");
|
||||
out.serializer & static_cast<CMapHeader&>(*gs->map);
|
||||
logGlobal->info("\tSaving options");
|
||||
out.serializer & gs->scenarioOps;
|
||||
out.serializer & gs->getStartInfo();
|
||||
logGlobal->info("\tSaving mod list");
|
||||
out.serializer & activeMods;
|
||||
logGlobal->info("\tSaving gamestate");
|
||||
|
@ -151,8 +151,6 @@ CGameState::~CGameState()
|
||||
// explicitly delete all ongoing battles first - BattleInfo destructor requires valid CGameState
|
||||
currentBattles.clear();
|
||||
map.dellNull();
|
||||
scenarioOps.dellNull();
|
||||
initialOpts.dellNull();
|
||||
}
|
||||
|
||||
const IGameSettings & CGameState::getSettings() const
|
||||
@ -170,8 +168,8 @@ void CGameState::init(const IMapService * mapService, StartInfo * si, Load::Prog
|
||||
{
|
||||
assert(services);
|
||||
assert(callback);
|
||||
scenarioOps = CMemorySerializer::deepCopy(*si).release();
|
||||
initialOpts = CMemorySerializer::deepCopy(*si).release();
|
||||
scenarioOps = CMemorySerializer::deepCopy(*si);
|
||||
initialOpts = CMemorySerializer::deepCopy(*si);
|
||||
si = nullptr;
|
||||
|
||||
switch(scenarioOps->mode)
|
||||
|
@ -46,6 +46,9 @@ DLL_LINKAGE std::ostream & operator<<(std::ostream & os, const EVictoryLossCheck
|
||||
class DLL_LINKAGE CGameState : public CNonConstInfoCallback, public Serializeable
|
||||
{
|
||||
friend class CGameStateCampaign;
|
||||
|
||||
std::unique_ptr<StartInfo> initialOpts; //copy of settings received from pregame (not randomized)
|
||||
std::unique_ptr<StartInfo> scenarioOps;
|
||||
public:
|
||||
/// Stores number of times each artifact was placed on map via randomization
|
||||
std::map<ArtifactID, int> allocatedArtifacts;
|
||||
@ -71,8 +74,6 @@ public:
|
||||
void init(const IMapService * mapService, StartInfo * si, Load::ProgressAccumulator &, bool allowSavingRandomMap = true);
|
||||
void updateOnLoad(StartInfo * si);
|
||||
|
||||
ConstTransitivePtr<StartInfo> scenarioOps;
|
||||
ConstTransitivePtr<StartInfo> initialOpts; //copy of settings received from pregame (not randomized)
|
||||
ui32 day; //total number of days in game
|
||||
ConstTransitivePtr<CMap> map;
|
||||
std::map<PlayerColor, PlayerState> players;
|
||||
@ -123,6 +124,19 @@ public:
|
||||
void obtainPlayersStats(SThievesGuildInfo & tgi, int level); //fills tgi with info about other players that is available at given level of thieves' guild
|
||||
const IGameSettings & getSettings() const;
|
||||
|
||||
StartInfo * getStartInfo()
|
||||
{
|
||||
return scenarioOps.get();
|
||||
}
|
||||
const StartInfo * getStartInfo() const final
|
||||
{
|
||||
return scenarioOps.get();
|
||||
}
|
||||
const StartInfo * getInitialStartInfo() const final
|
||||
{
|
||||
return initialOpts.get();
|
||||
}
|
||||
|
||||
bool isVisible(int3 pos, const std::optional<PlayerColor> & player) const override;
|
||||
bool isVisible(const CGObjectInstance * obj, const std::optional<PlayerColor> & player) const override;
|
||||
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include "../mapping/CMap.h"
|
||||
#include "../ArtifactUtils.h"
|
||||
#include "../CPlayerState.h"
|
||||
#include "../serializer/CMemorySerializer.h"
|
||||
|
||||
#include <vstd/RNG.h>
|
||||
#include <vcmi/HeroTypeService.h>
|
||||
|
@ -444,10 +444,10 @@ DamageRange CGTownInstance::getKeepDamageRange() const
|
||||
FactionID CGTownInstance::randomizeFaction(vstd::RNG & rand)
|
||||
{
|
||||
if(getOwner().isValidPlayer())
|
||||
return cb->gameState()->scenarioOps->getIthPlayersSettings(getOwner()).castle;
|
||||
return cb->getStartInfo()->getIthPlayersSettings(getOwner()).castle;
|
||||
|
||||
if(alignmentToPlayer.isValidPlayer())
|
||||
return cb->gameState()->scenarioOps->getIthPlayersSettings(alignmentToPlayer).castle;
|
||||
return cb->getStartInfo()->getIthPlayersSettings(alignmentToPlayer).castle;
|
||||
|
||||
std::vector<FactionID> potentialPicks;
|
||||
|
||||
|
@ -1122,14 +1122,14 @@ void PlayerEndsGame::applyGs(CGameState *gs)
|
||||
|
||||
// TODO: Campaign-specific code might as well go somewhere else
|
||||
// keep all heroes from the winning player
|
||||
if(p->human && gs->scenarioOps->campState)
|
||||
if(p->human && gs->getStartInfo()->campState)
|
||||
{
|
||||
std::vector<CGHeroInstance *> crossoverHeroes;
|
||||
for (CGHeroInstance * hero : gs->map->heroesOnMap)
|
||||
if (hero->tempOwner == player)
|
||||
crossoverHeroes.push_back(hero);
|
||||
|
||||
gs->scenarioOps->campState->setCurrentMapAsConquered(crossoverHeroes);
|
||||
gs->getStartInfo()->campState->setCurrentMapAsConquered(crossoverHeroes);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1143,14 +1143,14 @@ void PlayerEndsGame::applyGs(CGameState *gs)
|
||||
|
||||
void PlayerReinitInterface::applyGs(CGameState *gs)
|
||||
{
|
||||
if(!gs || !gs->scenarioOps)
|
||||
if(!gs || !gs->getStartInfo())
|
||||
return;
|
||||
|
||||
//TODO: what does mean if more that one player connected?
|
||||
if(playerConnectionId == PlayerSettings::PLAYER_AI)
|
||||
{
|
||||
for(const auto & player : players)
|
||||
gs->scenarioOps->getIthPlayersSettings(player).connectedPlayerIDs.clear();
|
||||
gs->getStartInfo()->getIthPlayersSettings(player).connectedPlayerIDs.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,7 +208,7 @@ void CVCMIServer::prepareToRestart()
|
||||
return;
|
||||
}
|
||||
|
||||
* si = * gh->gs->initialOpts;
|
||||
* si = * gh->gs->getInitialStartInfo();
|
||||
setState(EServerState::LOBBY);
|
||||
if (si->campState)
|
||||
{
|
||||
|
@ -225,7 +225,7 @@ void ApplyOnServerNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pack)
|
||||
return;
|
||||
}
|
||||
|
||||
pack.initializedStartInfo = std::make_shared<StartInfo>(*srv.gh->getStartInfo(true));
|
||||
pack.initializedStartInfo = std::make_shared<StartInfo>(*srv.gh->getInitialStartInfo());
|
||||
pack.initializedGameState = srv.gh->gameState();
|
||||
result = true;
|
||||
}
|
||||
|
@ -17,7 +17,8 @@ class IGameInfoCallbackMock : public IGameInfoCallback
|
||||
public:
|
||||
//various
|
||||
MOCK_CONST_METHOD1(getDate, int(Date));
|
||||
MOCK_CONST_METHOD1(getStartInfo, const StartInfo *(bool));
|
||||
MOCK_CONST_METHOD0(getStartInfo, const StartInfo *());
|
||||
MOCK_CONST_METHOD0(getInitialStartInfo, const StartInfo *());
|
||||
|
||||
MOCK_CONST_METHOD1(isAllowed, bool(SpellID));
|
||||
MOCK_CONST_METHOD1(isAllowed, bool(ArtifactID));
|
||||
|
Reference in New Issue
Block a user