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