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