CGameState.h 2.1 KB

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