CBattleStackAnimation.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "StdInc.h"
  2. #include "CBattleStackAnimation.h"
  3. #include "CBattleInterface.h"
  4. #include "../../lib/BattleState.h"
  5. CBattleStackAnimation::CBattleStackAnimation(CBattleInterface * _owner, const CStack * _stack)
  6. : CBattleAnimation(_owner), stack(_stack)
  7. {
  8. }
  9. bool CBattleStackAnimation::isToReverseHlp(SHexField hexFrom, SHexField hexTo, bool curDir)
  10. {
  11. int fromMod = hexFrom % GameConstants::BFIELD_WIDTH;
  12. int fromDiv = hexFrom / GameConstants::BFIELD_WIDTH;
  13. int toMod = hexTo % GameConstants::BFIELD_WIDTH;
  14. if(curDir && fromMod < toMod)
  15. return false;
  16. else if(curDir && fromMod > toMod)
  17. return true;
  18. else if(curDir && fromMod == toMod)
  19. {
  20. return fromDiv % 2 == 0;
  21. }
  22. else if(!curDir && fromMod < toMod)
  23. return true;
  24. else if(!curDir && fromMod > toMod)
  25. return false;
  26. else if(!curDir && fromMod == toMod)
  27. {
  28. return fromDiv % 2 == 1;
  29. }
  30. tlog1 << "Catastrope in CBattleStackAnimation::isToReverse!" << std::endl;
  31. return false; //should never happen
  32. }
  33. bool CBattleStackAnimation::isToReverse(SHexField hexFrom, SHexField hexTo, bool curDir, bool toDoubleWide, bool toDir)
  34. {
  35. if(hexTo < 0) //turret
  36. return false;
  37. if(toDoubleWide)
  38. {
  39. return isToReverseHlp(hexFrom, hexTo, curDir) &&
  40. (toDir ? isToReverseHlp(hexFrom, hexTo-1, curDir) : isToReverseHlp(hexFrom, hexTo+1, curDir) );
  41. }
  42. else
  43. {
  44. return isToReverseHlp(hexFrom, hexTo, curDir);
  45. }
  46. }
  47. CCreatureAnimation* CBattleStackAnimation::myAnim()
  48. {
  49. return owner->creAnims[stack->ID];
  50. }