CGameState.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef CGAMESTATE_H
  2. #define CGAMESTATE_H
  3. #include "global.h"
  4. #include <set>
  5. #include <vector>
  6. #include <tchar.h>
  7. class CScriptCallback;
  8. class CCallback;
  9. class CLuaCallback;
  10. class CCPPObjectScript;
  11. class CCreatureSet;
  12. class CStack;
  13. class CGHeroInstance;
  14. class CGTownInstance;
  15. class CArmedInstance;
  16. class CGDefInfo;
  17. class CObjectScript;
  18. class CGObjectInstance;
  19. class CCreature;
  20. struct Mapa;
  21. struct StartInfo;
  22. struct SDL_Surface;
  23. class CMapHandler;
  24. class CPathfinder;
  25. struct IPack;
  26. struct DLL_EXPORT PlayerState
  27. {
  28. public:
  29. int color, serial;
  30. std::vector<std::vector<std::vector<unsigned char> > > fogOfWarMap; //true - visible, false - hidden
  31. std::vector<int> resources;
  32. std::vector<CGHeroInstance *> heroes;
  33. std::vector<CGTownInstance *> towns;
  34. PlayerState():color(-1){};
  35. };
  36. struct DLL_EXPORT BattleInfo
  37. {
  38. int side1, side2;
  39. int round, activeStack;
  40. int siege; // = 0 ordinary battle = 1 a siege with a Fort = 2 a siege with a Citadel = 3 a siege with a Castle
  41. int3 tile; //for background and bonuses
  42. CGHeroInstance *hero1, *hero2;
  43. CCreatureSet * army1, * army2;
  44. std::vector<CStack*> stacks;
  45. bool stackActionPerformed; //true if current stack has been moved
  46. };
  47. class DLL_EXPORT CStack
  48. {
  49. public:
  50. int ID; //unique ID of stack
  51. CCreature * creature;
  52. int amount;
  53. int firstHPleft; //HP of first creature in stack
  54. int owner;
  55. bool attackerOwned; //if true, this stack is owned by attakcer (this one from left hand side of battle)
  56. int position; //position on battlefield
  57. bool alive; //true if it is alive
  58. CStack(CCreature * C, int A, int O, int I, bool AO);
  59. CStack() : creature(NULL),amount(-1),owner(255), alive(true), position(-1), ID(-1), attackerOwned(true), firstHPleft(-1){};
  60. };
  61. class DLL_EXPORT CGameState
  62. {
  63. private:
  64. StartInfo* scenarioOps;
  65. ui32 seed;
  66. ui8 currentPlayer; //ID of player currently having turn
  67. BattleInfo *curB; //current battle
  68. ui32 day; //total number of days in game
  69. Mapa * map;
  70. std::map<ui8,PlayerState> players; //ID <-> playerstate
  71. std::set<CCPPObjectScript *> cppscripts; //C++ scripts
  72. std::map<int, std::map<std::string, CObjectScript*> > objscr; //non-C++ scripts
  73. std::map<int, CGDefInfo*> villages, forts, capitols; //def-info for town graphics
  74. bool checkFunc(int obid, std::string name)
  75. {
  76. if (objscr.find(obid)!=objscr.end())
  77. {
  78. if(objscr[obid].find(name)!=objscr[obid].end())
  79. {
  80. return true;
  81. }
  82. }
  83. return false;
  84. }
  85. void init(StartInfo * si, Mapa * map, int Seed);
  86. void apply(IPack * pack);
  87. void randomizeObject(CGObjectInstance *cur);
  88. std::pair<int,int> pickObject(CGObjectInstance *obj);
  89. int pickHero(int owner);
  90. void battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2);
  91. bool battleMoveCreatureStack(int ID, int dest);
  92. bool battleAttackCreatureStack(int ID, int dest);
  93. std::vector<int> battleGetRange(int ID); //called by std::vector<int> CCallback::battleGetAvailableHexes(int ID);
  94. public:
  95. int getDate(int mode=0) const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
  96. friend class CCallback;
  97. friend class CPathfinder;;
  98. friend class CLuaCallback;
  99. friend class CClient;
  100. friend void initGameState(Mapa * map, CGameInfo * cgi);
  101. friend class CScriptCallback;
  102. friend void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script);
  103. friend class CMapHandler;
  104. friend class CGameHandler;
  105. };
  106. #endif //CGAMESTATE_H