2023-09-07 21:37:42 +02:00
|
|
|
/*
|
2023-09-16 19:07:02 +02:00
|
|
|
* HeroMovementController.h, part of VCMI engine
|
2023-09-07 21:37:42 +02:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../lib/constants/EntityIdentifiers.h"
|
|
|
|
#include "../lib/int3.h"
|
2023-09-11 11:54:25 +02:00
|
|
|
#include "../lib/filesystem/ResourcePath.h"
|
2023-09-07 21:37:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
using TTeleportExitsList = std::vector<std::pair<ObjectInstanceID, int3>>;
|
|
|
|
|
|
|
|
class CGHeroInstance;
|
2023-09-08 17:02:36 +02:00
|
|
|
class CArmedInstance;
|
2023-09-15 21:18:36 +02:00
|
|
|
struct CGPathNode;
|
2023-09-07 21:37:42 +02:00
|
|
|
|
|
|
|
struct CGPath;
|
|
|
|
struct TryMoveHero;
|
2023-09-11 11:54:25 +02:00
|
|
|
enum class EPathNodeAction : ui8;
|
2023-09-07 21:37:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
|
|
|
class HeroMovementController
|
|
|
|
{
|
2023-09-15 21:18:36 +02:00
|
|
|
/// there is an ongoing movement loop, in one or another stage
|
|
|
|
bool duringMovement = false;
|
|
|
|
/// movement was requested to be terminated, e.g. by player or due to inability to move
|
|
|
|
bool stoppingMovement = false;
|
2023-09-07 21:37:42 +02:00
|
|
|
|
2023-09-16 19:07:02 +02:00
|
|
|
bool waitingForQueryApplyReply = false;
|
|
|
|
|
2023-09-16 12:40:49 +02:00
|
|
|
const CGHeroInstance * currentlyMovingHero = nullptr;
|
2023-09-15 21:18:36 +02:00
|
|
|
AudioPath currentMovementSoundName;
|
|
|
|
int currentMovementSoundChannel = -1;
|
2023-09-07 21:37:42 +02:00
|
|
|
|
2023-09-15 21:18:36 +02:00
|
|
|
bool canHeroStopAtNode(const CGPathNode & node) const;
|
2023-09-07 21:37:42 +02:00
|
|
|
|
2023-09-15 21:18:36 +02:00
|
|
|
void updatePath(const CGHeroInstance * hero, const TryMoveHero & details);
|
2023-09-08 17:02:36 +02:00
|
|
|
|
2024-04-20 13:20:54 +02:00
|
|
|
/// Sends one request to server to move selected hero alongside path.
|
|
|
|
/// Automatically selects between single-tile and multi-tile movement modes
|
|
|
|
void sendMovementRequest(const CGHeroInstance * h, const CGPath & path);
|
2024-04-17 17:18:28 +02:00
|
|
|
|
2023-09-18 17:17:26 +02:00
|
|
|
void endMove(const CGHeroInstance * h);
|
2023-09-11 11:54:25 +02:00
|
|
|
|
|
|
|
AudioPath getMovementSoundFor(const CGHeroInstance * hero, int3 posPrev, int3 posNext, EPathNodeAction moveType);
|
|
|
|
void updateMovementSound(const CGHeroInstance * hero, int3 posPrev, int3 posNext, EPathNodeAction moveType);
|
|
|
|
void stopMovementSound();
|
2023-09-07 21:37:42 +02:00
|
|
|
|
2023-09-15 21:18:36 +02:00
|
|
|
public:
|
2023-09-08 17:02:36 +02:00
|
|
|
// const queries
|
2023-09-16 19:07:02 +02:00
|
|
|
|
|
|
|
/// Returns true if hero should move through garrison without displaying garrison dialog
|
2023-09-08 17:02:36 +02:00
|
|
|
bool isHeroMovingThroughGarrison(const CGHeroInstance * hero, const CArmedInstance * garrison) const;
|
2023-09-16 19:07:02 +02:00
|
|
|
|
|
|
|
/// Returns true if there is an ongoing hero movement process
|
2023-09-07 21:37:42 +02:00
|
|
|
bool isHeroMoving() const;
|
|
|
|
|
2023-09-08 17:02:36 +02:00
|
|
|
// netpack handlers
|
2023-09-07 21:37:42 +02:00
|
|
|
void onMoveHeroApplied();
|
2023-09-16 19:07:02 +02:00
|
|
|
void onQueryReplyApplied();
|
2023-09-07 21:37:42 +02:00
|
|
|
void onPlayerTurnStarted();
|
|
|
|
void onBattleStarted();
|
2023-09-15 21:18:36 +02:00
|
|
|
void showTeleportDialog(const CGHeroInstance * hero, TeleportChannelID channel, TTeleportExitsList exits, bool impassable, QueryID askID);
|
2023-09-18 17:17:26 +02:00
|
|
|
void onTryMoveHero(const CGHeroInstance * hero, const TryMoveHero & details);
|
2023-09-07 21:37:42 +02:00
|
|
|
|
2023-09-08 17:02:36 +02:00
|
|
|
// UI handlers
|
2023-09-18 17:17:26 +02:00
|
|
|
void requestMovementStart(const CGHeroInstance * h, const CGPath & path);
|
|
|
|
void requestMovementAbort();
|
2023-09-07 21:37:42 +02:00
|
|
|
};
|