improved code for final time calculation
[rocksndiamonds.git] / src / game.h
1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
5 //                  Holger Schemel
6 //                  info@artsoft.org
7 //                  https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
9 // game.h
10 // ============================================================================
11
12 #ifndef GAME_H
13 #define GAME_H
14
15 // (not included here due to collisions with Emerald Mine engine definitions)
16 // #include "main.h"
17
18 #define MAX_INVENTORY_SIZE              1000
19
20 #define MAX_HEALTH                      100
21
22 #define STD_NUM_KEYS                    4
23 #define MAX_NUM_KEYS                    8
24
25 #define NUM_BELTS                       4
26 #define NUM_BELT_PARTS                  3
27
28 #define NUM_PANEL_INVENTORY             8
29 #define NUM_PANEL_GRAPHICS              8
30 #define NUM_PANEL_ELEMENTS              8
31 #define NUM_PANEL_CE_SCORE              8
32
33 #define STR_SNAPSHOT_MODE_OFF           "off"
34 #define STR_SNAPSHOT_MODE_EVERY_STEP    "every_step"
35 #define STR_SNAPSHOT_MODE_EVERY_MOVE    "every_move"
36 #define STR_SNAPSHOT_MODE_EVERY_COLLECT "every_collect"
37 #define STR_SNAPSHOT_MODE_DEFAULT       STR_SNAPSHOT_MODE_OFF
38
39 #define SNAPSHOT_MODE_OFF               0
40 #define SNAPSHOT_MODE_EVERY_STEP        1
41 #define SNAPSHOT_MODE_EVERY_MOVE        2
42 #define SNAPSHOT_MODE_EVERY_COLLECT     3
43 #define SNAPSHOT_MODE_DEFAULT           SNAPSHOT_MODE_OFF
44
45
46 struct GamePanelInfo
47 {
48   struct TextPosInfo level_number;
49   struct TextPosInfo gems;
50   struct TextPosInfo inventory_count;
51   struct TextPosInfo inventory_first[NUM_PANEL_INVENTORY];
52   struct TextPosInfo inventory_last[NUM_PANEL_INVENTORY];
53   struct TextPosInfo key[MAX_NUM_KEYS];
54   struct TextPosInfo key_white;
55   struct TextPosInfo key_white_count;
56   struct TextPosInfo score;
57   struct TextPosInfo highscore;
58   struct TextPosInfo time;
59   struct TextPosInfo time_hh;
60   struct TextPosInfo time_mm;
61   struct TextPosInfo time_ss;
62   struct TextPosInfo time_anim;
63   struct TextPosInfo health;
64   struct TextPosInfo health_anim;
65   struct TextPosInfo frame;
66   struct TextPosInfo shield_normal;
67   struct TextPosInfo shield_normal_time;
68   struct TextPosInfo shield_deadly;
69   struct TextPosInfo shield_deadly_time;
70   struct TextPosInfo exit;
71   struct TextPosInfo emc_magic_ball;
72   struct TextPosInfo emc_magic_ball_switch;
73   struct TextPosInfo light_switch;
74   struct TextPosInfo light_switch_time;
75   struct TextPosInfo timegate_switch;
76   struct TextPosInfo timegate_switch_time;
77   struct TextPosInfo switchgate_switch;
78   struct TextPosInfo emc_lenses;
79   struct TextPosInfo emc_lenses_time;
80   struct TextPosInfo emc_magnifier;
81   struct TextPosInfo emc_magnifier_time;
82   struct TextPosInfo balloon_switch;
83   struct TextPosInfo dynabomb_number;
84   struct TextPosInfo dynabomb_size;
85   struct TextPosInfo dynabomb_power;
86   struct TextPosInfo penguins;
87   struct TextPosInfo sokoban_objects;
88   struct TextPosInfo sokoban_fields;
89   struct TextPosInfo robot_wheel;
90   struct TextPosInfo conveyor_belt[NUM_BELTS];
91   struct TextPosInfo conveyor_belt_switch[NUM_BELTS];
92   struct TextPosInfo magic_wall;
93   struct TextPosInfo magic_wall_time;
94   struct TextPosInfo gravity_state;
95   struct TextPosInfo graphic[NUM_PANEL_GRAPHICS];
96   struct TextPosInfo element[NUM_PANEL_ELEMENTS];
97   struct TextPosInfo element_count[NUM_PANEL_ELEMENTS];
98   struct TextPosInfo ce_score[NUM_PANEL_CE_SCORE];
99   struct TextPosInfo ce_score_element[NUM_PANEL_CE_SCORE];
100   struct TextPosInfo player_name;
101   struct TextPosInfo level_name;
102   struct TextPosInfo level_author;
103
104   // value to determine if panel will be updated or not
105   boolean active;
106 };
107
108 struct GameButtonInfo
109 {
110   struct XY stop;
111   struct XY pause;
112   struct XY play;
113
114   struct XY undo;
115   struct XY redo;
116
117   struct XY save;
118   struct XY pause2;
119   struct XY load;
120
121   struct XY sound_music;
122   struct XY sound_loops;
123   struct XY sound_simple;
124
125   struct XY panel_stop;
126   struct XY panel_pause;
127   struct XY panel_play;
128
129   struct XY panel_sound_music;
130   struct XY panel_sound_loops;
131   struct XY panel_sound_simple;
132
133   struct XY touch_stop;
134   struct XY touch_pause;
135 };
136
137 struct GameSnapshotInfo
138 {
139   int mode;
140
141   byte last_action[MAX_PLAYERS];
142   boolean changed_action;
143   boolean collected_item;
144
145   boolean save_snapshot;
146 };
147
148 struct GameInfo
149 {
150   // values for control panel
151   struct GamePanelInfo panel;
152   struct GameButtonInfo button;
153
154   // values for graphics engine customization
155   int graphics_engine_version;
156   boolean use_native_emc_graphics_engine;
157   boolean use_native_sp_graphics_engine;
158   boolean use_masked_pushing;
159   boolean use_masked_elements;
160   int forced_scroll_delay_value;
161   int scroll_delay_value;
162   int tile_size;
163
164   // constant within running game
165   int engine_version;
166   int emulation;
167   int initial_move_delay[MAX_PLAYERS];
168   int initial_move_delay_value[MAX_PLAYERS];
169   int initial_push_delay_value;
170
171   // flag for single or multi-player mode (needed for playing tapes)
172   // (when playing/recording games, this is identical to "setup.team_mode"
173   boolean team_mode;
174
175   // flags to handle bugs in and changes between different engine versions
176   // (for the latest engine version, these flags should always be "FALSE")
177   boolean use_change_when_pushing_bug;
178   boolean use_block_last_field_bug;
179   boolean max_num_changes_per_frame;
180   boolean use_reverse_scan_direction;
181
182   // flags to indicate which game actions are used in this game
183   boolean use_key_actions;
184   boolean use_mouse_actions;
185
186   // variable within running game
187   int yamyam_content_nr;
188   boolean robot_wheel_active;
189   boolean magic_wall_active;
190   int magic_wall_time_left;
191   int light_time_left;
192   int timegate_time_left;
193   int belt_dir[4];
194   int belt_dir_nr[4];
195   int switchgate_pos;
196   int wind_direction;
197
198   boolean explosions_delayed;
199   boolean envelope_active;
200   boolean no_time_limit;        // (variable only in very special case)
201
202   int time_final;               // time (in seconds) or steps left or played
203
204   int score;
205   int score_final;
206
207   int health;
208   int health_final;
209
210   int gems_still_needed;
211   int sokoban_fields_still_needed;
212   int sokoban_objects_still_needed;
213   int lights_still_needed;
214   int players_still_needed;
215   int friends_still_needed;
216
217   int robot_wheel_x, robot_wheel_y;
218   int exit_x, exit_y;
219
220   boolean all_players_gone;
221
222   // values for the new EMC elements
223   int lenses_time_left;
224   int magnify_time_left;
225   boolean ball_active;
226   int ball_content_nr;
227
228   // values for player idle animation (no effect on engine)
229   int player_boring_delay_fixed;
230   int player_boring_delay_random;
231   int player_sleeping_delay_fixed;
232   int player_sleeping_delay_random;
233
234   // values for special game initialization control
235   boolean restart_level;
236
237   // trigger message to ask for restarting the game
238   char *restart_game_message;
239
240   // values for special request dialog control
241   boolean request_active;
242   boolean request_active_or_moving;
243
244   // values for special game control
245   int centered_player_nr;
246   int centered_player_nr_next;
247   boolean set_centered_player;
248   boolean set_centered_player_wrap;
249
250   // values for single step mode control
251   boolean enter_single_step_mode;
252
253   // values for random number generator initialization after snapshot
254   unsigned int num_random_calls;
255
256   // values for game engine snapshot control
257   struct GameSnapshotInfo snapshot;
258
259   // values for handling states for solved level and game over
260   boolean LevelSolved;
261   boolean GamePlayed;
262   boolean GameOver;
263
264   boolean LevelSolved_GameWon;
265   boolean LevelSolved_GameEnd;
266   boolean LevelSolved_SaveTape;
267   boolean LevelSolved_SaveScore;
268
269   int LevelSolved_CountingTime;
270   int LevelSolved_CountingScore;
271   int LevelSolved_CountingHealth;
272 };
273
274 struct PlayerInfo
275 {
276   boolean present;              // player present in level playfield
277   boolean connected_locally;    // player connected (locally)
278   boolean connected_network;    // player connected (network)
279   boolean connected;            // player connected (locally or via network)
280   boolean active;               // player present and connected
281   boolean mapped;               // player already mapped to input device
282
283   boolean killed;               // player maybe present/active, but killed
284   boolean reanimated;           // player maybe killed, but reanimated
285   boolean buried;               // player finally killed and removed
286
287   int index_nr;                 // player number (0 to 3)
288   int index_bit;                // player number bit (1 << 0 to 1 << 3)
289   int element_nr;               // element (EL_PLAYER_1 to EL_PLAYER_4)
290   int client_nr;                // network client identifier
291
292   byte action;                  // action from local input device
293   byte effective_action;        /* action acknowledged from network server
294                                    or summarized over all configured input
295                                    devices when in single player mode */
296   byte programmed_action;       /* action forced by game itself (like moving
297                                    through doors); overrides other actions */
298   byte snap_action;             // action from TAS snap keys
299
300   struct MouseActionInfo mouse_action;           // (used by MM engine only)
301   struct MouseActionInfo effective_mouse_action; // (used by MM engine only)
302
303   int jx, jy, last_jx, last_jy;
304   int MovDir, MovPos, GfxDir, GfxPos;
305   int Frame, StepFrame;
306
307   int GfxAction;
308
309   int initial_element;          // EL_PLAYER_1 to EL_PLAYER_4 or EL_SP_MURPHY
310   int artwork_element;
311   boolean use_murphy;
312
313   boolean block_last_field;
314   int block_delay_adjustment;   // needed for different engine versions
315
316   boolean can_fall_into_acid;
317
318   boolean gravity;
319
320   int last_move_dir;
321
322   boolean is_active;
323
324   boolean is_waiting;
325   boolean is_moving;
326   boolean is_auto_moving;
327   boolean is_digging;
328   boolean is_snapping;
329   boolean is_collecting;
330   boolean is_pushing;
331   boolean is_switching;
332   boolean is_dropping;
333   boolean is_dropping_pressed;
334
335   boolean is_bored;
336   boolean is_sleeping;
337
338   boolean was_waiting;
339   boolean was_moving;
340   boolean was_snapping;
341   boolean was_dropping;
342
343   boolean cannot_move;
344
345   boolean force_dropping;       // needed for single step mode
346
347   int frame_counter_bored;
348   int frame_counter_sleeping;
349
350   int anim_delay_counter;
351   int post_delay_counter;
352
353   int dir_waiting;
354   int action_waiting, last_action_waiting;
355   int special_action_bored;
356   int special_action_sleeping;
357
358   int num_special_action_bored;
359   int num_special_action_sleeping;
360
361   int switch_x, switch_y;
362   int drop_x, drop_y;
363
364   int show_envelope;
365
366   int move_delay;
367   int move_delay_value;
368   int move_delay_value_next;
369   int move_delay_reset_counter;
370
371   int push_delay;
372   int push_delay_value;
373
374   unsigned int actual_frame_counter;
375
376   int drop_delay;
377   int drop_pressed_delay;
378
379   int step_counter;
380
381   int key[MAX_NUM_KEYS];
382   int num_white_keys;
383   int dynabomb_count, dynabomb_size, dynabombs_left, dynabomb_xl;
384   int shield_normal_time_left;
385   int shield_deadly_time_left;
386
387   int last_removed_element;
388
389   int inventory_element[MAX_INVENTORY_SIZE];
390   int inventory_infinite_element;
391   int inventory_size;
392 };
393
394 extern struct GameInfo          game;
395 extern struct PlayerInfo        stored_player[MAX_PLAYERS], *local_player;
396
397
398 #ifdef DEBUG
399 void DEBUG_SetMaximumDynamite(void);
400 #endif
401
402 void GetPlayerConfig(void);
403 int GetElementFromGroupElement(int);
404
405 int getPlayerInventorySize(int);
406
407 void UpdateGameDoorValues(void);
408 void DrawGameDoorValues(void);
409
410 void UpdateAndDisplayGameControlValues(void);
411
412 void InitGameSound(void);
413 void InitGame(void);
414
415 void UpdateEngineValues(int, int, int, int);
416 void GameWon(void);
417 void GameEnd(void);
418
419 void InitPlayerGfxAnimation(struct PlayerInfo *, int, int);
420 void Moving2Blocked(int, int, int *, int *);
421 void Blocked2Moving(int, int, int *, int *);
422 void DrawDynamite(int, int);
423
424 void StartGameActions(boolean, boolean, int);
425
426 void GameActions(void);
427 void GameActions_EM_Main(void);
428 void GameActions_SP_Main(void);
429 void GameActions_MM_Main(void);
430 void GameActions_RND_Main(void);
431 void GameActions_RND(void);
432
433 void ScrollLevel(int, int);
434
435 void InitPlayLevelSound(void);
436 void PlayLevelSound_EM(int, int, int, int);
437 void PlayLevelSound_SP(int, int, int, int);
438 void PlayLevelSound_MM(int, int, int, int);
439 void PlaySound_MM(int);
440 void PlaySoundLoop_MM(int);
441 void StopSound_MM(int);
442
443 void RaiseScore(int);
444 void RaiseScoreElement(int);
445
446 void RequestQuitGameExt(boolean, boolean, char *);
447 void RequestQuitGame(boolean);
448 void RequestRestartGame(char *);
449 void CheckGameOver(void);
450
451 boolean checkGameSolved(void);
452 boolean checkGameFailed(void);
453 boolean checkGameEnded(void);
454
455 unsigned int InitEngineRandom_RND(int);
456 unsigned int RND(int);
457
458 void FreeEngineSnapshotSingle(void);
459 void FreeEngineSnapshotList(void);
460 void LoadEngineSnapshotSingle(void);
461 void SaveEngineSnapshotSingle(void);
462 boolean CheckSaveEngineSnapshotToList(void);
463 void SaveEngineSnapshotToList(void);
464 void SaveEngineSnapshotToListInitial(void);
465 boolean CheckEngineSnapshotSingle(void);
466 boolean CheckEngineSnapshotList(void);
467
468 void CreateGameButtons(void);
469 void FreeGameButtons(void);
470 void MapUndoRedoButtons(void);
471 void UnmapUndoRedoButtons(void);
472 void ModifyPauseButtons(void);
473 void MapGameButtons(void);
474 void UnmapGameButtons(void);
475 void RedrawGameButtons(void);
476 void MapGameButtonsOnTape(void);
477 void UnmapGameButtonsOnTape(void);
478 void RedrawGameButtonsOnTape(void);
479
480 void HandleSoundButtonKeys(Key);
481
482 #endif