CGameState.h 3.5 KB

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