added showing optional title screen for native BD cavesets
[rocksndiamonds.git] / src / game_bd / bd_cave.h
1 /*
2  * Copyright (c) 2007, 2008, 2009, Czirkos Zoltan <cirix@fw.hu>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #ifndef BD_CAVE_H
18 #define BD_CAVE_H
19
20 #include "bd_elements.h"
21 #include "bd_colors.h"
22 #include "bd_random.h"
23
24
25 // ============================================================================
26 // BIG STRUCT HANDLING
27 // ============================================================================
28
29 // possible types handled
30 typedef enum _gd_type
31 {
32   // not real types, only used by editor to build ui
33   GD_TAB,
34   GD_LABEL,
35
36   // gd types
37   GD_TYPE_STRING,               // static string, fixed array of characters
38   GD_TYPE_LONGSTRING,           // long string which has its own notebook page in the editor
39   GD_TYPE_INT,
40   GD_TYPE_RATIO,
41   GD_TYPE_ELEMENT,
42   GD_TYPE_BOOLEAN,
43   GD_TYPE_PROBABILITY,          // probabilities are stored in parts per million,
44                                 // ie. *1E6, converted to int.
45   GD_TYPE_COLOR,
46   GD_TYPE_EFFECT,
47   GD_TYPE_DIRECTION,
48   GD_TYPE_SCHEDULING,
49 } GdType;
50
51 enum _gd_property_flags
52 {
53   GD_ALWAYS_SAVE           = 1 << 0,
54   GD_DONT_SAVE             = 1 << 1,
55   GD_DONT_SHOW_IN_EDITOR   = 1 << 2,
56   GD_SHOW_LEVEL_LABEL      = 1 << 3,
57   GD_COMPATIBILITY_SETTING = 1 << 4,
58 };
59
60 typedef struct _gd_struct_descriptor
61 {
62   char *identifier;             // bdcff identifier
63   GdType type;                  // data type
64   int flags;                    // flags for bdcff saving/loading
65   char *name;                   // name in editor
66   int offset;                   // byte offset in a GdCave structure. use the CAVE_OFFSET macro
67   int count;                    // size of array; usually 1, for non-arrays.
68   char *tooltip;                // tooltip text in editor
69   int min, max;                 // integers have minimum and maximum
70 } GdStructDescriptor;
71
72 typedef struct _gd_property_default
73 {
74   int offset;                   // data offset (bytes) in a cave structure
75   int defval;                   // default value, converted to int. if type is a float, *1000000
76
77   int property_index;           // index in gd_cave_properties; created at runtime
78 } GdPropertyDefault;
79
80
81 void gd_struct_set_defaults_from_array(void *str, const GdStructDescriptor *properties, GdPropertyDefault *defaults);
82
83 // these define the number of the cells in the png file
84 #define GD_NUM_OF_CELLS_X       8
85 #define GD_NUM_OF_CELLS_Y       46
86
87 // +80: placeholder for cells which are rendered by the game;
88 // for example diamond + arrow = falling diamond
89 #define GD_NUM_OF_CELLS         (GD_NUM_OF_CELLS_X * GD_NUM_OF_CELLS_Y + 80)
90
91 // maximum replay size (maximum seconds x game cycles per second)
92 #define MAX_REPLAY_LEN          (10000 * FRAMES_PER_SECOND / 8)
93
94 extern const GdColor gd_flash_color;
95 extern const GdColor gd_select_color;
96
97 enum _element_property
98 {
99   E_P_SLOPED_LEFT,              // stones and diamonds roll down to left on this
100   E_P_SLOPED_RIGHT,             // stones and diamonds roll down to right on this
101   E_P_SLOPED_UP,
102   E_P_SLOPED_DOWN,
103   E_P_BLADDER_SLOPED,           // element act sloped also for the bladder
104
105   E_P_AMOEBA_CONSUMES,          // amoeba can eat this
106   E_P_DIRT,                     // it is dirt, or something similar (dirt2 or sloped dirt)
107   E_P_BLOWS_UP_FLIES,           // flies blow up, if they touch this
108   E_P_EXPLODES_BY_HIT,          // explodes if hit by a stone
109
110   E_P_EXPLOSION,                // set for every stage of every explosion.
111   E_P_EXPLOSION_FIRST_STAGE,    // set for first stage of every explosion.
112                                 // helps slower/faster explosions changing
113
114   E_P_NON_EXPLODABLE,           // selfexplaining
115   E_P_CCW,                      // this creature has a default counterclockwise
116                                 // rotation (for example, o_fire_1)
117   E_P_CAN_BE_HAMMERED,          // can be broken by pneumatic hammer
118   E_P_VISUAL_EFFECT,            // if the element can use a visual effect.
119                                 // used to check consistency of the code
120   E_P_PLAYER,                   // easier to find out if it is a player element
121   E_P_MOVED_BY_CONVEYOR_TOP,    // can be moved by conveyor belt
122   E_P_MOVED_BY_CONVEYOR_BOTTOM, // can be moved UNDER the conveyor belt
123
124   E_P_DIGGABLE,                 // can be digged
125   E_P_COLLECTIBLE,              // can be collected
126   E_P_PUSHABLE,                 // can be pushed
127   E_P_CAN_MOVE,                 // can move
128   E_P_CAN_FALL,                 // can fall
129 };
130
131 // properties
132 #define P_SLOPED_LEFT                   (1 << E_P_SLOPED_LEFT)
133 #define P_SLOPED_RIGHT                  (1 << E_P_SLOPED_RIGHT)
134 #define P_SLOPED_UP                     (1 << E_P_SLOPED_UP)
135 #define P_SLOPED_DOWN                   (1 << E_P_SLOPED_DOWN)
136
137 // flag to say "any direction"
138 #define P_SLOPED                        (P_SLOPED_LEFT  |               \
139                                          P_SLOPED_RIGHT |               \
140                                          P_SLOPED_UP    |               \
141                                          P_SLOPED_DOWN)
142
143 #define P_BLADDER_SLOPED                (1 << E_P_BLADDER_SLOPED)
144
145 #define P_AMOEBA_CONSUMES               (1 << E_P_AMOEBA_CONSUMES)
146 #define P_DIRT                          (1 << E_P_DIRT)
147 #define P_BLOWS_UP_FLIES                (1 << E_P_BLOWS_UP_FLIES)
148
149 #define P_EXPLODES_BY_HIT               (1 << E_P_EXPLODES_BY_HIT)
150 #define P_EXPLOSION                     (1 << E_P_EXPLOSION)
151 #define P_EXPLOSION_FIRST_STAGE         (1 << E_P_EXPLOSION_FIRST_STAGE)
152
153 #define P_NON_EXPLODABLE                (1 << E_P_NON_EXPLODABLE)
154 #define P_CCW                           (1 << E_P_CCW)
155 #define P_CAN_BE_HAMMERED               (1 << E_P_CAN_BE_HAMMERED)
156 #define P_VISUAL_EFFECT                 (1 << E_P_VISUAL_EFFECT)
157 #define P_PLAYER                        (1 << E_P_PLAYER)
158 #define P_MOVED_BY_CONVEYOR_TOP         (1 << E_P_MOVED_BY_CONVEYOR_TOP)
159 #define P_MOVED_BY_CONVEYOR_BOTTOM      (1 << E_P_MOVED_BY_CONVEYOR_BOTTOM)
160
161 #define P_DIGGABLE                      (1 << E_P_DIGGABLE)
162 #define P_COLLECTIBLE                   (1 << E_P_COLLECTIBLE)
163 #define P_PUSHABLE                      (1 << E_P_PUSHABLE)
164 #define P_CAN_MOVE                      (1 << E_P_CAN_MOVE)
165 #define P_CAN_FALL                      (1 << E_P_CAN_FALL)
166
167 // These are states of the magic wall.
168 typedef enum _magic_wall_state
169 {
170   GD_MW_DORMANT,                // Starting with this.
171   GD_MW_ACTIVE,                 // Boulder or diamond dropped into.
172   GD_MW_EXPIRED                 // Turned off after magic_wall_milling_time.
173 } GdMagicWallState;
174
175 // These are states of Player.
176 typedef enum _player_state
177 {
178   GD_PL_NOT_YET,                // Not yet living. Beginning of cave time.
179   GD_PL_LIVING,                 // Ok.
180   GD_PL_TIMEOUT,                // Time is up
181   GD_PL_DIED,                   // Died.
182   GD_PL_EXITED                  // Exited the cave, proceed to next one
183 } GdPlayerState;
184
185 // States of amoeba
186 typedef enum _amoeba_state
187 {
188   GD_AM_SLEEPING,               // sleeping - not yet let out.
189   GD_AM_AWAKE,                  // living, growing
190   GD_AM_TOO_BIG,                // grown too big, will convert to stones
191   GD_AM_ENCLOSED,               // enclosed, will convert to diamonds
192 } GdAmoebaState;
193
194 typedef enum _direction
195 {
196   // not moving
197   GD_MV_STILL           = 0,
198   GD_MV_THIS            = 0,
199
200   // directions
201   GD_MV_UP              = 1,
202   GD_MV_UP_RIGHT        = 2,
203   GD_MV_RIGHT           = 3,
204   GD_MV_DOWN_RIGHT      = 4,
205   GD_MV_DOWN            = 5,
206   GD_MV_DOWN_LEFT       = 6,
207   GD_MV_LEFT            = 7,
208   GD_MV_UP_LEFT         = 8,
209
210   // to be able to type GD_MV_TWICE + GD_MV_DOWN, for example
211   GD_MV_TWICE           = 8,
212
213   // directions * 2
214   GD_MV_UP_2            = 9,
215   GD_MV_UP_RIGHT_2      = 10,
216   GD_MV_RIGHT_2         = 11,
217   GD_MV_DOWN_RIGHT_2    = 12,
218   GD_MV_DOWN_2          = 13,
219   GD_MV_DOWN_LEFT_2     = 14,
220   GD_MV_LEFT_2          = 15,
221   GD_MV_UP_LEFT_2       = 16,
222
223   GD_MV_MAX,
224 } GdDirection;
225
226 enum
227 {
228   GD_REPLAY_MOVE_MASK    = 0x0f,
229   GD_REPLAY_FIRE_MASK    = 0x10,
230   GD_REPLAY_SUICIDE_MASK = 0x20,
231 };
232
233
234 // ELEMENTS DESCRIPTION
235 typedef struct _elements
236 {
237   GdElement element;            // element number. for example O_DIRT
238   char *name;                   // name in editor, for example "Dirt". some have
239                                 // different names than their real engine meaning!
240   unsigned int properties;      // engine properties, like P_SLOPED or P_EXPLODES
241   char *filename;               // name in bdcff file, like "DIRT"
242   char character;               // character representation in bdcff file, like '.'
243   int image;                    // image in editor (index in cells.png)
244   int image_simple;             // image in editor (index in cells.png) (simple view / combo box)
245   int image_game;               // image for game. negative if animated
246   int ckdelay;                  // ckdelay ratio - how much time required for a c64 to
247                                 // process this element - in microseconds.
248
249   char *lowercase_name;         // lowercase of translated name. for editor;
250                                 // generated inside the game.
251   char character_new;           // character given automatically for elements which
252                                 // don't have one defined in original bdcff description
253 } GdElements;
254
255
256 typedef char GdString[128];
257
258 typedef struct _highscore
259 {
260   GdString name;
261   int score;
262 } GdHighScore;
263
264 typedef struct _replay_movements
265 {
266   unsigned char data[MAX_REPLAY_LEN];
267   unsigned int len;
268 } GdReplayMovements;
269
270 // maximum seed value for the cave random generator. should be smaller than a signed int.
271 #define GD_CAVE_SEED_MAX        (1 << 30)
272
273 typedef struct _gd_cave_replay
274 {
275   int level;                    // replay for level n
276   unsigned int seed;            // seed the cave is to be rendered with
277   boolean saved;                // also store it in the saved bdcff
278   GdString recorded_with;       // recorded with - application name and version
279
280   GdString player_name;         // who played this
281   GdString date;                // when played
282   char *comment;                // some comments from the player
283
284   int score;                    // score collected
285   int duration;                 // number of seconds played
286   boolean success;              // successful playing of cave?
287   unsigned int checksum;        // checksum of the rendered cave.
288
289   boolean wrong_checksum;
290   GdReplayMovements *movements;
291   int current_playing_pos;
292 } GdReplay;
293
294 typedef enum _gd_scheduling
295 {
296   GD_SCHEDULING_MILLISECONDS,
297   GD_SCHEDULING_BD1,
298   GD_SCHEDULING_BD2,
299   GD_SCHEDULING_PLCK,
300   GD_SCHEDULING_CRDR,
301   GD_SCHEDULING_BD1_ATARI,
302   GD_SCHEDULING_BD2_PLCK_ATARI,
303   GD_SCHEDULING_MAX
304 } GdScheduling;
305
306 typedef struct _gd_c64_random_generator
307 {
308   int rand_seed_1, rand_seed_2;
309 } GdC64RandomGenerator;
310
311 // ----------------------------------------------------------------------------
312 // Structure holding all data belonging to a cave.
313 // ----------------------------------------------------------------------------
314
315 #define GD_HIGHSCORE_NUM 20
316
317 typedef struct _gd_cave
318 {
319   // Defined by the editor. public data :)
320   GdString name;                        // name of cave
321   GdString description;                 // some words about the cave
322   GdString author;                      // author
323   GdString difficulty;                  // difficulty of the game, for info purposes
324   GdString www;                         // link to author's webpage
325   GdString date;                        // date of creation
326   char *story;                          // story for the cave - will be shown when cave is played.
327   char *remark;                         // some note
328
329   GdString charset;                     // these are not used by gdash
330   GdString fontset;
331
332   // and this one the highscores
333   GdHighScore highscore[GD_HIGHSCORE_NUM];
334
335   HashTable *tags;                      // stores read-but-not-understood strings from bdcff,
336                                         // so we can save them later.
337
338   GdElement **map;                      // pointer to data for map, non-null if has a map
339   List *objects;
340   List *replays;
341
342   boolean intermission;                 // is this cave an intermission?
343   boolean intermission_instantlife;     // one life extra, if the intermission is reached
344   boolean intermission_rewardlife;      // one life extra, if the intermission is finished
345   boolean selectable;                   // is this selectable as an initial cave for a game?
346   boolean diagonal_movements;           // are diagonal movements allowed?
347   GdElement snap_element;               // snapping (press fire+move) usually leaves space behind,
348                                         // but can be other
349   boolean short_explosions;             // in >= 1stb, diamond/creature explosions were of 5 stages
350
351   GdScheduling scheduling;              // scheduling type; see above
352   boolean pal_timing;                   // use faster seconds
353
354   boolean active_is_first_found;        // active player is the uppermost.
355   boolean lineshift;                    // true is line shifting emulation,
356                                         // false is perfect borders emulation
357   boolean border_scan_first_and_last;   // if true, scans the first and last line of the border.
358                                         // false for plck
359   boolean wraparound_objects;           // if this is true, object drawing (cave rendering)
360                                         // will wraparound as well.
361
362   GdElement initial_fill;
363   GdElement initial_border;
364   GdElement random_fill[4];             // Random fill elements.
365   int random_fill_probability[4];       // Random fill, probability of each element.
366
367   int level_rand[5];                    // Random seed.
368   int level_diamonds[5];                // Must collect diamonds, on level x
369   int level_speed[5];                   // Time between game cycles in ms
370   int level_ckdelay[5];                 // Timing in original game units
371   int level_time[5];                    // Available time, per level
372   int level_timevalue[5];               // points for each second remaining, when exiting level
373
374   int max_time;                         // the maximum time in seconds. if above, it overflows
375
376   int w, h;                             // Sizes of cave, width and height.
377   int x1,y1,x2,y2;                      // Visible part of the cave
378   GdColor colorb;                       // border color
379   GdColor color0, color1, color2, color3, color4, color5;    // c64-style colors;
380                                                              // color 4 and 5 are amoeba and slime.
381
382   int diamond_value;                    // Score for a diamond.
383   int extra_diamond_value;              // Score for a diamond, when gate is open.
384
385   boolean stone_sound;
386   boolean nut_sound;
387   boolean diamond_sound;
388   boolean nitro_sound;
389   boolean falling_wall_sound;
390   boolean expanding_wall_sound;
391   boolean bladder_spender_sound;
392   boolean bladder_convert_sound;
393
394   int level_magic_wall_time[5];         // magic wall 'on' state for each level (seconds)
395   boolean magic_wall_stops_amoeba;      // Turning on magic wall changes amoeba to diamonds.
396                                         // Original BD: yes, constkit: no
397   boolean magic_timer_wait_for_hatching;// magic wall timer does not start before player's birth
398   boolean magic_wall_sound;             // magic wall has sound
399
400   int level_amoeba_time[5];             // amoeba time for each level
401   int amoeba_growth_prob;               // Amoeba slow growth probability
402   int amoeba_fast_growth_prob;          // Amoeba fast growth probability
403   int level_amoeba_threshold[5];        // amoeba turns to stones; if count is bigger than this
404                                         // (number of cells)
405   GdElement amoeba_enclosed_effect;     // an enclosed amoeba converts to this element
406   GdElement amoeba_too_big_effect;      // an amoeba grown too big converts to this element
407
408   int level_amoeba_2_time[5];           // amoeba time for each level
409   int amoeba_2_growth_prob;             // Amoeba slow growth probability
410   int amoeba_2_fast_growth_prob;        // Amoeba fast growth probability
411   int level_amoeba_2_threshold[5];      // amoeba turns to stones; if count is bigger than this
412                                         // (number of cells)
413   GdElement amoeba_2_enclosed_effect;   // an enclosed amoeba converts to this element
414   GdElement amoeba_2_too_big_effect;    // an amoeba grown too big converts to this element
415   boolean amoeba_2_explodes_by_amoeba;  // amoeba 2 will explode if touched by amoeba1
416   GdElement amoeba_2_explosion_effect;  // amoeba 2 explosion ends in ...
417   GdElement amoeba_2_looks_like;        // an amoeba 2 looks like this element
418
419   boolean amoeba_timer_started_immediately; // FALSE: amoeba will start life at the first
420                                             //        possibility of growing.
421   boolean amoeba_timer_wait_for_hatching;   // amoeba timer does not start before player's birth
422   boolean amoeba_sound;                 // if the living amoeba has sound.
423
424   GdElement acid_eats_this;             // acid eats this element
425   int acid_spread_ratio;                // Probability of acid blowing up, each frame
426   boolean acid_spread_sound;            // acid has sound
427   GdElement acid_turns_to;              // whether acid converts to explosion on spreading or other
428
429   GdElement nut_turns_to_when_crushed;  // when nut is hit by stone, it converts to this element
430
431   int level_slime_permeability[5];      // true random slime
432   int level_slime_permeability_c64[5];  // Appearing in bd 2
433   int level_slime_seed_c64[5];          // predictable slime random seed
434   boolean slime_predictable;            // predictable random start for slime. yes for plck.
435   GdElement slime_eats_1, slime_converts_1; // slime eats element x and converts to element x;
436                                             // for example diamond -> falling diamond
437   GdElement slime_eats_2, slime_converts_2; // this is usually stone -> stone_f
438   GdElement slime_eats_3, slime_converts_3; // this is usually nut -> nut_f
439   boolean slime_sound;                  // slime has sound
440
441   boolean lava_sound;                   // elements sinking in lava have sound
442
443   int level_hatching_delay_frame[5];    // Scan frames before Player's birth.
444   int level_hatching_delay_time[5];     // Scan frames before Player's birth.
445
446   int level_bonus_time[5];              // bonus time for clock collected.
447   int level_penalty_time[5];            // Time penalty when voodoo destroyed.
448   boolean voodoo_collects_diamonds;     // Voodoo can collect diamonds
449   boolean voodoo_dies_by_stone;         // Voodoo can be killed by a falling stone
450   boolean voodoo_disappear_in_explosion;// Voodoo can be destroyed by and explosion
451   boolean voodoo_any_hurt_kills_player; // If any voodoo hurt in any way, player is killed.
452
453   boolean water_does_not_flow_down;     // if true, water will not grow downwards,
454                                         // only in other directions.
455   boolean water_sound;                  // water has sound
456
457   boolean bladder_sound;                // bladder moving and pushing has sound
458   GdElement bladder_converts_by;        // bladder converts to clock by touching this element
459
460   int biter_delay_frame;                // frame count biters do move
461   GdElement biter_eat;                  // biters eat this
462   boolean biter_sound;                  // biters have sound
463
464   boolean expanding_wall_changed;       // expanding wall direction is changed
465
466   int    replicator_delay_frame;        // replicator delay in frames (number of frames
467                                         // to wait between creating a new element)
468   boolean replicators_active;           // replicators are active.
469   boolean replicator_sound;             // when replicating an element, play sound or not.
470
471   boolean conveyor_belts_active;
472   boolean conveyor_belts_direction_changed;
473
474   // effects
475   GdElement explosion_effect;           // explosion converts to this element after its last stage.
476                                         // diego effect.
477   GdElement diamond_birth_effect;       // a diamond birth converts to this element after its last
478                                         // stage. diego effect.
479   GdElement bomb_explosion_effect;      // bombs explode to this element. diego effect (almost).
480   GdElement nitro_explosion_effect;     // nitros explode to this
481
482   GdElement firefly_explode_to;         // fireflies explode to this when hit by stone
483   GdElement alt_firefly_explode_to;     // alternative fireflies explode to this when hit by stone
484   GdElement butterfly_explode_to;       // butterflies explode to this when hit by stone
485   GdElement alt_butterfly_explode_to;   // alternative butterflies explode to this when hit by stone
486   GdElement stonefly_explode_to;        // stoneflies explode to this when hit by stone
487   GdElement dragonfly_explode_to;       // dragonflies explode to this when hit by stone
488
489   GdElement stone_falling_effect;       // falling stone converts to this element. diego effect.
490   GdElement diamond_falling_effect;     // falling diamond converts to this element. diego effect.
491   GdElement stone_bouncing_effect;      // bouncing stone converts to this element. diego effect.
492   GdElement diamond_bouncing_effect;    // bouncing diamond converts to this element. diego effect.
493
494   GdElement expanding_wall_looks_like;  // an expanding wall looks like this element. diego effect.
495   GdElement dirt_looks_like;            // dirt looks like this element. diego effect.
496
497   GdElement magic_stone_to;             // magic wall converts falling stone to
498   GdElement magic_diamond_to;           // magic wall converts falling diamond to
499   GdElement magic_mega_stone_to;        // magic wall converts a falling mega stone to
500   GdElement magic_nitro_pack_to;        // magic wall converts a falling nitro pack to
501   GdElement magic_nut_to;               // magic wall converts a falling nut to
502   GdElement magic_flying_stone_to;      // flying stones are converted to
503   GdElement magic_flying_diamond_to;    // flying diamonds are converted to
504
505   int pushing_stone_prob;               // probability of pushing stone
506   int pushing_stone_prob_sweet;         // probability of pushing, after eating sweet
507   boolean mega_stones_pushable_with_sweet; // mega stones may be pushed with sweet
508
509   boolean creatures_backwards;          // creatures changed direction
510   boolean creatures_direction_auto_change_on_start; // the change occurs also at the start signal
511   int creatures_direction_auto_change_time; // creatures automatically change direction every x
512                                             // seconds
513   boolean creature_direction_auto_change_sound; // automatically changing creature direction may
514                                                 // have the sound of the creature dir switch
515
516   int skeletons_needed_for_pot;         // how many skeletons to be collected, to use a pot
517   int skeletons_worth_diamonds;         // for crazy dream 7 compatibility: collecting skeletons
518                                         // might open the cave door.
519
520   GdDirection gravity;
521   int gravity_change_time;
522   boolean gravity_change_sound;
523   boolean gravity_affects_all;          // if true, gravity also affects falling wall, bladder
524                                         // and waiting stones
525   boolean gravity_switch_active;        // true if gravity switch is activated, and can be used.
526
527   boolean hammered_walls_reappear;
528   int pneumatic_hammer_frame;
529   int hammered_wall_reappear_frame;
530   boolean pneumatic_hammer_sound;
531
532   // internal variables, used during the game. private data :)
533
534   // returns range corrected x/y position (points to perfect or line shifting get function)
535   int (*getx) (const struct _gd_cave*, int x, int y);
536   int (*gety) (const struct _gd_cave*, int x, int y);
537
538   // returns pointer to element at x, y (points to perfect border or a line shifting get function)
539   GdElement* (*getp) (const struct _gd_cave*, int x, int y);
540
541   boolean hatched;                      // hatching has happened. (timers may run, ...)
542   boolean gate_open;                    // self-explaining
543   unsigned int render_seed;             // the seed value, which was used to render the cave,
544                                         // is saved here. will be used by record&playback
545   GdRand *random;                       // random number generator of rendered cave
546   int rendered;                         // if not zero, rendered at level x
547   int timing_factor;                    // number of "milliseconds" in each second :)
548                                         // 1000 for ntsc, 1200 for pal.
549   void ***objects_order;                // two-dimensional map of cave; each cell is a pointer
550                                         // to the drawing object, which created this element.
551                                         // NULL if map or random.
552   int **hammered_reappear;              // integer map of cave; if non-zero, a brick wall will
553                                         // appear there
554
555   int speed;                            // Time between game cycles in ms
556   int c64_timing;                       // a ckdelay value for the level this cave is rendered for
557   int ckdelay;                          // ckdelay value for the current iteration
558   int ckdelay_extra_for_animation;      // bd1 and similar engines had animation bits in cave data,
559                                         // to set which elements to animate (firefly, butterfly,
560                                         // amoeba).
561                                         // animating an element also caused some delay each frame;
562                                         //  according to my measurements, around 2.6 ms/element.
563
564   int frame;  // XXX
565
566   int hatching_delay_frame;
567   int hatching_delay_time;
568   int time_bonus;                       // bonus time for clock collected.
569   int time_penalty;                     // Time penalty when voodoo destroyed.
570   int time;                             // milliseconds remaining to finish cave
571   int timevalue;                        // points for remaining seconds - for current level
572   int diamonds_needed;                  // diamonds needed to open outbox
573   int diamonds_collected;               // diamonds collected
574   int skeletons_collected;              // number of skeletons collected
575   int gate_open_flash;                  // flashing of screen when gate opens
576   int score;                            // Score got this frame.
577   int amoeba_time;                      // Amoeba growing slow (low probability, default 3%) for
578                                         // milliseconds. After that, fast growth default (25%)
579   int amoeba_2_time;                    // Amoeba growing slow (low probability, default 3%) for
580                                         // milliseconds. After that, fast growth default (25%)
581   int amoeba_max_count;                 // selected amoeba 1 threshold for this level
582   int amoeba_2_max_count;               // selected amoeba 2 threshold for this level
583   GdAmoebaState amoeba_state;           // state of amoeba 1
584   GdAmoebaState amoeba_2_state;         // state of amoeba 2
585   int magic_wall_time;                  // magic wall 'on' state for seconds
586   int slime_permeability;               // true random slime
587   int slime_permeability_c64;           // Appearing in bd 2
588   GdMagicWallState magic_wall_state;    // State of magic wall
589   GdPlayerState player_state;           // Player state. not yet living, living, exited...
590   int player_seen_ago;                  // player was seen this number of scans ago
591   boolean voodoo_touched;               // as its name says
592   boolean kill_player;                  // Voodoo died, or used pressed escape to restart level.
593   boolean sweet_eaten;                  // player ate sweet, he's strong. prob_sweet applies,
594                                         // and also able to push chasing stones
595   int player_x, player_y;               // Coordinates of player (for scrolling)
596   int px[16], py[16];                   // coordinates of player, for chasing stone
597   int key1, key2, key3;                 // The player is holding this number of keys of each color
598   boolean diamond_key_collected;        // Key collected, so trapped diamonds convert to diamonds
599   boolean inbox_flash_toggle;           // negated every scan. helps drawing inboxes, and making
600                                         // players be born at different times.
601   GdDirection last_direction;           // last direction player moved. used by draw routines
602   GdDirection last_horizontal_direction;
603   int biters_wait_frame;                // number of frames to wait until biters will move again
604   int replicators_wait_frame;           // number of frames to wait until replicators are
605                                         // activated again
606   int creatures_direction_will_change;  // creatures automatically change direction every x seconds
607   GdC64RandomGenerator c64_rand;        // used for predictable random generator during the game.
608
609   int gravity_will_change;              // gravity will change in this number of milliseconds
610   boolean gravity_disabled;             // when player is stirring the pot, there is no gravity.
611   GdDirection gravity_next_direction;   // next direction when the gravity changes.
612                                         // will be set by the player "getting" a gravity switch
613   boolean got_pneumatic_hammer;         // true if the player has a pneumatic hammer
614   int pneumatic_hammer_active_delay;    // number of frames to wait, till pneumatic hammer will
615                                         // destroy the wall
616   GdSound sound1, sound2, sound3;       // sound set for 3 channels after each iteration
617 } GdCave;
618
619
620 #define CAVE_OFFSET(property) (STRUCT_OFFSET(GdCave, property))
621
622 // arrays for movements
623 // also no1 and bd2 cave data import helpers; line direction coordinates
624 extern const int gd_dx[], gd_dy[];
625
626 extern GdElement gd_char_to_element[];
627
628 void gd_create_char_to_element_table(void);
629 GdElement gd_get_element_from_character(unsigned char character);
630 GdElement gd_get_element_from_string(const char *string);
631
632 // init cave engine
633 void gd_cave_init(void);
634
635 // for cave tags hash table
636 int gd_str_case_equal(void *s1, void *s2);
637 unsigned int gd_str_case_hash(void *v);
638
639 // cave highscore functions
640 int gd_highscore_compare(const void *a, const void *b);
641 boolean gd_is_highscore(GdHighScore *scores, int score);
642 int gd_add_highscore(GdHighScore *highscores, const char *name, int score);
643 void gd_clear_highscore(GdHighScore *hs);
644 boolean gd_has_highscore(GdHighScore *hs);
645
646 // cave creator and destructor functions
647 GdCave *gd_cave_new(void);
648 GdCave *gd_cave_new_from_cave(const GdCave *orig);
649 void gd_cave_copy(GdCave *dest, const GdCave *src);
650 void gd_cave_free(GdCave *cave);
651
652 // cave manipulation
653 void gd_cave_set_gdash_defaults(GdCave *cave);
654 void gd_cave_set_defaults_from_array(GdCave* cave, GdPropertyDefault *defaults);
655 void gd_cave_correct_visible_size(GdCave *cave);
656 void gd_cave_auto_shrink(GdCave *cave);
657
658 void gd_cave_setup_for_game(GdCave *cave);
659 void gd_cave_count_diamonds(GdCave *cave);
660
661 // c64 random generator support for cave fill
662 unsigned int gd_c64_random(GdC64RandomGenerator *rand);
663 unsigned int gd_cave_c64_random(GdCave *);
664 void gd_c64_random_set_seed(GdC64RandomGenerator *rand, int seed1, int seed2);
665 void gd_cave_c64_random_set_seed(GdCave *cave, int seed1, int seed2);
666 void gd_cave_set_random_c64_colors(GdCave *cave);
667
668 // support
669 void *gd_cave_map_new_for_cave(const GdCave *cave, const int cell_size);
670 void *gd_cave_map_dup_size(const GdCave * cave, const void *map, const int cell_size);
671 #define gd_cave_map_new(CAVE, TYPE) ((TYPE **)gd_cave_map_new_for_cave((CAVE), sizeof(TYPE)))
672 #define gd_cave_map_dup(CAVE, MAP) ((void *)gd_cave_map_dup_size((CAVE), (void **)(CAVE)->MAP, sizeof((CAVE)->MAP[0][0])))
673 void gd_cave_map_free(void *map);
674
675 void gd_cave_store_rc(GdCave * cave, int x, int y, const GdElement element, const void* order);
676 GdElement gd_cave_get_rc (const GdCave *cave, int x, int y);
677
678 // direction
679 const char *gd_direction_get_visible_name(GdDirection dir);
680 const char *gd_direction_get_filename(GdDirection dir);
681 GdDirection gd_direction_from_string(const char *str);
682
683 // scheduling
684 const char *gd_scheduling_get_visible_name(GdScheduling sched);
685 const char *gd_scheduling_get_filename(GdScheduling sched);
686 GdScheduling gd_scheduling_from_string(const char *str);
687
688 // game playing helpers
689 #define GD_REDRAW (1 << 10)
690
691 void gd_drawcave_game(const GdCave *cave, int **element_buffer, int **gfx_buffer,
692                       boolean bonus_life_flash, int animcycle, boolean hate_invisible_outbox);
693
694 // function to copy a GdString
695 static inline char *gd_strcpy(GdString dest, const GdString src)
696 {
697     return strncpy(dest, src, sizeof(GdString));
698 }
699
700 int gd_cave_time_show(const GdCave *cave, int internal_time);
701
702 GdReplay *gd_replay_new(void);
703 GdReplay *gd_replay_new_from_replay(GdReplay *orig);
704 void gd_replay_free(GdReplay *replay);
705 void gd_replay_store_movement(GdReplay *replay, GdDirection player_move, boolean player_fire, boolean suicide);
706
707 unsigned int gd_cave_adler_checksum(GdCave *cave);
708 void gd_cave_adler_checksum_more(GdCave *cave, unsigned int *a, unsigned int *b);
709
710 #endif  // BD_CAVE_H