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

map objects hierarchy now uses IGameInfoCallback

This commit is contained in:
Ivan Savenko
2025-05-14 15:50:13 +03:00
parent 6f20235d07
commit 4d4da0454f
111 changed files with 485 additions and 507 deletions

View File

@@ -14,7 +14,7 @@
#include "../Goals/Goals.h"
#include "../AIGateway.h"
#include "../Engine/Nullkiller.h"
#include "../../../lib/callback/CGameInfoCallback.h"
#include "../../../lib/callback/IGameInfoCallback.h"
#include "../../../lib/mapping/CMap.h"
#include "../../../lib/mapObjects/MapObjects.h"
#include "../../../lib/pathfinder/CPathfinder.h"
@@ -121,7 +121,7 @@ void AINodeStorage::initialize(const PathfinderOptions & options, const CGameSta
//TODO: fix this code duplication with NodeStorage::initialize, problem is to keep `resetTile` inline
const PlayerColor fowPlayer = ai->playerID;
const auto & fow = static_cast<const CGameInfoCallback *>(gs)->getPlayerTeam(fowPlayer)->fogOfWarMap;
const auto & fow = static_cast<const IGameInfoCallback *>(gs)->getPlayerTeam(fowPlayer)->fogOfWarMap;
const int3 sizes = gs->getMapSize();
//Each thread gets different x, but an array of y located next to each other in memory

View File

@@ -11,7 +11,7 @@
#include "AINodeStorage.h"
#include "Actions/TownPortalAction.h"
#include "../Goals/Goals.h"
#include "../../../lib/callback/CGameInfoCallback.h"
#include "../../../lib/callback/IGameInfoCallback.h"
#include "../../../lib/mapping/CMap.h"
#include "../../../lib/mapObjects/MapObjects.h"
#include "../../../lib/pathfinder/CPathfinder.h"
@@ -33,7 +33,7 @@ void AINodeStorage::initialize(const PathfinderOptions & options, const CGameSta
{
int3 pos;
const int3 sizes = gs->getMapSize();
const auto & fow = static_cast<const CGameInfoCallback *>(gs)->getPlayerTeam(hero->tempOwner)->fogOfWarMap;
const auto & fow = static_cast<const IGameInfoCallback *>(gs)->getPlayerTeam(hero->tempOwner)->fogOfWarMap;
const PlayerColor player = hero->tempOwner;
//make 200% sure that these are loop invariants (also a bit shorter code), let compiler do the rest(loop unswitching)

View File

@@ -475,7 +475,7 @@ void ApplyFirstClientNetPackVisitor::visitRemoveObject(RemoveObject & pack)
{
//below line contains little cheat for AI so it will be aware of deletion of enemy heroes that moved or got re-covered by FoW
//TODO: loose requirements as next AI related crashes appear, for example another pack.player collects object that got re-covered by FoW, unsure if AI code workarounds this
if(gs.isVisible(o, i->first) || (!cl.getPlayerState(i->first)->human && o->ID == Obj::HERO && o->tempOwner != i->first))
if(gs.isVisibleFor(o, i->first) || (!cl.getPlayerState(i->first)->human && o->ID == Obj::HERO && o->tempOwner != i->first))
i->second->objectRemoved(o, pack.initiator);
}
@@ -540,8 +540,8 @@ void ApplyClientNetPackVisitor::visitTryMoveHero(TryMoveHero & pack)
if(i->first != PlayerColor::SPECTATOR && gs.checkForStandardLoss(i->first)) // Do not notify vanquished pack.player's interface
continue;
if(gs.isVisible(h->convertToVisitablePos(pack.start), i->first)
|| gs.isVisible(h->convertToVisitablePos(pack.end), i->first))
if(gs.isVisibleFor(h->convertToVisitablePos(pack.start), i->first)
|| gs.isVisibleFor(h->convertToVisitablePos(pack.end), i->first))
{
// pack.src and pack.dst of enemy hero move may be not visible => 'verbose' should be false
const bool verbose = cl.getPlayerRelations(i->first, player) != PlayerRelations::ENEMIES;
@@ -601,9 +601,9 @@ void ApplyClientNetPackVisitor::visitSetHeroesInTown(SetHeroesInTown & pack)
if(!i->first.isValidPlayer())
continue;
if(gs.isVisible(t, i->first) ||
(hGarr && gs.isVisible(hGarr, i->first)) ||
(hVisit && gs.isVisible(hVisit, i->first)))
if(gs.isVisibleFor(t, i->first) ||
(hGarr && gs.isVisibleFor(hGarr, i->first)) ||
(hVisit && gs.isVisibleFor(hVisit, i->first)))
{
cl.playerint[i->first]->heroInGarrisonChange(t);
}
@@ -650,7 +650,7 @@ void ApplyFirstClientNetPackVisitor::visitSetObjectProperty(SetObjectProperty &
//inform all players that see this object
for(auto it = cl.playerint.cbegin(); it != cl.playerint.cend(); ++it)
{
if(gs.isVisible(gs.getObjInstance(pack.id), it->first))
if(gs.isVisibleFor(gs.getObjInstance(pack.id), it->first))
callInterfaceIfPresent(cl, it->first, &IGameEventsReceiver::beforeObjectPropertyChanged, &pack);
}
@@ -667,7 +667,7 @@ void ApplyClientNetPackVisitor::visitSetObjectProperty(SetObjectProperty & pack)
//inform all players that see this object
for(auto it = cl.playerint.cbegin(); it != cl.playerint.cend(); ++it)
{
if(gs.isVisible(gs.getObjInstance(pack.id), it->first))
if(gs.isVisibleFor(gs.getObjInstance(pack.id), it->first))
callInterfaceIfPresent(cl, it->first, &IGameEventsReceiver::objectPropertyChanged, &pack);
}
@@ -1050,7 +1050,7 @@ void ApplyClientNetPackVisitor::visitNewObject(NewObject & pack)
for(auto i=cl.playerint.begin(); i!=cl.playerint.end(); i++)
{
if(gs.isVisible(obj, i->first))
if(gs.isVisibleFor(obj, i->first))
i->second->newObject(obj);
}

View File

@@ -14,7 +14,7 @@
#include "CCreatureHandler.h"
#include "GameLibrary.h"
#include "IGameSettings.h"
#include "callback/CGameInfoCallback.h"
#include "callback/IGameInfoCallback.h"
#include "entities/hero/CHeroHandler.h"
#include "mapObjects/CGHeroInstance.h"
#include "modding/ModScope.h"
@@ -707,7 +707,7 @@ void CCreatureSet::serializeJson(JsonSerializeFormat & handler, const std::strin
}
}
CStackInstance::CStackInstance(CGameInfoCallback *cb, bool isHypothetic)
CStackInstance::CStackInstance(IGameInfoCallback *cb, bool isHypothetic)
: CBonusSystemNode(isHypothetic)
, CStackBasicDescriptor(nullptr, 0)
, CArtifactSet(cb)
@@ -719,7 +719,7 @@ CStackInstance::CStackInstance(CGameInfoCallback *cb, bool isHypothetic)
setNodeType(STACK_INSTANCE);
}
CStackInstance::CStackInstance(CGameInfoCallback *cb, const CreatureID & id, TQuantity Count, bool isHypothetic)
CStackInstance::CStackInstance(IGameInfoCallback *cb, const CreatureID & id, TQuantity Count, bool isHypothetic)
: CStackInstance(cb, false)
{
setType(id);
@@ -1034,11 +1034,11 @@ const IBonusBearer* CStackInstance::getBonusBearer() const
return this;
}
CCommanderInstance::CCommanderInstance(CGameInfoCallback *cb)
CCommanderInstance::CCommanderInstance(IGameInfoCallback *cb)
:CStackInstance(cb)
{}
CCommanderInstance::CCommanderInstance(CGameInfoCallback *cb, const CreatureID & id)
CCommanderInstance::CCommanderInstance(IGameInfoCallback *cb, const CreatureID & id)
: CStackInstance(cb)
, name("Commando")
{

View File

@@ -78,7 +78,7 @@ class DLL_LINKAGE CStackInstance : public CBonusSystemNode, public CStackBasicDe
CArmedInstance * armyInstance = nullptr; //stack must be part of some army, army must be part of some object
CGameInfoCallback * getCallback() const final { return cb; }
IGameInfoCallback * getCallback() const final { return cb; }
TExpType totalExperience;//commander needs same amount of exp as hero
public:
@@ -146,8 +146,8 @@ public:
virtual int getLevel() const; //different for regular stack and commander
CreatureID getCreatureID() const; //-1 if not available
std::string getName() const; //plural or singular
CStackInstance(CGameInfoCallback *cb, bool isHypothetic = false);
CStackInstance(CGameInfoCallback *cb, const CreatureID & id, TQuantity count, bool isHypothetic = false);
CStackInstance(IGameInfoCallback *cb, bool isHypothetic = false);
CStackInstance(IGameInfoCallback *cb, const CreatureID & id, TQuantity count, bool isHypothetic = false);
virtual ~CStackInstance() = default;
void setType(const CreatureID & creID);
@@ -182,8 +182,8 @@ public:
std::vector <ui8> secondarySkills; //ID -> level
std::set <ui8> specialSkills;
//std::vector <CArtifactInstance *> arts;
CCommanderInstance(CGameInfoCallback *cb);
CCommanderInstance(CGameInfoCallback *cb, const CreatureID & id);
CCommanderInstance(IGameInfoCallback *cb);
CCommanderInstance(IGameInfoCallback *cb, const CreatureID & id);
void setAlive (bool alive);
void levelUp ();

View File

@@ -11,7 +11,7 @@
#include "CPlayerState.h"
#include "GameLibrary.h"
#include "callback/CGameInfoCallback.h"
#include "callback/IGameInfoCallback.h"
#include "mapObjects/CGHeroInstance.h"
#include "mapObjects/CGTownInstance.h"
#include "gameState/CGameState.h"
@@ -21,7 +21,7 @@
VCMI_LIB_NAMESPACE_BEGIN
PlayerState::PlayerState(CGameInfoCallback *cb)
PlayerState::PlayerState(IGameInfoCallback *cb)
: CBonusSystemNode(PLAYER)
, GameCallbackHolder(cb)
, color(-1)

View File

@@ -75,7 +75,7 @@ public:
std::optional<ui8> daysWithoutCastle;
TurnTimerInfo turnTimer;
PlayerState(CGameInfoCallback *cb);
PlayerState(IGameInfoCallback *cb);
~PlayerState();
std::string nodeName() const override;

View File

@@ -15,7 +15,7 @@
#include "bonuses/Limiters.h"
#include "bonuses/Updaters.h"
#include "../CStack.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../entities/artifact/CArtifact.h"
#include "../entities/building/TownFortifications.h"
#include "../filesystem/Filesystem.h"
@@ -156,7 +156,7 @@ struct RangeGenerator
std::function<int()> myRand;
};
std::unique_ptr<BattleInfo> BattleInfo::setupBattle(CGameInfoCallback *cb, const int3 & tile, TerrainId terrain, const BattleField & battlefieldType, BattleSideArray<const CArmedInstance *> armies, BattleSideArray<const CGHeroInstance *> heroes, const BattleLayout & layout, const CGTownInstance * town)
std::unique_ptr<BattleInfo> BattleInfo::setupBattle(IGameInfoCallback *cb, const int3 & tile, TerrainId terrain, const BattleField & battlefieldType, BattleSideArray<const CArmedInstance *> armies, BattleSideArray<const CGHeroInstance *> heroes, const BattleLayout & layout, const CGTownInstance * town)
{
CMP_stack cmpst;
auto currentBattle = std::make_unique<BattleInfo>(cb, layout);
@@ -458,13 +458,13 @@ CStack * BattleInfo::getStack(int stackID, bool onlyAlive)
return const_cast<CStack *>(battleGetStackByID(stackID, onlyAlive));
}
BattleInfo::BattleInfo(CGameInfoCallback *cb, const BattleLayout & layout):
BattleInfo::BattleInfo(IGameInfoCallback *cb, const BattleLayout & layout):
BattleInfo(cb)
{
*this->layout = layout;
}
BattleInfo::BattleInfo(CGameInfoCallback *cb)
BattleInfo::BattleInfo(IGameInfoCallback *cb)
:GameCallbackHolder(cb),
sides({SideInBattle(cb), SideInBattle(cb)}),
layout(std::make_unique<BattleLayout>()),

View File

@@ -74,8 +74,8 @@ public:
}
//////////////////////////////////////////////////////////////////////////
BattleInfo(CGameInfoCallback *cb, const BattleLayout & layout);
BattleInfo(CGameInfoCallback *cb);
BattleInfo(IGameInfoCallback *cb, const BattleLayout & layout);
BattleInfo(IGameInfoCallback *cb);
virtual ~BattleInfo();
const IBattleInfo * getBattle() const override;
@@ -164,7 +164,7 @@ public:
const CGHeroInstance * getHero(const PlayerColor & player) const; //returns fighting hero that belongs to given player
void localInit();
static std::unique_ptr<BattleInfo> setupBattle(CGameInfoCallback *cb, const int3 & tile, TerrainId, const BattleField & battlefieldType, BattleSideArray<const CArmedInstance *> armies, BattleSideArray<const CGHeroInstance *> heroes, const BattleLayout & layout, const CGTownInstance * town);
static std::unique_ptr<BattleInfo> setupBattle(IGameInfoCallback *cb, const int3 & tile, TerrainId, const BattleField & battlefieldType, BattleSideArray<const CArmedInstance *> armies, BattleSideArray<const CGHeroInstance *> heroes, const BattleLayout & layout, const CGTownInstance * town);
BattleSide whatSide(const PlayerColor & player) const;

View File

@@ -12,18 +12,18 @@
#include "../GameSettings.h"
#include "../GameLibrary.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../json/JsonNode.h"
#include "../mapObjects/CArmedInstance.h"
VCMI_LIB_NAMESPACE_BEGIN
BattleLayout BattleLayout::createDefaultLayout(CGameInfoCallback * cb, const CArmedInstance * attacker, const CArmedInstance * defender)
BattleLayout BattleLayout::createDefaultLayout(IGameInfoCallback * cb, const CArmedInstance * attacker, const CArmedInstance * defender)
{
return createLayout(cb, "default", attacker, defender);
}
BattleLayout BattleLayout::createLayout(CGameInfoCallback * cb, const std::string & layoutName, const CArmedInstance * attacker, const CArmedInstance * defender)
BattleLayout BattleLayout::createLayout(IGameInfoCallback * cb, const std::string & layoutName, const CArmedInstance * attacker, const CArmedInstance * defender)
{
const auto & loadHex = [](const JsonNode & node)
{

View File

@@ -17,7 +17,7 @@
VCMI_LIB_NAMESPACE_BEGIN
class CArmedInstance;
class CGameInfoCallback;
class IGameInfoCallback;
struct DLL_EXPORT BattleLayout
{
@@ -32,8 +32,8 @@ struct DLL_EXPORT BattleLayout
bool tacticsAllowed = false;
bool obstaclesAllowed = false;
static BattleLayout createDefaultLayout(CGameInfoCallback * cb, const CArmedInstance * attacker, const CArmedInstance * defender);
static BattleLayout createLayout(CGameInfoCallback * cb, const std::string & layoutName, const CArmedInstance * attacker, const CArmedInstance * defender);
static BattleLayout createDefaultLayout(IGameInfoCallback * cb, const CArmedInstance * attacker, const CArmedInstance * defender);
static BattleLayout createLayout(IGameInfoCallback * cb, const std::string & layoutName, const CArmedInstance * attacker, const CArmedInstance * defender);
};
VCMI_LIB_NAMESPACE_END

View File

@@ -10,7 +10,7 @@
#include "StdInc.h"
#include "SideInBattle.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../mapObjects/CGHeroInstance.h"
VCMI_LIB_NAMESPACE_BEGIN

View File

@@ -12,6 +12,7 @@
#include "../entities/building/CBuilding.h"
#include "../gameState/CGameState.h"
#include "../gameState/UpgradeInfo.h"
#include "../gameState/InfoAboutArmy.h"
#include "../gameState/TavernHeroesPool.h"
#include "../mapObjects/CGHeroInstance.h"
@@ -143,7 +144,7 @@ const CGObjectInstance* CGameInfoCallback::getObj(ObjectInstanceID objid, bool v
return nullptr;
}
if(!isVisible(ret, getPlayerID()) && ret->tempOwner != getPlayerID())
if(getPlayerID().has_value() && !isVisibleFor(ret, *getPlayerID()) && ret->tempOwner != getPlayerID())
{
if(verbose)
logGlobal->error("Cannot get object with id %d. Object is not visible.", objid.getNum());
@@ -184,6 +185,36 @@ void CGameInfoCallback::fillUpgradeInfo(const CArmedInstance *obj, SlotID stackP
ERROR_RET_IF(!canGetFullInfo(obj), "Cannot get info about not owned object!");
ERROR_RET_IF(!obj->hasStackAtSlot(stackPos), "There is no such stack!");
gameState().fillUpgradeInfo(obj, stackPos, out);
const auto & stack = obj->getStack(stackPos);
const CCreature *base = stack.getCreature();
UpgradeInfo ret(base->getId());
if (stack.getArmy()->ID == Obj::HERO)
{
auto hero = dynamic_cast<const CGHeroInstance *>(stack.getArmy());
hero->fillUpgradeInfo(ret, stack);
if (hero->getVisitedTown())
{
hero->getVisitedTown()->fillUpgradeInfo(ret, stack);
}
else
{
auto object = vstd::frontOrNull(getVisitableObjs(hero->visitablePos()));
auto upgradeSource = dynamic_cast<const ICreatureUpgrader*>(object);
if (object != hero && upgradeSource != nullptr)
upgradeSource->fillUpgradeInfo(ret, stack);
}
}
if (stack.getArmy()->ID == Obj::TOWN)
{
auto town = dynamic_cast<const CGTownInstance *>(stack.getArmy());
town->fillUpgradeInfo(ret, stack);
}
out = ret;
}
const StartInfo * CGameInfoCallback::getStartInfo() const
@@ -244,7 +275,7 @@ int CGameInfoCallback::howManyTowns(PlayerColor Player) const
bool CGameInfoCallback::getTownInfo(const CGObjectInstance * town, InfoAboutTown & dest, const CGObjectInstance * selectedObject) const
{
ERROR_RET_VAL_IF(!isVisible(town, getPlayerID()), "Town is not visible!", false); //it's not a town or it's not visible for layer
ERROR_RET_VAL_IF(getPlayerID().has_value() && !isVisibleFor(town, *getPlayerID()), "Town is not visible!", false); //it's not a town or it's not visible for layer
bool detailed = hasAccess(town->tempOwner);
if(town->ID == Obj::TOWN)
@@ -270,10 +301,10 @@ const IGameSettings & CGameInfoCallback::getSettings() const
return gameState().getSettings();
}
int3 CGameInfoCallback::guardingCreaturePosition (int3 pos) const //FIXME: redundant?
int3 CGameInfoCallback::guardingCreaturePosition (int3 pos) const
{
ERROR_RET_VAL_IF(!isVisible(pos), "Tile is not visible!", int3(-1,-1,-1));
return gameState().guardingCreaturePosition(pos);
return gameState().getMap().guardingCreaturePositions[pos.z][pos.x][pos.y];
}
std::vector<const CGObjectInstance*> CGameInfoCallback::getGuardingCreatures (int3 pos) const
@@ -413,24 +444,28 @@ int CGameInfoCallback::getDate(Date mode) const
return gameState().getDate(mode);
}
bool CGameInfoCallback::isVisible(int3 pos, const std::optional<PlayerColor> & Player) const
bool CGameInfoCallback::isVisibleFor(int3 pos, PlayerColor player) const
{
return gameState().isVisible(pos, Player);
return gameState().isVisibleFor(pos, player);
}
bool CGameInfoCallback::isVisible(int3 pos) const
{
return isVisible(pos, getPlayerID());
return getPlayerID().has_value() ?
gameState().isVisibleFor(pos, *getPlayerID()):
gameState().isVisible(pos);
}
bool CGameInfoCallback::isVisible(const CGObjectInstance * obj, const std::optional<PlayerColor> & Player) const
bool CGameInfoCallback::isVisibleFor(const CGObjectInstance * obj, PlayerColor player) const
{
return gameState().isVisible(obj, Player);
return gameState().isVisibleFor(obj, player);
}
bool CGameInfoCallback::isVisible(const CGObjectInstance *obj) const
{
return isVisible(obj, getPlayerID());
return getPlayerID().has_value() ?
gameState().isVisibleFor(obj, *getPlayerID()):
gameState().isVisible(obj);
}
std::vector <const CGObjectInstance *> CGameInfoCallback::getBlockingObjs( int3 pos ) const
@@ -500,7 +535,6 @@ std::vector<const CGHeroInstance *> CGameInfoCallback::getAvailableHeroes(const
{
ASSERT_IF_CALLED_WITH_PLAYER
std::vector<const CGHeroInstance *> ret;
//ERROR_RET_VAL_IF(!isOwnedOrVisited(townOrTavern), "Town or tavern must be owned or visited!", ret);
//TODO: town needs to be owned, advmap tavern needs to be visited; to be reimplemented when visit tracking is done
const CGTownInstance * town = getTown(townOrTavern->id);
@@ -685,17 +719,6 @@ int CGameInfoCallback::getHeroCount( PlayerColor player, bool includeGarrisoned
return ret;
}
bool CGameInfoCallback::isOwnedOrVisited(const CGObjectInstance *obj) const
{
if(canGetFullInfo(obj))
return true;
const TerrainTile *t = getTile(obj->visitablePos()); //get entrance tile
const ObjectInstanceID visitorID = t->visitableObjects.back(); //visitong hero if present or the object itself at last
const CGObjectInstance * visitor = getObj(visitorID);
return visitor->ID == Obj::HERO && canGetFullInfo(visitor); //owned or allied hero is a visitor
}
bool CGameInfoCallback::isPlayerMakingTurn(PlayerColor player) const
{
return gameState().actingPlayers.count(player);
@@ -778,7 +801,7 @@ std::vector<ObjectInstanceID> CGameInfoCallback::getVisibleTeleportObjects(std::
vstd::erase_if(ids, [&](const ObjectInstanceID & id) -> bool
{
const auto * obj = getObj(id, false);
return player != PlayerColor::UNFLAGGABLE && (!obj || !isVisible(obj->visitablePos(), player));
return player != PlayerColor::UNFLAGGABLE && (!obj || !isVisibleFor(obj->visitablePos(), player));
});
return ids;
}

View File

@@ -11,42 +11,10 @@
#include "IGameInfoCallback.h"
#include "../int3.h"
VCMI_LIB_NAMESPACE_BEGIN
struct PlayerSettings;
struct TerrainTile;
struct InfoAboutHero;
struct InfoAboutTown;
struct SThievesGuildInfo;
struct TeamState;
struct TurnTimerInfo;
struct ArtifactLocation;
class IGameSettings;
class PlayerState;
class UpgradeInfo;
class CMapHeader;
class CGameState;
class PathfinderConfig;
class CArtifactSet;
class CArmedInstance;
class CGTeleport;
class CGTownInstance;
class IMarket;
#if SCRIPTING_ENABLED
namespace scripting
{
class Pool;
}
#endif
namespace vstd
{
class RNG;
}
class Player;
class DLL_LINKAGE CGameInfoCallback : public IGameInfoCallback
{
@@ -54,120 +22,103 @@ protected:
bool hasAccess(std::optional<PlayerColor> playerId) const;
bool canGetFullInfo(const CGObjectInstance *obj) const; //true we player owns obj or ally owns obj or privileged mode
bool isOwnedOrVisited(const CGObjectInstance *obj) const;
public:
virtual CGameState & gameState() = 0;
virtual const CGameState & gameState() const = 0;
//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() const override;
const StartInfo * getInitialStartInfo() const override;
const StartInfo * getInitialStartInfo() const;
bool isAllowed(SpellID id) const override;
bool isAllowed(ArtifactID id) const override;
bool isAllowed(SecondarySkill id) const override;
const IGameSettings & getSettings() const;
const IGameSettings & getSettings() const override;
//player
std::optional<PlayerColor> getPlayerID() const override;
const Player * getPlayer(PlayerColor color) const override;
virtual const PlayerState * getPlayerState(PlayerColor color, bool verbose = true) const;
virtual int getResource(PlayerColor Player, GameResID which) const;
virtual PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2) const;
virtual void getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj); //get thieves' guild info obtainable while visiting given object
virtual EPlayerStatus getPlayerStatus(PlayerColor player, bool verbose = true) const; //-1 if no such player
virtual bool isPlayerMakingTurn(PlayerColor player) const; //player that currently makes move // TODO synchronous turns
virtual const PlayerSettings * getPlayerSettings(PlayerColor color) const;
virtual TurnTimerInfo getPlayerTurnTime(PlayerColor color) const;
virtual std::optional<PlayerColor> getPlayerID() const;
const Player * getPlayer(PlayerColor color) const;
const PlayerState * getPlayerState(PlayerColor color, bool verbose = true) const override;
int getResource(PlayerColor Player, GameResID which) const override;
PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2) const override;
void getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj);
EPlayerStatus getPlayerStatus(PlayerColor player, bool verbose = true) const override;
bool isPlayerMakingTurn(PlayerColor player) const;
const PlayerSettings * getPlayerSettings(PlayerColor color) const override;
TurnTimerInfo getPlayerTurnTime(PlayerColor color) const;
//map
virtual bool isVisible(int3 pos, const std::optional<PlayerColor> & Player) const;
virtual bool isVisible(const CGObjectInstance * obj, const std::optional<PlayerColor> & Player) const;
virtual bool isVisible(const CGObjectInstance * obj) const;
virtual bool isVisible(int3 pos) const;
bool isVisibleFor(int3 pos, PlayerColor player) const override;
bool isVisibleFor(const CGObjectInstance * obj, PlayerColor player) const override;
bool isVisible(const CGObjectInstance * obj) const;
bool isVisible(int3 pos) const;
//armed object
virtual void fillUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo &out) const;
void fillUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo &out) const;
//hero
const CGHeroInstance * getHero(ObjectInstanceID objid) const override;
virtual int getHeroCount(PlayerColor player, bool includeGarrisoned) const;
virtual bool getHeroInfo(const CGObjectInstance * hero, InfoAboutHero & dest, const CGObjectInstance * selectedObject = nullptr) const;
virtual int32_t getSpellCost(const spells::Spell * sp, const CGHeroInstance * caster) const; //when called during battle, takes into account creatures' spell cost reduction
virtual int64_t estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const; //estimates damage of given spell; returns 0 if spell causes no dmg
virtual const CArtifactInstance * getArtInstance(ArtifactInstanceID aid) const;
virtual const CGObjectInstance * getObjInstance(ObjectInstanceID oid) const;
virtual const CArtifactSet * getArtSet(const ArtifactLocation & loc) const;
//virtual const CGObjectInstance * getArmyInstance(ObjectInstanceID oid) const;
int getHeroCount(PlayerColor player, bool includeGarrisoned) const override;
bool getHeroInfo(const CGObjectInstance * hero, InfoAboutHero & dest, const CGObjectInstance * selectedObject = nullptr) const;
int32_t getSpellCost(const spells::Spell * sp, const CGHeroInstance * caster) const;
int64_t estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const;
const CArtifactInstance * getArtInstance(ArtifactInstanceID aid) const override;
const CGObjectInstance * getObjInstance(ObjectInstanceID oid) const override;
const CArtifactSet * getArtSet(const ArtifactLocation & loc) const;
//objects
const CGObjectInstance * getObj(ObjectInstanceID objid, bool verbose = true) const override;
virtual std::vector<const CGObjectInstance *> getBlockingObjs(int3 pos) const;
std::vector<const CGObjectInstance *> getVisitableObjs(int3 pos, bool verbose = true) const override;
std::vector<const CGObjectInstance *> getBlockingObjs(int3 pos) const;
std::vector<const CGObjectInstance *> getVisitableObjs(int3 pos, bool verbose = true) const;
std::vector<const CGObjectInstance *> getAllVisitableObjs() const;
virtual std::vector<const CGObjectInstance *> getFlaggableObjects(int3 pos) const;
virtual const CGObjectInstance * getTopObj(int3 pos) const;
virtual PlayerColor getOwner(ObjectInstanceID heroID) const;
virtual const IMarket * getMarket(ObjectInstanceID objid) const;
std::vector<const CGObjectInstance *> getFlaggableObjects(int3 pos) const;
const CGObjectInstance * getTopObj(int3 pos) const override;
PlayerColor getOwner(ObjectInstanceID heroID) const;
const IMarket * getMarket(ObjectInstanceID objid) const;
//map
virtual int3 guardingCreaturePosition (int3 pos) const;
virtual std::vector<const CGObjectInstance*> getGuardingCreatures (int3 pos) const;
virtual bool isTileGuardedUnchecked(int3 tile) const;
virtual const CMapHeader * getMapHeader()const;
virtual int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map
virtual const TerrainTile * getTile(int3 tile, bool verbose = true) const;
virtual const TerrainTile * getTileUnchecked(int3 tile) const;
virtual bool isInTheMap(const int3 &pos) const;
virtual void getVisibleTilesInRange(std::unordered_set<int3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const;
virtual void calculatePaths(const std::shared_ptr<PathfinderConfig> & config) const;
virtual EDiggingStatus getTileDigStatus(int3 tile, bool verbose = true) const;
int3 guardingCreaturePosition (int3 pos) const;
std::vector<const CGObjectInstance*> getGuardingCreatures (int3 pos) const;
bool isTileGuardedUnchecked(int3 tile) const;
const CMapHeader * getMapHeader()const override;
int3 getMapSize() const override;
const TerrainTile * getTile(int3 tile, bool verbose = true) const override;
const TerrainTile * getTileUnchecked(int3 tile) const override;
bool isInTheMap(const int3 &pos) const override;
void getVisibleTilesInRange(std::unordered_set<int3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const;
void calculatePaths(const std::shared_ptr<PathfinderConfig> & config) const override;
EDiggingStatus getTileDigStatus(int3 tile, bool verbose = true) const override;
//town
virtual const CGTownInstance* getTown(ObjectInstanceID objid) const;
virtual int howManyTowns(PlayerColor Player) const;
//virtual const CGTownInstance * getTownInfo(int val, bool mode)const; //mode = 0 -> val = player town serial; mode = 1 -> val = object id (serial)
virtual std::vector<const CGHeroInstance *> getAvailableHeroes(const CGObjectInstance * townOrTavern) const; //heroes that can be recruited
virtual std::string getTavernRumor(const CGObjectInstance * townOrTavern) const;
virtual EBuildingState canBuildStructure(const CGTownInstance *t, BuildingID ID);//// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements
virtual bool getTownInfo(const CGObjectInstance * town, InfoAboutTown & dest, const CGObjectInstance * selectedObject = nullptr) const;
const CGTownInstance* getTown(ObjectInstanceID objid) const override;
int howManyTowns(PlayerColor Player) const;
std::vector<const CGHeroInstance *> getAvailableHeroes(const CGObjectInstance * townOrTavern) const;
std::string getTavernRumor(const CGObjectInstance * townOrTavern) const;
EBuildingState canBuildStructure(const CGTownInstance *t, BuildingID ID);
bool getTownInfo(const CGObjectInstance * town, InfoAboutTown & dest, const CGObjectInstance * selectedObject = nullptr) const;
//from gs
virtual const TeamState *getTeam(TeamID teamID) const;
virtual const TeamState *getPlayerTeam(PlayerColor color) const;
//virtual EBuildingState canBuildStructure(const CGTownInstance *t, BuildingID ID) const;// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements
const TeamState *getTeam(TeamID teamID) const override;
const TeamState *getPlayerTeam(PlayerColor color) const override;
//teleport
virtual std::vector<ObjectInstanceID> getVisibleTeleportObjects(std::vector<ObjectInstanceID> ids, PlayerColor player) const;
virtual std::vector<ObjectInstanceID> getTeleportChannelEntrances(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
virtual std::vector<ObjectInstanceID> getTeleportChannelExits(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
virtual ETeleportChannelType getTeleportChannelType(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
virtual bool isTeleportChannelImpassable(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
virtual bool isTeleportChannelBidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
virtual bool isTeleportChannelUnidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
virtual bool isTeleportEntrancePassable(const CGTeleport * obj, PlayerColor player) const;
std::vector<ObjectInstanceID> getVisibleTeleportObjects(std::vector<ObjectInstanceID> ids, PlayerColor player) const override;
std::vector<ObjectInstanceID> getTeleportChannelEntrances(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const override;
std::vector<ObjectInstanceID> getTeleportChannelExits(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const override;
ETeleportChannelType getTeleportChannelType(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
bool isTeleportChannelImpassable(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const override;
bool isTeleportChannelBidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const override;
bool isTeleportChannelUnidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const override;
bool isTeleportEntrancePassable(const CGTeleport * obj, PlayerColor player) const override;
//used for random spawns
void getFreeTiles(std::vector<int3> &tiles) const;
void getTilesInRange(std::unordered_set<int3> & tiles, const int3 & pos, int radius, ETileVisibility mode, std::optional<PlayerColor> player = std::optional<PlayerColor>(), int3::EDistanceFormula formula = int3::DIST_2D) const override;
void getAllTiles(std::unordered_set<int3> &tiles, std::optional<PlayerColor> player, int level, std::function<bool(const TerrainTile *)> filter) const override;
//mode 1 - only unrevealed tiles; mode 0 - all, mode -1 - only revealed
void getTilesInRange(std::unordered_set<int3> & tiles,
const int3 & pos,
int radius,
ETileVisibility mode,
std::optional<PlayerColor> player = std::optional<PlayerColor>(),
int3::EDistanceFormula formula = int3::DIST_2D) const;
//returns all tiles on given level (-1 - both levels, otherwise number of level)
void getAllTiles(std::unordered_set<int3> &tiles, std::optional<PlayerColor> player, int level, std::function<bool(const TerrainTile *)> filter) const;
//gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant
void pickAllowedArtsSet(std::vector<ArtifactID> & out, vstd::RNG & rand);
void pickAllowedArtsSet(std::vector<ArtifactID> & out, vstd::RNG & rand) override;
void getAllowedSpells(std::vector<SpellID> &out, std::optional<ui16> level = std::nullopt);
#if SCRIPTING_ENABLED
virtual scripting::Pool * getGlobalContextPool() const;
virtual scripting::Pool * getGlobalContextPool() const override;
#endif
};

View File

@@ -38,7 +38,7 @@ std::vector < const CGTownInstance *> CPlayerSpecificInfoCallback::getTownsInfo(
{
for(const auto & town : i.second.getTowns())
{
if(i.first == getPlayerID() || (!onlyOur && isVisible(town, getPlayerID())))
if(i.first == getPlayerID() || (!onlyOur && isVisibleFor(town, *getPlayerID())))
{
ret.push_back(town);
}

View File

@@ -11,14 +11,14 @@
VCMI_LIB_NAMESPACE_BEGIN
class CGameInfoCallback;
class IGameInfoCallback;
class DLL_LINKAGE GameCallbackHolder
{
public:
CGameInfoCallback * cb;
IGameInfoCallback * cb;
explicit GameCallbackHolder(CGameInfoCallback *cb):
explicit GameCallbackHolder(IGameInfoCallback *cb):
cb(cb)
{}
};

View File

@@ -11,92 +11,156 @@
#include "../constants/EntityIdentifiers.h"
#include "../constants/Enumerations.h"
#include "../int3.h"
VCMI_LIB_NAMESPACE_BEGIN
class int3;
struct StartInfo;
class CGHeroInstance;
class CGObjectInstance;
class Player;
struct PlayerSettings;
struct TerrainTile;
struct InfoAboutHero;
struct InfoAboutTown;
struct TeamState;
struct TurnTimerInfo;
struct ArtifactLocation;
class IGameSettings;
class PlayerState;
class UpgradeInfo;
class CMapHeader;
class CGameState;
class PathfinderConfig;
class CArtifactSet;
class CArmedInstance;
class CGTeleport;
class CGTownInstance;
class IMarket;
#if SCRIPTING_ENABLED
namespace scripting
{
class Pool;
}
#endif
namespace vstd
{
class RNG;
}
/// Provide interfaces through which map objects can access game state data
/// TODO: currently it is also used as Environment::GameCb. Consider separating these two interfaces
class DLL_LINKAGE IGameInfoCallback : boost::noncopyable
{
public:
//TODO: all other public methods of CGameInfoCallback
~IGameInfoCallback() = default;
// //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
/// Access underlying non-const gamestate
/// TODO: remove ASAP
virtual CGameState & gameState() = 0;
/// Access underlying gamestate
/// TODO: remove
virtual const CGameState & gameState() const = 0;
/// Returns current date:
/// DAY - number of days since start of the game (1..inf)
/// DAY_OF_WEEK - number of days since start of the week (1..7)
/// WEEK - number of week within month (1..4)
/// MONTH - current month (1..inf)
/// DAY_OF_MONTH - number of day within current month, (1..28)
virtual int getDate(Date mode=Date::DAY)const = 0;
/// Return pointer to static map header for current map
virtual const CMapHeader * getMapHeader()const = 0;
/// Returns post-randomized startin information on current game
virtual const StartInfo * getStartInfo() const = 0;
virtual const StartInfo * getInitialStartInfo() const = 0;
/// Returns true if corresponding spell is allowed, and not banned in map settings
virtual bool isAllowed(SpellID id) const = 0;
/// Returns true if corresponding artifact is allowed, and not banned in map settings
virtual bool isAllowed(ArtifactID id) const = 0;
/// Returns true if corresponding secondary skill is allowed, and not banned in map settings
virtual bool isAllowed(SecondarySkill id) const = 0;
//player
virtual std::optional<PlayerColor> getPlayerID() const = 0;
virtual const Player * getPlayer(PlayerColor color) const = 0;
// virtual int getResource(PlayerColor Player, EGameResID which) const = 0;
// bool isVisible(int3 pos) const;
// PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2) const;
// void getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj); //get thieves' guild info obtainable while visiting given object
// EPlayerStatus getPlayerStatus(PlayerColor player, bool verbose = true) const; //-1 if no such player
// const PlayerSettings * getPlayerSettings(PlayerColor color) const;
/// Returns true if specified tile is visible for specific player. Player must be valid
virtual bool isVisibleFor(int3 pos, PlayerColor player) const = 0;
/// Returns true if specified object is visible for specific player. Player must be valid
virtual bool isVisibleFor(const CGObjectInstance * obj, PlayerColor player) const = 0;
// //armed object
// void fillUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo &out)const;
//// Returns game settings for current map
virtual const IGameSettings & getSettings() const = 0;
//hero
/// Returns dimesions for current map. 'z' coordinate indicates number of level (2 for maps with underground layer)
virtual int3 getMapSize() const = 0;
/// Returns true if tile with specified position exists within map
virtual bool isInTheMap(const int3 &pos) const = 0;
/// Returns pointer to specified team. Team must be valid
virtual const TeamState *getTeam(TeamID teamID) const = 0;
/// Returns pointer to specified team. Player must be valid. Players without belong to a team with single member
virtual const TeamState *getPlayerTeam(PlayerColor color) const = 0;
/// Returns current state of a specific player. Player must be valid
virtual const PlayerState * getPlayerState(PlayerColor color, bool verbose = true) const = 0;
/// Returns starting settings of a specified player. Player must be valid
virtual const PlayerSettings * getPlayerSettings(PlayerColor color) const = 0;
/// Returns relations (allies, enemies, etc) of two specified, valid players
virtual PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2) const = 0;
/// Returns number of wandering heroes or wandering and garrisoned heroes for specified player
virtual int getHeroCount(PlayerColor player, bool includeGarrisoned) const = 0;
/// Returns in-game status if specified player. Player must be valid
virtual EPlayerStatus getPlayerStatus(PlayerColor player, bool verbose = true) const = 0;
/// Returns amount of resource of a specific type owned by a specified player
virtual int getResource(PlayerColor Player, GameResID which) const = 0;
/// Returns pointer to hero using provided object ID. Returns null on failure
virtual const CGHeroInstance * getHero(ObjectInstanceID objid) const = 0;
// int getHeroCount(PlayerColor player, bool includeGarrisoned) const;
// bool getHeroInfo(const CGObjectInstance * hero, InfoAboutHero & dest, const CGObjectInstance * selectedObject = nullptr) const;
// int32_t getSpellCost(const spells::Spell * sp, const CGHeroInstance * caster) const; //when called during battle, takes into account creatures' spell cost reduction
// int64_t estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const; //estimates damage of given spell; returns 0 if spell causes no dmg
// const CArtifactInstance * getArtInstance(ArtifactInstanceID aid) const;
// const CGObjectInstance * getObjInstance(ObjectInstanceID oid) const;
// const CGObjectInstance * getArmyInstance(ObjectInstanceID oid) const;
//objects
/// Returns pointer to town using provided object ID. Returns null on failure
virtual const CGTownInstance* getTown(ObjectInstanceID objid) const = 0;
/// Returns pointer to object using provided object ID. Returns null on failure
virtual const CGObjectInstance * getObj(ObjectInstanceID objid, bool verbose = true) const = 0;
// std::vector <const CGObjectInstance * > getBlockingObjs(int3 pos) const;
virtual std::vector<const CGObjectInstance *> getVisitableObjs(int3 pos, bool verbose = true) const = 0;
// std::vector <const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
// const CGObjectInstance * getTopObj (int3 pos) const;
// PlayerColor getOwner(ObjectInstanceID heroID) const;
/// Returns pointer to object using provided object ID. Returns null on failure
virtual const CGObjectInstance * getObjInstance(ObjectInstanceID oid) const = 0;
/// Returns pointer to artifact using provided object ID. Returns null on failure
virtual const CArtifactInstance * getArtInstance(ArtifactInstanceID aid) const = 0;
//map
// int3 guardingCreaturePosition (int3 pos) const;
// std::vector<const CGObjectInstance*> getGuardingCreatures (int3 pos) const;
// const CMapHeader * getMapHeader()const;
// int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map
// const TerrainTile * getTile(int3 tile, bool verbose = true) const;
// bool isInTheMap(const int3 &pos) const;
/// Returns pointer to specified tile or nullptr on error
virtual const TerrainTile * getTile(int3 tile, bool verbose = true) const = 0;
/// Returns pointer to specified tile without checking for permissions. Avoid its usage!
virtual const TerrainTile * getTileUnchecked(int3 tile) const = 0;
/// Returns pointer to top-most object on specified tile, or nullptr on error
virtual const CGObjectInstance * getTopObj(int3 pos) const = 0;
/// Returns whether it is possible to dig for Grail on specified tile
virtual EDiggingStatus getTileDigStatus(int3 tile, bool verbose = true) const = 0;
/// Calculates pathfinding data into specified pathfinder config
virtual void calculatePaths(const std::shared_ptr<PathfinderConfig> & config) const = 0;
//town
// const CGTownInstance* getTown(ObjectInstanceID objid) const;
// int howManyTowns(PlayerColor Player) const;
// const CGTownInstance * getTownInfo(int val, bool mode)const; //mode = 0 -> val = player town serial; mode = 1 -> val = object id (serial)
// std::vector<const CGHeroInstance *> getAvailableHeroes(const CGObjectInstance * townOrTavern) const; //heroes that can be recruited
// std::string getTavernRumor(const CGObjectInstance * townOrTavern) const;
// EBuildingState canBuildStructure(const CGTownInstance *t, BuildingID ID);//// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements
// virtual bool getTownInfo(const CGObjectInstance * town, InfoAboutTown & dest, const CGObjectInstance * selectedObject = nullptr) const;
/// Returns all tiles within specified range with specific tile visibility mode
virtual void getTilesInRange(std::unordered_set<int3> & tiles, const int3 & pos, int radius, ETileVisibility mode, std::optional<PlayerColor> player = std::optional<PlayerColor>(), int3::EDistanceFormula formula = int3::DIST_2D) const = 0;
//from gs
// const TeamState *getTeam(TeamID teamID) const;
// const TeamState *getPlayerTeam(PlayerColor color) const;
// EBuildingState canBuildStructure(const CGTownInstance *t, BuildingID ID) const;// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements
/// returns all tiles on given level (-1 - both levels, otherwise number of level)
virtual void getAllTiles(std::unordered_set<int3> &tiles, std::optional<PlayerColor> player, int level, std::function<bool(const TerrainTile *)> filter) const = 0;
//teleport
// std::vector<ObjectInstanceID> getVisibleTeleportObjects(std::vector<ObjectInstanceID> ids, PlayerColor player) const;
// std::vector<ObjectInstanceID> getTeleportChannelEntrances(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
// std::vector<ObjectInstanceID> getTeleportChannelExits(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
// ETeleportChannelType getTeleportChannelType(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
// bool isTeleportChannelImpassable(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
// bool isTeleportChannelBidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
// bool isTeleportChannelUnidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
// bool isTeleportEntrancePassable(const CGTeleport * obj, PlayerColor player) const;
virtual std::vector<ObjectInstanceID> getVisibleTeleportObjects(std::vector<ObjectInstanceID> ids, PlayerColor player) const = 0;
virtual std::vector<ObjectInstanceID> getTeleportChannelEntrances(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const = 0;
virtual std::vector<ObjectInstanceID> getTeleportChannelExits(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const = 0;
virtual bool isTeleportChannelImpassable(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const = 0;
virtual bool isTeleportChannelBidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const = 0;
virtual bool isTeleportChannelUnidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const = 0;
virtual bool isTeleportEntrancePassable(const CGTeleport * obj, PlayerColor player) const = 0;
/// gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant
virtual void pickAllowedArtsSet(std::vector<ArtifactID> & out, vstd::RNG & rand) = 0;
#if SCRIPTING_ENABLED
virtual scripting::Pool * getGlobalContextPool() const = 0;
#endif
};
VCMI_LIB_NAMESPACE_END

View File

@@ -420,7 +420,7 @@ std::optional<ui8> CampaignState::getBonusID(CampaignScenarioID which) const
return chosenCampaignBonuses.at(which);
}
std::unique_ptr<CMap> CampaignState::getMap(CampaignScenarioID scenarioId, CGameInfoCallback * cb)
std::unique_ptr<CMap> CampaignState::getMap(CampaignScenarioID scenarioId, IGameInfoCallback * cb)
{
// FIXME: there is certainly better way to handle maps inside campaigns
if(scenarioId == CampaignScenarioID::NONE)

View File

@@ -28,7 +28,7 @@ class CMap;
class CMapHeader;
class CMapInfo;
class JsonNode;
class CGameInfoCallback;
class IGameInfoCallback;
class DLL_LINKAGE CampaignRegions
{
@@ -338,7 +338,7 @@ public:
/// Returns true if all available scenarios have been completed and campaign is finished
bool isCampaignFinished() const;
std::unique_ptr<CMap> getMap(CampaignScenarioID scenarioId, CGameInfoCallback * cb);
std::unique_ptr<CMap> getMap(CampaignScenarioID scenarioId, IGameInfoCallback * cb);
std::unique_ptr<CMapHeader> getMapHeader(CampaignScenarioID scenarioId) const;
std::shared_ptr<CMapInfo> getMapInfo(CampaignScenarioID scenarioId) const;

View File

@@ -43,7 +43,7 @@ class CCreature;
class CHero;
class CSpell;
class CSkill;
class CGameInfoCallback;
class IGameInfoCallback;
class CNonConstInfoCallback;
class ArtifactInstanceID : public StaticIdentifier<ArtifactInstanceID>

View File

@@ -11,11 +11,11 @@
#include "StdInc.h"
#include "ArtSlotInfo.h"
#include "../../callback/CGameInfoCallback.h"
#include "../../callback/IGameInfoCallback.h"
VCMI_LIB_NAMESPACE_BEGIN
ArtSlotInfo::ArtSlotInfo(CGameInfoCallback * cb)
ArtSlotInfo::ArtSlotInfo(IGameInfoCallback * cb)
: GameCallbackHolder(cb)
{
}

View File

@@ -21,7 +21,7 @@ struct DLL_LINKAGE ArtSlotInfo : public GameCallbackHolder
ArtifactInstanceID artifactID;
bool locked = false; //if locked, then artifact points to the combined artifact
explicit ArtSlotInfo(CGameInfoCallback * cb);
explicit ArtSlotInfo(IGameInfoCallback * cb);
ArtSlotInfo(const CArtifactInstance * artifact, bool locked);
const CArtifactInstance * getArt() const;

View File

@@ -13,7 +13,7 @@
VCMI_LIB_NAMESPACE_BEGIN
CArtifactFittingSet::CArtifactFittingSet(CGameInfoCallback *cb, ArtBearer bearer)
CArtifactFittingSet::CArtifactFittingSet(IGameInfoCallback *cb, ArtBearer bearer)
: CArtifactSet(cb)
, GameCallbackHolder(cb)
, bearer(bearer)

View File

@@ -18,13 +18,13 @@ VCMI_LIB_NAMESPACE_BEGIN
// Used to try on artifacts before the claimed changes have been applied
class DLL_LINKAGE CArtifactFittingSet : public CArtifactSet, public GameCallbackHolder
{
CGameInfoCallback * getCallback() const final
IGameInfoCallback * getCallback() const final
{
return cb;
}
public:
CArtifactFittingSet(CGameInfoCallback * cb, ArtBearer Bearer);
CArtifactFittingSet(IGameInfoCallback * cb, ArtBearer Bearer);
explicit CArtifactFittingSet(const CArtifactSet & artSet);
ArtBearer bearerType() const override;

View File

@@ -14,7 +14,7 @@
#include "CArtifact.h"
#include "CArtifactSet.h"
#include "../../callback/CGameInfoCallback.h"
#include "../../callback/IGameInfoCallback.h"
#include "../../gameState/CGameState.h"
VCMI_LIB_NAMESPACE_BEGIN
@@ -125,13 +125,13 @@ void CGrowingArtifactInstance::growingUp()
}
}
CArtifactInstance::CArtifactInstance(CGameInfoCallback *cb, const CArtifact * art)
CArtifactInstance::CArtifactInstance(IGameInfoCallback *cb, const CArtifact * art)
:CArtifactInstance(cb)
{
setType(art);
}
CArtifactInstance::CArtifactInstance(CGameInfoCallback *cb)
CArtifactInstance::CArtifactInstance(IGameInfoCallback *cb)
: CBonusSystemNode(ARTIFACT_INSTANCE)
, CCombinedArtifactInstance(cb)
{

View File

@@ -82,8 +82,8 @@ class DLL_LINKAGE CArtifactInstance final
ArtifactID artTypeID;
public:
CArtifactInstance(CGameInfoCallback *cb, const CArtifact * art);
CArtifactInstance(CGameInfoCallback *cb);
CArtifactInstance(IGameInfoCallback *cb, const CArtifact * art);
CArtifactInstance(IGameInfoCallback *cb);
void setType(const CArtifact * art);
std::string nodeName() const override;
ArtifactID getTypeId() const;

View File

@@ -184,7 +184,7 @@ CArtifactSet::ArtPlacementMap CArtifactSet::putArtifact(const ArtifactPosition &
return resArtPlacement;
}
CArtifactSet::CArtifactSet(CGameInfoCallback * cb)
CArtifactSet::CArtifactSet(IGameInfoCallback * cb)
:artifactsTransitionPos(cb)
{}

View File

@@ -40,11 +40,11 @@ public:
bool hasScroll(const SpellID & aid, bool onlyWorn = false) const;
bool isPositionFree(const ArtifactPosition & pos, bool onlyLockCheck = false) const;
virtual CGameInfoCallback * getCallback() const = 0;
virtual IGameInfoCallback * getCallback() const = 0;
virtual ArtBearer bearerType() const = 0;
virtual ArtPlacementMap putArtifact(const ArtifactPosition & slot, const CArtifactInstance * art);
virtual void removeArtifact(const ArtifactPosition & slot);
CArtifactSet(CGameInfoCallback * cb);
CArtifactSet(IGameInfoCallback * cb);
virtual ~CArtifactSet() = default;
template <typename Handler> void serialize(Handler &h)

View File

@@ -31,7 +31,7 @@
#include "../bonuses/Propagators.h"
#include "../bonuses/Updaters.h"
#include "../battle/BattleInfo.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../campaign/CampaignState.h"
#include "../constants/StringConstants.h"
#include "../entities/artifact/ArtifactUtils.h"
@@ -150,7 +150,7 @@ int CGameState::getDate(Date mode) const
return getDate(day, mode);
}
CGameState::CGameState(CGameInfoCallback * callback)
CGameState::CGameState(IGameInfoCallback * callback)
: GameCallbackHolder(callback)
{
heroesPool = std::make_unique<TavernHeroesPool>(this);
@@ -1066,46 +1066,7 @@ BattleField CGameState::battleGetBattlefieldType(int3 tile, vstd::RNG & randomGe
return BattleField(*RandomGeneratorUtil::nextItem(t.getTerrain()->battleFields, randomGenerator));
}
void CGameState::fillUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo &out) const
{
assert(obj);
assert(obj->hasStackAtSlot(stackPos));
out = fillUpgradeInfo(obj->getStack(stackPos));
}
UpgradeInfo CGameState::fillUpgradeInfo(const CStackInstance & stack) const
{
const CCreature *base = stack.getCreature();
UpgradeInfo ret(base->getId());
if (stack.getArmy()->ID == Obj::HERO)
{
auto hero = dynamic_cast<const CGHeroInstance *>(stack.getArmy());
hero->fillUpgradeInfo(ret, stack);
if (hero->getVisitedTown())
{
hero->getVisitedTown()->fillUpgradeInfo(ret, stack);
}
else
{
auto object = vstd::frontOrNull(getVisitableObjs(hero->visitablePos()));
auto upgradeSource = dynamic_cast<const ICreatureUpgrader*>(object);
if (object != hero && upgradeSource != nullptr)
upgradeSource->fillUpgradeInfo(ret, stack);
}
}
if (stack.getArmy()->ID == Obj::TOWN)
{
auto town = dynamic_cast<const CGTownInstance *>(stack.getArmy());
town->fillUpgradeInfo(ret, stack);
}
return ret;
}
PlayerRelations CGameState::getPlayerRelations( PlayerColor color1, PlayerColor color2 ) const
{
@@ -1187,29 +1148,21 @@ std::vector<const CGObjectInstance*> CGameState::guardingCreatures (int3 pos) co
pos.x++;
}
return guards;
}
int3 CGameState::guardingCreaturePosition (int3 pos) const
{
return getMap().guardingCreaturePositions[pos.z][pos.x][pos.y];
}
bool CGameState::isVisible(int3 pos, const std::optional<PlayerColor> & player) const
bool CGameState::isVisibleFor(int3 pos, PlayerColor player) const
{
if (!map->isInTheMap(pos))
return false;
if (!player)
return true;
if(player == PlayerColor::NEUTRAL)
return false;
if(player->isSpectator())
if(player.isSpectator())
return true;
return getPlayerTeam(*player)->fogOfWarMap[pos.z][pos.x][pos.y];
return getPlayerTeam(player)->fogOfWarMap[pos.z][pos.x][pos.y];
}
bool CGameState::isVisible(const CGObjectInstance * obj, const std::optional<PlayerColor> & player) const
bool CGameState::isVisibleFor(const CGObjectInstance * obj, PlayerColor player) const
{
if(!player)
return true;
@@ -1218,8 +1171,9 @@ bool CGameState::isVisible(const CGObjectInstance * obj, const std::optional<Pla
if (player == obj->tempOwner)
return true;
if(*player == PlayerColor::NEUTRAL) //-> TODO ??? needed?
if(player == PlayerColor::NEUTRAL) //-> TODO ??? needed?
return false;
//object is visible when at least one blocked tile is visible
for(int fy=0; fy < obj->getHeight(); ++fy)
{
@@ -1229,7 +1183,7 @@ bool CGameState::isVisible(const CGObjectInstance * obj, const std::optional<Pla
if ( map->isInTheMap(pos) &&
obj->coveringAt(pos) &&
isVisible(pos, *player))
isVisibleFor(pos, player))
return true;
}
}
@@ -1353,7 +1307,7 @@ bool CGameState::checkForVictory(const PlayerColor & player, const EventConditio
case EventCondition::CONTROL:
{
// list of players that need to control object to fulfull condition
// NOTE: cgameinfocallback specified explicitly in order to get const version
// NOTE: CGameInfoCallback specified explicitly in order to get const version
const auto * team = CGameInfoCallback::getPlayerTeam(player);
if (condition.objectID != ObjectInstanceID::NONE) // mode A - flag one specific object, like town

View File

@@ -68,7 +68,7 @@ public:
/// list of players currently making turn. Usually - just one, except for simturns
std::set<PlayerColor> actingPlayers;
CGameState(CGameInfoCallback * callback);
CGameState(IGameInfoCallback * callback);
virtual ~CGameState();
CGameState & gameState() final { return *this; }
@@ -99,11 +99,9 @@ public:
void apply(CPackForClient & pack);
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;
bool checkForVisitableDir(const int3 & src, const int3 & dst) const; //check if src tile is visitable from dst tile
void calculatePaths(const std::shared_ptr<PathfinderConfig> & config) const override;
int3 guardingCreaturePosition (int3 pos) const override;
std::vector<const CGObjectInstance*> guardingCreatures (int3 pos) const;
/// Gets a artifact ID randomly and removes the selected artifact from this handler.
@@ -135,7 +133,7 @@ public:
bool checkForStandardLoss(const PlayerColor & player) const; //checks if given player lost the game
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;
const IGameSettings & getSettings() const override;
StartInfo * getStartInfo()
{
@@ -145,7 +143,7 @@ public:
{
return scenarioOps.get();
}
const StartInfo * getInitialStartInfo() const final
const StartInfo * getInitialStartInfo() const
{
return initialOpts.get();
}
@@ -159,8 +157,8 @@ public:
return *map;
}
bool isVisible(int3 pos, const std::optional<PlayerColor> & player) const override;
bool isVisible(const CGObjectInstance * obj, const std::optional<PlayerColor> & player) const override;
bool isVisibleFor(int3 pos, const PlayerColor player) const override;
bool isVisibleFor(const CGObjectInstance * obj, const PlayerColor player) const override;
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
@@ -232,7 +230,6 @@ private:
bool isUsedHero(const HeroTypeID & hid) const; //looks in heroes and prisons
std::set<HeroTypeID> getUnusedAllowedHeroes(bool alsoIncludeNotAllowed = false) const;
HeroTypeID pickUnusedHeroTypeRandomly(vstd::RNG & randomGenerator, const PlayerColor & owner); // picks a unused hero type randomly
UpgradeInfo fillUpgradeInfo(const CStackInstance &stack) const;
// ---- data -----
Services * services;
@@ -240,7 +237,7 @@ private:
/// Pointer to campaign state manager. Nullptr for single scenarios
std::unique_ptr<CGameStateCampaign> campaign;
friend class CGameInfoCallback;
friend class IGameInfoCallback;
friend class CMapHandler;
friend class CGameHandler;
};

View File

@@ -366,16 +366,8 @@ void GameStatePackVisitor::visitRemoveObject(RemoveObject & pack)
gs.getPlayerState(pack.initiator)->destroyedObjects.insert(pack.objectID);
if(obj->getOwner().isValidPlayer())
{
gs.getPlayerState(obj->getOwner())->removeOwnedObject(obj); //object removed via map event or hero got beaten
FlaggableMapObject* flaggableObject = dynamic_cast<FlaggableMapObject*>(obj);
if(flaggableObject)
{
flaggableObject->markAsDeleted();
}
}
if(obj->ID == Obj::HERO) //remove beaten hero
{
auto beatenHero = dynamic_cast<CGHeroInstance*>(obj);
@@ -1080,8 +1072,6 @@ void GameStatePackVisitor::visitSetObjectProperty(SetObjectProperty & pack)
return;
}
auto * cai = dynamic_cast<CArmedInstance *>(obj);
if(pack.what == ObjProperty::OWNER && obj->asOwnable())
{
PlayerColor oldOwner = obj->getOwner();

View File

@@ -259,7 +259,7 @@ float Statistic::getMapExploredRatio(const CGameState * gs, PlayerColor player)
if(tile.blocked() && !tile.visitable())
continue;
if(gs->isVisible(int3(x, y, layer), player))
if(gs->isVisibleFor(int3(x, y, layer), player))
visible++;
numTiles++;
}

View File

@@ -10,12 +10,12 @@
#include "StdInc.h"
#include "QuestInfo.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../mapObjects/CQuest.h"
VCMI_LIB_NAMESPACE_BEGIN
const CQuest * QuestInfo::getQuest(CGameInfoCallback *cb) const
const CQuest * QuestInfo::getQuest(IGameInfoCallback *cb) const
{
auto questObject = dynamic_cast<const IQuestObject*>(getObject(cb));
assert(questObject);
@@ -23,12 +23,12 @@ const CQuest * QuestInfo::getQuest(CGameInfoCallback *cb) const
return &questObject->getQuest();
}
const CGObjectInstance * QuestInfo::getObject(CGameInfoCallback *cb) const
const CGObjectInstance * QuestInfo::getObject(IGameInfoCallback *cb) const
{
return cb->getObjInstance(obj);
}
int3 QuestInfo::getPosition(CGameInfoCallback *cb) const
int3 QuestInfo::getPosition(IGameInfoCallback *cb) const
{
return getObject(cb)->visitablePos();
}

View File

@@ -16,7 +16,7 @@ VCMI_LIB_NAMESPACE_BEGIN
class CQuest;
class CGObjectInstance;
class CGameInfoCallback;
class IGameInfoCallback;
struct DLL_LINKAGE QuestInfo //universal interface for human and AI
{
@@ -27,9 +27,9 @@ struct DLL_LINKAGE QuestInfo //universal interface for human and AI
: obj(Obj)
{}
const CQuest * getQuest(CGameInfoCallback *cb) const;
const CGObjectInstance * getObject(CGameInfoCallback *cb) const;
int3 getPosition(CGameInfoCallback *cb) const;
const CQuest * getQuest(IGameInfoCallback *cb) const;
const CGObjectInstance * getObject(IGameInfoCallback *cb) const;
int3 getPosition(IGameInfoCallback *cb) const;
bool operator== (const QuestInfo & qi) const
{

View File

@@ -18,7 +18,7 @@
#include "JsonBonus.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../constants/StringConstants.h"
#include "../GameLibrary.h"
#include "../CCreatureHandler.h"

View File

@@ -23,7 +23,7 @@ class RNG;
class ObjectTemplate;
class CGObjectInstance;
class IObjectInfo;
class CGameInfoCallback;
class IGameInfoCallback;
/// Class responsible for creation of objects of specific type & subtype
class DLL_LINKAGE AObjectTypeHandler : public boost::noncopyable
@@ -118,7 +118,7 @@ public:
/// Creates object and set up core properties (like ID/subID). Object is NOT initialized
/// to allow creating objects before game start (e.g. map loading)
virtual std::shared_ptr<CGObjectInstance> create(CGameInfoCallback * cb, std::shared_ptr<const ObjectTemplate> tmpl) const = 0;
virtual std::shared_ptr<CGObjectInstance> create(IGameInfoCallback * cb, std::shared_ptr<const ObjectTemplate> tmpl) const = 0;
/// Configures object properties. Should be re-entrable, resetting state of the object if necessarily
/// This should set remaining properties, including randomized or depending on map

View File

@@ -27,7 +27,7 @@ class CDefaultObjectTypeHandler : public AObjectTypeHandler
randomizeObject(castedObject, rng);
}
std::shared_ptr<CGObjectInstance> create(CGameInfoCallback * cb, std::shared_ptr<const ObjectTemplate> tmpl) const final
std::shared_ptr<CGObjectInstance> create(IGameInfoCallback * cb, std::shared_ptr<const ObjectTemplate> tmpl) const final
{
auto result = createObject(cb);
@@ -44,7 +44,7 @@ class CDefaultObjectTypeHandler : public AObjectTypeHandler
protected:
virtual void initializeObject(ObjectType * object) const {}
virtual void randomizeObject(ObjectType * object, vstd::RNG & rng) const {}
virtual std::shared_ptr<ObjectType> createObject(CGameInfoCallback * cb) const
virtual std::shared_ptr<ObjectType> createObject(IGameInfoCallback * cb) const
{
return std::make_shared<ObjectType>(cb);
}

View File

@@ -37,7 +37,7 @@ bool CRewardableConstructor::hasNameTextID() const
return !objectInfo.getParameters()["name"].isNull();
}
std::shared_ptr<CGObjectInstance> CRewardableConstructor::create(CGameInfoCallback * cb, std::shared_ptr<const ObjectTemplate> tmpl) const
std::shared_ptr<CGObjectInstance> CRewardableConstructor::create(IGameInfoCallback * cb, std::shared_ptr<const ObjectTemplate> tmpl) const
{
auto ret = std::make_shared<CRewardableObject>(cb);
preInitObject(ret.get());
@@ -55,7 +55,7 @@ void CRewardableConstructor::assignBonuses(std::vector<Bonus> & bonuses, MapObje
}
}
Rewardable::Configuration CRewardableConstructor::generateConfiguration(CGameInfoCallback * cb, vstd::RNG & rand, MapObjectID objectID, const std::map<std::string, JsonNode> & presetVariables) const
Rewardable::Configuration CRewardableConstructor::generateConfiguration(IGameInfoCallback * cb, vstd::RNG & rand, MapObjectID objectID, const std::map<std::string, JsonNode> & presetVariables) const
{
Rewardable::Configuration result;
result.variables.preset = presetVariables;

View File

@@ -28,13 +28,13 @@ class DLL_LINKAGE CRewardableConstructor : public AObjectTypeHandler
public:
bool hasNameTextID() const override;
std::shared_ptr<CGObjectInstance> create(CGameInfoCallback * cb, std::shared_ptr<const ObjectTemplate> tmpl = nullptr) const override;
std::shared_ptr<CGObjectInstance> create(IGameInfoCallback * cb, std::shared_ptr<const ObjectTemplate> tmpl = nullptr) const override;
void configureObject(CGObjectInstance * object, vstd::RNG & rng) const override;
std::unique_ptr<IObjectInfo> getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const override;
Rewardable::Configuration generateConfiguration(CGameInfoCallback * cb, vstd::RNG & rand, MapObjectID objectID, const std::map<std::string, JsonNode> & presetVariables) const;
Rewardable::Configuration generateConfiguration(IGameInfoCallback * cb, vstd::RNG & rand, MapObjectID objectID, const std::map<std::string, JsonNode> & presetVariables) const;
};
VCMI_LIB_NAMESPACE_END

View File

@@ -17,7 +17,7 @@
#include "../GameLibrary.h"
#include "../CConfigHandler.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../entities/faction/CTownHandler.h"
#include "../entities/hero/CHeroClass.h"
#include "../json/JsonUtils.h"
@@ -318,7 +318,7 @@ bool MarketInstanceConstructor::hasDescription() const
return !descriptionTextID.empty();
}
std::shared_ptr<CGMarket> MarketInstanceConstructor::createObject(CGameInfoCallback * cb) const
std::shared_ptr<CGMarket> MarketInstanceConstructor::createObject(IGameInfoCallback * cb) const
{
if(marketModes.size() == 1)
{

View File

@@ -137,7 +137,7 @@ class MarketInstanceConstructor : public CDefaultObjectTypeHandler<CGMarket>
void initTypeData(const JsonNode & config) override;
public:
std::shared_ptr<CGMarket> createObject(CGameInfoCallback * cb) const override;
std::shared_ptr<CGMarket> createObject(IGameInfoCallback * cb) const override;
void randomizeObject(CGMarket * object, vstd::RNG & rng) const override;
const std::set<EMarketMode> & availableModes() const;

View File

@@ -13,7 +13,7 @@
#include "../CCreatureHandler.h"
#include "../CPlayerState.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../entities/faction/CFaction.h"
#include "../entities/faction/CTown.h"
#include "../entities/faction/CTownHandler.h"
@@ -41,12 +41,12 @@ void CArmedInstance::randomizeArmy(FactionID type)
}
}
CArmedInstance::CArmedInstance(CGameInfoCallback *cb)
CArmedInstance::CArmedInstance(IGameInfoCallback *cb)
:CArmedInstance(cb, false)
{
}
CArmedInstance::CArmedInstance(CGameInfoCallback *cb, bool isHypothetic):
CArmedInstance::CArmedInstance(IGameInfoCallback *cb, bool isHypothetic):
CGObjectInstance(cb),
CBonusSystemNode(isHypothetic),
nonEvilAlignmentMix(this, Selector::type()(BonusType::NONEVIL_ALIGNMENT_MIX)), // Take Angelic Alliance troop-mixing freedom of non-evil units into account.

View File

@@ -50,8 +50,8 @@ public:
void restoreBonusSystem(CGameState & gs) override;
//////////////////////////////////////////////////////////////////////////
CArmedInstance(CGameInfoCallback *cb);
CArmedInstance(CGameInfoCallback *cb, bool isHypothetic);
CArmedInstance(IGameInfoCallback *cb);
CArmedInstance(IGameInfoCallback *cb, bool isHypothetic);
PlayerColor getOwner() const override
{

View File

@@ -15,7 +15,7 @@
#include "../texts/CGeneralTextHandler.h"
#include "../CConfigHandler.h"
#include "../IGameSettings.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../callback/IGameEventCallback.h"
#include "../gameState/CGameState.h"
#include "../mapObjectConstructors/CObjectClassesHandler.h"

View File

@@ -10,7 +10,7 @@
#include "StdInc.h"
#include "CGDwelling.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../callback/IGameEventCallback.h"
#include "../serializer/JsonSerializeFormat.h"
#include "../entities/faction/CTownHandler.h"
@@ -47,7 +47,7 @@ void CGDwellingRandomizationInfo::serializeJson(JsonSerializeFormat & handler)
}
}
CGDwelling::CGDwelling(CGameInfoCallback *cb):
CGDwelling::CGDwelling(IGameInfoCallback *cb):
CArmedInstance(cb)
{}

View File

@@ -39,7 +39,7 @@ public:
std::optional<CGDwellingRandomizationInfo> randomizationInfo; //random dwelling options; not serialized
TCreaturesSet creatures; //creatures[level] -> <vector of alternative ids (base creature and upgrades, creatures amount>
CGDwelling(CGameInfoCallback *cb);
CGDwelling(IGameInfoCallback *cb);
~CGDwelling() override;
const IOwnableObject * asOwnable() const final;

View File

@@ -15,7 +15,7 @@
#include <vcmi/spells/Spell.h>
#include <vstd/RNG.h>
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../callback/IGameEventCallback.h"
#include "../texts/CGeneralTextHandler.h"
#include "../TerrainHandler.h"
@@ -254,7 +254,7 @@ int CGHeroInstance::movementPointsLimitCached(bool onLand, const TurnInfo * ti)
return ti->getMovePointsLimitWater();
}
CGHeroInstance::CGHeroInstance(CGameInfoCallback * cb)
CGHeroInstance::CGHeroInstance(IGameInfoCallback * cb)
: CArmedInstance(cb),
CArtifactSet(cb),
tacticFormationEnabled(false),

View File

@@ -72,7 +72,7 @@ class DLL_LINKAGE CGHeroInstance : public CArmedInstance, public IBoatGenerator,
ui32 movement; //remaining movement points
bool inTownGarrison; // if hero is in town garrison
CGameInfoCallback * getCallback() const final { return cb; }
IGameInfoCallback * getCallback() const final { return cb; }
public:
//////////////////////////////////////////////////////////////////////////
@@ -281,7 +281,7 @@ public:
/// If this hero perishes, the scenario is failed
bool isMissionCritical() const;
CGHeroInstance(CGameInfoCallback *cb);
CGHeroInstance(IGameInfoCallback *cb);
virtual ~CGHeroInstance();
PlayerColor getOwner() const override;

View File

@@ -11,7 +11,7 @@
#include "StdInc.h"
#include "CGMarket.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../callback/IGameEventCallback.h"
#include "../texts/CGeneralTextHandler.h"
#include "../CCreatureHandler.h"
@@ -78,7 +78,7 @@ std::set<EMarketMode> CGMarket::availableModes() const
return getMarketHandler()->availableModes();
}
CGMarket::CGMarket(CGameInfoCallback *cb)
CGMarket::CGMarket(IGameInfoCallback *cb)
: CGObjectInstance(cb)
, IMarket(cb)
{}

View File

@@ -22,7 +22,7 @@ protected:
std::shared_ptr<MarketInstanceConstructor> getMarketHandler() const;
public:
CGMarket(CGameInfoCallback *cb);
CGMarket(IGameInfoCallback *cb);
///IObjectInterface
void onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const override; //open trading window
void initObj(vstd::RNG & rand) override;//set skills for trade

View File

@@ -14,7 +14,7 @@
#include "CGHeroInstance.h"
#include "ObjectTemplate.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../callback/IGameEventCallback.h"
#include "../gameState/CGameState.h"
#include "../texts/CGeneralTextHandler.h"
@@ -31,7 +31,7 @@
VCMI_LIB_NAMESPACE_BEGIN
//TODO: remove constructor
CGObjectInstance::CGObjectInstance(CGameInfoCallback *cb):
CGObjectInstance::CGObjectInstance(IGameInfoCallback *cb):
IObjectInterface(cb),
pos(-1,-1,-1),
ID(Obj::NO_OBJ),

View File

@@ -45,7 +45,7 @@ public:
std::string instanceName;
CGObjectInstance(CGameInfoCallback *cb);
CGObjectInstance(IGameInfoCallback *cb);
~CGObjectInstance() override;
MapObjectID getObjGroupIndex() const override;

View File

@@ -18,7 +18,7 @@
#include "../CSkillHandler.h"
#include "../StartInfo.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../callback/IGameEventCallback.h"
#include "../constants/StringConstants.h"
#include "../networkPacks/PacksForClient.h"

View File

@@ -11,7 +11,7 @@
#include "StdInc.h"
#include "CGResource.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../callback/IGameEventCallback.h"
#include "../mapObjectConstructors/CommonConstructors.h"
#include "../texts/CGeneralTextHandler.h"

View File

@@ -24,7 +24,7 @@
#include "../CPlayerState.h"
#include "../StartInfo.h"
#include "../TerrainHandler.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../callback/IGameEventCallback.h"
#include "../entities/building/CBuilding.h"
#include "../entities/faction/CTownHandler.h"
@@ -264,7 +264,7 @@ TownFortifications CGTownInstance::fortificationsLevel() const
return result;
}
CGTownInstance::CGTownInstance(CGameInfoCallback *cb):
CGTownInstance::CGTownInstance(IGameInfoCallback *cb):
CGDwelling(cb),
IMarket(cb),
built(0),

View File

@@ -207,7 +207,7 @@ public:
/// Returns true if provided war machine is available in any of built buildings of this town
bool isWarMachineAvailable(ArtifactID) const;
CGTownInstance(CGameInfoCallback *cb);
CGTownInstance(IGameInfoCallback *cb);
virtual ~CGTownInstance();
///IObjectInterface overrides

View File

@@ -17,7 +17,7 @@
#include "../texts/CGeneralTextHandler.h"
#include "CGCreature.h"
#include "../IGameSettings.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../callback/IGameEventCallback.h"
#include "../entities/artifact/CArtifact.h"
#include "../entities/hero/CHeroHandler.h"
@@ -158,7 +158,7 @@ void CQuest::completeQuest(IGameEventCallback & gameEvents, const CGHeroInstance
gameEvents.giveResources(h->getOwner(), -mission.resources);
}
void CQuest::addTextReplacements(const CGameInfoCallback * cb, MetaString & text, std::vector<Component> & components) const
void CQuest::addTextReplacements(const IGameInfoCallback * cb, MetaString & text, std::vector<Component> & components) const
{
if(mission.heroLevel > 0)
text.replaceNumber(mission.heroLevel);
@@ -257,7 +257,7 @@ void CQuest::addTextReplacements(const CGameInfoCallback * cb, MetaString & text
text.replaceNumber(lastDay - cb->getDate(Date::DAY));
}
void CQuest::getVisitText(const CGameInfoCallback * cb, MetaString &iwText, std::vector<Component> &components, bool firstVisit, const CGHeroInstance * h) const
void CQuest::getVisitText(const IGameInfoCallback * cb, MetaString &iwText, std::vector<Component> &components, bool firstVisit, const CGHeroInstance * h) const
{
bool failRequirements = (h ? !checkQuest(h) : true);
mission.loadComponents(components, h);
@@ -273,7 +273,7 @@ void CQuest::getVisitText(const CGameInfoCallback * cb, MetaString &iwText, std:
addTextReplacements(cb, iwText, components);
}
void CQuest::getRolloverText(const CGameInfoCallback * cb, MetaString &ms, bool onHover) const
void CQuest::getRolloverText(const IGameInfoCallback * cb, MetaString &ms, bool onHover) const
{
if(onHover)
ms.appendRawString("\n\n");
@@ -286,7 +286,7 @@ void CQuest::getRolloverText(const CGameInfoCallback * cb, MetaString &ms, bool
addTextReplacements(cb, ms, components);
}
void CQuest::getCompletionText(const CGameInfoCallback * cb, MetaString &iwText) const
void CQuest::getCompletionText(const IGameInfoCallback * cb, MetaString &iwText) const
{
iwText.appendRawString(completedText.toString());

View File

@@ -77,11 +77,11 @@ public:
static bool checkMissionArmy(const CQuest * q, const CCreatureSet * army);
bool checkQuest(const CGHeroInstance * h) const; //determines whether the quest is complete or not
void getVisitText(const CGameInfoCallback * cb, MetaString &text, std::vector<Component> & components, bool FirstVisit, const CGHeroInstance * h = nullptr) const;
void getCompletionText(const CGameInfoCallback * cb, MetaString &text) const;
void getRolloverText (const CGameInfoCallback * cb, MetaString &text, bool onHover) const; //hover or quest log entry
void getVisitText(const IGameInfoCallback * cb, MetaString &text, std::vector<Component> & components, bool FirstVisit, const CGHeroInstance * h = nullptr) const;
void getCompletionText(const IGameInfoCallback * cb, MetaString &text) const;
void getRolloverText (const IGameInfoCallback * cb, MetaString &text, bool onHover) const; //hover or quest log entry
void completeQuest(IGameEventCallback & gameEvents, const CGHeroInstance * h, bool allowFullArmyRemoval) const;
void addTextReplacements(const CGameInfoCallback * cb, MetaString &out, std::vector<Component> & components) const;
void addTextReplacements(const IGameInfoCallback * cb, MetaString &out, std::vector<Component> & components) const;
void addKillTargetReplacements(MetaString &out) const;
void defineQuestName();

View File

@@ -14,7 +14,7 @@
#include "../CPlayerState.h"
#include "../IGameSettings.h"
#include "../battle/BattleLayout.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../callback/IGameEventCallback.h"
#include "../gameState/CGameState.h"
#include "../mapObjectConstructors/AObjectTypeHandler.h"
@@ -355,7 +355,7 @@ void CRewardableObject::initObj(vstd::RNG & rand)
getObjectHandler()->configureObject(this, rand);
}
CRewardableObject::CRewardableObject(CGameInfoCallback *cb)
CRewardableObject::CRewardableObject(IGameInfoCallback *cb)
:CArmedInstance(cb)
{}

View File

@@ -77,7 +77,7 @@ public:
void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;
CRewardableObject(CGameInfoCallback *cb);
CRewardableObject(IGameInfoCallback *cb);
std::string getHoverText(PlayerColor player) const override;
std::string getHoverText(const CGHeroInstance * hero) const override;

View File

@@ -14,7 +14,7 @@
#include "CGHeroInstance.h"
#include "../CPlayerState.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../callback/IGameEventCallback.h"
#include "../gameState/CGameState.h"
#include "../mapObjectConstructors/FlaggableInstanceConstructor.h"

View File

@@ -140,7 +140,7 @@ int IMarket::availableUnits(const EMarketMode mode, const int marketItemSerial)
}
}
IMarket::IMarket(CGameInfoCallback *cb)
IMarket::IMarket(IGameInfoCallback *cb)
:altarArtifactsStorage(std::make_unique<CArtifactSetAltar>(cb))
{
}

View File

@@ -18,19 +18,19 @@ VCMI_LIB_NAMESPACE_BEGIN
class DLL_LINKAGE IMarket : public virtual Serializeable, boost::noncopyable
{
public:
explicit IMarket(CGameInfoCallback *cb);
explicit IMarket(IGameInfoCallback *cb);
~IMarket();
class CArtifactSetAltar : public CArtifactSet
{
CGameInfoCallback *cb;
IGameInfoCallback *cb;
public:
CArtifactSetAltar(CGameInfoCallback *cb)
CArtifactSetAltar(IGameInfoCallback *cb)
: CArtifactSet(cb)
, cb(cb)
{}
CGameInfoCallback * getCallback() const override {return cb;};
IGameInfoCallback * getCallback() const override {return cb;};
ArtBearer bearerType() const override {return ArtBearer::ALTAR;};
};

View File

@@ -15,7 +15,7 @@
#include "MiscObjects.h"
#include "../TerrainHandler.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../callback/IGameEventCallback.h"
#include "../mapObjects/CGHeroInstance.h"
#include "../networkPacks/PacksForClient.h"

View File

@@ -28,7 +28,7 @@ class BoatId;
class CGObjectInstance;
class CStackInstance;
class CGHeroInstance;
class CGameInfoCallback;
class IGameInfoCallback;
class IGameEventCallback;
class ResourceSet;
class int3;

View File

@@ -12,7 +12,7 @@
#include "MiscObjects.h"
#include "../bonuses/Propagators.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../callback/IGameEventCallback.h"
#include "../constants/StringConstants.h"
#include "../entities/artifact/ArtifactUtils.h"
@@ -483,7 +483,7 @@ void CGSubterraneanGate::initObj(vstd::RNG & rand)
type = BOTH;
}
void CGSubterraneanGate::postInit(CGameInfoCallback * cb) //matches subterranean gates into pairs
void CGSubterraneanGate::postInit(IGameInfoCallback * cb) //matches subterranean gates into pairs
{
//split on underground and surface gates
std::vector<CGSubterraneanGate *> gatesSplit[2]; //surface and underground gates
@@ -986,7 +986,7 @@ void CGMagi::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance *
}
}
CGBoat::CGBoat(CGameInfoCallback * cb)
CGBoat::CGBoat(IGameInfoCallback * cb)
: CGObjectInstance(cb)
{
direction = 4;

View File

@@ -257,7 +257,7 @@ class DLL_LINKAGE CGSubterraneanGate : public CGMonolith
public:
using CGMonolith::CGMonolith;
static void postInit(CGameInfoCallback * cb);
static void postInit(IGameInfoCallback * cb);
template <typename Handler> void serialize(Handler &h)
{
@@ -312,7 +312,7 @@ public:
AnimationPath overlayAnimation; //waves animations
std::array<AnimationPath, PlayerColor::PLAYER_LIMIT_I> flagAnimations;
CGBoat(CGameInfoCallback * cb);
CGBoat(IGameInfoCallback * cb);
bool isCoastVisitable() const override;
void setBoardedHero(const CGHeroInstance * hero);

View File

@@ -12,7 +12,7 @@
#include "TownBuildingInstance.h"
#include "CGTownInstance.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../callback/IGameEventCallback.h"
#include "../mapObjects/CGHeroInstance.h"
#include "../entities/building/CBuilding.h"
@@ -21,7 +21,7 @@
VCMI_LIB_NAMESPACE_BEGIN
TownBuildingInstance::TownBuildingInstance(CGameInfoCallback * cb)
TownBuildingInstance::TownBuildingInstance(IGameInfoCallback * cb)
: IObjectInterface(cb)
, town(nullptr)
{}
@@ -62,7 +62,7 @@ int3 TownBuildingInstance::anchorPos() const
return town->anchorPos();
}
TownRewardableBuildingInstance::TownRewardableBuildingInstance(CGameInfoCallback *cb)
TownRewardableBuildingInstance::TownRewardableBuildingInstance(IGameInfoCallback *cb)
: TownBuildingInstance(cb)
{}

View File

@@ -23,7 +23,7 @@ class DLL_LINKAGE TownBuildingInstance : public IObjectInterface
///basic class for town structures handled as map objects
public:
TownBuildingInstance(CGTownInstance * town, const BuildingID & index);
TownBuildingInstance(CGameInfoCallback *cb);
TownBuildingInstance(IGameInfoCallback *cb);
CGTownInstance * town;
@@ -78,7 +78,7 @@ public:
void blockingDialogAnswered(IGameEventCallback & gameEvents, const CGHeroInstance *hero, int32_t answer) const override;
TownRewardableBuildingInstance(CGTownInstance * town, const BuildingID & index, vstd::RNG & rand);
TownRewardableBuildingInstance(CGameInfoCallback *cb);
TownRewardableBuildingInstance(IGameInfoCallback *cb);
template <typename Handler> void serialize(Handler &h)
{

View File

@@ -21,7 +21,7 @@
#include "../RoadHandler.h"
#include "../TerrainHandler.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../entities/artifact/CArtHandler.h"
#include "../entities/hero/CHeroHandler.h"
#include "../gameState/CGameState.h"
@@ -170,7 +170,7 @@ EDiggingStatus TerrainTile::getDiggingStatus(const bool excludeTop) const
return EDiggingStatus::CAN_DIG;
}
CMap::CMap(CGameInfoCallback * cb)
CMap::CMap(IGameInfoCallback * cb)
: GameCallbackHolder(cb)
, grailPos(-1, -1, -1)
, grailRadius(0)

View File

@@ -80,7 +80,7 @@ public:
/// TODO: make private
std::vector<std::shared_ptr<CGObjectInstance>> objects;
explicit CMap(CGameInfoCallback *cb);
explicit CMap(IGameInfoCallback *cb);
~CMap();
void initTerrain();

View File

@@ -30,7 +30,7 @@
VCMI_LIB_NAMESPACE_BEGIN
std::unique_ptr<CMap> CMapService::loadMap(const ResourcePath & name, CGameInfoCallback * cb) const
std::unique_ptr<CMap> CMapService::loadMap(const ResourcePath & name, IGameInfoCallback * cb) const
{
std::string modName = LIBRARY->modh->findResourceOrigin(name);
std::string encoding = LIBRARY->modh->findResourceEncoding(name);
@@ -48,7 +48,7 @@ std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const ResourcePath & name
return getMapLoader(stream, name.getName(), modName, encoding)->loadMapHeader();
}
std::unique_ptr<CMap> CMapService::loadMap(const uint8_t * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding, CGameInfoCallback * cb) const
std::unique_ptr<CMap> CMapService::loadMap(const uint8_t * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding, IGameInfoCallback * cb) const
{
auto stream = getStreamFromMem(buffer, size);
std::unique_ptr<CMap> map(getMapLoader(stream, name, modName, encoding)->loadMap(cb));

View File

@@ -22,7 +22,7 @@ class CInputStream;
class IMapLoader;
class IMapPatcher;
class CGameInfoCallback;
class IGameInfoCallback;
/**
* The map service provides loading of VCMI/H3 map files. It can
@@ -39,7 +39,7 @@ public:
* @param name the name of the map
* @return a unique ptr to the loaded map class
*/
virtual std::unique_ptr<CMap> loadMap(const ResourcePath & name, CGameInfoCallback * cb) const = 0;
virtual std::unique_ptr<CMap> loadMap(const ResourcePath & name, IGameInfoCallback * cb) const = 0;
/**
* Loads the VCMI/H3 map header specified by the name.
@@ -56,7 +56,7 @@ public:
* @param name indicates name of file that will be used during map header patching
* @return a unique ptr to the loaded map class
*/
virtual std::unique_ptr<CMap> loadMap(const uint8_t * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding, CGameInfoCallback * cb) const = 0;
virtual std::unique_ptr<CMap> loadMap(const uint8_t * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding, IGameInfoCallback * cb) const = 0;
/**
* Loads the VCMI/H3 map header from a buffer. This method is temporarily
@@ -81,9 +81,9 @@ public:
CMapService() = default;
virtual ~CMapService() = default;
std::unique_ptr<CMap> loadMap(const ResourcePath & name, CGameInfoCallback * cb) const override;
std::unique_ptr<CMap> loadMap(const ResourcePath & name, IGameInfoCallback * cb) const override;
std::unique_ptr<CMapHeader> loadMapHeader(const ResourcePath & name) const override;
std::unique_ptr<CMap> loadMap(const uint8_t * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding, CGameInfoCallback * cb) const override;
std::unique_ptr<CMap> loadMap(const uint8_t * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding, IGameInfoCallback * cb) const override;
std::unique_ptr<CMapHeader> loadMapHeader(const uint8_t * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding) const override;
void saveMap(const std::unique_ptr<CMap> & map, boost::filesystem::path fullPath) const override;
@@ -141,7 +141,7 @@ public:
*
* @return a unique ptr of the loaded map class
*/
virtual std::unique_ptr<CMap> loadMap(CGameInfoCallback * cb) = 0;
virtual std::unique_ptr<CMap> loadMap(IGameInfoCallback * cb) = 0;
/**
* Loads the VCMI/H3 map header.

View File

@@ -72,7 +72,7 @@ CMapLoaderH3M::CMapLoaderH3M(const std::string & mapName, const std::string & mo
//must be instantiated in .cpp file for access to complete types of all member fields
CMapLoaderH3M::~CMapLoaderH3M() = default;
std::unique_ptr<CMap> CMapLoaderH3M::loadMap(CGameInfoCallback * cb)
std::unique_ptr<CMap> CMapLoaderH3M::loadMap(IGameInfoCallback * cb)
{
// Init map object by parsing the input buffer
map = new CMap(cb);

View File

@@ -86,7 +86,7 @@ public:
*
* @return a unique ptr of the loaded map class
*/
std::unique_ptr<CMap> loadMap(CGameInfoCallback * cb) override;
std::unique_ptr<CMap> loadMap(IGameInfoCallback * cb) override;
/**
* Loads the VCMI/H3 map header.

View File

@@ -767,7 +767,7 @@ CMapLoaderJson::CMapLoaderJson(CInputStream * stream)
{
}
std::unique_ptr<CMap> CMapLoaderJson::loadMap(CGameInfoCallback * cb)
std::unique_ptr<CMap> CMapLoaderJson::loadMap(IGameInfoCallback * cb)
{
LOG_TRACE(logGlobal);
auto result = std::make_unique<CMap>(cb);

View File

@@ -167,7 +167,7 @@ public:
*
* @return a unique ptr of the loaded map class
*/
std::unique_ptr<CMap> loadMap(CGameInfoCallback * cb) override;
std::unique_ptr<CMap> loadMap(IGameInfoCallback * cb) override;
/**
* Loads the VCMI/Json map header.

View File

@@ -230,7 +230,7 @@ bool ObstacleProxy::isProhibited(const rmg::Area& objArea) const
return false;
};
int ObstacleProxy::getWeightedObjects(const int3 & tile, vstd::RNG & rand, CGameInfoCallback * cb, std::list<rmg::Object> & allObjects, std::vector<std::pair<rmg::Object*, int3>> & weightedObjects)
int ObstacleProxy::getWeightedObjects(const int3 & tile, vstd::RNG & rand, IGameInfoCallback * cb, std::list<rmg::Object> & allObjects, std::vector<std::pair<rmg::Object*, int3>> & weightedObjects)
{
int maxWeight = std::numeric_limits<int>::min();
for(auto & possibleObstacle : possibleObstacles)
@@ -311,7 +311,7 @@ int ObstacleProxy::getWeightedObjects(const int3 & tile, vstd::RNG & rand, CGame
return maxWeight;
}
std::set<std::shared_ptr<CGObjectInstance>> ObstacleProxy::createObstacles(vstd::RNG & rand, CGameInfoCallback * cb)
std::set<std::shared_ptr<CGObjectInstance>> ObstacleProxy::createObstacles(vstd::RNG & rand, IGameInfoCallback * cb)
{
//reverse order, since obstacles begin in bottom-right corner, while the map coordinates begin in top-left
auto blockedTiles = blockedArea.getTilesVector();

View File

@@ -18,7 +18,7 @@ VCMI_LIB_NAMESPACE_BEGIN
class CMapEditManager;
class CGObjectInstance;
class ObjectTemplate;
class CGameInfoCallback;
class IGameInfoCallback;
class ObstacleSetFilter;
class DLL_LINKAGE ObstacleProxy
@@ -43,7 +43,7 @@ public:
virtual void placeObject(rmg::Object & object, std::set<std::shared_ptr<CGObjectInstance>> & instances);
virtual std::set<std::shared_ptr<CGObjectInstance>> createObstacles(vstd::RNG & rand, CGameInfoCallback * cb);
virtual std::set<std::shared_ptr<CGObjectInstance>> createObstacles(vstd::RNG & rand, IGameInfoCallback * cb);
virtual bool isInTheMap(const int3& tile) = 0;
@@ -52,7 +52,7 @@ public:
virtual void postProcess(const rmg::Object& object) {};
protected:
int getWeightedObjects(const int3& tile, vstd::RNG& rand, CGameInfoCallback * cb, std::list<rmg::Object>& allObjects, std::vector<std::pair<rmg::Object*, int3>>& weightedObjects);
int getWeightedObjects(const int3& tile, vstd::RNG& rand, IGameInfoCallback * cb, std::list<rmg::Object>& allObjects, std::vector<std::pair<rmg::Object*, int3>>& weightedObjects);
void sortObstacles();
rmg::Area blockedArea;

View File

@@ -20,7 +20,7 @@
#include "../CPlayerState.h"
#include "../TerrainHandler.h"
#include "../RoadHandler.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../mapObjects/CGHeroInstance.h"
#include "../mapObjects/CGTownInstance.h"
#include "../mapObjects/MiscObjects.h"

View File

@@ -28,7 +28,7 @@ void NodeStorage::initialize(const PathfinderOptions & options, const CGameState
int3 pos;
const PlayerColor player = out.hero->tempOwner;
const int3 sizes = gs->getMapSize();
const auto & fow = static_cast<const CGameInfoCallback *>(gs)->getPlayerTeam(player)->fogOfWarMap;
const auto & fow = static_cast<const IGameInfoCallback *>(gs)->getPlayerTeam(player)->fogOfWarMap;
//make 200% sure that these are loop invariants (also a bit shorter code), let compiler do the rest(loop unswitching)
const bool useFlying = options.useFlying;

View File

@@ -13,7 +13,7 @@
#include "CGPathNode.h"
#include "PathfinderOptions.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../mapObjects/CGHeroInstance.h"
VCMI_LIB_NAMESPACE_BEGIN
@@ -35,7 +35,7 @@ std::shared_ptr<CPathsInfo> PathfinderCache::buildPaths(const CGHeroInstance * h
return result;
}
PathfinderCache::PathfinderCache(const CGameInfoCallback * cb, const PathfinderOptions & options)
PathfinderCache::PathfinderCache(const IGameInfoCallback * cb, const PathfinderOptions & options)
: cb(cb)
, options(options)
{

View File

@@ -13,14 +13,14 @@
VCMI_LIB_NAMESPACE_BEGIN
class CGameInfoCallback;
class IGameInfoCallback;
class CGHeroInstance;
class PathfinderConfig;
struct CPathsInfo;
class DLL_LINKAGE PathfinderCache
{
const CGameInfoCallback * cb;
const IGameInfoCallback * cb;
std::mutex pathCacheMutex;
std::map<const CGHeroInstance *, std::shared_ptr<CPathsInfo>> pathCache;
PathfinderOptions options;
@@ -28,7 +28,7 @@ class DLL_LINKAGE PathfinderCache
std::shared_ptr<PathfinderConfig> createConfig(const CGHeroInstance *h, CPathsInfo &out);
std::shared_ptr<CPathsInfo> buildPaths(const CGHeroInstance *h);
public:
PathfinderCache(const CGameInfoCallback * cb, const PathfinderOptions & options);
PathfinderCache(const IGameInfoCallback * cb, const PathfinderOptions & options);
/// Invalidates and erases all existing paths from the cache
void invalidatePaths();

View File

@@ -19,7 +19,7 @@
VCMI_LIB_NAMESPACE_BEGIN
PathfinderOptions::PathfinderOptions(const CGameInfoCallback & cb)
PathfinderOptions::PathfinderOptions(const IGameInfoCallback & cb)
: useFlying(true)
, useWaterWalking(true)
, ignoreGuards(cb.getSettings().getBoolean(EGameSettings::PATHFINDER_IGNORE_GUARDS))
@@ -39,7 +39,7 @@ PathfinderOptions::PathfinderOptions(const CGameInfoCallback & cb)
{
}
PathfinderConfig::PathfinderConfig(std::shared_ptr<INodeStorage> nodeStorage, const CGameInfoCallback & callback, std::vector<std::shared_ptr<IPathfindingRule>> rules):
PathfinderConfig::PathfinderConfig(std::shared_ptr<INodeStorage> nodeStorage, const IGameInfoCallback & callback, std::vector<std::shared_ptr<IPathfindingRule>> rules):
nodeStorage(std::move(nodeStorage)),
rules(std::move(rules)),
options(callback)
@@ -59,7 +59,7 @@ std::vector<std::shared_ptr<IPathfindingRule>> SingleHeroPathfinderConfig::build
SingleHeroPathfinderConfig::~SingleHeroPathfinderConfig() = default;
SingleHeroPathfinderConfig::SingleHeroPathfinderConfig(CPathsInfo & out, const CGameInfoCallback & gs, const CGHeroInstance * hero)
SingleHeroPathfinderConfig::SingleHeroPathfinderConfig(CPathsInfo & out, const IGameInfoCallback & gs, const CGHeroInstance * hero)
: PathfinderConfig(std::make_shared<NodeStorage>(out, hero), gs, buildRuleSet())
, hero(hero)
{

View File

@@ -16,7 +16,7 @@ class IPathfindingRule;
class CPathfinderHelper;
class CGameState;
class CGHeroInstance;
class CGameInfoCallback;
class IGameInfoCallback;
struct PathNodeInfo;
struct CPathsInfo;
@@ -85,7 +85,7 @@ struct DLL_LINKAGE PathfinderOptions
/// </summary>
bool allowLayerTransitioningAfterBattle;
PathfinderOptions(const CGameInfoCallback & callback);
PathfinderOptions(const IGameInfoCallback & callback);
};
class DLL_LINKAGE PathfinderConfig
@@ -97,7 +97,7 @@ public:
PathfinderConfig(
std::shared_ptr<INodeStorage> nodeStorage,
const CGameInfoCallback & callback,
const IGameInfoCallback & callback,
std::vector<std::shared_ptr<IPathfindingRule>> rules);
virtual ~PathfinderConfig() = default;
@@ -111,7 +111,7 @@ private:
const CGHeroInstance * hero;
public:
SingleHeroPathfinderConfig(CPathsInfo & out, const CGameInfoCallback & gs, const CGHeroInstance * hero);
SingleHeroPathfinderConfig(CPathsInfo & out, const IGameInfoCallback & gs, const CGHeroInstance * hero);
virtual ~SingleHeroPathfinderConfig();
CPathfinderHelper * getOrCreatePathfinderHelper(const PathNodeInfo & source, CGameState & gs) override;

View File

@@ -14,7 +14,7 @@
#include "../TerrainHandler.h"
#include "../GameLibrary.h"
#include "../bonuses/BonusList.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../json/JsonNode.h"
#include "../mapObjects/CGHeroInstance.h"
#include "../mapObjects/MiscObjects.h"

View File

@@ -108,7 +108,7 @@ void Rewardable::Info::init(const JsonNode & objectConfig, const std::string & o
loadString(parameters["onGuardedMessage"], TextIdentifier(objectName, "onGuarded"));
}
Rewardable::LimitersList Rewardable::Info::configureSublimiters(Rewardable::Configuration & object, vstd::RNG & rng, CGameInfoCallback * cb, const JsonNode & source) const
Rewardable::LimitersList Rewardable::Info::configureSublimiters(Rewardable::Configuration & object, vstd::RNG & rng, IGameInfoCallback * cb, const JsonNode & source) const
{
Rewardable::LimitersList result;
for (const auto & input : source.Vector())
@@ -123,7 +123,7 @@ Rewardable::LimitersList Rewardable::Info::configureSublimiters(Rewardable::Conf
return result;
}
void Rewardable::Info::configureLimiter(Rewardable::Configuration & object, vstd::RNG & rng, CGameInfoCallback * cb, Rewardable::Limiter & limiter, const JsonNode & source) const
void Rewardable::Info::configureLimiter(Rewardable::Configuration & object, vstd::RNG & rng, IGameInfoCallback * cb, Rewardable::Limiter & limiter, const JsonNode & source) const
{
auto const & variables = object.variables.values;
JsonRandom randomizer(cb);
@@ -160,7 +160,7 @@ void Rewardable::Info::configureLimiter(Rewardable::Configuration & object, vstd
limiter.noneOf = configureSublimiters(object, rng, cb, source["noneOf"] );
}
void Rewardable::Info::configureReward(Rewardable::Configuration & object, vstd::RNG & rng, CGameInfoCallback * cb, Rewardable::Reward & reward, const JsonNode & source) const
void Rewardable::Info::configureReward(Rewardable::Configuration & object, vstd::RNG & rng, IGameInfoCallback * cb, Rewardable::Reward & reward, const JsonNode & source) const
{
auto const & variables = object.variables.values;
JsonRandom randomizer(cb);
@@ -233,7 +233,7 @@ void Rewardable::Info::configureResetInfo(Rewardable::Configuration & object, vs
resetParameters.rewards = source["rewards"].Bool();
}
void Rewardable::Info::configureVariables(Rewardable::Configuration & object, vstd::RNG & rng, CGameInfoCallback * cb, const JsonNode & source) const
void Rewardable::Info::configureVariables(Rewardable::Configuration & object, vstd::RNG & rng, IGameInfoCallback * cb, const JsonNode & source) const
{
JsonRandom randomizer(cb);
@@ -351,7 +351,7 @@ void Rewardable::Info::replaceTextPlaceholders(MetaString & target, const Variab
void Rewardable::Info::configureRewards(
Rewardable::Configuration & object,
vstd::RNG & rng,
CGameInfoCallback * cb,
IGameInfoCallback * cb,
const JsonNode & source,
Rewardable::EEventType event,
const std::string & modeName) const
@@ -408,7 +408,7 @@ void Rewardable::Info::configureRewards(
}
}
void Rewardable::Info::configureObject(Rewardable::Configuration & object, vstd::RNG & rng, CGameInfoCallback * cb) const
void Rewardable::Info::configureObject(Rewardable::Configuration & object, vstd::RNG & rng, IGameInfoCallback * cb) const
{
object.info.clear();
object.variables.values.clear();

View File

@@ -21,7 +21,7 @@ class RNG;
}
class MetaString;
class CGameInfoCallback;
class IGameInfoCallback;
namespace Rewardable
{
@@ -42,13 +42,13 @@ class DLL_LINKAGE Info : public IObjectInfo
void replaceTextPlaceholders(MetaString & target, const Variables & variables) const;
void replaceTextPlaceholders(MetaString & target, const Variables & variables, const VisitInfo & info) const;
void configureVariables(Rewardable::Configuration & object, vstd::RNG & rng, CGameInfoCallback * cb, const JsonNode & source) const;
void configureRewards(Rewardable::Configuration & object, vstd::RNG & rng, CGameInfoCallback * cb, const JsonNode & source, Rewardable::EEventType mode, const std::string & textPrefix) const;
void configureVariables(Rewardable::Configuration & object, vstd::RNG & rng, IGameInfoCallback * cb, const JsonNode & source) const;
void configureRewards(Rewardable::Configuration & object, vstd::RNG & rng, IGameInfoCallback * cb, const JsonNode & source, Rewardable::EEventType mode, const std::string & textPrefix) const;
void configureLimiter(Rewardable::Configuration & object, vstd::RNG & rng, CGameInfoCallback * cb, Rewardable::Limiter & limiter, const JsonNode & source) const;
Rewardable::LimitersList configureSublimiters(Rewardable::Configuration & object, vstd::RNG & rng, CGameInfoCallback * cb, const JsonNode & source) const;
void configureLimiter(Rewardable::Configuration & object, vstd::RNG & rng, IGameInfoCallback * cb, Rewardable::Limiter & limiter, const JsonNode & source) const;
Rewardable::LimitersList configureSublimiters(Rewardable::Configuration & object, vstd::RNG & rng, IGameInfoCallback * cb, const JsonNode & source) const;
void configureReward(Rewardable::Configuration & object, vstd::RNG & rng, CGameInfoCallback * cb, Rewardable::Reward & info, const JsonNode & source) const;
void configureReward(Rewardable::Configuration & object, vstd::RNG & rng, IGameInfoCallback * cb, Rewardable::Reward & info, const JsonNode & source) const;
void configureResetInfo(Rewardable::Configuration & object, vstd::RNG & rng, Rewardable::ResetInfo & info, const JsonNode & source) const;
public:
const JsonNode & getParameters() const;
@@ -70,7 +70,7 @@ public:
bool hasGuards() const override;
void configureObject(Rewardable::Configuration & object, vstd::RNG & rng, CGameInfoCallback * cb) const;
void configureObject(Rewardable::Configuration & object, vstd::RNG & rng, IGameInfoCallback * cb) const;
void init(const JsonNode & objectConfig, const std::string & objectTextID);

View File

@@ -14,7 +14,7 @@
#include "../TerrainHandler.h"
#include "../CPlayerState.h"
#include "../CSoundBase.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../callback/IGameEventCallback.h"
#include "../entities/hero/CHeroHandler.h"
#include "../gameState/CGameState.h"

View File

@@ -13,7 +13,7 @@
#include "../CPlayerState.h"
#include "../CSkillHandler.h"
#include "../callback/CGameInfoCallback.h"
#include "../callback/IGameInfoCallback.h"
#include "../constants/StringConstants.h"
#include "../entities/artifact/ArtifactUtils.h"
#include "../mapObjects/CGHeroInstance.h"

View File

@@ -40,7 +40,7 @@
VCMI_LIB_NAMESPACE_BEGIN
CMapGenerator::CMapGenerator(CMapGenOptions& mapGenOptions, CGameInfoCallback * cb, int RandomSeed) :
CMapGenerator::CMapGenerator(CMapGenOptions& mapGenOptions, IGameInfoCallback * cb, int RandomSeed) :
mapGenOptions(mapGenOptions), randomSeed(RandomSeed),
monolithIndex(0),
rand(std::make_unique<CRandomGenerator>(RandomSeed))

View File

@@ -23,7 +23,7 @@ class RmgMap;
class CMap;
class Zone;
class CZonePlacer;
class CGameInfoCallback;
class IGameInfoCallback;
using JsonVector = std::vector<JsonNode>;
@@ -54,7 +54,7 @@ public:
bool singleThread;
};
explicit CMapGenerator(CMapGenOptions& mapGenOptions, CGameInfoCallback * cb, int RandomSeed);
explicit CMapGenerator(CMapGenOptions& mapGenOptions, IGameInfoCallback * cb, int RandomSeed);
~CMapGenerator(); // required due to std::unique_ptr
const Config & getConfig() const;

View File

@@ -39,7 +39,7 @@
VCMI_LIB_NAMESPACE_BEGIN
RmgMap::RmgMap(const CMapGenOptions& mapGenOptions, CGameInfoCallback * cb) :
RmgMap::RmgMap(const CMapGenOptions& mapGenOptions, IGameInfoCallback * cb) :
mapGenOptions(mapGenOptions), zonesTotal(0)
{
mapInstance = std::make_unique<CMap>(cb);

View File

@@ -38,7 +38,7 @@ public:
std::shared_ptr<MapProxy> getMapProxy() const;
CMap & getMap(const CMapGenerator *) const; //limited access
RmgMap(const CMapGenOptions& mapGenOptions, CGameInfoCallback * cb);
RmgMap(const CMapGenOptions& mapGenOptions, IGameInfoCallback * cb);
~RmgMap() = default;
CMapEditManager* getEditManager() const;

View File

@@ -23,7 +23,7 @@ public:
using Version = ESerializationVersion;
static constexpr bool saving = false;
CGameInfoCallback * cb = nullptr;
IGameInfoCallback * cb = nullptr;
Version version = Version::NONE;
bool loadingGamestate = false;
bool reverseEndianness = false; //if source has different endianness than us, we reverse bytes

View File

@@ -19,7 +19,7 @@ struct static_caster
};
CLoadFile::CLoadFile(const boost::filesystem::path & fname, CGameInfoCallback * cb)
CLoadFile::CLoadFile(const boost::filesystem::path & fname, IGameInfoCallback * cb)
: serializer(this)
, sfile(fname.c_str(), std::ios::in | std::ios::binary)
{

View File

@@ -21,7 +21,7 @@ class DLL_LINKAGE CLoadFile : public IBinaryReader
int read(std::byte * data, unsigned size) override; //throws!
public:
CLoadFile(const boost::filesystem::path & fname, CGameInfoCallback * cb); //throws!
CLoadFile(const boost::filesystem::path & fname, IGameInfoCallback * cb); //throws!
template<class T>
void load(T & data)

View File

@@ -124,7 +124,7 @@ void CConnection::enterLobbyConnectionMode()
serializer->clear();
}
void CConnection::setCallback(CGameInfoCallback * cb)
void CConnection::setCallback(IGameInfoCallback * cb)
{
deserializer->cb = cb;
}

View File

@@ -20,7 +20,7 @@ class INetworkConnection;
class ConnectionPackReader;
class ConnectionPackWriter;
class CGameState;
class CGameInfoCallback;
class IGameInfoCallback;
/// Wrapper class for game connection
/// Handles serialization and deserialization of data received from network
@@ -50,7 +50,7 @@ public:
std::unique_ptr<CPack> retrievePack(const std::vector<std::byte> & data);
void enterLobbyConnectionMode();
void setCallback(CGameInfoCallback * cb);
void setCallback(IGameInfoCallback * cb);
void enterGameplayConnectionMode(CGameState & gs);
void setSerializationVersion(ESerializationVersion version);
};

View File

@@ -30,12 +30,12 @@ template<typename Type>
class SerializerReflection final : public ISerializerReflection
{
public:
Serializeable * createPtr(BinaryDeserializer &ar, CGameInfoCallback * cb) const override
Serializeable * createPtr(BinaryDeserializer &ar, IGameInfoCallback * cb) const override
{
return ClassObjectCreator<Type>::invoke(cb);
}
void loadPtr(BinaryDeserializer &ar, CGameInfoCallback * cb, Serializeable * data) const override
void loadPtr(BinaryDeserializer &ar, IGameInfoCallback * cb, Serializeable * data) const override
{
auto * realPtr = dynamic_cast<Type *>(data);
realPtr->serialize(ar);
@@ -52,7 +52,7 @@ template<typename Type, ESerializationVersion maxVersion>
class SerializerCompatibility : public ISerializerReflection
{
public:
Serializeable * createPtr(BinaryDeserializer &ar, CGameInfoCallback * cb) const override
Serializeable * createPtr(BinaryDeserializer &ar, IGameInfoCallback * cb) const override
{
return ClassObjectCreator<Type>::invoke(cb);
}

Some files were not shown because too many files have changed in this diff Show More