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