CBattleStacksController.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. /*
  2. * CBattleStacksController.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 "CBattleStacksController.h"
  12. #include "CBattleSiegeController.h"
  13. #include "CBattleInterfaceClasses.h"
  14. #include "CBattleInterface.h"
  15. #include "CBattleAnimations.h"
  16. #include "CBattleFieldController.h"
  17. #include "CBattleEffectsController.h"
  18. #include "CBattleProjectileController.h"
  19. #include "CBattleControlPanel.h"
  20. #include "../CBitmapHandler.h"
  21. #include "../gui/SDL_Extensions.h"
  22. #include "../gui/CGuiHandler.h"
  23. #include "../../lib/battle/BattleHex.h"
  24. #include "../CPlayerInterface.h"
  25. #include "CCreatureAnimation.h"
  26. #include "../../lib/CGameState.h"
  27. #include "../../CCallback.h"
  28. #include "../../lib/CStack.h"
  29. #include "../../lib/CondSh.h"
  30. #include "../CMusicHandler.h"
  31. #include "../CGameInfo.h"
  32. static void onAnimationFinished(const CStack *stack, std::weak_ptr<CCreatureAnimation> anim)
  33. {
  34. std::shared_ptr<CCreatureAnimation> animation = anim.lock();
  35. if(!animation)
  36. return;
  37. if (animation->isIdle())
  38. {
  39. const CCreature *creature = stack->getCreature();
  40. if (animation->framesInGroup(CCreatureAnim::MOUSEON) > 0)
  41. {
  42. if (CRandomGenerator::getDefault().nextDouble(99.0) < creature->animation.timeBetweenFidgets *10)
  43. animation->playOnce(CCreatureAnim::MOUSEON);
  44. else
  45. animation->setType(CCreatureAnim::HOLDING);
  46. }
  47. else
  48. {
  49. animation->setType(CCreatureAnim::HOLDING);
  50. }
  51. }
  52. // always reset callback
  53. animation->onAnimationReset += std::bind(&onAnimationFinished, stack, anim);
  54. }
  55. static void transformPalette(SDL_Surface *surf, double rCor, double gCor, double bCor)
  56. {
  57. SDL_Color *colorsToChange = surf->format->palette->colors;
  58. for (int g=0; g<surf->format->palette->ncolors; ++g)
  59. {
  60. SDL_Color *color = &colorsToChange[g];
  61. if (color->b != 132 &&
  62. color->g != 231 &&
  63. color->r != 255) //it's not yellow border
  64. {
  65. color->r = static_cast<Uint8>(color->r * rCor);
  66. color->g = static_cast<Uint8>(color->g * gCor);
  67. color->b = static_cast<Uint8>(color->b * bCor);
  68. }
  69. }
  70. }
  71. CBattleStacksController::CBattleStacksController(CBattleInterface * owner):
  72. owner(owner)
  73. {
  74. //preparing graphics for displaying amounts of creatures
  75. amountNormal = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
  76. CSDL_Ext::alphaTransform(amountNormal);
  77. transformPalette(amountNormal, 0.59, 0.19, 0.93);
  78. amountPositive = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
  79. CSDL_Ext::alphaTransform(amountPositive);
  80. transformPalette(amountPositive, 0.18, 1.00, 0.18);
  81. amountNegative = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
  82. CSDL_Ext::alphaTransform(amountNegative);
  83. transformPalette(amountNegative, 1.00, 0.18, 0.18);
  84. amountEffNeutral = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
  85. CSDL_Ext::alphaTransform(amountEffNeutral);
  86. transformPalette(amountEffNeutral, 1.00, 1.00, 0.18);
  87. std::vector<const CStack*> stacks = owner->curInt->cb->battleGetAllStacks(true);
  88. for(const CStack * s : stacks)
  89. {
  90. stackAdded(s);
  91. }
  92. }
  93. CBattleStacksController::~CBattleStacksController()
  94. {
  95. SDL_FreeSurface(amountNormal);
  96. SDL_FreeSurface(amountNegative);
  97. SDL_FreeSurface(amountPositive);
  98. SDL_FreeSurface(amountEffNeutral);
  99. }
  100. void CBattleStacksController::sortObjectsByHex(BattleObjectsByHex & sorted)
  101. {
  102. auto getCurrentPosition = [&](const CStack *stack) -> BattleHex
  103. {
  104. for (auto & anim : pendingAnims)
  105. {
  106. // certainly ugly workaround but fixes quite annoying bug
  107. // stack position will be updated only *after* movement is finished
  108. // before this - stack is always at its initial position. Thus we need to find
  109. // its current position. Which can be found only in this class
  110. if (CMovementAnimation *move = dynamic_cast<CMovementAnimation*>(anim.first))
  111. {
  112. if (move->stack == stack)
  113. return move->nextHex;
  114. }
  115. }
  116. return stack->getPosition();
  117. };
  118. auto stacks = owner->curInt->cb->battleGetStacksIf([](const CStack *s)
  119. {
  120. return !s->isTurret();
  121. });
  122. for (auto & stack : stacks)
  123. {
  124. if (creAnims.find(stack->ID) == creAnims.end()) //e.g. for summoned but not yet handled stacks
  125. continue;
  126. if (stack->initialPosition < 0) // turret shooters are handled separately
  127. continue;
  128. //FIXME: hack to ignore ghost stacks
  129. if ((creAnims[stack->ID]->getType() == CCreatureAnim::DEAD || creAnims[stack->ID]->getType() == CCreatureAnim::HOLDING) && stack->isGhost())
  130. continue;//ignore
  131. if (creAnims[stack->ID]->isDead())
  132. {
  133. sorted.hex[stack->getPosition()].dead.push_back(stack);
  134. continue;
  135. }
  136. if (!creAnims[stack->ID]->isMoving())
  137. {
  138. sorted.hex[stack->getPosition()].alive.push_back(stack);
  139. continue;
  140. }
  141. // flying creature - just blit them over everyone else
  142. if (stack->hasBonusOfType(Bonus::FLYING))
  143. {
  144. sorted.afterAll.alive.push_back(stack);
  145. continue;
  146. }
  147. sorted.hex[getCurrentPosition(stack)].alive.push_back(stack);
  148. }
  149. }
  150. void CBattleStacksController::stackReset(const CStack * stack)
  151. {
  152. auto iter = creAnims.find(stack->ID);
  153. if(iter == creAnims.end())
  154. {
  155. logGlobal->error("Unit %d have no animation", stack->ID);
  156. return;
  157. }
  158. auto animation = iter->second;
  159. if(stack->alive() && animation->isDead())
  160. animation->setType(CCreatureAnim::HOLDING);
  161. if (stack->isClone())
  162. {
  163. ColorShifterDeepBlue shifter;
  164. animation->shiftColor(&shifter);
  165. }
  166. //TODO: handle more cases
  167. }
  168. void CBattleStacksController::stackAdded(const CStack * stack)
  169. {
  170. creDir[stack->ID] = stack->side == BattleSide::ATTACKER; // must be set before getting stack position
  171. Point coords = CClickableHex::getXYUnitAnim(stack->getPosition(), stack, owner);
  172. if(stack->initialPosition < 0) //turret
  173. {
  174. assert(owner->siegeController);
  175. const CCreature *turretCreature = owner->siegeController->turretCreature();
  176. creAnims[stack->ID] = AnimationControls::getAnimation(turretCreature);
  177. creAnims[stack->ID]->pos.h = 225;
  178. coords = owner->siegeController->turretCreaturePosition(stack->initialPosition);
  179. }
  180. else
  181. {
  182. creAnims[stack->ID] = AnimationControls::getAnimation(stack->getCreature());
  183. creAnims[stack->ID]->onAnimationReset += std::bind(&onAnimationFinished, stack, creAnims[stack->ID]);
  184. creAnims[stack->ID]->pos.h = creAnims[stack->ID]->getHeight();
  185. }
  186. creAnims[stack->ID]->pos.x = coords.x;
  187. creAnims[stack->ID]->pos.y = coords.y;
  188. creAnims[stack->ID]->pos.w = creAnims[stack->ID]->getWidth();
  189. creAnims[stack->ID]->setType(CCreatureAnim::HOLDING);
  190. //loading projectiles for units
  191. if(stack->isShooter())
  192. {
  193. owner->projectilesController->initStackProjectile(stack);
  194. }
  195. }
  196. void CBattleStacksController::setActiveStack(const CStack *stack)
  197. {
  198. if (activeStack) // update UI
  199. creAnims[activeStack->ID]->setBorderColor(AnimationControls::getNoBorder());
  200. activeStack = stack;
  201. if (activeStack) // update UI
  202. creAnims[activeStack->ID]->setBorderColor(AnimationControls::getGoldBorder());
  203. owner->controlPanel->blockUI(activeStack == nullptr);
  204. }
  205. void CBattleStacksController::setHoveredStack(const CStack *stack)
  206. {
  207. if ( stack == mouseHoveredStack )
  208. return;
  209. if (mouseHoveredStack)
  210. creAnims[mouseHoveredStack->ID]->setBorderColor(AnimationControls::getNoBorder());
  211. // stack must be alive and not active (which uses gold border instead)
  212. if (stack && stack->alive() && stack != activeStack)
  213. {
  214. mouseHoveredStack = stack;
  215. if (mouseHoveredStack)
  216. {
  217. creAnims[mouseHoveredStack->ID]->setBorderColor(AnimationControls::getBlueBorder());
  218. if (creAnims[mouseHoveredStack->ID]->framesInGroup(CCreatureAnim::MOUSEON) > 0)
  219. creAnims[mouseHoveredStack->ID]->playOnce(CCreatureAnim::MOUSEON);
  220. }
  221. }
  222. else
  223. mouseHoveredStack = nullptr;
  224. }
  225. void CBattleStacksController::showAliveStacks(SDL_Surface *to, std::vector<const CStack *> stacks)
  226. {
  227. BattleHex currentActionTarget;
  228. if(owner->curInt->curAction)
  229. {
  230. auto target = owner->curInt->curAction->getTarget(owner->curInt->cb.get());
  231. if(!target.empty())
  232. currentActionTarget = target.at(0).hexValue;
  233. }
  234. auto isAmountBoxVisible = [&](const CStack *stack) -> bool
  235. {
  236. if(stack->hasBonusOfType(Bonus::SIEGE_WEAPON) && stack->getCount() == 1) //do not show box for singular war machines, stacked war machines with box shown are supported as extension feature
  237. return false;
  238. if(stack->getCount() == 0) //hide box when target is going to die anyway - do not display "0 creatures"
  239. return false;
  240. for(auto anim : pendingAnims) //no matter what other conditions below are, hide box when creature is playing hit animation
  241. {
  242. auto hitAnimation = dynamic_cast<CDefenceAnimation*>(anim.first);
  243. if(hitAnimation && (hitAnimation->stack->ID == stack->ID)) //we process only "current creature" as other creatures will be processed reliably on their own iteration
  244. return false;
  245. }
  246. if(owner->curInt->curAction)
  247. {
  248. if(owner->curInt->curAction->stackNumber == stack->ID) //stack is currently taking action (is not a target of another creature's action etc)
  249. {
  250. if(owner->curInt->curAction->actionType == EActionType::WALK || owner->curInt->curAction->actionType == EActionType::SHOOT) //hide when stack walks or shoots
  251. return false;
  252. else if(owner->curInt->curAction->actionType == EActionType::WALK_AND_ATTACK && currentActionTarget != stack->getPosition()) //when attacking, hide until walk phase finished
  253. return false;
  254. }
  255. if(owner->curInt->curAction->actionType == EActionType::SHOOT && currentActionTarget == stack->getPosition()) //hide if we are ranged attack target
  256. return false;
  257. }
  258. return true;
  259. };
  260. auto getEffectsPositivness = [&](const std::vector<si32> & activeSpells) -> int
  261. {
  262. int pos = 0;
  263. for (const auto & spellId : activeSpells)
  264. {
  265. pos += CGI->spellh->objects.at(spellId)->positiveness;
  266. }
  267. return pos;
  268. };
  269. auto getAmountBoxBackground = [&](int positivness) -> SDL_Surface *
  270. {
  271. if (positivness > 0)
  272. return amountPositive;
  273. if (positivness < 0)
  274. return amountNegative;
  275. return amountEffNeutral;
  276. };
  277. showStacks(to, stacks); // Actual display of all stacks
  278. for (auto & stack : stacks)
  279. {
  280. assert(stack);
  281. //printing amount
  282. if (isAmountBoxVisible(stack))
  283. {
  284. const int sideShift = stack->side == BattleSide::ATTACKER ? 1 : -1;
  285. const int reverseSideShift = stack->side == BattleSide::ATTACKER ? -1 : 1;
  286. const BattleHex nextPos = stack->getPosition() + sideShift;
  287. const bool edge = stack->getPosition() % GameConstants::BFIELD_WIDTH == (stack->side == BattleSide::ATTACKER ? GameConstants::BFIELD_WIDTH - 2 : 1);
  288. const bool moveInside = !edge && !owner->fieldController->stackCountOutsideHex(nextPos);
  289. int xAdd = (stack->side == BattleSide::ATTACKER ? 220 : 202) +
  290. (stack->doubleWide() ? 44 : 0) * sideShift +
  291. (moveInside ? amountNormal->w + 10 : 0) * reverseSideShift;
  292. int yAdd = 260 + ((stack->side == BattleSide::ATTACKER || moveInside) ? 0 : -15);
  293. //blitting amount background box
  294. SDL_Surface *amountBG = amountNormal;
  295. std::vector<si32> activeSpells = stack->activeSpells();
  296. if (!activeSpells.empty())
  297. amountBG = getAmountBoxBackground(getEffectsPositivness(activeSpells));
  298. SDL_Rect temp_rect = genRect(amountBG->h, amountBG->w, creAnims[stack->ID]->pos.x + xAdd, creAnims[stack->ID]->pos.y + yAdd);
  299. SDL_BlitSurface(amountBG, nullptr, to, &temp_rect);
  300. //blitting amount
  301. Point textPos(creAnims[stack->ID]->pos.x + xAdd + amountNormal->w/2,
  302. creAnims[stack->ID]->pos.y + yAdd + amountNormal->h/2);
  303. graphics->fonts[FONT_TINY]->renderTextCenter(to, makeNumberShort(stack->getCount()), Colors::WHITE, textPos);
  304. }
  305. }
  306. }
  307. void CBattleStacksController::showStacks(SDL_Surface *to, std::vector<const CStack *> stacks)
  308. {
  309. for (const CStack *stack : stacks)
  310. {
  311. creAnims[stack->ID]->nextFrame(to, facingRight(stack)); // do actual blit
  312. creAnims[stack->ID]->incrementFrame(float(GH.mainFPSmng->getElapsedMilliseconds()) / 1000);
  313. }
  314. }
  315. void CBattleStacksController::updateBattleAnimations()
  316. {
  317. //handle animations
  318. for (auto & elem : pendingAnims)
  319. {
  320. if (!elem.first) //this animation should be deleted
  321. continue;
  322. if (!elem.second)
  323. {
  324. elem.second = elem.first->init();
  325. }
  326. if (elem.second && elem.first)
  327. elem.first->nextFrame();
  328. }
  329. //delete anims
  330. int preSize = static_cast<int>(pendingAnims.size());
  331. for (auto it = pendingAnims.begin(); it != pendingAnims.end(); ++it)
  332. {
  333. if (it->first == nullptr)
  334. {
  335. pendingAnims.erase(it);
  336. it = pendingAnims.begin();
  337. break;
  338. }
  339. }
  340. if (preSize > 0 && pendingAnims.empty())
  341. {
  342. //anims ended
  343. owner->controlPanel->blockUI(activeStack == nullptr);
  344. owner->animsAreDisplayed.setn(false);
  345. }
  346. }
  347. void CBattleStacksController::addNewAnim(CBattleAnimation *anim)
  348. {
  349. pendingAnims.push_back( std::make_pair(anim, false) );
  350. owner->animsAreDisplayed.setn(true);
  351. }
  352. void CBattleStacksController::stackActivated(const CStack *stack) //TODO: check it all before game state is changed due to abilities
  353. {
  354. stackToActivate = stack;
  355. owner->waitForAnims();
  356. if (stackToActivate) //during waiting stack may have gotten activated through show
  357. activateStack();
  358. }
  359. void CBattleStacksController::stackRemoved(uint32_t stackID)
  360. {
  361. if (getActiveStack() != nullptr)
  362. {
  363. if (getActiveStack()->ID == stackID)
  364. {
  365. BattleAction *action = new BattleAction();
  366. action->side = owner->defendingHeroInstance ? (owner->curInt->playerID == owner->defendingHeroInstance->tempOwner) : false;
  367. action->actionType = EActionType::CANCEL;
  368. action->stackNumber = owner->stacksController->getActiveStack()->ID;
  369. owner->givenCommand.setn(action);
  370. setActiveStack(nullptr);
  371. }
  372. }
  373. //todo: ensure that ghost stack animation has fadeout effect
  374. }
  375. void CBattleStacksController::stacksAreAttacked(std::vector<StackAttackedInfo> attackedInfos)
  376. {
  377. for(auto & attackedInfo : attackedInfos)
  378. {
  379. //if (!attackedInfo.cloneKilled) //FIXME: play dead animation for cloned creature before it vanishes
  380. addNewAnim(new CDefenceAnimation(attackedInfo, owner));
  381. if(attackedInfo.rebirth)
  382. {
  383. owner->effectsController->displayEffect(EBattleEffect::RESURRECT, soundBase::RESURECT, attackedInfo.defender->getPosition()); //TODO: play reverse death animation
  384. }
  385. }
  386. owner->waitForAnims();
  387. for (auto & attackedInfo : attackedInfos)
  388. {
  389. if (attackedInfo.rebirth)
  390. creAnims[attackedInfo.defender->ID]->setType(CCreatureAnim::HOLDING);
  391. if (attackedInfo.cloneKilled)
  392. stackRemoved(attackedInfo.defender->ID);
  393. }
  394. }
  395. void CBattleStacksController::stackMoved(const CStack *stack, std::vector<BattleHex> destHex, int distance)
  396. {
  397. addNewAnim(new CMovementAnimation(owner, stack, destHex, distance));
  398. owner->waitForAnims();
  399. }
  400. void CBattleStacksController::stackAttacking( const CStack *attacker, BattleHex dest, const CStack *attacked, bool shooting )
  401. {
  402. if (shooting)
  403. {
  404. addNewAnim(new CShootingAnimation(owner, attacker, dest, attacked));
  405. }
  406. else
  407. {
  408. addNewAnim(new CMeleeAttackAnimation(owner, attacker, dest, attacked));
  409. }
  410. //waitForAnims();
  411. }
  412. bool CBattleStacksController::shouldRotate(const CStack * stack, const BattleHex & oldPos, const BattleHex & nextHex)
  413. {
  414. Point begPosition = CClickableHex::getXYUnitAnim(oldPos,stack, owner);
  415. Point endPosition = CClickableHex::getXYUnitAnim(nextHex, stack, owner);
  416. if((begPosition.x > endPosition.x) && facingRight(stack))
  417. return true;
  418. else if((begPosition.x < endPosition.x) && !facingRight(stack))
  419. return true;
  420. return false;
  421. }
  422. void CBattleStacksController::endAction(const BattleAction* action)
  423. {
  424. //check if we should reverse stacks
  425. //for some strange reason, it's not enough
  426. TStacks stacks = owner->curInt->cb->battleGetStacks(CBattleCallback::MINE_AND_ENEMY);
  427. for (const CStack *s : stacks)
  428. {
  429. bool shouldFaceRight = s && s->side == BattleSide::ATTACKER;
  430. if (s && facingRight(s) != shouldFaceRight && s->alive() && creAnims[s->ID]->isIdle())
  431. {
  432. addNewAnim(new CReverseAnimation(owner, s, s->getPosition(), false));
  433. }
  434. }
  435. }
  436. void CBattleStacksController::startAction(const BattleAction* action)
  437. {
  438. const CStack *stack = owner->curInt->cb->battleGetStackByID(action->stackNumber);
  439. setHoveredStack(nullptr);
  440. auto actionTarget = action->getTarget(owner->curInt->cb.get());
  441. if(action->actionType == EActionType::WALK
  442. || (action->actionType == EActionType::WALK_AND_ATTACK && actionTarget.at(0).hexValue != stack->getPosition()))
  443. {
  444. assert(stack);
  445. owner->moveStarted = true;
  446. if (creAnims[action->stackNumber]->framesInGroup(CCreatureAnim::MOVE_START))
  447. {
  448. pendingAnims.push_back(std::make_pair(new CMovementStartAnimation(owner, stack), false));
  449. }
  450. if(shouldRotate(stack, stack->getPosition(), actionTarget.at(0).hexValue))
  451. pendingAnims.push_back(std::make_pair(new CReverseAnimation(owner, stack, stack->getPosition(), true), false));
  452. }
  453. }
  454. void CBattleStacksController::activateStack()
  455. {
  456. if ( !pendingAnims.empty())
  457. return;
  458. if ( !stackToActivate)
  459. return;
  460. owner->trySetActivePlayer(stackToActivate->owner);
  461. setActiveStack(stackToActivate);
  462. stackToActivate = nullptr;
  463. const CStack * s = owner->stacksController->getActiveStack();
  464. if(!s)
  465. return;
  466. //set casting flag to true if creature can use it to not check it every time
  467. const auto spellcaster = s->getBonusLocalFirst(Selector::type()(Bonus::SPELLCASTER));
  468. const auto randomSpellcaster = s->getBonusLocalFirst(Selector::type()(Bonus::RANDOM_SPELLCASTER));
  469. if(s->canCast() && (spellcaster || randomSpellcaster))
  470. {
  471. stackCanCastSpell = true;
  472. if(randomSpellcaster)
  473. creatureSpellToCast = -1; //spell will be set later on cast
  474. else
  475. creatureSpellToCast = owner->curInt->cb->battleGetRandomStackSpell(CRandomGenerator::getDefault(), s, CBattleInfoCallback::RANDOM_AIMED); //faerie dragon can cast only one spell until their next move
  476. //TODO: what if creature can cast BOTH random genie spell and aimed spell?
  477. //TODO: faerie dragon type spell should be selected by server
  478. }
  479. else
  480. {
  481. stackCanCastSpell = false;
  482. creatureSpellToCast = -1;
  483. }
  484. }
  485. void CBattleStacksController::setSelectedStack(const CStack *stack)
  486. {
  487. selectedStack = stack;
  488. }
  489. const CStack* CBattleStacksController::getSelectedStack()
  490. {
  491. return selectedStack;
  492. }
  493. const CStack* CBattleStacksController::getActiveStack()
  494. {
  495. return activeStack;
  496. }
  497. bool CBattleStacksController::facingRight(const CStack * stack)
  498. {
  499. return creDir[stack->ID];
  500. }
  501. bool CBattleStacksController::activeStackSpellcaster()
  502. {
  503. return stackCanCastSpell;
  504. }
  505. SpellID CBattleStacksController::activeStackSpellToCast()
  506. {
  507. if (!stackCanCastSpell)
  508. return SpellID::NONE;
  509. return SpellID(creatureSpellToCast);
  510. }