BattleActionsController.cpp 37 KB

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