2f21455f8cfe65e2470a006ed6f26afd5c5a637d
[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 STD_NUM_KEYS                    4
21 #define MAX_NUM_KEYS                    8
22
23 #define NUM_BELTS                       4
24 #define NUM_BELT_PARTS                  3
25
26 #define NUM_PANEL_INVENTORY             8
27 #define NUM_PANEL_GRAPHICS              8
28 #define NUM_PANEL_ELEMENTS              8
29 #define NUM_PANEL_CE_SCORE              8
30
31 #define STR_SNAPSHOT_MODE_OFF           "off"
32 #define STR_SNAPSHOT_MODE_EVERY_STEP    "every_step"
33 #define STR_SNAPSHOT_MODE_EVERY_MOVE    "every_move"
34 #define STR_SNAPSHOT_MODE_EVERY_COLLECT "every_collect"
35 #define STR_SNAPSHOT_MODE_DEFAULT       STR_SNAPSHOT_MODE_OFF
36
37 #define SNAPSHOT_MODE_OFF               0
38 #define SNAPSHOT_MODE_EVERY_STEP        1
39 #define SNAPSHOT_MODE_EVERY_MOVE        2
40 #define SNAPSHOT_MODE_EVERY_COLLECT     3
41 #define SNAPSHOT_MODE_DEFAULT           SNAPSHOT_MODE_OFF
42
43
44 struct GamePanelInfo
45 {
46   struct TextPosInfo level_number;
47   struct TextPosInfo gems;
48   struct TextPosInfo inventory_count;
49   struct TextPosInfo inventory_first[NUM_PANEL_INVENTORY];
50   struct TextPosInfo inventory_last[NUM_PANEL_INVENTORY];
51   struct TextPosInfo key[MAX_NUM_KEYS];
52   struct TextPosInfo key_white;
53   struct TextPosInfo key_white_count;
54   struct TextPosInfo score;
55   struct TextPosInfo highscore;
56   struct TextPosInfo time;
57   struct TextPosInfo time_hh;
58   struct TextPosInfo time_mm;
59   struct TextPosInfo time_ss;
60   struct TextPosInfo frame;
61   struct TextPosInfo shield_normal;
62   struct TextPosInfo shield_normal_time;
63   struct TextPosInfo shield_deadly;
64   struct TextPosInfo shield_deadly_time;
65   struct TextPosInfo exit;
66   struct TextPosInfo emc_magic_ball;
67   struct TextPosInfo emc_magic_ball_switch;
68   struct TextPosInfo light_switch;
69   struct TextPosInfo light_switch_time;
70   struct TextPosInfo timegate_switch;
71   struct TextPosInfo timegate_switch_time;
72   struct TextPosInfo switchgate_switch;
73   struct TextPosInfo emc_lenses;
74   struct TextPosInfo emc_lenses_time;
75   struct TextPosInfo emc_magnifier;
76   struct TextPosInfo emc_magnifier_time;
77   struct TextPosInfo balloon_switch;
78   struct TextPosInfo dynabomb_number;
79   struct TextPosInfo dynabomb_size;
80   struct TextPosInfo dynabomb_power;
81   struct TextPosInfo penguins;
82   struct TextPosInfo sokoban_objects;
83   struct TextPosInfo sokoban_fields;
84   struct TextPosInfo robot_wheel;
85   struct TextPosInfo conveyor_belt[NUM_BELTS];
86   struct TextPosInfo conveyor_belt_switch[NUM_BELTS];
87   struct TextPosInfo magic_wall;
88   struct TextPosInfo magic_wall_time;
89   struct TextPosInfo gravity_state;
90   struct TextPosInfo graphic[NUM_PANEL_GRAPHICS];
91   struct TextPosInfo element[NUM_PANEL_ELEMENTS];
92   struct TextPosInfo element_count[NUM_PANEL_ELEMENTS];
93   struct TextPosInfo ce_score[NUM_PANEL_CE_SCORE];
94   struct TextPosInfo ce_score_element[NUM_PANEL_CE_SCORE];
95   struct TextPosInfo player_name;
96   struct TextPosInfo level_name;
97   struct TextPosInfo level_author;
98 };
99
100 struct GameButtonInfo
101 {
102   struct XY stop;
103   struct XY pause;
104   struct XY play;
105
106   struct XY undo;
107   struct XY redo;
108
109   struct XY save;
110   struct XY pause2;
111   struct XY load;
112
113   struct XY sound_music;
114   struct XY sound_loops;
115   struct XY sound_simple;
116 };
117
118 struct GameSnapshotInfo
119 {
120   int mode;
121
122   byte last_action[MAX_PLAYERS];
123   boolean changed_action;
124   boolean collected_item;
125
126   boolean save_snapshot;
127 };
128
129 struct GameInfo
130 {
131   /* values for control panel */
132   struct GamePanelInfo panel;
133   struct GameButtonInfo button;
134
135   /* values for graphics engine customization */
136   int graphics_engine_version;
137   boolean use_native_emc_graphics_engine;
138   boolean use_native_sp_graphics_engine;
139   boolean use_masked_pushing;
140   int forced_scroll_delay_value;
141   int scroll_delay_value;
142   int tile_size;
143
144   /* values for engine initialization */
145   int default_push_delay_fixed;
146   int default_push_delay_random;
147
148   /* constant within running game */
149   int engine_version;
150   int emulation;
151   int initial_move_delay[MAX_PLAYERS];
152   int initial_move_delay_value[MAX_PLAYERS];
153   int initial_push_delay_value;
154
155   /* flag for single or multi-player mode (needed for playing tapes) */
156   /* (when playing/recording games, this is identical to "setup.team_mode" */
157   boolean team_mode;
158
159   /* flags to handle bugs in and changes between different engine versions */
160   /* (for the latest engine version, these flags should always be "FALSE") */
161   boolean use_change_when_pushing_bug;
162   boolean use_block_last_field_bug;
163   boolean max_num_changes_per_frame;
164   boolean use_reverse_scan_direction;
165
166   /* variable within running game */
167   int yamyam_content_nr;
168   boolean robot_wheel_active;
169   boolean magic_wall_active;
170   int magic_wall_time_left;
171   int light_time_left;
172   int timegate_time_left;
173   int belt_dir[4];
174   int belt_dir_nr[4];
175   int switchgate_pos;
176   int wind_direction;
177   boolean gravity;
178   boolean explosions_delayed;
179   boolean envelope_active;
180   boolean no_time_limit;        /* (variable only in very special case) */
181
182   /* values for the new EMC elements */
183   int lenses_time_left;
184   int magnify_time_left;
185   boolean ball_state;
186   int ball_content_nr;
187
188   /* values for player idle animation (no effect on engine) */
189   int player_boring_delay_fixed;
190   int player_boring_delay_random;
191   int player_sleeping_delay_fixed;
192   int player_sleeping_delay_random;
193
194   /* values for special game initialization control */
195   boolean restart_level;
196
197   /* values for special game control */
198   int centered_player_nr;
199   int centered_player_nr_next;
200   boolean set_centered_player;
201
202   /* values for random number generator initialization after snapshot */
203   unsigned int num_random_calls;
204
205   /* values for game engine snapshot control */
206   struct GameSnapshotInfo snapshot;
207 };
208
209 struct PlayerInfo
210 {
211   boolean present;              /* player present in level playfield */
212   boolean connected;            /* player connected (locally or via network) */
213   boolean active;               /* player present and connected */
214   boolean mapped;               /* player already mapped to input device */
215
216   boolean killed;               /* player maybe present/active, but killed */
217   boolean reanimated;           /* player maybe killed, but reanimated */
218
219   int index_nr;                 /* player number (0 to 3) */
220   int index_bit;                /* player number bit (1 << 0 to 1 << 3) */
221   int element_nr;               /* element (EL_PLAYER_1 to EL_PLAYER_4) */
222   int client_nr;                /* network client identifier */
223
224   byte action;                  /* action from local input device */
225   byte mapped_action;           /* action mapped from device to player */
226   byte effective_action;        /* action acknowledged from network server
227                                    or summarized over all configured input
228                                    devices when in single player mode */
229   byte programmed_action;       /* action forced by game itself (like moving
230                                    through doors); overrides other actions */
231
232   int jx, jy, last_jx, last_jy;
233   int MovDir, MovPos, GfxDir, GfxPos;
234   int Frame, StepFrame;
235
236   int GfxAction;
237
238   int initial_element;          /* EL_PLAYER_1 to EL_PLAYER_4 or EL_SP_MURPHY */
239   int artwork_element;
240   boolean use_murphy;
241
242   boolean block_last_field;
243   int block_delay_adjustment;   /* needed for different engine versions */
244
245   boolean can_fall_into_acid;
246
247   boolean gravity;
248
249   boolean LevelSolved, GameOver;
250
251   boolean LevelSolved_GameWon;
252   boolean LevelSolved_GameEnd;
253   boolean LevelSolved_PanelOff;
254   boolean LevelSolved_SaveTape;
255   boolean LevelSolved_SaveScore;
256   int LevelSolved_CountingTime;
257   int LevelSolved_CountingScore;
258
259   int last_move_dir;
260
261   boolean is_active;
262
263   boolean is_waiting;
264   boolean is_moving;
265   boolean is_auto_moving;
266   boolean is_digging;
267   boolean is_snapping;
268   boolean is_collecting;
269   boolean is_pushing;
270   boolean is_switching;
271   boolean is_dropping;
272   boolean is_dropping_pressed;
273
274   boolean is_bored;
275   boolean is_sleeping;
276
277   boolean was_waiting;
278   boolean was_moving;
279   boolean was_snapping;
280   boolean was_dropping;
281
282   boolean cannot_move;
283
284   int frame_counter_bored;
285   int frame_counter_sleeping;
286
287   int anim_delay_counter;
288   int post_delay_counter;
289
290   int dir_waiting;
291   int action_waiting, last_action_waiting;
292   int special_action_bored;
293   int special_action_sleeping;
294
295   int num_special_action_bored;
296   int num_special_action_sleeping;
297
298   int switch_x, switch_y;
299   int drop_x, drop_y;
300
301   int show_envelope;
302
303   int move_delay;
304   int move_delay_value;
305   int move_delay_value_next;
306   int move_delay_reset_counter;
307
308   int push_delay;
309   int push_delay_value;
310
311   unsigned int actual_frame_counter;
312
313   int drop_delay;
314   int drop_pressed_delay;
315
316   int step_counter;
317
318   int score;
319   int score_final;
320
321   int gems_still_needed;
322   int sokobanfields_still_needed;
323   int lights_still_needed;
324   int friends_still_needed;
325   int key[MAX_NUM_KEYS];
326   int num_white_keys;
327   int dynabomb_count, dynabomb_size, dynabombs_left, dynabomb_xl;
328   int shield_normal_time_left;
329   int shield_deadly_time_left;
330
331   int inventory_element[MAX_INVENTORY_SIZE];
332   int inventory_infinite_element;
333   int inventory_size;
334 };
335
336 extern struct GameInfo          game;
337 extern struct PlayerInfo        stored_player[MAX_PLAYERS], *local_player;
338
339
340 #ifdef DEBUG
341 void DEBUG_SetMaximumDynamite();
342 #endif
343
344 void GetPlayerConfig(void);
345 int GetElementFromGroupElement(int);
346
347 void DrawGameValue_Time(int);
348 void DrawGameDoorValues(void);
349
350 void UpdateAndDisplayGameControlValues();
351
352 void InitGameSound();
353 void InitGame();
354
355 void UpdateEngineValues(int, int);
356 void GameWon(void);
357 void GameEnd(void);
358
359 void InitPlayerGfxAnimation(struct PlayerInfo *, int, int);
360 void Moving2Blocked(int, int, int *, int *);
361 void Blocked2Moving(int, int, int *, int *);
362 void DrawDynamite(int, int);
363
364 void StartGameActions(boolean, boolean, int);
365
366 void GameActions(void);
367 void GameActions_EM_Main();
368 void GameActions_SP_Main();
369 void GameActions_RND_Main();
370 void GameActions_RND();
371
372 void ScrollLevel(int, int);
373
374 void InitPlayLevelSound();
375 void PlayLevelSound_EM(int, int, int, int);
376 void PlayLevelSound_SP(int, int, int, int);
377
378 void RaiseScore(int);
379 void RaiseScoreElement(int);
380
381 void RequestQuitGameExt(boolean, boolean, char *);
382 void RequestQuitGame(boolean);
383
384 unsigned int InitEngineRandom_RND(int);
385 unsigned int RND(int);
386
387 void FreeEngineSnapshotSingle();
388 void FreeEngineSnapshotList();
389 void LoadEngineSnapshotSingle();
390 void SaveEngineSnapshotSingle();
391 boolean CheckSaveEngineSnapshotToList();
392 void SaveEngineSnapshotToList();
393 void SaveEngineSnapshotToListInitial();
394 boolean CheckEngineSnapshotSingle();
395 boolean CheckEngineSnapshotList();
396
397 void CreateGameButtons();
398 void FreeGameButtons();
399 void MapUndoRedoButtons();
400 void UnmapUndoRedoButtons();
401 void MapGameButtons();
402 void UnmapGameButtons();
403 void RedrawGameButtons();
404
405 void HandleSoundButtonKeys(Key);
406
407 #endif