BattleLogic.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #ifndef __BATTLE_LOGIC_H__
  2. #define __BATTLE_LOGIC_H__
  3. #include "Common.h"
  4. #include "BattleHelper.h"
  5. #pragma warning (disable: 4100 4251 4245 4018 4081)
  6. #include "../../global.h"
  7. #include "../../CCallback.h"
  8. #include "../../lib/CCreatureHandler.h"
  9. #include "../../lib/CObjectHandler.h"
  10. #pragma warning (default: 4100 4251 4245 4018 4081)
  11. #pragma warning (disable: 4100)
  12. using namespace std;
  13. namespace geniusai { namespace BattleAI {
  14. /**
  15. * Class is responsible for making decision during the battle.
  16. */
  17. class CBattleLogic
  18. {
  19. private:
  20. enum EMainStrategyType
  21. {
  22. strategy_super_aggresive,
  23. strategy_aggresive,
  24. strategy_neutral,
  25. strategy_defensive,
  26. strategy_super_defensive,
  27. strategy_berserk_attack /** cause max damage, usually when creatures fight against overwhelming army*/
  28. };
  29. enum ECreatureRoleInBattle
  30. {
  31. creature_role_shooter,
  32. creature_role_defenser,
  33. creature_role_fast_attacker,
  34. creature_role_attacker
  35. };
  36. enum EActionType
  37. {
  38. action_cancel = 0, // Cancel BattleAction
  39. action_cast_spell = 1, // Hero cast a spell
  40. action_walk = 2, // Walk
  41. action_defend = 3, // Defend
  42. action_retreat = 4, // Retreat from the battle
  43. action_surrender = 5, // Surrender
  44. action_walk_and_attack = 6, // Walk and Attack
  45. action_shoot = 7, // Shoot
  46. action_wait = 8, // Wait
  47. action_catapult = 9, // Catapult
  48. action_monster_casts_spell = 10 // Monster casts a spell (i.e. Faerie Dragons)
  49. };
  50. struct SCreatureCasualties
  51. {
  52. int amount_max; // amount of creatures that will be dead
  53. int amount_min;
  54. int damage_max; // number of hit points that creature will lost
  55. int damage_min;
  56. int leftHitPoints_for_max; // number of hit points that will remain (for last unity)
  57. int leftHitPoint_for_min; // scenario
  58. };
  59. public:
  60. CBattleLogic(CCallback *cb, const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side);
  61. ~CBattleLogic();
  62. void SetCurrentTurn(int turn);
  63. /**
  64. * Get the final decision.
  65. */
  66. BattleAction MakeDecision(int stackID);
  67. private:
  68. CBattleHelper m_battleHelper;
  69. //BattleInfo m_battleInfo;
  70. int m_iCurrentTurn;
  71. bool m_bIsAttacker;
  72. CCallback *m_cb;
  73. const CCreatureSet *m_army1;
  74. const CCreatureSet *m_army2;
  75. int3 m_tile;
  76. const CGHeroInstance *m_hero1;
  77. const CGHeroInstance *m_hero2;
  78. bool m_side;
  79. // statistics
  80. typedef std::vector<std::pair<int, int> > creature_stat; // first - creature id, second - value
  81. creature_stat m_statMaxDamage;
  82. creature_stat m_statMinDamage;
  83. //
  84. creature_stat m_statMaxSpeed;
  85. creature_stat m_statDistance;
  86. creature_stat m_statDistanceFromShooters;
  87. creature_stat m_statHitPoints;
  88. typedef std::vector<std::pair<int, SCreatureCasualties> > creature_stat_casualties;
  89. creature_stat_casualties m_statCasualties;
  90. bool m_bEnemyDominates;
  91. /**
  92. * Before decision we have to make some calculation and simulation.
  93. */
  94. void MakeStatistics(int currentCreatureId);
  95. /**
  96. * Helper function. It's used for performing an attack action.
  97. */
  98. std::vector<int> GetAvailableHexesForAttacker(const CStack *defender, const CStack *attacker = NULL);
  99. /**
  100. * Make an attack action if it's possible.
  101. * If it's not possible then function returns defend action.
  102. */
  103. BattleAction MakeAttack(int attackerID, int destinationID);
  104. /**
  105. * Berserk mode - do maximum casualties.
  106. * Return vector wiht IDs of creatures to attack,
  107. * additional info: -2 means wait, -1 - defend, 0 - make attack
  108. */
  109. list<int> PerformBerserkAttack(int stackID, int &additionalInfo);
  110. /**
  111. * Normal mode - equilibrium between casualties and yields.
  112. * Return vector wiht IDs of creatures to attack,
  113. * additional info: -2 means wait, -1 - defend, 0 - make attack
  114. */
  115. list<int> PerformDefaultAction(int stackID, int &additionalInfo);
  116. /**
  117. * Only for debug purpose.
  118. */
  119. void PrintBattleAction(const BattleAction &action);
  120. };
  121. }}
  122. #endif/*__BATTLE_LOGIC_H__*/