CReverseAnimation.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "StdInc.h"
  2. #include "CReverseAnimation.h"
  3. #include "CCreatureAnimation.h"
  4. #include "../../lib/BattleState.h"
  5. #include "CBattleInterface.h"
  6. #include "CClickableHex.h"
  7. bool CReverseAnimation::init()
  8. {
  9. if(myAnim() == NULL || myAnim()->getType() == 5)
  10. {
  11. endAnim();
  12. return false; //there is no such creature
  13. }
  14. if(!priority && !isEarliest(false))
  15. return false;
  16. if(myAnim()->framesInGroup(CCreatureAnim::TURN_R))
  17. myAnim()->setType(CCreatureAnim::TURN_R);
  18. else
  19. setupSecondPart();
  20. return true;
  21. }
  22. void CReverseAnimation::nextFrame()
  23. {
  24. if(partOfAnim == 1) //first part of animation
  25. {
  26. if(myAnim()->onLastFrameInGroup())
  27. {
  28. partOfAnim = 2;
  29. }
  30. }
  31. else if(partOfAnim == 2)
  32. {
  33. if(!secondPartSetup)
  34. {
  35. setupSecondPart();
  36. }
  37. if(myAnim()->onLastFrameInGroup())
  38. {
  39. endAnim();
  40. }
  41. }
  42. }
  43. void CReverseAnimation::endAnim()
  44. {
  45. CBattleAnimation::endAnim();
  46. if( stack->alive() )//don't do that if stack is dead
  47. myAnim()->setType(CCreatureAnim::HOLDING);
  48. delete this;
  49. }
  50. CReverseAnimation::CReverseAnimation(CBattleInterface * _owner, const CStack * stack, SBattleHex dest, bool _priority)
  51. : CBattleStackAnimation(_owner, stack), partOfAnim(1), secondPartSetup(false), hex(dest), priority(_priority)
  52. {
  53. }
  54. void CReverseAnimation::setupSecondPart()
  55. {
  56. owner->creDir[stack->ID] = !owner->creDir[stack->ID];
  57. if(!stack)
  58. {
  59. endAnim();
  60. return;
  61. }
  62. SPoint coords = CClickableHex::getXYUnitAnim(hex, owner->creDir[stack->ID], stack, owner);
  63. myAnim()->pos.x = coords.x;
  64. //creAnims[stackID]->pos.y = coords.second;
  65. if(stack->doubleWide())
  66. {
  67. if(stack->attackerOwned)
  68. {
  69. if(!owner->creDir[stack->ID])
  70. myAnim()->pos.x -= 44;
  71. }
  72. else
  73. {
  74. if(owner->creDir[stack->ID])
  75. myAnim()->pos.x += 44;
  76. }
  77. }
  78. secondPartSetup = true;
  79. if(myAnim()->framesInGroup(CCreatureAnim::TURN_L))
  80. myAnim()->setType(CCreatureAnim::TURN_L);
  81. else
  82. endAnim();
  83. }