ScummVM API documentation
player.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef HARVESTER_PLAYER_H
23 #define HARVESTER_PLAYER_H
24 
25 #include "harvester/scene/room_support.h"
26 
27 namespace Harvester {
28 
29 class EntityManager;
30 
31 namespace PlayerMovement {
32 struct MovementContext;
33 struct MovementPosition;
34 }
35 
37  Entity *entity = nullptr;
38  int centerX = 0;
39  int bottomY = 0;
40  float z = 0.0f;
41  int facing = -1;
42  int combatLoadout = 0;
43  int animationRate = 17;
44  int evasiveState = -1;
45  int evasiveFirstFrame = -1;
46  int evasiveLastFrame = -1;
47  int evasiveXStep = 0;
48  Common::Rect evasiveFrameBounds;
49  uint32 nextMovementTick = 0;
50  int keyboardWalkRequest = -1;
51  int walkHorizontalDirection = 0;
52  int walkDepthDirection = 0;
53  bool hasMoveTarget = false;
54  int targetX = 0;
55  int targetBottomY = 0;
56  float targetZ = 0.0f;
57  bool moveTargetXReached = false;
58  bool moveTargetZReached = false;
59  Common::String currentBlockerName;
60 
61  Common::String upwardBlockerHistory;
62  Common::String downwardBlockerHistory;
63  Common::String leftwardBlockerHistory;
64  Common::String rightwardBlockerHistory;
65  bool turnActive = false;
66  int turnTargetFacing = -1;
67  int turnFirstFrame = -1;
68  int turnLastFrame = -1;
69  int turnEndFrame = -1;
70  bool turnPlayBackwards = false;
71  bool attackActive = false;
72  int attackFirstFrame = -1;
73  int attackLastFrame = -1;
74  int attackContactFrame = -1;
75  int attackResumeFacing = -1;
76  bool attackSoundPlayed = false;
77  int attackSoundPlaybackFrame = -1;
78  bool attackContactResolved = false;
79 
80  Common::String attackTargetName;
81  int attackTargetClassId = -1;
82  bool hitActive = false;
83  int hitFirstFrame = -1;
84  int hitLastFrame = -1;
85  int hitResumeFacing = -1;
86  int hitKnockbackRemainingX = 0;
87  int hitKnockbackDecayStep = 0;
88  bool deathActive = false;
89  int deathFirstFrame = -1;
90  int deathLastFrame = -1;
91  int deathDamageType = 0;
92 };
93 
95  Entity *entity = nullptr;
96  int restoreFacing = -1;
97  uint32 activityTick = 0;
98  uint32 resetTick = 0;
99  uint32 triggerTick = 0;
100  bool active = false;
101  bool loopStarted = false;
102  bool exiting = false;
103 };
104 
105 class Player {
106 public:
107  Player() = default;
108  Player(const Player &) = delete;
109  Player &operator=(const Player &) = delete;
110 
111  const RoomPlayerState &getState() const { return _state; }
112  const RoomIdleAnimationState &getIdleState() const { return _idleState; }
113  void initialize(const RoomSetupState &state, Entity *entity, int combatLoadout);
114  bool isCombatLocked() const;
115  void cancelMovement();
116  void cancelMovementForAttack();
117  bool cancelAttackAnimation();
118  void clearAttackTarget();
119  void captureAttackTarget(const Common::String &name, int classId);
120  void markAttackContactResolved();
121  void resetIdleState();
122  void noteActivity();
123  void cancelIdleAnimation();
124  void applyGotoXZ(const RoomSetupState &state, EntityManager *entityManager, int x, int z);
125  void rebindAfterSceneRefresh(HarvesterEngine &engine, const RoomSetupState &state,
126  EntityManager *entityManager, bool preservePlayerPlacement);
127  void syncAnimationPlacement();
128  static float computeDepthScale(const RoomSetupState &state, float z);
129  static int resolveFacingFrame(int facing);
130  static const char *describeCombatLoadout(int loadout);
131  static const char *describeCombatDamageType(int damageType);
132  static Common::String resolveCombatLoadoutResourcePath(int loadout);
133  static int resolveCombatLoadoutDamageAmount(int loadout);
134  static int resolveCombatLoadoutDamageType(int loadout);
135  static int resolveCombatLoadoutContactFrameOffset(int loadout);
136  static bool isProjectileCombatLoadout(int loadout);
137  static bool supportsMovementBand(const RoomSetupState &state);
138  static uint32 getRuntimeClockTicks();
139  static bool isIdleAnimationExcludedRoom(const Common::String &roomName);
140 
141  void setMoveTarget(const RoomSetupState &state, int targetX, float targetZ);
142  void setRegionMoveTarget(const RoomSetupState &state, int targetX, float targetZ);
143  void setMoveTargetFromScreenPoint(const RoomSetupState &state, int targetX, int targetBottomY);
144  bool resolveBlockedStartupSpawn(HarvesterEngine &engine, const RoomSetupState &state,
145  const Common::Array<ObjectRecord> &sceneObjects, const Common::Array<AnimRecord> &sceneAnimations);
146  static int resolveRegionTargetX(const RoomSetupState &state, const RegionRecord &region,
147  const RoomPlayerState &playerState);
148  static float resolveRegionTargetZ(const RegionRecord &region);
149  void syncCombatLoadout(HarvesterEngine &engine, const RoomSetupState &state);
150  bool syncCombatLoadoutVisual(HarvesterEngine &engine, const RoomSetupState &state, int loadout);
151  bool setIdleAnimation(int facing);
152  bool updateAnimationRate(bool speedUp);
153  bool startEvasiveAnimation(bool moveLeft, bool moveRight, bool moveUp, bool moveDown);
154  bool updateEvasiveAnimation(HarvesterEngine &engine);
155  bool startAttackAnimation(const RoomSetupState &state, const Common::Point &mousePos);
156  bool startKeyboardAttackAnimation(const RoomSetupState &state,
157  bool attackLeft, bool attackRight, bool attackUp, bool attackDown);
158  bool updateAttackAnimationState(HarvesterEngine &engine);
159  bool startHitAnimation(HarvesterEngine &engine, int monsterAttackFirstFrame);
160  bool updateHitAnimationState(HarvesterEngine &engine, const RoomSetupState &state,
161  const Common::Array<ObjectRecord> &sceneObjects, const Common::Array<AnimRecord> &sceneAnimations);
162  bool startDeathAnimation(int damageType, bool goreEnabled);
163  bool updateDeathAnimationState();
164  bool startTurnAnimation(int targetFacing);
165  bool updateTurnAnimationState();
166  bool stepMoveTarget(HarvesterEngine &engine, const RoomSetupState &state,
167  const Common::Array<ObjectRecord> &sceneObjects, const Common::Array<AnimRecord> &sceneAnimations,
168  int regionFacing = -1);
169  bool stepKeyboardMovement(HarvesterEngine &engine, const RoomSetupState &state,
170  const Common::Array<ObjectRecord> &sceneObjects, const Common::Array<AnimRecord> &sceneAnimations,
171  bool moveLeft, bool moveRight, bool moveUp, bool moveDown);
172  bool requestIdleAnimationExit(const RoomSetupState &state);
173  bool startIdleAnimation(HarvesterEngine &engine, const RoomSetupState &state);
174  bool updateIdleAnimation(const RoomSetupState &state);
175 
176 private:
177  bool finishIdleAnimation(const RoomSetupState &state);
178 
179  bool stopMoveTargetStep(const PlayerMovement::MovementContext &context,
180  const PlayerMovement::MovementPosition &candidate, int horizontalDirection, int depthDirection,
181  const Entity *blocker);
182 
183  RoomPlayerState _state;
184  RoomIdleAnimationState _idleState;
185 };
186 
187 } // End of namespace Harvester
188 
189 #endif // HARVESTER_PLAYER_H
Definition: script.h:237
Definition: str.h:59
Definition: art.h:31
Definition: player_movement.h:30
Definition: array.h:52
Definition: player.h:36
Definition: rect.h:536
Definition: entity.h:66
Definition: entity.h:184
Definition: player.h:94
Definition: rect.h:144
Definition: player.h:105
Definition: harvester.h:47
Definition: script.h:164
Definition: player_movement.h:38