BattleActionsController.cpp 37 KB

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