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