BattleInfo.h 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 & activeStack & selectedStack & town & tile & stacks & obstacles
  36. & si & battlefieldType & terrainType;
  37. h & tacticsSide & tacticDistance;
  38. h & static_cast<CBonusSystemNode&>(*this);
  39. }
  40. //////////////////////////////////////////////////////////////////////////
  41. BattleInfo();
  42. ~BattleInfo(){};
  43. //////////////////////////////////////////////////////////////////////////
  44. CStack * getStack(int stackID, bool onlyAlive = true);
  45. using CBattleInfoEssentials::battleGetArmyObject;
  46. CArmedInstance * battleGetArmyObject(ui8 side) const;
  47. using CBattleInfoEssentials::battleGetFightingHero;
  48. CGHeroInstance * battleGetFightingHero(ui8 side) const;
  49. const CStack * getNextStack() const; //which stack will have turn after current one
  50. int getAvaliableHex(CreatureID creID, ui8 side, int initialPos = -1) const; //find place for summon / clone effects
  51. 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
  52. std::shared_ptr<CObstacleInstance> getObstacleOnTile(BattleHex tile) const;
  53. std::set<BattleHex> getStoppers(bool whichSidePerspective) const;
  54. 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)
  55. void calculateCasualties(std::map<ui32,si32> * casualties) const; //casualties are array of maps size 2 (attacker, defeneder), maps are (crid => amount)
  56. CStack * generateNewStack(const CStackInstance &base, ui8 side, SlotID slot, BattleHex position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield
  57. CStack * generateNewStack(const CStackBasicDescriptor &base, ui8 side, SlotID slot, BattleHex position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield
  58. int getIdForNewStack() const; //suggest a currently unused ID that'd suitable for generating a new stack
  59. const CGHeroInstance * getHero(PlayerColor player) const; //returns fighting hero that belongs to given player
  60. void localInit();
  61. void localInitStack(CStack * s);
  62. static BattleInfo * setupBattle(int3 tile, ETerrainType terrain, BFieldType battlefieldType, const CArmedInstance * armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance * town);
  63. //bool hasNativeStack(ui8 side) const;
  64. PlayerColor theOtherPlayer(PlayerColor player) const;
  65. ui8 whatSide(PlayerColor player) const;
  66. static BattlefieldBI::BattlefieldBI battlefieldTypeToBI(BFieldType bfieldType); //converts above to ERM BI format
  67. static int battlefieldTypeToTerrain(int bfieldType); //converts above to ERM BI format
  68. };
  69. class DLL_LINKAGE CMP_stack
  70. {
  71. int phase; //rules of which phase will be used
  72. int turn;
  73. public:
  74. bool operator ()(const CStack* a, const CStack* b);
  75. CMP_stack(int Phase = 1, int Turn = 0);
  76. };