2
0

CBattleStacksController.cpp 19 KB

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