BattleActionsController.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  1. /*
  2. * BattleActionsController.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 "BattleActionsController.h"
  12. #include "BattleWindow.h"
  13. #include "BattleStacksController.h"
  14. #include "BattleInterface.h"
  15. #include "BattleFieldController.h"
  16. #include "BattleSiegeController.h"
  17. #include "BattleInterfaceClasses.h"
  18. #include "../CPlayerInterface.h"
  19. #include "../gui/CursorHandler.h"
  20. #include "../GameEngine.h"
  21. #include "../gui/CIntObject.h"
  22. #include "../gui/WindowHandler.h"
  23. #include "../windows/CCreatureWindow.h"
  24. #include "../windows/InfoWindows.h"
  25. #include "../../CCallback.h"
  26. #include "../../lib/CConfigHandler.h"
  27. #include "../../lib/texts/CGeneralTextHandler.h"
  28. #include "../../lib/CRandomGenerator.h"
  29. #include "../../lib/CStack.h"
  30. #include "../../lib/battle/BattleAction.h"
  31. #include "../../lib/spells/CSpellHandler.h"
  32. #include "../../lib/spells/ISpellMechanics.h"
  33. #include "../../lib/spells/Problem.h"
  34. struct TextReplacement
  35. {
  36. std::string placeholder;
  37. std::string replacement;
  38. };
  39. using TextReplacementList = std::vector<TextReplacement>;
  40. static std::string replacePlaceholders(std::string input, const TextReplacementList & format )
  41. {
  42. for(const auto & entry : format)
  43. boost::replace_all(input, entry.placeholder, entry.replacement);
  44. return input;
  45. }
  46. static std::string translatePlural(int amount, const std::string& baseTextID)
  47. {
  48. if(amount == 1)
  49. return VLC->generaltexth->translate(baseTextID + ".1");
  50. return VLC->generaltexth->translate(baseTextID);
  51. }
  52. static std::string formatPluralImpl(int amount, const std::string & amountString, const std::string & baseTextID)
  53. {
  54. std::string baseString = translatePlural(amount, baseTextID);
  55. TextReplacementList replacements {
  56. { "%d", amountString }
  57. };
  58. return replacePlaceholders(baseString, replacements);
  59. }
  60. static std::string formatPlural(int amount, const std::string & baseTextID)
  61. {
  62. return formatPluralImpl(amount, std::to_string(amount), baseTextID);
  63. }
  64. static std::string formatPlural(DamageRange range, const std::string & baseTextID)
  65. {
  66. if (range.min == range.max)
  67. return formatPlural(range.min, baseTextID);
  68. std::string rangeString = std::to_string(range.min) + " - " + std::to_string(range.max);
  69. return formatPluralImpl(range.max, rangeString, baseTextID);
  70. }
  71. static std::string formatAttack(const DamageEstimation & estimation, const std::string & creatureName, const std::string & baseTextID, int shotsLeft)
  72. {
  73. TextReplacementList replacements = {
  74. { "%CREATURE", creatureName },
  75. { "%DAMAGE", formatPlural(estimation.damage, "vcmi.battleWindow.damageEstimation.damage") },
  76. { "%SHOTS", formatPlural(shotsLeft, "vcmi.battleWindow.damageEstimation.shots") },
  77. { "%KILLS", formatPlural(estimation.kills, "vcmi.battleWindow.damageEstimation.kills") },
  78. };
  79. return replacePlaceholders(VLC->generaltexth->translate(baseTextID), replacements);
  80. }
  81. static std::string formatMeleeAttack(const DamageEstimation & estimation, const std::string & creatureName)
  82. {
  83. std::string baseTextID = estimation.kills.max == 0 ?
  84. "vcmi.battleWindow.damageEstimation.melee" :
  85. "vcmi.battleWindow.damageEstimation.meleeKills";
  86. return formatAttack(estimation, creatureName, baseTextID, 0);
  87. }
  88. static std::string formatRangedAttack(const DamageEstimation & estimation, const std::string & creatureName, int shotsLeft)
  89. {
  90. std::string baseTextID = estimation.kills.max == 0 ?
  91. "vcmi.battleWindow.damageEstimation.ranged" :
  92. "vcmi.battleWindow.damageEstimation.rangedKills";
  93. return formatAttack(estimation, creatureName, baseTextID, shotsLeft);
  94. }
  95. static std::string formatRetaliation(const DamageEstimation & estimation, bool mayBeKilled)
  96. {
  97. if (estimation.damage.max == 0)
  98. return VLC->generaltexth->translate("vcmi.battleWindow.damageRetaliation.never");
  99. std::string baseTextID = estimation.kills.max == 0 ?
  100. "vcmi.battleWindow.damageRetaliation.damage" :
  101. "vcmi.battleWindow.damageRetaliation.damageKills";
  102. std::string prefixTextID = mayBeKilled ?
  103. "vcmi.battleWindow.damageRetaliation.may" :
  104. "vcmi.battleWindow.damageRetaliation.will";
  105. return VLC->generaltexth->translate(prefixTextID) + formatAttack(estimation, "", baseTextID, 0);
  106. }
  107. BattleActionsController::BattleActionsController(BattleInterface & owner):
  108. owner(owner),
  109. selectedStack(nullptr),
  110. heroSpellToCast(nullptr)
  111. {
  112. }
  113. void BattleActionsController::endCastingSpell()
  114. {
  115. if(heroSpellToCast)
  116. {
  117. heroSpellToCast.reset();
  118. owner.windowObject->blockUI(false);
  119. }
  120. if(owner.stacksController->getActiveStack())
  121. possibleActions = getPossibleActionsForStack(owner.stacksController->getActiveStack()); //restore actions after they were cleared
  122. selectedStack = nullptr;
  123. ENGINE->fakeMouseMove();
  124. }
  125. bool BattleActionsController::isActiveStackSpellcaster() const
  126. {
  127. const CStack * casterStack = owner.stacksController->getActiveStack();
  128. if (!casterStack)
  129. return false;
  130. bool spellcaster = casterStack->hasBonusOfType(BonusType::SPELLCASTER);
  131. return (spellcaster && casterStack->canCast());
  132. }
  133. void BattleActionsController::enterCreatureCastingMode()
  134. {
  135. //silently check for possible errors
  136. if (owner.tacticsMode)
  137. return;
  138. //hero is casting a spell
  139. if (heroSpellToCast)
  140. return;
  141. if (!owner.stacksController->getActiveStack())
  142. return;
  143. if(owner.getBattle()->battleCanTargetEmptyHex(owner.stacksController->getActiveStack()))
  144. {
  145. auto actionFilterPredicate = [](const PossiblePlayerBattleAction x)
  146. {
  147. return x.get() != PossiblePlayerBattleAction::SHOOT;
  148. };
  149. vstd::erase_if(possibleActions, actionFilterPredicate);
  150. ENGINE->fakeMouseMove();
  151. return;
  152. }
  153. if (!isActiveStackSpellcaster())
  154. return;
  155. for(const auto & action : possibleActions)
  156. {
  157. if (action.get() != PossiblePlayerBattleAction::NO_LOCATION)
  158. continue;
  159. const spells::Caster * caster = owner.stacksController->getActiveStack();
  160. const CSpell * spell = action.spell().toSpell();
  161. spells::Target target;
  162. target.emplace_back();
  163. spells::BattleCast cast(owner.getBattle().get(), caster, spells::Mode::CREATURE_ACTIVE, spell);
  164. auto m = spell->battleMechanics(&cast);
  165. spells::detail::ProblemImpl ignored;
  166. const bool isCastingPossible = m->canBeCastAt(target, ignored);
  167. if (isCastingPossible)
  168. {
  169. owner.giveCommand(EActionType::MONSTER_SPELL, BattleHex::INVALID, spell->getId());
  170. selectedStack = nullptr;
  171. ENGINE->cursor().set(Cursor::Combat::POINTER);
  172. }
  173. return;
  174. }
  175. possibleActions = getPossibleActionsForStack(owner.stacksController->getActiveStack());
  176. auto actionFilterPredicate = [](const PossiblePlayerBattleAction x)
  177. {
  178. return !x.spellcast();
  179. };
  180. vstd::erase_if(possibleActions, actionFilterPredicate);
  181. ENGINE->fakeMouseMove();
  182. }
  183. std::vector<PossiblePlayerBattleAction> BattleActionsController::getPossibleActionsForStack(const CStack *stack) const
  184. {
  185. BattleClientInterfaceData data; //hard to get rid of these things so for now they're required data to pass
  186. for(const auto & spell : creatureSpells)
  187. data.creatureSpellsToCast.push_back(spell->id);
  188. data.tacticsMode = owner.tacticsMode;
  189. auto allActions = owner.getBattle()->getClientActionsForStack(stack, data);
  190. allActions.push_back(PossiblePlayerBattleAction::HERO_INFO);
  191. allActions.push_back(PossiblePlayerBattleAction::CREATURE_INFO);
  192. return std::vector<PossiblePlayerBattleAction>(allActions);
  193. }
  194. void BattleActionsController::reorderPossibleActionsPriority(const CStack * stack, const CStack * targetStack)
  195. {
  196. if(owner.tacticsMode || possibleActions.empty()) return; //this function is not supposed to be called in tactics mode or before getPossibleActionsForStack
  197. auto assignPriority = [&](const PossiblePlayerBattleAction & item
  198. ) -> uint8_t //large lambda assigning priority which would have to be part of possibleActions without it
  199. {
  200. switch(item.get())
  201. {
  202. case PossiblePlayerBattleAction::AIMED_SPELL_CREATURE:
  203. case PossiblePlayerBattleAction::ANY_LOCATION:
  204. case PossiblePlayerBattleAction::NO_LOCATION:
  205. case PossiblePlayerBattleAction::FREE_LOCATION:
  206. case PossiblePlayerBattleAction::OBSTACLE:
  207. if(!stack->hasBonusOfType(BonusType::NO_SPELLCAST_BY_DEFAULT) && targetStack != nullptr)
  208. {
  209. PlayerColor stackOwner = owner.getBattle()->battleGetOwner(targetStack);
  210. bool enemyTargetingPositiveSpellcast = item.spell().toSpell()->isPositive() && stackOwner != LOCPLINT->playerID;
  211. bool friendTargetingNegativeSpellcast = item.spell().toSpell()->isNegative() && stackOwner == LOCPLINT->playerID;
  212. if(!enemyTargetingPositiveSpellcast && !friendTargetingNegativeSpellcast)
  213. return 1;
  214. }
  215. return 100; //bottom priority
  216. break;
  217. case PossiblePlayerBattleAction::RANDOM_GENIE_SPELL:
  218. return 2;
  219. break;
  220. case PossiblePlayerBattleAction::SHOOT:
  221. if(targetStack == nullptr || targetStack->unitSide() == stack->unitSide() || !targetStack->alive())
  222. return 100; //bottom priority
  223. return 4;
  224. break;
  225. case PossiblePlayerBattleAction::ATTACK_AND_RETURN:
  226. return 5;
  227. break;
  228. case PossiblePlayerBattleAction::ATTACK:
  229. return 6;
  230. break;
  231. case PossiblePlayerBattleAction::WALK_AND_ATTACK:
  232. return 7;
  233. break;
  234. case PossiblePlayerBattleAction::MOVE_STACK:
  235. return 8;
  236. break;
  237. case PossiblePlayerBattleAction::CATAPULT:
  238. return 9;
  239. break;
  240. case PossiblePlayerBattleAction::HEAL:
  241. return 10;
  242. break;
  243. case PossiblePlayerBattleAction::CREATURE_INFO:
  244. return 11;
  245. break;
  246. case PossiblePlayerBattleAction::HERO_INFO:
  247. return 12;
  248. break;
  249. case PossiblePlayerBattleAction::TELEPORT:
  250. return 13;
  251. break;
  252. default:
  253. assert(0);
  254. return 200;
  255. break;
  256. }
  257. };
  258. auto comparer = [&](const PossiblePlayerBattleAction & lhs, const PossiblePlayerBattleAction & rhs)
  259. {
  260. return assignPriority(lhs) < assignPriority(rhs);
  261. };
  262. std::sort(possibleActions.begin(), possibleActions.end(), comparer);
  263. }
  264. void BattleActionsController::castThisSpell(SpellID spellID)
  265. {
  266. heroSpellToCast = std::make_shared<BattleAction>();
  267. heroSpellToCast->actionType = EActionType::HERO_SPELL;
  268. heroSpellToCast->spell = spellID;
  269. heroSpellToCast->stackNumber = -1;
  270. heroSpellToCast->side = owner.curInt->cb->getBattle(owner.getBattleID())->battleGetMySide();
  271. //choosing possible targets
  272. const CGHeroInstance *castingHero = (owner.attackingHeroInstance->tempOwner == owner.curInt->playerID) ? owner.attackingHeroInstance : owner.defendingHeroInstance;
  273. assert(castingHero); // code below assumes non-null hero
  274. PossiblePlayerBattleAction spellSelMode = owner.getBattle()->getCasterAction(spellID.toSpell(), castingHero, spells::Mode::HERO);
  275. if (spellSelMode.get() == PossiblePlayerBattleAction::NO_LOCATION) //user does not have to select location
  276. {
  277. heroSpellToCast->aimToHex(BattleHex::INVALID);
  278. owner.curInt->cb->battleMakeSpellAction(owner.getBattleID(), *heroSpellToCast);
  279. endCastingSpell();
  280. }
  281. else
  282. {
  283. possibleActions.clear();
  284. possibleActions.push_back (spellSelMode); //only this one action can be performed at the moment
  285. ENGINE->fakeMouseMove();//update cursor
  286. }
  287. owner.windowObject->blockUI(true);
  288. }
  289. const CSpell * BattleActionsController::getHeroSpellToCast( ) const
  290. {
  291. if (heroSpellToCast)
  292. return heroSpellToCast->spell.toSpell();
  293. return nullptr;
  294. }
  295. const CSpell * BattleActionsController::getStackSpellToCast(const BattleHex & hoveredHex)
  296. {
  297. if (heroSpellToCast)
  298. return nullptr;
  299. if (!owner.stacksController->getActiveStack())
  300. return nullptr;
  301. if (!hoveredHex.isValid())
  302. return nullptr;
  303. auto action = selectAction(hoveredHex);
  304. if(owner.stacksController->getActiveStack()->hasBonusOfType(BonusType::SPELL_LIKE_ATTACK))
  305. {
  306. auto bonus = owner.stacksController->getActiveStack()->getBonus(Selector::type()(BonusType::SPELL_LIKE_ATTACK));
  307. return bonus->subtype.as<SpellID>().toSpell();
  308. }
  309. if (action.spell() == SpellID::NONE)
  310. return nullptr;
  311. return action.spell().toSpell();
  312. }
  313. const CSpell * BattleActionsController::getCurrentSpell(const BattleHex & hoveredHex)
  314. {
  315. if (getHeroSpellToCast())
  316. return getHeroSpellToCast();
  317. return getStackSpellToCast(hoveredHex);
  318. }
  319. const CStack * BattleActionsController::getStackForHex(const BattleHex & hoveredHex)
  320. {
  321. const CStack * shere = owner.getBattle()->battleGetStackByPos(hoveredHex, true);
  322. if(shere)
  323. return shere;
  324. return owner.getBattle()->battleGetStackByPos(hoveredHex, false);
  325. }
  326. void BattleActionsController::actionSetCursor(PossiblePlayerBattleAction action, const BattleHex & targetHex)
  327. {
  328. switch (action.get())
  329. {
  330. case PossiblePlayerBattleAction::CHOOSE_TACTICS_STACK:
  331. ENGINE->cursor().set(Cursor::Combat::POINTER);
  332. return;
  333. case PossiblePlayerBattleAction::MOVE_TACTICS:
  334. case PossiblePlayerBattleAction::MOVE_STACK:
  335. if (owner.stacksController->getActiveStack()->hasBonusOfType(BonusType::FLYING))
  336. ENGINE->cursor().set(Cursor::Combat::FLY);
  337. else
  338. ENGINE->cursor().set(Cursor::Combat::MOVE);
  339. return;
  340. case PossiblePlayerBattleAction::ATTACK:
  341. case PossiblePlayerBattleAction::WALK_AND_ATTACK:
  342. case PossiblePlayerBattleAction::ATTACK_AND_RETURN:
  343. {
  344. static const std::map<BattleHex::EDir, Cursor::Combat> sectorCursor = {
  345. {BattleHex::TOP_LEFT, Cursor::Combat::HIT_SOUTHEAST},
  346. {BattleHex::TOP_RIGHT, Cursor::Combat::HIT_SOUTHWEST},
  347. {BattleHex::RIGHT, Cursor::Combat::HIT_WEST },
  348. {BattleHex::BOTTOM_RIGHT, Cursor::Combat::HIT_NORTHWEST},
  349. {BattleHex::BOTTOM_LEFT, Cursor::Combat::HIT_NORTHEAST},
  350. {BattleHex::LEFT, Cursor::Combat::HIT_EAST },
  351. {BattleHex::TOP, Cursor::Combat::HIT_SOUTH },
  352. {BattleHex::BOTTOM, Cursor::Combat::HIT_NORTH }
  353. };
  354. auto direction = owner.fieldController->selectAttackDirection(targetHex);
  355. assert(sectorCursor.count(direction) > 0);
  356. if (sectorCursor.count(direction))
  357. ENGINE->cursor().set(sectorCursor.at(direction));
  358. return;
  359. }
  360. case PossiblePlayerBattleAction::SHOOT:
  361. if (owner.getBattle()->battleHasShootingPenalty(owner.stacksController->getActiveStack(), targetHex))
  362. ENGINE->cursor().set(Cursor::Combat::SHOOT_PENALTY);
  363. else
  364. ENGINE->cursor().set(Cursor::Combat::SHOOT);
  365. return;
  366. case PossiblePlayerBattleAction::AIMED_SPELL_CREATURE:
  367. case PossiblePlayerBattleAction::ANY_LOCATION:
  368. case PossiblePlayerBattleAction::RANDOM_GENIE_SPELL:
  369. case PossiblePlayerBattleAction::FREE_LOCATION:
  370. case PossiblePlayerBattleAction::OBSTACLE:
  371. ENGINE->cursor().set(Cursor::Spellcast::SPELL);
  372. return;
  373. case PossiblePlayerBattleAction::TELEPORT:
  374. ENGINE->cursor().set(Cursor::Combat::TELEPORT);
  375. return;
  376. case PossiblePlayerBattleAction::SACRIFICE:
  377. ENGINE->cursor().set(Cursor::Combat::SACRIFICE);
  378. return;
  379. case PossiblePlayerBattleAction::HEAL:
  380. ENGINE->cursor().set(Cursor::Combat::HEAL);
  381. return;
  382. case PossiblePlayerBattleAction::CATAPULT:
  383. ENGINE->cursor().set(Cursor::Combat::SHOOT_CATAPULT);
  384. return;
  385. case PossiblePlayerBattleAction::CREATURE_INFO:
  386. ENGINE->cursor().set(Cursor::Combat::QUERY);
  387. return;
  388. case PossiblePlayerBattleAction::HERO_INFO:
  389. ENGINE->cursor().set(Cursor::Combat::HERO);
  390. return;
  391. }
  392. assert(0);
  393. }
  394. void BattleActionsController::actionSetCursorBlocked(PossiblePlayerBattleAction action, const BattleHex & targetHex)
  395. {
  396. switch (action.get())
  397. {
  398. case PossiblePlayerBattleAction::AIMED_SPELL_CREATURE:
  399. case PossiblePlayerBattleAction::RANDOM_GENIE_SPELL:
  400. case PossiblePlayerBattleAction::TELEPORT:
  401. case PossiblePlayerBattleAction::SACRIFICE:
  402. case PossiblePlayerBattleAction::FREE_LOCATION:
  403. ENGINE->cursor().set(Cursor::Combat::BLOCKED);
  404. return;
  405. default:
  406. if (targetHex == -1)
  407. ENGINE->cursor().set(Cursor::Combat::POINTER);
  408. else
  409. ENGINE->cursor().set(Cursor::Combat::BLOCKED);
  410. return;
  411. }
  412. assert(0);
  413. }
  414. std::string BattleActionsController::actionGetStatusMessage(PossiblePlayerBattleAction action, const BattleHex & targetHex)
  415. {
  416. const CStack * targetStack = getStackForHex(targetHex);
  417. switch (action.get()) //display console message, realize selected action
  418. {
  419. case PossiblePlayerBattleAction::CHOOSE_TACTICS_STACK:
  420. return (boost::format(VLC->generaltexth->allTexts[481]) % targetStack->getName()).str(); //Select %s
  421. case PossiblePlayerBattleAction::MOVE_TACTICS:
  422. case PossiblePlayerBattleAction::MOVE_STACK:
  423. if (owner.stacksController->getActiveStack()->hasBonusOfType(BonusType::FLYING))
  424. return (boost::format(VLC->generaltexth->allTexts[295]) % owner.stacksController->getActiveStack()->getName()).str(); //Fly %s here
  425. else
  426. return (boost::format(VLC->generaltexth->allTexts[294]) % owner.stacksController->getActiveStack()->getName()).str(); //Move %s here
  427. case PossiblePlayerBattleAction::ATTACK:
  428. case PossiblePlayerBattleAction::WALK_AND_ATTACK:
  429. case PossiblePlayerBattleAction::ATTACK_AND_RETURN: //TODO: allow to disable return
  430. {
  431. const auto * attacker = owner.stacksController->getActiveStack();
  432. BattleHex attackFromHex = owner.fieldController->fromWhichHexAttack(targetHex);
  433. int distance = attacker->position.isValid() ? owner.getBattle()->battleGetDistances(attacker, attacker->getPosition())[attackFromHex.toInt()] : 0;
  434. DamageEstimation retaliation;
  435. BattleAttackInfo attackInfo(attacker, targetStack, distance, false );
  436. DamageEstimation estimation = owner.getBattle()->battleEstimateDamage(attackInfo, &retaliation);
  437. estimation.kills.max = std::min<int64_t>(estimation.kills.max, targetStack->getCount());
  438. estimation.kills.min = std::min<int64_t>(estimation.kills.min, targetStack->getCount());
  439. bool enemyMayBeKilled = estimation.kills.max == targetStack->getCount();
  440. return formatMeleeAttack(estimation, targetStack->getName()) + "\n" + formatRetaliation(retaliation, enemyMayBeKilled);
  441. }
  442. case PossiblePlayerBattleAction::SHOOT:
  443. {
  444. if(targetStack == nullptr) //should be true only for spell-like attack
  445. {
  446. auto spellLikeAttackBonus = owner.stacksController->getActiveStack()->getBonus(Selector::type()(BonusType::SPELL_LIKE_ATTACK));
  447. assert(spellLikeAttackBonus != nullptr);
  448. return boost::str(boost::format(VLC->generaltexth->allTexts[26]) % spellLikeAttackBonus->subtype.as<SpellID>().toSpell()->getNameTranslated());
  449. }
  450. const auto * shooter = owner.stacksController->getActiveStack();
  451. DamageEstimation retaliation;
  452. BattleAttackInfo attackInfo(shooter, targetStack, 0, true );
  453. DamageEstimation estimation = owner.getBattle()->battleEstimateDamage(attackInfo, &retaliation);
  454. estimation.kills.max = std::min<int64_t>(estimation.kills.max, targetStack->getCount());
  455. estimation.kills.min = std::min<int64_t>(estimation.kills.min, targetStack->getCount());
  456. return formatRangedAttack(estimation, targetStack->getName(), shooter->shots.available());
  457. }
  458. case PossiblePlayerBattleAction::AIMED_SPELL_CREATURE:
  459. return boost::str(boost::format(VLC->generaltexth->allTexts[27]) % action.spell().toSpell()->getNameTranslated() % targetStack->getName()); //Cast %s on %s
  460. case PossiblePlayerBattleAction::ANY_LOCATION:
  461. return boost::str(boost::format(VLC->generaltexth->allTexts[26]) % action.spell().toSpell()->getNameTranslated()); //Cast %s
  462. case PossiblePlayerBattleAction::RANDOM_GENIE_SPELL: //we assume that teleport / sacrifice will never be available as random spell
  463. return boost::str(boost::format(VLC->generaltexth->allTexts[301]) % targetStack->getName()); //Cast a spell on %
  464. case PossiblePlayerBattleAction::TELEPORT:
  465. return VLC->generaltexth->allTexts[25]; //Teleport Here
  466. case PossiblePlayerBattleAction::OBSTACLE:
  467. return VLC->generaltexth->allTexts[550];
  468. case PossiblePlayerBattleAction::SACRIFICE:
  469. return (boost::format(VLC->generaltexth->allTexts[549]) % targetStack->getName()).str(); //sacrifice the %s
  470. case PossiblePlayerBattleAction::FREE_LOCATION:
  471. return boost::str(boost::format(VLC->generaltexth->allTexts[26]) % action.spell().toSpell()->getNameTranslated()); //Cast %s
  472. case PossiblePlayerBattleAction::HEAL:
  473. return (boost::format(VLC->generaltexth->allTexts[419]) % targetStack->getName()).str(); //Apply first aid to the %s
  474. case PossiblePlayerBattleAction::CATAPULT:
  475. return ""; // TODO
  476. case PossiblePlayerBattleAction::CREATURE_INFO:
  477. return (boost::format(VLC->generaltexth->allTexts[297]) % targetStack->getName()).str();
  478. case PossiblePlayerBattleAction::HERO_INFO:
  479. return VLC->generaltexth->translate("core.genrltxt.417"); // "View Hero Stats"
  480. }
  481. assert(0);
  482. return "";
  483. }
  484. std::string BattleActionsController::actionGetStatusMessageBlocked(PossiblePlayerBattleAction action, const BattleHex & targetHex)
  485. {
  486. switch (action.get())
  487. {
  488. case PossiblePlayerBattleAction::AIMED_SPELL_CREATURE:
  489. case PossiblePlayerBattleAction::RANDOM_GENIE_SPELL:
  490. return VLC->generaltexth->allTexts[23];
  491. break;
  492. case PossiblePlayerBattleAction::TELEPORT:
  493. return VLC->generaltexth->allTexts[24]; //Invalid Teleport Destination
  494. break;
  495. case PossiblePlayerBattleAction::SACRIFICE:
  496. return VLC->generaltexth->allTexts[543]; //choose army to sacrifice
  497. break;
  498. case PossiblePlayerBattleAction::FREE_LOCATION:
  499. return boost::str(boost::format(VLC->generaltexth->allTexts[181]) % action.spell().toSpell()->getNameTranslated()); //No room to place %s here
  500. break;
  501. default:
  502. return "";
  503. }
  504. }
  505. bool BattleActionsController::actionIsLegal(PossiblePlayerBattleAction action, const BattleHex & targetHex)
  506. {
  507. const CStack * targetStack = getStackForHex(targetHex);
  508. bool targetStackOwned = targetStack && targetStack->unitOwner() == owner.curInt->playerID;
  509. switch (action.get())
  510. {
  511. case PossiblePlayerBattleAction::CHOOSE_TACTICS_STACK:
  512. return (targetStack && targetStackOwned && targetStack->getMovementRange() > 0);
  513. case PossiblePlayerBattleAction::CREATURE_INFO:
  514. return (targetStack && targetStackOwned && targetStack->alive());
  515. case PossiblePlayerBattleAction::HERO_INFO:
  516. if (targetHex == BattleHex::HERO_ATTACKER)
  517. return owner.attackingHero != nullptr;
  518. if (targetHex == BattleHex::HERO_DEFENDER)
  519. return owner.defendingHero != nullptr;
  520. return false;
  521. case PossiblePlayerBattleAction::MOVE_TACTICS:
  522. case PossiblePlayerBattleAction::MOVE_STACK:
  523. if (!(targetStack && targetStack->alive())) //we can walk on dead stacks
  524. {
  525. if(canStackMoveHere(owner.stacksController->getActiveStack(), targetHex))
  526. return true;
  527. }
  528. return false;
  529. case PossiblePlayerBattleAction::ATTACK:
  530. case PossiblePlayerBattleAction::WALK_AND_ATTACK:
  531. case PossiblePlayerBattleAction::ATTACK_AND_RETURN:
  532. if(owner.getBattle()->battleCanAttack(owner.stacksController->getActiveStack(), targetStack, targetHex))
  533. {
  534. if (owner.fieldController->isTileAttackable(targetHex)) // move isTileAttackable to be part of battleCanAttack?
  535. return true;
  536. }
  537. return false;
  538. case PossiblePlayerBattleAction::SHOOT:
  539. {
  540. auto currentStack = owner.stacksController->getActiveStack();
  541. if(!owner.getBattle()->battleCanShoot(currentStack, targetHex))
  542. return false;
  543. if(targetStack == nullptr && owner.getBattle()->battleCanTargetEmptyHex(currentStack))
  544. {
  545. auto spellLikeAttackBonus = currentStack->getBonus(Selector::type()(BonusType::SPELL_LIKE_ATTACK));
  546. const CSpell * spellDataToCheck = spellLikeAttackBonus->subtype.as<SpellID>().toSpell();
  547. return isCastingPossibleHere(spellDataToCheck, nullptr, targetHex);
  548. }
  549. return true;
  550. }
  551. case PossiblePlayerBattleAction::NO_LOCATION:
  552. return false;
  553. case PossiblePlayerBattleAction::ANY_LOCATION:
  554. return isCastingPossibleHere(action.spell().toSpell(), nullptr, targetHex);
  555. case PossiblePlayerBattleAction::AIMED_SPELL_CREATURE:
  556. return !selectedStack && targetStack && isCastingPossibleHere(action.spell().toSpell(), nullptr, targetHex);
  557. case PossiblePlayerBattleAction::RANDOM_GENIE_SPELL:
  558. if(targetStack && targetStackOwned && targetStack != owner.stacksController->getActiveStack() && targetStack->alive()) //only positive spells for other allied creatures
  559. {
  560. SpellID spellID = owner.getBattle()->getRandomBeneficialSpell(CRandomGenerator::getDefault(), owner.stacksController->getActiveStack(), targetStack);
  561. return spellID != SpellID::NONE;
  562. }
  563. return false;
  564. case PossiblePlayerBattleAction::TELEPORT:
  565. return selectedStack && isCastingPossibleHere(action.spell().toSpell(), selectedStack, targetHex);
  566. case PossiblePlayerBattleAction::SACRIFICE: //choose our living stack to sacrifice
  567. return targetStack && targetStack != selectedStack && targetStackOwned && targetStack->alive();
  568. case PossiblePlayerBattleAction::OBSTACLE:
  569. case PossiblePlayerBattleAction::FREE_LOCATION:
  570. return isCastingPossibleHere(action.spell().toSpell(), nullptr, targetHex);
  571. case PossiblePlayerBattleAction::CATAPULT:
  572. return owner.siegeController && owner.siegeController->isAttackableByCatapult(targetHex);
  573. case PossiblePlayerBattleAction::HEAL:
  574. return targetStack && targetStackOwned && targetStack->canBeHealed();
  575. }
  576. assert(0);
  577. return false;
  578. }
  579. void BattleActionsController::actionRealize(PossiblePlayerBattleAction action, const BattleHex & targetHex)
  580. {
  581. const CStack * targetStack = getStackForHex(targetHex);
  582. switch (action.get()) //display console message, realize selected action
  583. {
  584. case PossiblePlayerBattleAction::CHOOSE_TACTICS_STACK:
  585. {
  586. owner.stackActivated(targetStack);
  587. return;
  588. }
  589. case PossiblePlayerBattleAction::MOVE_TACTICS:
  590. case PossiblePlayerBattleAction::MOVE_STACK:
  591. {
  592. if(owner.stacksController->getActiveStack()->doubleWide())
  593. {
  594. BattleHexArray acc = owner.getBattle()->battleGetAvailableHexes(owner.stacksController->getActiveStack(), false);
  595. BattleHex shiftedDest = targetHex.cloneInDirection(owner.stacksController->getActiveStack()->destShiftDir(), false);
  596. if(acc.contains(targetHex))
  597. owner.giveCommand(EActionType::WALK, targetHex);
  598. else if(acc.contains(shiftedDest))
  599. owner.giveCommand(EActionType::WALK, shiftedDest);
  600. }
  601. else
  602. {
  603. owner.giveCommand(EActionType::WALK, targetHex);
  604. }
  605. return;
  606. }
  607. case PossiblePlayerBattleAction::ATTACK:
  608. case PossiblePlayerBattleAction::WALK_AND_ATTACK:
  609. case PossiblePlayerBattleAction::ATTACK_AND_RETURN: //TODO: allow to disable return
  610. {
  611. bool returnAfterAttack = action.get() == PossiblePlayerBattleAction::ATTACK_AND_RETURN;
  612. BattleHex attackFromHex = owner.fieldController->fromWhichHexAttack(targetHex);
  613. if(attackFromHex.isValid()) //we can be in this line when unreachable creature is L - clicked (as of revision 1308)
  614. {
  615. BattleAction command = BattleAction::makeMeleeAttack(owner.stacksController->getActiveStack(), targetHex, attackFromHex, returnAfterAttack);
  616. owner.sendCommand(command, owner.stacksController->getActiveStack());
  617. }
  618. return;
  619. }
  620. case PossiblePlayerBattleAction::SHOOT:
  621. {
  622. owner.giveCommand(EActionType::SHOOT, targetHex);
  623. return;
  624. }
  625. case PossiblePlayerBattleAction::HEAL:
  626. {
  627. owner.giveCommand(EActionType::STACK_HEAL, targetHex);
  628. return;
  629. };
  630. case PossiblePlayerBattleAction::CATAPULT:
  631. {
  632. owner.giveCommand(EActionType::CATAPULT, targetHex);
  633. return;
  634. }
  635. case PossiblePlayerBattleAction::CREATURE_INFO:
  636. {
  637. ENGINE->windows().createAndPushWindow<CStackWindow>(targetStack, false);
  638. return;
  639. }
  640. case PossiblePlayerBattleAction::HERO_INFO:
  641. {
  642. if (targetHex == BattleHex::HERO_ATTACKER)
  643. owner.attackingHero->heroLeftClicked();
  644. if (targetHex == BattleHex::HERO_DEFENDER)
  645. owner.defendingHero->heroLeftClicked();
  646. return;
  647. }
  648. case PossiblePlayerBattleAction::AIMED_SPELL_CREATURE:
  649. case PossiblePlayerBattleAction::ANY_LOCATION:
  650. case PossiblePlayerBattleAction::RANDOM_GENIE_SPELL: //we assume that teleport / sacrifice will never be available as random spell
  651. case PossiblePlayerBattleAction::TELEPORT:
  652. case PossiblePlayerBattleAction::OBSTACLE:
  653. case PossiblePlayerBattleAction::SACRIFICE:
  654. case PossiblePlayerBattleAction::FREE_LOCATION:
  655. {
  656. if (action.get() == PossiblePlayerBattleAction::AIMED_SPELL_CREATURE )
  657. {
  658. if (action.spell() == SpellID::SACRIFICE)
  659. {
  660. heroSpellToCast->aimToHex(targetHex);
  661. possibleActions.push_back({PossiblePlayerBattleAction::SACRIFICE, action.spell()});
  662. selectedStack = targetStack;
  663. return;
  664. }
  665. if (action.spell() == SpellID::TELEPORT)
  666. {
  667. heroSpellToCast->aimToUnit(targetStack);
  668. possibleActions.push_back({PossiblePlayerBattleAction::TELEPORT, action.spell()});
  669. selectedStack = targetStack;
  670. return;
  671. }
  672. }
  673. if (!heroSpellcastingModeActive())
  674. {
  675. if (action.spell().hasValue())
  676. {
  677. owner.giveCommand(EActionType::MONSTER_SPELL, targetHex, action.spell());
  678. }
  679. else //unknown random spell
  680. {
  681. owner.giveCommand(EActionType::MONSTER_SPELL, targetHex);
  682. }
  683. }
  684. else
  685. {
  686. assert(getHeroSpellToCast());
  687. switch (getHeroSpellToCast()->id.toEnum())
  688. {
  689. case SpellID::SACRIFICE:
  690. heroSpellToCast->aimToUnit(targetStack);//victim
  691. break;
  692. default:
  693. heroSpellToCast->aimToHex(targetHex);
  694. break;
  695. }
  696. owner.curInt->cb->battleMakeSpellAction(owner.getBattleID(), *heroSpellToCast);
  697. endCastingSpell();
  698. }
  699. selectedStack = nullptr;
  700. return;
  701. }
  702. }
  703. assert(0);
  704. return;
  705. }
  706. PossiblePlayerBattleAction BattleActionsController::selectAction(const BattleHex & targetHex)
  707. {
  708. assert(owner.stacksController->getActiveStack() != nullptr);
  709. assert(!possibleActions.empty());
  710. assert(targetHex.isValid());
  711. if (owner.stacksController->getActiveStack() == nullptr)
  712. return PossiblePlayerBattleAction::INVALID;
  713. if (possibleActions.empty())
  714. return PossiblePlayerBattleAction::INVALID;
  715. const CStack * targetStack = getStackForHex(targetHex);
  716. reorderPossibleActionsPriority(owner.stacksController->getActiveStack(), targetStack);
  717. for (PossiblePlayerBattleAction action : possibleActions)
  718. {
  719. if (actionIsLegal(action, targetHex))
  720. return action;
  721. }
  722. return possibleActions.front();
  723. }
  724. void BattleActionsController::onHexHovered(const BattleHex & hoveredHex)
  725. {
  726. if (owner.openingPlaying())
  727. {
  728. currentConsoleMsg = VLC->generaltexth->translate("vcmi.battleWindow.pressKeyToSkipIntro");
  729. ENGINE->statusbar()->write(currentConsoleMsg);
  730. return;
  731. }
  732. if (owner.stacksController->getActiveStack() == nullptr)
  733. return;
  734. if (hoveredHex == BattleHex::INVALID)
  735. {
  736. if (!currentConsoleMsg.empty())
  737. ENGINE->statusbar()->clearIfMatching(currentConsoleMsg);
  738. currentConsoleMsg.clear();
  739. ENGINE->cursor().set(Cursor::Combat::BLOCKED);
  740. return;
  741. }
  742. auto action = selectAction(hoveredHex);
  743. std::string newConsoleMsg;
  744. if (actionIsLegal(action, hoveredHex))
  745. {
  746. actionSetCursor(action, hoveredHex);
  747. newConsoleMsg = actionGetStatusMessage(action, hoveredHex);
  748. }
  749. else
  750. {
  751. actionSetCursorBlocked(action, hoveredHex);
  752. newConsoleMsg = actionGetStatusMessageBlocked(action, hoveredHex);
  753. }
  754. if (!currentConsoleMsg.empty())
  755. ENGINE->statusbar()->clearIfMatching(currentConsoleMsg);
  756. if (!newConsoleMsg.empty())
  757. ENGINE->statusbar()->write(newConsoleMsg);
  758. currentConsoleMsg = newConsoleMsg;
  759. }
  760. void BattleActionsController::onHoverEnded()
  761. {
  762. ENGINE->cursor().set(Cursor::Combat::POINTER);
  763. if (!currentConsoleMsg.empty())
  764. ENGINE->statusbar()->clearIfMatching(currentConsoleMsg);
  765. currentConsoleMsg.clear();
  766. }
  767. void BattleActionsController::onHexLeftClicked(const BattleHex & clickedHex)
  768. {
  769. if (owner.stacksController->getActiveStack() == nullptr)
  770. return;
  771. auto action = selectAction(clickedHex);
  772. std::string newConsoleMsg;
  773. if (!actionIsLegal(action, clickedHex))
  774. return;
  775. actionRealize(action, clickedHex);
  776. ENGINE->statusbar()->clear();
  777. }
  778. void BattleActionsController::tryActivateStackSpellcasting(const CStack *casterStack)
  779. {
  780. creatureSpells.clear();
  781. bool spellcaster = casterStack->hasBonusOfType(BonusType::SPELLCASTER);
  782. if(casterStack->canCast() && spellcaster)
  783. {
  784. // faerie dragon can cast only one, randomly selected spell until their next move
  785. //TODO: faerie dragon type spell should be selected by server
  786. const auto spellToCast = owner.getBattle()->getRandomCastedSpell(CRandomGenerator::getDefault(), casterStack);
  787. if (spellToCast.hasValue())
  788. creatureSpells.push_back(spellToCast.toSpell());
  789. }
  790. TConstBonusListPtr bl = casterStack->getBonusesOfType(BonusType::SPELLCASTER);
  791. for(const auto & bonus : *bl)
  792. {
  793. if (bonus->additionalInfo[0] <= 0 && bonus->subtype.as<SpellID>().hasValue())
  794. creatureSpells.push_back(bonus->subtype.as<SpellID>().toSpell());
  795. }
  796. }
  797. const spells::Caster * BattleActionsController::getCurrentSpellcaster() const
  798. {
  799. if (heroSpellToCast)
  800. return owner.currentHero();
  801. else
  802. return owner.stacksController->getActiveStack();
  803. }
  804. spells::Mode BattleActionsController::getCurrentCastMode() const
  805. {
  806. if (heroSpellToCast)
  807. return spells::Mode::HERO;
  808. else
  809. return spells::Mode::CREATURE_ACTIVE;
  810. }
  811. bool BattleActionsController::isCastingPossibleHere(const CSpell * currentSpell, const CStack *targetStack, const BattleHex & targetHex)
  812. {
  813. assert(currentSpell);
  814. if (!currentSpell)
  815. return false;
  816. auto caster = getCurrentSpellcaster();
  817. const spells::Mode mode = heroSpellToCast ? spells::Mode::HERO : spells::Mode::CREATURE_ACTIVE;
  818. spells::Target target;
  819. if(targetStack)
  820. target.emplace_back(targetStack);
  821. target.emplace_back(targetHex);
  822. spells::BattleCast cast(owner.getBattle().get(), caster, mode, currentSpell);
  823. auto m = currentSpell->battleMechanics(&cast);
  824. spells::detail::ProblemImpl problem; //todo: display problem in status bar
  825. return m->canBeCastAt(target, problem);
  826. }
  827. bool BattleActionsController::canStackMoveHere(const CStack * stackToMove, const BattleHex & myNumber) const
  828. {
  829. BattleHexArray acc = owner.getBattle()->battleGetAvailableHexes(stackToMove, false);
  830. BattleHex shiftedDest = myNumber.cloneInDirection(stackToMove->destShiftDir(), false);
  831. if (acc.contains(myNumber))
  832. return true;
  833. else if (stackToMove->doubleWide() && acc.contains(shiftedDest))
  834. return true;
  835. else
  836. return false;
  837. }
  838. void BattleActionsController::activateStack()
  839. {
  840. const CStack * s = owner.stacksController->getActiveStack();
  841. if(s)
  842. {
  843. tryActivateStackSpellcasting(s);
  844. possibleActions = getPossibleActionsForStack(s);
  845. std::list<PossiblePlayerBattleAction> actionsToSelect;
  846. if(!possibleActions.empty())
  847. {
  848. auto primaryAction = possibleActions.front().get();
  849. if(primaryAction == PossiblePlayerBattleAction::SHOOT || primaryAction == PossiblePlayerBattleAction::AIMED_SPELL_CREATURE
  850. || primaryAction == PossiblePlayerBattleAction::ANY_LOCATION || primaryAction == PossiblePlayerBattleAction::ATTACK_AND_RETURN)
  851. {
  852. actionsToSelect.push_back(possibleActions.front());
  853. auto shootActionPredicate = [](const PossiblePlayerBattleAction& action)
  854. {
  855. return action.get() == PossiblePlayerBattleAction::SHOOT;
  856. };
  857. bool hasShootSecondaryAction = std::any_of(possibleActions.begin() + 1, possibleActions.end(), shootActionPredicate);
  858. if(hasShootSecondaryAction) //casters may have shooting capabilities, for example storm elementals
  859. actionsToSelect.emplace_back(PossiblePlayerBattleAction::SHOOT);
  860. /* TODO: maybe it would also make sense to check spellcast as non-top priority action ("NO_SPELLCAST_BY_DEFAULT" bonus)?
  861. * it would require going beyond this "if" block for melee casters
  862. * F button helps, but some mod creatures may have that bonus and more than 1 castable spell */
  863. actionsToSelect.emplace_back(PossiblePlayerBattleAction::ATTACK); //always allow melee attack as last option
  864. }
  865. }
  866. owner.windowObject->setAlternativeActions(actionsToSelect);
  867. }
  868. }
  869. void BattleActionsController::onHexRightClicked(const BattleHex & clickedHex)
  870. {
  871. bool isCurrentStackInSpellcastMode = creatureSpellcastingModeActive();
  872. if (heroSpellcastingModeActive() || isCurrentStackInSpellcastMode)
  873. {
  874. endCastingSpell();
  875. CRClickPopup::createAndPush(VLC->generaltexth->translate("core.genrltxt.731")); // spell cancelled
  876. return;
  877. }
  878. auto selectedStack = owner.getBattle()->battleGetStackByPos(clickedHex, true);
  879. if (selectedStack != nullptr)
  880. ENGINE->windows().createAndPushWindow<CStackWindow>(selectedStack, true);
  881. if (clickedHex == BattleHex::HERO_ATTACKER && owner.attackingHero)
  882. owner.attackingHero->heroRightClicked();
  883. if (clickedHex == BattleHex::HERO_DEFENDER && owner.defendingHero)
  884. owner.defendingHero->heroRightClicked();
  885. }
  886. bool BattleActionsController::heroSpellcastingModeActive() const
  887. {
  888. return heroSpellToCast != nullptr;
  889. }
  890. bool BattleActionsController::creatureSpellcastingModeActive() const
  891. {
  892. auto spellcastModePredicate = [](const PossiblePlayerBattleAction & action)
  893. {
  894. return action.spellcast() || action.get() == PossiblePlayerBattleAction::SHOOT; //for hotkey-eligible SPELL_LIKE_ATTACK creature should have only SHOOT action
  895. };
  896. return !possibleActions.empty() && std::all_of(possibleActions.begin(), possibleActions.end(), spellcastModePredicate);
  897. }
  898. bool BattleActionsController::currentActionSpellcasting(const BattleHex & hoveredHex)
  899. {
  900. if (heroSpellToCast)
  901. return true;
  902. if (!owner.stacksController->getActiveStack())
  903. return false;
  904. auto action = selectAction(hoveredHex);
  905. return action.spellcast();
  906. }
  907. const std::vector<PossiblePlayerBattleAction> & BattleActionsController::getPossibleActions() const
  908. {
  909. return possibleActions;
  910. }
  911. void BattleActionsController::removePossibleAction(PossiblePlayerBattleAction action)
  912. {
  913. vstd::erase(possibleActions, action);
  914. }
  915. void BattleActionsController::pushFrontPossibleAction(PossiblePlayerBattleAction action)
  916. {
  917. possibleActions.insert(possibleActions.begin(), action);
  918. }
  919. void BattleActionsController::resetCurrentStackPossibleActions()
  920. {
  921. possibleActions = getPossibleActionsForStack(owner.stacksController->getActiveStack());
  922. }