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