CBattleStacksController.cpp 19 KB

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