1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

Completely remove IGameCallback class

- CClient now inherits directly from CPrivilegedInfoCallback, like
IGameCallback did before. However CClient no longer needs dummy
implementation of IGameEventCallback
- CGObjectInstance hierarchy now uses CPrivilegedInfoCallback for
callback. Actual events can only be emitted in calls that receive
IGameEventCallback pointer, e.g. heroVisit
- CGameHandler now inherits directly from both CPrivilegedInfoCallback
and IGameEventCallback as it did before via IGameCallback
This commit is contained in:
Ivan Savenko
2025-05-13 15:24:45 +03:00
parent f7d08a7288
commit 716da918f8
109 changed files with 854 additions and 933 deletions

View File

@@ -68,7 +68,7 @@ public:
/// list of players currently making turn. Usually - just one, except for simturns
std::set<PlayerColor> actingPlayers;
CGameState(IGameCallback * callback);
CGameState(CPrivilegedInfoCallback * callback);
virtual ~CGameState();
CGameState & gameState() final { return *this; }
@@ -76,7 +76,7 @@ public:
void preInit(Services * services);
void init(const IMapService * mapService, StartInfo * si, Load::ProgressAccumulator &, bool allowSavingRandomMap = true);
void init(const IMapService * mapService, StartInfo * si, vstd::RNG & randomGenerator, Load::ProgressAccumulator &, bool allowSavingRandomMap = true);
void updateOnLoad(StartInfo * si);
ui32 day; //total number of days in game
@@ -94,10 +94,10 @@ public:
bool giveHeroArtifact(CGHeroInstance * h, const ArtifactID & aid);
/// picks next free hero type of the H3 hero init sequence -> chosen starting hero, then unused hero type randomly
HeroTypeID pickNextHeroType(const PlayerColor & owner);
HeroTypeID pickNextHeroType(vstd::RNG & randomGenerator, const PlayerColor & owner);
void apply(CPackForClient & pack);
BattleField battleGetBattlefieldType(int3 tile, vstd::RNG & rand);
BattleField battleGetBattlefieldType(int3 tile, vstd::RNG & randomGenerator);
void fillUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo &out) const override;
PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2) const override;
@@ -107,10 +107,10 @@ public:
std::vector<const CGObjectInstance*> guardingCreatures (int3 pos) const;
/// Gets a artifact ID randomly and removes the selected artifact from this handler.
ArtifactID pickRandomArtifact(vstd::RNG & rand, std::optional<EArtifactClass> type);
ArtifactID pickRandomArtifact(vstd::RNG & rand, std::function<bool(ArtifactID)> accepts);
ArtifactID pickRandomArtifact(vstd::RNG & rand, std::optional<EArtifactClass> type, std::function<bool(ArtifactID)> accepts);
ArtifactID pickRandomArtifact(vstd::RNG & rand, std::set<ArtifactID> filtered);
ArtifactID pickRandomArtifact(vstd::RNG & randomGenerator, std::optional<EArtifactClass> type);
ArtifactID pickRandomArtifact(vstd::RNG & randomGenerator, std::function<bool(ArtifactID)> accepts);
ArtifactID pickRandomArtifact(vstd::RNG & randomGenerator, std::optional<EArtifactClass> type, std::function<bool(ArtifactID)> accepts);
ArtifactID pickRandomArtifact(vstd::RNG & randomGenerator, std::set<ArtifactID> filtered);
/// Creates instance of spell scroll artifact with provided spell
CArtifactInstance * createScroll(const SpellID & spellId);
@@ -165,16 +165,9 @@ public:
static int getDate(int day, Date mode);
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
// ----- getters, setters -----
/// This RNG should only be used inside GS or CPackForClient-derived applyGs
/// If this doesn't work for your code that mean you need a new netpack
///
/// Client-side must use vstd::RNG::getDefault which is not serialized
///
/// CGameHandler have it's own getter for vstd::RNG::getDefault
/// Any server-side code outside of GH must use vstd::RNG::getDefault
vstd::RNG & getRandomGenerator();
#if SCRIPTING_ENABLED
scripting::Pool * getGlobalContextPool() const override;
#endif
void saveGame(CSaveFile & file) const;
void loadGame(CLoadFile & file);
@@ -206,24 +199,24 @@ public:
private:
// ----- initialization -----
void initNewGame(const IMapService * mapService, bool allowSavingRandomMap, Load::ProgressAccumulator & progressTracking);
void initNewGame(const IMapService * mapService, vstd::RNG & randomGenerator, bool allowSavingRandomMap, Load::ProgressAccumulator & progressTracking);
void initGlobalBonuses();
void initGrailPosition();
void initRandomFactionsForPlayers();
void initGrailPosition(vstd::RNG & randomGenerator);
void initRandomFactionsForPlayers(vstd::RNG & randomGenerator);
void initOwnedObjects();
void randomizeMapObjects();
void randomizeMapObjects(vstd::RNG & randomGenerator);
void initPlayerStates();
void placeStartingHeroes();
void placeStartingHeroes(vstd::RNG & randomGenerator);
void placeStartingHero(const PlayerColor & playerColor, const HeroTypeID & heroTypeId, int3 townPos);
void removeHeroPlaceholders();
void initDifficulty();
void initHeroes();
void initHeroes(vstd::RNG & randomGenerator);
void placeHeroesInTowns();
void initFogOfWar();
void initStartingBonus();
void initTowns();
void initTownNames();
void initMapObjects();
void initStartingBonus(vstd::RNG & randomGenerator);
void initTowns(vstd::RNG & randomGenerator);
void initTownNames(vstd::RNG & randomGenerator);
void initMapObjects(vstd::RNG & randomGenerator);
void initVisitingAndGarrisonedHeroes();
void initCampaign();
@@ -238,7 +231,7 @@ private:
CGHeroInstance * getUsedHero(const HeroTypeID & hid) const;
bool isUsedHero(const HeroTypeID & hid) const; //looks in heroes and prisons
std::set<HeroTypeID> getUnusedAllowedHeroes(bool alsoIncludeNotAllowed = false) const;
HeroTypeID pickUnusedHeroTypeRandomly(const PlayerColor & owner); // picks a unused hero type randomly
HeroTypeID pickUnusedHeroTypeRandomly(vstd::RNG & randomGenerator, const PlayerColor & owner); // picks a unused hero type randomly
UpgradeInfo fillUpgradeInfo(const CStackInstance &stack) const;
// ---- data -----
@@ -247,7 +240,7 @@ private:
/// Pointer to campaign state manager. Nullptr for single scenarios
std::unique_ptr<CGameStateCampaign> campaign;
friend class IGameCallback;
friend class CPrivilegedInfoCallback;
friend class CMapHandler;
friend class CGameHandler;
};