CBattleStacksController.cpp 19 KB

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