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