fixed default graphics for growing or exploding BD engine elements
[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_needed;
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 no_level_time_limit;  // (variable only in very special case)
220   boolean time_limit;           // forced by levelset config or setup option
221
222   int time_final;               // time (in seconds) or steps left or played
223   int score_time_final;         // time (in frames) or steps played
224
225   int score;
226   int score_final;
227
228   int health;
229   int health_final;
230
231   int gems_still_needed;
232   int sokoban_fields_still_needed;
233   int sokoban_objects_still_needed;
234   int lights_still_needed;
235   int players_still_needed;
236   int friends_still_needed;
237
238   int robot_wheel_x, robot_wheel_y;
239   int exit_x, exit_y;
240
241   boolean all_players_gone;
242
243   // values for the new EMC elements
244   int lenses_time_left;
245   int magnify_time_left;
246   boolean ball_active;
247   int ball_content_nr;
248
249   // values for player idle animation (no effect on engine)
250   int player_boring_delay_fixed;
251   int player_boring_delay_random;
252   int player_sleeping_delay_fixed;
253   int player_sleeping_delay_random;
254
255   // values for special game initialization control
256   boolean restart_level;
257
258   // values for special request dialog control
259   boolean request_active;
260   boolean envelope_active;
261   boolean any_door_active;
262
263   // values for special game control
264   int centered_player_nr;
265   int centered_player_nr_next;
266   boolean set_centered_player;
267   boolean set_centered_player_wrap;
268
269   // values for single step mode control
270   boolean enter_single_step_mode;
271
272   // values for random number generator initialization after snapshot
273   unsigned int num_random_calls;
274
275   // values for game engine snapshot control
276   struct GameSnapshotInfo snapshot;
277
278   // values for handling states for solved level and game over
279   boolean LevelSolved;
280   boolean GamePlayed;
281   boolean GameOver;
282
283   boolean LevelSolved_GameWon;
284   boolean LevelSolved_GameEnd;
285   boolean LevelSolved_SaveTape;
286   boolean LevelSolved_SaveScore;
287
288   int LevelSolved_CountingTime;
289   int LevelSolved_CountingScore;
290   int LevelSolved_CountingHealth;
291
292   boolean RestartGameRequested;
293 };
294
295 struct PlayerInfo
296 {
297   boolean present;              // player present in level playfield
298   boolean connected_locally;    // player connected (locally)
299   boolean connected_network;    // player connected (network)
300   boolean connected;            // player connected (locally or via network)
301   boolean active;               // player present and connected
302   boolean mapped;               // player already mapped to input device
303
304   boolean killed;               // player maybe present/active, but killed
305   boolean reanimated;           // player maybe killed, but reanimated
306   boolean buried;               // player finally killed and removed
307
308   int index_nr;                 // player number (0 to 3)
309   int index_bit;                // player number bit (1 << 0 to 1 << 3)
310   int element_nr;               // element (EL_PLAYER_1 to EL_PLAYER_4)
311   int client_nr;                // network client identifier
312
313   byte action;                  // action from local input device
314   byte effective_action;        /* action acknowledged from network server
315                                    or summarized over all configured input
316                                    devices when in single player mode */
317   byte programmed_action;       /* action forced by game itself (like moving
318                                    through doors); overrides other actions */
319   byte snap_action;             // action from TAS snap keys
320
321   struct MouseActionInfo mouse_action;           // (used by MM engine only)
322   struct MouseActionInfo effective_mouse_action; // (used by MM engine only)
323
324   int jx, jy, last_jx, last_jy;
325   int MovDir, MovPos, GfxDir, GfxPos;
326   int Frame, StepFrame;
327
328   int GfxAction;
329
330   int initial_element;          // EL_PLAYER_1 to EL_PLAYER_4 or EL_SP_MURPHY
331   int artwork_element;
332   boolean use_murphy;
333
334   boolean block_last_field;
335   int block_delay_adjustment;   // needed for different engine versions
336
337   boolean can_fall_into_acid;
338
339   boolean gravity;
340
341   int last_move_dir;
342
343   boolean is_active;
344
345   boolean is_waiting;
346   boolean is_moving;
347   boolean is_auto_moving;
348   boolean is_digging;
349   boolean is_snapping;
350   boolean is_collecting;
351   boolean is_pushing;
352   boolean is_switching;
353   boolean is_dropping;
354   boolean is_dropping_pressed;
355
356   boolean is_bored;
357   boolean is_sleeping;
358
359   boolean was_waiting;
360   boolean was_moving;
361   boolean was_snapping;
362   boolean was_dropping;
363
364   boolean cannot_move;
365
366   boolean force_dropping;       // needed for single step mode
367
368   int frame_counter_bored;
369   int frame_counter_sleeping;
370
371   int anim_delay_counter;
372   int post_delay_counter;
373
374   int dir_waiting;
375   int action_waiting, last_action_waiting;
376   int special_action_bored;
377   int special_action_sleeping;
378
379   int num_special_action_bored;
380   int num_special_action_sleeping;
381
382   int switch_x, switch_y;
383   int drop_x, drop_y;
384
385   int show_envelope;
386
387   int move_delay;
388   int move_delay_value;
389   int move_delay_value_next;
390   int move_delay_reset_counter;
391
392   int push_delay;
393   int push_delay_value;
394
395   DelayCounter actual_frame_counter;
396
397   int drop_delay;
398   int drop_pressed_delay;
399
400   int step_counter;
401
402   int key[MAX_NUM_KEYS];
403   int num_white_keys;
404   int dynabomb_count, dynabomb_size, dynabombs_left, dynabomb_xl;
405   int shield_normal_time_left;
406   int shield_deadly_time_left;
407
408   int last_removed_element;
409
410   int inventory_element[MAX_INVENTORY_SIZE];
411   int inventory_infinite_element;
412   int inventory_size;
413 };
414
415 extern struct GameInfo          game;
416 extern struct PlayerInfo        stored_player[MAX_PLAYERS], *local_player;
417
418
419 #ifdef DEBUG
420 void DEBUG_SetMaximumDynamite(void);
421 #endif
422
423 void GetPlayerConfig(void);
424 int GetElementFromGroupElement(int);
425
426 int getPlayerInventorySize(int);
427
428 void UpdateGameDoorValues(void);
429 void DrawGameDoorValues(void);
430
431 void UpdateAndDisplayGameControlValues(void);
432
433 void InitGameSound(void);
434 void InitGame(void);
435
436 void UpdateEngineValues(int, int, int, int);
437 void GameWon(void);
438 void GameEnd(void);
439
440 void MergeServerScore(void);
441
442 void InitPlayerGfxAnimation(struct PlayerInfo *, int, int);
443
444 void Moving2Blocked(int, int, int *, int *);
445 void Blocked2Moving(int, int, int *, int *);
446
447 void DrawDynamite(int, int);
448
449 void StartGameActions(boolean, boolean, int);
450
451 void GameActions(void);
452 void GameActions_BD_Main(void);
453 void GameActions_EM_Main(void);
454 void GameActions_SP_Main(void);
455 void GameActions_MM_Main(void);
456 void GameActions_RND_Main(void);
457 void GameActions_RND(void);
458
459 void ScrollLevel(int, int);
460
461 void InitPlayLevelSound(void);
462 void PlayLevelSound_EM(int, int, int, int);
463 void PlayLevelSound_SP(int, int, int, int);
464 void PlayLevelSound_MM(int, int, int, int);
465 void PlaySound_MM(int);
466 void PlaySoundLoop_MM(int);
467 void StopSound_MM(int);
468
469 void RaiseScore(int);
470 void RaiseScoreElement(int);
471
472 void RequestQuitGameExt(boolean, boolean, char *);
473 void RequestQuitGame(boolean);
474
475 boolean CheckRestartGame(void);
476 boolean checkGameRunning(void);
477 boolean checkGamePlaying(void);
478 boolean checkGameSolved(void);
479 boolean checkGameFailed(void);
480 boolean checkGameEnded(void);
481 boolean checkRequestActive(void);
482
483 unsigned int InitEngineRandom_RND(int);
484 unsigned int RND(int);
485
486 void FreeEngineSnapshotSingle(void);
487 void FreeEngineSnapshotList(void);
488 void LoadEngineSnapshotSingle(void);
489 void SaveEngineSnapshotSingle(void);
490 boolean CheckSaveEngineSnapshotToList(void);
491 void SaveEngineSnapshotToList(void);
492 void SaveEngineSnapshotToListInitial(void);
493 boolean CheckEngineSnapshotSingle(void);
494 boolean CheckEngineSnapshotList(void);
495
496 void CreateGameButtons(void);
497 void FreeGameButtons(void);
498 void MapLoadSaveButtons(void);
499 void MapUndoRedoButtons(void);
500 void ModifyPauseButtons(void);
501 void MapGameButtons(void);
502 void UnmapGameButtons(void);
503 void RedrawGameButtons(void);
504 void MapGameButtonsOnTape(void);
505 void UnmapGameButtonsOnTape(void);
506 void RedrawGameButtonsOnTape(void);
507
508 void HandleSoundButtonKeys(Key);
509
510 #endif