CGameState.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef CGAMESTATE_H
  2. #define CGAMESTATE_H
  3. #include "mapHandler.h"
  4. #include <set>
  5. class CScriptCallback;
  6. class CHeroInstance;
  7. class CTownInstance;
  8. class CCallback;
  9. class CLuaCallback;
  10. class CCPPObjectScript;
  11. struct PlayerState
  12. {
  13. public:
  14. int color, serial;
  15. //std::vector<std::vector<std::vector<char> > > fogOfWarMap; //true - visible, false - hidden
  16. PseudoV< PseudoV< PseudoV<unsigned char> > > fogOfWarMap; //true - visible, false - hidden
  17. std::vector<int> resources;
  18. std::vector<CGHeroInstance *> heroes;
  19. std::vector<CGTownInstance *> towns;
  20. PlayerState():color(-1){};
  21. };
  22. class CGameState
  23. {
  24. private:
  25. int currentPlayer;
  26. int day; //total number of days in game
  27. std::map<int,PlayerState> players; //color <-> playerstate
  28. std::set<CCPPObjectScript *> cppscripts;
  29. std::map<int, std::map<std::string, CObjectScript*> > objscr; //custom user scripts (as for now only Lua)
  30. bool checkFunc(int obid, std::string name)
  31. {
  32. if (objscr.find(obid)!=objscr.end())
  33. {
  34. if(objscr[obid].find(name)!=objscr[obid].end())
  35. {
  36. return true;
  37. }
  38. }
  39. return false;
  40. }
  41. CGHeroInstance * getHero(int ID, int mode)
  42. {
  43. if (mode != 0)
  44. throw new std::exception("gs->getHero: This mode is not supported!");
  45. for ( std::map<int, PlayerState>::iterator i=players.begin() ; i!=players.end();i++)
  46. {
  47. for (int j=0;j<(*i).second.heroes.size();j++)
  48. {
  49. if (i->second.heroes[j]->subID == ID)
  50. return i->second.heroes[j];
  51. }
  52. }
  53. return NULL;
  54. }
  55. public:
  56. friend CCallback;
  57. friend CLuaCallback;
  58. friend int _tmain(int argc, _TCHAR* argv[]);
  59. friend void initGameState(CGameInfo * cgi);
  60. friend CScriptCallback;
  61. friend void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script);
  62. //CCallback * cb; //for communication between PlayerInterface/AI and GameState
  63. friend SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap); //todo: wywalic koniecznie, tylko do flag obecnie!!!!
  64. };
  65. #endif //CGAMESTATE_H