BattleStateInfoForRetreat.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * BattleStateInfoForRetreat.cpp, 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. #include "StdInc.h"
  11. #include "BattleStateInfoForRetreat.h"
  12. #include "Unit.h"
  13. #include "CBattleInfoCallback.h"
  14. #include "../CCreatureSet.h"
  15. #include "../mapObjects/CGHeroInstance.h"
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. BattleStateInfoForRetreat::BattleStateInfoForRetreat()
  18. : canFlee(false), canSurrender(false), isLastTurnBeforeDie(false), ourStacks(), enemyStacks(), ourHero(nullptr), enemyHero(nullptr), ourSide(-1)
  19. {
  20. }
  21. uint64_t getFightingStrength(std::vector<const battle::Unit *> stacks, const CGHeroInstance * hero = nullptr)
  22. {
  23. uint64_t result = 0;
  24. for(const battle::Unit * stack : stacks)
  25. {
  26. result += stack->creatureId().toCreature()->AIValue * stack->getCount();
  27. }
  28. if(hero)
  29. {
  30. result = (uint64_t)(result * hero->getFightingStrength());
  31. }
  32. return result;
  33. }
  34. uint64_t BattleStateInfoForRetreat::getOurStrength() const
  35. {
  36. return getFightingStrength(ourStacks, ourHero);
  37. }
  38. uint64_t BattleStateInfoForRetreat::getEnemyStrength() const
  39. {
  40. return getFightingStrength(enemyStacks, enemyHero);
  41. }
  42. VCMI_LIB_NAMESPACE_END