-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathACrab.h
More file actions
388 lines (320 loc) · 15.8 KB
/
ACrab.h
File metadata and controls
388 lines (320 loc) · 15.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#pragma once
/// Header file for the ACrab class.
/// @author Daniel Tabar
/// data@datarealms.com
/// http://www.datarealms.com
/// Inclusions of header files
#include "Actor.h"
#include "LimbPath.h"
#include "Leg.h"
#include <memory>
struct BITMAP;
namespace RTE {
class Turret;
class AEJetpack;
/// A crab-like actor with four legs.
class ACrab : public Actor {
friend struct EntityLuaBindings;
enum Side {
LEFTSIDE = 0,
RIGHTSIDE,
SIDECOUNT
};
enum Layer {
FGROUND = 0,
BGROUND,
LAYERCOUNT
};
/// Public member variable, method and friend function declarations
public:
// Concrete allocation and cloning definitions
EntityAllocation(ACrab);
AddScriptFunctionNames(Actor, "OnStride");
SerializableOverrideMethods;
ClassInfoGetters;
DefaultPieMenuNameGetter(HasObjectInGroup("Turrets") ? "Default Turret Pie Menu" : "Default Crab Pie Menu");
/// Constructor method used to instantiate a ACrab object in system
/// memory. Create() should be called before using the object.
ACrab();
/// Destructor method used to clean up a ACrab object before deletion
/// from system memory.
~ACrab() override;
/// Makes the ACrab object ready for use.
/// @return An error return value signaling sucess or any particular failure.
/// Anything below 0 is an error signal.
int Create() override;
/// Creates a ACrab to be identical to another, by deep copy.
/// @param reference A reference to the ACrab to deep copy.
/// @return An error return value signaling sucess or any particular failure.
/// Anything below 0 is an error signal.
int Create(const ACrab& reference);
/// Resets the entire ACrab, including its inherited members, to their
/// default settings or values.
void Reset() override {
Clear();
Actor::Reset();
}
/// Destroys and resets (through Clear()) the SceneLayer object.
/// @param notInherited Whether to only destroy the members defined in this derived class, or (default: false)
/// to destroy all inherited members also.
void Destroy(bool notInherited = false) override;
/// Gets the absoltue position of this' eye, or equivalent, where look
/// vector starts from.
/// @return A Vector with the absolute position of this' eye or view point.
Vector GetEyePos() const override;
/// Gets the Turret of this ACrab.
/// @return A pointer to Turret of this ACrab. Ownership is NOT transferred!
Turret* GetTurret() const { return m_pTurret; }
/// Sets the Turret for this ACrab. Ownership IS transferred!
/// @param newTurret The new Turret to use.
void SetTurret(Turret* newTurret);
/// Gets the jetpack of this ACrab.
/// @return A pointer to the jetpack of this ACrab. Ownership is NOT transferred!
AEJetpack* GetJetpack() const { return m_pJetpack; }
/// Sets the jetpack for this ACrab. Ownership IS Transferred!
/// @param newJetpack The new jetpack to use.
void SetJetpack(AEJetpack* newJetpack);
/// Gets the left foreground Leg of this ACrab.
/// @return A pointer to the left foreground Leg of this ACrab. Ownership is NOT transferred!
Leg* GetLeftFGLeg() const { return m_pLFGLeg; }
/// Sets the left foreground Leg for this ACrab. Ownership IS transferred!
/// @param newLeg The new Leg to use.
void SetLeftFGLeg(Leg* newLeg);
/// Gets the left background Leg of this ACrab.
/// @return A pointer to the left background Leg of this ACrab. Ownership is NOT transferred!
Leg* GetLeftBGLeg() const { return m_pLBGLeg; }
/// Sets the left background Leg for this ACrab. Ownership IS transferred!
/// @param newLeg The new Leg to use.
void SetLeftBGLeg(Leg* newLeg);
/// Gets the right foreground Leg of this ACrab.
/// @return A pointer to the right foreground Leg of this ACrab. Ownership is NOT transferred!
Leg* GetRightFGLeg() const { return m_pRFGLeg; }
/// Sets the right foreground Leg for this ACrab. Ownership IS transferred!
/// @param newLeg The new Leg to use.
void SetRightFGLeg(Leg* newLeg);
/// Gets the right BG Leg of this ACrab.
/// @return A pointer to the right background Leg of this ACrab. Ownership is NOT transferred!
Leg* GetRightBGLeg() const { return m_pRBGLeg; }
/// Sets the right background Leg for this ACrab. Ownership IS transferred!
/// @param newLeg The new Leg to use.
void SetRightBGLeg(Leg* newLeg);
/// Tries to handle the activated PieSlice in this object's PieMenu, if there is one, based on its SliceType.
/// @param pieSliceType The SliceType of the PieSlice being handled.
/// @return Whether or not the activated PieSlice SliceType was able to be handled.
bool HandlePieCommand(PieSliceType pieSliceType) override;
/// Returns whatever is equipped in the turret, if anything. OWNERSHIP IS NOT TRANSFERRED!
/// @return The currently equipped item, if any.
MovableObject* GetEquippedItem() const;
/// Indicates whether the currently held HDFirearm's is ready for use, and has
/// ammo etc.
/// @return Whether a currently HDFirearm (if any) is ready for use.
bool FirearmIsReady() const;
/// Indicates whether the currently held HDFirearm's is out of ammo.
/// @return Whether a currently HDFirearm (if any) is out of ammo.
bool FirearmIsEmpty() const;
/// Indicates whether the currently held HDFirearm's is almost out of ammo.
/// @return Whether a currently HDFirearm (if any) has less than half of ammo left.
bool FirearmNeedsReload() const;
/// Gets whether or not all of this ACrab's Turret's HDFirearms are full.
/// @return Whether or not all of this ACrab's Turret's HDFirearms are full. Will return true if there is no Turret or no HDFirearms.
bool FirearmsAreFull() const;
/// Indicates whether the currently held HDFirearm's is semi or full auto.
/// @return Whether a currently HDFirearm (if any) is a semi auto device.
bool FirearmIsSemiAuto() const;
/// Returns the currently held device's delay between pulling the trigger
/// and activating.
/// @return Delay in ms or zero if not a HDFirearm.
int FirearmActivationDelay() const;
/// Reloads the currently held firearms, if any.
void ReloadFirearms();
/// Tells whether a point on the scene is within close range of the currently
/// used device and aiming status, if applicable.
/// @param point A Vector witht he aboslute coordinates of a point to check.
/// @return Whether the point is within close range of this.
bool IsWithinRange(Vector& point) const override;
/// Casts an unseen-revealing ray in the direction of where this is facing.
/// @param FOVSpread The degree angle to deviate from the current view point in the ray
/// casting. A random ray will be chosen out of this +-range.
/// @param range The range, in pixels, beyond the actors sharp aim that the ray will have.
/// @return Whether any unseen pixels were revealed by this look.
bool Look(float FOVSpread, float range) override;
/// Casts an MO detecting ray in the direction of where the head is looking
/// at the time. Factors including head rotation, sharp aim mode, and
/// other variables determine how this ray is cast.
/// @param FOVSpread The degree angle to deviate from the current view point in the ray (default: 45)
/// casting. A random ray will be chosen out of this +-range.
/// @param ignoreMaterial A specific material ID to ignore (see through) (default: 0)
/// @param ignoreAllTerrain Whether to ignore all terrain or not (true means 'x-ray vision'). (default: false)
/// @return A pointer to the MO seen while looking.
MovableObject* LookForMOs(float FOVSpread = 45, unsigned char ignoreMaterial = 0, bool ignoreAllTerrain = false);
/// Gets the GUI representation of this ACrab, only defaulting to its Turret or body if no GraphicalIcon has been defined.
/// @return The graphical representation of this ACrab as a BITMAP.
BITMAP* GetGraphicalIcon() const override;
/// Gets whether this ACrab has just taken a stride this frame.
/// @return Whether this ACrab has taken a stride this frame or not.
bool StrideFrame() const { return m_StrideFrame; }
/// Update called prior to controller update. Ugly hack. Supposed to be done every frame.
void PreControllerUpdate() override;
/// Updates this MovableObject. Supposed to be done every frame.
void Update() override;
/// Draws this ACrab's current graphical representation to a
/// BITMAP of choice.
/// @param pTargetBitmap A pointer to a BITMAP to draw on.
/// @param targetPos The absolute position of the target bitmap's upper left corner in the Scene. (default: Vector())
/// @param mode In which mode to draw in. See the DrawMode enumeration for the modes. (default: g_DrawColor)
/// @param onlyPhysical Whether to not draw any extra 'ghost' items of this MovableObject, (default: false)
/// indicator arrows or hovering HUD text and so on.
void Draw(BITMAP* pTargetBitmap, const Vector& targetPos = Vector(), DrawMode mode = g_DrawColor, bool onlyPhysical = false) const override;
/// Draws this Actor's current graphical HUD overlay representation to a
/// BITMAP of choice.
/// @param pTargetBitmap A pointer to a BITMAP to draw on.
/// @param targetPos The absolute position of the target bitmap's upper left corner in the Scene. (default: Vector())
/// @param whichScreen Which player's screen this is being drawn to. May affect what HUD elements (default: 0)
/// get drawn etc.
void DrawHUD(BITMAP* pTargetBitmap, const Vector& targetPos = Vector(), int whichScreen = 0, bool playerControlled = false) override;
/// Gets the LimbPath corresponding to the passed in Side, Layer and MovementState values.
/// @param side Whether to get the left or right side.
/// @param layer Whether to get foreground or background LimbPath.
/// @param movementState Which movement state to get the LimbPath for.
/// @return The LimbPath corresponding to the passed in Layer and MovementState values.
LimbPath* GetLimbPath(Side side, Layer layer, MovementState movementState) { return &m_Paths[side][layer][movementState]; }
/// Shortcut to get the speed of a particular move state's FG (and left side if relevant) limb path.
/// @param movementState Which movement state to get the limb path speed for.
/// @return Limb path speed for the specified movement state in m/s.
float GetLimbPathTravelSpeed(MovementState movementState);
/// Shortcut to set the speed of a particular move state's limb path, including all layers (and sides if relevant)
/// @param movementState Which movement state to set the limb path speed for.
/// @param newSpeed New speed value in m/s.
void SetLimbPathTravelSpeed(MovementState movementStateourmaxmovement, float newSpeed);
/// Shortcut to get the push force of a particular move state's FG (and left side if relevant) limb path.
/// @return The push force, in kg * m/s^2.
float GetLimbPathPushForce(MovementState movementState);
/// Shortcut to set the push force of a particular move state's limb path, including all layers (and sides if relevant)
/// @param movementState Which movement state to set the limb path speed for.
/// @param newForce New push force value in kg * m/s^2.
void SetLimbPathPushForce(MovementState movementState, float newForce);
/// Gets this ACrab's stride sound.
/// @return The SoundContainer for this ACrab's stride sound.
std::shared_ptr<SoundContainer> GetStrideSound() const { return m_StrideSound; }
/// Sets this ACrab's stride sound to a copy of the input.
/// @param newSound The new SoundContainer for this ACrab's stride sound to copy.
void SetStrideSound(const SoundContainer* newSound) {
if (!newSound)
m_StrideSound = nullptr;
else
m_StrideSound = std::make_shared<SoundContainer>(*newSound);
}
/// Gets the upper limit of this ACrab's aim range.
/// @return The upper limit of this ACrab's aim range.
float GetAimRangeUpperLimit() const { return m_AimRangeUpperLimit; }
/// Sets the upper limit of this ACrab's aim range.
/// @param aimRangeUpperLimit The new upper limit of this ACrab's aim range.
void SetAimRangeUpperLimit(float aimRangeUpperLimit) { m_AimRangeUpperLimit = aimRangeUpperLimit; }
/// Gets the lower limit of this ACrab's aim range.
/// @return The lower limit of this ACrab's aim range.
float GetAimRangeLowerLimit() const { return m_AimRangeLowerLimit; }
/// Sets the lower limit of this ACrab's aim range.
/// @param aimRangeLowerLimit The new lower limit of this ACrab's aim range.
void SetAimRangeLowerLimit(float aimRangeLowerLimit) { m_AimRangeLowerLimit = aimRangeLowerLimit; }
// Estimates how high this actor can jump.
/// @return The actor's jump height.
virtual float EstimateJumpHeight() const override;
/// Protected member variable and method declarations
protected:
/// Function that is called when we get a new movepath.
/// This processes and cleans up the movepath.
void OnNewMovePath() override;
// Member variables
static Entity::ClassInfo m_sClass;
// Turret which can be mounted with a weapon
Turret* m_pTurret;
// TODO when this class is cleaned up these legs and footgroups should probably be renamed. L and R should be expanded to Left and Right. I think FG and BG can stay as is cause they're everywhere.
// Left Foreground leg.
Leg* m_pLFGLeg;
// Left Background leg.
Leg* m_pLBGLeg;
// Right Foreground leg.
Leg* m_pRFGLeg;
// Right Background leg.
Leg* m_pRBGLeg;
// Limb AtomGroups.
AtomGroup* m_pLFGFootGroup;
AtomGroup* m_BackupLFGFootGroup;
AtomGroup* m_pLBGFootGroup;
AtomGroup* m_BackupLBGFootGroup;
AtomGroup* m_pRFGFootGroup;
AtomGroup* m_BackupRFGFootGroup;
AtomGroup* m_pRBGFootGroup;
AtomGroup* m_BackupRBGFootGroup;
// The sound of the actor taking a step (think robot servo)
std::shared_ptr<SoundContainer> m_StrideSound;
// Jetpack booster.
AEJetpack* m_pJetpack;
// Blink timer
Timer m_IconBlinkTimer;
// Whether a stride was taken this frame or not.
bool m_StrideFrame = false;
// Limb paths for different movement states.
// First which side, then which background/foreground, then the movement state
LimbPath m_Paths[SIDECOUNT][LAYERCOUNT][MOVEMENTSTATECOUNT];
// Whether was aiming during the last frame too.
bool m_Aiming;
// Controls the start of leg synch.
bool m_StrideStart[SIDECOUNT];
// Times the strides to make sure they get restarted if they end up too long
Timer m_StrideTimer[SIDECOUNT];
// The maximum angle MountedMO can be aimed up, positive values only, in radians
float m_AimRangeUpperLimit;
// The maximum angle MountedMO can be aimed down, positive values only, in radians
float m_AimRangeLowerLimit;
// Whether mouse input should be locked to the aim range, or whether we can "wander" out. For static emplacements like turrets, this is good, but for moving things it's a bit sticky.
bool m_LockMouseAimInput;
// AI States
enum DeviceHandlingState {
STILL = 0,
POINTING,
SCANNING,
AIMING,
FIRING,
THROWING,
DIGGING
};
enum SweepState {
NOSWEEP = 0,
SWEEPINGUP,
SWEEPUPPAUSE,
SWEEPINGDOWN,
SWEEPDOWNPAUSE
};
enum DigState {
NOTDIGGING = 0,
PREDIG,
STARTDIG,
TUNNELING,
FINISHINGDIG,
PAUSEDIGGER
};
enum JumpState {
NOTJUMPING = 0,
FORWARDJUMP,
PREUPJUMP,
UPJUMP,
APEXJUMP,
LANDJUMP
};
#pragma region Event Handling
/// Event listener to be run while this ACrab's PieMenu is opened.
/// @param pieMenu The PieMenu this event listener needs to listen to. This will always be this' m_PieMenu and only exists for std::bind.
/// @return An error return value signaling success or any particular failure. Anything below 0 is an error signal.
int WhilePieMenuOpenListener(const PieMenu* pieMenu) override;
#pragma endregion
/// Private member variable and method declarations
private:
/// Clears all the member variables of this ACrab, effectively
/// resetting the members of this abstraction level only.
void Clear();
// Disallow the use of some implicit methods.
ACrab(const ACrab& reference) = delete;
ACrab& operator=(const ACrab& rhs) = delete;
};
} // namespace RTE