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