1 /* ResidualVM - A 3D game interpreter
2 *
3 * ResidualVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the AUTHORS
5 * file distributed with this source distribution.
6 *
7 * Additional copyright for this file:
8 * Copyright (C) 1999-2000 Revolution Software Ltd.
9 * This code is based on source code created by Revolution Software,
10 * used with permission.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 *
26 */
27
28 #ifndef ICB_PLAYER
29 #define ICB_PLAYER
30
31 #include "engines/icb/common/px_common.h"
32 #include "engines/icb/debug.h"
33 #include "engines/icb/object_structs.h"
34 #include "engines/icb/common/px_route_barriers.h"
35 #include "engines/icb/common/px_scriptengine.h"
36 #include "engines/icb/animation_mega_set.h"
37 #include "engines/icb/fn_routines.h"
38 #include "engines/icb/bone.h"
39
40 namespace ICB {
41
42 extern int32 armedChangesMode;
43 extern int32 animToggles;
44 extern PXreal REPEL_TURN;
45 extern PXreal REPULSE_DISTANCE;
46 extern int32 CAMERA_SMOOTH_CYCLES;
47
48 // How deep the player control mode stack is !
49 #define CONTROL_MODE_STACK_DEPTH 4
50
51 // The maximum number of ammo clips the player can carry
52 static const uint32 MAX_AMMO_CLIPS = 5;
53
54 // The maximum number of hit points the player has
55 static const uint32 MAX_HITS = 10;
56
57 // the player service is not tied to the session but exists as a global engine service
58 enum _player_stat {
59 STOOD, // 1
60 WALKING, // 2
61 CROUCH_WALK, // 3
62 RUNNING, // 4
63 CROUCH_TO_PUNCH, // 5
64 CROUCH_TO_STAND_UNARMED, // 6
65 CROUCH_TO_STAND_ARMED, // 7
66 CROUCHING, // 8
67 NEW_AIM, // 9
68 CROUCH_AIM, // 10
69 PUTTING_AWAY_GUN, // 11
70 PUTTING_AWAY_CROUCH_GUN, // 12
71 LINKING, // 13
72 GUN_LINKING, // 14
73 FAST_LINKING, // 15
74 EASY_LINKING, // 16
75 REVERSE_LINKING, // 17
76 FAST_REVERSE_LINKING, // 18
77 STILL_LINKING, // 19
78 INVENTORY, // 20
79 REMORA, // 21
80 STRIKING, // 22
81 ON_STAIRS, // 23
82 RUNNING_ON_STAIRS, // 24
83 STOOD_ON_STAIRS, // 25
84 REVERSE_ON_STAIRS, // 26
85 ON_LADDER, // 27
86 BEGIN_DOWN_LADDER, // 28
87 LEAVE_LADDER, // 29
88 LEAVE_LADDER_BOTTOM, // 30
89 SLIP_SLIDIN_AWAY, // 31
90 FINISHED_RELOADING, // 32
91 FIN_NORMAL_RELOAD, // 33
92 FIN_NORMAL_CROUCH_RELOAD, // 34
93 STILL_REVERSE_LINKING, // 35
94
95 __TOTAL_PLAYER_MODES
96 };
97
98 // routines called from gateway return one of these
99 enum __mode_return { __FINISHED_THIS_CYCLE, __MORE_THIS_CYCLE };
100
101 // these are the raw input device states that the player control interface is derived from
102 enum __player_momentum {
103 __STILL,
104 __BACKWARD_1,
105 __FORWARD_1,
106 __FORWARD_2, // only analogue device
107
108 __FORWARD_3
109 };
110
111 enum __player_turn {
112 __NO_TURN,
113 __LEFT,
114 __RIGHT,
115
116 // psx and pc analogue devices only
117 __HARD_LEFT, // analogue controllers only - will stop forward momentum and instigate a turn on spot
118 __HARD_RIGHT // as above
119 };
120
121 enum __player_button {
122 // PlayStation PC Default Use
123
124 __BUTTON_1, // X ctrl fire
125 __BUTTON_2, // O space interact
126 __BUTTON_3, // Rshift unused
127 __BUTTON_4, // /\ enter inventory
128 __BUTTON_5, // delete unused
129 __BUTTON_6, // R2 Lshift remora
130 __BUTTON_7, // L1 Ralt sidestep
131 __NO_BUTTON
132 };
133
134 // Powers of two bit-flag settings
135 enum ButtonEnums {
136 __INTERACT = 1,
137 __ATTACK = 2, // fire or punch
138 __INVENTORY = 4,
139 __ARMUNARM = 8,
140 __REMORA = 16,
141 __CROUCH = 32,
142 __SIDESTEP = 64, // this is a movement modifier button
143 __WALKBACK = 64, // this is a movement modifier button
144 __JOG = 128, // RUN !
145 __UNUSEDBUTTON = 256
146 }; // Note, __EXAMINE was never used
147
148 struct _input {
149 __player_momentum momentum;
150 __player_turn turn;
151
152 int32 bitflag;
153
SetButton_input154 void SetButton(const enum ButtonEnums b) { bitflag |= b; }
UnSetButton_input155 void UnSetButton(const enum ButtonEnums b) { bitflag &= ~b; }
IsButtonSet_input156 uint32 IsButtonSet(const enum ButtonEnums b) const {
157 return (bitflag & b);
158 }
159 };
160
161 typedef struct {
162 PXreal x, z;
163 bool8 stepped_on_step;
164 } _step_sample;
165
166 #define MAX_stair_length 40
167 #define TOP_stair_num (MAX_stair_length - 1)
168
169 enum __pc_input { __KEYS, __OTHER_DI_DEVICE };
170
171 // What type of control system is being by the player
172 enum __Actor_control_mode { ACTOR_RELATIVE, SCREEN_RELATIVE };
173
174 class _player {
175 public:
176 void ___init();
177
178 void Set_player_id(uint32 id);
179 uint32 Fetch_player_id();
180 mcodeFunctionReturnCodes Gateway();
181 void Update_input_state();
182
183 void DrawCompass();
184
185 void Find_current_player_interact_object();
186 void Render_crude_interact_highlight();
187
188 uint32 Fetch_player_interact_id();
189 bool8 Fetch_player_interact_status();
190
191 bool8 Player_exists();
192
193 void Reset_player();
194
195 _input *Fetch_input_state();
196
197 uint32 GetBulletsPerClip();
198 uint32 GetMaxClips();
199
200 int32 GetNoBullets();
201 void SetBullets(uint32 num);
202 void UseBullets(uint32 num);
203
204 int32 GetNoAmmoClips();
205 void AddAmmoClips(uint32 num, bool8 bFlashIcons);
206 void UseAmmoClips(uint32 num);
207
208 int32 GetNoMediPacks();
209 void AddMediPacks(uint32 num, bool8 bFlashIcons);
210 void UseMediPacks(uint32 num);
211
212 __mode_return Player_walking();
213 __mode_return Player_crouch_walk();
214 __mode_return Player_running();
215 __mode_return Player_stood();
216 __mode_return Player_crouching();
217 __mode_return Player_aiming();
218 __mode_return Player_new_aim();
219 __mode_return Player_crouch_aim();
220 __mode_return Process_strike();
221 __mode_return Player_stairs();
222 __mode_return Player_running_on_stairs();
223 __mode_return Player_stood_on_stairs();
224 __mode_return Player_ladder();
225 __mode_return Player_slide_on_ladder();
226
227 void Leave_stair();
228
229 __mode_return Process_link();
230 __mode_return Process_fast_link();
231
232 __mode_return Process_reverse_link();
233
234 __mode_return Process_easy_link();
235 __mode_return Process_still_link();
236 __mode_return Process_reverse_still_link();
237
238 __mode_return Player_interact();
239 __mode_return Player_press_fire_button();
240 __mode_return Player_press_inv_button();
241 __mode_return Player_press_strike_button();
242 __mode_return Player_press_remora_button();
243
244 void Add_to_interact_history();
245
246 void Set_to_first_frame(__mega_set_names opt_link);
247 void Set_to_last_frame(__mega_set_names opt_link);
248
249 void Start_new_mode(_player_stat new_mode);
250
251 void Soft_start_new_mode_no_link(_player_stat new_mode, __mega_set_names type);
252
253 void Soft_start_new_mode(_player_stat new_mode, __mega_set_names opt_link);
254 void Soft_start_new_mode(_player_stat new_mode, __mega_set_names opt_link, __mega_set_names opt_link2);
255
256 void Hard_start_new_mode(_player_stat new_mode, __mega_set_names opt_link);
257 void Fast_hard_start_new_mode(_player_stat new_mode, __mega_set_names opt_link);
258
259 void Hard_start_reverse_new_mode(_player_stat new_mode, __mega_set_names opt_link);
260
261 void Easy_start_new_mode(_player_stat new_mode, __mega_set_names opt_link);
262
263 void Still_start_new_mode(_player_stat new_mode, __mega_set_names link);
264 void Still_reverse_start_new_mode(_player_stat new_mode, __mega_set_names link);
265
266 bool8 Advance_frame_motion_and_pan(__mega_set_names anim_type);
267 bool8 Reverse_frame_motion_and_pan(__mega_set_names anim_type);
268
269 void Set_player_status(_player_stat new_mode);
270
271 inline void Push_control_mode(__Actor_control_mode newMode);
272 inline void Pop_control_mode();
273 inline void Set_control_mode(__Actor_control_mode newMode);
274 inline __Actor_control_mode Get_control_mode();
275
276 void Push_player_stat();
277 void Pop_player_stat();
278
279 // the master high level switch
280 uint32 player_id; // number of object file of the player object - set this for fast access to structs in sub-modules
281 _logic *log; // for the objects logic structure
282
283 // high level master mode switch
284 _player_stat player_status;
285
286 // player status to switch to after link animation has finished
287 _player_stat stat_after_link;
288
289 // pushed stat
290 _player_stat previous_stat;
291
292 // input device state calculated at start of each cycle
293 _input cur_state;
294
295 uint32 inv_cycle_count;
296 uint32 cur_interact_id; // id number of nico - which has same name as game object
297 uint32 look_at_id; // when no interact id exists we may look-at a more distant prop
298
299 // __Actor_control_mode control_mode_stack[CONTROL_MODE_STACK_DEPTH];
300 __Actor_control_mode focus_mode;
301 __Actor_control_mode master_mode;
302
303 PXfloat lastCameraPan;
304 PXfloat deltaCameraPan;
305 PXfloat scrnPan;
306
307 PXfloat aim_turn_amount; // ANGLE_UNITS_PER_GAME_CYCLE
308 PXfloat stood_turn_amount; // ANGLE_UNITS_PER_GAME_CYCLE
309 PXfloat stood_fast_turn_amount; // ANGLE_UNITS_PER_GAME_CYCLE
310 PXfloat walk_turn_amount; // ANGLE_UNITS_PER_GAME_CYCLE
311 PXfloat run_turn_amount; // ANGLE_UNITS_PER_GAME_CYCLE
312 PXfloat crouch_turn_amount; // ANGLE_UNITS_PER_GAME_CYCLE
313
314 // yes, its that stair drift correction system
315 _step_sample step_samples[MAX_stair_length];
316
317 BoneDeformation shotDeformation;
318
319 // Note these are at the end of the structure to keep DWORD alignment
320 uint8 panCycle;
321 bool8 crouch;
322 bool8 backward_lock; // set to TRUE to stop repeating backward steps
323 bool8 forward_lock;
324
325 bool8 remora_lock;
326 bool8 interact_lock;
327 bool8 fire_lock;
328 bool8 inv_lock;
329
330 bool8 has_weapon;
331 bool8 interact_selected; // is there a current player interact object?
332 bool8 look_at_selected; // sometimes when there is no interact
333 bool8 dead_mega; // is the target dead or not - if a mega
334
335 // set to true when
336 bool8 player_exists;
337 bool8 haveCamera;
338 bool8 hunting;
339 // stairway stuff
340 uint8 stair_num; // stair number we're on
341
342 uint8 stair_dir; // 1 up, 0 down
343 uint8 stair_unit; // how many cycles into stair are we
344 uint8 left_right; // 1 left / 0 right
345 uint8 was_climbing; // 1 yes, 0 no - used to see if first stand
346
347 uint8 begun_at_bottom; // used when deciding to write history
348 int8 being_shot;
349 int8 shot_by_id;
350 int32 step_sample_num;
351
352 int8 walk_count; // counts up as you walk - used to alert guards of non creeping player
353 bool8 stood_on_lift; // are we stood on a lift
354 // armed menu
355 uint8 padding[2];
356
357 // SORTED PADDING AGAIN. MAYBE IT'S NOT IMPORTANT, 'COS EVERY TIME I GO TO WELL-USED CLASSES
358 // LIKE PLAYER, THE ALLIGNMENT IS ALL OVER THE PLACE.
359 };
360
Player_exists()361 inline bool8 _player::Player_exists() {
362 // return id of player object
363
364 return (player_exists);
365 }
366
Fetch_player_id()367 inline uint32 _player::Fetch_player_id() {
368 // return id of player object
369
370 if (!player_exists)
371 Fatal_error("no live player - must stop");
372
373 return (player_id);
374 }
375
Fetch_player_interact_id()376 inline uint32 _player::Fetch_player_interact_id() {
377 // return id of player object
378
379 return (cur_interact_id);
380 }
381
Fetch_player_interact_status()382 inline bool8 _player::Fetch_player_interact_status() {
383 // return id of player object
384
385 return (interact_selected);
386 }
387
Fetch_input_state()388 inline _input *_player::Fetch_input_state() {
389 // return id of player object
390
391 return (&cur_state);
392 }
393
Push_control_mode(__Actor_control_mode newMode)394 inline void _player::Push_control_mode(__Actor_control_mode newMode) { focus_mode = newMode; }
395
Set_control_mode(__Actor_control_mode newMode)396 inline void _player::Set_control_mode(__Actor_control_mode newMode) {
397 focus_mode = newMode;
398 master_mode = newMode;
399 }
400
Pop_control_mode()401 inline void _player::Pop_control_mode() {}
402
Get_control_mode()403 inline __Actor_control_mode _player::Get_control_mode() { return focus_mode; }
404
405
406 extern uint32 fire_key;
407 extern uint32 interact_key;
408 extern uint32 inventory_key;
409 extern uint32 arm_key;
410 extern uint32 remora_key;
411 extern uint32 crouch_key;
412 extern uint32 sidestep_key;
413 extern uint32 run_key;
414 extern uint32 pause_key;
415 extern uint32 up_key;
416 extern uint32 down_key;
417 extern uint32 left_key;
418 extern uint32 right_key;
419
420
421 } // End of namespace ICB
422
423 #endif
424