mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Game interfaces can register another interfaces to receive info on game events.
This commit is contained in:
parent
254f194220
commit
2be2143844
@ -376,6 +376,29 @@ int CCallback::mergeOrSwapStacks(const CArmedInstance *s1, const CArmedInstance
|
||||
return swapCreatures(s1, s2, p1, p2);
|
||||
}
|
||||
|
||||
void CCallback::registerGameInterface(CGameInterface *cgi)
|
||||
{
|
||||
cl->additionalPlayerInts[*player].push_back(cgi);
|
||||
registerBattleInterface(cgi);
|
||||
}
|
||||
|
||||
void CCallback::registerBattleInterface(CBattleGameInterface *cbga)
|
||||
{
|
||||
cl->additionalBattleInts[*player].push_back(cbga);
|
||||
}
|
||||
|
||||
void CCallback::unregisterGameInterface(CGameInterface *cgi)
|
||||
{
|
||||
cl->additionalPlayerInts[*player] -= cgi;
|
||||
unregisterBattleInterface(cgi);
|
||||
|
||||
}
|
||||
|
||||
void CCallback::unregisterBattleInterface(CBattleGameInterface *cbga)
|
||||
{
|
||||
cl->additionalBattleInts[*player] -= cbga;
|
||||
}
|
||||
|
||||
CBattleCallback::CBattleCallback(CGameState *GS, boost::optional<PlayerColor> Player, CClient *C )
|
||||
{
|
||||
gs = GS;
|
||||
|
@ -27,6 +27,8 @@ struct CGPathNode;
|
||||
struct CGPath;
|
||||
struct CPathsInfo;
|
||||
struct CPack;
|
||||
class CBattleGameInterface;
|
||||
class CGameInterface;
|
||||
|
||||
class IBattleCallback
|
||||
{
|
||||
@ -111,6 +113,11 @@ public:
|
||||
virtual void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out, int3 src = int3(-1,-1,-1), int movement = -1);
|
||||
virtual void recalculatePaths(); //updates main, client pathfinder info (should be called when moving hero is over)
|
||||
|
||||
//Set of metrhods that allows adding more interfaces for this player that'll receive game event call-ins.
|
||||
void registerGameInterface(CGameInterface *cgi);
|
||||
void registerBattleInterface(CBattleGameInterface *cbga);
|
||||
void unregisterGameInterface(CGameInterface *cgi);
|
||||
void unregisterBattleInterface(CBattleGameInterface *cbga);
|
||||
|
||||
void unregisterMyInterface(); //stops delivering information about game events to that player's interface -> can be called ONLY after victory/loss
|
||||
|
||||
|
@ -919,7 +919,7 @@ void startGame(StartInfo * options, CConnection *serv/* = NULL*/)
|
||||
{
|
||||
if(vm.count("onlyAI"))
|
||||
{
|
||||
auto ais = vm["ai"].as<std::vector<std::string>>();
|
||||
auto ais = vm.count("ai") ? vm["ai"].as<std::vector<std::string>>() : std::vector<std::string>();
|
||||
|
||||
int i = 0;
|
||||
|
||||
|
@ -118,6 +118,10 @@ public:
|
||||
std::vector<IBattleEventsReceiver*> privilagedBattleEventReceivers; //scripting modules, spectator interfaces
|
||||
std::map<PlayerColor,CGameInterface *> playerint;
|
||||
std::map<PlayerColor,CBattleGameInterface *> battleints;
|
||||
|
||||
std::map<PlayerColor,std::vector<CGameInterface *>> additionalPlayerInts;
|
||||
std::map<PlayerColor,std::vector<CBattleGameInterface *>> additionalBattleInts;
|
||||
|
||||
bool hotSeat;
|
||||
CConnection *serv;
|
||||
|
||||
|
@ -57,6 +57,10 @@
|
||||
{ \
|
||||
if(vstd::contains(cl->battleints,player)) \
|
||||
cl->battleints[player]->function(__VA_ARGS__); \
|
||||
\
|
||||
if(cl->additionalBattleInts.count(player)) \
|
||||
BOOST_FOREACH(auto bInt, cl->additionalBattleInts[player])\
|
||||
bInt->function(__VA_ARGS__); \
|
||||
} while (0);
|
||||
|
||||
#define BATTLE_INTERFACE_CALL_RECEIVERS(function,...) \
|
||||
|
Loading…
Reference in New Issue
Block a user