CGameState.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 CStack
  36. {
  37. public:
  38. int ID; //unique ID of stack
  39. CCreature * creature;
  40. int amount;
  41. int owner;
  42. int position; //position on battlefield
  43. bool alive; //true if it is alive
  44. CStack(CCreature * C, int A, int O, int I):creature(C),amount(A),owner(O), alive(true), position(-1), ID(I){};
  45. CStack() : creature(NULL),amount(-1),owner(255), alive(true), position(-1), ID(-1){};
  46. };
  47. class CGameState
  48. {
  49. private:
  50. int currentPlayer;
  51. BattleInfo *curB; //current battle
  52. int day; //total number of days in game
  53. std::map<int,PlayerState> players; //color <-> playerstate
  54. std::set<CCPPObjectScript *> cppscripts;
  55. std::map<int, std::map<std::string, CObjectScript*> > objscr; //custom user scripts (as for now only Lua)
  56. bool checkFunc(int obid, std::string name)
  57. {
  58. if (objscr.find(obid)!=objscr.end())
  59. {
  60. if(objscr[obid].find(name)!=objscr[obid].end())
  61. {
  62. return true;
  63. }
  64. }
  65. return false;
  66. }
  67. CGHeroInstance * getHero(int ID, int mode)
  68. {
  69. if (mode != 0)
  70. throw new std::exception("gs->getHero: This mode is not supported!");
  71. for ( std::map<int, PlayerState>::iterator i=players.begin() ; i!=players.end();i++)
  72. {
  73. for (int j=0;j<(*i).second.heroes.size();j++)
  74. {
  75. if (i->second.heroes[j]->subID == ID)
  76. return i->second.heroes[j];
  77. }
  78. }
  79. return NULL;
  80. }
  81. void battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2);
  82. public:
  83. friend CCallback;
  84. friend CPathfinder;;
  85. friend CLuaCallback;
  86. friend int _tmain(int argc, _TCHAR* argv[]);
  87. friend void initGameState(CGameInfo * cgi);
  88. friend CScriptCallback;
  89. friend void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script);
  90. //CCallback * cb; //for communication between PlayerInterface/AI and GameState
  91. 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!!!!
  92. };
  93. #endif //CGAMESTATE_H