BattleInfo.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * BattleInfo.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "SiegeInfo.h"
  12. #include "SideInBattle.h"
  13. #include "../HeroBonus.h"
  14. #include "CBattleInfoCallback.h"
  15. #include "../int3.h"
  16. class CStack;
  17. class CStackInstance;
  18. class CStackBasicDescriptor;
  19. struct DLL_LINKAGE BattleInfo : public CBonusSystemNode, public CBattleInfoCallback
  20. {
  21. std::array<SideInBattle, 2> sides; //sides[0] - attacker, sides[1] - defender
  22. si32 round, activeStack, selectedStack;
  23. const CGTownInstance * town; //used during town siege, nullptr if this is not a siege (note that fortless town IS also a siege)
  24. int3 tile; //for background and bonuses
  25. std::vector<CStack*> stacks;
  26. std::vector<std::shared_ptr<CObstacleInstance> > obstacles;
  27. SiegeInfo si;
  28. BFieldType battlefieldType; //like !!BA:B
  29. ETerrainType terrainType; //used for some stack nativity checks (not the bonus limiters though that have their own copy)
  30. ui8 tacticsSide; //which side is requested to play tactics phase
  31. ui8 tacticDistance; //how many hexes we can go forward (1 = only hexes adjacent to margin line)
  32. template <typename Handler> void serialize(Handler &h, const int version)
  33. {
  34. h & sides;
  35. h & round;
  36. h & activeStack;
  37. h & selectedStack;
  38. h & town;
  39. h & tile;
  40. h & stacks;
  41. h & obstacles;
  42. h & si;
  43. h & battlefieldType;
  44. h & terrainType;
  45. h & tacticsSide;
  46. h & tacticDistance;
  47. h & static_cast<CBonusSystemNode&>(*this);
  48. }
  49. //////////////////////////////////////////////////////////////////////////
  50. BattleInfo();
  51. ~BattleInfo(){};
  52. //////////////////////////////////////////////////////////////////////////
  53. CStack * getStack(int stackID, bool onlyAlive = true);
  54. using CBattleInfoEssentials::battleGetArmyObject;
  55. CArmedInstance * battleGetArmyObject(ui8 side) const;
  56. using CBattleInfoEssentials::battleGetFightingHero;
  57. CGHeroInstance * battleGetFightingHero(ui8 side) const;
  58. const CStack * getNextStack() const; //which stack will have turn after current one
  59. int getAvaliableHex(CreatureID creID, ui8 side, int initialPos = -1) const; //find place for summon / clone effects
  60. std::pair< std::vector<BattleHex>, int > getPath(BattleHex start, BattleHex dest, const CStack * stack); //returned value: pair<path, length>; length may be different than number of elements in path since flying vreatures jump between distant hexes
  61. std::shared_ptr<CObstacleInstance> getObstacleOnTile(BattleHex tile) const;
  62. std::set<BattleHex> getStoppers(bool whichSidePerspective) const;
  63. ui32 calculateDmg(const CStack * attacker, const CStack * defender, bool shooting, ui8 charge, bool lucky, bool unlucky, bool deathBlow, bool ballistaDoubleDmg, CRandomGenerator & rand); //charge - number of hexes travelled before attack (for champion's jousting)
  64. void calculateCasualties(std::map<ui32,si32> * casualties) const; //casualties are array of maps size 2 (attacker, defeneder), maps are (crid => amount)
  65. CStack * generateNewStack(const CStackInstance &base, ui8 side, SlotID slot, BattleHex position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield
  66. CStack * generateNewStack(const CStackBasicDescriptor &base, ui8 side, SlotID slot, BattleHex position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield
  67. int getIdForNewStack() const; //suggest a currently unused ID that'd suitable for generating a new stack
  68. const CGHeroInstance * getHero(PlayerColor player) const; //returns fighting hero that belongs to given player
  69. void localInit();
  70. static BattleInfo * setupBattle(int3 tile, ETerrainType terrain, BFieldType battlefieldType, const CArmedInstance * armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance * town);
  71. //bool hasNativeStack(ui8 side) const;
  72. PlayerColor theOtherPlayer(PlayerColor player) const;
  73. ui8 whatSide(PlayerColor player) const;
  74. static BattlefieldBI::BattlefieldBI battlefieldTypeToBI(BFieldType bfieldType); //converts above to ERM BI format
  75. static int battlefieldTypeToTerrain(int bfieldType); //converts above to ERM BI format
  76. };
  77. class DLL_LINKAGE CMP_stack
  78. {
  79. int phase; //rules of which phase will be used
  80. int turn;
  81. public:
  82. bool operator ()(const CStack* a, const CStack* b);
  83. CMP_stack(int Phase = 1, int Turn = 0);
  84. };