HeroMovementController.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * HeroMovementController.h, 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. #pragma once
  11. #include "../lib/constants/EntityIdentifiers.h"
  12. #include "../lib/int3.h"
  13. #include "../lib/filesystem/ResourcePath.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. using TTeleportExitsList = std::vector<std::pair<ObjectInstanceID, int3>>;
  16. class CGHeroInstance;
  17. class CArmedInstance;
  18. struct CGPathNode;
  19. struct CGPath;
  20. struct TryMoveHero;
  21. enum class EPathNodeAction : ui8;
  22. VCMI_LIB_NAMESPACE_END
  23. class HeroMovementController
  24. {
  25. /// there is an ongoing movement loop, in one or another stage
  26. bool duringMovement = false;
  27. /// movement was requested to be terminated, e.g. by player or due to inability to move
  28. bool stoppingMovement = false;
  29. bool waitingForQueryApplyReply = false;
  30. const CGHeroInstance * currentlyMovingHero = nullptr;
  31. AudioPath currentMovementSoundName;
  32. int currentMovementSoundChannel = -1;
  33. bool canHeroStopAtNode(const CGPathNode & node) const;
  34. void updatePath(const CGHeroInstance * hero, const TryMoveHero & details);
  35. /// Sends one request to server to move selected hero alongside path.
  36. /// Automatically selects between single-tile and multi-tile movement modes
  37. void sendMovementRequest(const CGHeroInstance * h, const CGPath & path);
  38. void endMove(const CGHeroInstance * h);
  39. AudioPath getMovementSoundFor(const CGHeroInstance * hero, int3 posPrev, int3 posNext, EPathNodeAction moveType);
  40. void updateMovementSound(const CGHeroInstance * hero, int3 posPrev, int3 posNext, EPathNodeAction moveType);
  41. void stopMovementSound();
  42. public:
  43. // const queries
  44. /// Returns true if hero should move through garrison without displaying garrison dialog
  45. bool isHeroMovingThroughGarrison(const CGHeroInstance * hero, const CArmedInstance * garrison) const;
  46. /// Returns true if there is an ongoing hero movement process
  47. bool isHeroMoving() const;
  48. // netpack handlers
  49. void onMoveHeroApplied();
  50. void onQueryReplyApplied();
  51. void onPlayerTurnStarted();
  52. void onBattleStarted();
  53. void showTeleportDialog(const CGHeroInstance * hero, TeleportChannelID channel, TTeleportExitsList exits, bool impassable, QueryID askID);
  54. void onTryMoveHero(const CGHeroInstance * hero, const TryMoveHero & details);
  55. // UI handlers
  56. void requestMovementStart(const CGHeroInstance * h, const CGPath & path);
  57. void requestMovementAbort();
  58. };