CGameState.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #ifndef CGAMESTATE_H
  2. #define CGAMESTATE_H
  3. #include "mapHandler.h"
  4. #include <set>
  5. #include <tchar.h>
  6. class CScriptCallback;
  7. class CCallback;
  8. class CLuaCallback;
  9. class CCPPObjectScript;
  10. class CCreatureSet;
  11. class CStack;
  12. class CGHeroInstance;
  13. class CArmedInstance;
  14. struct PlayerState
  15. {
  16. public:
  17. int color, serial;
  18. //std::vector<std::vector<std::vector<char> > > fogOfWarMap; //true - visible, false - hidden
  19. PseudoV< PseudoV< PseudoV<unsigned char> > > fogOfWarMap; //true - visible, false - hidden
  20. std::vector<int> resources;
  21. std::vector<CGHeroInstance *> heroes;
  22. std::vector<CGTownInstance *> towns;
  23. PlayerState():color(-1){};
  24. };
  25. struct BattleInfo
  26. {
  27. int side1, side2;
  28. int round, activeStack;
  29. int siege; // = 0 ordinary battle = 1 a siege with a Fort = 2 a siege with a Citadel = 3 a siege with a Castle
  30. int3 tile; //for background and bonuses
  31. CGHeroInstance *hero1, *hero2;
  32. CCreatureSet * army1, * army2;
  33. std::vector<CStack*> stacks;
  34. };
  35. class CGameState
  36. {
  37. private:
  38. int currentPlayer;
  39. BattleInfo *curB; //current battle
  40. int day; //total number of days in game
  41. std::map<int,PlayerState> players; //color <-> playerstate
  42. std::set<CCPPObjectScript *> cppscripts;
  43. std::map<int, std::map<std::string, CObjectScript*> > objscr; //custom user scripts (as for now only Lua)
  44. bool checkFunc(int obid, std::string name)
  45. {
  46. if (objscr.find(obid)!=objscr.end())
  47. {
  48. if(objscr[obid].find(name)!=objscr[obid].end())
  49. {
  50. return true;
  51. }
  52. }
  53. return false;
  54. }
  55. CGHeroInstance * getHero(int ID, int mode)
  56. {
  57. if (mode != 0)
  58. throw new std::exception("gs->getHero: This mode is not supported!");
  59. for ( std::map<int, PlayerState>::iterator i=players.begin() ; i!=players.end();i++)
  60. {
  61. for (int j=0;j<(*i).second.heroes.size();j++)
  62. {
  63. if (i->second.heroes[j]->subID == ID)
  64. return i->second.heroes[j];
  65. }
  66. }
  67. return NULL;
  68. }
  69. void battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2);
  70. public:
  71. friend CCallback;
  72. friend CPathfinder;;
  73. friend CLuaCallback;
  74. friend int _tmain(int argc, _TCHAR* argv[]);
  75. friend void initGameState(CGameInfo * cgi);
  76. friend CScriptCallback;
  77. friend void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script);
  78. //CCallback * cb; //for communication between PlayerInterface/AI and GameState
  79. 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!!!!
  80. };
  81. #endif //CGAMESTATE_H