CBattleStacksController.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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 "../gui/CAnimation.h"
  21. #include "../gui/CGuiHandler.h"
  22. #include "../gui/CCanvas.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. 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 : pendingAnims)
  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.first))
  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 (creAnims.find(stack->ID) == creAnims.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 ((creAnims[stack->ID]->getType() == CCreatureAnim::DEAD || creAnims[stack->ID]->getType() == CCreatureAnim::HOLDING) && stack->isGhost())
  111. continue;//ignore
  112. if (creAnims[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 (!creAnims[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 = creAnims.find(stack->ID);
  144. if(iter == creAnims.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. creDir[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. creAnims[stack->ID] = AnimationControls::getAnimation(turretCreature);
  168. creAnims[stack->ID]->pos.h = 225;
  169. coords = owner->siegeController->getTurretCreaturePosition(stack->initialPosition);
  170. }
  171. else
  172. {
  173. creAnims[stack->ID] = AnimationControls::getAnimation(stack->getCreature());
  174. creAnims[stack->ID]->onAnimationReset += std::bind(&onAnimationFinished, stack, creAnims[stack->ID]);
  175. creAnims[stack->ID]->pos.h = creAnims[stack->ID]->getHeight();
  176. }
  177. creAnims[stack->ID]->pos.x = coords.x;
  178. creAnims[stack->ID]->pos.y = coords.y;
  179. creAnims[stack->ID]->pos.w = creAnims[stack->ID]->getWidth();
  180. creAnims[stack->ID]->setType(CCreatureAnim::HOLDING);
  181. }
  182. void CBattleStacksController::setActiveStack(const CStack *stack)
  183. {
  184. if (activeStack) // update UI
  185. creAnims[activeStack->ID]->setBorderColor(AnimationControls::getNoBorder());
  186. activeStack = stack;
  187. if (activeStack) // update UI
  188. creAnims[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. creAnims[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. creAnims[mouseHoveredStack->ID]->setBorderColor(AnimationControls::getBlueBorder());
  204. if (creAnims[mouseHoveredStack->ID]->framesInGroup(CCreatureAnim::MOUSEON) > 0)
  205. creAnims[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 : pendingAnims) //no matter what other conditions below are, hide box when creature is playing hit animation
  227. {
  228. auto hitAnimation = dynamic_cast<CDefenceAnimation*>(anim.first);
  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, creAnims[stack->ID]->pos.topLeft() + Point(xAdd, yAdd));
  274. //blitting amount
  275. Point textPos = creAnims[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. creAnims[stack->ID]->nextFrame(canvas, facingRight(stack)); // do actual blit
  281. creAnims[stack->ID]->incrementFrame(float(GH.mainFPSmng->getElapsedMilliseconds()) / 1000);
  282. if (stackNeedsAmountBox(stack))
  283. showStackAmountBox(canvas, stack);
  284. }
  285. void CBattleStacksController::updateBattleAnimations()
  286. {
  287. //handle animations
  288. for (auto & elem : pendingAnims)
  289. {
  290. if (!elem.first) //this animation should be deleted
  291. continue;
  292. if (!elem.second)
  293. {
  294. elem.second = elem.first->init();
  295. }
  296. if (elem.second && elem.first)
  297. elem.first->nextFrame();
  298. }
  299. //delete anims
  300. int preSize = static_cast<int>(pendingAnims.size());
  301. for (auto it = pendingAnims.begin(); it != pendingAnims.end(); ++it)
  302. {
  303. if (it->first == nullptr)
  304. {
  305. pendingAnims.erase(it);
  306. it = pendingAnims.begin();
  307. break;
  308. }
  309. }
  310. if (preSize > 0 && pendingAnims.empty())
  311. {
  312. //anims ended
  313. owner->controlPanel->blockUI(activeStack == nullptr);
  314. owner->animsAreDisplayed.setn(false);
  315. }
  316. }
  317. void CBattleStacksController::addNewAnim(CBattleAnimation *anim)
  318. {
  319. pendingAnims.push_back( std::make_pair(anim, false) );
  320. owner->animsAreDisplayed.setn(true);
  321. }
  322. void CBattleStacksController::stackActivated(const CStack *stack) //TODO: check it all before game state is changed due to abilities
  323. {
  324. stackToActivate = stack;
  325. owner->waitForAnims();
  326. if (stackToActivate) //during waiting stack may have gotten activated through show
  327. owner->activateStack();
  328. }
  329. void CBattleStacksController::stackRemoved(uint32_t stackID)
  330. {
  331. if (getActiveStack() != nullptr)
  332. {
  333. if (getActiveStack()->ID == stackID)
  334. {
  335. BattleAction *action = new BattleAction();
  336. action->side = owner->defendingHeroInstance ? (owner->curInt->playerID == owner->defendingHeroInstance->tempOwner) : false;
  337. action->actionType = EActionType::CANCEL;
  338. action->stackNumber = getActiveStack()->ID;
  339. owner->givenCommand.setn(action);
  340. setActiveStack(nullptr);
  341. }
  342. }
  343. //todo: ensure that ghost stack animation has fadeout effect
  344. }
  345. void CBattleStacksController::stacksAreAttacked(std::vector<StackAttackedInfo> attackedInfos)
  346. {
  347. for(auto & attackedInfo : attackedInfos)
  348. {
  349. //if (!attackedInfo.cloneKilled) //FIXME: play dead animation for cloned creature before it vanishes
  350. addNewAnim(new CDefenceAnimation(attackedInfo, owner));
  351. if(attackedInfo.rebirth)
  352. {
  353. owner->effectsController->displayEffect(EBattleEffect::RESURRECT, soundBase::RESURECT, attackedInfo.defender->getPosition()); //TODO: play reverse death animation
  354. }
  355. }
  356. owner->waitForAnims();
  357. for (auto & attackedInfo : attackedInfos)
  358. {
  359. if (attackedInfo.rebirth)
  360. creAnims[attackedInfo.defender->ID]->setType(CCreatureAnim::HOLDING);
  361. if (attackedInfo.cloneKilled)
  362. stackRemoved(attackedInfo.defender->ID);
  363. }
  364. }
  365. void CBattleStacksController::stackMoved(const CStack *stack, std::vector<BattleHex> destHex, int distance)
  366. {
  367. addNewAnim(new CMovementAnimation(owner, stack, destHex, distance));
  368. owner->waitForAnims();
  369. }
  370. void CBattleStacksController::stackAttacking( const CStack *attacker, BattleHex dest, const CStack *attacked, bool shooting )
  371. {
  372. if (shooting)
  373. {
  374. addNewAnim(new CShootingAnimation(owner, attacker, dest, attacked));
  375. }
  376. else
  377. {
  378. addNewAnim(new CMeleeAttackAnimation(owner, attacker, dest, attacked));
  379. }
  380. //waitForAnims();
  381. }
  382. bool CBattleStacksController::shouldRotate(const CStack * stack, const BattleHex & oldPos, const BattleHex & nextHex)
  383. {
  384. Point begPosition = getStackPositionAtHex(oldPos,stack);
  385. Point endPosition = getStackPositionAtHex(nextHex, stack);
  386. if((begPosition.x > endPosition.x) && facingRight(stack))
  387. return true;
  388. else if((begPosition.x < endPosition.x) && !facingRight(stack))
  389. return true;
  390. return false;
  391. }
  392. void CBattleStacksController::endAction(const BattleAction* action)
  393. {
  394. //check if we should reverse stacks
  395. //for some strange reason, it's not enough
  396. TStacks stacks = owner->curInt->cb->battleGetStacks(CBattleCallback::MINE_AND_ENEMY);
  397. for (const CStack *s : stacks)
  398. {
  399. bool shouldFaceRight = s && s->side == BattleSide::ATTACKER;
  400. if (s && facingRight(s) != shouldFaceRight && s->alive() && creAnims[s->ID]->isIdle())
  401. {
  402. addNewAnim(new CReverseAnimation(owner, s, s->getPosition(), false));
  403. }
  404. }
  405. }
  406. void CBattleStacksController::startAction(const BattleAction* action)
  407. {
  408. const CStack *stack = owner->curInt->cb->battleGetStackByID(action->stackNumber);
  409. setHoveredStack(nullptr);
  410. auto actionTarget = action->getTarget(owner->curInt->cb.get());
  411. if(action->actionType == EActionType::WALK
  412. || (action->actionType == EActionType::WALK_AND_ATTACK && actionTarget.at(0).hexValue != stack->getPosition()))
  413. {
  414. assert(stack);
  415. owner->moveStarted = true;
  416. if (creAnims[action->stackNumber]->framesInGroup(CCreatureAnim::MOVE_START))
  417. addNewAnim(new CMovementStartAnimation(owner, stack));
  418. if(shouldRotate(stack, stack->getPosition(), actionTarget.at(0).hexValue))
  419. addNewAnim(new CReverseAnimation(owner, stack, stack->getPosition(), true));
  420. }
  421. }
  422. void CBattleStacksController::activateStack()
  423. {
  424. if ( !pendingAnims.empty())
  425. return;
  426. if ( !stackToActivate)
  427. return;
  428. owner->trySetActivePlayer(stackToActivate->owner);
  429. setActiveStack(stackToActivate);
  430. stackToActivate = nullptr;
  431. const CStack * s = getActiveStack();
  432. if(!s)
  433. return;
  434. //set casting flag to true if creature can use it to not check it every time
  435. const auto spellcaster = s->getBonusLocalFirst(Selector::type()(Bonus::SPELLCASTER));
  436. const auto randomSpellcaster = s->getBonusLocalFirst(Selector::type()(Bonus::RANDOM_SPELLCASTER));
  437. if(s->canCast() && (spellcaster || randomSpellcaster))
  438. {
  439. stackCanCastSpell = true;
  440. if(randomSpellcaster)
  441. creatureSpellToCast = -1; //spell will be set later on cast
  442. else
  443. creatureSpellToCast = owner->curInt->cb->battleGetRandomStackSpell(CRandomGenerator::getDefault(), s, CBattleInfoCallback::RANDOM_AIMED); //faerie dragon can cast only one spell until their next move
  444. //TODO: what if creature can cast BOTH random genie spell and aimed spell?
  445. //TODO: faerie dragon type spell should be selected by server
  446. }
  447. else
  448. {
  449. stackCanCastSpell = false;
  450. creatureSpellToCast = -1;
  451. }
  452. }
  453. void CBattleStacksController::setSelectedStack(const CStack *stack)
  454. {
  455. selectedStack = stack;
  456. }
  457. const CStack* CBattleStacksController::getSelectedStack()
  458. {
  459. return selectedStack;
  460. }
  461. const CStack* CBattleStacksController::getActiveStack()
  462. {
  463. return activeStack;
  464. }
  465. bool CBattleStacksController::facingRight(const CStack * stack)
  466. {
  467. return creDir[stack->ID];
  468. }
  469. bool CBattleStacksController::activeStackSpellcaster()
  470. {
  471. return stackCanCastSpell;
  472. }
  473. SpellID CBattleStacksController::activeStackSpellToCast()
  474. {
  475. if (!stackCanCastSpell)
  476. return SpellID::NONE;
  477. return SpellID(creatureSpellToCast);
  478. }
  479. Point CBattleStacksController::getStackPositionAtHex(BattleHex hexNum, const CStack * stack)
  480. {
  481. Point ret(-500, -500); //returned value
  482. if(stack && stack->initialPosition < 0) //creatures in turrets
  483. return owner->siegeController->getTurretCreaturePosition(stack->initialPosition);
  484. static const Point basePos(-190, -139); // position of creature in topleft corner
  485. static const int imageShiftX = 30; // X offset to base pos for facing right stacks, negative for facing left
  486. ret.x = basePos.x + 22 * ( (hexNum.getY() + 1)%2 ) + 44 * hexNum.getX();
  487. ret.y = basePos.y + 42 * hexNum.getY();
  488. if (stack)
  489. {
  490. if(facingRight(stack))
  491. ret.x += imageShiftX;
  492. else
  493. ret.x -= imageShiftX;
  494. //shifting position for double - hex creatures
  495. if(stack->doubleWide())
  496. {
  497. if(stack->side == BattleSide::ATTACKER)
  498. {
  499. if(facingRight(stack))
  500. ret.x -= 44;
  501. }
  502. else
  503. {
  504. if(!facingRight(stack))
  505. ret.x += 44;
  506. }
  507. }
  508. }
  509. //returning
  510. return ret + owner->pos.topLeft();
  511. }