BattleStacksController.cpp 19 KB

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