CGameHandler.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #include "../global.h"
  3. #include <set>
  4. #include "../CGameState.h"
  5. #include "../lib/Connection.h"
  6. #include <boost/thread.hpp>
  7. class CVCMIServer;
  8. class CGameState;
  9. //class CConnection;
  10. struct StartInfo;
  11. class CCPPObjectScript;
  12. class CScriptCallback;
  13. template <typename T> struct CPack;
  14. class CGHeroInstance;
  15. class CGameHandler
  16. {
  17. CGameState *gs;
  18. std::set<CCPPObjectScript *> cppscripts; //C++ scripts
  19. //std::map<int, std::map<std::string, CObjectScript*> > objscr; //non-C++ scripts
  20. CVCMIServer *s;
  21. std::map<int,CConnection*> connections; //player color -> connection to clinet with interface of that player
  22. std::map<int,int> states; //player color -> player state
  23. std::set<CConnection*> conns;
  24. void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script);
  25. void changePrimSkill(int ID, int which, int val, bool abs=false);
  26. void startBattle(CCreatureSet army1, CCreatureSet army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2); //use hero=NULL for no hero
  27. public:
  28. CGameHandler(void);
  29. ~CGameHandler(void);
  30. void init(StartInfo *si, int Seed);
  31. void handleConnection(std::set<int> players, CConnection &c);
  32. template <typename T>void sendToAllClients(CPack<T> * info)
  33. {
  34. for(std::set<CConnection*>::iterator i=conns.begin(); i!=conns.end();i++)
  35. {
  36. (*i)->wmx->lock();
  37. **i << info->getType() << *info->This();
  38. (*i)->wmx->unlock();
  39. }
  40. }
  41. template <typename T>void sendAndApply(CPack<T> * info)
  42. {
  43. gs->apply(info);
  44. sendToAllClients(info);
  45. }
  46. void run();
  47. void newTurn();
  48. friend class CVCMIServer;
  49. friend class CScriptCallback;
  50. };