ScummVM API documentation
avatar_mover_process.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 WORLD_ACTORS_AVATARMOVERPROCESS_H
23 #define WORLD_ACTORS_AVATARMOVERPROCESS_H
24 
25 #include "ultima/ultima8/metaengine.h"
26 #include "ultima/ultima8/kernel/process.h"
27 #include "ultima/ultima8/kernel/mouse.h"
28 #include "ultima/ultima8/world/actors/animation.h"
29 
30 namespace Ultima {
31 namespace Ultima8 {
32 
37 class AvatarMoverProcess : public Process {
38 public:
40  ~AvatarMoverProcess() override;
41 
42  void run() override;
43 
44  void resetIdleTime() {
45  _idleTime = 0;
46  }
47 
48  bool loadData(Common::ReadStream *rs, uint32 version);
49  void saveData(Common::WriteStream *ws) override;
50 
51  bool hasMovementFlags(uint32 flags) const {
52  return (_movementFlags & flags) != 0;
53  }
54  void setMovementFlag(uint32 mask) {
55  _movementFlags |= mask;
56  }
57  virtual void clearMovementFlag(uint32 mask) {
58  _movementFlags &= ~mask;
59  }
60  void resetMovementFlags() {
61  _movementFlags = 0;
62  }
63  void onMouseDown(int button, int32 mx, int32 my);
64  void onMouseUp(int button);
65 
66  // Return true if handled, false if not.
67  bool onActionDown(KeybindingAction action);
68  bool onActionUp(KeybindingAction action);
69 
70  enum MovementFlags {
71  MOVE_MOUSE_DIRECTION = 0x001,
72  MOVE_RUN = 0x0002,
73  MOVE_STEP = 0x0004, // also side-steps in crusader
74  MOVE_JUMP = 0x0008, // used for roll in crusader (when combined with left/right), and crouch (when combined with back)
75 
76  // Tank controls
77  MOVE_TURN_LEFT = 0x0010,
78  MOVE_TURN_RIGHT = 0x0020,
79  MOVE_FORWARD = 0x0040,
80  MOVE_BACK = 0x0080,
81 
82  // Directional controls
83  MOVE_LEFT = 0x0100,
84  MOVE_RIGHT = 0x0200,
85  MOVE_UP = 0x0400,
86  MOVE_DOWN = 0x0800,
87 
88  // Firing weapon (Crusader only)
89  MOVE_ATTACKING = 0x1000,
90  // Pending turn (Crusader only)
91  MOVE_PENDING_TURN_LEFT = 0x2000,
92  MOVE_PENDING_TURN_RIGHT = 0x4000,
93 
94  // Single-button moves (Crusader only)
95  MOVE_SHORT_JUMP = 0x008000,
96  MOVE_ROLL_LEFT = 0x010000,
97  MOVE_ROLL_RIGHT = 0x020000,
98  MOVE_STEP_LEFT = 0x040000,
99  MOVE_STEP_RIGHT = 0x080000,
100  MOVE_STEP_FORWARD = 0x100000,
101  MOVE_STEP_BACK = 0x200000,
102  MOVE_TOGGLE_CROUCH = 0x400000,
103 
104  MOVE_ANY_DIRECTION = MOVE_MOUSE_DIRECTION | MOVE_FORWARD | MOVE_BACK | MOVE_LEFT | MOVE_RIGHT | MOVE_UP | MOVE_DOWN
105  };
106 
107 protected:
108  virtual void handleHangingMode() = 0;
109  virtual void handleCombatMode() = 0;
110  virtual void handleNormalMode() = 0;
111 
112  void turnToDirection(Direction direction);
113  bool checkTurn(Direction direction, bool moving);
114 
115  // Walk and then stop in the given direction
116  void slowFromRun(Direction direction);
117 
118  // Stow weapon and stand
119  void putAwayWeapon(Direction direction);
120 
121  // If the last animation was falling or die but we're not dead, stand up!
122  // return true if we are waiting to get up
123  bool standUpIfNeeded(Direction direction);
124 
125  // Get directions based on what movement flags are set, eg y=+1 for up, x=-1 for left.
126  void getMovementFlagAxes(int &x, int &y);
127 
128  // Adjust the direction based on the current turn flags
129  Direction getTurnDirForTurnFlags(Direction direction, DirectionMode dirmode);
130 
131  // attack speed limiting
132  uint32 _lastAttack;
133 
134  // shake head when idle
135  uint32 _idleTime;
136 
137  MButton _mouseButton[2];
138 
139  uint32 _movementFlags;
140 };
141 
142 } // End of namespace Ultima8
143 } // End of namespace Ultima
144 
145 #endif
Definition: stream.h:77
Definition: process.h:34
Definition: avatar_mover_process.h:37
Definition: detection.h:27
void saveData(Common::WriteStream *ws) override
save Process data
Definition: stream.h:385
Definition: mouse.h:38