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 sound_music;
127   struct XY sound_loops;
128   struct XY sound_simple;
129
130   struct XY panel_stop;
131   struct XY panel_pause;
132   struct XY panel_play;
133
134   struct XY panel_sound_music;
135   struct XY panel_sound_loops;
136   struct XY panel_sound_simple;
137
138   struct XY touch_stop;
139   struct XY touch_pause;
140 };
141
142 struct GameSnapshotInfo
143 {
144   int mode;
145
146   byte last_action[MAX_PLAYERS];
147   boolean changed_action;
148   boolean collected_item;
149
150   boolean save_snapshot;
151 };
152
153 struct GameInfo
154 {
155   // values for control panel
156   struct GamePanelInfo panel;
157   struct GameButtonInfo button;
158
159   // values for graphics engine customization
160   int graphics_engine_version;
161   boolean use_native_emc_graphics_engine;
162   boolean use_native_sp_graphics_engine;
163   boolean use_masked_pushing;
164   boolean use_masked_elements;
165   int forced_scroll_delay_value;
166   int scroll_delay_value;
167   int tile_size;
168
169   // constant within running game
170   int engine_version;
171   int emulation;
172   int initial_move_delay[MAX_PLAYERS];
173   int initial_move_delay_value[MAX_PLAYERS];
174   int initial_push_delay_value;
175
176   // flag for single or multi-player mode (needed for playing tapes)
177   // (when playing/recording games, this is identical to "setup.team_mode"
178   boolean team_mode;
179
180   // flags to handle bugs in and changes between different engine versions
181   // (for the latest engine version, these flags should always be "FALSE")
182   boolean use_change_when_pushing_bug;
183   boolean use_block_last_field_bug;
184   boolean max_num_changes_per_frame;
185   boolean use_reverse_scan_direction;
186
187   // flags to indicate which game actions are used in this game
188   boolean use_key_actions;
189   boolean use_mouse_actions;
190
191   // variable within running game
192   int yamyam_content_nr;
193   boolean robot_wheel_active;
194   boolean magic_wall_active;
195   int magic_wall_time_left;
196   int light_time_left;
197   int timegate_time_left;
198   int belt_dir[4];
199   int belt_dir_nr[4];
200   int switchgate_pos;
201   int wind_direction;
202
203   boolean explosions_delayed;
204   boolean envelope_active;
205   boolean no_time_limit;        // (variable only in very special case)
206
207   int time_final;               // time (in seconds) or steps left or played
208   int score_time_final;         // time (in frames) or steps played
209
210   int score;
211   int score_final;
212
213   int health;
214   int health_final;
215
216   int gems_still_needed;
217   int sokoban_fields_still_needed;
218   int sokoban_objects_still_needed;
219   int lights_still_needed;
220   int players_still_needed;
221   int friends_still_needed;
222
223   int robot_wheel_x, robot_wheel_y;
224   int exit_x, exit_y;
225
226   boolean all_players_gone;
227
228   // values for the new EMC elements
229   int lenses_time_left;
230   int magnify_time_left;
231   boolean ball_active;
232   int ball_content_nr;
233
234   // values for player idle animation (no effect on engine)
235   int player_boring_delay_fixed;
236   int player_boring_delay_random;
237   int player_sleeping_delay_fixed;
238   int player_sleeping_delay_random;
239
240   // values for special game initialization control
241   boolean restart_level;
242
243   // trigger message to ask for restarting the game
244   char *restart_game_message;
245
246   // values for special request dialog control
247   boolean request_active;
248   boolean request_active_or_moving;
249
250   // values for special game control
251   int centered_player_nr;
252   int centered_player_nr_next;
253   boolean set_centered_player;
254   boolean set_centered_player_wrap;
255
256   // values for single step mode control
257   boolean enter_single_step_mode;
258
259   // values for random number generator initialization after snapshot
260   unsigned int num_random_calls;
261
262   // values for game engine snapshot control
263   struct GameSnapshotInfo snapshot;
264
265   // values for handling states for solved level and game over
266   boolean LevelSolved;
267   boolean GamePlayed;
268   boolean GameOver;
269
270   boolean LevelSolved_GameWon;
271   boolean LevelSolved_GameEnd;
272   boolean LevelSolved_SaveTape;
273   boolean LevelSolved_SaveScore;
274
275   int LevelSolved_CountingTime;
276   int LevelSolved_CountingScore;
277   int LevelSolved_CountingHealth;
278 };
279
280 struct PlayerInfo
281 {
282   boolean present;              // player present in level playfield
283   boolean connected_locally;    // player connected (locally)
284   boolean connected_network;    // player connected (network)
285   boolean connected;            // player connected (locally or via network)
286   boolean active;               // player present and connected
287   boolean mapped;               // player already mapped to input device
288
289   boolean killed;               // player maybe present/active, but killed
290   boolean reanimated;           // player maybe killed, but reanimated
291   boolean buried;               // player finally killed and removed
292
293   int index_nr;                 // player number (0 to 3)
294   int index_bit;                // player number bit (1 << 0 to 1 << 3)
295   int element_nr;               // element (EL_PLAYER_1 to EL_PLAYER_4)
296   int client_nr;                // network client identifier
297
298   byte action;                  // action from local input device
299   byte effective_action;        /* action acknowledged from network server
300                                    or summarized over all configured input
301                                    devices when in single player mode */
302   byte programmed_action;       /* action forced by game itself (like moving
303                                    through doors); overrides other actions */
304   byte snap_action;             // action from TAS snap keys
305
306   struct MouseActionInfo mouse_action;           // (used by MM engine only)
307   struct MouseActionInfo effective_mouse_action; // (used by MM engine only)
308
309   int jx, jy, last_jx, last_jy;
310   int MovDir, MovPos, GfxDir, GfxPos;
311   int Frame, StepFrame;
312
313   int GfxAction;
314
315   int initial_element;          // EL_PLAYER_1 to EL_PLAYER_4 or EL_SP_MURPHY
316   int artwork_element;
317   boolean use_murphy;
318
319   boolean block_last_field;
320   int block_delay_adjustment;   // needed for different engine versions
321
322   boolean can_fall_into_acid;
323
324   boolean gravity;
325
326   int last_move_dir;
327
328   boolean is_active;
329
330   boolean is_waiting;
331   boolean is_moving;
332   boolean is_auto_moving;
333   boolean is_digging;
334   boolean is_snapping;
335   boolean is_collecting;
336   boolean is_pushing;
337   boolean is_switching;
338   boolean is_dropping;
339   boolean is_dropping_pressed;
340
341   boolean is_bored;
342   boolean is_sleeping;
343
344   boolean was_waiting;
345   boolean was_moving;
346   boolean was_snapping;
347   boolean was_dropping;
348
349   boolean cannot_move;
350
351   boolean force_dropping;       // needed for single step mode
352
353   int frame_counter_bored;
354   int frame_counter_sleeping;
355
356   int anim_delay_counter;
357   int post_delay_counter;
358
359   int dir_waiting;
360   int action_waiting, last_action_waiting;
361   int special_action_bored;
362   int special_action_sleeping;
363
364   int num_special_action_bored;
365   int num_special_action_sleeping;
366
367   int switch_x, switch_y;
368   int drop_x, drop_y;
369
370   int show_envelope;
371
372   int move_delay;
373   int move_delay_value;
374   int move_delay_value_next;
375   int move_delay_reset_counter;
376
377   int push_delay;
378   int push_delay_value;
379
380   unsigned int actual_frame_counter;
381
382   int drop_delay;
383   int drop_pressed_delay;
384
385   int step_counter;
386
387   int key[MAX_NUM_KEYS];
388   int num_white_keys;
389   int dynabomb_count, dynabomb_size, dynabombs_left, dynabomb_xl;
390   int shield_normal_time_left;
391   int shield_deadly_time_left;
392
393   int last_removed_element;
394
395   int inventory_element[MAX_INVENTORY_SIZE];
396   int inventory_infinite_element;
397   int inventory_size;
398 };
399
400 extern struct GameInfo          game;
401 extern struct PlayerInfo        stored_player[MAX_PLAYERS], *local_player;
402
403
404 #ifdef DEBUG
405 void DEBUG_SetMaximumDynamite(void);
406 #endif
407
408 void GetPlayerConfig(void);
409 int GetElementFromGroupElement(int);
410
411 int getPlayerInventorySize(int);
412
413 void UpdateGameDoorValues(void);
414 void DrawGameDoorValues(void);
415
416 void UpdateAndDisplayGameControlValues(void);
417
418 void InitGameSound(void);
419 void InitGame(void);
420
421 void UpdateEngineValues(int, int, int, int);
422 void GameWon(void);
423 void GameEnd(void);
424
425 void MergeServerScore(void);
426
427 void InitPlayerGfxAnimation(struct PlayerInfo *, int, int);
428 void Moving2Blocked(int, int, int *, int *);
429 void Blocked2Moving(int, int, int *, int *);
430 void DrawDynamite(int, int);
431
432 void StartGameActions(boolean, boolean, int);
433
434 void GameActions(void);
435 void GameActions_EM_Main(void);
436 void GameActions_SP_Main(void);
437 void GameActions_MM_Main(void);
438 void GameActions_RND_Main(void);
439 void GameActions_RND(void);
440
441 void ScrollLevel(int, int);
442
443 void InitPlayLevelSound(void);
444 void PlayLevelSound_EM(int, int, int, int);
445 void PlayLevelSound_SP(int, int, int, int);
446 void PlayLevelSound_MM(int, int, int, int);
447 void PlaySound_MM(int);
448 void PlaySoundLoop_MM(int);
449 void StopSound_MM(int);
450
451 void RaiseScore(int);
452 void RaiseScoreElement(int);
453
454 void RequestQuitGameExt(boolean, boolean, char *);
455 void RequestQuitGame(boolean);
456 void RequestRestartGame(char *);
457 void CheckGameOver(void);
458
459 boolean checkGameSolved(void);
460 boolean checkGameFailed(void);
461 boolean checkGameEnded(void);
462
463 unsigned int InitEngineRandom_RND(int);
464 unsigned int RND(int);
465
466 void FreeEngineSnapshotSingle(void);
467 void FreeEngineSnapshotList(void);
468 void LoadEngineSnapshotSingle(void);
469 void SaveEngineSnapshotSingle(void);
470 boolean CheckSaveEngineSnapshotToList(void);
471 void SaveEngineSnapshotToList(void);
472 void SaveEngineSnapshotToListInitial(void);
473 boolean CheckEngineSnapshotSingle(void);
474 boolean CheckEngineSnapshotList(void);
475
476 void CreateGameButtons(void);
477 void FreeGameButtons(void);
478 void MapLoadSaveButtons(void);
479 void MapUndoRedoButtons(void);
480 void ModifyPauseButtons(void);
481 void MapGameButtons(void);
482 void UnmapGameButtons(void);
483 void RedrawGameButtons(void);
484 void MapGameButtonsOnTape(void);
485 void UnmapGameButtonsOnTape(void);
486 void RedrawGameButtonsOnTape(void);
487
488 void HandleSoundButtonKeys(Key);
489
490 #endif