CGameState.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. #ifndef __CGAMESTATE_H__
  2. #define __CGAMESTATE_H__
  3. #include "../global.h"
  4. #include <cassert>
  5. #ifndef _MSC_VER
  6. #include "CCreatureHandler.h"
  7. #include "VCMI_Lib.h"
  8. #include "map.h"
  9. #endif
  10. #include <set>
  11. #include <vector>
  12. #include <list>
  13. #include "HeroBonus.h"
  14. #include "CCreatureSet.h"
  15. #ifdef _WIN32
  16. #include <tchar.h>
  17. #else
  18. #include "../tchar_amigaos4.h"
  19. #endif
  20. #include "ConstTransitivePtr.h"
  21. /*
  22. * CGameState.h, part of VCMI engine
  23. *
  24. * Authors: listed in file AUTHORS in main folder
  25. *
  26. * License: GNU General Public License v2.0 or later
  27. * Full text of license available in license.txt file, in main folder
  28. *
  29. */
  30. class CTown;
  31. class CScriptCallback;
  32. class CCallback;
  33. class IGameCallback;
  34. class CLuaCallback;
  35. class CCPPObjectScript;
  36. class CCreatureSet;
  37. class CStack;
  38. class CGHeroInstance;
  39. class CGTownInstance;
  40. class CArmedInstance;
  41. class CGDwelling;
  42. class CGDefInfo;
  43. class CObjectScript;
  44. class CGObjectInstance;
  45. class CCreature;
  46. struct Mapa;
  47. struct StartInfo;
  48. struct SDL_Surface;
  49. class CMapHandler;
  50. class CPathfinder;
  51. struct SetObjectProperty;
  52. struct MetaString;
  53. struct CPack;
  54. class CSpell;
  55. struct TerrainTile;
  56. class CHeroClass;
  57. class CCampaign;
  58. class CCampaignState;
  59. class IModableArt;
  60. namespace boost
  61. {
  62. class shared_mutex;
  63. }
  64. //numbers of creatures are exact numbers if detailed else they are quantity ids (0 - a few, 1 - several and so on; additionaly -1 - unknown)
  65. struct DLL_EXPORT ArmyDescriptor : public std::map<TSlot, CStackBasicDescriptor>
  66. {
  67. ArmyDescriptor(const CArmedInstance *army, bool detailed); //not detailed -> quantity ids as count
  68. ArmyDescriptor();
  69. };
  70. struct DLL_EXPORT InfoAboutHero
  71. {
  72. private:
  73. void assign(const InfoAboutHero & iah);
  74. public:
  75. struct DLL_EXPORT Details
  76. {
  77. std::vector<int> primskills;
  78. int mana, luck, morale;
  79. } *details;
  80. char owner;
  81. const CHeroClass *hclass;
  82. std::string name;
  83. int portrait;
  84. ArmyDescriptor army;
  85. InfoAboutHero();
  86. InfoAboutHero(const InfoAboutHero & iah);
  87. InfoAboutHero & operator=(const InfoAboutHero & iah);
  88. ~InfoAboutHero();
  89. void initFromHero(const CGHeroInstance *h, bool detailed);
  90. };
  91. // typedef si32 TResourceUnit;
  92. // typedef std::vector<si32> TResourceVector;
  93. // typedef std::set<si32> TResourceSet;
  94. struct DLL_EXPORT SThievesGuildInfo
  95. {
  96. std::vector<ui8> playerColors; //colors of players that are in-game
  97. std::vector< std::list< ui8 > > numOfTowns, numOfHeroes, gold, woodOre, mercSulfCrystGems, obelisks, artifacts, army, income; // [place] -> [colours of players]
  98. std::map<ui8, InfoAboutHero> colorToBestHero; //maps player's color to his best heros'
  99. std::map<ui8, si8> personality; // color to personality // -1 - human, AI -> (00 - random, 01 - warrior, 02 - builder, 03 - explorer)
  100. std::map<ui8, si32> bestCreature; // color to ID // id or -1 if not known
  101. // template <typename Handler> void serialize(Handler &h, const int version)
  102. // {
  103. // h & playerColors & numOfTowns & numOfHeroes & gold & woodOre & mercSulfCrystGems & obelisks & artifacts & army & income;
  104. // h & colorToBestHero & personality & bestCreature;
  105. // }
  106. };
  107. struct DLL_EXPORT PlayerState : public CBonusSystemNode
  108. {
  109. public:
  110. enum EStatus {INGAME, LOSER, WINNER};
  111. ui8 color;
  112. ui8 human; //true if human controlled player, false for AI
  113. ui32 currentSelection; //id of hero/town, 0xffffffff if none
  114. ui8 team;
  115. std::vector<si32> resources;
  116. std::vector<ConstTransitivePtr<CGHeroInstance> > heroes;
  117. std::vector<ConstTransitivePtr<CGTownInstance> > towns;
  118. std::vector<ConstTransitivePtr<CGHeroInstance> > availableHeroes; //heroes available in taverns
  119. std::vector<ConstTransitivePtr<CGDwelling> > dwellings; //used for town growth
  120. ui8 enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory
  121. ui8 status; //0 - in game, 1 - loser, 2 - winner <- uses EStatus enum
  122. ui8 daysWithoutCastle;
  123. PlayerState();
  124. std::string nodeName() const OVERRIDE;
  125. //override
  126. //void getParents(TCNodes &out, const CBonusSystemNode *root = NULL) const;
  127. //void getBonuses(BonusList &out, const CSelector &selector, const CBonusSystemNode *root = NULL) const;
  128. template <typename Handler> void serialize(Handler &h, const int version)
  129. {
  130. h & color & human & currentSelection & team & resources & status;
  131. h & heroes & towns & availableHeroes & dwellings & bonuses;
  132. h & status & daysWithoutCastle;
  133. h & enteredLosingCheatCode & enteredWinningCheatCode;
  134. h & static_cast<CBonusSystemNode&>(*this);
  135. }
  136. };
  137. struct DLL_EXPORT TeamState : public CBonusSystemNode
  138. {
  139. public:
  140. ui8 id; //position in gameState::teams
  141. std::set<ui8> players; // members of this team
  142. std::vector<std::vector<std::vector<ui8> > > fogOfWarMap; //true - visible, false - hidden
  143. //TeamState();
  144. template <typename Handler> void serialize(Handler &h, const int version)
  145. {
  146. h & id & players & fogOfWarMap;
  147. h & static_cast<CBonusSystemNode&>(*this);
  148. }
  149. };
  150. struct DLL_EXPORT CObstacleInstance
  151. {
  152. int uniqueID;
  153. int ID; //ID of obstacle (defines type of it)
  154. int pos; //position on battlefield
  155. template <typename Handler> void serialize(Handler &h, const int version)
  156. {
  157. h & ID & pos & uniqueID;
  158. }
  159. };
  160. //only for use in BattleInfo
  161. struct DLL_EXPORT SiegeInfo
  162. {
  163. ui8 wallState[8]; //[0] - keep, [1] - bottom tower, [2] - bottom wall, [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate; 1 - intact, 2 - damaged, 3 - destroyed
  164. template <typename Handler> void serialize(Handler &h, const int version)
  165. {
  166. h & wallState;
  167. }
  168. };
  169. struct DLL_EXPORT BattleInfo : public CBonusSystemNode
  170. {
  171. ui8 side1, side2; //side1 - attacker, side2 - defender
  172. si32 round, activeStack;
  173. ui8 siege; // = 0 ordinary battle = 1 a siege with a Fort = 2 a siege with a Citadel = 3 a siege with a Castle
  174. si32 tid; //used during town siege - id of attacked town; -1 if not town defence
  175. int3 tile; //for background and bonuses
  176. CGHeroInstance *heroes[2];
  177. CArmedInstance *belligerents[2]; //may be same as heroes
  178. std::vector<CStack*> stacks;
  179. std::vector<CObstacleInstance> obstacles;
  180. ui8 castSpells[2]; //[0] - attacker, [1] - defender
  181. SiegeInfo si;
  182. template <typename Handler> void serialize(Handler &h, const int version)
  183. {
  184. h & side1 & side2 & round & activeStack & siege & tid & tile & stacks & belligerents & obstacles
  185. & castSpells & si;
  186. h & heroes;
  187. h & static_cast<CBonusSystemNode&>(*this);
  188. }
  189. //////////////////////////////////////////////////////////////////////////
  190. //void getBonuses(BonusList &out, const CSelector &selector, const CBonusSystemNode *root = NULL) const;
  191. //////////////////////////////////////////////////////////////////////////
  192. const CStack * getNextStack() const; //which stack will have turn after current one
  193. void getStackQueue(std::vector<const CStack *> &out, int howMany, int turn = 0, int lastMoved = -1) const; //returns stack in order of their movement action
  194. CStack * getStack(int stackID, bool onlyAlive = true);
  195. const CStack * getStack(int stackID, bool onlyAlive = true) const;
  196. CStack * getStackT(int tileID, bool onlyAlive = true);
  197. const CStack * getStackT(int tileID, bool onlyAlive = true) const;
  198. void getAccessibilityMap(bool *accessibility, bool twoHex, bool attackerOwned, bool addOccupiable, std::set<int> & occupyable, bool flying, int stackToOmmit=-1) const; //send pointer to at least 187 allocated bytes
  199. static bool isAccessible(int hex, bool * accessibility, bool twoHex, bool attackerOwned, bool flying, bool lastPos); //helper for makeBFS
  200. void makeBFS(int start, bool*accessibility, int *predecessor, int *dists, bool twoHex, bool attackerOwned, bool flying, bool fillPredecessors) const; //*accessibility must be prepared bool[187] array; last two pointers must point to the at least 187-elements int arrays - there is written result
  201. std::pair< std::vector<int>, int > getPath(int start, int dest, bool*accessibility, bool flyingCreature, bool twoHex, bool attackerOwned); //returned value: pair<path, length>; length may be different than number of elements in path since flying vreatures jump between distant hexes
  202. std::vector<int> getAccessibility(int stackID, bool addOccupiable) const; //returns vector of accessible tiles (taking into account the creature range)
  203. bool isStackBlocked(int ID); //returns true if there is neighboring enemy stack
  204. static signed char mutualPosition(int hex1, int hex2); //returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left)
  205. static std::vector<int> neighbouringTiles(int hex);
  206. static si8 getDistance(int hex1, int hex2); //returns distance between given hexes
  207. ui32 calculateDmg(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge, bool lucky); //charge - number of hexes travelled before attack (for champion's jousting)
  208. std::pair<ui32, ui32> calculateDmgRange(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge, bool lucky); //charge - number of hexes travelled before attack (for champion's jousting); returns pair <min dmg, max dmg>
  209. void calculateCasualties(std::map<ui32,si32> *casualties) const; //casualties are array of maps size 2 (attacker, defeneder), maps are (crid => amount)
  210. std::set<CStack*> getAttackedCreatures(const CSpell * s, int skillLevel, ui8 attackerOwner, int destinationTile); //calculates stack affected by given spell
  211. static int calculateSpellDuration(const CSpell * spell, const CGHeroInstance * caster, int usedSpellPower);
  212. CStack * generateNewStack(const CStackInstance &base, int stackID, bool attackerOwned, int slot, int position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield
  213. CStack * generateNewStack(const CStackBasicDescriptor &base, int stackID, bool attackerOwned, int slot, int position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield
  214. ui32 getSpellCost(const CSpell * sp, const CGHeroInstance * caster) const; //returns cost of given spell
  215. int hexToWallPart(int hex) const; //returns part of destructible wall / gate / keep under given hex or -1 if not found
  216. int lineToWallHex(int line) const; //returns hex with wall in given line
  217. std::pair<const CStack *, int> getNearestStack(const CStack * closest, boost::logic::tribool attackerOwned) const; //if attackerOwned is indetermnate, returened stack is of any owner; hex is the number of hex we should be looking from; returns (nerarest creature, predecessorHex)
  218. ui32 calculateSpellBonus(ui32 baseDamage, const CSpell * sp, const CGHeroInstance * caster, const CStack * affectedCreature) const;
  219. ui32 calculateSpellDmg(const CSpell * sp, const CGHeroInstance * caster, const CStack * affectedCreature, int spellSchoolLevel, int usedSpellPower) const; //calculates damage inflicted by spell
  220. ui32 calculateHealedHP(const CGHeroInstance * caster, const CSpell * spell, const CStack * stack) const;
  221. si8 hasDistancePenalty(int stackID, int destHex); //determines if given stack has distance penalty shooting given pos
  222. si8 sameSideOfWall(int pos1, int pos2); //determines if given positions are on the same side of wall
  223. si8 hasWallPenalty(int stackID, int destHex); //determines if given stack has wall penalty shooting given pos
  224. si8 canTeleportTo(int stackID, int destHex, int telportLevel); //determines if given stack can teleport to given place
  225. };
  226. class DLL_EXPORT CStack : public CBonusSystemNode, public CStackBasicDescriptor
  227. {
  228. public:
  229. const CStackInstance *base;
  230. ui32 ID; //unique ID of stack
  231. ui32 baseAmount;
  232. ui32 firstHPleft; //HP of first creature in stack
  233. ui8 owner, slot; //owner - player colour (255 for neutrals), slot - position in garrison (may be 255 for neutrals/called creatures)
  234. ui8 attackerOwned; //if true, this stack is owned by attakcer (this one from left hand side of battle)
  235. si16 position; //position on battlefield; -2 - keep, -3 - lower tower, -4 - upper tower
  236. ui8 counterAttacks; //how many counter attacks can be performed more in this turn (by default set at the beginning of the round to 1)
  237. si16 shots; //how many shots left
  238. std::set<ECombatInfo> state;
  239. //overrides
  240. const CCreature* getCreature() const {return type;}
  241. CStack(const CStackInstance *base, int O, int I, bool AO, int S); //c-tor
  242. CStack(const CStackBasicDescriptor *stack, int O, int I, bool AO, int S = 255); //c-tor
  243. CStack(); //c-tor
  244. ~CStack();
  245. std::string nodeName() const OVERRIDE;
  246. void init(); //set initial (invalid) values
  247. void postInit(); //used to finish initialization when inheriting creature parameters is working
  248. const Bonus * getEffect(ui16 id, int turn = 0) const; //effect id (SP)
  249. ui8 howManyEffectsSet(ui16 id) const; //returns amount of effects with given id set for this stack
  250. bool willMove(int turn = 0) const; //if stack has remaining move this turn
  251. bool moved(int turn = 0) const; //if stack was already moved this turn
  252. bool canMove(int turn = 0) const; //if stack can move
  253. ui32 Speed(int turn = 0) const; //get speed of creature with all modificators
  254. BonusList getSpellBonuses() const;
  255. void stackEffectToFeature(BonusList & sf, const Bonus & sse);
  256. std::vector<si32> activeSpells() const; //returns vector of active spell IDs sorted by time of cast
  257. const CGHeroInstance *getMyHero() const; //if stack belongs to hero (directly or was by him summoned) returns hero, NULL otherwise
  258. static inline Bonus *featureGenerator(Bonus::BonusType type, si16 subtype, si32 value, ui16 turnsRemain, si32 additionalInfo = 0, si32 limit = Bonus::NO_LIMIT)
  259. {
  260. Bonus *hb = makeFeature(type, Bonus::N_TURNS, subtype, value, Bonus::SPELL_EFFECT, turnsRemain, additionalInfo);
  261. hb->effectRange = limit;
  262. hb->source = Bonus::CASTED_SPELL; //right?
  263. return hb;
  264. }
  265. static inline Bonus *featureGeneratorVT(Bonus::BonusType type, si16 subtype, si32 value, ui16 turnsRemain, ui8 valType)
  266. {
  267. Bonus *ret(makeFeature(type, Bonus::N_TURNS, subtype, value, Bonus::SPELL_EFFECT, turnsRemain));
  268. ret->valType = valType;
  269. ret->source = Bonus::CASTED_SPELL; //right?
  270. return ret;
  271. }
  272. bool doubleWide() const;
  273. int occupiedHex() const; //returns number of occupied hex (not the position) if stack is double wide; otherwise -1
  274. template <typename Handler> void serialize(Handler &h, const int version)
  275. {
  276. assert(isIndependentNode());
  277. h & static_cast<CBonusSystemNode&>(*this);
  278. h & static_cast<CStackBasicDescriptor&>(*this);
  279. h & ID & baseAmount & firstHPleft & owner & slot & attackerOwned & position & state & counterAttacks
  280. & shots & count;
  281. TSlot slot = (base ? base->armyObj->findStack(base) : -1);
  282. const CArmedInstance *army = (base ? base->armyObj : NULL);
  283. if(h.saving)
  284. {
  285. h & army & slot;
  286. }
  287. else
  288. {
  289. h & army & slot;
  290. if(!army || slot == -1 || !army->hasStackAtSlot(slot))
  291. {
  292. base = NULL;
  293. tlog3 << type->nameSing << " don't have a base stack!\n";
  294. }
  295. else
  296. {
  297. base = &army->getStack(slot);
  298. }
  299. }
  300. }
  301. bool alive() const //determines if stack is alive
  302. {
  303. return vstd::contains(state,ALIVE);
  304. }
  305. };
  306. class DLL_EXPORT CMP_stack
  307. {
  308. int phase; //rules of which phase will be used
  309. int turn;
  310. public:
  311. bool operator ()(const CStack* a, const CStack* b);
  312. CMP_stack(int Phase = 1, int Turn = 0);
  313. };
  314. struct UpgradeInfo
  315. {
  316. int oldID; //creature to be upgraded
  317. std::vector<int> newID; //possible upgrades
  318. std::vector<std::set<std::pair<int,int> > > cost; // cost[upgrade_serial] -> set of pairs<resource_ID,resource_amount>
  319. UpgradeInfo(){oldID = -1;};
  320. };
  321. struct CPathNode
  322. {
  323. bool accessible; //true if a hero can be on this node
  324. int dist; //distance from the first node of searching; -1 is infinity
  325. CPathNode * theNodeBefore;
  326. int3 coord; //coordiantes
  327. bool visited;
  328. };
  329. struct CGPathNode
  330. {
  331. enum
  332. {
  333. ACCESSIBLE=1, //tile can be entered and passed
  334. VISITABLE, //tile can be entered as the last tile in path
  335. BLOCKVIS, //visitable from neighbouring tile but not passable
  336. BLOCKED, //tile can't be entered nor visited
  337. FLYABLE //if hero flies, he can pass this tile
  338. };
  339. ui8 accessible; //the enum above
  340. ui8 land;
  341. ui8 turns;
  342. ui32 moveRemains;
  343. CGPathNode * theNodeBefore;
  344. int3 coord; //coordinates
  345. CGPathNode();
  346. };
  347. struct DLL_EXPORT CPath
  348. {
  349. std::vector<CPathNode> nodes; //just get node by node
  350. int3 startPos() const; // start point
  351. int3 endPos() const; //destination point
  352. void convert(ui8 mode); //mode=0 -> from 'manifest' to 'object'
  353. };
  354. struct DLL_EXPORT CGPath
  355. {
  356. std::vector<CGPathNode> nodes; //just get node by node
  357. int3 startPos() const; // start point
  358. int3 endPos() const; //destination point
  359. void convert(ui8 mode); //mode=0 -> from 'manifest' to 'object'
  360. };
  361. struct DLL_EXPORT CPathsInfo
  362. {
  363. const CGHeroInstance *hero;
  364. int3 hpos;
  365. int3 sizes;
  366. CGPathNode ***nodes; //[w][h][level]
  367. bool getPath(const int3 &dst, CGPath &out);
  368. CPathsInfo(const int3 &Sizes);
  369. ~CPathsInfo();
  370. };
  371. class DLL_EXPORT CGameState
  372. {
  373. public:
  374. ConstTransitivePtr<StartInfo> scenarioOps, initialOpts; //second one is a copy of settings received from pregame (not randomized)
  375. ConstTransitivePtr<CCampaignState> campaign;
  376. ui32 seed;
  377. ui8 currentPlayer; //ID of player currently having turn
  378. ConstTransitivePtr<BattleInfo> curB; //current battle
  379. ui32 day; //total number of days in game
  380. ConstTransitivePtr<Mapa> map;
  381. bmap<ui8, PlayerState> players; //ID <-> player state
  382. bmap<ui8, TeamState> teams; //ID <-> team state
  383. bmap<int, ConstTransitivePtr<CGDefInfo> > villages, forts, capitols; //def-info for town graphics
  384. CBonusSystemNode globalEffects;
  385. struct DLL_EXPORT HeroesPool
  386. {
  387. bmap<ui32, ConstTransitivePtr<CGHeroInstance> > heroesPool; //[subID] - heroes available to buy; NULL if not available
  388. bmap<ui32,ui8> pavailable; // [subid] -> which players can recruit hero (binary flags)
  389. CGHeroInstance * pickHeroFor(bool native, int player, const CTown *town, bmap<ui32, ConstTransitivePtr<CGHeroInstance> > &available, const CHeroClass *bannedClass = NULL) const;
  390. template <typename Handler> void serialize(Handler &h, const int version)
  391. {
  392. h & heroesPool & pavailable;
  393. }
  394. } hpool; //we have here all heroes available on this map that are not hired
  395. boost::shared_mutex *mx;
  396. PlayerState *getPlayer(ui8 color, bool verbose = true);
  397. TeamState *getTeam(ui8 teamID);//get team by team ID
  398. TeamState *getPlayerTeam(ui8 color);// get team by player color
  399. const PlayerState *getPlayer(ui8 color, bool verbose = true) const;
  400. const TeamState *getTeam(ui8 teamID) const;
  401. const TeamState *getPlayerTeam(ui8 color) const;
  402. void init(StartInfo * si, ui32 checksum, int Seed);
  403. void buildGameLogicTree();
  404. void loadTownDInfos();
  405. void randomizeObject(CGObjectInstance *cur);
  406. std::pair<int,int> pickObject(CGObjectInstance *obj); //chooses type of object to be randomized, returns <type, subtype>
  407. int pickHero(int owner);
  408. void apply(CPack *pack);
  409. CGHeroInstance *getHero(int objid);
  410. CGTownInstance *getTown(int objid);
  411. const CGHeroInstance *getHero(int objid) const;
  412. const CGTownInstance *getTown(int objid) const;
  413. bool battleCanFlee(int player); //returns true if player can flee from the battle
  414. int battleGetStack(int pos, bool onlyAlive); //returns ID of stack at given tile
  415. int battleGetBattlefieldType(int3 tile = int3());// 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship
  416. const CGHeroInstance * battleGetOwner(int stackID); //returns hero that owns given stack; NULL if none
  417. si8 battleMaxSpellLevel(); //calculates maximum spell level possible to be cast on battlefield - takes into account artifacts of both heroes; if no effects are set, SPELL_LEVELS is returned
  418. bool battleCanShoot(int ID, int dest); //determines if stack with given ID shoot at the selected destination
  419. UpgradeInfo getUpgradeInfo(const CStackInstance &stack);
  420. int getPlayerRelations(ui8 color1, ui8 color2);// 0 = enemy, 1 = ally, 2 = same player
  421. //float getMarketEfficiency(int player, int mode=0);
  422. std::set<int> getBuildingRequiments(const CGTownInstance *t, int ID);
  423. int canBuildStructure(const CGTownInstance *t, int ID);// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements
  424. bool checkForVisitableDir(const int3 & src, const int3 & dst) const; //check if src tile is visitable from dst tile
  425. bool checkForVisitableDir(const int3 & src, const TerrainTile *pom, const int3 & dst) const; //check if src tile is visitable from dst tile
  426. bool getPath(int3 src, int3 dest, const CGHeroInstance * hero, CPath &ret); //calculates path between src and dest; returns pointer to newly allocated CPath or NULL if path does not exists
  427. void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out, int3 src = int3(-1,-1,-1), int movement = -1); //calculates possible paths for hero, by default uses current hero position and movement left; returns pointer to newly allocated CPath or NULL if path does not exists
  428. int3 guardingCreaturePosition (int3 pos) const;
  429. int victoryCheck(ui8 player) const; //checks if given player is winner; -1 if std victory, 1 if special victory, 0 else
  430. int lossCheck(ui8 player) const; //checks if given player is loser; -1 if std loss, 1 if special, 0 else
  431. ui8 checkForStandardWin() const; //returns color of player that accomplished standard victory conditions or 255 if no winner
  432. bool checkForStandardLoss(ui8 player) const; //checks if given player lost the game
  433. void obtainPlayersStats(SThievesGuildInfo & tgi, int level); //fills tgi with info about other players that is available at given level of thieves' guild
  434. bmap<ui32, ConstTransitivePtr<CGHeroInstance> > unusedHeroesFromPool(); //heroes pool without heroes that are available in taverns
  435. BattleInfo * setupBattle(int3 tile, const CArmedInstance *armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance *town);
  436. bool isVisible(int3 pos, int player);
  437. bool isVisible(const CGObjectInstance *obj, int player);
  438. CGameState(); //c-tor
  439. ~CGameState(); //d-tor
  440. void getNeighbours(const TerrainTile &srct, int3 tile, std::vector<int3> &vec, const boost::logic::tribool &onLand, bool limitCoastSailing);
  441. int getMovementCost(const CGHeroInstance *h, const int3 &src, const int3 &dest, int remainingMovePoints=-1, bool checkLast=true);
  442. 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
  443. template <typename Handler> void serialize(Handler &h, const int version)
  444. {
  445. h & scenarioOps & seed & currentPlayer & day & map & players & teams & hpool & globalEffects & campaign;
  446. h & villages & forts & capitols;
  447. if(!h.saving)
  448. {
  449. loadTownDInfos();
  450. }
  451. }
  452. friend class CCallback;
  453. friend class CLuaCallback;
  454. friend class CClient;
  455. friend void initGameState(Mapa * map, CGameInfo * cgi);
  456. friend class IGameCallback;
  457. friend class CMapHandler;
  458. friend class CGameHandler;
  459. };
  460. #endif // __CGAMESTATE_H__