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