mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +02:00
- Refactored method CGameState::init
This commit is contained in:
@ -699,7 +699,6 @@ int CClient::sendRequest(const CPack *request, PlayerColor player)
|
|||||||
void CClient::campaignMapFinished( shared_ptr<CCampaignState> camp )
|
void CClient::campaignMapFinished( shared_ptr<CCampaignState> camp )
|
||||||
{
|
{
|
||||||
endGame(false);
|
endGame(false);
|
||||||
LOCPLINT = nullptr; //TODO free res
|
|
||||||
|
|
||||||
GH.curInt = CGPreGame::create();
|
GH.curInt = CGPreGame::create();
|
||||||
auto & epilogue = camp->camp->scenarios[camp->mapsConquered.back()].epilog;
|
auto & epilogue = camp->camp->scenarios[camp->mapsConquered.back()].epilog;
|
||||||
|
1484
lib/CGameState.cpp
1484
lib/CGameState.cpp
File diff suppressed because it is too large
Load Diff
@ -29,11 +29,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class CTown;
|
class CTown;
|
||||||
class CScriptCallback;
|
|
||||||
class CCallback;
|
class CCallback;
|
||||||
class IGameCallback;
|
class IGameCallback;
|
||||||
class CLuaCallback;
|
|
||||||
class CCPPObjectScript;
|
|
||||||
class CCreatureSet;
|
class CCreatureSet;
|
||||||
class CStack;
|
class CStack;
|
||||||
class CQuest;
|
class CQuest;
|
||||||
@ -388,15 +385,6 @@ DLL_LINKAGE std::ostream & operator<<(std::ostream & os, const EVictoryLossCheck
|
|||||||
class DLL_LINKAGE CGameState : public CNonConstInfoCallback
|
class DLL_LINKAGE CGameState : public CNonConstInfoCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ConstTransitivePtr<StartInfo> scenarioOps, initialOpts; //second one is a copy of settings received from pregame (not randomized)
|
|
||||||
PlayerColor currentPlayer; //ID of player currently having turn
|
|
||||||
ConstTransitivePtr<BattleInfo> curB; //current battle
|
|
||||||
ui32 day; //total number of days in game
|
|
||||||
ConstTransitivePtr<CMap> map;
|
|
||||||
std::map<PlayerColor, PlayerState> players;
|
|
||||||
std::map<TeamID, TeamState> teams;
|
|
||||||
CBonusSystemNode globalEffects;
|
|
||||||
|
|
||||||
struct DLL_LINKAGE HeroesPool
|
struct DLL_LINKAGE HeroesPool
|
||||||
{
|
{
|
||||||
std::map<ui32, ConstTransitivePtr<CGHeroInstance> > heroesPool; //[subID] - heroes available to buy; nullptr if not available
|
std::map<ui32, ConstTransitivePtr<CGHeroInstance> > heroesPool; //[subID] - heroes available to buy; nullptr if not available
|
||||||
@ -410,18 +398,22 @@ public:
|
|||||||
}
|
}
|
||||||
} hpool; //we have here all heroes available on this map that are not hired
|
} hpool; //we have here all heroes available on this map that are not hired
|
||||||
|
|
||||||
boost::shared_mutex *mx;
|
CGameState();
|
||||||
|
virtual ~CGameState();
|
||||||
|
|
||||||
void init(StartInfo * si);
|
void init(StartInfo * si);
|
||||||
|
|
||||||
bool isUsedHero(HeroTypeID hid) const; //looks in heroes and prisons
|
ConstTransitivePtr<StartInfo> scenarioOps, initialOpts; //second one is a copy of settings received from pregame (not randomized)
|
||||||
void placeCampaignHeroes(const std::vector<std::pair<CGHeroInstance*, ObjectInstanceID> > &campHeroReplacements);
|
PlayerColor currentPlayer; //ID of player currently having turn
|
||||||
std::vector<std::pair<CGHeroInstance*, ObjectInstanceID> > campaignHeroesToReplace(); //returns heroes and placeholders in where heroes will be put; may remove some placeholders
|
ConstTransitivePtr<BattleInfo> curB; //current battle
|
||||||
std::set<HeroTypeID> getUnusedAllowedHeroes(bool alsoIncludeNotAllowed = false) const;
|
ui32 day; //total number of days in game
|
||||||
void initDuel();
|
ConstTransitivePtr<CMap> map;
|
||||||
void randomizeObject(CGObjectInstance *cur);
|
std::map<PlayerColor, PlayerState> players;
|
||||||
std::pair<Obj,int> pickObject(CGObjectInstance *obj); //chooses type of object to be randomized, returns <type, subtype>
|
std::map<TeamID, TeamState> teams;
|
||||||
int pickHero(PlayerColor owner);
|
CBonusSystemNode globalEffects;
|
||||||
|
|
||||||
|
boost::shared_mutex *mx;
|
||||||
|
|
||||||
void giveHeroArtifact(CGHeroInstance *h, ArtifactID aid);
|
void giveHeroArtifact(CGHeroInstance *h, ArtifactID aid);
|
||||||
|
|
||||||
void apply(CPack *pack);
|
void apply(CPack *pack);
|
||||||
@ -439,38 +431,65 @@ public:
|
|||||||
std::map<ui32, ConstTransitivePtr<CGHeroInstance> > unusedHeroesFromPool(); //heroes pool without heroes that are available in taverns
|
std::map<ui32, ConstTransitivePtr<CGHeroInstance> > unusedHeroesFromPool(); //heroes pool without heroes that are available in taverns
|
||||||
BattleInfo * setupBattle(int3 tile, const CArmedInstance *armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance *town);
|
BattleInfo * setupBattle(int3 tile, const CArmedInstance *armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance *town);
|
||||||
|
|
||||||
void buildBonusSystemTree();
|
|
||||||
void attachArmedObjects();
|
|
||||||
void buildGlobalTeamPlayerTree();
|
|
||||||
void deserializationFix();
|
|
||||||
|
|
||||||
bool isVisible(int3 pos, PlayerColor player);
|
bool isVisible(int3 pos, PlayerColor player);
|
||||||
bool isVisible(const CGObjectInstance *obj, boost::optional<PlayerColor> player);
|
bool isVisible(const CGObjectInstance *obj, boost::optional<PlayerColor> player);
|
||||||
|
|
||||||
CGameState(); //c-tor
|
|
||||||
virtual ~CGameState(); //d-tor
|
|
||||||
void getNeighbours(const TerrainTile &srct, int3 tile, std::vector<int3> &vec, const boost::logic::tribool &onLand, bool limitCoastSailing);
|
void getNeighbours(const TerrainTile &srct, int3 tile, std::vector<int3> &vec, const boost::logic::tribool &onLand, bool limitCoastSailing);
|
||||||
int getMovementCost(const CGHeroInstance *h, const int3 &src, const int3 &dest, int remainingMovePoints=-1, bool checkLast=true);
|
int getMovementCost(const CGHeroInstance *h, const int3 &src, const int3 &dest, int remainingMovePoints=-1, bool checkLast=true);
|
||||||
int getDate(Date::EDateType mode=Date::DAY) const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
int getDate(Date::EDateType mode=Date::DAY) const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
{
|
{
|
||||||
h & scenarioOps & initialOpts & currentPlayer & day & map & players & teams & hpool & globalEffects;
|
h & scenarioOps & initialOpts & currentPlayer & day & map & players & teams & hpool & globalEffects;
|
||||||
BONUS_TREE_DESERIALIZATION_FIX
|
BONUS_TREE_DESERIALIZATION_FIX
|
||||||
}
|
}
|
||||||
|
|
||||||
friend class CCallback;
|
|
||||||
friend class CLuaCallback;
|
|
||||||
friend class CClient;
|
|
||||||
friend void initGameState(CMap * map, CGameInfo * cgi);
|
|
||||||
friend class IGameCallback;
|
|
||||||
friend class CMapHandler;
|
|
||||||
friend class CGameHandler;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Init game state
|
||||||
|
void initNewGame();
|
||||||
|
void initCampaign();
|
||||||
|
void initDuel();
|
||||||
|
void checkMapChecksum();
|
||||||
|
void initGrailPosition();
|
||||||
|
void initRandomFactionsForPlayers();
|
||||||
|
void randomizeMapObjects();
|
||||||
|
void randomizeObject(CGObjectInstance *cur);
|
||||||
|
void initPlayerStates();
|
||||||
|
void initHeroPlaceholders();
|
||||||
|
void placeCampaignHeroes(const std::vector<std::pair<CGHeroInstance*, ObjectInstanceID> > &campHeroReplacements);
|
||||||
|
void placeStartingHeroes();
|
||||||
|
void initStartingResources();
|
||||||
|
void initHeroes();
|
||||||
|
void giveCampaignBonusToHero(CGHeroInstance * hero);
|
||||||
|
void initFogOfWar();
|
||||||
|
void initStartingBonus();
|
||||||
|
void initTowns();
|
||||||
|
void initMapObjects();
|
||||||
|
void initVisitingAndGarrisonedHeroes();
|
||||||
|
|
||||||
|
// Victory / Loss condition checks
|
||||||
EVictoryLossCheckResult checkForVictory(PlayerColor player) const; //checks if given player is winner
|
EVictoryLossCheckResult checkForVictory(PlayerColor player) const; //checks if given player is winner
|
||||||
EVictoryLossCheckResult checkForLoss(PlayerColor player) const; //checks if given player is loser
|
EVictoryLossCheckResult checkForLoss(PlayerColor player) const; //checks if given player is loser
|
||||||
PlayerColor checkForStandardWin() const; //returns color of player that accomplished standard victory conditions or 255 (NEUTRAL) if no winner
|
PlayerColor checkForStandardWin() const; //returns color of player that accomplished standard victory conditions or 255 (NEUTRAL) if no winner
|
||||||
bool checkForStandardLoss(PlayerColor player) const; //checks if given player lost the game
|
bool checkForStandardLoss(PlayerColor player) const; //checks if given player lost the game
|
||||||
|
|
||||||
|
// Bonus system handling
|
||||||
|
void buildBonusSystemTree();
|
||||||
|
void attachArmedObjects();
|
||||||
|
void buildGlobalTeamPlayerTree();
|
||||||
|
void deserializationFix();
|
||||||
|
|
||||||
|
bool isUsedHero(HeroTypeID hid) const; //looks in heroes and prisons
|
||||||
|
std::vector<std::pair<CGHeroInstance*, ObjectInstanceID> > campaignHeroesToReplace(); //returns heroes and placeholders in where heroes will be put; may remove some placeholders
|
||||||
|
std::set<HeroTypeID> getUnusedAllowedHeroes(bool alsoIncludeNotAllowed = false) const;
|
||||||
|
std::pair<Obj,int> pickObject(CGObjectInstance *obj); //chooses type of object to be randomized, returns <type, subtype>
|
||||||
|
int pickHero(PlayerColor owner);
|
||||||
|
|
||||||
|
friend class CCallback;
|
||||||
|
friend class CClient;
|
||||||
|
friend class IGameCallback;
|
||||||
|
friend class CMapHandler;
|
||||||
|
friend class CGameHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DLL_LINKAGE QuestInfo //universal interface for human and AI
|
struct DLL_LINKAGE QuestInfo //universal interface for human and AI
|
||||||
|
@ -25,7 +25,6 @@ struct BattleInfo;
|
|||||||
struct QuestInfo;
|
struct QuestInfo;
|
||||||
class IGameCallback;
|
class IGameCallback;
|
||||||
struct BattleResult;
|
struct BattleResult;
|
||||||
class CCPPObjectScript;
|
|
||||||
class CGObjectInstance;
|
class CGObjectInstance;
|
||||||
class CScript;
|
class CScript;
|
||||||
class CObjectScript;
|
class CObjectScript;
|
||||||
|
@ -443,10 +443,9 @@ boost::optional<CScenarioTravel::STravelBonus> CCampaignState::getBonusForCurren
|
|||||||
{
|
{
|
||||||
auto bonuses = getCurrentScenario().travelOptions.bonusesToChoose;
|
auto bonuses = getCurrentScenario().travelOptions.bonusesToChoose;
|
||||||
assert(chosenCampaignBonuses.count(*currentMap) || bonuses.size() == 0);
|
assert(chosenCampaignBonuses.count(*currentMap) || bonuses.size() == 0);
|
||||||
if(bonuses.size())
|
|
||||||
return bonuses[currentBonusID()];
|
if(bonuses.empty()) return boost::optional<CScenarioTravel::STravelBonus>();
|
||||||
else
|
else return bonuses[currentBonusID()];
|
||||||
return boost::optional<CScenarioTravel::STravelBonus>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const CCampaignScenario & CCampaignState::getCurrentScenario() const
|
const CCampaignScenario & CCampaignState::getCurrentScenario() const
|
||||||
|
@ -83,16 +83,6 @@ public:
|
|||||||
class DLL_LINKAGE CCampaignScenario
|
class DLL_LINKAGE CCampaignScenario
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string mapName; //*.h3m
|
|
||||||
std::string scenarioName; //from header. human-readble
|
|
||||||
ui32 packedMapSize; //generally not used
|
|
||||||
std::set<ui8> preconditionRegions; //what we need to conquer to conquer this one (stored as bitfield in h3c)
|
|
||||||
ui8 regionColor;
|
|
||||||
ui8 difficulty;
|
|
||||||
bool conquered;
|
|
||||||
|
|
||||||
std::string regionText;
|
|
||||||
|
|
||||||
struct DLL_LINKAGE SScenarioPrologEpilog
|
struct DLL_LINKAGE SScenarioPrologEpilog
|
||||||
{
|
{
|
||||||
bool hasPrologEpilog;
|
bool hasPrologEpilog;
|
||||||
@ -106,17 +96,23 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string mapName; //*.h3m
|
||||||
|
std::string scenarioName; //from header. human-readble
|
||||||
|
ui32 packedMapSize; //generally not used
|
||||||
|
std::set<ui8> preconditionRegions; //what we need to conquer to conquer this one (stored as bitfield in h3c)
|
||||||
|
ui8 regionColor;
|
||||||
|
ui8 difficulty;
|
||||||
|
bool conquered;
|
||||||
|
|
||||||
|
std::string regionText;
|
||||||
SScenarioPrologEpilog prolog, epilog;
|
SScenarioPrologEpilog prolog, epilog;
|
||||||
|
|
||||||
CScenarioTravel travelOptions;
|
CScenarioTravel travelOptions;
|
||||||
|
|
||||||
std::vector<CGHeroInstance *> crossoverHeroes;
|
std::vector<CGHeroInstance *> crossoverHeroes;
|
||||||
|
|
||||||
const CGHeroInstance * strongestHero(PlayerColor owner) const;
|
const CGHeroInstance * strongestHero(PlayerColor owner) const;
|
||||||
|
|
||||||
void loadPreconditionRegions(ui32 regions);
|
void loadPreconditionRegions(ui32 regions);
|
||||||
void prepareCrossoverHeroes(std::vector<CGHeroInstance *> heroes);
|
void prepareCrossoverHeroes(std::vector<CGHeroInstance *> heroes);
|
||||||
|
|
||||||
bool isNotVoid() const;
|
bool isNotVoid() const;
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h, const int formatVersion)
|
template <typename Handler> void serialize(Handler &h, const int formatVersion)
|
||||||
|
@ -24,8 +24,6 @@ class CGameHandler;
|
|||||||
class CVCMIServer;
|
class CVCMIServer;
|
||||||
class CGameState;
|
class CGameState;
|
||||||
struct StartInfo;
|
struct StartInfo;
|
||||||
class CCPPObjectScript;
|
|
||||||
class CScriptCallback;
|
|
||||||
struct BattleResult;
|
struct BattleResult;
|
||||||
struct BattleAttack;
|
struct BattleAttack;
|
||||||
struct BattleStackAttacked;
|
struct BattleStackAttacked;
|
||||||
@ -286,7 +284,6 @@ public:
|
|||||||
bool sacrificeArtifact(const IMarket * m, const CGHeroInstance * hero, ArtifactPosition slot);
|
bool sacrificeArtifact(const IMarket * m, const CGHeroInstance * hero, ArtifactPosition slot);
|
||||||
void spawnWanderingMonsters(CreatureID creatureID);
|
void spawnWanderingMonsters(CreatureID creatureID);
|
||||||
friend class CVCMIServer;
|
friend class CVCMIServer;
|
||||||
friend class CScriptCallback;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::list<PlayerColor> generatePlayerTurnOrder() const;
|
std::list<PlayerColor> generatePlayerTurnOrder() const;
|
||||||
|
Reference in New Issue
Block a user