From 2be2143844e99b6b08a8d00ce4ff2ad826af6d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sat, 22 Jun 2013 18:22:44 +0000 Subject: [PATCH] Game interfaces can register another interfaces to receive info on game events. --- CCallback.cpp | 23 +++++++++++++++++++++++ CCallback.h | 7 +++++++ client/CMT.cpp | 2 +- client/Client.h | 4 ++++ client/NetPacksClient.cpp | 4 ++++ 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/CCallback.cpp b/CCallback.cpp index 72eb78fd1..a44f46d72 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -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 Player, CClient *C ) { gs = GS; diff --git a/CCallback.h b/CCallback.h index cae4b9f70..725ac3cab 100644 --- a/CCallback.h +++ b/CCallback.h @@ -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 diff --git a/client/CMT.cpp b/client/CMT.cpp index 0bb36423a..8663d1499 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -919,7 +919,7 @@ void startGame(StartInfo * options, CConnection *serv/* = NULL*/) { if(vm.count("onlyAI")) { - auto ais = vm["ai"].as>(); + auto ais = vm.count("ai") ? vm["ai"].as>() : std::vector(); int i = 0; diff --git a/client/Client.h b/client/Client.h index 216221dba..f9a44be44 100644 --- a/client/Client.h +++ b/client/Client.h @@ -118,6 +118,10 @@ public: std::vector privilagedBattleEventReceivers; //scripting modules, spectator interfaces std::map playerint; std::map battleints; + + std::map> additionalPlayerInts; + std::map> additionalBattleInts; + bool hotSeat; CConnection *serv; diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index c86084793..d444cf9b8 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -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,...) \