1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2006 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
19 #include "libgame/libgame.h"
27 #define CHUNK_ID_LEN 4 /* IFF style chunk id length */
28 #define CHUNK_SIZE_UNDEFINED 0 /* undefined chunk size == 0 */
29 #define CHUNK_SIZE_NONE -1 /* do not write chunk size */
31 #define LEVEL_CHUNK_NAME_SIZE MAX_LEVEL_NAME_LEN
32 #define LEVEL_CHUNK_AUTH_SIZE MAX_LEVEL_AUTHOR_LEN
34 #define LEVEL_CHUNK_VERS_SIZE 8 /* size of file version chunk */
35 #define LEVEL_CHUNK_DATE_SIZE 4 /* size of file date chunk */
36 #define LEVEL_CHUNK_HEAD_SIZE 80 /* size of level file header */
37 #define LEVEL_CHUNK_HEAD_UNUSED 0 /* unused level header bytes */
38 #define LEVEL_CHUNK_CNT2_SIZE 160 /* size of level CNT2 chunk */
39 #define LEVEL_CHUNK_CNT2_UNUSED 11 /* unused CNT2 chunk bytes */
40 #define LEVEL_CHUNK_CNT3_HEADER 16 /* size of level CNT3 header */
41 #define LEVEL_CHUNK_CNT3_UNUSED 10 /* unused CNT3 chunk bytes */
42 #define LEVEL_CPART_CUS3_SIZE 134 /* size of CUS3 chunk part */
43 #define LEVEL_CPART_CUS3_UNUSED 15 /* unused CUS3 bytes / part */
44 #define LEVEL_CHUNK_GRP1_SIZE 74 /* size of level GRP1 chunk */
46 /* (element number, number of change pages, change page number) */
47 #define LEVEL_CHUNK_CUSX_UNCHANGED (2 + (1 + 1) + (1 + 1))
49 /* (element number only) */
50 #define LEVEL_CHUNK_GRPX_UNCHANGED 2
51 #define LEVEL_CHUNK_NOTE_UNCHANGED 2
53 /* (nothing at all if unchanged) */
54 #define LEVEL_CHUNK_ELEM_UNCHANGED 0
56 #define TAPE_CHUNK_VERS_SIZE 8 /* size of file version chunk */
57 #define TAPE_CHUNK_HEAD_SIZE 20 /* size of tape file header */
58 #define TAPE_CHUNK_HEAD_UNUSED 3 /* unused tape header bytes */
60 #define LEVEL_CHUNK_CNT3_SIZE(x) (LEVEL_CHUNK_CNT3_HEADER + (x))
61 #define LEVEL_CHUNK_CUS3_SIZE(x) (2 + (x) * LEVEL_CPART_CUS3_SIZE)
62 #define LEVEL_CHUNK_CUS4_SIZE(x) (96 + (x) * 48)
64 /* file identifier strings */
65 #define LEVEL_COOKIE_TMPL "ROCKSNDIAMONDS_LEVEL_FILE_VERSION_x.x"
66 #define TAPE_COOKIE_TMPL "ROCKSNDIAMONDS_TAPE_FILE_VERSION_x.x"
67 #define SCORE_COOKIE "ROCKSNDIAMONDS_SCORE_FILE_VERSION_1.2"
69 /* values for deciding when (not) to save configuration data */
70 #define SAVE_CONF_NEVER 0
71 #define SAVE_CONF_ALWAYS 1
72 #define SAVE_CONF_WHEN_CHANGED -1
74 /* values for chunks using micro chunks */
75 #define CONF_MASK_1_BYTE 0x00
76 #define CONF_MASK_2_BYTE 0x40
77 #define CONF_MASK_4_BYTE 0x80
78 #define CONF_MASK_MULTI_BYTES 0xc0
80 #define CONF_MASK_BYTES 0xc0
81 #define CONF_MASK_TOKEN 0x3f
83 #define CONF_VALUE_1_BYTE(x) (CONF_MASK_1_BYTE | (x))
84 #define CONF_VALUE_2_BYTE(x) (CONF_MASK_2_BYTE | (x))
85 #define CONF_VALUE_4_BYTE(x) (CONF_MASK_4_BYTE | (x))
86 #define CONF_VALUE_MULTI_BYTES(x) (CONF_MASK_MULTI_BYTES | (x))
88 /* these definitions are just for convenience of use and readability */
89 #define CONF_VALUE_8_BIT(x) CONF_VALUE_1_BYTE(x)
90 #define CONF_VALUE_16_BIT(x) CONF_VALUE_2_BYTE(x)
91 #define CONF_VALUE_32_BIT(x) CONF_VALUE_4_BYTE(x)
92 #define CONF_VALUE_BYTES(x) CONF_VALUE_MULTI_BYTES(x)
94 #define CONF_VALUE_NUM_BYTES(x) ((x) == CONF_MASK_1_BYTE ? 1 : \
95 (x) == CONF_MASK_2_BYTE ? 2 : \
96 (x) == CONF_MASK_4_BYTE ? 4 : 0)
98 #define CONF_CONTENT_NUM_ELEMENTS (3 * 3)
99 #define CONF_CONTENT_NUM_BYTES (CONF_CONTENT_NUM_ELEMENTS * 2)
100 #define CONF_ELEMENT_NUM_BYTES (2)
102 #define CONF_ENTITY_NUM_BYTES(t) ((t) == TYPE_ELEMENT || \
103 (t) == TYPE_ELEMENT_LIST ? \
104 CONF_ELEMENT_NUM_BYTES : \
105 (t) == TYPE_CONTENT || \
106 (t) == TYPE_CONTENT_LIST ? \
107 CONF_CONTENT_NUM_BYTES : 1)
109 #define CONF_ELEMENT_BYTE_POS(i) ((i) * CONF_ELEMENT_NUM_BYTES)
110 #define CONF_ELEMENTS_ELEMENT(b,i) ((b[CONF_ELEMENT_BYTE_POS(i)] << 8) | \
111 (b[CONF_ELEMENT_BYTE_POS(i) + 1]))
113 #define CONF_CONTENT_ELEMENT_POS(c,x,y) ((c) * CONF_CONTENT_NUM_ELEMENTS + \
115 #define CONF_CONTENT_BYTE_POS(c,x,y) (CONF_CONTENT_ELEMENT_POS(c,x,y) * \
116 CONF_ELEMENT_NUM_BYTES)
117 #define CONF_CONTENTS_ELEMENT(b,c,x,y) ((b[CONF_CONTENT_BYTE_POS(c,x,y)]<< 8)|\
118 (b[CONF_CONTENT_BYTE_POS(c,x,y) + 1]))
120 /* temporary variables used to store pointers to structure members */
121 static struct LevelInfo li;
122 static struct ElementInfo xx_ei, yy_ei;
123 static struct ElementChangeInfo xx_change;
124 static struct ElementGroupInfo xx_group;
125 static struct EnvelopeInfo xx_envelope;
126 static unsigned int xx_event_bits[NUM_CE_BITFIELDS];
127 static char xx_default_description[MAX_ELEMENT_NAME_LEN + 1];
128 static int xx_num_contents;
129 static int xx_current_change_page;
130 static char xx_default_string_empty[1] = "";
131 static int xx_string_length_unused;
133 struct LevelFileConfigInfo
135 int element; /* element for which data is to be stored */
136 int save_type; /* save data always, never or when changed */
137 int data_type; /* data type (used internally, not stored) */
138 int conf_type; /* micro chunk identifier (stored in file) */
141 void *value; /* variable that holds the data to be stored */
142 int default_value; /* initial default value for this variable */
145 void *value_copy; /* variable that holds the data to be copied */
146 void *num_entities; /* number of entities for multi-byte data */
147 int default_num_entities; /* default number of entities for this data */
148 int max_num_entities; /* maximal number of entities for this data */
149 char *default_string; /* optional default string for string data */
152 static struct LevelFileConfigInfo chunk_config_INFO[] =
154 /* ---------- values not related to single elements ----------------------- */
157 -1, SAVE_CONF_ALWAYS,
158 TYPE_INTEGER, CONF_VALUE_8_BIT(1),
159 &li.game_engine_type, GAME_ENGINE_TYPE_RND
163 -1, SAVE_CONF_ALWAYS,
164 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
165 &li.fieldx, STD_LEV_FIELDX
168 -1, SAVE_CONF_ALWAYS,
169 TYPE_INTEGER, CONF_VALUE_16_BIT(2),
170 &li.fieldy, STD_LEV_FIELDY
174 -1, SAVE_CONF_ALWAYS,
175 TYPE_INTEGER, CONF_VALUE_16_BIT(3),
180 -1, SAVE_CONF_ALWAYS,
181 TYPE_INTEGER, CONF_VALUE_16_BIT(4),
187 TYPE_INTEGER, CONF_VALUE_32_BIT(2),
193 TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
194 &li.use_step_counter, FALSE
199 TYPE_BITFIELD, CONF_VALUE_8_BIT(4),
200 &li.wind_direction_initial, MV_NONE
205 TYPE_BOOLEAN, CONF_VALUE_8_BIT(5),
206 &li.em_slippery_gems, FALSE
211 TYPE_BOOLEAN, CONF_VALUE_8_BIT(6),
212 &li.use_custom_template, FALSE
217 TYPE_BITFIELD, CONF_VALUE_32_BIT(1),
218 &li.can_move_into_acid_bits, ~0 /* default: everything can */
223 TYPE_BITFIELD, CONF_VALUE_8_BIT(7),
224 &li.dont_collide_with_bits, ~0 /* default: always deadly */
229 TYPE_BOOLEAN, CONF_VALUE_8_BIT(8),
230 &li.em_explodes_by_fire, FALSE
235 TYPE_INTEGER, CONF_VALUE_16_BIT(5),
236 &li.score[SC_TIME_BONUS], 1
246 static struct LevelFileConfigInfo chunk_config_ELEM[] =
248 /* (these values are the same for each player) */
251 TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
252 &li.block_last_field, FALSE /* default case for EM levels */
256 TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
257 &li.sp_block_last_field, TRUE /* default case for SP levels */
261 TYPE_BOOLEAN, CONF_VALUE_8_BIT(3),
262 &li.instant_relocation, FALSE
266 TYPE_BOOLEAN, CONF_VALUE_8_BIT(4),
267 &li.can_pass_to_walkable, FALSE
271 TYPE_BOOLEAN, CONF_VALUE_8_BIT(5),
272 &li.block_snap_field, TRUE
276 TYPE_BOOLEAN, CONF_VALUE_8_BIT(6),
277 &li.continuous_snapping, TRUE
281 TYPE_BOOLEAN, CONF_VALUE_8_BIT(12),
282 &li.shifted_relocation, FALSE
285 /* (these values are different for each player) */
288 TYPE_INTEGER, CONF_VALUE_8_BIT(7),
289 &li.initial_player_stepsize[0], STEPSIZE_NORMAL
293 TYPE_BOOLEAN, CONF_VALUE_8_BIT(8),
294 &li.initial_player_gravity[0], FALSE
298 TYPE_BOOLEAN, CONF_VALUE_8_BIT(9),
299 &li.use_start_element[0], FALSE
303 TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
304 &li.start_element[0], EL_PLAYER_1
308 TYPE_BOOLEAN, CONF_VALUE_8_BIT(10),
309 &li.use_artwork_element[0], FALSE
313 TYPE_ELEMENT, CONF_VALUE_16_BIT(2),
314 &li.artwork_element[0], EL_PLAYER_1
318 TYPE_BOOLEAN, CONF_VALUE_8_BIT(11),
319 &li.use_explosion_element[0], FALSE
323 TYPE_ELEMENT, CONF_VALUE_16_BIT(3),
324 &li.explosion_element[0], EL_PLAYER_1
328 TYPE_BOOLEAN, CONF_VALUE_8_BIT(13),
329 &li.use_initial_inventory[0], FALSE
333 TYPE_BOOLEAN, CONF_VALUE_8_BIT(14),
334 &li.initial_inventory_size[0], 1
338 TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(1),
339 &li.initial_inventory_content[0][0],EL_EMPTY, NULL,
340 &li.initial_inventory_size[0], 1, MAX_INITIAL_INVENTORY_SIZE
345 TYPE_INTEGER, CONF_VALUE_8_BIT(7),
346 &li.initial_player_stepsize[1], STEPSIZE_NORMAL
350 TYPE_BOOLEAN, CONF_VALUE_8_BIT(8),
351 &li.initial_player_gravity[1], FALSE
355 TYPE_BOOLEAN, CONF_VALUE_8_BIT(9),
356 &li.use_start_element[1], FALSE
360 TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
361 &li.start_element[1], EL_PLAYER_2
365 TYPE_BOOLEAN, CONF_VALUE_8_BIT(10),
366 &li.use_artwork_element[1], FALSE
370 TYPE_ELEMENT, CONF_VALUE_16_BIT(2),
371 &li.artwork_element[1], EL_PLAYER_2
375 TYPE_BOOLEAN, CONF_VALUE_8_BIT(11),
376 &li.use_explosion_element[1], FALSE
380 TYPE_ELEMENT, CONF_VALUE_16_BIT(3),
381 &li.explosion_element[1], EL_PLAYER_2
385 TYPE_BOOLEAN, CONF_VALUE_8_BIT(13),
386 &li.use_initial_inventory[1], FALSE
390 TYPE_BOOLEAN, CONF_VALUE_8_BIT(14),
391 &li.initial_inventory_size[1], 1
395 TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(1),
396 &li.initial_inventory_content[1][0],EL_EMPTY, NULL,
397 &li.initial_inventory_size[1], 1, MAX_INITIAL_INVENTORY_SIZE
402 TYPE_INTEGER, CONF_VALUE_8_BIT(7),
403 &li.initial_player_stepsize[2], STEPSIZE_NORMAL
407 TYPE_BOOLEAN, CONF_VALUE_8_BIT(8),
408 &li.initial_player_gravity[2], FALSE
412 TYPE_BOOLEAN, CONF_VALUE_8_BIT(9),
413 &li.use_start_element[2], FALSE
417 TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
418 &li.start_element[2], EL_PLAYER_3
422 TYPE_BOOLEAN, CONF_VALUE_8_BIT(10),
423 &li.use_artwork_element[2], FALSE
427 TYPE_ELEMENT, CONF_VALUE_16_BIT(2),
428 &li.artwork_element[2], EL_PLAYER_3
432 TYPE_BOOLEAN, CONF_VALUE_8_BIT(11),
433 &li.use_explosion_element[2], FALSE
437 TYPE_ELEMENT, CONF_VALUE_16_BIT(3),
438 &li.explosion_element[2], EL_PLAYER_3
442 TYPE_BOOLEAN, CONF_VALUE_8_BIT(13),
443 &li.use_initial_inventory[2], FALSE
447 TYPE_BOOLEAN, CONF_VALUE_8_BIT(14),
448 &li.initial_inventory_size[2], 1
452 TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(1),
453 &li.initial_inventory_content[2][0],EL_EMPTY, NULL,
454 &li.initial_inventory_size[2], 1, MAX_INITIAL_INVENTORY_SIZE
459 TYPE_INTEGER, CONF_VALUE_8_BIT(7),
460 &li.initial_player_stepsize[3], STEPSIZE_NORMAL
464 TYPE_BOOLEAN, CONF_VALUE_8_BIT(8),
465 &li.initial_player_gravity[3], FALSE
469 TYPE_BOOLEAN, CONF_VALUE_8_BIT(9),
470 &li.use_start_element[3], FALSE
474 TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
475 &li.start_element[3], EL_PLAYER_4
479 TYPE_BOOLEAN, CONF_VALUE_8_BIT(10),
480 &li.use_artwork_element[3], FALSE
484 TYPE_ELEMENT, CONF_VALUE_16_BIT(2),
485 &li.artwork_element[3], EL_PLAYER_4
489 TYPE_BOOLEAN, CONF_VALUE_8_BIT(11),
490 &li.use_explosion_element[3], FALSE
494 TYPE_ELEMENT, CONF_VALUE_16_BIT(3),
495 &li.explosion_element[3], EL_PLAYER_4
499 TYPE_BOOLEAN, CONF_VALUE_8_BIT(13),
500 &li.use_initial_inventory[3], FALSE
504 TYPE_BOOLEAN, CONF_VALUE_8_BIT(14),
505 &li.initial_inventory_size[3], 1
509 TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(1),
510 &li.initial_inventory_content[3][0],EL_EMPTY, NULL,
511 &li.initial_inventory_size[3], 1, MAX_INITIAL_INVENTORY_SIZE
516 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
517 &li.score[SC_EMERALD], 10
522 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
523 &li.score[SC_DIAMOND], 10
528 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
529 &li.score[SC_BUG], 10
534 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
535 &li.score[SC_SPACESHIP], 10
540 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
541 &li.score[SC_PACMAN], 10
546 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
547 &li.score[SC_NUT], 10
552 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
553 &li.score[SC_DYNAMITE], 10
558 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
559 &li.score[SC_KEY], 10
564 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
565 &li.score[SC_PEARL], 10
570 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
571 &li.score[SC_CRYSTAL], 10
576 TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
577 &li.amoeba_content, EL_DIAMOND
581 TYPE_INTEGER, CONF_VALUE_16_BIT(2),
586 TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
587 &li.grow_into_diggable, TRUE
592 TYPE_CONTENT_LIST, CONF_VALUE_BYTES(1),
593 &li.yamyam_content, EL_ROCK, NULL,
594 &li.num_yamyam_contents, 4, MAX_ELEMENT_CONTENTS
598 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
599 &li.score[SC_YAMYAM], 10
604 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
605 &li.score[SC_ROBOT], 10
609 TYPE_INTEGER, CONF_VALUE_16_BIT(2),
615 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
621 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
622 &li.time_magic_wall, 10
627 TYPE_INTEGER, CONF_VALUE_8_BIT(1),
628 &li.game_of_life[0], 2
632 TYPE_INTEGER, CONF_VALUE_8_BIT(2),
633 &li.game_of_life[1], 3
637 TYPE_INTEGER, CONF_VALUE_8_BIT(3),
638 &li.game_of_life[2], 3
642 TYPE_INTEGER, CONF_VALUE_8_BIT(4),
643 &li.game_of_life[3], 3
648 TYPE_INTEGER, CONF_VALUE_8_BIT(1),
653 TYPE_INTEGER, CONF_VALUE_8_BIT(2),
658 TYPE_INTEGER, CONF_VALUE_8_BIT(3),
663 TYPE_INTEGER, CONF_VALUE_8_BIT(4),
668 EL_TIMEGATE_SWITCH, -1,
669 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
670 &li.time_timegate, 10
674 EL_LIGHT_SWITCH_ACTIVE, -1,
675 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
680 EL_SHIELD_NORMAL, -1,
681 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
682 &li.shield_normal_time, 10
685 EL_SHIELD_NORMAL, -1,
686 TYPE_INTEGER, CONF_VALUE_16_BIT(2),
687 &li.score[SC_SHIELD], 10
691 EL_SHIELD_DEADLY, -1,
692 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
693 &li.shield_deadly_time, 10
696 EL_SHIELD_DEADLY, -1,
697 TYPE_INTEGER, CONF_VALUE_16_BIT(2),
698 &li.score[SC_SHIELD], 10
703 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
708 TYPE_INTEGER, CONF_VALUE_16_BIT(2),
709 &li.extra_time_score, 10
713 EL_TIME_ORB_FULL, -1,
714 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
715 &li.time_orb_time, 10
718 EL_TIME_ORB_FULL, -1,
719 TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
720 &li.use_time_orb_bug, FALSE
725 TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
726 &li.use_spring_bug, FALSE
731 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
732 &li.android_move_time, 10
736 TYPE_INTEGER, CONF_VALUE_16_BIT(2),
737 &li.android_clone_time, 10
741 TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(1),
742 &li.android_clone_element[0], EL_EMPTY, NULL,
743 &li.num_android_clone_elements, 1, MAX_ANDROID_ELEMENTS
748 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
753 TYPE_INTEGER, CONF_VALUE_16_BIT(2),
758 EL_EMC_MAGNIFIER, -1,
759 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
760 &li.magnify_score, 10
763 EL_EMC_MAGNIFIER, -1,
764 TYPE_INTEGER, CONF_VALUE_16_BIT(2),
769 EL_EMC_MAGIC_BALL, -1,
770 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
774 EL_EMC_MAGIC_BALL, -1,
775 TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
776 &li.ball_random, FALSE
779 EL_EMC_MAGIC_BALL, -1,
780 TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
781 &li.ball_state_initial, FALSE
784 EL_EMC_MAGIC_BALL, -1,
785 TYPE_CONTENT_LIST, CONF_VALUE_BYTES(1),
786 &li.ball_content, EL_EMPTY, NULL,
787 &li.num_ball_contents, 4, MAX_ELEMENT_CONTENTS
790 /* ---------- unused values ----------------------------------------------- */
793 EL_UNKNOWN, SAVE_CONF_NEVER,
794 TYPE_INTEGER, CONF_VALUE_16_BIT(1),
795 &li.score[SC_UNKNOWN_14], 10
798 EL_UNKNOWN, SAVE_CONF_NEVER,
799 TYPE_INTEGER, CONF_VALUE_16_BIT(2),
800 &li.score[SC_UNKNOWN_15], 10
810 static struct LevelFileConfigInfo chunk_config_NOTE[] =
814 TYPE_INTEGER, CONF_VALUE_8_BIT(1),
815 &xx_envelope.xsize, MAX_ENVELOPE_XSIZE,
819 TYPE_INTEGER, CONF_VALUE_8_BIT(2),
820 &xx_envelope.ysize, MAX_ENVELOPE_YSIZE,
825 TYPE_BOOLEAN, CONF_VALUE_8_BIT(3),
826 &xx_envelope.autowrap, FALSE
830 TYPE_BOOLEAN, CONF_VALUE_8_BIT(4),
831 &xx_envelope.centered, FALSE
836 TYPE_STRING, CONF_VALUE_BYTES(1),
837 &xx_envelope.text, -1, NULL,
838 &xx_string_length_unused, -1, MAX_ENVELOPE_TEXT_LEN,
839 &xx_default_string_empty[0]
849 static struct LevelFileConfigInfo chunk_config_CUSX_base[] =
853 TYPE_STRING, CONF_VALUE_BYTES(1),
854 &xx_ei.description[0], -1,
855 &yy_ei.description[0],
856 &xx_string_length_unused, -1, MAX_ELEMENT_NAME_LEN,
857 &xx_default_description[0]
862 TYPE_BITFIELD, CONF_VALUE_32_BIT(1),
863 &xx_ei.properties[EP_BITFIELD_BASE_NR], EP_BITMASK_BASE_DEFAULT,
864 &yy_ei.properties[EP_BITFIELD_BASE_NR]
870 TYPE_BITFIELD, CONF_VALUE_32_BIT(2),
871 &xx_ei.properties[EP_BITFIELD_BASE_NR + 1], EP_BITMASK_DEFAULT,
872 &yy_ei.properties[EP_BITFIELD_BASE_NR + 1]
878 TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
879 &xx_ei.use_gfx_element, FALSE,
880 &yy_ei.use_gfx_element
884 TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
885 &xx_ei.gfx_element_initial, EL_EMPTY_SPACE,
886 &yy_ei.gfx_element_initial
891 TYPE_BITFIELD, CONF_VALUE_8_BIT(2),
892 &xx_ei.access_direction, MV_ALL_DIRECTIONS,
893 &yy_ei.access_direction
898 TYPE_INTEGER, CONF_VALUE_16_BIT(2),
899 &xx_ei.collect_score_initial, 10,
900 &yy_ei.collect_score_initial
904 TYPE_INTEGER, CONF_VALUE_16_BIT(3),
905 &xx_ei.collect_count_initial, 1,
906 &yy_ei.collect_count_initial
911 TYPE_INTEGER, CONF_VALUE_16_BIT(4),
912 &xx_ei.ce_value_fixed_initial, 0,
913 &yy_ei.ce_value_fixed_initial
917 TYPE_INTEGER, CONF_VALUE_16_BIT(5),
918 &xx_ei.ce_value_random_initial, 0,
919 &yy_ei.ce_value_random_initial
923 TYPE_BOOLEAN, CONF_VALUE_8_BIT(3),
924 &xx_ei.use_last_ce_value, FALSE,
925 &yy_ei.use_last_ce_value
930 TYPE_INTEGER, CONF_VALUE_16_BIT(6),
931 &xx_ei.push_delay_fixed, 8,
932 &yy_ei.push_delay_fixed
936 TYPE_INTEGER, CONF_VALUE_16_BIT(7),
937 &xx_ei.push_delay_random, 8,
938 &yy_ei.push_delay_random
942 TYPE_INTEGER, CONF_VALUE_16_BIT(8),
943 &xx_ei.drop_delay_fixed, 0,
944 &yy_ei.drop_delay_fixed
948 TYPE_INTEGER, CONF_VALUE_16_BIT(9),
949 &xx_ei.drop_delay_random, 0,
950 &yy_ei.drop_delay_random
954 TYPE_INTEGER, CONF_VALUE_16_BIT(10),
955 &xx_ei.move_delay_fixed, 0,
956 &yy_ei.move_delay_fixed
960 TYPE_INTEGER, CONF_VALUE_16_BIT(11),
961 &xx_ei.move_delay_random, 0,
962 &yy_ei.move_delay_random
967 TYPE_BITFIELD, CONF_VALUE_32_BIT(3),
968 &xx_ei.move_pattern, MV_ALL_DIRECTIONS,
973 TYPE_BITFIELD, CONF_VALUE_8_BIT(4),
974 &xx_ei.move_direction_initial, MV_START_AUTOMATIC,
975 &yy_ei.move_direction_initial
979 TYPE_INTEGER, CONF_VALUE_8_BIT(5),
980 &xx_ei.move_stepsize, TILEX / 8,
986 TYPE_ELEMENT, CONF_VALUE_16_BIT(12),
987 &xx_ei.move_enter_element, EL_EMPTY_SPACE,
988 &yy_ei.move_enter_element
992 TYPE_ELEMENT, CONF_VALUE_16_BIT(13),
993 &xx_ei.move_leave_element, EL_EMPTY_SPACE,
994 &yy_ei.move_leave_element
998 TYPE_INTEGER, CONF_VALUE_8_BIT(6),
999 &xx_ei.move_leave_type, LEAVE_TYPE_UNLIMITED,
1000 &yy_ei.move_leave_type
1005 TYPE_INTEGER, CONF_VALUE_8_BIT(7),
1006 &xx_ei.slippery_type, SLIPPERY_ANY_RANDOM,
1007 &yy_ei.slippery_type
1012 TYPE_INTEGER, CONF_VALUE_8_BIT(8),
1013 &xx_ei.explosion_type, EXPLODES_3X3,
1014 &yy_ei.explosion_type
1018 TYPE_INTEGER, CONF_VALUE_16_BIT(14),
1019 &xx_ei.explosion_delay, 16,
1020 &yy_ei.explosion_delay
1024 TYPE_INTEGER, CONF_VALUE_16_BIT(15),
1025 &xx_ei.ignition_delay, 8,
1026 &yy_ei.ignition_delay
1031 TYPE_CONTENT_LIST, CONF_VALUE_BYTES(2),
1032 &xx_ei.content, EL_EMPTY_SPACE,
1034 &xx_num_contents, 1, 1
1037 /* ---------- "num_change_pages" must be the last entry ------------------- */
1040 -1, SAVE_CONF_ALWAYS,
1041 TYPE_INTEGER, CONF_VALUE_8_BIT(9),
1042 &xx_ei.num_change_pages, 1,
1043 &yy_ei.num_change_pages
1054 static struct LevelFileConfigInfo chunk_config_CUSX_change[] =
1056 /* ---------- "current_change_page" must be the first entry --------------- */
1059 -1, SAVE_CONF_ALWAYS,
1060 TYPE_INTEGER, CONF_VALUE_8_BIT(1),
1061 &xx_current_change_page, -1
1064 /* ---------- (the remaining entries can be in any order) ----------------- */
1068 TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
1069 &xx_change.can_change, FALSE
1074 TYPE_BITFIELD, CONF_VALUE_32_BIT(1),
1075 &xx_event_bits[0], 0
1079 TYPE_BITFIELD, CONF_VALUE_32_BIT(2),
1080 &xx_event_bits[1], 0
1085 TYPE_BITFIELD, CONF_VALUE_8_BIT(3),
1086 &xx_change.trigger_player, CH_PLAYER_ANY
1090 TYPE_BITFIELD, CONF_VALUE_8_BIT(4),
1091 &xx_change.trigger_side, CH_SIDE_ANY
1095 TYPE_BITFIELD, CONF_VALUE_32_BIT(3),
1096 &xx_change.trigger_page, CH_PAGE_ANY
1101 TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
1102 &xx_change.target_element, EL_EMPTY_SPACE
1107 TYPE_INTEGER, CONF_VALUE_16_BIT(2),
1108 &xx_change.delay_fixed, 0
1112 TYPE_INTEGER, CONF_VALUE_16_BIT(3),
1113 &xx_change.delay_random, 0
1117 TYPE_INTEGER, CONF_VALUE_16_BIT(4),
1118 &xx_change.delay_frames, FRAMES_PER_SECOND
1123 TYPE_ELEMENT, CONF_VALUE_16_BIT(5),
1124 &xx_change.initial_trigger_element, EL_EMPTY_SPACE
1129 TYPE_BOOLEAN, CONF_VALUE_8_BIT(6),
1130 &xx_change.explode, FALSE
1134 TYPE_BOOLEAN, CONF_VALUE_8_BIT(7),
1135 &xx_change.use_target_content, FALSE
1139 TYPE_BOOLEAN, CONF_VALUE_8_BIT(8),
1140 &xx_change.only_if_complete, FALSE
1144 TYPE_BOOLEAN, CONF_VALUE_8_BIT(9),
1145 &xx_change.use_random_replace, FALSE
1149 TYPE_INTEGER, CONF_VALUE_8_BIT(10),
1150 &xx_change.random_percentage, 100
1154 TYPE_INTEGER, CONF_VALUE_8_BIT(11),
1155 &xx_change.replace_when, CP_WHEN_EMPTY
1160 TYPE_BOOLEAN, CONF_VALUE_8_BIT(12),
1161 &xx_change.has_action, FALSE
1165 TYPE_INTEGER, CONF_VALUE_8_BIT(13),
1166 &xx_change.action_type, CA_NO_ACTION
1170 TYPE_INTEGER, CONF_VALUE_8_BIT(14),
1171 &xx_change.action_mode, CA_MODE_UNDEFINED
1175 TYPE_INTEGER, CONF_VALUE_16_BIT(6),
1176 &xx_change.action_arg, CA_ARG_UNDEFINED
1181 TYPE_ELEMENT, CONF_VALUE_16_BIT(7),
1182 &xx_change.action_element, EL_EMPTY_SPACE
1187 TYPE_CONTENT_LIST, CONF_VALUE_BYTES(1),
1188 &xx_change.target_content, EL_EMPTY_SPACE, NULL,
1189 &xx_num_contents, 1, 1
1199 static struct LevelFileConfigInfo chunk_config_GRPX[] =
1203 TYPE_STRING, CONF_VALUE_BYTES(1),
1204 &xx_ei.description[0], -1, NULL,
1205 &xx_string_length_unused, -1, MAX_ELEMENT_NAME_LEN,
1206 &xx_default_description[0]
1211 TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
1212 &xx_ei.use_gfx_element, FALSE
1216 TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
1217 &xx_ei.gfx_element_initial, EL_EMPTY_SPACE
1222 TYPE_INTEGER, CONF_VALUE_8_BIT(2),
1223 &xx_group.choice_mode, ANIM_RANDOM
1228 TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(2),
1229 &xx_group.element[0], EL_EMPTY_SPACE, NULL,
1230 &xx_group.num_elements, 1, MAX_ELEMENTS_IN_GROUP
1240 static struct LevelFileConfigInfo chunk_config_CONF[] = /* (OBSOLETE) */
1244 TYPE_BOOLEAN, CONF_VALUE_8_BIT(9),
1245 &li.block_snap_field, TRUE
1249 TYPE_BOOLEAN, CONF_VALUE_8_BIT(13),
1250 &li.continuous_snapping, TRUE
1254 TYPE_INTEGER, CONF_VALUE_8_BIT(1),
1255 &li.initial_player_stepsize[0], STEPSIZE_NORMAL
1259 TYPE_BOOLEAN, CONF_VALUE_8_BIT(10),
1260 &li.use_start_element[0], FALSE
1264 TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
1265 &li.start_element[0], EL_PLAYER_1
1269 TYPE_BOOLEAN, CONF_VALUE_8_BIT(11),
1270 &li.use_artwork_element[0], FALSE
1274 TYPE_ELEMENT, CONF_VALUE_16_BIT(2),
1275 &li.artwork_element[0], EL_PLAYER_1
1279 TYPE_BOOLEAN, CONF_VALUE_8_BIT(12),
1280 &li.use_explosion_element[0], FALSE
1284 TYPE_ELEMENT, CONF_VALUE_16_BIT(3),
1285 &li.explosion_element[0], EL_PLAYER_1
1300 filetype_id_list[] =
1302 { LEVEL_FILE_TYPE_RND, "RND" },
1303 { LEVEL_FILE_TYPE_BD, "BD" },
1304 { LEVEL_FILE_TYPE_EM, "EM" },
1305 { LEVEL_FILE_TYPE_SP, "SP" },
1306 { LEVEL_FILE_TYPE_DX, "DX" },
1307 { LEVEL_FILE_TYPE_SB, "SB" },
1308 { LEVEL_FILE_TYPE_DC, "DC" },
1313 /* ========================================================================= */
1314 /* level file functions */
1315 /* ========================================================================= */
1317 static struct DateInfo getCurrentDate()
1319 time_t epoch_seconds = time(NULL);
1320 struct tm *now = localtime(&epoch_seconds);
1321 struct DateInfo date;
1323 date.year = now->tm_year + 1900;
1324 date.month = now->tm_mon + 1;
1325 date.day = now->tm_mday;
1330 static void resetEventFlags(struct ElementChangeInfo *change)
1334 for (i = 0; i < NUM_CHANGE_EVENTS; i++)
1335 change->has_event[i] = FALSE;
1338 static void resetEventBits()
1342 for (i = 0; i < NUM_CE_BITFIELDS; i++)
1343 xx_event_bits[i] = 0;
1346 static void setEventFlagsFromEventBits(struct ElementChangeInfo *change)
1350 /* important: only change event flag if corresponding event bit is set
1351 (this is because all xx_event_bits[] values are loaded separately,
1352 and all xx_event_bits[] values are set back to zero before loading
1353 another value xx_event_bits[x] (each value representing 32 flags)) */
1355 for (i = 0; i < NUM_CHANGE_EVENTS; i++)
1356 if (xx_event_bits[CH_EVENT_BITFIELD_NR(i)] & CH_EVENT_BIT(i))
1357 change->has_event[i] = TRUE;
1360 static void setEventBitsFromEventFlags(struct ElementChangeInfo *change)
1364 /* in contrast to the above function setEventFlagsFromEventBits(), it
1365 would also be possible to set all bits in xx_event_bits[] to 0 or 1
1366 depending on the corresponding change->has_event[i] values here, as
1367 all xx_event_bits[] values are reset in resetEventBits() before */
1369 for (i = 0; i < NUM_CHANGE_EVENTS; i++)
1370 if (change->has_event[i])
1371 xx_event_bits[CH_EVENT_BITFIELD_NR(i)] |= CH_EVENT_BIT(i);
1374 static char *getDefaultElementDescription(struct ElementInfo *ei)
1376 static char description[MAX_ELEMENT_NAME_LEN + 1];
1377 char *default_description = (ei->custom_description != NULL ?
1378 ei->custom_description :
1379 ei->editor_description);
1382 /* always start with reliable default values */
1383 for (i = 0; i < MAX_ELEMENT_NAME_LEN + 1; i++)
1384 description[i] = '\0';
1386 /* truncate element description to MAX_ELEMENT_NAME_LEN bytes */
1387 strncpy(description, default_description, MAX_ELEMENT_NAME_LEN);
1389 return &description[0];
1392 static void setElementDescriptionToDefault(struct ElementInfo *ei)
1394 char *default_description = getDefaultElementDescription(ei);
1397 for (i = 0; i < MAX_ELEMENT_NAME_LEN + 1; i++)
1398 ei->description[i] = default_description[i];
1401 static void setConfigToDefaultsFromConfigList(struct LevelFileConfigInfo *conf)
1405 for (i = 0; conf[i].data_type != -1; i++)
1407 int default_value = conf[i].default_value;
1408 int data_type = conf[i].data_type;
1409 int conf_type = conf[i].conf_type;
1410 int byte_mask = conf_type & CONF_MASK_BYTES;
1412 if (byte_mask == CONF_MASK_MULTI_BYTES)
1414 int default_num_entities = conf[i].default_num_entities;
1415 int max_num_entities = conf[i].max_num_entities;
1417 *(int *)(conf[i].num_entities) = default_num_entities;
1419 if (data_type == TYPE_STRING)
1421 char *default_string = conf[i].default_string;
1422 char *string = (char *)(conf[i].value);
1424 strncpy(string, default_string, max_num_entities);
1426 else if (data_type == TYPE_ELEMENT_LIST)
1428 int *element_array = (int *)(conf[i].value);
1431 for (j = 0; j < max_num_entities; j++)
1432 element_array[j] = default_value;
1434 else if (data_type == TYPE_CONTENT_LIST)
1436 struct Content *content = (struct Content *)(conf[i].value);
1439 for (c = 0; c < max_num_entities; c++)
1440 for (y = 0; y < 3; y++)
1441 for (x = 0; x < 3; x++)
1442 content[c].e[x][y] = default_value;
1445 else /* constant size configuration data (1, 2 or 4 bytes) */
1447 if (data_type == TYPE_BOOLEAN)
1448 *(boolean *)(conf[i].value) = default_value;
1450 *(int *) (conf[i].value) = default_value;
1455 static void copyConfigFromConfigList(struct LevelFileConfigInfo *conf)
1459 for (i = 0; conf[i].data_type != -1; i++)
1461 int data_type = conf[i].data_type;
1462 int conf_type = conf[i].conf_type;
1463 int byte_mask = conf_type & CONF_MASK_BYTES;
1465 if (byte_mask == CONF_MASK_MULTI_BYTES)
1467 int max_num_entities = conf[i].max_num_entities;
1469 if (data_type == TYPE_STRING)
1471 char *string = (char *)(conf[i].value);
1472 char *string_copy = (char *)(conf[i].value_copy);
1474 strncpy(string_copy, string, max_num_entities);
1476 else if (data_type == TYPE_ELEMENT_LIST)
1478 int *element_array = (int *)(conf[i].value);
1479 int *element_array_copy = (int *)(conf[i].value_copy);
1482 for (j = 0; j < max_num_entities; j++)
1483 element_array_copy[j] = element_array[j];
1485 else if (data_type == TYPE_CONTENT_LIST)
1487 struct Content *content = (struct Content *)(conf[i].value);
1488 struct Content *content_copy = (struct Content *)(conf[i].value_copy);
1491 for (c = 0; c < max_num_entities; c++)
1492 for (y = 0; y < 3; y++)
1493 for (x = 0; x < 3; x++)
1494 content_copy[c].e[x][y] = content[c].e[x][y];
1497 else /* constant size configuration data (1, 2 or 4 bytes) */
1499 if (data_type == TYPE_BOOLEAN)
1500 *(boolean *)(conf[i].value_copy) = *(boolean *)(conf[i].value);
1502 *(int *) (conf[i].value_copy) = *(int *) (conf[i].value);
1507 void copyElementInfo(struct ElementInfo *ei_from, struct ElementInfo *ei_to)
1511 xx_ei = *ei_from; /* copy element data into temporary buffer */
1512 yy_ei = *ei_to; /* copy element data into temporary buffer */
1514 copyConfigFromConfigList(chunk_config_CUSX_base);
1519 /* ---------- reinitialize and copy change pages ---------- */
1521 ei_to->num_change_pages = ei_from->num_change_pages;
1522 ei_to->current_change_page = ei_from->current_change_page;
1524 setElementChangePages(ei_to, ei_to->num_change_pages);
1526 for (i = 0; i < ei_to->num_change_pages; i++)
1527 ei_to->change_page[i] = ei_from->change_page[i];
1529 /* ---------- copy group element info ---------- */
1530 if (ei_from->group != NULL && ei_to->group != NULL) /* group or internal */
1531 *ei_to->group = *ei_from->group;
1533 /* mark this custom element as modified */
1534 ei_to->modified_settings = TRUE;
1537 void setElementChangePages(struct ElementInfo *ei, int change_pages)
1539 int change_page_size = sizeof(struct ElementChangeInfo);
1541 ei->num_change_pages = MAX(1, change_pages);
1544 checked_realloc(ei->change_page, ei->num_change_pages * change_page_size);
1546 if (ei->current_change_page >= ei->num_change_pages)
1547 ei->current_change_page = ei->num_change_pages - 1;
1549 ei->change = &ei->change_page[ei->current_change_page];
1552 void setElementChangeInfoToDefaults(struct ElementChangeInfo *change)
1554 xx_change = *change; /* copy change data into temporary buffer */
1557 /* (not needed; set by setConfigToDefaultsFromConfigList()) */
1558 xx_num_contents = 1;
1561 setConfigToDefaultsFromConfigList(chunk_config_CUSX_change);
1563 *change = xx_change;
1565 resetEventFlags(change);
1567 change->direct_action = 0;
1568 change->other_action = 0;
1570 change->pre_change_function = NULL;
1571 change->change_function = NULL;
1572 change->post_change_function = NULL;
1575 static void setLevelInfoToDefaults(struct LevelInfo *level)
1577 static boolean clipboard_elements_initialized = FALSE;
1580 InitElementPropertiesStatic();
1582 li = *level; /* copy level data into temporary buffer */
1584 setConfigToDefaultsFromConfigList(chunk_config_INFO);
1585 setConfigToDefaultsFromConfigList(chunk_config_ELEM);
1587 *level = li; /* copy temporary buffer back to level data */
1589 setLevelInfoToDefaults_EM();
1591 level->native_em_level = &native_em_level;
1593 level->file_version = FILE_VERSION_ACTUAL;
1594 level->game_version = GAME_VERSION_ACTUAL;
1596 level->creation_date = getCurrentDate();
1598 level->encoding_16bit_field = TRUE;
1599 level->encoding_16bit_yamyam = TRUE;
1600 level->encoding_16bit_amoeba = TRUE;
1602 for (x = 0; x < MAX_LEV_FIELDX; x++)
1603 for (y = 0; y < MAX_LEV_FIELDY; y++)
1604 level->field[x][y] = EL_SAND;
1606 for (i = 0; i < MAX_LEVEL_NAME_LEN; i++)
1607 level->name[i] = '\0';
1608 for (i = 0; i < MAX_LEVEL_AUTHOR_LEN; i++)
1609 level->author[i] = '\0';
1611 strcpy(level->name, NAMELESS_LEVEL_NAME);
1612 strcpy(level->author, ANONYMOUS_NAME);
1614 level->field[0][0] = EL_PLAYER_1;
1615 level->field[STD_LEV_FIELDX - 1][STD_LEV_FIELDY - 1] = EL_EXIT_CLOSED;
1617 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1620 struct ElementInfo *ei = &element_info[element];
1622 /* never initialize clipboard elements after the very first time */
1623 /* (to be able to use clipboard elements between several levels) */
1624 if (IS_CLIPBOARD_ELEMENT(element) && clipboard_elements_initialized)
1627 if (IS_ENVELOPE(element))
1629 int envelope_nr = element - EL_ENVELOPE_1;
1631 setConfigToDefaultsFromConfigList(chunk_config_NOTE);
1633 level->envelope[envelope_nr] = xx_envelope;
1636 if (IS_CUSTOM_ELEMENT(element) ||
1637 IS_GROUP_ELEMENT(element) ||
1638 IS_INTERNAL_ELEMENT(element))
1640 xx_ei = *ei; /* copy element data into temporary buffer */
1642 setConfigToDefaultsFromConfigList(chunk_config_CUSX_base);
1647 setElementChangePages(ei, 1);
1648 setElementChangeInfoToDefaults(ei->change);
1650 if (IS_CUSTOM_ELEMENT(element) ||
1651 IS_GROUP_ELEMENT(element) ||
1652 IS_INTERNAL_ELEMENT(element))
1654 setElementDescriptionToDefault(ei);
1656 ei->modified_settings = FALSE;
1659 if (IS_CUSTOM_ELEMENT(element) ||
1660 IS_INTERNAL_ELEMENT(element))
1662 /* internal values used in level editor */
1664 ei->access_type = 0;
1665 ei->access_layer = 0;
1666 ei->access_protected = 0;
1667 ei->walk_to_action = 0;
1668 ei->smash_targets = 0;
1671 ei->can_explode_by_fire = FALSE;
1672 ei->can_explode_smashed = FALSE;
1673 ei->can_explode_impact = FALSE;
1675 ei->current_change_page = 0;
1678 if (IS_GROUP_ELEMENT(element) ||
1679 IS_INTERNAL_ELEMENT(element))
1681 struct ElementGroupInfo *group;
1683 /* initialize memory for list of elements in group */
1684 if (ei->group == NULL)
1685 ei->group = checked_malloc(sizeof(struct ElementGroupInfo));
1689 xx_group = *group; /* copy group data into temporary buffer */
1691 setConfigToDefaultsFromConfigList(chunk_config_GRPX);
1697 clipboard_elements_initialized = TRUE;
1699 BorderElement = EL_STEELWALL;
1701 level->no_valid_file = FALSE;
1703 level->changed = FALSE;
1705 /* set all bug compatibility flags to "false" => do not emulate this bug */
1706 level->use_action_after_change_bug = FALSE;
1708 if (leveldir_current == NULL) /* only when dumping level */
1711 /* try to determine better author name than 'anonymous' */
1712 if (!strEqual(leveldir_current->author, ANONYMOUS_NAME))
1714 strncpy(level->author, leveldir_current->author, MAX_LEVEL_AUTHOR_LEN);
1715 level->author[MAX_LEVEL_AUTHOR_LEN] = '\0';
1719 switch (LEVELCLASS(leveldir_current))
1721 case LEVELCLASS_TUTORIAL:
1722 strcpy(level->author, PROGRAM_AUTHOR_STRING);
1725 case LEVELCLASS_CONTRIB:
1726 strncpy(level->author, leveldir_current->name, MAX_LEVEL_AUTHOR_LEN);
1727 level->author[MAX_LEVEL_AUTHOR_LEN] = '\0';
1730 case LEVELCLASS_PRIVATE:
1731 strncpy(level->author, getRealName(), MAX_LEVEL_AUTHOR_LEN);
1732 level->author[MAX_LEVEL_AUTHOR_LEN] = '\0';
1736 /* keep default value */
1742 static void setFileInfoToDefaults(struct LevelFileInfo *level_file_info)
1744 level_file_info->nr = 0;
1745 level_file_info->type = LEVEL_FILE_TYPE_UNKNOWN;
1746 level_file_info->packed = FALSE;
1747 level_file_info->basename = NULL;
1748 level_file_info->filename = NULL;
1751 static void ActivateLevelTemplate()
1753 /* Currently there is no special action needed to activate the template
1754 data, because 'element_info' property settings overwrite the original
1755 level data, while all other variables do not change. */
1758 static char *getLevelFilenameFromBasename(char *basename)
1760 static char *filename = NULL;
1762 checked_free(filename);
1764 filename = getPath2(getCurrentLevelDir(), basename);
1769 static int getFileTypeFromBasename(char *basename)
1771 static char *filename = NULL;
1772 struct stat file_status;
1774 /* ---------- try to determine file type from filename ---------- */
1776 /* check for typical filename of a Supaplex level package file */
1777 if (strlen(basename) == 10 && (strncmp(basename, "levels.d", 8) == 0 ||
1778 strncmp(basename, "LEVELS.D", 8) == 0))
1779 return LEVEL_FILE_TYPE_SP;
1781 /* check for typical filename of a Diamond Caves II level package file */
1782 if (strSuffix(basename, ".dc") ||
1783 strSuffix(basename, ".dc2"))
1784 return LEVEL_FILE_TYPE_DC;
1786 /* ---------- try to determine file type from filesize ---------- */
1788 checked_free(filename);
1789 filename = getPath2(getCurrentLevelDir(), basename);
1791 if (stat(filename, &file_status) == 0)
1793 /* check for typical filesize of a Supaplex level package file */
1794 if (file_status.st_size == 170496)
1795 return LEVEL_FILE_TYPE_SP;
1798 return LEVEL_FILE_TYPE_UNKNOWN;
1801 static char *getSingleLevelBasename(int nr)
1803 static char basename[MAX_FILENAME_LEN];
1806 sprintf(basename, "template.%s", LEVELFILE_EXTENSION);
1808 sprintf(basename, "%03d.%s", nr, LEVELFILE_EXTENSION);
1813 static char *getPackedLevelBasename(int type)
1815 static char basename[MAX_FILENAME_LEN];
1816 char *directory = getCurrentLevelDir();
1818 struct dirent *dir_entry;
1820 strcpy(basename, UNDEFINED_FILENAME); /* default: undefined file */
1822 if ((dir = opendir(directory)) == NULL)
1824 Error(ERR_WARN, "cannot read current level directory '%s'", directory);
1829 while ((dir_entry = readdir(dir)) != NULL) /* loop until last dir entry */
1831 char *entry_basename = dir_entry->d_name;
1832 int entry_type = getFileTypeFromBasename(entry_basename);
1834 if (entry_type != LEVEL_FILE_TYPE_UNKNOWN) /* found valid level package */
1836 if (type == LEVEL_FILE_TYPE_UNKNOWN ||
1839 strcpy(basename, entry_basename);
1851 static char *getSingleLevelFilename(int nr)
1853 return getLevelFilenameFromBasename(getSingleLevelBasename(nr));
1857 static char *getPackedLevelFilename(int type)
1859 return getLevelFilenameFromBasename(getPackedLevelBasename(type));
1863 char *getDefaultLevelFilename(int nr)
1865 return getSingleLevelFilename(nr);
1869 static void setLevelFileInfo_SingleLevelFilename(struct LevelFileInfo *lfi,
1873 lfi->packed = FALSE;
1874 lfi->basename = getSingleLevelBasename(lfi->nr, lfi->type);
1875 lfi->filename = getLevelFilenameFromBasename(lfi->basename);
1879 static void setLevelFileInfo_FormatLevelFilename(struct LevelFileInfo *lfi,
1880 int type, char *format, ...)
1882 static char basename[MAX_FILENAME_LEN];
1885 va_start(ap, format);
1886 vsprintf(basename, format, ap);
1890 lfi->packed = FALSE;
1891 lfi->basename = basename;
1892 lfi->filename = getLevelFilenameFromBasename(lfi->basename);
1895 static void setLevelFileInfo_PackedLevelFilename(struct LevelFileInfo *lfi,
1900 lfi->basename = getPackedLevelBasename(lfi->type);
1901 lfi->filename = getLevelFilenameFromBasename(lfi->basename);
1904 static int getFiletypeFromID(char *filetype_id)
1906 char *filetype_id_lower;
1907 int filetype = LEVEL_FILE_TYPE_UNKNOWN;
1910 if (filetype_id == NULL)
1911 return LEVEL_FILE_TYPE_UNKNOWN;
1913 filetype_id_lower = getStringToLower(filetype_id);
1915 for (i = 0; filetype_id_list[i].id != NULL; i++)
1917 char *id_lower = getStringToLower(filetype_id_list[i].id);
1919 if (strEqual(filetype_id_lower, id_lower))
1920 filetype = filetype_id_list[i].filetype;
1924 if (filetype != LEVEL_FILE_TYPE_UNKNOWN)
1928 free(filetype_id_lower);
1933 static void determineLevelFileInfo_Filename(struct LevelFileInfo *lfi)
1937 /* special case: level number is negative => check for level template file */
1940 setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_RND,
1941 "template.%s", LEVELFILE_EXTENSION);
1943 /* no fallback if template file not existing */
1947 /* special case: check for file name/pattern specified in "levelinfo.conf" */
1948 if (leveldir_current->level_filename != NULL)
1950 int filetype = getFiletypeFromID(leveldir_current->level_filetype);
1952 setLevelFileInfo_FormatLevelFilename(lfi, filetype,
1953 leveldir_current->level_filename, nr);
1954 if (fileExists(lfi->filename))
1958 /* check for native Rocks'n'Diamonds level file */
1959 setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_RND,
1960 "%03d.%s", nr, LEVELFILE_EXTENSION);
1961 if (fileExists(lfi->filename))
1964 /* check for Emerald Mine level file (V1) */
1965 setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_EM, "a%c%c",
1966 'a' + (nr / 10) % 26, '0' + nr % 10);
1967 if (fileExists(lfi->filename))
1969 setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_EM, "A%c%c",
1970 'A' + (nr / 10) % 26, '0' + nr % 10);
1971 if (fileExists(lfi->filename))
1974 /* check for Emerald Mine level file (V2 to V5) */
1975 setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_EM, "%d", nr);
1976 if (fileExists(lfi->filename))
1979 /* check for Emerald Mine level file (V6 / single mode) */
1980 setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_EM, "%02ds", nr);
1981 if (fileExists(lfi->filename))
1983 setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_EM, "%02dS", nr);
1984 if (fileExists(lfi->filename))
1987 /* check for Emerald Mine level file (V6 / teamwork mode) */
1988 setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_EM, "%02dt", nr);
1989 if (fileExists(lfi->filename))
1991 setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_EM, "%02dT", nr);
1992 if (fileExists(lfi->filename))
1995 /* check for various packed level file formats */
1996 setLevelFileInfo_PackedLevelFilename(lfi, LEVEL_FILE_TYPE_UNKNOWN);
1997 if (fileExists(lfi->filename))
2000 /* no known level file found -- use default values (and fail later) */
2001 setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_RND,
2002 "%03d.%s", nr, LEVELFILE_EXTENSION);
2005 static void determineLevelFileInfo_Filetype(struct LevelFileInfo *lfi)
2007 if (lfi->type == LEVEL_FILE_TYPE_UNKNOWN)
2008 lfi->type = getFileTypeFromBasename(lfi->basename);
2011 static void setLevelFileInfo(struct LevelFileInfo *level_file_info, int nr)
2013 /* always start with reliable default values */
2014 setFileInfoToDefaults(level_file_info);
2016 level_file_info->nr = nr; /* set requested level number */
2018 determineLevelFileInfo_Filename(level_file_info);
2019 determineLevelFileInfo_Filetype(level_file_info);
2022 /* ------------------------------------------------------------------------- */
2023 /* functions for loading R'n'D level */
2024 /* ------------------------------------------------------------------------- */
2026 int getMappedElement(int element)
2028 /* remap some (historic, now obsolete) elements */
2032 case EL_PLAYER_OBSOLETE:
2033 element = EL_PLAYER_1;
2036 case EL_KEY_OBSOLETE:
2040 case EL_EM_KEY_1_FILE_OBSOLETE:
2041 element = EL_EM_KEY_1;
2044 case EL_EM_KEY_2_FILE_OBSOLETE:
2045 element = EL_EM_KEY_2;
2048 case EL_EM_KEY_3_FILE_OBSOLETE:
2049 element = EL_EM_KEY_3;
2052 case EL_EM_KEY_4_FILE_OBSOLETE:
2053 element = EL_EM_KEY_4;
2056 case EL_ENVELOPE_OBSOLETE:
2057 element = EL_ENVELOPE_1;
2065 if (element >= NUM_FILE_ELEMENTS)
2067 Error(ERR_WARN, "invalid level element %d", element);
2069 element = EL_UNKNOWN;
2077 int getMappedElementByVersion(int element, int game_version)
2079 /* remap some elements due to certain game version */
2081 if (game_version <= VERSION_IDENT(2,2,0,0))
2083 /* map game font elements */
2084 element = (element == EL_CHAR('[') ? EL_CHAR_AUMLAUT :
2085 element == EL_CHAR('\\') ? EL_CHAR_OUMLAUT :
2086 element == EL_CHAR(']') ? EL_CHAR_UUMLAUT :
2087 element == EL_CHAR('^') ? EL_CHAR_COPYRIGHT : element);
2090 if (game_version < VERSION_IDENT(3,0,0,0))
2092 /* map Supaplex gravity tube elements */
2093 element = (element == EL_SP_GRAVITY_PORT_LEFT ? EL_SP_PORT_LEFT :
2094 element == EL_SP_GRAVITY_PORT_RIGHT ? EL_SP_PORT_RIGHT :
2095 element == EL_SP_GRAVITY_PORT_UP ? EL_SP_PORT_UP :
2096 element == EL_SP_GRAVITY_PORT_DOWN ? EL_SP_PORT_DOWN :
2103 static int LoadLevel_VERS(FILE *file, int chunk_size, struct LevelInfo *level)
2105 level->file_version = getFileVersion(file);
2106 level->game_version = getFileVersion(file);
2111 static int LoadLevel_DATE(FILE *file, int chunk_size, struct LevelInfo *level)
2113 level->creation_date.year = getFile16BitBE(file);
2114 level->creation_date.month = getFile8Bit(file);
2115 level->creation_date.day = getFile8Bit(file);
2120 static int LoadLevel_HEAD(FILE *file, int chunk_size, struct LevelInfo *level)
2122 int initial_player_stepsize;
2123 int initial_player_gravity;
2126 level->fieldx = getFile8Bit(file);
2127 level->fieldy = getFile8Bit(file);
2129 level->time = getFile16BitBE(file);
2130 level->gems_needed = getFile16BitBE(file);
2132 for (i = 0; i < MAX_LEVEL_NAME_LEN; i++)
2133 level->name[i] = getFile8Bit(file);
2134 level->name[MAX_LEVEL_NAME_LEN] = 0;
2136 for (i = 0; i < LEVEL_SCORE_ELEMENTS; i++)
2137 level->score[i] = getFile8Bit(file);
2139 level->num_yamyam_contents = STD_ELEMENT_CONTENTS;
2140 for (i = 0; i < STD_ELEMENT_CONTENTS; i++)
2141 for (y = 0; y < 3; y++)
2142 for (x = 0; x < 3; x++)
2143 level->yamyam_content[i].e[x][y] = getMappedElement(getFile8Bit(file));
2145 level->amoeba_speed = getFile8Bit(file);
2146 level->time_magic_wall = getFile8Bit(file);
2147 level->time_wheel = getFile8Bit(file);
2148 level->amoeba_content = getMappedElement(getFile8Bit(file));
2150 initial_player_stepsize = (getFile8Bit(file) == 1 ? STEPSIZE_FAST :
2153 for (i = 0; i < MAX_PLAYERS; i++)
2154 level->initial_player_stepsize[i] = initial_player_stepsize;
2156 initial_player_gravity = (getFile8Bit(file) == 1 ? TRUE : FALSE);
2158 for (i = 0; i < MAX_PLAYERS; i++)
2159 level->initial_player_gravity[i] = initial_player_gravity;
2161 level->encoding_16bit_field = (getFile8Bit(file) == 1 ? TRUE : FALSE);
2162 level->em_slippery_gems = (getFile8Bit(file) == 1 ? TRUE : FALSE);
2164 level->use_custom_template = (getFile8Bit(file) == 1 ? TRUE : FALSE);
2166 level->block_last_field = (getFile8Bit(file) == 1 ? TRUE : FALSE);
2167 level->sp_block_last_field = (getFile8Bit(file) == 1 ? TRUE : FALSE);
2168 level->can_move_into_acid_bits = getFile32BitBE(file);
2169 level->dont_collide_with_bits = getFile8Bit(file);
2171 level->use_spring_bug = (getFile8Bit(file) == 1 ? TRUE : FALSE);
2172 level->use_step_counter = (getFile8Bit(file) == 1 ? TRUE : FALSE);
2174 level->instant_relocation = (getFile8Bit(file) == 1 ? TRUE : FALSE);
2175 level->can_pass_to_walkable = (getFile8Bit(file) == 1 ? TRUE : FALSE);
2176 level->grow_into_diggable = (getFile8Bit(file) == 1 ? TRUE : FALSE);
2178 level->game_engine_type = getFile8Bit(file);
2180 ReadUnusedBytesFromFile(file, LEVEL_CHUNK_HEAD_UNUSED);
2185 static int LoadLevel_NAME(FILE *file, int chunk_size, struct LevelInfo *level)
2189 for (i = 0; i < MAX_LEVEL_NAME_LEN; i++)
2190 level->name[i] = getFile8Bit(file);
2191 level->name[MAX_LEVEL_NAME_LEN] = 0;
2196 static int LoadLevel_AUTH(FILE *file, int chunk_size, struct LevelInfo *level)
2200 for (i = 0; i < MAX_LEVEL_AUTHOR_LEN; i++)
2201 level->author[i] = getFile8Bit(file);
2202 level->author[MAX_LEVEL_AUTHOR_LEN] = 0;
2207 static int LoadLevel_BODY(FILE *file, int chunk_size, struct LevelInfo *level)
2210 int chunk_size_expected = level->fieldx * level->fieldy;
2212 /* Note: "chunk_size" was wrong before version 2.0 when elements are
2213 stored with 16-bit encoding (and should be twice as big then).
2214 Even worse, playfield data was stored 16-bit when only yamyam content
2215 contained 16-bit elements and vice versa. */
2217 if (level->encoding_16bit_field && level->file_version >= FILE_VERSION_2_0)
2218 chunk_size_expected *= 2;
2220 if (chunk_size_expected != chunk_size)
2222 ReadUnusedBytesFromFile(file, chunk_size);
2223 return chunk_size_expected;
2226 for (y = 0; y < level->fieldy; y++)
2227 for (x = 0; x < level->fieldx; x++)
2228 level->field[x][y] =
2229 getMappedElement(level->encoding_16bit_field ? getFile16BitBE(file) :
2234 static int LoadLevel_CONT(FILE *file, int chunk_size, struct LevelInfo *level)
2237 int header_size = 4;
2238 int content_size = MAX_ELEMENT_CONTENTS * 3 * 3;
2239 int chunk_size_expected = header_size + content_size;
2241 /* Note: "chunk_size" was wrong before version 2.0 when elements are
2242 stored with 16-bit encoding (and should be twice as big then).
2243 Even worse, playfield data was stored 16-bit when only yamyam content
2244 contained 16-bit elements and vice versa. */
2246 if (level->encoding_16bit_field && level->file_version >= FILE_VERSION_2_0)
2247 chunk_size_expected += content_size;
2249 if (chunk_size_expected != chunk_size)
2251 ReadUnusedBytesFromFile(file, chunk_size);
2252 return chunk_size_expected;
2256 level->num_yamyam_contents = getFile8Bit(file);
2260 /* correct invalid number of content fields -- should never happen */
2261 if (level->num_yamyam_contents < 1 ||
2262 level->num_yamyam_contents > MAX_ELEMENT_CONTENTS)
2263 level->num_yamyam_contents = STD_ELEMENT_CONTENTS;
2265 for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
2266 for (y = 0; y < 3; y++)
2267 for (x = 0; x < 3; x++)
2268 level->yamyam_content[i].e[x][y] =
2269 getMappedElement(level->encoding_16bit_field ?
2270 getFile16BitBE(file) : getFile8Bit(file));
2274 static int LoadLevel_CNT2(FILE *file, int chunk_size, struct LevelInfo *level)
2278 int num_contents, content_xsize, content_ysize;
2279 int content_array[MAX_ELEMENT_CONTENTS][3][3];
2281 element = getMappedElement(getFile16BitBE(file));
2282 num_contents = getFile8Bit(file);
2283 content_xsize = getFile8Bit(file);
2284 content_ysize = getFile8Bit(file);
2286 ReadUnusedBytesFromFile(file, LEVEL_CHUNK_CNT2_UNUSED);
2288 for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
2289 for (y = 0; y < 3; y++)
2290 for (x = 0; x < 3; x++)
2291 content_array[i][x][y] = getMappedElement(getFile16BitBE(file));
2293 /* correct invalid number of content fields -- should never happen */
2294 if (num_contents < 1 || num_contents > MAX_ELEMENT_CONTENTS)
2295 num_contents = STD_ELEMENT_CONTENTS;
2297 if (element == EL_YAMYAM)
2299 level->num_yamyam_contents = num_contents;
2301 for (i = 0; i < num_contents; i++)
2302 for (y = 0; y < 3; y++)
2303 for (x = 0; x < 3; x++)
2304 level->yamyam_content[i].e[x][y] = content_array[i][x][y];
2306 else if (element == EL_BD_AMOEBA)
2308 level->amoeba_content = content_array[0][0][0];
2312 Error(ERR_WARN, "cannot load content for element '%d'", element);
2318 static int LoadLevel_CNT3(FILE *file, int chunk_size, struct LevelInfo *level)
2324 int chunk_size_expected;
2326 element = getMappedElement(getFile16BitBE(file));
2327 if (!IS_ENVELOPE(element))
2328 element = EL_ENVELOPE_1;
2330 envelope_nr = element - EL_ENVELOPE_1;
2332 envelope_len = getFile16BitBE(file);
2334 level->envelope[envelope_nr].xsize = getFile8Bit(file);
2335 level->envelope[envelope_nr].ysize = getFile8Bit(file);
2337 ReadUnusedBytesFromFile(file, LEVEL_CHUNK_CNT3_UNUSED);
2339 chunk_size_expected = LEVEL_CHUNK_CNT3_SIZE(envelope_len);
2340 if (chunk_size_expected != chunk_size)
2342 ReadUnusedBytesFromFile(file, chunk_size - LEVEL_CHUNK_CNT3_HEADER);
2343 return chunk_size_expected;
2346 for (i = 0; i < envelope_len; i++)
2347 level->envelope[envelope_nr].text[i] = getFile8Bit(file);
2352 static int LoadLevel_CUS1(FILE *file, int chunk_size, struct LevelInfo *level)
2354 int num_changed_custom_elements = getFile16BitBE(file);
2355 int chunk_size_expected = 2 + num_changed_custom_elements * 6;
2358 if (chunk_size_expected != chunk_size)
2360 ReadUnusedBytesFromFile(file, chunk_size - 2);
2361 return chunk_size_expected;
2364 for (i = 0; i < num_changed_custom_elements; i++)
2366 int element = getMappedElement(getFile16BitBE(file));
2367 int properties = getFile32BitBE(file);
2369 if (IS_CUSTOM_ELEMENT(element))
2370 element_info[element].properties[EP_BITFIELD_BASE_NR] = properties;
2372 Error(ERR_WARN, "invalid custom element number %d", element);
2374 /* older game versions that wrote level files with CUS1 chunks used
2375 different default push delay values (not yet stored in level file) */
2376 element_info[element].push_delay_fixed = 2;
2377 element_info[element].push_delay_random = 8;
2383 static int LoadLevel_CUS2(FILE *file, int chunk_size, struct LevelInfo *level)
2385 int num_changed_custom_elements = getFile16BitBE(file);
2386 int chunk_size_expected = 2 + num_changed_custom_elements * 4;
2389 if (chunk_size_expected != chunk_size)
2391 ReadUnusedBytesFromFile(file, chunk_size - 2);
2392 return chunk_size_expected;
2395 for (i = 0; i < num_changed_custom_elements; i++)
2397 int element = getMappedElement(getFile16BitBE(file));
2398 int custom_target_element = getMappedElement(getFile16BitBE(file));
2400 if (IS_CUSTOM_ELEMENT(element))
2401 element_info[element].change->target_element = custom_target_element;
2403 Error(ERR_WARN, "invalid custom element number %d", element);
2409 static int LoadLevel_CUS3(FILE *file, int chunk_size, struct LevelInfo *level)
2411 int num_changed_custom_elements = getFile16BitBE(file);
2412 int chunk_size_expected = LEVEL_CHUNK_CUS3_SIZE(num_changed_custom_elements);
2415 if (chunk_size_expected != chunk_size)
2417 ReadUnusedBytesFromFile(file, chunk_size - 2);
2418 return chunk_size_expected;
2421 for (i = 0; i < num_changed_custom_elements; i++)
2423 int element = getMappedElement(getFile16BitBE(file));
2424 struct ElementInfo *ei = &element_info[element];
2425 unsigned int event_bits;
2427 if (!IS_CUSTOM_ELEMENT(element))
2429 Error(ERR_WARN, "invalid custom element number %d", element);
2431 element = EL_INTERNAL_DUMMY;
2434 for (j = 0; j < MAX_ELEMENT_NAME_LEN; j++)
2435 ei->description[j] = getFile8Bit(file);
2436 ei->description[MAX_ELEMENT_NAME_LEN] = 0;
2438 ei->properties[EP_BITFIELD_BASE_NR] = getFile32BitBE(file);
2440 /* some free bytes for future properties and padding */
2441 ReadUnusedBytesFromFile(file, 7);
2443 ei->use_gfx_element = getFile8Bit(file);
2444 ei->gfx_element_initial = getMappedElement(getFile16BitBE(file));
2446 ei->collect_score_initial = getFile8Bit(file);
2447 ei->collect_count_initial = getFile8Bit(file);
2449 ei->push_delay_fixed = getFile16BitBE(file);
2450 ei->push_delay_random = getFile16BitBE(file);
2451 ei->move_delay_fixed = getFile16BitBE(file);
2452 ei->move_delay_random = getFile16BitBE(file);
2454 ei->move_pattern = getFile16BitBE(file);
2455 ei->move_direction_initial = getFile8Bit(file);
2456 ei->move_stepsize = getFile8Bit(file);
2458 for (y = 0; y < 3; y++)
2459 for (x = 0; x < 3; x++)
2460 ei->content.e[x][y] = getMappedElement(getFile16BitBE(file));
2462 event_bits = getFile32BitBE(file);
2463 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
2464 if (event_bits & (1 << j))
2465 ei->change->has_event[j] = TRUE;
2467 ei->change->target_element = getMappedElement(getFile16BitBE(file));
2469 ei->change->delay_fixed = getFile16BitBE(file);
2470 ei->change->delay_random = getFile16BitBE(file);
2471 ei->change->delay_frames = getFile16BitBE(file);
2473 ei->change->initial_trigger_element= getMappedElement(getFile16BitBE(file));
2475 ei->change->explode = getFile8Bit(file);
2476 ei->change->use_target_content = getFile8Bit(file);
2477 ei->change->only_if_complete = getFile8Bit(file);
2478 ei->change->use_random_replace = getFile8Bit(file);
2480 ei->change->random_percentage = getFile8Bit(file);
2481 ei->change->replace_when = getFile8Bit(file);
2483 for (y = 0; y < 3; y++)
2484 for (x = 0; x < 3; x++)
2485 ei->change->target_content.e[x][y] =
2486 getMappedElement(getFile16BitBE(file));
2488 ei->slippery_type = getFile8Bit(file);
2490 /* some free bytes for future properties and padding */
2491 ReadUnusedBytesFromFile(file, LEVEL_CPART_CUS3_UNUSED);
2493 /* mark that this custom element has been modified */
2494 ei->modified_settings = TRUE;
2500 static int LoadLevel_CUS4(FILE *file, int chunk_size, struct LevelInfo *level)
2502 struct ElementInfo *ei;
2503 int chunk_size_expected;
2507 /* ---------- custom element base property values (96 bytes) ------------- */
2509 element = getMappedElement(getFile16BitBE(file));
2511 if (!IS_CUSTOM_ELEMENT(element))
2513 Error(ERR_WARN, "invalid custom element number %d", element);
2515 ReadUnusedBytesFromFile(file, chunk_size - 2);
2519 ei = &element_info[element];
2521 for (i = 0; i < MAX_ELEMENT_NAME_LEN; i++)
2522 ei->description[i] = getFile8Bit(file);
2523 ei->description[MAX_ELEMENT_NAME_LEN] = 0;
2525 ei->properties[EP_BITFIELD_BASE_NR] = getFile32BitBE(file);
2527 ReadUnusedBytesFromFile(file, 4); /* reserved for more base properties */
2529 ei->num_change_pages = getFile8Bit(file);
2531 chunk_size_expected = LEVEL_CHUNK_CUS4_SIZE(ei->num_change_pages);
2532 if (chunk_size_expected != chunk_size)
2534 ReadUnusedBytesFromFile(file, chunk_size - 43);
2535 return chunk_size_expected;
2538 ei->ce_value_fixed_initial = getFile16BitBE(file);
2539 ei->ce_value_random_initial = getFile16BitBE(file);
2540 ei->use_last_ce_value = getFile8Bit(file);
2542 ei->use_gfx_element = getFile8Bit(file);
2543 ei->gfx_element_initial = getMappedElement(getFile16BitBE(file));
2545 ei->collect_score_initial = getFile8Bit(file);
2546 ei->collect_count_initial = getFile8Bit(file);
2548 ei->drop_delay_fixed = getFile8Bit(file);
2549 ei->push_delay_fixed = getFile8Bit(file);
2550 ei->drop_delay_random = getFile8Bit(file);
2551 ei->push_delay_random = getFile8Bit(file);
2552 ei->move_delay_fixed = getFile16BitBE(file);
2553 ei->move_delay_random = getFile16BitBE(file);
2555 /* bits 0 - 15 of "move_pattern" ... */
2556 ei->move_pattern = getFile16BitBE(file);
2557 ei->move_direction_initial = getFile8Bit(file);
2558 ei->move_stepsize = getFile8Bit(file);
2560 ei->slippery_type = getFile8Bit(file);
2562 for (y = 0; y < 3; y++)
2563 for (x = 0; x < 3; x++)
2564 ei->content.e[x][y] = getMappedElement(getFile16BitBE(file));
2566 ei->move_enter_element = getMappedElement(getFile16BitBE(file));
2567 ei->move_leave_element = getMappedElement(getFile16BitBE(file));
2568 ei->move_leave_type = getFile8Bit(file);
2570 /* ... bits 16 - 31 of "move_pattern" (not nice, but downward compatible) */
2571 ei->move_pattern |= (getFile16BitBE(file) << 16);
2573 ei->access_direction = getFile8Bit(file);
2575 ei->explosion_delay = getFile8Bit(file);
2576 ei->ignition_delay = getFile8Bit(file);
2577 ei->explosion_type = getFile8Bit(file);
2579 /* some free bytes for future custom property values and padding */
2580 ReadUnusedBytesFromFile(file, 1);
2582 /* ---------- change page property values (48 bytes) --------------------- */
2584 setElementChangePages(ei, ei->num_change_pages);
2586 for (i = 0; i < ei->num_change_pages; i++)
2588 struct ElementChangeInfo *change = &ei->change_page[i];
2589 unsigned int event_bits;
2591 /* always start with reliable default values */
2592 setElementChangeInfoToDefaults(change);
2594 /* bits 0 - 31 of "has_event[]" ... */
2595 event_bits = getFile32BitBE(file);
2596 for (j = 0; j < MIN(NUM_CHANGE_EVENTS, 32); j++)
2597 if (event_bits & (1 << j))
2598 change->has_event[j] = TRUE;
2600 change->target_element = getMappedElement(getFile16BitBE(file));
2602 change->delay_fixed = getFile16BitBE(file);
2603 change->delay_random = getFile16BitBE(file);
2604 change->delay_frames = getFile16BitBE(file);
2606 change->initial_trigger_element = getMappedElement(getFile16BitBE(file));
2608 change->explode = getFile8Bit(file);
2609 change->use_target_content = getFile8Bit(file);
2610 change->only_if_complete = getFile8Bit(file);
2611 change->use_random_replace = getFile8Bit(file);
2613 change->random_percentage = getFile8Bit(file);
2614 change->replace_when = getFile8Bit(file);
2616 for (y = 0; y < 3; y++)
2617 for (x = 0; x < 3; x++)
2618 change->target_content.e[x][y]= getMappedElement(getFile16BitBE(file));
2620 change->can_change = getFile8Bit(file);
2622 change->trigger_side = getFile8Bit(file);
2624 change->trigger_player = getFile8Bit(file);
2625 change->trigger_page = getFile8Bit(file);
2627 change->trigger_page = (change->trigger_page == CH_PAGE_ANY_FILE ?
2628 CH_PAGE_ANY : (1 << change->trigger_page));
2630 change->has_action = getFile8Bit(file);
2631 change->action_type = getFile8Bit(file);
2632 change->action_mode = getFile8Bit(file);
2633 change->action_arg = getFile16BitBE(file);
2635 /* ... bits 32 - 39 of "has_event[]" (not nice, but downward compatible) */
2636 event_bits = getFile8Bit(file);
2637 for (j = 32; j < NUM_CHANGE_EVENTS; j++)
2638 if (event_bits & (1 << (j - 32)))
2639 change->has_event[j] = TRUE;
2642 /* mark this custom element as modified */
2643 ei->modified_settings = TRUE;
2648 static int LoadLevel_GRP1(FILE *file, int chunk_size, struct LevelInfo *level)
2650 struct ElementInfo *ei;
2651 struct ElementGroupInfo *group;
2655 element = getMappedElement(getFile16BitBE(file));
2657 if (!IS_GROUP_ELEMENT(element))
2659 Error(ERR_WARN, "invalid group element number %d", element);
2661 ReadUnusedBytesFromFile(file, chunk_size - 2);
2665 ei = &element_info[element];
2667 for (i = 0; i < MAX_ELEMENT_NAME_LEN; i++)
2668 ei->description[i] = getFile8Bit(file);
2669 ei->description[MAX_ELEMENT_NAME_LEN] = 0;
2671 group = element_info[element].group;
2673 group->num_elements = getFile8Bit(file);
2675 ei->use_gfx_element = getFile8Bit(file);
2676 ei->gfx_element_initial = getMappedElement(getFile16BitBE(file));
2678 group->choice_mode = getFile8Bit(file);
2680 /* some free bytes for future values and padding */
2681 ReadUnusedBytesFromFile(file, 3);
2683 for (i = 0; i < MAX_ELEMENTS_IN_GROUP; i++)
2684 group->element[i] = getMappedElement(getFile16BitBE(file));
2686 /* mark this group element as modified */
2687 element_info[element].modified_settings = TRUE;
2692 static int LoadLevel_MicroChunk(FILE *file, struct LevelFileConfigInfo *conf,
2693 int element, int real_element)
2695 int micro_chunk_size = 0;
2696 int conf_type = getFile8Bit(file);
2697 int byte_mask = conf_type & CONF_MASK_BYTES;
2698 boolean element_found = FALSE;
2701 micro_chunk_size += 1;
2703 if (byte_mask == CONF_MASK_MULTI_BYTES)
2705 int num_bytes = getFile16BitBE(file);
2706 byte *buffer = checked_malloc(num_bytes);
2708 ReadBytesFromFile(file, buffer, num_bytes);
2710 for (i = 0; conf[i].data_type != -1; i++)
2712 if (conf[i].element == element &&
2713 conf[i].conf_type == conf_type)
2715 int data_type = conf[i].data_type;
2716 int num_entities = num_bytes / CONF_ENTITY_NUM_BYTES(data_type);
2717 int max_num_entities = conf[i].max_num_entities;
2719 if (num_entities > max_num_entities)
2722 "truncating number of entities for element %d from %d to %d",
2723 element, num_entities, max_num_entities);
2725 num_entities = max_num_entities;
2728 if (num_entities == 0 && (data_type == TYPE_ELEMENT_LIST ||
2729 data_type == TYPE_CONTENT_LIST))
2731 /* for element and content lists, zero entities are not allowed */
2732 Error(ERR_WARN, "found empty list of entities for element %d",
2735 /* do not set "num_entities" here to prevent reading behind buffer */
2737 *(int *)(conf[i].num_entities) = 1; /* at least one is required */
2741 *(int *)(conf[i].num_entities) = num_entities;
2744 element_found = TRUE;
2746 if (data_type == TYPE_STRING)
2748 char *string = (char *)(conf[i].value);
2751 for (j = 0; j < max_num_entities; j++)
2752 string[j] = (j < num_entities ? buffer[j] : '\0');
2754 else if (data_type == TYPE_ELEMENT_LIST)
2756 int *element_array = (int *)(conf[i].value);
2759 for (j = 0; j < num_entities; j++)
2761 getMappedElement(CONF_ELEMENTS_ELEMENT(buffer, j));
2763 else if (data_type == TYPE_CONTENT_LIST)
2765 struct Content *content= (struct Content *)(conf[i].value);
2768 for (c = 0; c < num_entities; c++)
2769 for (y = 0; y < 3; y++)
2770 for (x = 0; x < 3; x++)
2771 content[c].e[x][y] =
2772 getMappedElement(CONF_CONTENTS_ELEMENT(buffer, c, x, y));
2775 element_found = FALSE;
2781 checked_free(buffer);
2783 micro_chunk_size += 2 + num_bytes;
2785 else /* constant size configuration data (1, 2 or 4 bytes) */
2787 int value = (byte_mask == CONF_MASK_1_BYTE ? getFile8Bit (file) :
2788 byte_mask == CONF_MASK_2_BYTE ? getFile16BitBE(file) :
2789 byte_mask == CONF_MASK_4_BYTE ? getFile32BitBE(file) : 0);
2791 for (i = 0; conf[i].data_type != -1; i++)
2793 if (conf[i].element == element &&
2794 conf[i].conf_type == conf_type)
2796 int data_type = conf[i].data_type;
2798 if (data_type == TYPE_ELEMENT)
2799 value = getMappedElement(value);
2801 if (data_type == TYPE_BOOLEAN)
2802 *(boolean *)(conf[i].value) = value;
2804 *(int *) (conf[i].value) = value;
2806 element_found = TRUE;
2812 micro_chunk_size += CONF_VALUE_NUM_BYTES(byte_mask);
2817 char *error_conf_chunk_bytes =
2818 (byte_mask == CONF_MASK_1_BYTE ? "CONF_VALUE_8_BIT" :
2819 byte_mask == CONF_MASK_2_BYTE ? "CONF_VALUE_16_BIT" :
2820 byte_mask == CONF_MASK_4_BYTE ? "CONF_VALUE_32_BIT" :"CONF_VALUE_BYTES");
2821 int error_conf_chunk_token = conf_type & CONF_MASK_TOKEN;
2822 int error_element = real_element;
2824 Error(ERR_WARN, "cannot load micro chunk '%s(%d)' value for element %d ['%s']",
2825 error_conf_chunk_bytes, error_conf_chunk_token,
2826 error_element, EL_NAME(error_element));
2829 return micro_chunk_size;
2832 static int LoadLevel_INFO(FILE *file, int chunk_size, struct LevelInfo *level)
2834 int real_chunk_size = 0;
2836 li = *level; /* copy level data into temporary buffer */
2840 real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_INFO, -1, -1);
2842 if (real_chunk_size >= chunk_size)
2846 *level = li; /* copy temporary buffer back to level data */
2848 return real_chunk_size;
2851 static int LoadLevel_CONF(FILE *file, int chunk_size, struct LevelInfo *level)
2853 int real_chunk_size = 0;
2855 li = *level; /* copy level data into temporary buffer */
2859 int element = getMappedElement(getFile16BitBE(file));
2861 real_chunk_size += 2;
2862 real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_CONF,
2864 if (real_chunk_size >= chunk_size)
2868 *level = li; /* copy temporary buffer back to level data */
2870 return real_chunk_size;
2873 static int LoadLevel_ELEM(FILE *file, int chunk_size, struct LevelInfo *level)
2875 int real_chunk_size = 0;
2877 li = *level; /* copy level data into temporary buffer */
2881 int element = getMappedElement(getFile16BitBE(file));
2883 real_chunk_size += 2;
2884 real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_ELEM,
2886 if (real_chunk_size >= chunk_size)
2890 *level = li; /* copy temporary buffer back to level data */
2892 return real_chunk_size;
2895 static int LoadLevel_NOTE(FILE *file, int chunk_size, struct LevelInfo *level)
2897 int element = getMappedElement(getFile16BitBE(file));
2898 int envelope_nr = element - EL_ENVELOPE_1;
2899 int real_chunk_size = 2;
2903 real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_NOTE,
2906 if (real_chunk_size >= chunk_size)
2910 level->envelope[envelope_nr] = xx_envelope;
2912 return real_chunk_size;
2915 static int LoadLevel_CUSX(FILE *file, int chunk_size, struct LevelInfo *level)
2917 int element = getMappedElement(getFile16BitBE(file));
2918 int real_chunk_size = 2;
2919 struct ElementInfo *ei = &element_info[element];
2922 xx_ei = *ei; /* copy element data into temporary buffer */
2924 xx_ei.num_change_pages = -1;
2928 real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_CUSX_base,
2930 if (xx_ei.num_change_pages != -1)
2933 if (real_chunk_size >= chunk_size)
2939 if (ei->num_change_pages == -1)
2941 Error(ERR_WARN, "LoadLevel_CUSX(): missing 'num_change_pages' for '%s'",
2944 ei->num_change_pages = 1;
2946 setElementChangePages(ei, 1);
2947 setElementChangeInfoToDefaults(ei->change);
2949 return real_chunk_size;
2952 /* initialize number of change pages stored for this custom element */
2953 setElementChangePages(ei, ei->num_change_pages);
2954 for (i = 0; i < ei->num_change_pages; i++)
2955 setElementChangeInfoToDefaults(&ei->change_page[i]);
2957 /* start with reading properties for the first change page */
2958 xx_current_change_page = 0;
2962 struct ElementChangeInfo *change = &ei->change_page[xx_current_change_page];
2964 xx_change = *change; /* copy change data into temporary buffer */
2966 resetEventBits(); /* reset bits; change page might have changed */
2968 real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_CUSX_change,
2971 *change = xx_change;
2973 setEventFlagsFromEventBits(change);
2975 if (real_chunk_size >= chunk_size)
2979 return real_chunk_size;
2982 static int LoadLevel_GRPX(FILE *file, int chunk_size, struct LevelInfo *level)
2984 int element = getMappedElement(getFile16BitBE(file));
2985 int real_chunk_size = 2;
2986 struct ElementInfo *ei = &element_info[element];
2987 struct ElementGroupInfo *group = ei->group;
2989 xx_ei = *ei; /* copy element data into temporary buffer */
2990 xx_group = *group; /* copy group data into temporary buffer */
2994 real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_GRPX,
2997 if (real_chunk_size >= chunk_size)
3004 return real_chunk_size;
3007 static void LoadLevelFromFileInfo_RND(struct LevelInfo *level,
3008 struct LevelFileInfo *level_file_info)
3010 char *filename = level_file_info->filename;
3011 char cookie[MAX_LINE_LEN];
3012 char chunk_name[CHUNK_ID_LEN + 1];
3016 if (!(file = fopen(filename, MODE_READ)))
3018 level->no_valid_file = TRUE;
3020 if (level != &level_template)
3021 Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename);
3026 getFileChunkBE(file, chunk_name, NULL);
3027 if (strEqual(chunk_name, "RND1"))
3029 getFile32BitBE(file); /* not used */
3031 getFileChunkBE(file, chunk_name, NULL);
3032 if (!strEqual(chunk_name, "CAVE"))
3034 level->no_valid_file = TRUE;
3036 Error(ERR_WARN, "unknown format of level file '%s'", filename);
3041 else /* check for pre-2.0 file format with cookie string */
3043 strcpy(cookie, chunk_name);
3044 fgets(&cookie[4], MAX_LINE_LEN - 4, file);
3045 if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
3046 cookie[strlen(cookie) - 1] = '\0';
3048 if (!checkCookieString(cookie, LEVEL_COOKIE_TMPL))
3050 level->no_valid_file = TRUE;
3052 Error(ERR_WARN, "unknown format of level file '%s'", filename);
3057 if ((level->file_version = getFileVersionFromCookieString(cookie)) == -1)
3059 level->no_valid_file = TRUE;
3061 Error(ERR_WARN, "unsupported version of level file '%s'", filename);
3066 /* pre-2.0 level files have no game version, so use file version here */
3067 level->game_version = level->file_version;
3070 if (level->file_version < FILE_VERSION_1_2)
3072 /* level files from versions before 1.2.0 without chunk structure */
3073 LoadLevel_HEAD(file, LEVEL_CHUNK_HEAD_SIZE, level);
3074 LoadLevel_BODY(file, level->fieldx * level->fieldy, level);
3082 int (*loader)(FILE *, int, struct LevelInfo *);
3086 { "VERS", LEVEL_CHUNK_VERS_SIZE, LoadLevel_VERS },
3087 { "DATE", LEVEL_CHUNK_DATE_SIZE, LoadLevel_DATE },
3088 { "HEAD", LEVEL_CHUNK_HEAD_SIZE, LoadLevel_HEAD },
3089 { "NAME", LEVEL_CHUNK_NAME_SIZE, LoadLevel_NAME },
3090 { "AUTH", LEVEL_CHUNK_AUTH_SIZE, LoadLevel_AUTH },
3091 { "INFO", -1, LoadLevel_INFO },
3092 { "BODY", -1, LoadLevel_BODY },
3093 { "CONT", -1, LoadLevel_CONT },
3094 { "CNT2", LEVEL_CHUNK_CNT2_SIZE, LoadLevel_CNT2 },
3095 { "CNT3", -1, LoadLevel_CNT3 },
3096 { "CUS1", -1, LoadLevel_CUS1 },
3097 { "CUS2", -1, LoadLevel_CUS2 },
3098 { "CUS3", -1, LoadLevel_CUS3 },
3099 { "CUS4", -1, LoadLevel_CUS4 },
3100 { "GRP1", -1, LoadLevel_GRP1 },
3101 { "CONF", -1, LoadLevel_CONF },
3102 { "ELEM", -1, LoadLevel_ELEM },
3103 { "NOTE", -1, LoadLevel_NOTE },
3104 { "CUSX", -1, LoadLevel_CUSX },
3105 { "GRPX", -1, LoadLevel_GRPX },
3110 while (getFileChunkBE(file, chunk_name, &chunk_size))
3114 while (chunk_info[i].name != NULL &&
3115 !strEqual(chunk_name, chunk_info[i].name))
3118 if (chunk_info[i].name == NULL)
3120 Error(ERR_WARN, "unknown chunk '%s' in level file '%s'",
3121 chunk_name, filename);
3122 ReadUnusedBytesFromFile(file, chunk_size);
3124 else if (chunk_info[i].size != -1 &&
3125 chunk_info[i].size != chunk_size)
3127 Error(ERR_WARN, "wrong size (%d) of chunk '%s' in level file '%s'",
3128 chunk_size, chunk_name, filename);
3129 ReadUnusedBytesFromFile(file, chunk_size);
3133 /* call function to load this level chunk */
3134 int chunk_size_expected =
3135 (chunk_info[i].loader)(file, chunk_size, level);
3137 /* the size of some chunks cannot be checked before reading other
3138 chunks first (like "HEAD" and "BODY") that contain some header
3139 information, so check them here */
3140 if (chunk_size_expected != chunk_size)
3142 Error(ERR_WARN, "wrong size (%d) of chunk '%s' in level file '%s'",
3143 chunk_size, chunk_name, filename);
3152 /* ------------------------------------------------------------------------- */
3153 /* functions for loading EM level */
3154 /* ------------------------------------------------------------------------- */
3158 static int map_em_element_yam(int element)
3162 case 0x00: return EL_EMPTY;
3163 case 0x01: return EL_EMERALD;
3164 case 0x02: return EL_DIAMOND;
3165 case 0x03: return EL_ROCK;
3166 case 0x04: return EL_ROBOT;
3167 case 0x05: return EL_SPACESHIP_UP;
3168 case 0x06: return EL_BOMB;
3169 case 0x07: return EL_BUG_UP;
3170 case 0x08: return EL_AMOEBA_DROP;
3171 case 0x09: return EL_NUT;
3172 case 0x0a: return EL_YAMYAM;
3173 case 0x0b: return EL_QUICKSAND_FULL;
3174 case 0x0c: return EL_SAND;
3175 case 0x0d: return EL_WALL_SLIPPERY;
3176 case 0x0e: return EL_STEELWALL;
3177 case 0x0f: return EL_WALL;
3178 case 0x10: return EL_EM_KEY_1;
3179 case 0x11: return EL_EM_KEY_2;
3180 case 0x12: return EL_EM_KEY_4;
3181 case 0x13: return EL_EM_KEY_3;
3182 case 0x14: return EL_MAGIC_WALL;
3183 case 0x15: return EL_ROBOT_WHEEL;
3184 case 0x16: return EL_DYNAMITE;
3186 case 0x17: return EL_EM_KEY_1; /* EMC */
3187 case 0x18: return EL_BUG_UP; /* EMC */
3188 case 0x1a: return EL_DIAMOND; /* EMC */
3189 case 0x1b: return EL_EMERALD; /* EMC */
3190 case 0x25: return EL_NUT; /* EMC */
3191 case 0x80: return EL_EMPTY; /* EMC */
3192 case 0x85: return EL_EM_KEY_1; /* EMC */
3193 case 0x86: return EL_EM_KEY_2; /* EMC */
3194 case 0x87: return EL_EM_KEY_4; /* EMC */
3195 case 0x88: return EL_EM_KEY_3; /* EMC */
3196 case 0x94: return EL_QUICKSAND_EMPTY; /* EMC */
3197 case 0x9a: return EL_AMOEBA_WET; /* EMC */
3198 case 0xaf: return EL_DYNAMITE; /* EMC */
3199 case 0xbd: return EL_SAND; /* EMC */
3202 Error(ERR_WARN, "invalid level element %d", element);
3207 static int map_em_element_field(int element)
3209 if (element >= 0xc8 && element <= 0xe1)
3210 return EL_CHAR_A + (element - 0xc8);
3211 else if (element >= 0xe2 && element <= 0xeb)
3212 return EL_CHAR_0 + (element - 0xe2);
3216 case 0x00: return EL_ROCK;
3217 case 0x01: return EL_ROCK; /* EMC */
3218 case 0x02: return EL_DIAMOND;
3219 case 0x03: return EL_DIAMOND;
3220 case 0x04: return EL_ROBOT;
3221 case 0x05: return EL_ROBOT; /* EMC */
3222 case 0x06: return EL_EMPTY_SPACE; /* EMC */
3223 case 0x07: return EL_EMPTY_SPACE; /* EMC */
3224 case 0x08: return EL_SPACESHIP_UP;
3225 case 0x09: return EL_SPACESHIP_RIGHT;
3226 case 0x0a: return EL_SPACESHIP_DOWN;
3227 case 0x0b: return EL_SPACESHIP_LEFT;
3228 case 0x0c: return EL_SPACESHIP_UP;
3229 case 0x0d: return EL_SPACESHIP_RIGHT;
3230 case 0x0e: return EL_SPACESHIP_DOWN;
3231 case 0x0f: return EL_SPACESHIP_LEFT;
3233 case 0x10: return EL_BOMB;
3234 case 0x11: return EL_BOMB; /* EMC */
3235 case 0x12: return EL_EMERALD;
3236 case 0x13: return EL_EMERALD;
3237 case 0x14: return EL_BUG_UP;
3238 case 0x15: return EL_BUG_RIGHT;
3239 case 0x16: return EL_BUG_DOWN;
3240 case 0x17: return EL_BUG_LEFT;
3241 case 0x18: return EL_BUG_UP;
3242 case 0x19: return EL_BUG_RIGHT;
3243 case 0x1a: return EL_BUG_DOWN;
3244 case 0x1b: return EL_BUG_LEFT;
3245 case 0x1c: return EL_AMOEBA_DROP;
3246 case 0x1d: return EL_AMOEBA_DROP; /* EMC */
3247 case 0x1e: return EL_AMOEBA_DROP; /* EMC */
3248 case 0x1f: return EL_AMOEBA_DROP; /* EMC */
3250 case 0x20: return EL_ROCK;
3251 case 0x21: return EL_BOMB; /* EMC */
3252 case 0x22: return EL_DIAMOND; /* EMC */
3253 case 0x23: return EL_EMERALD; /* EMC */
3254 case 0x24: return EL_MAGIC_WALL;
3255 case 0x25: return EL_NUT;
3256 case 0x26: return EL_NUT; /* EMC */
3257 case 0x27: return EL_NUT; /* EMC */
3259 /* looks like magic wheel, but is _always_ activated */
3260 case 0x28: return EL_ROBOT_WHEEL; /* EMC */
3262 case 0x29: return EL_YAMYAM; /* up */
3263 case 0x2a: return EL_YAMYAM; /* down */
3264 case 0x2b: return EL_YAMYAM; /* left */ /* EMC */
3265 case 0x2c: return EL_YAMYAM; /* right */ /* EMC */
3266 case 0x2d: return EL_QUICKSAND_FULL;
3267 case 0x2e: return EL_EMPTY_SPACE; /* EMC */
3268 case 0x2f: return EL_EMPTY_SPACE; /* EMC */
3270 case 0x30: return EL_EMPTY_SPACE; /* EMC */
3271 case 0x31: return EL_SAND; /* EMC */
3272 case 0x32: return EL_SAND; /* EMC */
3273 case 0x33: return EL_SAND; /* EMC */
3274 case 0x34: return EL_QUICKSAND_FULL; /* EMC */
3275 case 0x35: return EL_QUICKSAND_FULL; /* EMC */
3276 case 0x36: return EL_QUICKSAND_FULL; /* EMC */
3277 case 0x37: return EL_SAND; /* EMC */
3278 case 0x38: return EL_ROCK; /* EMC */
3279 case 0x39: return EL_EXPANDABLE_WALL_HORIZONTAL; /* EMC */
3280 case 0x3a: return EL_EXPANDABLE_WALL_VERTICAL; /* EMC */
3281 case 0x3b: return EL_DYNAMITE_ACTIVE; /* 1 */
3282 case 0x3c: return EL_DYNAMITE_ACTIVE; /* 2 */
3283 case 0x3d: return EL_DYNAMITE_ACTIVE; /* 3 */
3284 case 0x3e: return EL_DYNAMITE_ACTIVE; /* 4 */
3285 case 0x3f: return EL_ACID_POOL_BOTTOM;
3287 case 0x40: return EL_EXIT_OPEN; /* 1 */
3288 case 0x41: return EL_EXIT_OPEN; /* 2 */
3289 case 0x42: return EL_EXIT_OPEN; /* 3 */
3290 case 0x43: return EL_BALLOON; /* EMC */
3291 case 0x44: return EL_UNKNOWN; /* EMC ("plant") */
3292 case 0x45: return EL_SPRING; /* EMC */
3293 case 0x46: return EL_SPRING; /* falling */ /* EMC */
3294 case 0x47: return EL_SPRING; /* left */ /* EMC */
3295 case 0x48: return EL_SPRING; /* right */ /* EMC */
3296 case 0x49: return EL_UNKNOWN; /* EMC ("ball 1") */
3297 case 0x4a: return EL_UNKNOWN; /* EMC ("ball 2") */
3298 case 0x4b: return EL_UNKNOWN; /* EMC ("android") */
3299 case 0x4c: return EL_EMPTY_SPACE; /* EMC */
3300 case 0x4d: return EL_UNKNOWN; /* EMC ("android") */
3301 case 0x4e: return EL_INVISIBLE_WALL; /* EMC (? "android") */
3302 case 0x4f: return EL_UNKNOWN; /* EMC ("android") */
3304 case 0x50: return EL_UNKNOWN; /* EMC ("android") */
3305 case 0x51: return EL_UNKNOWN; /* EMC ("android") */
3306 case 0x52: return EL_UNKNOWN; /* EMC ("android") */
3307 case 0x53: return EL_UNKNOWN; /* EMC ("android") */
3308 case 0x54: return EL_UNKNOWN; /* EMC ("android") */
3309 case 0x55: return EL_EMPTY_SPACE; /* EMC */
3310 case 0x56: return EL_EMPTY_SPACE; /* EMC */
3311 case 0x57: return EL_EMPTY_SPACE; /* EMC */
3312 case 0x58: return EL_EMPTY_SPACE; /* EMC */
3313 case 0x59: return EL_EMPTY_SPACE; /* EMC */
3314 case 0x5a: return EL_EMPTY_SPACE; /* EMC */
3315 case 0x5b: return EL_EMPTY_SPACE; /* EMC */
3316 case 0x5c: return EL_EMPTY_SPACE; /* EMC */
3317 case 0x5d: return EL_EMPTY_SPACE; /* EMC */
3318 case 0x5e: return EL_EMPTY_SPACE; /* EMC */
3319 case 0x5f: return EL_EMPTY_SPACE; /* EMC */
3321 case 0x60: return EL_EMPTY_SPACE; /* EMC */
3322 case 0x61: return EL_EMPTY_SPACE; /* EMC */
3323 case 0x62: return EL_EMPTY_SPACE; /* EMC */
3324 case 0x63: return EL_SPRING; /* left */ /* EMC */
3325 case 0x64: return EL_SPRING; /* right */ /* EMC */
3326 case 0x65: return EL_ACID; /* 1 */ /* EMC */
3327 case 0x66: return EL_ACID; /* 2 */ /* EMC */
3328 case 0x67: return EL_ACID; /* 3 */ /* EMC */
3329 case 0x68: return EL_ACID; /* 4 */ /* EMC */
3330 case 0x69: return EL_ACID; /* 5 */ /* EMC */
3331 case 0x6a: return EL_ACID; /* 6 */ /* EMC */
3332 case 0x6b: return EL_ACID; /* 7 */ /* EMC */
3333 case 0x6c: return EL_ACID; /* 8 */ /* EMC */
3334 case 0x6d: return EL_EMPTY_SPACE; /* EMC */
3335 case 0x6e: return EL_EMPTY_SPACE; /* EMC */
3336 case 0x6f: return EL_EMPTY_SPACE; /* EMC */
3338 case 0x70: return EL_EMPTY_SPACE; /* EMC */
3339 case 0x71: return EL_EMPTY_SPACE; /* EMC */
3340 case 0x72: return EL_NUT; /* left */ /* EMC */
3341 case 0x73: return EL_SAND; /* EMC (? "nut") */
3342 case 0x74: return EL_STEELWALL;
3343 case 0x75: return EL_EMPTY_SPACE; /* EMC */
3344 case 0x76: return EL_EMPTY_SPACE; /* EMC */
3345 case 0x77: return EL_BOMB; /* left */ /* EMC */
3346 case 0x78: return EL_BOMB; /* right */ /* EMC */
3347 case 0x79: return EL_ROCK; /* left */ /* EMC */
3348 case 0x7a: return EL_ROCK; /* right */ /* EMC */
3349 case 0x7b: return EL_ACID; /* (? EMC "blank") */
3350 case 0x7c: return EL_EMPTY_SPACE; /* EMC */
3351 case 0x7d: return EL_EMPTY_SPACE; /* EMC */
3352 case 0x7e: return EL_EMPTY_SPACE; /* EMC */
3353 case 0x7f: return EL_EMPTY_SPACE; /* EMC */
3355 case 0x80: return EL_EMPTY;
3356 case 0x81: return EL_WALL_SLIPPERY;
3357 case 0x82: return EL_SAND;
3358 case 0x83: return EL_STEELWALL;
3359 case 0x84: return EL_WALL;
3360 case 0x85: return EL_EM_KEY_1;
3361 case 0x86: return EL_EM_KEY_2;
3362 case 0x87: return EL_EM_KEY_4;
3363 case 0x88: return EL_EM_KEY_3;
3364 case 0x89: return EL_EM_GATE_1;
3365 case 0x8a: return EL_EM_GATE_2;
3366 case 0x8b: return EL_EM_GATE_4;
3367 case 0x8c: return EL_EM_GATE_3;
3368 case 0x8d: return EL_INVISIBLE_WALL; /* EMC (? "dripper") */
3369 case 0x8e: return EL_EM_GATE_1_GRAY;
3370 case 0x8f: return EL_EM_GATE_2_GRAY;
3372 case 0x90: return EL_EM_GATE_4_GRAY;
3373 case 0x91: return EL_EM_GATE_3_GRAY;
3374 case 0x92: return EL_MAGIC_WALL;
3375 case 0x93: return EL_ROBOT_WHEEL;
3376 case 0x94: return EL_QUICKSAND_EMPTY; /* (? EMC "sand") */
3377 case 0x95: return EL_ACID_POOL_TOPLEFT;
3378 case 0x96: return EL_ACID_POOL_TOPRIGHT;
3379 case 0x97: return EL_ACID_POOL_BOTTOMLEFT;
3380 case 0x98: return EL_ACID_POOL_BOTTOMRIGHT;
3381 case 0x99: return EL_ACID; /* (? EMC "fake blank") */
3382 case 0x9a: return EL_AMOEBA_DEAD; /* 1 */
3383 case 0x9b: return EL_AMOEBA_DEAD; /* 2 */
3384 case 0x9c: return EL_AMOEBA_DEAD; /* 3 */
3385 case 0x9d: return EL_AMOEBA_DEAD; /* 4 */
3386 case 0x9e: return EL_EXIT_CLOSED;
3387 case 0x9f: return EL_CHAR_LESS; /* arrow left */
3389 /* looks like normal sand, but behaves like wall */
3390 case 0xa0: return EL_UNKNOWN; /* EMC ("fake grass") */
3391 case 0xa1: return EL_UNKNOWN; /* EMC ("lenses") */
3392 case 0xa2: return EL_UNKNOWN; /* EMC ("magnify") */
3393 case 0xa3: return EL_UNKNOWN; /* EMC ("fake blank") */
3394 case 0xa4: return EL_UNKNOWN; /* EMC ("fake grass") */
3395 case 0xa5: return EL_UNKNOWN; /* EMC ("switch") */
3396 case 0xa6: return EL_UNKNOWN; /* EMC ("switch") */
3397 case 0xa7: return EL_EMPTY_SPACE; /* EMC */
3398 case 0xa8: return EL_EMC_WALL_1; /* EMC ("decor 8") */
3399 case 0xa9: return EL_EMC_WALL_2; /* EMC ("decor 9") */
3400 case 0xaa: return EL_EMC_WALL_3; /* EMC ("decor 10") */
3401 case 0xab: return EL_EMC_WALL_7; /* EMC ("decor 5") */
3402 case 0xac: return EL_CHAR_COMMA; /* EMC */
3403 case 0xad: return EL_CHAR_QUOTEDBL; /* EMC */
3404 case 0xae: return EL_CHAR_MINUS; /* EMC */
3405 case 0xaf: return EL_DYNAMITE;
3407 case 0xb0: return EL_EMC_STEELWALL_1; /* EMC ("steel 3") */
3408 case 0xb1: return EL_EMC_WALL_8; /* EMC ("decor 6") */
3409 case 0xb2: return EL_UNKNOWN; /* EMC ("decor 7") */
3410 case 0xb3: return EL_STEELWALL; /* 2 */ /* EMC */
3411 case 0xb4: return EL_WALL_SLIPPERY; /* 2 */ /* EMC */
3412 case 0xb5: return EL_EMC_WALL_6; /* EMC ("decor 2") */
3413 case 0xb6: return EL_EMC_WALL_5; /* EMC ("decor 4") */
3414 case 0xb7: return EL_EMC_WALL_4; /* EMC ("decor 3") */
3415 case 0xb8: return EL_BALLOON_SWITCH_ANY; /* EMC */
3416 case 0xb9: return EL_BALLOON_SWITCH_RIGHT; /* EMC */
3417 case 0xba: return EL_BALLOON_SWITCH_DOWN; /* EMC */
3418 case 0xbb: return EL_BALLOON_SWITCH_LEFT; /* EMC */
3419 case 0xbc: return EL_BALLOON_SWITCH_UP; /* EMC */
3420 case 0xbd: return EL_SAND; /* EMC ("dirt") */
3421 case 0xbe: return EL_UNKNOWN; /* EMC ("plant") */
3422 case 0xbf: return EL_UNKNOWN; /* EMC ("key 5") */
3424 case 0xc0: return EL_UNKNOWN; /* EMC ("key 6") */
3425 case 0xc1: return EL_UNKNOWN; /* EMC ("key 7") */
3426 case 0xc2: return EL_UNKNOWN; /* EMC ("key 8") */
3427 case 0xc3: return EL_UNKNOWN; /* EMC ("door 5") */
3428 case 0xc4: return EL_UNKNOWN; /* EMC ("door 6") */
3429 case 0xc5: return EL_UNKNOWN; /* EMC ("door 7") */
3430 case 0xc6: return EL_UNKNOWN; /* EMC ("door 8") */
3431 case 0xc7: return EL_UNKNOWN; /* EMC ("bumper") */
3433 /* characters: see above */
3435 case 0xec: return EL_CHAR_PERIOD;
3436 case 0xed: return EL_CHAR_EXCLAM;
3437 case 0xee: return EL_CHAR_COLON;
3438 case 0xef: return EL_CHAR_QUESTION;
3440 case 0xf0: return EL_CHAR_GREATER; /* arrow right */
3441 case 0xf1: return EL_CHAR_COPYRIGHT; /* EMC: "decor 1" */
3442 case 0xf2: return EL_UNKNOWN; /* EMC ("fake door 5") */
3443 case 0xf3: return EL_UNKNOWN; /* EMC ("fake door 6") */
3444 case 0xf4: return EL_UNKNOWN; /* EMC ("fake door 7") */
3445 case 0xf5: return EL_UNKNOWN; /* EMC ("fake door 8") */
3446 case 0xf6: return EL_EMPTY_SPACE; /* EMC */
3447 case 0xf7: return EL_EMPTY_SPACE; /* EMC */
3449 case 0xf8: return EL_EMPTY_SPACE; /* EMC */
3450 case 0xf9: return EL_EMPTY_SPACE; /* EMC */
3451 case 0xfa: return EL_EMPTY_SPACE; /* EMC */
3452 case 0xfb: return EL_EMPTY_SPACE; /* EMC */
3453 case 0xfc: return EL_EMPTY_SPACE; /* EMC */
3454 case 0xfd: return EL_EMPTY_SPACE; /* EMC */
3456 case 0xfe: return EL_PLAYER_1; /* EMC: "blank" */
3457 case 0xff: return EL_PLAYER_2; /* EMC: "blank" */
3460 /* should never happen (all 8-bit value cases should be handled) */
3461 Error(ERR_WARN, "invalid level element %d", element);
3466 #define EM_LEVEL_SIZE 2106
3467 #define EM_LEVEL_XSIZE 64
3468 #define EM_LEVEL_YSIZE 32
3470 static void OLD_LoadLevelFromFileInfo_EM(struct LevelInfo *level,
3471 struct LevelFileInfo *level_file_info)
3473 char *filename = level_file_info->filename;
3475 unsigned char leveldata[EM_LEVEL_SIZE];
3476 unsigned char *header = &leveldata[EM_LEVEL_XSIZE * EM_LEVEL_YSIZE];
3477 int nr = level_file_info->nr;
3480 if (!(file = fopen(filename, MODE_READ)))
3482 level->no_valid_file = TRUE;
3484 Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename);
3489 for (i = 0; i < EM_LEVEL_SIZE; i++)
3490 leveldata[i] = fgetc(file);
3494 /* check if level data is crypted by testing against known starting bytes
3495 of the few existing crypted level files (from Emerald Mine 1 + 2) */
3497 if ((leveldata[0] == 0xf1 ||
3498 leveldata[0] == 0xf5) && leveldata[2] == 0xe7 && leveldata[3] == 0xee)
3500 unsigned char code0 = 0x65;
3501 unsigned char code1 = 0x11;
3503 if (leveldata[0] == 0xf5) /* error in crypted Emerald Mine 2 levels */
3504 leveldata[0] = 0xf1;
3506 /* decode crypted level data */
3508 for (i = 0; i < EM_LEVEL_SIZE; i++)
3510 leveldata[i] ^= code0;
3511 leveldata[i] -= code1;
3513 code0 = (code0 + 7) & 0xff;
3517 level->fieldx = EM_LEVEL_XSIZE;
3518 level->fieldy = EM_LEVEL_YSIZE;
3520 level->time = header[46] * 10;
3521 level->gems_needed = header[47];
3523 /* The original Emerald Mine levels have their level number stored
3524 at the second byte of the level file...
3525 Do not trust this information at other level files, e.g. EMC,
3526 but correct it anyway (normally the first row is completely
3527 steel wall, so the correction does not hurt anyway). */
3529 if (leveldata[1] == nr)
3530 leveldata[1] = leveldata[2]; /* correct level number field */
3532 sprintf(level->name, "Level %d", nr); /* set level name */
3534 level->score[SC_EMERALD] = header[36];
3535 level->score[SC_DIAMOND] = header[37];
3536 level->score[SC_ROBOT] = header[38];
3537 level->score[SC_SPACESHIP] = header[39];
3538 level->score[SC_BUG] = header[40];
3539 level->score[SC_YAMYAM] = header[41];
3540 level->score[SC_NUT] = header[42];
3541 level->score[SC_DYNAMITE] = header[43];
3542 level->score[SC_TIME_BONUS] = header[44];
3544 level->num_yamyam_contents = 4;
3546 for (i = 0; i < level->num_yamyam_contents; i++)
3547 for (y = 0; y < 3; y++)
3548 for (x = 0; x < 3; x++)
3549 level->yamyam_content[i].e[x][y] =
3550 map_em_element_yam(header[i * 9 + y * 3 + x]);
3552 level->amoeba_speed = (header[52] * 256 + header[53]) % 256;
3553 level->time_magic_wall = (header[54] * 256 + header[55]) * 16 / 100;
3554 level->time_wheel = (header[56] * 256 + header[57]) * 16 / 100;
3555 level->amoeba_content = EL_DIAMOND;
3557 for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++)
3559 int new_element = map_em_element_field(leveldata[y * EM_LEVEL_XSIZE + x]);
3561 if (new_element == EL_AMOEBA_DEAD && level->amoeba_speed)
3562 new_element = EL_AMOEBA_WET;
3564 level->field[x][y] = new_element;
3567 x = (header[48] * 256 + header[49]) % EM_LEVEL_XSIZE;
3568 y = (header[48] * 256 + header[49]) / EM_LEVEL_XSIZE;
3569 level->field[x][y] = EL_PLAYER_1;
3571 x = (header[50] * 256 + header[51]) % EM_LEVEL_XSIZE;
3572 y = (header[50] * 256 + header[51]) / EM_LEVEL_XSIZE;
3573 level->field[x][y] = EL_PLAYER_2;
3578 void CopyNativeLevel_RND_to_EM(struct LevelInfo *level)
3580 static int ball_xy[8][2] =
3591 struct LevelInfo_EM *level_em = level->native_em_level;
3592 struct LEVEL *lev = level_em->lev;
3593 struct PLAYER **ply = level_em->ply;
3596 lev->width = MIN(level->fieldx, EM_MAX_CAVE_WIDTH);
3597 lev->height = MIN(level->fieldy, EM_MAX_CAVE_HEIGHT);
3599 lev->time_seconds = level->time;
3600 lev->required_initial = level->gems_needed;
3602 lev->emerald_score = level->score[SC_EMERALD];
3603 lev->diamond_score = level->score[SC_DIAMOND];
3604 lev->alien_score = level->score[SC_ROBOT];
3605 lev->tank_score = level->score[SC_SPACESHIP];
3606 lev->bug_score = level->score[SC_BUG];
3607 lev->eater_score = level->score[SC_YAMYAM];
3608 lev->nut_score = level->score[SC_NUT];
3609 lev->dynamite_score = level->score[SC_DYNAMITE];
3610 lev->key_score = level->score[SC_KEY];
3611 lev->exit_score = level->score[SC_TIME_BONUS];
3613 for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
3614 for (y = 0; y < 3; y++)
3615 for (x = 0; x < 3; x++)
3616 lev->eater_array[i][y * 3 + x] =
3617 map_element_RND_to_EM(level->yamyam_content[i].e[x][y]);
3619 lev->amoeba_time = level->amoeba_speed;
3620 lev->wonderwall_time_initial = level->time_magic_wall;
3621 lev->wheel_time = level->time_wheel;
3623 lev->android_move_time = level->android_move_time;
3624 lev->android_clone_time = level->android_clone_time;
3625 lev->ball_random = level->ball_random;
3626 lev->ball_state_initial = level->ball_state_initial;
3627 lev->ball_time = level->ball_time;
3628 lev->num_ball_arrays = level->num_ball_contents;
3630 lev->lenses_score = level->lenses_score;
3631 lev->magnify_score = level->magnify_score;
3632 lev->slurp_score = level->slurp_score;
3634 lev->lenses_time = level->lenses_time;
3635 lev->magnify_time = level->magnify_time;
3637 lev->wind_direction_initial =
3638 map_direction_RND_to_EM(level->wind_direction_initial);
3639 lev->wind_cnt_initial = (level->wind_direction_initial != MV_NONE ?
3640 lev->wind_time : 0);
3642 for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
3643 for (j = 0; j < 8; j++)
3644 lev->ball_array[i][j] =
3645 map_element_RND_to_EM(level->
3646 ball_content[i].e[ball_xy[j][0]][ball_xy[j][1]]);
3648 map_android_clone_elements_RND_to_EM(level);
3650 /* first fill the complete playfield with the default border element */
3651 for (y = 0; y < EM_MAX_CAVE_HEIGHT; y++)
3652 for (x = 0; x < EM_MAX_CAVE_WIDTH; x++)
3653 level_em->cave[x][y] = ZBORDER;
3655 if (BorderElement == EL_STEELWALL)
3657 for (y = 0; y < lev->height + 2; y++)
3658 for (x = 0; x < lev->width + 2; x++)
3659 level_em->cave[x + 1][y + 1] = map_element_RND_to_EM(EL_STEELWALL);
3662 /* then copy the real level contents from level file into the playfield */
3663 for (y = 0; y < lev->height; y++) for (x = 0; x < lev->width; x++)
3665 int new_element = map_element_RND_to_EM(level->field[x][y]);
3666 int offset = (BorderElement == EL_STEELWALL ? 1 : 0);
3667 int xx = x + 1 + offset;
3668 int yy = y + 1 + offset;
3670 if (level->field[x][y] == EL_AMOEBA_DEAD)
3671 new_element = map_element_RND_to_EM(EL_AMOEBA_WET);
3673 level_em->cave[xx][yy] = new_element;
3676 for (i = 0; i < MAX_PLAYERS; i++)
3678 ply[i]->x_initial = 0;
3679 ply[i]->y_initial = 0;
3682 /* initialize player positions and delete players from the playfield */
3683 for (y = 0; y < lev->height; y++) for (x = 0; x < lev->width; x++)
3685 if (ELEM_IS_PLAYER(level->field[x][y]))
3687 int player_nr = GET_PLAYER_NR(level->field[x][y]);
3688 int offset = (BorderElement == EL_STEELWALL ? 1 : 0);
3689 int xx = x + 1 + offset;
3690 int yy = y + 1 + offset;
3692 ply[player_nr]->x_initial = xx;
3693 ply[player_nr]->y_initial = yy;
3695 level_em->cave[xx][yy] = map_element_RND_to_EM(EL_EMPTY);
3699 if (BorderElement == EL_STEELWALL)
3706 void CopyNativeLevel_EM_to_RND(struct LevelInfo *level)
3708 static int ball_xy[8][2] =
3719 struct LevelInfo_EM *level_em = level->native_em_level;
3720 struct LEVEL *lev = level_em->lev;
3721 struct PLAYER **ply = level_em->ply;
3724 level->fieldx = MIN(lev->width, MAX_LEV_FIELDX);
3725 level->fieldy = MIN(lev->height, MAX_LEV_FIELDY);
3727 level->time = lev->time_seconds;
3728 level->gems_needed = lev->required_initial;
3730 sprintf(level->name, "Level %d", level->file_info.nr);
3732 level->score[SC_EMERALD] = lev->emerald_score;
3733 level->score[SC_DIAMOND] = lev->diamond_score;
3734 level->score[SC_ROBOT] = lev->alien_score;
3735 level->score[SC_SPACESHIP] = lev->tank_score;
3736 level->score[SC_BUG] = lev->bug_score;
3737 level->score[SC_YAMYAM] = lev->eater_score;
3738 level->score[SC_NUT] = lev->nut_score;
3739 level->score[SC_DYNAMITE] = lev->dynamite_score;
3740 level->score[SC_KEY] = lev->key_score;
3741 level->score[SC_TIME_BONUS] = lev->exit_score;
3743 level->num_yamyam_contents = MAX_ELEMENT_CONTENTS;
3745 for (i = 0; i < level->num_yamyam_contents; i++)
3746 for (y = 0; y < 3; y++)
3747 for (x = 0; x < 3; x++)
3748 level->yamyam_content[i].e[x][y] =
3749 map_element_EM_to_RND(lev->eater_array[i][y * 3 + x]);
3751 level->amoeba_speed = lev->amoeba_time;
3752 level->time_magic_wall = lev->wonderwall_time_initial;
3753 level->time_wheel = lev->wheel_time;
3755 level->android_move_time = lev->android_move_time;
3756 level->android_clone_time = lev->android_clone_time;
3757 level->ball_random = lev->ball_random;
3758 level->ball_state_initial = lev->ball_state_initial;
3759 level->ball_time = lev->ball_time;
3760 level->num_ball_contents = lev->num_ball_arrays;
3762 level->lenses_score = lev->lenses_score;
3763 level->magnify_score = lev->magnify_score;
3764 level->slurp_score = lev->slurp_score;
3766 level->lenses_time = lev->lenses_time;
3767 level->magnify_time = lev->magnify_time;
3769 level->wind_direction_initial =
3770 map_direction_EM_to_RND(lev->wind_direction_initial);
3772 for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
3773 for (j = 0; j < 8; j++)
3774 level->ball_content[i].e[ball_xy[j][0]][ball_xy[j][1]] =
3775 map_element_EM_to_RND(lev->ball_array[i][j]);
3777 map_android_clone_elements_EM_to_RND(level);
3779 /* convert the playfield (some elements need special treatment) */
3780 for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++)
3782 int new_element = map_element_EM_to_RND(level_em->cave[x + 1][y + 1]);
3784 if (new_element == EL_AMOEBA_WET && level->amoeba_speed == 0)
3785 new_element = EL_AMOEBA_DEAD;
3787 level->field[x][y] = new_element;
3790 for (i = 0; i < MAX_PLAYERS; i++)
3792 /* in case of all players set to the same field, use the first player */
3793 int nr = MAX_PLAYERS - i - 1;
3794 int jx = ply[nr]->x_initial - 1;
3795 int jy = ply[nr]->y_initial - 1;
3797 if (jx != -1 && jy != -1)
3798 level->field[jx][jy] = EL_PLAYER_1 + nr;
3802 static void LoadLevelFromFileInfo_EM(struct LevelInfo *level,
3803 struct LevelFileInfo *level_file_info)
3805 if (!LoadNativeLevel_EM(level_file_info->filename))
3806 level->no_valid_file = TRUE;
3809 void CopyNativeLevel_RND_to_Native(struct LevelInfo *level)
3811 if (level->game_engine_type == GAME_ENGINE_TYPE_EM)
3812 CopyNativeLevel_RND_to_EM(level);
3815 void CopyNativeLevel_Native_to_RND(struct LevelInfo *level)
3817 if (level->game_engine_type == GAME_ENGINE_TYPE_EM)
3818 CopyNativeLevel_EM_to_RND(level);
3822 /* ------------------------------------------------------------------------- */
3823 /* functions for loading SP level */
3824 /* ------------------------------------------------------------------------- */
3826 #define NUM_SUPAPLEX_LEVELS_PER_PACKAGE 111
3827 #define SP_LEVEL_SIZE 1536
3828 #define SP_LEVEL_XSIZE 60
3829 #define SP_LEVEL_YSIZE 24
3830 #define SP_LEVEL_NAME_LEN 23
3832 static void LoadLevelFromFileStream_SP(FILE *file, struct LevelInfo *level,
3835 int initial_player_gravity;
3836 int num_special_ports;
3839 /* for details of the Supaplex level format, see Herman Perk's Supaplex
3840 documentation file "SPFIX63.DOC" from his Supaplex "SpeedFix" package */
3842 /* read level body (width * height == 60 * 24 tiles == 1440 bytes) */
3843 for (y = 0; y < SP_LEVEL_YSIZE; y++)
3845 for (x = 0; x < SP_LEVEL_XSIZE; x++)
3847 int element_old = fgetc(file);
3850 if (element_old <= 0x27)
3851 element_new = getMappedElement(EL_SP_START + element_old);
3852 else if (element_old == 0x28)
3853 element_new = EL_INVISIBLE_WALL;
3856 Error(ERR_WARN, "in level %d, at position %d, %d:", nr, x, y);
3857 Error(ERR_WARN, "invalid level element %d", element_old);
3859 element_new = EL_UNKNOWN;
3862 level->field[x][y] = element_new;
3866 ReadUnusedBytesFromFile(file, 4); /* (not used by Supaplex engine) */
3868 /* initial gravity: 1 == "on", anything else (0) == "off" */
3869 initial_player_gravity = (fgetc(file) == 1 ? TRUE : FALSE);
3871 for (i = 0; i < MAX_PLAYERS; i++)
3872 level->initial_player_gravity[i] = initial_player_gravity;
3874 ReadUnusedBytesFromFile(file, 1); /* (not used by Supaplex engine) */
3876 /* level title in uppercase letters, padded with dashes ("-") (23 bytes) */
3877 for (i = 0; i < SP_LEVEL_NAME_LEN; i++)
3878 level->name[i] = fgetc(file);
3879 level->name[SP_LEVEL_NAME_LEN] = '\0';
3881 /* initial "freeze zonks": 2 == "on", anything else (0, 1) == "off" */
3882 ReadUnusedBytesFromFile(file, 1); /* (not used by R'n'D engine) */
3884 /* number of infotrons needed; 0 means that Supaplex will count the total
3885 amount of infotrons in the level and use the low byte of that number
3886 (a multiple of 256 infotrons will result in "0 infotrons needed"!) */
3887 level->gems_needed = fgetc(file);
3889 /* number of special ("gravity") port entries below (maximum 10 allowed) */
3890 num_special_ports = fgetc(file);
3892 /* database of properties of up to 10 special ports (6 bytes per port) */
3893 for (i = 0; i < 10; i++)
3895 int port_location, port_x, port_y, port_element;
3898 /* high and low byte of the location of a special port; if (x, y) are the
3899 coordinates of a port in the field and (0, 0) is the top-left corner,
3900 the 16 bit value here calculates as 2 * (x + (y * 60)) (this is twice
3901 of what may be expected: Supaplex works with a game field in memory
3902 which is 2 bytes per tile) */
3903 port_location = getFile16BitBE(file);
3905 /* change gravity: 1 == "turn on", anything else (0) == "turn off" */
3906 gravity = fgetc(file);
3908 /* "freeze zonks": 2 == "turn on", anything else (0, 1) == "turn off" */
3909 ReadUnusedBytesFromFile(file, 1); /* (not used by R'n'D engine) */
3911 /* "freeze enemies": 1 == "turn on", anything else (0) == "turn off" */
3912 ReadUnusedBytesFromFile(file, 1); /* (not used by R'n'D engine) */
3914 ReadUnusedBytesFromFile(file, 1); /* (not used by Supaplex engine) */
3916 if (i >= num_special_ports)
3919 port_x = (port_location / 2) % SP_LEVEL_XSIZE;
3920 port_y = (port_location / 2) / SP_LEVEL_XSIZE;
3922 if (port_x < 0 || port_x >= SP_LEVEL_XSIZE ||
3923 port_y < 0 || port_y >= SP_LEVEL_YSIZE)
3925 Error(ERR_WARN, "special port position (%d, %d) out of bounds",
3931 port_element = level->field[port_x][port_y];
3933 if (port_element < EL_SP_GRAVITY_PORT_RIGHT ||
3934 port_element > EL_SP_GRAVITY_PORT_UP)
3936 Error(ERR_WARN, "no special port at position (%d, %d)", port_x, port_y);
3941 /* change previous (wrong) gravity inverting special port to either
3942 gravity enabling special port or gravity disabling special port */
3943 level->field[port_x][port_y] +=
3944 (gravity == 1 ? EL_SP_GRAVITY_ON_PORT_RIGHT :
3945 EL_SP_GRAVITY_OFF_PORT_RIGHT) - EL_SP_GRAVITY_PORT_RIGHT;
3948 ReadUnusedBytesFromFile(file, 4); /* (not used by Supaplex engine) */
3950 /* change special gravity ports without database entries to normal ports */
3951 for (y = 0; y < SP_LEVEL_YSIZE; y++)
3952 for (x = 0; x < SP_LEVEL_XSIZE; x++)
3953 if (level->field[x][y] >= EL_SP_GRAVITY_PORT_RIGHT &&
3954 level->field[x][y] <= EL_SP_GRAVITY_PORT_UP)
3955 level->field[x][y] += EL_SP_PORT_RIGHT - EL_SP_GRAVITY_PORT_RIGHT;
3957 /* auto-determine number of infotrons if it was stored as "0" -- see above */
3958 if (level->gems_needed == 0)
3960 for (y = 0; y < SP_LEVEL_YSIZE; y++)
3961 for (x = 0; x < SP_LEVEL_XSIZE; x++)
3962 if (level->field[x][y] == EL_SP_INFOTRON)
3963 level->gems_needed++;
3965 level->gems_needed &= 0xff; /* only use low byte -- see above */
3968 level->fieldx = SP_LEVEL_XSIZE;
3969 level->fieldy = SP_LEVEL_YSIZE;
3971 level->time = 0; /* no time limit */
3972 level->amoeba_speed = 0;
3973 level->time_magic_wall = 0;
3974 level->time_wheel = 0;
3975 level->amoeba_content = EL_EMPTY;
3978 /* original Supaplex does not use score values -- use default values */
3980 for (i = 0; i < LEVEL_SCORE_ELEMENTS; i++)
3981 level->score[i] = 0;
3984 /* there are no yamyams in supaplex levels */
3985 for (i = 0; i < level->num_yamyam_contents; i++)
3986 for (y = 0; y < 3; y++)
3987 for (x = 0; x < 3; x++)
3988 level->yamyam_content[i].e[x][y] = EL_EMPTY;
3991 static void LoadLevelFromFileInfo_SP(struct LevelInfo *level,
3992 struct LevelFileInfo *level_file_info)
3994 char *filename = level_file_info->filename;
3996 int nr = level_file_info->nr - leveldir_current->first_level;
3998 char name_first, name_last;
3999 struct LevelInfo multipart_level;
4000 int multipart_xpos, multipart_ypos;
4001 boolean is_multipart_level;
4002 boolean is_first_part;
4003 boolean reading_multipart_level = FALSE;
4004 boolean use_empty_level = FALSE;
4006 if (!(file = fopen(filename, MODE_READ)))
4008 level->no_valid_file = TRUE;
4010 Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename);
4015 /* position file stream to the requested level inside the level package */
4016 if (fseek(file, nr * SP_LEVEL_SIZE, SEEK_SET) != 0)
4018 level->no_valid_file = TRUE;
4020 Error(ERR_WARN, "cannot fseek in file '%s' -- using empty level", filename);
4025 /* there exist Supaplex level package files with multi-part levels which
4026 can be detected as follows: instead of leading and trailing dashes ('-')
4027 to pad the level name, they have leading and trailing numbers which are
4028 the x and y coordinations of the current part of the multi-part level;
4029 if there are '?' characters instead of numbers on the left or right side
4030 of the level name, the multi-part level consists of only horizontal or
4033 for (l = nr; l < NUM_SUPAPLEX_LEVELS_PER_PACKAGE; l++)
4035 LoadLevelFromFileStream_SP(file, level, l);
4037 /* check if this level is a part of a bigger multi-part level */
4039 name_first = level->name[0];
4040 name_last = level->name[SP_LEVEL_NAME_LEN - 1];
4042 is_multipart_level =
4043 ((name_first == '?' || (name_first >= '0' && name_first <= '9')) &&
4044 (name_last == '?' || (name_last >= '0' && name_last <= '9')));
4047 ((name_first == '?' || name_first == '1') &&
4048 (name_last == '?' || name_last == '1'));
4050 /* correct leading multipart level meta information in level name */
4051 for (i = 0; i < SP_LEVEL_NAME_LEN && level->name[i] == name_first; i++)
4052 level->name[i] = '-';
4054 /* correct trailing multipart level meta information in level name */
4055 for (i = SP_LEVEL_NAME_LEN - 1; i >= 0 && level->name[i] == name_last; i--)
4056 level->name[i] = '-';
4058 /* ---------- check for normal single level ---------- */
4060 if (!reading_multipart_level && !is_multipart_level)
4062 /* the current level is simply a normal single-part level, and we are
4063 not reading a multi-part level yet, so return the level as it is */
4068 /* ---------- check for empty level (unused multi-part) ---------- */
4070 if (!reading_multipart_level && is_multipart_level && !is_first_part)
4072 /* this is a part of a multi-part level, but not the first part
4073 (and we are not already reading parts of a multi-part level);
4074 in this case, use an empty level instead of the single part */
4076 use_empty_level = TRUE;
4081 /* ---------- check for finished multi-part level ---------- */
4083 if (reading_multipart_level &&
4084 (!is_multipart_level ||
4085 !strEqual(level->name, multipart_level.name)))
4087 /* we are already reading parts of a multi-part level, but this level is
4088 either not a multi-part level, or a part of a different multi-part
4089 level; in both cases, the multi-part level seems to be complete */
4094 /* ---------- here we have one part of a multi-part level ---------- */
4096 reading_multipart_level = TRUE;
4098 if (is_first_part) /* start with first part of new multi-part level */
4100 /* copy level info structure from first part */
4101 multipart_level = *level;
4103 /* clear playfield of new multi-part level */
4104 for (y = 0; y < MAX_LEV_FIELDY; y++)
4105 for (x = 0; x < MAX_LEV_FIELDX; x++)
4106 multipart_level.field[x][y] = EL_EMPTY;
4109 if (name_first == '?')
4111 if (name_last == '?')
4114 multipart_xpos = (int)(name_first - '0');
4115 multipart_ypos = (int)(name_last - '0');
4118 printf("----------> part (%d/%d) of multi-part level '%s'\n",
4119 multipart_xpos, multipart_ypos, multipart_level.name);
4122 if (multipart_xpos * SP_LEVEL_XSIZE > MAX_LEV_FIELDX ||
4123 multipart_ypos * SP_LEVEL_YSIZE > MAX_LEV_FIELDY)
4125 Error(ERR_WARN, "multi-part level is too big -- ignoring part of it");
4130 multipart_level.fieldx = MAX(multipart_level.fieldx,
4131 multipart_xpos * SP_LEVEL_XSIZE);
4132 multipart_level.fieldy = MAX(multipart_level.fieldy,
4133 multipart_ypos * SP_LEVEL_YSIZE);
4135 /* copy level part at the right position of multi-part level */
4136 for (y = 0; y < SP_LEVEL_YSIZE; y++)
4138 for (x = 0; x < SP_LEVEL_XSIZE; x++)
4140 int start_x = (multipart_xpos - 1) * SP_LEVEL_XSIZE;
4141 int start_y = (multipart_ypos - 1) * SP_LEVEL_YSIZE;
4143 multipart_level.field[start_x + x][start_y + y] = level->field[x][y];
4150 if (use_empty_level)
4152 setLevelInfoToDefaults(level);
4154 level->fieldx = SP_LEVEL_XSIZE;
4155 level->fieldy = SP_LEVEL_YSIZE;
4157 for (y = 0; y < SP_LEVEL_YSIZE; y++)
4158 for (x = 0; x < SP_LEVEL_XSIZE; x++)
4159 level->field[x][y] = EL_EMPTY;
4161 strcpy(level->name, "-------- EMPTY --------");
4163 Error(ERR_WARN, "single part of multi-part level -- using empty level");
4166 if (reading_multipart_level)
4167 *level = multipart_level;
4171 #define DC_LEVEL_HEADER_SIZE 344
4173 unsigned short getDecodedWord_DC(unsigned short data_encoded, boolean init)
4175 static int last_data_encoded;
4179 int diff_hi, diff_lo;
4180 int data_hi, data_lo;
4181 unsigned short data_decoded;
4185 last_data_encoded = 0;
4192 diff = data_encoded - last_data_encoded;
4193 diff_hi = diff & ~0xff;
4194 diff_lo = diff & 0xff;
4198 data_hi = diff_hi - (offset1 << 8) + (offset2 & 0xff00);
4199 data_lo = (diff_lo + (data_hi >> 16)) & 0x00ff;
4200 data_hi = data_hi & 0xff00;
4202 data_decoded = data_hi | data_lo;
4204 last_data_encoded = data_encoded;
4206 offset1 = (offset1 + 1) % 31;
4207 offset2 = offset2 & 0xff;
4209 return data_decoded;
4212 int getMappedElement_DC(int element)
4220 /* 0x0117 - 0x036e: (?) */
4223 /* 0x042d - 0x0684: (?) */
4239 element = EL_CRYSTAL;
4242 case 0x0e77: /* quicksand (boulder) */
4243 element = EL_QUICKSAND_FAST_FULL;
4246 case 0x0e99: /* slow quicksand (boulder) */
4247 element = EL_QUICKSAND_FULL;
4251 element = EL_EM_EXIT_OPEN;
4255 element = EL_EM_EXIT_CLOSED;
4259 element = EL_EM_STEEL_EXIT_OPEN;
4263 element = EL_EM_STEEL_EXIT_CLOSED;
4266 case 0x0f4f: /* dynamite (lit 1) */
4267 element = EL_EM_DYNAMITE_ACTIVE;
4270 case 0x0f57: /* dynamite (lit 2) */
4271 element = EL_EM_DYNAMITE_ACTIVE;
4274 case 0x0f5f: /* dynamite (lit 3) */
4275 element = EL_EM_DYNAMITE_ACTIVE;
4278 case 0x0f67: /* dynamite (lit 4) */
4279 element = EL_EM_DYNAMITE_ACTIVE;
4286 element = EL_AMOEBA_WET;
4290 element = EL_AMOEBA_DROP;
4294 element = EL_DC_MAGIC_WALL;
4298 element = EL_SPACESHIP_UP;
4302 element = EL_SPACESHIP_DOWN;
4306 element = EL_SPACESHIP_LEFT;
4310 element = EL_SPACESHIP_RIGHT;
4314 element = EL_BUG_UP;
4318 element = EL_BUG_DOWN;
4322 element = EL_BUG_LEFT;
4326 element = EL_BUG_RIGHT;
4330 element = EL_MOLE_UP;
4334 element = EL_MOLE_DOWN;
4338 element = EL_MOLE_LEFT;
4342 element = EL_MOLE_RIGHT;
4350 element = EL_YAMYAM;
4354 element = EL_SWITCHGATE_OPEN;
4358 element = EL_SWITCHGATE_CLOSED;
4362 element = EL_DC_SWITCHGATE_SWITCH_UP;
4366 element = EL_TIMEGATE_CLOSED;
4369 case 0x144c: /* conveyor belt switch (green) */
4370 element = EL_CONVEYOR_BELT_3_SWITCH_MIDDLE;
4373 case 0x144f: /* conveyor belt switch (red) */
4374 element = EL_CONVEYOR_BELT_1_SWITCH_MIDDLE;
4377 case 0x1452: /* conveyor belt switch (blue) */
4378 element = EL_CONVEYOR_BELT_4_SWITCH_MIDDLE;
4382 element = EL_CONVEYOR_BELT_3_MIDDLE;
4386 element = EL_CONVEYOR_BELT_3_LEFT;
4390 element = EL_CONVEYOR_BELT_3_RIGHT;
4394 element = EL_CONVEYOR_BELT_1_MIDDLE;
4398 element = EL_CONVEYOR_BELT_1_LEFT;
4402 element = EL_CONVEYOR_BELT_1_RIGHT;
4406 element = EL_CONVEYOR_BELT_4_MIDDLE;
4410 element = EL_CONVEYOR_BELT_4_LEFT;
4414 element = EL_CONVEYOR_BELT_4_RIGHT;
4418 element = EL_EXPANDABLE_WALL_HORIZONTAL;
4422 element = EL_EXPANDABLE_WALL_VERTICAL;
4426 element = EL_EXPANDABLE_WALL_ANY;
4429 case 0x14ce: /* growing steel wall (left/right) */
4430 element = EL_EXPANDABLE_STEELWALL_HORIZONTAL;
4433 case 0x14df: /* growing steel wall (up/down) */
4434 element = EL_EXPANDABLE_STEELWALL_VERTICAL;
4437 case 0x14e8: /* growing steel wall (up/down/left/right) */
4438 element = EL_EXPANDABLE_STEELWALL_ANY;
4442 element = EL_SHIELD_DEADLY;
4446 element = EL_EXTRA_TIME;
4454 element = EL_EMPTY_SPACE;
4457 case 0x1578: /* quicksand (empty) */
4458 element = EL_QUICKSAND_FAST_EMPTY;
4461 case 0x1579: /* slow quicksand (empty) */
4462 element = EL_QUICKSAND_EMPTY;
4465 /* 0x157c - 0x158b: */
4468 /* 0x1590 - 0x159f: */
4469 /* EL_DC_LANDMINE */
4472 element = EL_EM_DYNAMITE;
4475 case 0x15a1: /* key (red) */
4476 element = EL_EM_KEY_1;
4479 case 0x15a2: /* key (yellow) */
4480 element = EL_EM_KEY_2;
4483 case 0x15a3: /* key (blue) */
4484 element = EL_EM_KEY_4;
4487 case 0x15a4: /* key (green) */
4488 element = EL_EM_KEY_3;
4491 case 0x15a5: /* key (white) */
4492 element = EL_DC_KEY_WHITE;
4496 element = EL_WALL_SLIPPERY;
4503 case 0x15a8: /* wall (not round) */
4507 case 0x15a9: /* (blue) */
4508 element = EL_CHAR_A;
4511 case 0x15aa: /* (blue) */
4512 element = EL_CHAR_B;
4515 case 0x15ab: /* (blue) */
4516 element = EL_CHAR_C;
4519 case 0x15ac: /* (blue) */
4520 element = EL_CHAR_D;
4523 case 0x15ad: /* (blue) */
4524 element = EL_CHAR_E;
4527 case 0x15ae: /* (blue) */
4528 element = EL_CHAR_F;
4531 case 0x15af: /* (blue) */
4532 element = EL_CHAR_G;
4535 case 0x15b0: /* (blue) */
4536 element = EL_CHAR_H;
4539 case 0x15b1: /* (blue) */
4540 element = EL_CHAR_I;
4543 case 0x15b2: /* (blue) */
4544 element = EL_CHAR_J;
4547 case 0x15b3: /* (blue) */
4548 element = EL_CHAR_K;
4551 case 0x15b4: /* (blue) */
4552 element = EL_CHAR_L;
4555 case 0x15b5: /* (blue) */
4556 element = EL_CHAR_M;
4559 case 0x15b6: /* (blue) */
4560 element = EL_CHAR_N;
4563 case 0x15b7: /* (blue) */
4564 element = EL_CHAR_O;
4567 case 0x15b8: /* (blue) */
4568 element = EL_CHAR_P;
4571 case 0x15b9: /* (blue) */
4572 element = EL_CHAR_Q;
4575 case 0x15ba: /* (blue) */
4576 element = EL_CHAR_R;
4579 case 0x15bb: /* (blue) */
4580 element = EL_CHAR_S;
4583 case 0x15bc: /* (blue) */
4584 element = EL_CHAR_T;
4587 case 0x15bd: /* (blue) */
4588 element = EL_CHAR_U;
4591 case 0x15be: /* (blue) */
4592 element = EL_CHAR_V;
4595 case 0x15bf: /* (blue) */
4596 element = EL_CHAR_W;
4599 case 0x15c0: /* (blue) */
4600 element = EL_CHAR_X;
4603 case 0x15c1: /* (blue) */
4604 element = EL_CHAR_Y;
4607 case 0x15c2: /* (blue) */
4608 element = EL_CHAR_Z;
4611 case 0x15c3: /* (blue) */
4612 element = EL_CHAR_AUMLAUT;
4615 case 0x15c4: /* (blue) */
4616 element = EL_CHAR_OUMLAUT;
4619 case 0x15c5: /* (blue) */
4620 element = EL_CHAR_UUMLAUT;
4623 case 0x15c6: /* (blue) */
4624 element = EL_CHAR_0;
4627 case 0x15c7: /* (blue) */
4628 element = EL_CHAR_1;
4631 case 0x15c8: /* (blue) */
4632 element = EL_CHAR_2;
4635 case 0x15c9: /* (blue) */
4636 element = EL_CHAR_3;
4639 case 0x15ca: /* (blue) */
4640 element = EL_CHAR_4;
4643 case 0x15cb: /* (blue) */
4644 element = EL_CHAR_5;
4647 case 0x15cc: /* (blue) */
4648 element = EL_CHAR_6;
4651 case 0x15cd: /* (blue) */
4652 element = EL_CHAR_7;
4655 case 0x15ce: /* (blue) */
4656 element = EL_CHAR_8;
4659 case 0x15cf: /* (blue) */
4660 element = EL_CHAR_9;
4663 case 0x15d0: /* (blue) */
4664 element = EL_CHAR_PERIOD;
4667 case 0x15d1: /* (blue) */
4668 element = EL_CHAR_EXCLAM;
4671 case 0x15d2: /* (blue) */
4672 element = EL_CHAR_COLON;
4675 case 0x15d3: /* (blue) */
4676 element = EL_CHAR_LESS;
4679 case 0x15d4: /* (blue) */
4680 element = EL_CHAR_GREATER;
4683 case 0x15d5: /* (blue) */
4684 element = EL_CHAR_QUESTION;
4687 case 0x15d6: /* (blue) */
4688 element = EL_CHAR_COPYRIGHT;
4691 case 0x15d7: /* (blue) */
4692 element = EL_CHAR_UP;
4695 case 0x15d8: /* (blue) */
4696 element = EL_CHAR_DOWN;
4699 case 0x15d9: /* (blue) */
4700 element = EL_CHAR_BUTTON;
4703 case 0x15da: /* (blue) */
4704 element = EL_CHAR_PLUS;
4707 case 0x15db: /* (blue) */
4708 element = EL_CHAR_MINUS;
4711 case 0x15dc: /* (blue) */
4712 element = EL_CHAR_APOSTROPHE;
4715 case 0x15dd: /* (blue) */
4716 element = EL_CHAR_PARENLEFT;
4719 case 0x15de: /* (blue) */
4720 element = EL_CHAR_PARENRIGHT;
4723 case 0x15df: /* (green) */
4724 element = EL_CHAR_A;
4727 case 0x15e0: /* (green) */
4728 element = EL_CHAR_B;
4731 case 0x15e1: /* (green) */
4732 element = EL_CHAR_C;
4735 case 0x15e2: /* (green) */
4736 element = EL_CHAR_D;
4739 case 0x15e3: /* (green) */
4740 element = EL_CHAR_E;
4743 case 0x15e4: /* (green) */
4744 element = EL_CHAR_F;
4747 case 0x15e5: /* (green) */
4748 element = EL_CHAR_G;
4751 case 0x15e6: /* (green) */
4752 element = EL_CHAR_H;
4755 case 0x15e7: /* (green) */
4756 element = EL_CHAR_I;
4759 case 0x15e8: /* (green) */
4760 element = EL_CHAR_J;
4763 case 0x15e9: /* (green) */
4764 element = EL_CHAR_K;
4767 case 0x15ea: /* (green) */
4768 element = EL_CHAR_L;
4771 case 0x15eb: /* (green) */
4772 element = EL_CHAR_M;
4775 case 0x15ec: /* (green) */
4776 element = EL_CHAR_N;
4779 case 0x15ed: /* (green) */
4780 element = EL_CHAR_O;
4783 case 0x15ee: /* (green) */
4784 element = EL_CHAR_P;
4787 case 0x15ef: /* (green) */
4788 element = EL_CHAR_Q;
4791 case 0x15f0: /* (green) */
4792 element = EL_CHAR_R;
4795 case 0x15f1: /* (green) */
4796 element = EL_CHAR_S;
4799 case 0x15f2: /* (green) */
4800 element = EL_CHAR_T;
4803 case 0x15f3: /* (green) */
4804 element = EL_CHAR_U;
4807 case 0x15f4: /* (green) */
4808 element = EL_CHAR_V;
4811 case 0x15f5: /* (green) */
4812 element = EL_CHAR_W;
4815 case 0x15f6: /* (green) */
4816 element = EL_CHAR_X;
4819 case 0x15f7: /* (green) */
4820 element = EL_CHAR_Y;
4823 case 0x15f8: /* (green) */
4824 element = EL_CHAR_Z;
4827 case 0x15f9: /* (green) */
4828 element = EL_CHAR_AUMLAUT;
4831 case 0x15fa: /* (green) */
4832 element = EL_CHAR_OUMLAUT;
4835 case 0x15fb: /* (green) */
4836 element = EL_CHAR_UUMLAUT;
4839 case 0x15fc: /* (green) */
4840 element = EL_CHAR_0;
4843 case 0x15fd: /* (green) */
4844 element = EL_CHAR_1;
4847 case 0x15fe: /* (green) */
4848 element = EL_CHAR_2;
4851 case 0x15ff: /* (green) */
4852 element = EL_CHAR_3;
4855 case 0x1600: /* (green) */
4856 element = EL_CHAR_4;
4859 case 0x1601: /* (green) */
4860 element = EL_CHAR_5;
4863 case 0x1602: /* (green) */
4864 element = EL_CHAR_6;
4867 case 0x1603: /* (green) */
4868 element = EL_CHAR_7;
4871 case 0x1604: /* (green) */
4872 element = EL_CHAR_8;
4875 case 0x1605: /* (green) */
4876 element = EL_CHAR_9;
4879 case 0x1606: /* (green) */
4880 element = EL_CHAR_PERIOD;
4883 case 0x1607: /* (green) */
4884 element = EL_CHAR_EXCLAM;
4887 case 0x1608: /* (green) */
4888 element = EL_CHAR_COLON;
4891 case 0x1609: /* (green) */
4892 element = EL_CHAR_LESS;
4895 case 0x160a: /* (green) */
4896 element = EL_CHAR_GREATER;
4899 case 0x160b: /* (green) */
4900 element = EL_CHAR_QUESTION;
4903 case 0x160c: /* (green) */
4904 element = EL_CHAR_COPYRIGHT;
4907 case 0x160d: /* (green) */
4908 element = EL_CHAR_UP;
4911 case 0x160e: /* (green) */
4912 element = EL_CHAR_DOWN;
4915 case 0x160f: /* (green) */
4916 element = EL_CHAR_BUTTON;
4919 case 0x1610: /* (green) */
4920 element = EL_CHAR_PLUS;
4923 case 0x1611: /* (green) */
4924 element = EL_CHAR_MINUS;
4927 case 0x1612: /* (green) */
4928 element = EL_CHAR_APOSTROPHE;
4931 case 0x1613: /* (green) */
4932 element = EL_CHAR_PARENLEFT;
4935 case 0x1614: /* (green) */
4936 element = EL_CHAR_PARENRIGHT;
4939 case 0x1615: /* (blue steel) */
4940 element = EL_STEEL_CHAR_A;
4943 case 0x1616: /* (blue steel) */
4944 element = EL_STEEL_CHAR_B;
4947 case 0x1617: /* (blue steel) */
4948 element = EL_STEEL_CHAR_C;
4951 case 0x1618: /* (blue steel) */
4952 element = EL_STEEL_CHAR_D;
4955 case 0x1619: /* (blue steel) */
4956 element = EL_STEEL_CHAR_E;
4959 case 0x161a: /* (blue steel) */
4960 element = EL_STEEL_CHAR_F;
4963 case 0x161b: /* (blue steel) */
4964 element = EL_STEEL_CHAR_G;
4967 case 0x161c: /* (blue steel) */
4968 element = EL_STEEL_CHAR_H;
4971 case 0x161d: /* (blue steel) */
4972 element = EL_STEEL_CHAR_I;
4975 case 0x161e: /* (blue steel) */
4976 element = EL_STEEL_CHAR_J;
4979 case 0x161f: /* (blue steel) */
4980 element = EL_STEEL_CHAR_K;
4983 case 0x1620: /* (blue steel) */
4984 element = EL_STEEL_CHAR_L;
4987 case 0x1621: /* (blue steel) */
4988 element = EL_STEEL_CHAR_M;
4991 case 0x1622: /* (blue steel) */
4992 element = EL_STEEL_CHAR_N;
4995 case 0x1623: /* (blue steel) */
4996 element = EL_STEEL_CHAR_O;
4999 case 0x1624: /* (blue steel) */
5000 element = EL_STEEL_CHAR_P;
5003 case 0x1625: /* (blue steel) */
5004 element = EL_STEEL_CHAR_Q;
5007 case 0x1626: /* (blue steel) */
5008 element = EL_STEEL_CHAR_R;
5011 case 0x1627: /* (blue steel) */
5012 element = EL_STEEL_CHAR_S;
5015 case 0x1628: /* (blue steel) */
5016 element = EL_STEEL_CHAR_T;
5019 case 0x1629: /* (blue steel) */
5020 element = EL_STEEL_CHAR_U;
5023 case 0x162a: /* (blue steel) */
5024 element = EL_STEEL_CHAR_V;
5027 case 0x162b: /* (blue steel) */
5028 element = EL_STEEL_CHAR_W;
5031 case 0x162c: /* (blue steel) */
5032 element = EL_STEEL_CHAR_X;
5035 case 0x162d: /* (blue steel) */
5036 element = EL_STEEL_CHAR_Y;
5039 case 0x162e: /* (blue steel) */
5040 element = EL_STEEL_CHAR_Z;
5043 case 0x162f: /* (blue steel) */
5044 element = EL_STEEL_CHAR_AUMLAUT;
5047 case 0x1630: /* (blue steel) */
5048 element = EL_STEEL_CHAR_OUMLAUT;
5051 case 0x1631: /* (blue steel) */
5052 element = EL_STEEL_CHAR_UUMLAUT;
5055 case 0x1632: /* (blue steel) */
5056 element = EL_STEEL_CHAR_0;
5059 case 0x1633: /* (blue steel) */
5060 element = EL_STEEL_CHAR_1;
5063 case 0x1634: /* (blue steel) */
5064 element = EL_STEEL_CHAR_2;
5067 case 0x1635: /* (blue steel) */
5068 element = EL_STEEL_CHAR_3;
5071 case 0x1636: /* (blue steel) */
5072 element = EL_STEEL_CHAR_4;
5075 case 0x1637: /* (blue steel) */
5076 element = EL_STEEL_CHAR_5;
5079 case 0x1638: /* (blue steel) */
5080 element = EL_STEEL_CHAR_6;
5083 case 0x1639: /* (blue steel) */
5084 element = EL_STEEL_CHAR_7;
5087 case 0x163a: /* (blue steel) */
5088 element = EL_STEEL_CHAR_8;
5091 case 0x163b: /* (blue steel) */
5092 element = EL_STEEL_CHAR_9;
5095 case 0x163c: /* (blue steel) */
5096 element = EL_STEEL_CHAR_PERIOD;
5099 case 0x163d: /* (blue steel) */
5100 element = EL_STEEL_CHAR_EXCLAM;
5103 case 0x163e: /* (blue steel) */
5104 element = EL_STEEL_CHAR_COLON;
5107 case 0x163f: /* (blue steel) */
5108 element = EL_STEEL_CHAR_LESS;
5111 case 0x1640: /* (blue steel) */
5112 element = EL_STEEL_CHAR_GREATER;
5115 case 0x1641: /* (blue steel) */
5116 element = EL_STEEL_CHAR_QUESTION;
5119 case 0x1642: /* (blue steel) */
5120 element = EL_STEEL_CHAR_COPYRIGHT;
5123 case 0x1643: /* (blue steel) */
5124 element = EL_STEEL_CHAR_UP;
5127 case 0x1644: /* (blue steel) */
5128 element = EL_STEEL_CHAR_DOWN;
5131 case 0x1645: /* (blue steel) */
5132 element = EL_STEEL_CHAR_BUTTON;
5135 case 0x1646: /* (blue steel) */
5136 element = EL_STEEL_CHAR_PLUS;
5139 case 0x1647: /* (blue steel) */
5140 element = EL_STEEL_CHAR_MINUS;
5143 case 0x1648: /* (blue steel) */
5144 element = EL_STEEL_CHAR_APOSTROPHE;
5147 case 0x1649: /* (blue steel) */
5148 element = EL_STEEL_CHAR_PARENLEFT;
5151 case 0x164a: /* (blue steel) */
5152 element = EL_STEEL_CHAR_PARENRIGHT;
5155 case 0x164b: /* (green steel) */
5156 element = EL_STEEL_CHAR_A;
5159 case 0x164c: /* (green steel) */
5160 element = EL_STEEL_CHAR_B;
5163 case 0x164d: /* (green steel) */
5164 element = EL_STEEL_CHAR_C;
5167 case 0x164e: /* (green steel) */
5168 element = EL_STEEL_CHAR_D;
5171 case 0x164f: /* (green steel) */
5172 element = EL_STEEL_CHAR_E;
5175 case 0x1650: /* (green steel) */
5176 element = EL_STEEL_CHAR_F;
5179 case 0x1651: /* (green steel) */
5180 element = EL_STEEL_CHAR_G;
5183 case 0x1652: /* (green steel) */
5184 element = EL_STEEL_CHAR_H;
5187 case 0x1653: /* (green steel) */
5188 element = EL_STEEL_CHAR_I;
5191 case 0x1654: /* (green steel) */
5192 element = EL_STEEL_CHAR_J;
5195 case 0x1655: /* (green steel) */
5196 element = EL_STEEL_CHAR_K;
5199 case 0x1656: /* (green steel) */
5200 element = EL_STEEL_CHAR_L;
5203 case 0x1657: /* (green steel) */
5204 element = EL_STEEL_CHAR_M;
5207 case 0x1658: /* (green steel) */
5208 element = EL_STEEL_CHAR_N;
5211 case 0x1659: /* (green steel) */
5212 element = EL_STEEL_CHAR_O;
5215 case 0x165a: /* (green steel) */
5216 element = EL_STEEL_CHAR_P;
5219 case 0x165b: /* (green steel) */
5220 element = EL_STEEL_CHAR_Q;
5223 case 0x165c: /* (green steel) */
5224 element = EL_STEEL_CHAR_R;
5227 case 0x165d: /* (green steel) */
5228 element = EL_STEEL_CHAR_S;
5231 case 0x165e: /* (green steel) */
5232 element = EL_STEEL_CHAR_T;
5235 case 0x165f: /* (green steel) */
5236 element = EL_STEEL_CHAR_U;
5239 case 0x1660: /* (green steel) */
5240 element = EL_STEEL_CHAR_V;
5243 case 0x1661: /* (green steel) */
5244 element = EL_STEEL_CHAR_W;
5247 case 0x1662: /* (green steel) */
5248 element = EL_STEEL_CHAR_X;
5251 case 0x1663: /* (green steel) */
5252 element = EL_STEEL_CHAR_Y;
5255 case 0x1664: /* (green steel) */
5256 element = EL_STEEL_CHAR_Z;
5259 case 0x1665: /* (green steel) */
5260 element = EL_STEEL_CHAR_AUMLAUT;
5263 case 0x1666: /* (green steel) */
5264 element = EL_STEEL_CHAR_OUMLAUT;
5267 case 0x1667: /* (green steel) */
5268 element = EL_STEEL_CHAR_UUMLAUT;
5271 case 0x1668: /* (green steel) */
5272 element = EL_STEEL_CHAR_0;
5275 case 0x1669: /* (green steel) */
5276 element = EL_STEEL_CHAR_1;
5279 case 0x166a: /* (green steel) */
5280 element = EL_STEEL_CHAR_2;
5283 case 0x166b: /* (green steel) */
5284 element = EL_STEEL_CHAR_3;
5287 case 0x166c: /* (green steel) */
5288 element = EL_STEEL_CHAR_4;
5291 case 0x166d: /* (green steel) */
5292 element = EL_STEEL_CHAR_5;
5295 case 0x166e: /* (green steel) */
5296 element = EL_STEEL_CHAR_6;
5299 case 0x166f: /* (green steel) */
5300 element = EL_STEEL_CHAR_7;
5303 case 0x1670: /* (green steel) */
5304 element = EL_STEEL_CHAR_8;
5307 case 0x1671: /* (green steel) */
5308 element = EL_STEEL_CHAR_9;
5311 case 0x1672: /* (green steel) */
5312 element = EL_STEEL_CHAR_PERIOD;
5315 case 0x1673: /* (green steel) */
5316 element = EL_STEEL_CHAR_EXCLAM;
5319 case 0x1674: /* (green steel) */
5320 element = EL_STEEL_CHAR_COLON;
5323 case 0x1675: /* (green steel) */
5324 element = EL_STEEL_CHAR_LESS;
5327 case 0x1676: /* (green steel) */
5328 element = EL_STEEL_CHAR_GREATER;
5331 case 0x1677: /* (green steel) */
5332 element = EL_STEEL_CHAR_QUESTION;
5335 case 0x1678: /* (green steel) */
5336 element = EL_STEEL_CHAR_COPYRIGHT;
5339 case 0x1679: /* (green steel) */
5340 element = EL_STEEL_CHAR_UP;
5343 case 0x167a: /* (green steel) */
5344 element = EL_STEEL_CHAR_DOWN;
5347 case 0x167b: /* (green steel) */
5348 element = EL_STEEL_CHAR_BUTTON;
5351 case 0x167c: /* (green steel) */
5352 element = EL_STEEL_CHAR_PLUS;
5355 case 0x167d: /* (green steel) */
5356 element = EL_STEEL_CHAR_MINUS;
5359 case 0x167e: /* (green steel) */
5360 element = EL_STEEL_CHAR_APOSTROPHE;
5363 case 0x167f: /* (green steel) */
5364 element = EL_STEEL_CHAR_PARENLEFT;
5367 case 0x1680: /* (green steel) */
5368 element = EL_STEEL_CHAR_PARENRIGHT;
5371 case 0x1681: /* gate (red) */
5372 element = EL_EM_GATE_1;
5375 case 0x1682: /* secret gate (red) */
5376 element = EL_GATE_1_GRAY;
5379 case 0x1683: /* gate (yellow) */
5380 element = EL_EM_GATE_2;
5383 case 0x1684: /* secret gate (yellow) */
5384 element = EL_GATE_2_GRAY;
5387 case 0x1685: /* gate (blue) */
5388 element = EL_EM_GATE_4;
5391 case 0x1686: /* secret gate (blue) */
5392 element = EL_GATE_4_GRAY;
5395 case 0x1687: /* gate (green) */
5396 element = EL_EM_GATE_3;
5399 case 0x1688: /* secret gate (green) */
5400 element = EL_GATE_3_GRAY;
5403 case 0x1689: /* gate (white) */
5404 element = EL_DC_GATE_WHITE;
5407 case 0x168a: /* secret gate (white) */
5408 element = EL_DC_GATE_WHITE_GRAY;
5411 case 0x168b: /* secret gate (no key) */
5412 element = EL_DC_GATE_FAKE_GRAY;
5416 element = EL_ROBOT_WHEEL;
5420 element = EL_DC_TIMEGATE_SWITCH;
5424 element = EL_ACID_POOL_BOTTOM;
5428 element = EL_ACID_POOL_TOPLEFT;
5432 element = EL_ACID_POOL_TOPRIGHT;
5436 element = EL_ACID_POOL_BOTTOMLEFT;
5440 element = EL_ACID_POOL_BOTTOMRIGHT;
5444 element = EL_STEELWALL;
5448 element = EL_STEELWALL_SLIPPERY;
5451 case 0x1695: /* steel wall (not round) */
5452 element = EL_STEELWALL;
5455 case 0x1696: /* steel wall (left) */
5456 element = EL_DC_STEELWALL_1_LEFT;
5459 case 0x1697: /* steel wall (bottom) */
5460 element = EL_DC_STEELWALL_1_BOTTOM;
5463 case 0x1698: /* steel wall (right) */
5464 element = EL_DC_STEELWALL_1_RIGHT;
5467 case 0x1699: /* steel wall (top) */
5468 element = EL_DC_STEELWALL_1_TOP;
5471 case 0x169a: /* steel wall (left/bottom) */
5472 element = EL_DC_STEELWALL_1_BOTTOMLEFT;
5475 case 0x169b: /* steel wall (right/bottom) */
5476 element = EL_DC_STEELWALL_1_BOTTOMRIGHT;
5479 case 0x169c: /* steel wall (right/top) */
5480 element = EL_DC_STEELWALL_1_TOPRIGHT;
5483 case 0x169d: /* steel wall (left/top) */
5484 element = EL_DC_STEELWALL_1_TOPLEFT;
5487 case 0x169e: /* steel wall (right/bottom small) */
5488 element = EL_DC_STEELWALL_1_BOTTOMRIGHT_2;
5491 case 0x169f: /* steel wall (left/bottom small) */
5492 element = EL_DC_STEELWALL_1_BOTTOMLEFT_2;
5495 case 0x16a0: /* steel wall (right/top small) */
5496 element = EL_DC_STEELWALL_1_TOPRIGHT_2;
5499 case 0x16a1: /* steel wall (left/top small) */
5500 element = EL_DC_STEELWALL_1_TOPLEFT_2;
5503 case 0x16a2: /* steel wall (left/right) */
5504 element = EL_DC_STEELWALL_1_VERTICAL;
5507 case 0x16a3: /* steel wall (top/bottom) */
5508 element = EL_DC_STEELWALL_1_HORIZONTAL;
5511 case 0x16a4: /* steel wall 2 (left end) */
5512 element = EL_DC_STEELWALL_2_LEFT;
5515 case 0x16a5: /* steel wall 2 (right end) */
5516 element = EL_DC_STEELWALL_2_RIGHT;
5519 case 0x16a6: /* steel wall 2 (top end) */
5520 element = EL_DC_STEELWALL_2_TOP;
5523 case 0x16a7: /* steel wall 2 (bottom end) */
5524 element = EL_DC_STEELWALL_2_BOTTOM;
5527 case 0x16a8: /* steel wall 2 (left/right) */
5528 element = EL_DC_STEELWALL_2_HORIZONTAL;
5531 case 0x16a9: /* steel wall 2 (up/down) */
5532 element = EL_DC_STEELWALL_2_VERTICAL;
5535 case 0x16aa: /* steel wall 2 (mid) */
5536 element = EL_DC_STEELWALL_2_MIDDLE;
5540 element = EL_SIGN_EXCLAMATION;
5544 element = EL_SIGN_RADIOACTIVITY;
5548 element = EL_SIGN_STOP;
5552 element = EL_SIGN_WHEELCHAIR;
5556 element = EL_SIGN_PARKING;
5560 element = EL_SIGN_NO_ENTRY;
5564 element = EL_SIGN_HEART;
5568 element = EL_SIGN_GIVE_WAY;
5572 element = EL_SIGN_ENTRY_FORBIDDEN;
5576 element = EL_SIGN_EMERGENCY_EXIT;
5580 element = EL_SIGN_YIN_YANG;
5584 element = EL_WALL_EMERALD;
5588 element = EL_WALL_DIAMOND;
5592 element = EL_WALL_PEARL;
5596 element = EL_WALL_CRYSTAL;
5600 element = EL_INVISIBLE_WALL;
5604 element = EL_INVISIBLE_STEELWALL;
5607 /* 0x16bc - 0x16cb: */
5608 /* EL_INVISIBLE_SAND */
5611 element = EL_LIGHT_SWITCH;
5615 element = EL_ENVELOPE_1;
5619 if (element >= 0x0117 && element <= 0x036e) /* (?) */
5620 element = EL_DIAMOND;
5621 else if (element >= 0x042d && element <= 0x0684) /* (?) */
5622 element = EL_EMERALD;
5623 else if (element >= 0x157c && element <= 0x158b)
5625 else if (element >= 0x1590 && element <= 0x159f)
5626 element = EL_DC_LANDMINE;
5627 else if (element >= 0x16bc && element <= 0x16cb)
5628 element = EL_INVISIBLE_SAND;
5631 Error(ERR_WARN, "unknown Diamond Caves element 0x%04x", element);
5632 element = EL_UNKNOWN;
5637 return getMappedElement(element);
5642 static void LoadLevelFromFileStream_DC(FILE *file, struct LevelInfo *level,
5645 byte header[DC_LEVEL_HEADER_SIZE];
5647 int envelope_header_pos = 62;
5648 int envelope_content_pos = 94;
5649 int level_name_pos = 251;
5650 int level_author_pos = 292;
5651 int envelope_header_len;
5652 int envelope_content_len;
5654 int level_author_len;
5656 int num_yamyam_contents;
5659 getDecodedWord_DC(0, TRUE); /* initialize DC2 decoding engine */
5661 for (i = 0; i < DC_LEVEL_HEADER_SIZE / 2; i++)
5663 unsigned short header_word = getDecodedWord_DC(getFile16BitBE(file), FALSE);
5665 header[i * 2 + 0] = header_word >> 8;
5666 header[i * 2 + 1] = header_word & 0xff;
5669 /* read some values from level header to check level decoding integrity */
5670 fieldx = header[6] | (header[7] << 8);
5671 fieldy = header[8] | (header[9] << 8);
5672 num_yamyam_contents = header[60] | (header[61] << 8);
5674 /* do some simple sanity checks to ensure that level was correctly decoded */
5675 if (fieldx < 1 || fieldx > 256 ||
5676 fieldy < 1 || fieldy > 256 ||
5677 num_yamyam_contents < 1 || num_yamyam_contents > 8)
5679 level->no_valid_file = TRUE;
5681 Error(ERR_WARN, "cannot decode level from stream -- using empty level");
5686 /* maximum envelope header size is 31 bytes */
5687 envelope_header_len = header[envelope_header_pos];
5688 /* maximum envelope content size is 110 (156?) bytes */
5689 envelope_content_len = header[envelope_content_pos];
5691 /* maximum level title size is 40 bytes */
5692 level_name_len = MIN(header[level_name_pos], MAX_LEVEL_NAME_LEN);
5693 /* maximum level author size is 30 (51?) bytes */
5694 level_author_len = MIN(header[level_author_pos], MAX_LEVEL_AUTHOR_LEN);
5698 for (i = 0; i < envelope_header_len; i++)
5699 if (envelope_size < MAX_ENVELOPE_TEXT_LEN)
5700 level->envelope[0].text[envelope_size++] =
5701 header[envelope_header_pos + 1 + i];
5703 if (envelope_header_len > 0 && envelope_content_len > 0)
5705 if (envelope_size < MAX_ENVELOPE_TEXT_LEN)
5706 level->envelope[0].text[envelope_size++] = '\n';
5707 if (envelope_size < MAX_ENVELOPE_TEXT_LEN)
5708 level->envelope[0].text[envelope_size++] = '\n';
5711 for (i = 0; i < envelope_content_len; i++)
5712 if (envelope_size < MAX_ENVELOPE_TEXT_LEN)
5713 level->envelope[0].text[envelope_size++] =
5714 header[envelope_content_pos + 1 + i];
5716 level->envelope[0].text[envelope_size] = '\0';
5718 level->envelope[0].xsize = MAX_ENVELOPE_XSIZE;
5719 level->envelope[0].ysize = 10;
5720 level->envelope[0].autowrap = TRUE;
5721 level->envelope[0].centered = TRUE;
5723 for (i = 0; i < level_name_len; i++)
5724 level->name[i] = header[level_name_pos + 1 + i];
5725 level->name[level_name_len] = '\0';
5727 for (i = 0; i < level_author_len; i++)
5728 level->author[i] = header[level_author_pos + 1 + i];
5729 level->author[level_author_len] = '\0';
5731 num_yamyam_contents = header[60] | (header[61] << 8);
5732 level->num_yamyam_contents =
5733 MIN(MAX(MIN_ELEMENT_CONTENTS, num_yamyam_contents), MAX_ELEMENT_CONTENTS);
5735 for (i = 0; i < num_yamyam_contents; i++)
5737 for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
5739 unsigned short word = getDecodedWord_DC(getFile16BitBE(file), FALSE);
5741 int element_dc = ((word & 0xff) << 8) | ((word >> 8) & 0xff);
5743 int element_dc = word;
5746 if (i < MAX_ELEMENT_CONTENTS)
5747 level->yamyam_content[i].e[x][y] = getMappedElement_DC(element_dc);
5751 fieldx = header[6] | (header[7] << 8);
5752 fieldy = header[8] | (header[9] << 8);
5753 level->fieldx = MIN(MAX(MIN_LEV_FIELDX, fieldx), MAX_LEV_FIELDX);
5754 level->fieldy = MIN(MAX(MIN_LEV_FIELDY, fieldy), MAX_LEV_FIELDY);
5756 for (y = 0; y < fieldy; y++) for (x = 0; x < fieldx; x++)
5758 unsigned short word = getDecodedWord_DC(getFile16BitBE(file), FALSE);
5760 int element_dc = ((word & 0xff) << 8) | ((word >> 8) & 0xff);
5762 int element_dc = word;
5765 if (x < MAX_LEV_FIELDX && y < MAX_LEV_FIELDY)
5766 level->field[x][y] = getMappedElement_DC(element_dc);
5769 x = MIN(MAX(0, (header[10] | (header[11] << 8)) - 1), MAX_LEV_FIELDX - 1);
5770 y = MIN(MAX(0, (header[12] | (header[13] << 8)) - 1), MAX_LEV_FIELDY - 1);
5771 level->field[x][y] = EL_PLAYER_1;
5773 x = MIN(MAX(0, (header[14] | (header[15] << 8)) - 1), MAX_LEV_FIELDX - 1);
5774 y = MIN(MAX(0, (header[16] | (header[17] << 8)) - 1), MAX_LEV_FIELDY - 1);
5775 level->field[x][y] = EL_PLAYER_2;
5777 level->gems_needed = header[18] | (header[19] << 8);
5779 level->score[SC_EMERALD] = header[20] | (header[21] << 8);
5780 level->score[SC_DIAMOND] = header[22] | (header[23] << 8);
5781 level->score[SC_PEARL] = header[24] | (header[25] << 8);
5782 level->score[SC_CRYSTAL] = header[26] | (header[27] << 8);
5783 level->score[SC_NUT] = header[28] | (header[29] << 8);
5784 level->score[SC_ROBOT] = header[30] | (header[31] << 8);
5785 level->score[SC_SPACESHIP] = header[32] | (header[33] << 8);
5786 level->score[SC_BUG] = header[34] | (header[35] << 8);
5787 level->score[SC_YAMYAM] = header[36] | (header[37] << 8);
5788 level->score[SC_DYNAMITE] = header[38] | (header[39] << 8);
5789 level->score[SC_KEY] = header[40] | (header[41] << 8);
5790 level->score[SC_TIME_BONUS] = header[42] | (header[43] << 8);
5792 level->time = header[44] | (header[45] << 8);
5794 level->amoeba_speed = header[46] | (header[47] << 8);
5795 level->time_light = header[48] | (header[49] << 8);
5796 level->time_timegate = header[50] | (header[51] << 8);
5797 level->time_wheel = header[52] | (header[53] << 8);
5798 level->time_magic_wall = header[54] | (header[55] << 8);
5799 level->extra_time = header[56] | (header[57] << 8);
5800 level->shield_normal_time = header[58] | (header[59] << 8);
5802 /* Diamond Caves has the same (strange) behaviour as Emerald Mine that gems
5803 can slip down from flat walls, like normal walls and steel walls */
5804 level->em_slippery_gems = TRUE;
5807 /* Diamond Caves II levels are always surrounded by indestructible wall, but
5808 not necessarily in a rectangular way -- fill with invisible steel wall */
5810 /* !!! not always true !!! keep level and set BorderElement instead !!! */
5812 for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++)
5815 if ((x == 0 || x == level->fieldx - 1 ||
5816 y == 0 || y == level->fieldy - 1) &&
5817 level->field[x][y] == EL_EMPTY)
5818 level->field[x][y] = EL_INVISIBLE_STEELWALL;
5820 if ((x == 0 || x == level->fieldx - 1 ||
5821 y == 0 || y == level->fieldy - 1) &&
5822 level->field[x][y] == EL_EMPTY)
5823 FloodFillLevel(x, y, EL_INVISIBLE_STEELWALL,
5824 level->field, level->fieldx, level->fieldy);
5830 static void LoadLevelFromFileInfo_DC(struct LevelInfo *level,
5831 struct LevelFileInfo *level_file_info)
5833 char *filename = level_file_info->filename;
5835 int num_magic_bytes = 8;
5836 char magic_bytes[num_magic_bytes + 1];
5837 int num_levels_to_skip = level_file_info->nr - leveldir_current->first_level;
5839 if (!(file = fopen(filename, MODE_READ)))
5841 level->no_valid_file = TRUE;
5843 Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename);
5848 // fseek(file, 0x0000, SEEK_SET);
5850 if (level_file_info->packed)
5852 /* read "magic bytes" from start of file */
5853 fgets(magic_bytes, num_magic_bytes + 1, file);
5855 /* check "magic bytes" for correct file format */
5856 if (!strPrefix(magic_bytes, "DC2"))
5858 level->no_valid_file = TRUE;
5860 Error(ERR_WARN, "unknown DC level file '%s' -- using empty level",
5866 if (strPrefix(magic_bytes, "DC2Win95") ||
5867 strPrefix(magic_bytes, "DC2Win98"))
5869 int position_first_level = 0x00fa;
5870 int extra_bytes = 4;
5873 /* advance file stream to first level inside the level package */
5874 skip_bytes = position_first_level - num_magic_bytes - extra_bytes;
5876 /* each block of level data is followed by block of non-level data */
5877 num_levels_to_skip *= 2;
5879 /* at least skip header bytes, therefore use ">= 0" instead of "> 0" */
5880 while (num_levels_to_skip >= 0)
5882 /* advance file stream to next level inside the level package */
5883 if (fseek(file, skip_bytes, SEEK_CUR) != 0)
5885 level->no_valid_file = TRUE;
5887 Error(ERR_WARN, "cannot fseek in file '%s' -- using empty level",
5893 /* skip apparently unused extra bytes following each level */
5894 ReadUnusedBytesFromFile(file, extra_bytes);
5896 /* read size of next level in level package */
5897 skip_bytes = getFile32BitLE(file);
5899 num_levels_to_skip--;
5904 level->no_valid_file = TRUE;
5906 Error(ERR_WARN, "unknown DC2 level file '%s' -- using empty level",
5913 LoadLevelFromFileStream_DC(file, level, level_file_info->nr);
5920 static void LoadLevelFromFileInfo_DC(struct LevelInfo *level,
5921 struct LevelFileInfo *level_file_info)
5923 char *filename = level_file_info->filename;
5926 int nr = level_file_info->nr - leveldir_current->first_level;
5928 byte header[DC_LEVEL_HEADER_SIZE];
5930 int envelope_header_pos = 62;
5931 int envelope_content_pos = 94;
5932 int level_name_pos = 251;
5933 int level_author_pos = 292;
5934 int envelope_header_len;
5935 int envelope_content_len;
5937 int level_author_len;
5939 int num_yamyam_contents;
5942 if (!(file = fopen(filename, MODE_READ)))
5944 level->no_valid_file = TRUE;
5946 Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename);
5952 /* position file stream to the requested level inside the level package */
5953 if (fseek(file, nr * SP_LEVEL_SIZE, SEEK_SET) != 0)
5955 level->no_valid_file = TRUE;
5957 Error(ERR_WARN, "cannot fseek in file '%s' -- using empty level", filename);
5963 getDecodedWord_DC(0, TRUE); /* initialize DC2 decoding engine */
5965 for (i = 0; i < DC_LEVEL_HEADER_SIZE / 2; i++)
5967 unsigned short header_word = getDecodedWord_DC(getFile16BitBE(file), FALSE);
5969 header[i * 2 + 0] = header_word >> 8;
5970 header[i * 2 + 1] = header_word & 0xff;
5973 /* read some values from level header to check level decoding integrity */
5974 fieldx = header[6] | (header[7] << 8);
5975 fieldy = header[8] | (header[9] << 8);
5976 num_yamyam_contents = header[60] | (header[61] << 8);
5978 /* do some simple sanity checks to ensure that level was correctly decoded */
5979 if (fieldx < 1 || fieldx > 256 ||
5980 fieldy < 1 || fieldy > 256 ||
5981 num_yamyam_contents < 1 || num_yamyam_contents > 8)
5983 level->no_valid_file = TRUE;
5985 Error(ERR_WARN, "cannot read level from file '%s' -- using empty level",
5991 /* maximum envelope header size is 31 bytes */
5992 envelope_header_len = header[envelope_header_pos];
5993 /* maximum envelope content size is 110 (156?) bytes */
5994 envelope_content_len = header[envelope_content_pos];
5996 /* maximum level title size is 40 bytes */
5997 level_name_len = MIN(header[level_name_pos], MAX_LEVEL_NAME_LEN);
5998 /* maximum level author size is 30 (51?) bytes */
5999 level_author_len = MIN(header[level_author_pos], MAX_LEVEL_AUTHOR_LEN);
6003 for (i = 0; i < envelope_header_len; i++)
6004 if (envelope_size < MAX_ENVELOPE_TEXT_LEN)
6005 level->envelope[0].text[envelope_size++] =
6006 header[envelope_header_pos + 1 + i];
6008 if (envelope_header_len > 0 && envelope_content_len > 0)
6010 if (envelope_size < MAX_ENVELOPE_TEXT_LEN)
6011 level->envelope[0].text[envelope_size++] = '\n';
6012 if (envelope_size < MAX_ENVELOPE_TEXT_LEN)
6013 level->envelope[0].text[envelope_size++] = '\n';
6016 for (i = 0; i < envelope_content_len; i++)
6017 if (envelope_size < MAX_ENVELOPE_TEXT_LEN)
6018 level->envelope[0].text[envelope_size++] =
6019 header[envelope_content_pos + 1 + i];
6021 level->envelope[0].text[envelope_size] = '\0';
6023 level->envelope[0].xsize = MAX_ENVELOPE_XSIZE;
6024 level->envelope[0].ysize = 10;
6025 level->envelope[0].autowrap = TRUE;
6026 level->envelope[0].centered = TRUE;
6028 for (i = 0; i < level_name_len; i++)
6029 level->name[i] = header[level_name_pos + 1 + i];
6030 level->name[level_name_len] = '\0';
6032 for (i = 0; i < level_author_len; i++)
6033 level->author[i] = header[level_author_pos + 1 + i];
6034 level->author[level_author_len] = '\0';
6036 num_yamyam_contents = header[60] | (header[61] << 8);
6037 level->num_yamyam_contents =
6038 MIN(MAX(MIN_ELEMENT_CONTENTS, num_yamyam_contents), MAX_ELEMENT_CONTENTS);
6040 for (i = 0; i < num_yamyam_contents; i++)
6042 for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
6044 unsigned short word = getDecodedWord_DC(getFile16BitBE(file), FALSE);
6046 int element_dc = ((word & 0xff) << 8) | ((word >> 8) & 0xff);
6048 int element_dc = word;
6051 if (i < MAX_ELEMENT_CONTENTS)
6052 level->yamyam_content[i].e[x][y] = getMappedElement_DC(element_dc);
6056 fieldx = header[6] | (header[7] << 8);
6057 fieldy = header[8] | (header[9] << 8);
6058 level->fieldx = MIN(MAX(MIN_LEV_FIELDX, fieldx), MAX_LEV_FIELDX);
6059 level->fieldy = MIN(MAX(MIN_LEV_FIELDY, fieldy), MAX_LEV_FIELDY);
6061 for (y = 0; y < fieldy; y++) for (x = 0; x < fieldx; x++)
6063 unsigned short word = getDecodedWord_DC(getFile16BitBE(file), FALSE);
6065 int element_dc = ((word & 0xff) << 8) | ((word >> 8) & 0xff);
6067 int element_dc = word;
6070 if (x < MAX_LEV_FIELDX && y < MAX_LEV_FIELDY)
6071 level->field[x][y] = getMappedElement_DC(element_dc);
6074 x = MIN(MAX(0, (header[10] | (header[11] << 8)) - 1), MAX_LEV_FIELDX - 1);
6075 y = MIN(MAX(0, (header[12] | (header[13] << 8)) - 1), MAX_LEV_FIELDY - 1);
6076 level->field[x][y] = EL_PLAYER_1;
6078 x = MIN(MAX(0, (header[14] | (header[15] << 8)) - 1), MAX_LEV_FIELDX - 1);
6079 y = MIN(MAX(0, (header[16] | (header[17] << 8)) - 1), MAX_LEV_FIELDY - 1);
6080 level->field[x][y] = EL_PLAYER_2;
6082 level->gems_needed = header[18] | (header[19] << 8);
6084 level->score[SC_EMERALD] = header[20] | (header[21] << 8);
6085 level->score[SC_DIAMOND] = header[22] | (header[23] << 8);
6086 level->score[SC_PEARL] = header[24] | (header[25] << 8);
6087 level->score[SC_CRYSTAL] = header[26] | (header[27] << 8);
6088 level->score[SC_NUT] = header[28] | (header[29] << 8);
6089 level->score[SC_ROBOT] = header[30] | (header[31] << 8);
6090 level->score[SC_SPACESHIP] = header[32] | (header[33] << 8);
6091 level->score[SC_BUG] = header[34] | (header[35] << 8);
6092 level->score[SC_YAMYAM] = header[36] | (header[37] << 8);
6093 level->score[SC_DYNAMITE] = header[38] | (header[39] << 8);
6094 level->score[SC_KEY] = header[40] | (header[41] << 8);
6095 level->score[SC_TIME_BONUS] = header[42] | (header[43] << 8);
6097 level->time = header[44] | (header[45] << 8);
6099 level->amoeba_speed = header[46] | (header[47] << 8);
6100 level->time_light = header[48] | (header[49] << 8);
6101 level->time_timegate = header[50] | (header[51] << 8);
6102 level->time_wheel = header[52] | (header[53] << 8);
6103 level->time_magic_wall = header[54] | (header[55] << 8);
6104 level->extra_time = header[56] | (header[57] << 8);
6105 level->shield_normal_time = header[58] | (header[59] << 8);
6109 /* Diamond Caves has the same (strange) behaviour as Emerald Mine that gems
6110 can slip down from flat walls, like normal walls and steel walls */
6111 level->em_slippery_gems = TRUE;
6114 /* Diamond Caves II levels are always surrounded by indestructible wall, but
6115 not necessarily in a rectangular way -- fill with invisible steel wall */
6117 /* !!! not always true !!! keep level and set BorderElement instead !!! */
6119 for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++)
6122 if ((x == 0 || x == level->fieldx - 1 ||
6123 y == 0 || y == level->fieldy - 1) &&
6124 level->field[x][y] == EL_EMPTY)
6125 level->field[x][y] = EL_INVISIBLE_STEELWALL;
6127 if ((x == 0 || x == level->fieldx - 1 ||
6128 y == 0 || y == level->fieldy - 1) &&
6129 level->field[x][y] == EL_EMPTY)
6130 FloodFillLevel(x, y, EL_INVISIBLE_STEELWALL,
6131 level->field, level->fieldx, level->fieldy);
6140 /* ------------------------------------------------------------------------- */
6141 /* functions for loading generic level */
6142 /* ------------------------------------------------------------------------- */
6144 void LoadLevelFromFileInfo(struct LevelInfo *level,
6145 struct LevelFileInfo *level_file_info)
6147 /* always start with reliable default values */
6148 setLevelInfoToDefaults(level);
6150 switch (level_file_info->type)
6152 case LEVEL_FILE_TYPE_RND:
6153 LoadLevelFromFileInfo_RND(level, level_file_info);
6156 case LEVEL_FILE_TYPE_EM:
6157 LoadLevelFromFileInfo_EM(level, level_file_info);
6158 level->game_engine_type = GAME_ENGINE_TYPE_EM;
6161 case LEVEL_FILE_TYPE_SP:
6162 LoadLevelFromFileInfo_SP(level, level_file_info);
6165 case LEVEL_FILE_TYPE_DC:
6166 LoadLevelFromFileInfo_DC(level, level_file_info);
6170 LoadLevelFromFileInfo_RND(level, level_file_info);
6174 /* if level file is invalid, restore level structure to default values */
6175 if (level->no_valid_file)
6176 setLevelInfoToDefaults(level);
6178 if (level->game_engine_type == GAME_ENGINE_TYPE_UNKNOWN)
6179 level->game_engine_type = GAME_ENGINE_TYPE_RND;
6181 if (level_file_info->type != LEVEL_FILE_TYPE_RND)
6182 CopyNativeLevel_Native_to_RND(level);
6185 void LoadLevelFromFilename(struct LevelInfo *level, char *filename)
6187 static struct LevelFileInfo level_file_info;
6189 /* always start with reliable default values */
6190 setFileInfoToDefaults(&level_file_info);
6192 level_file_info.nr = 0; /* unknown level number */
6193 level_file_info.type = LEVEL_FILE_TYPE_RND; /* no others supported yet */
6194 level_file_info.filename = filename;
6196 LoadLevelFromFileInfo(level, &level_file_info);
6199 static void LoadLevel_InitVersion(struct LevelInfo *level, char *filename)
6203 if (leveldir_current == NULL) /* only when dumping level */
6206 /* all engine modifications also valid for levels which use latest engine */
6207 if (level->game_version < VERSION_IDENT(3,2,0,5))
6209 /* time bonus score was given for 10 s instead of 1 s before 3.2.0-5 */
6210 level->score[SC_TIME_BONUS] /= 10;
6214 leveldir_current->latest_engine = TRUE; /* !!! TEST ONLY !!! */
6217 if (leveldir_current->latest_engine)
6219 /* ---------- use latest game engine ----------------------------------- */
6221 /* For all levels which are forced to use the latest game engine version
6222 (normally all but user contributed, private and undefined levels), set
6223 the game engine version to the actual version; this allows for actual
6224 corrections in the game engine to take effect for existing, converted
6225 levels (from "classic" or other existing games) to make the emulation
6226 of the corresponding game more accurate, while (hopefully) not breaking
6227 existing levels created from other players. */
6229 level->game_version = GAME_VERSION_ACTUAL;
6231 /* Set special EM style gems behaviour: EM style gems slip down from
6232 normal, steel and growing wall. As this is a more fundamental change,
6233 it seems better to set the default behaviour to "off" (as it is more
6234 natural) and make it configurable in the level editor (as a property
6235 of gem style elements). Already existing converted levels (neither
6236 private nor contributed levels) are changed to the new behaviour. */
6238 if (level->file_version < FILE_VERSION_2_0)
6239 level->em_slippery_gems = TRUE;
6244 /* ---------- use game engine the level was created with ----------------- */
6246 /* For all levels which are not forced to use the latest game engine
6247 version (normally user contributed, private and undefined levels),
6248 use the version of the game engine the levels were created for.
6250 Since 2.0.1, the game engine version is now directly stored
6251 in the level file (chunk "VERS"), so there is no need anymore
6252 to set the game version from the file version (except for old,
6253 pre-2.0 levels, where the game version is still taken from the
6254 file format version used to store the level -- see above). */
6256 /* player was faster than enemies in 1.0.0 and before */
6257 if (level->file_version == FILE_VERSION_1_0)
6258 for (i = 0; i < MAX_PLAYERS; i++)
6259 level->initial_player_stepsize[i] = STEPSIZE_FAST;
6261 /* default behaviour for EM style gems was "slippery" only in 2.0.1 */
6262 if (level->game_version == VERSION_IDENT(2,0,1,0))
6263 level->em_slippery_gems = TRUE;
6265 /* springs could be pushed over pits before (pre-release version) 2.2.0 */
6266 if (level->game_version < VERSION_IDENT(2,2,0,0))
6267 level->use_spring_bug = TRUE;
6269 if (level->game_version < VERSION_IDENT(3,2,0,5))
6271 /* time orb caused limited time in endless time levels before 3.2.0-5 */
6272 level->use_time_orb_bug = TRUE;
6274 /* default behaviour for snapping was "no snap delay" before 3.2.0-5 */
6275 level->block_snap_field = FALSE;
6277 /* extra time score was same value as time left score before 3.2.0-5 */
6278 level->extra_time_score = level->score[SC_TIME_BONUS];
6281 /* time bonus score was given for 10 s instead of 1 s before 3.2.0-5 */
6282 level->score[SC_TIME_BONUS] /= 10;
6286 if (level->game_version < VERSION_IDENT(3,2,0,7))
6288 /* default behaviour for snapping was "not continuous" before 3.2.0-7 */
6289 level->continuous_snapping = FALSE;
6292 /* only few elements were able to actively move into acid before 3.1.0 */
6293 /* trigger settings did not exist before 3.1.0; set to default "any" */
6294 if (level->game_version < VERSION_IDENT(3,1,0,0))
6296 /* correct "can move into acid" settings (all zero in old levels) */
6298 level->can_move_into_acid_bits = 0; /* nothing can move into acid */
6299 level->dont_collide_with_bits = 0; /* nothing is deadly when colliding */
6301 setMoveIntoAcidProperty(level, EL_ROBOT, TRUE);
6302 setMoveIntoAcidProperty(level, EL_SATELLITE, TRUE);
6303 setMoveIntoAcidProperty(level, EL_PENGUIN, TRUE);
6304 setMoveIntoAcidProperty(level, EL_BALLOON, TRUE);
6306 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
6307 SET_PROPERTY(EL_CUSTOM_START + i, EP_CAN_MOVE_INTO_ACID, TRUE);
6309 /* correct trigger settings (stored as zero == "none" in old levels) */
6311 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
6313 int element = EL_CUSTOM_START + i;
6314 struct ElementInfo *ei = &element_info[element];
6316 for (j = 0; j < ei->num_change_pages; j++)
6318 struct ElementChangeInfo *change = &ei->change_page[j];
6320 change->trigger_player = CH_PLAYER_ANY;
6321 change->trigger_page = CH_PAGE_ANY;
6326 /* try to detect and fix "Snake Bite" levels, which are broken with 3.2.0 */
6328 int element = EL_CUSTOM_256;
6329 struct ElementInfo *ei = &element_info[element];
6330 struct ElementChangeInfo *change = &ei->change_page[0];
6332 /* This is needed to fix a problem that was caused by a bugfix in function
6333 game.c/CreateFieldExt() introduced with 3.2.0 that corrects the behaviour
6334 when a custom element changes to EL_SOKOBAN_FIELD_PLAYER (before, it did
6335 not replace walkable elements, but instead just placed the player on it,
6336 without placing the Sokoban field under the player). Unfortunately, this
6337 breaks "Snake Bite" style levels when the snake is halfway through a door
6338 that just closes (the snake head is still alive and can be moved in this
6339 case). This can be fixed by replacing the EL_SOKOBAN_FIELD_PLAYER by the
6340 player (without Sokoban element) which then gets killed as designed). */
6342 if ((strncmp(leveldir_current->identifier, "snake_bite", 10) == 0 ||
6343 strncmp(ei->description, "pause b4 death", 14) == 0) &&
6344 change->target_element == EL_SOKOBAN_FIELD_PLAYER)
6345 change->target_element = EL_PLAYER_1;
6349 /* try to detect and fix "Zelda" style levels, which are broken with 3.2.5 */
6350 if (level->game_version < VERSION_IDENT(3,2,5,0))
6352 /* This is needed to fix a problem that was caused by a bugfix in function
6353 game.c/CheckTriggeredElementChangeExt() introduced with 3.2.5 that
6354 corrects the behaviour when a custom element changes to another custom
6355 element with a higher element number that has change actions defined.
6356 Normally, only one change per frame is allowed for custom elements.
6357 Therefore, it is checked if a custom element already changed in the
6358 current frame; if it did, subsequent changes are suppressed.
6359 Unfortunately, this is only checked for element changes, but not for
6360 change actions, which are still executed. As the function above loops
6361 through all custom elements from lower to higher, an element change
6362 resulting in a lower CE number won't be checked again, while a target
6363 element with a higher number will also be checked, and potential change
6364 actions will get executed for this CE, too (which is wrong), while
6365 further changes are ignored (which is correct). As this bugfix breaks
6366 Zelda II (and introduces graphical bugs to Zelda I, and also breaks a
6367 few other levels like Alan Bond's "FMV"), allow the previous, incorrect
6368 behaviour for existing levels and tapes that make use of this bug */
6370 level->use_action_after_change_bug = TRUE;
6373 /* !!! THIS DOES NOT FIX "Zelda I" (GRAPHICALLY) AND "Alan's FMV" LEVELS */
6374 /* try to detect and fix "Zelda II" levels, which are broken with 3.2.5 */
6376 int element = EL_CUSTOM_16;
6377 struct ElementInfo *ei = &element_info[element];
6379 /* This is needed to fix a problem that was caused by a bugfix in function
6380 game.c/CheckTriggeredElementChangeExt() introduced with 3.2.5 that
6381 corrects the behaviour when a custom element changes to another custom
6382 element with a higher element number that has change actions defined.
6383 Normally, only one change per frame is allowed for custom elements.
6384 Therefore, it is checked if a custom element already changed in the
6385 current frame; if it did, subsequent changes are suppressed.
6386 Unfortunately, this is only checked for element changes, but not for
6387 change actions, which are still executed. As the function above loops
6388 through all custom elements from lower to higher, an element change
6389 resulting in a lower CE number won't be checked again, while a target
6390 element with a higher number will also be checked, and potential change
6391 actions will get executed for this CE, too (which is wrong), while
6392 further changes are ignored (which is correct). As this bugfix breaks
6393 Zelda II (but no other levels), allow the previous, incorrect behaviour
6394 for this outstanding level set to not break the game or existing tapes */
6396 if (strncmp(leveldir_current->identifier, "zelda2", 6) == 0 ||
6397 strncmp(ei->description, "scanline - row 1", 16) == 0)
6398 level->use_action_after_change_bug = TRUE;
6402 /* not centering level after relocating player was default only in 3.2.3 */
6403 if (level->game_version == VERSION_IDENT(3,2,3,0)) /* (no pre-releases) */
6404 level->shifted_relocation = TRUE;
6406 /* EM style elements always chain-exploded in R'n'D engine before 3.2.6 */
6407 if (level->game_version < VERSION_IDENT(3,2,6,0))
6408 level->em_explodes_by_fire = TRUE;
6411 static void LoadLevel_InitElements(struct LevelInfo *level, char *filename)
6415 /* map custom element change events that have changed in newer versions
6416 (these following values were accidentally changed in version 3.0.1)
6417 (this seems to be needed only for 'ab_levelset3' and 'ab_levelset4') */
6418 if (level->game_version <= VERSION_IDENT(3,0,0,0))
6420 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
6422 int element = EL_CUSTOM_START + i;
6424 /* order of checking and copying events to be mapped is important */
6425 /* (do not change the start and end value -- they are constant) */
6426 for (j = CE_BY_OTHER_ACTION; j >= CE_VALUE_GETS_ZERO; j--)
6428 if (HAS_CHANGE_EVENT(element, j - 2))
6430 SET_CHANGE_EVENT(element, j - 2, FALSE);
6431 SET_CHANGE_EVENT(element, j, TRUE);
6435 /* order of checking and copying events to be mapped is important */
6436 /* (do not change the start and end value -- they are constant) */
6437 for (j = CE_PLAYER_COLLECTS_X; j >= CE_HITTING_SOMETHING; j--)
6439 if (HAS_CHANGE_EVENT(element, j - 1))
6441 SET_CHANGE_EVENT(element, j - 1, FALSE);
6442 SET_CHANGE_EVENT(element, j, TRUE);
6448 /* initialize "can_change" field for old levels with only one change page */
6449 if (level->game_version <= VERSION_IDENT(3,0,2,0))
6451 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
6453 int element = EL_CUSTOM_START + i;
6455 if (CAN_CHANGE(element))
6456 element_info[element].change->can_change = TRUE;
6460 /* correct custom element values (for old levels without these options) */
6461 if (level->game_version < VERSION_IDENT(3,1,1,0))
6463 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
6465 int element = EL_CUSTOM_START + i;
6466 struct ElementInfo *ei = &element_info[element];
6468 if (ei->access_direction == MV_NO_DIRECTION)
6469 ei->access_direction = MV_ALL_DIRECTIONS;
6473 /* correct custom element values (fix invalid values for all versions) */
6476 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
6478 int element = EL_CUSTOM_START + i;
6479 struct ElementInfo *ei = &element_info[element];
6481 for (j = 0; j < ei->num_change_pages; j++)
6483 struct ElementChangeInfo *change = &ei->change_page[j];
6485 if (change->trigger_player == CH_PLAYER_NONE)
6486 change->trigger_player = CH_PLAYER_ANY;
6488 if (change->trigger_side == CH_SIDE_NONE)
6489 change->trigger_side = CH_SIDE_ANY;
6494 /* initialize "can_explode" field for old levels which did not store this */
6495 /* !!! CHECK THIS -- "<= 3,1,0,0" IS PROBABLY WRONG !!! */
6496 if (level->game_version <= VERSION_IDENT(3,1,0,0))
6498 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
6500 int element = EL_CUSTOM_START + i;
6502 if (EXPLODES_1X1_OLD(element))
6503 element_info[element].explosion_type = EXPLODES_1X1;
6505 SET_PROPERTY(element, EP_CAN_EXPLODE, (EXPLODES_BY_FIRE(element) ||
6506 EXPLODES_SMASHED(element) ||
6507 EXPLODES_IMPACT(element)));
6511 /* correct previously hard-coded move delay values for maze runner style */
6512 if (level->game_version < VERSION_IDENT(3,1,1,0))
6514 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
6516 int element = EL_CUSTOM_START + i;
6518 if (element_info[element].move_pattern & MV_MAZE_RUNNER_STYLE)
6520 /* previously hard-coded and therefore ignored */
6521 element_info[element].move_delay_fixed = 9;
6522 element_info[element].move_delay_random = 0;
6527 /* map elements that have changed in newer versions */
6528 level->amoeba_content = getMappedElementByVersion(level->amoeba_content,
6529 level->game_version);
6530 for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
6531 for (x = 0; x < 3; x++)
6532 for (y = 0; y < 3; y++)
6533 level->yamyam_content[i].e[x][y] =
6534 getMappedElementByVersion(level->yamyam_content[i].e[x][y],
6535 level->game_version);
6537 /* initialize element properties for level editor etc. */
6538 InitElementPropertiesEngine(level->game_version);
6539 InitElementPropertiesAfterLoading(level->game_version);
6540 InitElementPropertiesGfxElement();
6543 static void LoadLevel_InitPlayfield(struct LevelInfo *level, char *filename)
6547 /* map elements that have changed in newer versions */
6548 for (y = 0; y < level->fieldy; y++)
6549 for (x = 0; x < level->fieldx; x++)
6550 level->field[x][y] = getMappedElementByVersion(level->field[x][y],
6551 level->game_version);
6553 /* copy elements to runtime playfield array */
6554 for (x = 0; x < MAX_LEV_FIELDX; x++)
6555 for (y = 0; y < MAX_LEV_FIELDY; y++)
6556 Feld[x][y] = level->field[x][y];
6558 /* initialize level size variables for faster access */
6559 lev_fieldx = level->fieldx;
6560 lev_fieldy = level->fieldy;
6562 /* determine border element for this level */
6563 if (level->file_info.type == LEVEL_FILE_TYPE_DC)
6564 BorderElement = EL_EMPTY; /* (in editor, SetBorderElement() is used) */
6569 static void LoadLevel_InitNativeEngines(struct LevelInfo *level,char *filename)
6571 struct LevelFileInfo *level_file_info = &level->file_info;
6573 if (level_file_info->type == LEVEL_FILE_TYPE_RND)
6574 CopyNativeLevel_RND_to_Native(level);
6577 void LoadLevelTemplate(int nr)
6581 setLevelFileInfo(&level_template.file_info, nr);
6582 filename = level_template.file_info.filename;
6584 LoadLevelFromFileInfo(&level_template, &level_template.file_info);
6586 LoadLevel_InitVersion(&level_template, filename);
6587 LoadLevel_InitElements(&level_template, filename);
6589 ActivateLevelTemplate();
6592 void LoadLevel(int nr)
6596 setLevelFileInfo(&level.file_info, nr);
6597 filename = level.file_info.filename;
6599 LoadLevelFromFileInfo(&level, &level.file_info);
6601 if (level.use_custom_template)
6602 LoadLevelTemplate(-1);
6604 LoadLevel_InitVersion(&level, filename);
6605 LoadLevel_InitElements(&level, filename);
6606 LoadLevel_InitPlayfield(&level, filename);
6608 LoadLevel_InitNativeEngines(&level, filename);
6611 static int SaveLevel_VERS(FILE *file, struct LevelInfo *level)
6615 chunk_size += putFileVersion(file, level->file_version);
6616 chunk_size += putFileVersion(file, level->game_version);
6621 static int SaveLevel_DATE(FILE *file, struct LevelInfo *level)
6625 chunk_size += putFile16BitBE(file, level->creation_date.year);
6626 chunk_size += putFile8Bit(file, level->creation_date.month);
6627 chunk_size += putFile8Bit(file, level->creation_date.day);
6633 static void SaveLevel_HEAD(FILE *file, struct LevelInfo *level)
6637 putFile8Bit(file, level->fieldx);
6638 putFile8Bit(file, level->fieldy);
6640 putFile16BitBE(file, level->time);
6641 putFile16BitBE(file, level->gems_needed);
6643 for (i = 0; i < MAX_LEVEL_NAME_LEN; i++)
6644 putFile8Bit(file, level->name[i]);
6646 for (i = 0; i < LEVEL_SCORE_ELEMENTS; i++)
6647 putFile8Bit(file, level->score[i]);
6649 for (i = 0; i < STD_ELEMENT_CONTENTS; i++)
6650 for (y = 0; y < 3; y++)
6651 for (x = 0; x < 3; x++)
6652 putFile8Bit(file, (level->encoding_16bit_yamyam ? EL_EMPTY :
6653 level->yamyam_content[i].e[x][y]));
6654 putFile8Bit(file, level->amoeba_speed);
6655 putFile8Bit(file, level->time_magic_wall);
6656 putFile8Bit(file, level->time_wheel);
6657 putFile8Bit(file, (level->encoding_16bit_amoeba ? EL_EMPTY :
6658 level->amoeba_content));
6659 putFile8Bit(file, (level->initial_player_stepsize == STEPSIZE_FAST ? 1 : 0));
6660 putFile8Bit(file, (level->initial_gravity ? 1 : 0));
6661 putFile8Bit(file, (level->encoding_16bit_field ? 1 : 0));
6662 putFile8Bit(file, (level->em_slippery_gems ? 1 : 0));
6664 putFile8Bit(file, (level->use_custom_template ? 1 : 0));
6666 putFile8Bit(file, (level->block_last_field ? 1 : 0));
6667 putFile8Bit(file, (level->sp_block_last_field ? 1 : 0));
6668 putFile32BitBE(file, level->can_move_into_acid_bits);
6669 putFile8Bit(file, level->dont_collide_with_bits);
6671 putFile8Bit(file, (level->use_spring_bug ? 1 : 0));
6672 putFile8Bit(file, (level->use_step_counter ? 1 : 0));
6674 putFile8Bit(file, (level->instant_relocation ? 1 : 0));
6675 putFile8Bit(file, (level->can_pass_to_walkable ? 1 : 0));
6676 putFile8Bit(file, (level->grow_into_diggable ? 1 : 0));
6678 putFile8Bit(file, level->game_engine_type);
6680 WriteUnusedBytesToFile(file, LEVEL_CHUNK_HEAD_UNUSED);
6684 static int SaveLevel_NAME(FILE *file, struct LevelInfo *level)
6689 for (i = 0; i < MAX_LEVEL_NAME_LEN; i++)
6690 chunk_size += putFile8Bit(file, level->name[i]);
6695 static int SaveLevel_AUTH(FILE *file, struct LevelInfo *level)
6700 for (i = 0; i < MAX_LEVEL_AUTHOR_LEN; i++)
6701 chunk_size += putFile8Bit(file, level->author[i]);
6707 static int SaveLevel_BODY(FILE *file, struct LevelInfo *level)
6712 for (y = 0; y < level->fieldy; y++)
6713 for (x = 0; x < level->fieldx; x++)
6714 if (level->encoding_16bit_field)
6715 chunk_size += putFile16BitBE(file, level->field[x][y]);
6717 chunk_size += putFile8Bit(file, level->field[x][y]);
6723 static int SaveLevel_BODY(FILE *file, struct LevelInfo *level)
6728 for (y = 0; y < level->fieldy; y++)
6729 for (x = 0; x < level->fieldx; x++)
6730 chunk_size += putFile16BitBE(file, level->field[x][y]);
6736 static void SaveLevel_CONT(FILE *file, struct LevelInfo *level)
6740 putFile8Bit(file, EL_YAMYAM);
6741 putFile8Bit(file, level->num_yamyam_contents);
6742 putFile8Bit(file, 0);
6743 putFile8Bit(file, 0);
6745 for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
6746 for (y = 0; y < 3; y++)
6747 for (x = 0; x < 3; x++)
6748 if (level->encoding_16bit_field)
6749 putFile16BitBE(file, level->yamyam_content[i].e[x][y]);
6751 putFile8Bit(file, level->yamyam_content[i].e[x][y]);
6756 static void SaveLevel_CNT2(FILE *file, struct LevelInfo *level, int element)
6759 int num_contents, content_xsize, content_ysize;
6760 int content_array[MAX_ELEMENT_CONTENTS][3][3];
6762 if (element == EL_YAMYAM)
6764 num_contents = level->num_yamyam_contents;
6768 for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
6769 for (y = 0; y < 3; y++)
6770 for (x = 0; x < 3; x++)
6771 content_array[i][x][y] = level->yamyam_content[i].e[x][y];
6773 else if (element == EL_BD_AMOEBA)
6779 for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
6780 for (y = 0; y < 3; y++)
6781 for (x = 0; x < 3; x++)
6782 content_array[i][x][y] = EL_EMPTY;
6783 content_array[0][0][0] = level->amoeba_content;
6787 /* chunk header already written -- write empty chunk data */
6788 WriteUnusedBytesToFile(file, LEVEL_CHUNK_CNT2_SIZE);
6790 Error(ERR_WARN, "cannot save content for element '%d'", element);
6794 putFile16BitBE(file, element);
6795 putFile8Bit(file, num_contents);
6796 putFile8Bit(file, content_xsize);
6797 putFile8Bit(file, content_ysize);
6799 WriteUnusedBytesToFile(file, LEVEL_CHUNK_CNT2_UNUSED);
6801 for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
6802 for (y = 0; y < 3; y++)
6803 for (x = 0; x < 3; x++)
6804 putFile16BitBE(file, content_array[i][x][y]);
6809 static int SaveLevel_CNT3(FILE *file, struct LevelInfo *level, int element)
6811 int envelope_nr = element - EL_ENVELOPE_1;
6812 int envelope_len = strlen(level->envelope_text[envelope_nr]) + 1;
6816 chunk_size += putFile16BitBE(file, element);
6817 chunk_size += putFile16BitBE(file, envelope_len);
6818 chunk_size += putFile8Bit(file, level->envelope_xsize[envelope_nr]);
6819 chunk_size += putFile8Bit(file, level->envelope_ysize[envelope_nr]);
6821 WriteUnusedBytesToFile(file, LEVEL_CHUNK_CNT3_UNUSED);
6822 chunk_size += LEVEL_CHUNK_CNT3_UNUSED;
6824 for (i = 0; i < envelope_len; i++)
6825 chunk_size += putFile8Bit(file, level->envelope_text[envelope_nr][i]);
6832 static void SaveLevel_CUS1(FILE *file, struct LevelInfo *level,
6833 int num_changed_custom_elements)
6837 putFile16BitBE(file, num_changed_custom_elements);
6839 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
6841 int element = EL_CUSTOM_START + i;
6843 struct ElementInfo *ei = &element_info[element];
6845 if (ei->properties[EP_BITFIELD_BASE_NR] != EP_BITMASK_DEFAULT)
6847 if (check < num_changed_custom_elements)
6849 putFile16BitBE(file, element);
6850 putFile32BitBE(file, ei->properties[EP_BITFIELD_BASE_NR]);
6857 if (check != num_changed_custom_elements) /* should not happen */
6858 Error(ERR_WARN, "inconsistent number of custom element properties");
6863 static void SaveLevel_CUS2(FILE *file, struct LevelInfo *level,
6864 int num_changed_custom_elements)
6868 putFile16BitBE(file, num_changed_custom_elements);
6870 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
6872 int element = EL_CUSTOM_START + i;
6874 if (element_info[element].change->target_element != EL_EMPTY_SPACE)
6876 if (check < num_changed_custom_elements)
6878 putFile16BitBE(file, element);
6879 putFile16BitBE(file, element_info[element].change->target_element);
6886 if (check != num_changed_custom_elements) /* should not happen */
6887 Error(ERR_WARN, "inconsistent number of custom target elements");
6892 static void SaveLevel_CUS3(FILE *file, struct LevelInfo *level,
6893 int num_changed_custom_elements)
6895 int i, j, x, y, check = 0;
6897 putFile16BitBE(file, num_changed_custom_elements);
6899 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
6901 int element = EL_CUSTOM_START + i;
6902 struct ElementInfo *ei = &element_info[element];
6904 if (ei->modified_settings)
6906 if (check < num_changed_custom_elements)
6908 putFile16BitBE(file, element);
6910 for (j = 0; j < MAX_ELEMENT_NAME_LEN; j++)
6911 putFile8Bit(file, ei->description[j]);
6913 putFile32BitBE(file, ei->properties[EP_BITFIELD_BASE_NR]);
6915 /* some free bytes for future properties and padding */
6916 WriteUnusedBytesToFile(file, 7);
6918 putFile8Bit(file, ei->use_gfx_element);
6919 putFile16BitBE(file, ei->gfx_element_initial);
6921 putFile8Bit(file, ei->collect_score_initial);
6922 putFile8Bit(file, ei->collect_count_initial);
6924 putFile16BitBE(file, ei->push_delay_fixed);
6925 putFile16BitBE(file, ei->push_delay_random);
6926 putFile16BitBE(file, ei->move_delay_fixed);
6927 putFile16BitBE(file, ei->move_delay_random);
6929 putFile16BitBE(file, ei->move_pattern);
6930 putFile8Bit(file, ei->move_direction_initial);
6931 putFile8Bit(file, ei->move_stepsize);
6933 for (y = 0; y < 3; y++)
6934 for (x = 0; x < 3; x++)
6935 putFile16BitBE(file, ei->content.e[x][y]);
6937 putFile32BitBE(file, ei->change->events);
6939 putFile16BitBE(file, ei->change->target_element);
6941 putFile16BitBE(file, ei->change->delay_fixed);
6942 putFile16BitBE(file, ei->change->delay_random);
6943 putFile16BitBE(file, ei->change->delay_frames);
6945 putFile16BitBE(file, ei->change->initial_trigger_element);
6947 putFile8Bit(file, ei->change->explode);
6948 putFile8Bit(file, ei->change->use_target_content);
6949 putFile8Bit(file, ei->change->only_if_complete);
6950 putFile8Bit(file, ei->change->use_random_replace);
6952 putFile8Bit(file, ei->change->random_percentage);
6953 putFile8Bit(file, ei->change->replace_when);
6955 for (y = 0; y < 3; y++)
6956 for (x = 0; x < 3; x++)
6957 putFile16BitBE(file, ei->change->content.e[x][y]);
6959 putFile8Bit(file, ei->slippery_type);
6961 /* some free bytes for future properties and padding */
6962 WriteUnusedBytesToFile(file, LEVEL_CPART_CUS3_UNUSED);
6969 if (check != num_changed_custom_elements) /* should not happen */
6970 Error(ERR_WARN, "inconsistent number of custom element properties");
6975 static void SaveLevel_CUS4(FILE *file, struct LevelInfo *level, int element)
6977 struct ElementInfo *ei = &element_info[element];
6980 /* ---------- custom element base property values (96 bytes) ------------- */
6982 putFile16BitBE(file, element);
6984 for (i = 0; i < MAX_ELEMENT_NAME_LEN; i++)
6985 putFile8Bit(file, ei->description[i]);
6987 putFile32BitBE(file, ei->properties[EP_BITFIELD_BASE_NR]);
6989 WriteUnusedBytesToFile(file, 4); /* reserved for more base properties */
6991 putFile8Bit(file, ei->num_change_pages);
6993 putFile16BitBE(file, ei->ce_value_fixed_initial);
6994 putFile16BitBE(file, ei->ce_value_random_initial);
6995 putFile8Bit(file, ei->use_last_ce_value);
6997 putFile8Bit(file, ei->use_gfx_element);
6998 putFile16BitBE(file, ei->gfx_element_initial);
7000 putFile8Bit(file, ei->collect_score_initial);
7001 putFile8Bit(file, ei->collect_count_initial);
7003 putFile8Bit(file, ei->drop_delay_fixed);
7004 putFile8Bit(file, ei->push_delay_fixed);
7005 putFile8Bit(file, ei->drop_delay_random);
7006 putFile8Bit(file, ei->push_delay_random);
7007 putFile16BitBE(file, ei->move_delay_fixed);
7008 putFile16BitBE(file, ei->move_delay_random);
7010 /* bits 0 - 15 of "move_pattern" ... */
7011 putFile16BitBE(file, ei->move_pattern & 0xffff);
7012 putFile8Bit(file, ei->move_direction_initial);
7013 putFile8Bit(file, ei->move_stepsize);
7015 putFile8Bit(file, ei->slippery_type);
7017 for (y = 0; y < 3; y++)
7018 for (x = 0; x < 3; x++)
7019 putFile16BitBE(file, ei->content.e[x][y]);
7021 putFile16BitBE(file, ei->move_enter_element);
7022 putFile16BitBE(file, ei->move_leave_element);
7023 putFile8Bit(file, ei->move_leave_type);
7025 /* ... bits 16 - 31 of "move_pattern" (not nice, but downward compatible) */
7026 putFile16BitBE(file, (ei->move_pattern >> 16) & 0xffff);
7028 putFile8Bit(file, ei->access_direction);
7030 putFile8Bit(file, ei->explosion_delay);
7031 putFile8Bit(file, ei->ignition_delay);
7032 putFile8Bit(file, ei->explosion_type);
7034 /* some free bytes for future custom property values and padding */
7035 WriteUnusedBytesToFile(file, 1);
7037 /* ---------- change page property values (48 bytes) --------------------- */
7039 for (i = 0; i < ei->num_change_pages; i++)
7041 struct ElementChangeInfo *change = &ei->change_page[i];
7042 unsigned int event_bits;
7044 /* bits 0 - 31 of "has_event[]" ... */
7046 for (j = 0; j < MIN(NUM_CHANGE_EVENTS, 32); j++)
7047 if (change->has_event[j])
7048 event_bits |= (1 << j);
7049 putFile32BitBE(file, event_bits);
7051 putFile16BitBE(file, change->target_element);
7053 putFile16BitBE(file, change->delay_fixed);
7054 putFile16BitBE(file, change->delay_random);
7055 putFile16BitBE(file, change->delay_frames);
7057 putFile16BitBE(file, change->initial_trigger_element);
7059 putFile8Bit(file, change->explode);
7060 putFile8Bit(file, change->use_target_content);
7061 putFile8Bit(file, change->only_if_complete);
7062 putFile8Bit(file, change->use_random_replace);
7064 putFile8Bit(file, change->random_percentage);
7065 putFile8Bit(file, change->replace_when);
7067 for (y = 0; y < 3; y++)
7068 for (x = 0; x < 3; x++)
7069 putFile16BitBE(file, change->target_content.e[x][y]);
7071 putFile8Bit(file, change->can_change);
7073 putFile8Bit(file, change->trigger_side);
7075 putFile8Bit(file, change->trigger_player);
7076 putFile8Bit(file, (change->trigger_page == CH_PAGE_ANY ? CH_PAGE_ANY_FILE :
7077 log_2(change->trigger_page)));
7079 putFile8Bit(file, change->has_action);
7080 putFile8Bit(file, change->action_type);
7081 putFile8Bit(file, change->action_mode);
7082 putFile16BitBE(file, change->action_arg);
7084 /* ... bits 32 - 39 of "has_event[]" (not nice, but downward compatible) */
7086 for (j = 32; j < NUM_CHANGE_EVENTS; j++)
7087 if (change->has_event[j])
7088 event_bits |= (1 << (j - 32));
7089 putFile8Bit(file, event_bits);
7095 static void SaveLevel_GRP1(FILE *file, struct LevelInfo *level, int element)
7097 struct ElementInfo *ei = &element_info[element];
7098 struct ElementGroupInfo *group = ei->group;
7101 putFile16BitBE(file, element);
7103 for (i = 0; i < MAX_ELEMENT_NAME_LEN; i++)
7104 putFile8Bit(file, ei->description[i]);
7106 putFile8Bit(file, group->num_elements);
7108 putFile8Bit(file, ei->use_gfx_element);
7109 putFile16BitBE(file, ei->gfx_element_initial);
7111 putFile8Bit(file, group->choice_mode);
7113 /* some free bytes for future values and padding */
7114 WriteUnusedBytesToFile(file, 3);
7116 for (i = 0; i < MAX_ELEMENTS_IN_GROUP; i++)
7117 putFile16BitBE(file, group->element[i]);
7121 static int SaveLevel_MicroChunk(FILE *file, struct LevelFileConfigInfo *entry,
7122 boolean write_element)
7124 int save_type = entry->save_type;
7125 int data_type = entry->data_type;
7126 int conf_type = entry->conf_type;
7127 int byte_mask = conf_type & CONF_MASK_BYTES;
7128 int element = entry->element;
7129 int default_value = entry->default_value;
7131 boolean modified = FALSE;
7133 if (byte_mask != CONF_MASK_MULTI_BYTES)
7135 void *value_ptr = entry->value;
7136 int value = (data_type == TYPE_BOOLEAN ? *(boolean *)value_ptr :
7139 /* check if any settings have been modified before saving them */
7140 if (value != default_value)
7143 /* do not save if explicitly told or if unmodified default settings */
7144 if ((save_type == SAVE_CONF_NEVER) ||
7145 (save_type == SAVE_CONF_WHEN_CHANGED && !modified))
7149 num_bytes += putFile16BitBE(file, element);
7151 num_bytes += putFile8Bit(file, conf_type);
7152 num_bytes += (byte_mask == CONF_MASK_1_BYTE ? putFile8Bit (file, value) :
7153 byte_mask == CONF_MASK_2_BYTE ? putFile16BitBE(file, value) :
7154 byte_mask == CONF_MASK_4_BYTE ? putFile32BitBE(file, value) :
7157 else if (data_type == TYPE_STRING)
7159 char *default_string = entry->default_string;
7160 char *string = (char *)(entry->value);
7161 int string_length = strlen(string);
7164 /* check if any settings have been modified before saving them */
7165 if (!strEqual(string, default_string))
7168 /* do not save if explicitly told or if unmodified default settings */
7169 if ((save_type == SAVE_CONF_NEVER) ||
7170 (save_type == SAVE_CONF_WHEN_CHANGED && !modified))
7174 num_bytes += putFile16BitBE(file, element);
7176 num_bytes += putFile8Bit(file, conf_type);
7177 num_bytes += putFile16BitBE(file, string_length);
7179 for (i = 0; i < string_length; i++)
7180 num_bytes += putFile8Bit(file, string[i]);
7182 else if (data_type == TYPE_ELEMENT_LIST)
7184 int *element_array = (int *)(entry->value);
7185 int num_elements = *(int *)(entry->num_entities);
7188 /* check if any settings have been modified before saving them */
7189 for (i = 0; i < num_elements; i++)
7190 if (element_array[i] != default_value)
7193 /* do not save if explicitly told or if unmodified default settings */
7194 if ((save_type == SAVE_CONF_NEVER) ||
7195 (save_type == SAVE_CONF_WHEN_CHANGED && !modified))
7199 num_bytes += putFile16BitBE(file, element);
7201 num_bytes += putFile8Bit(file, conf_type);
7202 num_bytes += putFile16BitBE(file, num_elements * CONF_ELEMENT_NUM_BYTES);
7204 for (i = 0; i < num_elements; i++)
7205 num_bytes += putFile16BitBE(file, element_array[i]);
7207 else if (data_type == TYPE_CONTENT_LIST)
7209 struct Content *content = (struct Content *)(entry->value);
7210 int num_contents = *(int *)(entry->num_entities);
7213 /* check if any settings have been modified before saving them */
7214 for (i = 0; i < num_contents; i++)
7215 for (y = 0; y < 3; y++)
7216 for (x = 0; x < 3; x++)
7217 if (content[i].e[x][y] != default_value)
7220 /* do not save if explicitly told or if unmodified default settings */
7221 if ((save_type == SAVE_CONF_NEVER) ||
7222 (save_type == SAVE_CONF_WHEN_CHANGED && !modified))
7226 num_bytes += putFile16BitBE(file, element);
7228 num_bytes += putFile8Bit(file, conf_type);
7229 num_bytes += putFile16BitBE(file, num_contents * CONF_CONTENT_NUM_BYTES);
7231 for (i = 0; i < num_contents; i++)
7232 for (y = 0; y < 3; y++)
7233 for (x = 0; x < 3; x++)
7234 num_bytes += putFile16BitBE(file, content[i].e[x][y]);
7240 static int SaveLevel_INFO(FILE *file, struct LevelInfo *level)
7245 li = *level; /* copy level data into temporary buffer */
7247 for (i = 0; chunk_config_INFO[i].data_type != -1; i++)
7248 chunk_size += SaveLevel_MicroChunk(file, &chunk_config_INFO[i], FALSE);
7253 static int SaveLevel_ELEM(FILE *file, struct LevelInfo *level)
7258 li = *level; /* copy level data into temporary buffer */
7260 for (i = 0; chunk_config_ELEM[i].data_type != -1; i++)
7261 chunk_size += SaveLevel_MicroChunk(file, &chunk_config_ELEM[i], TRUE);
7266 static int SaveLevel_NOTE(FILE *file, struct LevelInfo *level, int element)
7268 int envelope_nr = element - EL_ENVELOPE_1;
7272 chunk_size += putFile16BitBE(file, element);
7274 /* copy envelope data into temporary buffer */
7275 xx_envelope = level->envelope[envelope_nr];
7277 for (i = 0; chunk_config_NOTE[i].data_type != -1; i++)
7278 chunk_size += SaveLevel_MicroChunk(file, &chunk_config_NOTE[i], FALSE);
7283 static int SaveLevel_CUSX(FILE *file, struct LevelInfo *level, int element)
7285 struct ElementInfo *ei = &element_info[element];
7289 chunk_size += putFile16BitBE(file, element);
7291 xx_ei = *ei; /* copy element data into temporary buffer */
7293 /* set default description string for this specific element */
7294 strcpy(xx_default_description, getDefaultElementDescription(ei));
7297 /* set (fixed) number of content areas (may be wrong by broken level file) */
7298 /* (this is now directly corrected for broken level files after loading) */
7299 xx_num_contents = 1;
7302 for (i = 0; chunk_config_CUSX_base[i].data_type != -1; i++)
7303 chunk_size += SaveLevel_MicroChunk(file, &chunk_config_CUSX_base[i], FALSE);
7305 for (i = 0; i < ei->num_change_pages; i++)
7307 struct ElementChangeInfo *change = &ei->change_page[i];
7309 xx_current_change_page = i;
7311 xx_change = *change; /* copy change data into temporary buffer */
7314 setEventBitsFromEventFlags(change);
7316 for (j = 0; chunk_config_CUSX_change[j].data_type != -1; j++)
7317 chunk_size += SaveLevel_MicroChunk(file, &chunk_config_CUSX_change[j],
7324 static int SaveLevel_GRPX(FILE *file, struct LevelInfo *level, int element)
7326 struct ElementInfo *ei = &element_info[element];
7327 struct ElementGroupInfo *group = ei->group;
7331 chunk_size += putFile16BitBE(file, element);
7333 xx_ei = *ei; /* copy element data into temporary buffer */
7334 xx_group = *group; /* copy group data into temporary buffer */
7336 /* set default description string for this specific element */
7337 strcpy(xx_default_description, getDefaultElementDescription(ei));
7339 for (i = 0; chunk_config_GRPX[i].data_type != -1; i++)
7340 chunk_size += SaveLevel_MicroChunk(file, &chunk_config_GRPX[i], FALSE);
7345 static void SaveLevelFromFilename(struct LevelInfo *level, char *filename)
7351 if (!(file = fopen(filename, MODE_WRITE)))
7353 Error(ERR_WARN, "cannot save level file '%s'", filename);
7357 level->file_version = FILE_VERSION_ACTUAL;
7358 level->game_version = GAME_VERSION_ACTUAL;
7360 level->creation_date = getCurrentDate();
7362 putFileChunkBE(file, "RND1", CHUNK_SIZE_UNDEFINED);
7363 putFileChunkBE(file, "CAVE", CHUNK_SIZE_NONE);
7365 chunk_size = SaveLevel_VERS(NULL, level);
7366 putFileChunkBE(file, "VERS", chunk_size);
7367 SaveLevel_VERS(file, level);
7369 chunk_size = SaveLevel_DATE(NULL, level);
7370 putFileChunkBE(file, "DATE", chunk_size);
7371 SaveLevel_DATE(file, level);
7373 chunk_size = SaveLevel_NAME(NULL, level);
7374 putFileChunkBE(file, "NAME", chunk_size);
7375 SaveLevel_NAME(file, level);
7377 chunk_size = SaveLevel_AUTH(NULL, level);
7378 putFileChunkBE(file, "AUTH", chunk_size);
7379 SaveLevel_AUTH(file, level);
7381 chunk_size = SaveLevel_INFO(NULL, level);
7382 putFileChunkBE(file, "INFO", chunk_size);
7383 SaveLevel_INFO(file, level);
7385 chunk_size = SaveLevel_BODY(NULL, level);
7386 putFileChunkBE(file, "BODY", chunk_size);
7387 SaveLevel_BODY(file, level);
7389 chunk_size = SaveLevel_ELEM(NULL, level);
7390 if (chunk_size > LEVEL_CHUNK_ELEM_UNCHANGED) /* save if changed */
7392 putFileChunkBE(file, "ELEM", chunk_size);
7393 SaveLevel_ELEM(file, level);
7396 for (i = 0; i < NUM_ENVELOPES; i++)
7398 int element = EL_ENVELOPE_1 + i;
7400 chunk_size = SaveLevel_NOTE(NULL, level, element);
7401 if (chunk_size > LEVEL_CHUNK_NOTE_UNCHANGED) /* save if changed */
7403 putFileChunkBE(file, "NOTE", chunk_size);
7404 SaveLevel_NOTE(file, level, element);
7408 /* if not using template level, check for non-default custom/group elements */
7409 if (!level->use_custom_template)
7411 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
7413 int element = EL_CUSTOM_START + i;
7415 chunk_size = SaveLevel_CUSX(NULL, level, element);
7416 if (chunk_size > LEVEL_CHUNK_CUSX_UNCHANGED) /* save if changed */
7418 putFileChunkBE(file, "CUSX", chunk_size);
7419 SaveLevel_CUSX(file, level, element);
7423 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
7425 int element = EL_GROUP_START + i;
7427 chunk_size = SaveLevel_GRPX(NULL, level, element);
7428 if (chunk_size > LEVEL_CHUNK_GRPX_UNCHANGED) /* save if changed */
7430 putFileChunkBE(file, "GRPX", chunk_size);
7431 SaveLevel_GRPX(file, level, element);
7438 SetFilePermissions(filename, PERMS_PRIVATE);
7441 void SaveLevel(int nr)
7443 char *filename = getDefaultLevelFilename(nr);
7445 SaveLevelFromFilename(&level, filename);
7448 void SaveLevelTemplate()
7450 char *filename = getDefaultLevelFilename(-1);
7452 SaveLevelFromFilename(&level, filename);
7455 boolean SaveLevelChecked(int nr)
7457 char *filename = getDefaultLevelFilename(nr);
7458 boolean new_level = !fileExists(filename);
7459 boolean level_saved = FALSE;
7461 if (new_level || Request("Save this level and kill the old ?", REQ_ASK))
7466 Request("Level saved !", REQ_CONFIRM);
7474 void DumpLevel(struct LevelInfo *level)
7476 if (level->no_valid_file)
7478 Error(ERR_WARN, "cannot dump -- no valid level file found");
7483 printf_line("-", 79);
7484 printf("Level xxx (file version %08d, game version %08d)\n",
7485 level->file_version, level->game_version);
7486 printf_line("-", 79);
7488 printf("Level author: '%s'\n", level->author);
7489 printf("Level title: '%s'\n", level->name);
7491 printf("Playfield size: %d x %d\n", level->fieldx, level->fieldy);
7493 printf("Level time: %d seconds\n", level->time);
7494 printf("Gems needed: %d\n", level->gems_needed);
7496 printf("Time for magic wall: %d seconds\n", level->time_magic_wall);
7497 printf("Time for wheel: %d seconds\n", level->time_wheel);
7498 printf("Time for light: %d seconds\n", level->time_light);
7499 printf("Time for timegate: %d seconds\n", level->time_timegate);
7501 printf("Amoeba speed: %d\n", level->amoeba_speed);
7504 printf("EM style slippery gems: %s\n", (level->em_slippery_gems ? "yes" : "no"));
7505 printf("Player blocks last field: %s\n", (level->block_last_field ? "yes" : "no"));
7506 printf("SP player blocks last field: %s\n", (level->sp_block_last_field ? "yes" : "no"));
7507 printf("use spring bug: %s\n", (level->use_spring_bug ? "yes" : "no"));
7508 printf("use step counter: %s\n", (level->use_step_counter ? "yes" : "no"));
7510 printf_line("-", 79);
7514 /* ========================================================================= */
7515 /* tape file functions */
7516 /* ========================================================================= */
7518 static void setTapeInfoToDefaults()
7522 /* always start with reliable default values (empty tape) */
7525 /* default values (also for pre-1.2 tapes) with only the first player */
7526 tape.player_participates[0] = TRUE;
7527 for (i = 1; i < MAX_PLAYERS; i++)
7528 tape.player_participates[i] = FALSE;
7530 /* at least one (default: the first) player participates in every tape */
7531 tape.num_participating_players = 1;
7533 tape.level_nr = level_nr;
7535 tape.changed = FALSE;
7537 tape.recording = FALSE;
7538 tape.playing = FALSE;
7539 tape.pausing = FALSE;
7541 tape.no_valid_file = FALSE;
7544 static int LoadTape_VERS(FILE *file, int chunk_size, struct TapeInfo *tape)
7546 tape->file_version = getFileVersion(file);
7547 tape->game_version = getFileVersion(file);
7552 static int LoadTape_HEAD(FILE *file, int chunk_size, struct TapeInfo *tape)
7556 tape->random_seed = getFile32BitBE(file);
7557 tape->date = getFile32BitBE(file);
7558 tape->length = getFile32BitBE(file);
7560 /* read header fields that are new since version 1.2 */
7561 if (tape->file_version >= FILE_VERSION_1_2)
7563 byte store_participating_players = getFile8Bit(file);
7566 /* since version 1.2, tapes store which players participate in the tape */
7567 tape->num_participating_players = 0;
7568 for (i = 0; i < MAX_PLAYERS; i++)
7570 tape->player_participates[i] = FALSE;
7572 if (store_participating_players & (1 << i))
7574 tape->player_participates[i] = TRUE;
7575 tape->num_participating_players++;
7579 ReadUnusedBytesFromFile(file, TAPE_CHUNK_HEAD_UNUSED);
7581 engine_version = getFileVersion(file);
7582 if (engine_version > 0)
7583 tape->engine_version = engine_version;
7585 tape->engine_version = tape->game_version;
7591 static int LoadTape_INFO(FILE *file, int chunk_size, struct TapeInfo *tape)
7593 int level_identifier_size;
7596 level_identifier_size = getFile16BitBE(file);
7598 tape->level_identifier =
7599 checked_realloc(tape->level_identifier, level_identifier_size);
7601 for (i = 0; i < level_identifier_size; i++)
7602 tape->level_identifier[i] = getFile8Bit(file);
7604 tape->level_nr = getFile16BitBE(file);
7606 chunk_size = 2 + level_identifier_size + 2;
7611 static int LoadTape_BODY(FILE *file, int chunk_size, struct TapeInfo *tape)
7614 int chunk_size_expected =
7615 (tape->num_participating_players + 1) * tape->length;
7617 if (chunk_size_expected != chunk_size)
7619 ReadUnusedBytesFromFile(file, chunk_size);
7620 return chunk_size_expected;
7623 for (i = 0; i < tape->length; i++)
7625 if (i >= MAX_TAPE_LEN)
7628 for (j = 0; j < MAX_PLAYERS; j++)
7630 tape->pos[i].action[j] = MV_NONE;
7632 if (tape->player_participates[j])
7633 tape->pos[i].action[j] = getFile8Bit(file);
7636 tape->pos[i].delay = getFile8Bit(file);
7638 if (tape->file_version == FILE_VERSION_1_0)
7640 /* eliminate possible diagonal moves in old tapes */
7641 /* this is only for backward compatibility */
7643 byte joy_dir[4] = { JOY_LEFT, JOY_RIGHT, JOY_UP, JOY_DOWN };
7644 byte action = tape->pos[i].action[0];
7645 int k, num_moves = 0;
7647 for (k = 0; k<4; k++)
7649 if (action & joy_dir[k])
7651 tape->pos[i + num_moves].action[0] = joy_dir[k];
7653 tape->pos[i + num_moves].delay = 0;
7662 tape->length += num_moves;
7665 else if (tape->file_version < FILE_VERSION_2_0)
7667 /* convert pre-2.0 tapes to new tape format */
7669 if (tape->pos[i].delay > 1)
7672 tape->pos[i + 1] = tape->pos[i];
7673 tape->pos[i + 1].delay = 1;
7676 for (j = 0; j < MAX_PLAYERS; j++)
7677 tape->pos[i].action[j] = MV_NONE;
7678 tape->pos[i].delay--;
7689 if (i != tape->length)
7690 chunk_size = (tape->num_participating_players + 1) * i;
7695 void LoadTapeFromFilename(char *filename)
7697 char cookie[MAX_LINE_LEN];
7698 char chunk_name[CHUNK_ID_LEN + 1];
7702 /* always start with reliable default values */
7703 setTapeInfoToDefaults();
7705 if (!(file = fopen(filename, MODE_READ)))
7707 tape.no_valid_file = TRUE;
7712 getFileChunkBE(file, chunk_name, NULL);
7713 if (strEqual(chunk_name, "RND1"))
7715 getFile32BitBE(file); /* not used */
7717 getFileChunkBE(file, chunk_name, NULL);
7718 if (!strEqual(chunk_name, "TAPE"))
7720 tape.no_valid_file = TRUE;
7722 Error(ERR_WARN, "unknown format of tape file '%s'", filename);
7727 else /* check for pre-2.0 file format with cookie string */
7729 strcpy(cookie, chunk_name);
7730 fgets(&cookie[4], MAX_LINE_LEN - 4, file);
7731 if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
7732 cookie[strlen(cookie) - 1] = '\0';
7734 if (!checkCookieString(cookie, TAPE_COOKIE_TMPL))
7736 tape.no_valid_file = TRUE;
7738 Error(ERR_WARN, "unknown format of tape file '%s'", filename);
7743 if ((tape.file_version = getFileVersionFromCookieString(cookie)) == -1)
7745 tape.no_valid_file = TRUE;
7747 Error(ERR_WARN, "unsupported version of tape file '%s'", filename);
7752 /* pre-2.0 tape files have no game version, so use file version here */
7753 tape.game_version = tape.file_version;
7756 if (tape.file_version < FILE_VERSION_1_2)
7758 /* tape files from versions before 1.2.0 without chunk structure */
7759 LoadTape_HEAD(file, TAPE_CHUNK_HEAD_SIZE, &tape);
7760 LoadTape_BODY(file, 2 * tape.length, &tape);
7768 int (*loader)(FILE *, int, struct TapeInfo *);
7772 { "VERS", TAPE_CHUNK_VERS_SIZE, LoadTape_VERS },
7773 { "HEAD", TAPE_CHUNK_HEAD_SIZE, LoadTape_HEAD },
7774 { "INFO", -1, LoadTape_INFO },
7775 { "BODY", -1, LoadTape_BODY },
7779 while (getFileChunkBE(file, chunk_name, &chunk_size))
7783 while (chunk_info[i].name != NULL &&
7784 !strEqual(chunk_name, chunk_info[i].name))
7787 if (chunk_info[i].name == NULL)
7789 Error(ERR_WARN, "unknown chunk '%s' in tape file '%s'",
7790 chunk_name, filename);
7791 ReadUnusedBytesFromFile(file, chunk_size);
7793 else if (chunk_info[i].size != -1 &&
7794 chunk_info[i].size != chunk_size)
7796 Error(ERR_WARN, "wrong size (%d) of chunk '%s' in tape file '%s'",
7797 chunk_size, chunk_name, filename);
7798 ReadUnusedBytesFromFile(file, chunk_size);
7802 /* call function to load this tape chunk */
7803 int chunk_size_expected =
7804 (chunk_info[i].loader)(file, chunk_size, &tape);
7806 /* the size of some chunks cannot be checked before reading other
7807 chunks first (like "HEAD" and "BODY") that contain some header
7808 information, so check them here */
7809 if (chunk_size_expected != chunk_size)
7811 Error(ERR_WARN, "wrong size (%d) of chunk '%s' in tape file '%s'",
7812 chunk_size, chunk_name, filename);
7820 tape.length_seconds = GetTapeLength();
7823 printf("::: tape file version: %d\n", tape.file_version);
7824 printf("::: tape game version: %d\n", tape.game_version);
7825 printf("::: tape engine version: %d\n", tape.engine_version);
7829 void LoadTape(int nr)
7831 char *filename = getTapeFilename(nr);
7833 LoadTapeFromFilename(filename);
7836 void LoadSolutionTape(int nr)
7838 char *filename = getSolutionTapeFilename(nr);
7840 LoadTapeFromFilename(filename);
7843 static void SaveTape_VERS(FILE *file, struct TapeInfo *tape)
7845 putFileVersion(file, tape->file_version);
7846 putFileVersion(file, tape->game_version);
7849 static void SaveTape_HEAD(FILE *file, struct TapeInfo *tape)
7852 byte store_participating_players = 0;
7854 /* set bits for participating players for compact storage */
7855 for (i = 0; i < MAX_PLAYERS; i++)
7856 if (tape->player_participates[i])
7857 store_participating_players |= (1 << i);
7859 putFile32BitBE(file, tape->random_seed);
7860 putFile32BitBE(file, tape->date);
7861 putFile32BitBE(file, tape->length);
7863 putFile8Bit(file, store_participating_players);
7865 /* unused bytes not at the end here for 4-byte alignment of engine_version */
7866 WriteUnusedBytesToFile(file, TAPE_CHUNK_HEAD_UNUSED);
7868 putFileVersion(file, tape->engine_version);
7871 static void SaveTape_INFO(FILE *file, struct TapeInfo *tape)
7873 int level_identifier_size = strlen(tape->level_identifier) + 1;
7876 putFile16BitBE(file, level_identifier_size);
7878 for (i = 0; i < level_identifier_size; i++)
7879 putFile8Bit(file, tape->level_identifier[i]);
7881 putFile16BitBE(file, tape->level_nr);
7884 static void SaveTape_BODY(FILE *file, struct TapeInfo *tape)
7888 for (i = 0; i < tape->length; i++)
7890 for (j = 0; j < MAX_PLAYERS; j++)
7891 if (tape->player_participates[j])
7892 putFile8Bit(file, tape->pos[i].action[j]);
7894 putFile8Bit(file, tape->pos[i].delay);
7898 void SaveTape(int nr)
7900 char *filename = getTapeFilename(nr);
7903 boolean new_tape = TRUE;
7905 int num_participating_players = 0;
7906 int info_chunk_size;
7907 int body_chunk_size;
7910 InitTapeDirectory(leveldir_current->subdir);
7913 /* if a tape still exists, ask to overwrite it */
7914 if (fileExists(filename))
7917 if (!Request("Replace old tape ?", REQ_ASK))
7922 if (!(file = fopen(filename, MODE_WRITE)))
7924 Error(ERR_WARN, "cannot save level recording file '%s'", filename);
7928 tape.file_version = FILE_VERSION_ACTUAL;
7929 tape.game_version = GAME_VERSION_ACTUAL;
7931 /* count number of participating players */
7932 for (i = 0; i < MAX_PLAYERS; i++)
7933 if (tape.player_participates[i])
7934 num_participating_players++;
7936 info_chunk_size = 2 + (strlen(tape.level_identifier) + 1) + 2;
7937 body_chunk_size = (num_participating_players + 1) * tape.length;
7939 putFileChunkBE(file, "RND1", CHUNK_SIZE_UNDEFINED);
7940 putFileChunkBE(file, "TAPE", CHUNK_SIZE_NONE);
7942 putFileChunkBE(file, "VERS", TAPE_CHUNK_VERS_SIZE);
7943 SaveTape_VERS(file, &tape);
7945 putFileChunkBE(file, "HEAD", TAPE_CHUNK_HEAD_SIZE);
7946 SaveTape_HEAD(file, &tape);
7948 putFileChunkBE(file, "INFO", info_chunk_size);
7949 SaveTape_INFO(file, &tape);
7951 putFileChunkBE(file, "BODY", body_chunk_size);
7952 SaveTape_BODY(file, &tape);
7956 SetFilePermissions(filename, PERMS_PRIVATE);
7958 tape.changed = FALSE;
7962 Request("Tape saved !", REQ_CONFIRM);
7966 boolean SaveTapeChecked(int nr)
7968 char *filename = getTapeFilename(nr);
7969 boolean new_tape = !fileExists(filename);
7970 boolean tape_saved = FALSE;
7972 if (new_tape || Request("Replace old tape ?", REQ_ASK))
7977 Request("Tape saved !", REQ_CONFIRM);
7985 void DumpTape(struct TapeInfo *tape)
7987 int tape_frame_counter;
7990 if (tape->no_valid_file)
7992 Error(ERR_WARN, "cannot dump -- no valid tape file found");
7997 printf_line("-", 79);
7998 printf("Tape of Level %03d (file version %08d, game version %08d)\n",
7999 tape->level_nr, tape->file_version, tape->game_version);
8000 printf(" (effective engine version %08d)\n",
8001 tape->engine_version);
8002 printf("Level series identifier: '%s'\n", tape->level_identifier);
8003 printf_line("-", 79);
8005 tape_frame_counter = 0;
8007 for (i = 0; i < tape->length; i++)
8009 if (i >= MAX_TAPE_LEN)
8012 printf("%04d: ", i);
8014 for (j = 0; j < MAX_PLAYERS; j++)
8016 if (tape->player_participates[j])
8018 int action = tape->pos[i].action[j];
8020 printf("%d:%02x ", j, action);
8021 printf("[%c%c%c%c|%c%c] - ",
8022 (action & JOY_LEFT ? '<' : ' '),
8023 (action & JOY_RIGHT ? '>' : ' '),
8024 (action & JOY_UP ? '^' : ' '),
8025 (action & JOY_DOWN ? 'v' : ' '),
8026 (action & JOY_BUTTON_1 ? '1' : ' '),
8027 (action & JOY_BUTTON_2 ? '2' : ' '));
8031 printf("(%03d) ", tape->pos[i].delay);
8032 printf("[%05d]\n", tape_frame_counter);
8034 tape_frame_counter += tape->pos[i].delay;
8037 printf_line("-", 79);
8041 /* ========================================================================= */
8042 /* score file functions */
8043 /* ========================================================================= */
8045 void LoadScore(int nr)
8048 char *filename = getScoreFilename(nr);
8049 char cookie[MAX_LINE_LEN];
8050 char line[MAX_LINE_LEN];
8054 /* always start with reliable default values */
8055 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
8057 strcpy(highscore[i].Name, EMPTY_PLAYER_NAME);
8058 highscore[i].Score = 0;
8061 if (!(file = fopen(filename, MODE_READ)))
8064 /* check file identifier */
8065 fgets(cookie, MAX_LINE_LEN, file);
8066 if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
8067 cookie[strlen(cookie) - 1] = '\0';
8069 if (!checkCookieString(cookie, SCORE_COOKIE))
8071 Error(ERR_WARN, "unknown format of score file '%s'", filename);
8076 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
8078 fscanf(file, "%d", &highscore[i].Score);
8079 fgets(line, MAX_LINE_LEN, file);
8081 if (line[strlen(line) - 1] == '\n')
8082 line[strlen(line) - 1] = '\0';
8084 for (line_ptr = line; *line_ptr; line_ptr++)
8086 if (*line_ptr != ' ' && *line_ptr != '\t' && *line_ptr != '\0')
8088 strncpy(highscore[i].Name, line_ptr, MAX_PLAYER_NAME_LEN);
8089 highscore[i].Name[MAX_PLAYER_NAME_LEN] = '\0';
8098 void SaveScore(int nr)
8101 char *filename = getScoreFilename(nr);
8104 InitScoreDirectory(leveldir_current->subdir);
8106 if (!(file = fopen(filename, MODE_WRITE)))
8108 Error(ERR_WARN, "cannot save score for level %d", nr);
8112 fprintf(file, "%s\n\n", SCORE_COOKIE);
8114 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
8115 fprintf(file, "%d %s\n", highscore[i].Score, highscore[i].Name);
8119 SetFilePermissions(filename, PERMS_PUBLIC);
8123 /* ========================================================================= */
8124 /* setup file functions */
8125 /* ========================================================================= */
8127 #define TOKEN_STR_PLAYER_PREFIX "player_"
8130 #define SETUP_TOKEN_PLAYER_NAME 0
8131 #define SETUP_TOKEN_SOUND 1
8132 #define SETUP_TOKEN_SOUND_LOOPS 2
8133 #define SETUP_TOKEN_SOUND_MUSIC 3
8134 #define SETUP_TOKEN_SOUND_SIMPLE 4
8135 #define SETUP_TOKEN_TOONS 5
8136 #define SETUP_TOKEN_SCROLL_DELAY 6
8137 #define SETUP_TOKEN_SCROLL_DELAY_VALUE 7
8138 #define SETUP_TOKEN_SOFT_SCROLLING 8
8139 #define SETUP_TOKEN_FADE_SCREENS 9
8140 #define SETUP_TOKEN_AUTORECORD 10
8141 #define SETUP_TOKEN_SHOW_TITLESCREEN 11
8142 #define SETUP_TOKEN_QUICK_DOORS 12
8143 #define SETUP_TOKEN_TEAM_MODE 13
8144 #define SETUP_TOKEN_HANDICAP 14
8145 #define SETUP_TOKEN_SKIP_LEVELS 15
8146 #define SETUP_TOKEN_TIME_LIMIT 16
8147 #define SETUP_TOKEN_FULLSCREEN 17
8148 #define SETUP_TOKEN_FULLSCREEN_MODE 18
8149 #define SETUP_TOKEN_ASK_ON_ESCAPE 19
8150 #define SETUP_TOKEN_ASK_ON_ESCAPE_EDITOR 20
8151 #define SETUP_TOKEN_QUICK_SWITCH 21
8152 #define SETUP_TOKEN_INPUT_ON_FOCUS 22
8153 #define SETUP_TOKEN_PREFER_AGA_GRAPHICS 23
8154 #define SETUP_TOKEN_GAME_FRAME_DELAY 24
8155 #define SETUP_TOKEN_GRAPHICS_SET 25
8156 #define SETUP_TOKEN_SOUNDS_SET 26
8157 #define SETUP_TOKEN_MUSIC_SET 27
8158 #define SETUP_TOKEN_OVERRIDE_LEVEL_GRAPHICS 28
8159 #define SETUP_TOKEN_OVERRIDE_LEVEL_SOUNDS 29
8160 #define SETUP_TOKEN_OVERRIDE_LEVEL_MUSIC 30
8162 #define NUM_GLOBAL_SETUP_TOKENS 31
8165 #define SETUP_TOKEN_EDITOR_EL_BOULDERDASH 0
8166 #define SETUP_TOKEN_EDITOR_EL_EMERALD_MINE 1
8167 #define SETUP_TOKEN_EDITOR_EL_EMERALD_MINE_CLUB 2
8168 #define SETUP_TOKEN_EDITOR_EL_MORE 3
8169 #define SETUP_TOKEN_EDITOR_EL_SOKOBAN 4
8170 #define SETUP_TOKEN_EDITOR_EL_SUPAPLEX 5
8171 #define SETUP_TOKEN_EDITOR_EL_DIAMOND_CAVES 6
8172 #define SETUP_TOKEN_EDITOR_EL_DX_BOULDERDASH 7
8173 #define SETUP_TOKEN_EDITOR_EL_CHARS 8
8174 #define SETUP_TOKEN_EDITOR_EL_STEEL_CHARS 9
8175 #define SETUP_TOKEN_EDITOR_EL_CUSTOM 10
8176 #define SETUP_TOKEN_EDITOR_EL_HEADLINES 11
8177 #define SETUP_TOKEN_EDITOR_EL_USER_DEFINED 12
8178 #define SETUP_TOKEN_EDITOR_EL_DYNAMIC 13
8179 #define SETUP_TOKEN_EDITOR_EL_BY_GAME 14
8180 #define SETUP_TOKEN_EDITOR_EL_BY_TYPE 15
8181 #define SETUP_TOKEN_EDITOR_SHOW_ELEMENT_TOKEN 16
8183 #define NUM_EDITOR_SETUP_TOKENS 17
8185 /* editor cascade setup */
8186 #define SETUP_TOKEN_EDITOR_CASCADE_BD 0
8187 #define SETUP_TOKEN_EDITOR_CASCADE_EM 1
8188 #define SETUP_TOKEN_EDITOR_CASCADE_EMC 2
8189 #define SETUP_TOKEN_EDITOR_CASCADE_RND 3
8190 #define SETUP_TOKEN_EDITOR_CASCADE_SB 4
8191 #define SETUP_TOKEN_EDITOR_CASCADE_SP 5
8192 #define SETUP_TOKEN_EDITOR_CASCADE_DC 6
8193 #define SETUP_TOKEN_EDITOR_CASCADE_DX 7
8194 #define SETUP_TOKEN_EDITOR_CASCADE_TEXT 8
8195 #define SETUP_TOKEN_EDITOR_CASCADE_STEELTEXT 9
8196 #define SETUP_TOKEN_EDITOR_CASCADE_CE 10
8197 #define SETUP_TOKEN_EDITOR_CASCADE_GE 11
8198 #define SETUP_TOKEN_EDITOR_CASCADE_REF 12
8199 #define SETUP_TOKEN_EDITOR_CASCADE_USER 13
8200 #define SETUP_TOKEN_EDITOR_CASCADE_DYNAMIC 14
8202 #define NUM_EDITOR_CASCADE_SETUP_TOKENS 15
8204 /* shortcut setup */
8205 #define SETUP_TOKEN_SHORTCUT_SAVE_GAME 0
8206 #define SETUP_TOKEN_SHORTCUT_LOAD_GAME 1
8207 #define SETUP_TOKEN_SHORTCUT_TOGGLE_PAUSE 2
8208 #define SETUP_TOKEN_SHORTCUT_FOCUS_PLAYER_1 3
8209 #define SETUP_TOKEN_SHORTCUT_FOCUS_PLAYER_2 4
8210 #define SETUP_TOKEN_SHORTCUT_FOCUS_PLAYER_3 5
8211 #define SETUP_TOKEN_SHORTCUT_FOCUS_PLAYER_4 6
8212 #define SETUP_TOKEN_SHORTCUT_FOCUS_PLAYER_ALL 7
8214 #define NUM_SHORTCUT_SETUP_TOKENS 8
8217 #define SETUP_TOKEN_PLAYER_USE_JOYSTICK 0
8218 #define SETUP_TOKEN_PLAYER_JOY_DEVICE_NAME 1
8219 #define SETUP_TOKEN_PLAYER_JOY_XLEFT 2
8220 #define SETUP_TOKEN_PLAYER_JOY_XMIDDLE 3
8221 #define SETUP_TOKEN_PLAYER_JOY_XRIGHT 4
8222 #define SETUP_TOKEN_PLAYER_JOY_YUPPER 5
8223 #define SETUP_TOKEN_PLAYER_JOY_YMIDDLE 6
8224 #define SETUP_TOKEN_PLAYER_JOY_YLOWER 7
8225 #define SETUP_TOKEN_PLAYER_JOY_SNAP 8
8226 #define SETUP_TOKEN_PLAYER_JOY_DROP 9
8227 #define SETUP_TOKEN_PLAYER_KEY_LEFT 10
8228 #define SETUP_TOKEN_PLAYER_KEY_RIGHT 11
8229 #define SETUP_TOKEN_PLAYER_KEY_UP 12
8230 #define SETUP_TOKEN_PLAYER_KEY_DOWN 13
8231 #define SETUP_TOKEN_PLAYER_KEY_SNAP 14
8232 #define SETUP_TOKEN_PLAYER_KEY_DROP 15
8234 #define NUM_PLAYER_SETUP_TOKENS 16
8237 #define SETUP_TOKEN_SYSTEM_SDL_VIDEODRIVER 0
8238 #define SETUP_TOKEN_SYSTEM_SDL_AUDIODRIVER 1
8239 #define SETUP_TOKEN_SYSTEM_AUDIO_FRAGMENT_SIZE 2
8241 #define NUM_SYSTEM_SETUP_TOKENS 3
8244 #define SETUP_TOKEN_OPTIONS_VERBOSE 0
8246 #define NUM_OPTIONS_SETUP_TOKENS 1
8249 static struct SetupInfo si;
8250 static struct SetupEditorInfo sei;
8251 static struct SetupEditorCascadeInfo seci;
8252 static struct SetupShortcutInfo ssi;
8253 static struct SetupInputInfo sii;
8254 static struct SetupSystemInfo syi;
8255 static struct OptionInfo soi;
8257 static struct TokenInfo global_setup_tokens[] =
8259 { TYPE_STRING, &si.player_name, "player_name" },
8260 { TYPE_SWITCH, &si.sound, "sound" },
8261 { TYPE_SWITCH, &si.sound_loops, "repeating_sound_loops" },
8262 { TYPE_SWITCH, &si.sound_music, "background_music" },
8263 { TYPE_SWITCH, &si.sound_simple, "simple_sound_effects" },
8264 { TYPE_SWITCH, &si.toons, "toons" },
8265 { TYPE_SWITCH, &si.scroll_delay, "scroll_delay" },
8266 { TYPE_INTEGER,&si.scroll_delay_value,"scroll_delay_value" },
8267 { TYPE_SWITCH, &si.soft_scrolling, "soft_scrolling" },
8268 { TYPE_SWITCH, &si.fade_screens, "fade_screens" },
8269 { TYPE_SWITCH, &si.autorecord, "automatic_tape_recording" },
8270 { TYPE_SWITCH, &si.show_titlescreen, "show_titlescreen" },
8271 { TYPE_SWITCH, &si.quick_doors, "quick_doors" },
8272 { TYPE_SWITCH, &si.team_mode, "team_mode" },
8273 { TYPE_SWITCH, &si.handicap, "handicap" },
8274 { TYPE_SWITCH, &si.skip_levels, "skip_levels" },
8275 { TYPE_SWITCH, &si.time_limit, "time_limit" },
8276 { TYPE_SWITCH, &si.fullscreen, "fullscreen" },
8277 { TYPE_STRING, &si.fullscreen_mode, "fullscreen_mode" },
8278 { TYPE_SWITCH, &si.ask_on_escape, "ask_on_escape" },
8279 { TYPE_SWITCH, &si.ask_on_escape_editor, "ask_on_escape_editor" },
8280 { TYPE_SWITCH, &si.quick_switch, "quick_player_switch" },
8281 { TYPE_SWITCH, &si.input_on_focus, "input_on_focus" },
8282 { TYPE_SWITCH, &si.prefer_aga_graphics, "prefer_aga_graphics" },
8283 { TYPE_INTEGER,&si.game_frame_delay, "game_frame_delay" },
8284 { TYPE_STRING, &si.graphics_set, "graphics_set" },
8285 { TYPE_STRING, &si.sounds_set, "sounds_set" },
8286 { TYPE_STRING, &si.music_set, "music_set" },
8287 { TYPE_SWITCH3,&si.override_level_graphics, "override_level_graphics" },
8288 { TYPE_SWITCH3,&si.override_level_sounds, "override_level_sounds" },
8289 { TYPE_SWITCH3,&si.override_level_music, "override_level_music" },
8292 static boolean not_used = FALSE;
8293 static struct TokenInfo editor_setup_tokens[] =
8296 { TYPE_SWITCH, ¬_used, "editor.el_boulderdash" },
8297 { TYPE_SWITCH, ¬_used, "editor.el_emerald_mine" },
8298 { TYPE_SWITCH, ¬_used, "editor.el_emerald_mine_club" },
8299 { TYPE_SWITCH, ¬_used, "editor.el_more" },
8300 { TYPE_SWITCH, ¬_used, "editor.el_sokoban" },
8301 { TYPE_SWITCH, ¬_used, "editor.el_supaplex" },
8302 { TYPE_SWITCH, ¬_used, "editor.el_diamond_caves" },
8303 { TYPE_SWITCH, ¬_used, "editor.el_dx_boulderdash" },
8305 { TYPE_SWITCH, &sei.el_boulderdash, "editor.el_boulderdash" },
8306 { TYPE_SWITCH, &sei.el_emerald_mine, "editor.el_emerald_mine" },
8307 { TYPE_SWITCH, &sei.el_emerald_mine_club,"editor.el_emerald_mine_club"},
8308 { TYPE_SWITCH, &sei.el_more, "editor.el_more" },
8309 { TYPE_SWITCH, &sei.el_sokoban, "editor.el_sokoban" },
8310 { TYPE_SWITCH, &sei.el_supaplex, "editor.el_supaplex" },
8311 { TYPE_SWITCH, &sei.el_diamond_caves, "editor.el_diamond_caves" },
8312 { TYPE_SWITCH, &sei.el_dx_boulderdash,"editor.el_dx_boulderdash" },
8314 { TYPE_SWITCH, &sei.el_chars, "editor.el_chars" },
8315 { TYPE_SWITCH, &sei.el_steel_chars, "editor.el_steel_chars" },
8316 { TYPE_SWITCH, &sei.el_custom, "editor.el_custom" },
8318 { TYPE_SWITCH, ¬_used, "editor.el_headlines" },
8320 { TYPE_SWITCH, &sei.el_headlines, "editor.el_headlines" },
8322 { TYPE_SWITCH, &sei.el_user_defined, "editor.el_user_defined" },
8323 { TYPE_SWITCH, &sei.el_dynamic, "editor.el_dynamic" },
8324 { TYPE_SWITCH, &sei.el_by_game, "editor.el_by_game" },
8325 { TYPE_SWITCH, &sei.el_by_type, "editor.el_by_type" },
8326 { TYPE_SWITCH, &sei.show_element_token,"editor.show_element_token" },
8329 static struct TokenInfo editor_cascade_setup_tokens[] =
8331 { TYPE_SWITCH, &seci.el_bd, "editor.cascade.el_bd" },
8332 { TYPE_SWITCH, &seci.el_em, "editor.cascade.el_em" },
8333 { TYPE_SWITCH, &seci.el_emc, "editor.cascade.el_emc" },
8334 { TYPE_SWITCH, &seci.el_rnd, "editor.cascade.el_rnd" },
8335 { TYPE_SWITCH, &seci.el_sb, "editor.cascade.el_sb" },
8336 { TYPE_SWITCH, &seci.el_sp, "editor.cascade.el_sp" },
8337 { TYPE_SWITCH, &seci.el_dc, "editor.cascade.el_dc" },
8338 { TYPE_SWITCH, &seci.el_dx, "editor.cascade.el_dx" },
8339 { TYPE_SWITCH, &seci.el_chars, "editor.cascade.el_chars" },
8340 { TYPE_SWITCH, &seci.el_steel_chars, "editor.cascade.el_steel_chars" },
8341 { TYPE_SWITCH, &seci.el_ce, "editor.cascade.el_ce" },
8342 { TYPE_SWITCH, &seci.el_ge, "editor.cascade.el_ge" },
8343 { TYPE_SWITCH, &seci.el_ref, "editor.cascade.el_ref" },
8344 { TYPE_SWITCH, &seci.el_user, "editor.cascade.el_user" },
8345 { TYPE_SWITCH, &seci.el_dynamic, "editor.cascade.el_dynamic" },
8348 static struct TokenInfo shortcut_setup_tokens[] =
8350 { TYPE_KEY_X11, &ssi.save_game, "shortcut.save_game" },
8351 { TYPE_KEY_X11, &ssi.load_game, "shortcut.load_game" },
8352 { TYPE_KEY_X11, &ssi.toggle_pause, "shortcut.toggle_pause" },
8353 { TYPE_KEY_X11, &ssi.focus_player[0], "shortcut.focus_player_1" },
8354 { TYPE_KEY_X11, &ssi.focus_player[1], "shortcut.focus_player_2" },
8355 { TYPE_KEY_X11, &ssi.focus_player[2], "shortcut.focus_player_3" },
8356 { TYPE_KEY_X11, &ssi.focus_player[3], "shortcut.focus_player_4" },
8357 { TYPE_KEY_X11, &ssi.focus_player_all,"shortcut.focus_player_all" },
8360 static struct TokenInfo player_setup_tokens[] =
8362 { TYPE_BOOLEAN, &sii.use_joystick, ".use_joystick" },
8363 { TYPE_STRING, &sii.joy.device_name, ".joy.device_name" },
8364 { TYPE_INTEGER, &sii.joy.xleft, ".joy.xleft" },
8365 { TYPE_INTEGER, &sii.joy.xmiddle, ".joy.xmiddle" },
8366 { TYPE_INTEGER, &sii.joy.xright, ".joy.xright" },
8367 { TYPE_INTEGER, &sii.joy.yupper, ".joy.yupper" },
8368 { TYPE_INTEGER, &sii.joy.ymiddle, ".joy.ymiddle" },
8369 { TYPE_INTEGER, &sii.joy.ylower, ".joy.ylower" },
8370 { TYPE_INTEGER, &sii.joy.snap, ".joy.snap_field" },
8371 { TYPE_INTEGER, &sii.joy.drop, ".joy.place_bomb" },
8372 { TYPE_KEY_X11, &sii.key.left, ".key.move_left" },
8373 { TYPE_KEY_X11, &sii.key.right, ".key.move_right" },
8374 { TYPE_KEY_X11, &sii.key.up, ".key.move_up" },
8375 { TYPE_KEY_X11, &sii.key.down, ".key.move_down" },
8376 { TYPE_KEY_X11, &sii.key.snap, ".key.snap_field" },
8377 { TYPE_KEY_X11, &sii.key.drop, ".key.place_bomb" },
8380 static struct TokenInfo system_setup_tokens[] =
8382 { TYPE_STRING, &syi.sdl_videodriver, "system.sdl_videodriver" },
8383 { TYPE_STRING, &syi.sdl_audiodriver, "system.sdl_audiodriver" },
8384 { TYPE_INTEGER, &syi.audio_fragment_size,"system.audio_fragment_size" },
8387 static struct TokenInfo options_setup_tokens[] =
8389 { TYPE_BOOLEAN, &soi.verbose, "options.verbose" },
8392 static char *get_corrected_login_name(char *login_name)
8394 /* needed because player name must be a fixed length string */
8395 char *login_name_new = checked_malloc(MAX_PLAYER_NAME_LEN + 1);
8397 strncpy(login_name_new, login_name, MAX_PLAYER_NAME_LEN);
8398 login_name_new[MAX_PLAYER_NAME_LEN] = '\0';
8400 if (strlen(login_name) > MAX_PLAYER_NAME_LEN) /* name has been cut */
8401 if (strchr(login_name_new, ' '))
8402 *strchr(login_name_new, ' ') = '\0';
8404 return login_name_new;
8407 static void setSetupInfoToDefaults(struct SetupInfo *si)
8411 si->player_name = get_corrected_login_name(getLoginName());
8414 si->sound_loops = TRUE;
8415 si->sound_music = TRUE;
8416 si->sound_simple = TRUE;
8418 si->scroll_delay = TRUE;
8419 si->scroll_delay_value = STD_SCROLL_DELAY;
8420 si->soft_scrolling = TRUE;
8421 si->fade_screens = TRUE;
8422 si->autorecord = TRUE;
8423 si->show_titlescreen = TRUE;
8424 si->quick_doors = FALSE;
8425 si->team_mode = FALSE;
8426 si->handicap = TRUE;
8427 si->skip_levels = TRUE;
8428 si->time_limit = TRUE;
8429 si->fullscreen = FALSE;
8430 si->fullscreen_mode = getStringCopy(DEFAULT_FULLSCREEN_MODE);
8431 si->ask_on_escape = TRUE;
8432 si->ask_on_escape_editor = TRUE;
8433 si->quick_switch = FALSE;
8434 si->input_on_focus = FALSE;
8435 si->prefer_aga_graphics = TRUE;
8436 si->game_frame_delay = GAME_FRAME_DELAY;
8438 si->graphics_set = getStringCopy(GFX_DEFAULT_SUBDIR);
8439 si->sounds_set = getStringCopy(SND_DEFAULT_SUBDIR);
8440 si->music_set = getStringCopy(MUS_DEFAULT_SUBDIR);
8441 si->override_level_graphics = FALSE;
8442 si->override_level_sounds = FALSE;
8443 si->override_level_music = FALSE;
8445 si->editor.el_boulderdash = TRUE;
8446 si->editor.el_emerald_mine = TRUE;
8447 si->editor.el_emerald_mine_club = TRUE;
8448 si->editor.el_more = TRUE;
8449 si->editor.el_sokoban = TRUE;
8450 si->editor.el_supaplex = TRUE;
8451 si->editor.el_diamond_caves = TRUE;
8452 si->editor.el_dx_boulderdash = TRUE;
8453 si->editor.el_chars = TRUE;
8454 si->editor.el_steel_chars = TRUE;
8455 si->editor.el_custom = TRUE;
8457 si->editor.el_headlines = TRUE;
8458 si->editor.el_user_defined = FALSE;
8459 si->editor.el_dynamic = TRUE;
8461 si->editor.show_element_token = FALSE;
8463 si->shortcut.save_game = DEFAULT_KEY_SAVE_GAME;
8464 si->shortcut.load_game = DEFAULT_KEY_LOAD_GAME;
8465 si->shortcut.toggle_pause = DEFAULT_KEY_TOGGLE_PAUSE;
8467 si->shortcut.focus_player[0] = DEFAULT_KEY_FOCUS_PLAYER_1;
8468 si->shortcut.focus_player[1] = DEFAULT_KEY_FOCUS_PLAYER_2;
8469 si->shortcut.focus_player[2] = DEFAULT_KEY_FOCUS_PLAYER_3;
8470 si->shortcut.focus_player[3] = DEFAULT_KEY_FOCUS_PLAYER_4;
8471 si->shortcut.focus_player_all = DEFAULT_KEY_FOCUS_PLAYER_ALL;
8473 for (i = 0; i < MAX_PLAYERS; i++)
8475 si->input[i].use_joystick = FALSE;
8476 si->input[i].joy.device_name=getStringCopy(getDeviceNameFromJoystickNr(i));
8477 si->input[i].joy.xleft = JOYSTICK_XLEFT;
8478 si->input[i].joy.xmiddle = JOYSTICK_XMIDDLE;
8479 si->input[i].joy.xright = JOYSTICK_XRIGHT;
8480 si->input[i].joy.yupper = JOYSTICK_YUPPER;
8481 si->input[i].joy.ymiddle = JOYSTICK_YMIDDLE;
8482 si->input[i].joy.ylower = JOYSTICK_YLOWER;
8483 si->input[i].joy.snap = (i == 0 ? JOY_BUTTON_1 : 0);
8484 si->input[i].joy.drop = (i == 0 ? JOY_BUTTON_2 : 0);
8485 si->input[i].key.left = (i == 0 ? DEFAULT_KEY_LEFT : KSYM_UNDEFINED);
8486 si->input[i].key.right = (i == 0 ? DEFAULT_KEY_RIGHT : KSYM_UNDEFINED);
8487 si->input[i].key.up = (i == 0 ? DEFAULT_KEY_UP : KSYM_UNDEFINED);
8488 si->input[i].key.down = (i == 0 ? DEFAULT_KEY_DOWN : KSYM_UNDEFINED);
8489 si->input[i].key.snap = (i == 0 ? DEFAULT_KEY_SNAP : KSYM_UNDEFINED);
8490 si->input[i].key.drop = (i == 0 ? DEFAULT_KEY_DROP : KSYM_UNDEFINED);
8493 si->system.sdl_videodriver = getStringCopy(ARG_DEFAULT);
8494 si->system.sdl_audiodriver = getStringCopy(ARG_DEFAULT);
8495 si->system.audio_fragment_size = DEFAULT_AUDIO_FRAGMENT_SIZE;
8497 si->options.verbose = FALSE;
8499 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
8500 si->handicap = FALSE;
8501 si->fullscreen = TRUE;
8502 si->override_level_graphics = AUTO;
8503 si->override_level_sounds = AUTO;
8504 si->override_level_music = AUTO;
8508 static void setSetupInfoToDefaults_EditorCascade(struct SetupInfo *si)
8510 si->editor_cascade.el_bd = TRUE;
8511 si->editor_cascade.el_em = TRUE;
8512 si->editor_cascade.el_emc = TRUE;
8513 si->editor_cascade.el_rnd = TRUE;
8514 si->editor_cascade.el_sb = TRUE;
8515 si->editor_cascade.el_sp = TRUE;
8516 si->editor_cascade.el_dc = TRUE;
8517 si->editor_cascade.el_dx = TRUE;
8519 si->editor_cascade.el_chars = FALSE;
8520 si->editor_cascade.el_steel_chars = FALSE;
8521 si->editor_cascade.el_ce = FALSE;
8522 si->editor_cascade.el_ge = FALSE;
8523 si->editor_cascade.el_ref = FALSE;
8524 si->editor_cascade.el_user = FALSE;
8525 si->editor_cascade.el_dynamic = FALSE;
8528 static void decodeSetupFileHash(SetupFileHash *setup_file_hash)
8532 if (!setup_file_hash)
8537 for (i = 0; i < NUM_GLOBAL_SETUP_TOKENS; i++)
8538 setSetupInfo(global_setup_tokens, i,
8539 getHashEntry(setup_file_hash, global_setup_tokens[i].text));
8544 for (i = 0; i < NUM_EDITOR_SETUP_TOKENS; i++)
8545 setSetupInfo(editor_setup_tokens, i,
8546 getHashEntry(setup_file_hash,editor_setup_tokens[i].text));
8549 /* shortcut setup */
8550 ssi = setup.shortcut;
8551 for (i = 0; i < NUM_SHORTCUT_SETUP_TOKENS; i++)
8552 setSetupInfo(shortcut_setup_tokens, i,
8553 getHashEntry(setup_file_hash,shortcut_setup_tokens[i].text));
8554 setup.shortcut = ssi;
8557 for (pnr = 0; pnr < MAX_PLAYERS; pnr++)
8561 sprintf(prefix, "%s%d", TOKEN_STR_PLAYER_PREFIX, pnr + 1);
8563 sii = setup.input[pnr];
8564 for (i = 0; i < NUM_PLAYER_SETUP_TOKENS; i++)
8566 char full_token[100];
8568 sprintf(full_token, "%s%s", prefix, player_setup_tokens[i].text);
8569 setSetupInfo(player_setup_tokens, i,
8570 getHashEntry(setup_file_hash, full_token));
8572 setup.input[pnr] = sii;
8577 for (i = 0; i < NUM_SYSTEM_SETUP_TOKENS; i++)
8578 setSetupInfo(system_setup_tokens, i,
8579 getHashEntry(setup_file_hash, system_setup_tokens[i].text));
8583 soi = setup.options;
8584 for (i = 0; i < NUM_OPTIONS_SETUP_TOKENS; i++)
8585 setSetupInfo(options_setup_tokens, i,
8586 getHashEntry(setup_file_hash, options_setup_tokens[i].text));
8587 setup.options = soi;
8590 static void decodeSetupFileHash_EditorCascade(SetupFileHash *setup_file_hash)
8594 if (!setup_file_hash)
8597 /* editor cascade setup */
8598 seci = setup.editor_cascade;
8599 for (i = 0; i < NUM_EDITOR_CASCADE_SETUP_TOKENS; i++)
8600 setSetupInfo(editor_cascade_setup_tokens, i,
8601 getHashEntry(setup_file_hash,
8602 editor_cascade_setup_tokens[i].text));
8603 setup.editor_cascade = seci;
8608 char *filename = getSetupFilename();
8609 SetupFileHash *setup_file_hash = NULL;
8611 /* always start with reliable default values */
8612 setSetupInfoToDefaults(&setup);
8614 setup_file_hash = loadSetupFileHash(filename);
8616 if (setup_file_hash)
8618 char *player_name_new;
8620 checkSetupFileHashIdentifier(setup_file_hash, filename,getCookie("SETUP"));
8621 decodeSetupFileHash(setup_file_hash);
8623 freeSetupFileHash(setup_file_hash);
8625 /* needed to work around problems with fixed length strings */
8626 player_name_new = get_corrected_login_name(setup.player_name);
8627 free(setup.player_name);
8628 setup.player_name = player_name_new;
8630 /* "scroll_delay: on(3) / off(0)" was replaced by scroll delay value */
8631 if (setup.scroll_delay == FALSE)
8633 setup.scroll_delay_value = MIN_SCROLL_DELAY;
8634 setup.scroll_delay = TRUE; /* now always "on" */
8637 /* make sure that scroll delay value stays inside valid range */
8638 setup.scroll_delay_value =
8639 MIN(MAX(MIN_SCROLL_DELAY, setup.scroll_delay_value), MAX_SCROLL_DELAY);
8642 Error(ERR_WARN, "using default setup values");
8645 void LoadSetup_EditorCascade()
8647 char *filename = getPath2(getSetupDir(), EDITORCASCADE_FILENAME);
8648 SetupFileHash *setup_file_hash = NULL;
8650 /* always start with reliable default values */
8651 setSetupInfoToDefaults_EditorCascade(&setup);
8653 setup_file_hash = loadSetupFileHash(filename);
8655 if (setup_file_hash)
8657 checkSetupFileHashIdentifier(setup_file_hash, filename,getCookie("SETUP"));
8658 decodeSetupFileHash_EditorCascade(setup_file_hash);
8660 freeSetupFileHash(setup_file_hash);
8668 char *filename = getSetupFilename();
8672 InitUserDataDirectory();
8674 if (!(file = fopen(filename, MODE_WRITE)))
8676 Error(ERR_WARN, "cannot write setup file '%s'", filename);
8680 fprintf(file, "%s\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER,
8681 getCookie("SETUP")));
8682 fprintf(file, "\n");
8686 for (i = 0; i < NUM_GLOBAL_SETUP_TOKENS; i++)
8688 /* just to make things nicer :) */
8689 if (i == SETUP_TOKEN_PLAYER_NAME + 1 ||
8690 i == SETUP_TOKEN_GRAPHICS_SET)
8691 fprintf(file, "\n");
8693 fprintf(file, "%s\n", getSetupLine(global_setup_tokens, "", i));
8698 fprintf(file, "\n");
8699 for (i = 0; i < NUM_EDITOR_SETUP_TOKENS; i++)
8700 fprintf(file, "%s\n", getSetupLine(editor_setup_tokens, "", i));
8702 /* shortcut setup */
8703 ssi = setup.shortcut;
8704 fprintf(file, "\n");
8705 for (i = 0; i < NUM_SHORTCUT_SETUP_TOKENS; i++)
8706 fprintf(file, "%s\n", getSetupLine(shortcut_setup_tokens, "", i));
8709 for (pnr = 0; pnr < MAX_PLAYERS; pnr++)
8713 sprintf(prefix, "%s%d", TOKEN_STR_PLAYER_PREFIX, pnr + 1);
8714 fprintf(file, "\n");
8716 sii = setup.input[pnr];
8717 for (i = 0; i < NUM_PLAYER_SETUP_TOKENS; i++)
8718 fprintf(file, "%s\n", getSetupLine(player_setup_tokens, prefix, i));
8723 fprintf(file, "\n");
8724 for (i = 0; i < NUM_SYSTEM_SETUP_TOKENS; i++)
8725 fprintf(file, "%s\n", getSetupLine(system_setup_tokens, "", i));
8728 soi = setup.options;
8729 fprintf(file, "\n");
8730 for (i = 0; i < NUM_OPTIONS_SETUP_TOKENS; i++)
8731 fprintf(file, "%s\n", getSetupLine(options_setup_tokens, "", i));
8735 SetFilePermissions(filename, PERMS_PRIVATE);
8738 void SaveSetup_EditorCascade()
8740 char *filename = getPath2(getSetupDir(), EDITORCASCADE_FILENAME);
8744 InitUserDataDirectory();
8746 if (!(file = fopen(filename, MODE_WRITE)))
8748 Error(ERR_WARN, "cannot write editor cascade state file '%s'", filename);
8753 fprintf(file, "%s\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER,
8754 getCookie("SETUP")));
8755 fprintf(file, "\n");
8757 seci = setup.editor_cascade;
8758 fprintf(file, "\n");
8759 for (i = 0; i < NUM_EDITOR_CASCADE_SETUP_TOKENS; i++)
8760 fprintf(file, "%s\n", getSetupLine(editor_cascade_setup_tokens, "", i));
8764 SetFilePermissions(filename, PERMS_PRIVATE);
8769 void LoadCustomElementDescriptions()
8771 char *filename = getCustomArtworkConfigFilename(ARTWORK_TYPE_GRAPHICS);
8772 SetupFileHash *setup_file_hash;
8775 for (i = 0; i < NUM_FILE_ELEMENTS; i++)
8777 if (element_info[i].custom_description != NULL)
8779 free(element_info[i].custom_description);
8780 element_info[i].custom_description = NULL;
8784 if ((setup_file_hash = loadSetupFileHash(filename)) == NULL)
8787 for (i = 0; i < NUM_FILE_ELEMENTS; i++)
8789 char *token = getStringCat2(element_info[i].token_name, ".name");
8790 char *value = getHashEntry(setup_file_hash, token);
8793 element_info[i].custom_description = getStringCopy(value);
8798 freeSetupFileHash(setup_file_hash);
8801 static int getElementFromToken(char *token)
8804 char *value = getHashEntry(element_token_hash, token);
8811 /* !!! OPTIMIZE THIS BY USING HASH !!! */
8812 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
8813 if (strEqual(token, element_info[i].token_name))
8817 Error(ERR_WARN, "unknown element token '%s'", token);
8819 return EL_UNDEFINED;
8822 static int get_token_parameter_value(char *token, char *value_raw)
8826 if (token == NULL || value_raw == NULL)
8827 return ARG_UNDEFINED_VALUE;
8829 suffix = strrchr(token, '.');
8834 if (strEqual(suffix, ".element"))
8835 return getElementFromToken(value_raw);
8839 if (strncmp(suffix, ".font", 5) == 0)
8843 /* !!! OPTIMIZE THIS BY USING HASH !!! */
8844 for (i = 0; i < NUM_FONTS; i++)
8845 if (strEqual(value_raw, font_info[i].token_name))
8848 /* if font not found, use reliable default value */
8849 return FONT_INITIAL_1;
8853 /* !!! USE CORRECT VALUE TYPE (currently works also for TYPE_BOOLEAN) !!! */
8854 return get_parameter_value(value_raw, suffix, TYPE_INTEGER);
8857 void InitMenuDesignSettings_Static()
8860 static SetupFileHash *image_config_hash = NULL;
8865 if (image_config_hash == NULL)
8867 image_config_hash = newSetupFileHash();
8869 for (i = 0; image_config[i].token != NULL; i++)
8870 setHashEntry(image_config_hash,
8871 image_config[i].token,
8872 image_config[i].value);
8877 /* always start with reliable default values from static default config */
8878 for (i = 0; image_config_vars[i].token != NULL; i++)
8880 char *value = getHashEntry(image_config_hash, image_config_vars[i].token);
8883 *image_config_vars[i].value =
8884 get_token_parameter_value(image_config_vars[i].token, value);
8891 /* always start with reliable default values from static default config */
8892 for (i = 0; image_config_vars[i].token != NULL; i++)
8893 for (j = 0; image_config[j].token != NULL; j++)
8894 if (strEqual(image_config_vars[i].token, image_config[j].token))
8895 *image_config_vars[i].value =
8896 get_token_parameter_value(image_config_vars[i].token,
8897 image_config[j].value);
8901 static void InitMenuDesignSettings_SpecialPreProcessing()
8905 /* the following initializes hierarchical values from static configuration */
8907 /* special case: initialize "ARG_DEFAULT" values in static default config */
8908 /* (e.g., initialize "[titlemessage].fade_mode" from "[title].fade_mode") */
8909 titlemessage_initial_default.fade_mode = title_initial_default.fade_mode;
8910 titlemessage_initial_default.fade_delay = title_initial_default.fade_delay;
8911 titlemessage_initial_default.post_delay = title_initial_default.post_delay;
8912 titlemessage_initial_default.auto_delay = title_initial_default.auto_delay;
8913 titlemessage_default.fade_mode = title_default.fade_mode;
8914 titlemessage_default.fade_delay = title_default.fade_delay;
8915 titlemessage_default.post_delay = title_default.post_delay;
8916 titlemessage_default.auto_delay = title_default.auto_delay;
8918 /* special case: initialize "ARG_DEFAULT" values in static default config */
8919 /* (e.g., init "titlemessage_1.fade_mode" from "[titlemessage].fade_mode") */
8920 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
8922 titlemessage_initial[i] = titlemessage_initial_default;
8923 titlemessage[i] = titlemessage_default;
8926 /* special case: initialize "ARG_DEFAULT" values in static default config */
8927 /* (eg, init "menu.enter_screen.SCORES.xyz" from "menu.enter_screen.xyz") */
8928 for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
8930 menu.enter_screen[i] = menu.enter_screen[GFX_SPECIAL_ARG_DEFAULT];
8931 menu.leave_screen[i] = menu.leave_screen[GFX_SPECIAL_ARG_DEFAULT];
8935 static void InitMenuDesignSettings_SpecialPostProcessing()
8937 /* special case: initialize later added SETUP list size from LEVELS value */
8938 if (menu.list_size[GAME_MODE_SETUP] == -1)
8939 menu.list_size[GAME_MODE_SETUP] = menu.list_size[GAME_MODE_LEVELS];
8942 static void LoadMenuDesignSettingsFromFilename(char *filename)
8944 static struct TitleMessageInfo tmi;
8945 static struct TokenInfo titlemessage_tokens[] =
8947 { TYPE_INTEGER, &tmi.x, ".x" },
8948 { TYPE_INTEGER, &tmi.y, ".y" },
8949 { TYPE_INTEGER, &tmi.width, ".width" },
8950 { TYPE_INTEGER, &tmi.height, ".height" },
8951 { TYPE_INTEGER, &tmi.chars, ".chars" },
8952 { TYPE_INTEGER, &tmi.lines, ".lines" },
8953 { TYPE_INTEGER, &tmi.align, ".align" },
8954 { TYPE_INTEGER, &tmi.valign, ".valign" },
8955 { TYPE_INTEGER, &tmi.font, ".font" },
8956 { TYPE_BOOLEAN, &tmi.autowrap, ".autowrap" },
8957 { TYPE_BOOLEAN, &tmi.centered, ".centered" },
8958 { TYPE_BOOLEAN, &tmi.parse_comments, ".parse_comments" },
8959 { TYPE_INTEGER, &tmi.sort_priority, ".sort_priority" },
8960 { TYPE_INTEGER, &tmi.fade_mode, ".fade_mode" },
8961 { TYPE_INTEGER, &tmi.fade_delay, ".fade_delay" },
8962 { TYPE_INTEGER, &tmi.post_delay, ".post_delay" },
8963 { TYPE_INTEGER, &tmi.auto_delay, ".auto_delay" },
8969 struct TitleMessageInfo *array;
8972 titlemessage_arrays[] =
8974 { titlemessage_initial, "[titlemessage_initial]" },
8975 { titlemessage, "[titlemessage]" },
8979 SetupFileHash *setup_file_hash;
8983 printf("LoadMenuDesignSettings from file '%s' ...\n", filename);
8986 if ((setup_file_hash = loadSetupFileHash(filename)) == NULL)
8989 /* the following initializes hierarchical values from dynamic configuration */
8991 /* special case: initialize with default values that may be overwritten */
8992 /* (e.g., init "menu.draw_xoffset.INFO" from "menu.draw_xoffset") */
8993 for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
8995 char *value_1 = getHashEntry(setup_file_hash, "menu.draw_xoffset");
8996 char *value_2 = getHashEntry(setup_file_hash, "menu.draw_yoffset");
8997 char *value_3 = getHashEntry(setup_file_hash, "menu.list_size");
8999 if (value_1 != NULL)
9000 menu.draw_xoffset[i] = get_integer_from_string(value_1);
9001 if (value_2 != NULL)
9002 menu.draw_yoffset[i] = get_integer_from_string(value_2);
9003 if (value_3 != NULL)
9004 menu.list_size[i] = get_integer_from_string(value_3);
9007 /* special case: initialize with default values that may be overwritten */
9008 /* (eg, init "menu.draw_xoffset.INFO[XXX]" from "menu.draw_xoffset.INFO") */
9009 for (i = 0; i < NUM_SPECIAL_GFX_INFO_ARGS; i++)
9011 char *value_1 = getHashEntry(setup_file_hash, "menu.draw_xoffset.INFO");
9012 char *value_2 = getHashEntry(setup_file_hash, "menu.draw_yoffset.INFO");
9014 if (value_1 != NULL)
9015 menu.draw_xoffset_info[i] = get_integer_from_string(value_1);
9016 if (value_2 != NULL)
9017 menu.draw_yoffset_info[i] = get_integer_from_string(value_2);
9020 /* special case: initialize with default values that may be overwritten */
9021 /* (eg, init "menu.draw_xoffset.SETUP[XXX]" from "menu.draw_xoffset.SETUP") */
9022 for (i = 0; i < NUM_SPECIAL_GFX_SETUP_ARGS; i++)
9024 char *value_1 = getHashEntry(setup_file_hash, "menu.draw_xoffset.SETUP");
9025 char *value_2 = getHashEntry(setup_file_hash, "menu.draw_yoffset.SETUP");
9027 if (value_1 != NULL)
9028 menu.draw_xoffset_setup[i] = get_integer_from_string(value_1);
9029 if (value_2 != NULL)
9030 menu.draw_yoffset_setup[i] = get_integer_from_string(value_2);
9033 /* special case: initialize with default values that may be overwritten */
9034 /* (eg, init "menu.enter_screen.SCORES.xyz" from "menu.enter_screen.xyz") */
9035 for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
9037 char *token_1 = "menu.enter_screen.fade_mode";
9038 char *token_2 = "menu.enter_screen.fade_delay";
9039 char *token_3 = "menu.enter_screen.post_delay";
9040 char *token_4 = "menu.leave_screen.fade_mode";
9041 char *token_5 = "menu.leave_screen.fade_delay";
9042 char *token_6 = "menu.leave_screen.post_delay";
9043 char *value_1 = getHashEntry(setup_file_hash, token_1);
9044 char *value_2 = getHashEntry(setup_file_hash, token_2);
9045 char *value_3 = getHashEntry(setup_file_hash, token_3);
9046 char *value_4 = getHashEntry(setup_file_hash, token_4);
9047 char *value_5 = getHashEntry(setup_file_hash, token_5);
9048 char *value_6 = getHashEntry(setup_file_hash, token_6);
9050 if (value_1 != NULL)
9051 menu.enter_screen[i].fade_mode = get_token_parameter_value(token_1,
9053 if (value_2 != NULL)
9054 menu.enter_screen[i].fade_delay = get_token_parameter_value(token_2,
9056 if (value_3 != NULL)
9057 menu.enter_screen[i].post_delay = get_token_parameter_value(token_3,
9059 if (value_4 != NULL)
9060 menu.leave_screen[i].fade_mode = get_token_parameter_value(token_4,
9062 if (value_5 != NULL)
9063 menu.leave_screen[i].fade_delay = get_token_parameter_value(token_5,
9065 if (value_6 != NULL)
9066 menu.leave_screen[i].post_delay = get_token_parameter_value(token_6,
9070 /* special case: initialize with default values that may be overwritten */
9071 /* (e.g., init "titlemessage_1.fade_mode" from "[titlemessage].fade_mode") */
9072 for (i = 0; titlemessage_arrays[i].array != NULL; i++)
9074 struct TitleMessageInfo *array = titlemessage_arrays[i].array;
9075 char *base_token = titlemessage_arrays[i].text;
9077 for (j = 0; titlemessage_tokens[j].type != -1; j++)
9079 char *token = getStringCat2(base_token, titlemessage_tokens[j].text);
9080 char *value = getHashEntry(setup_file_hash, token);
9084 int parameter_value = get_token_parameter_value(token, value);
9086 for (k = 0; k < MAX_NUM_TITLE_MESSAGES; k++)
9090 if (titlemessage_tokens[j].type == TYPE_INTEGER)
9091 *(boolean *)titlemessage_tokens[j].value = (boolean)parameter_value;
9093 *(int *)titlemessage_tokens[j].value = (int)parameter_value;
9103 /* read (and overwrite with) values that may be specified in config file */
9104 for (i = 0; image_config_vars[i].token != NULL; i++)
9106 char *value = getHashEntry(setup_file_hash, image_config_vars[i].token);
9108 /* (ignore definitions set to "[DEFAULT]" which are already initialized) */
9109 if (value != NULL && !strEqual(value, ARG_DEFAULT))
9110 *image_config_vars[i].value =
9111 get_token_parameter_value(image_config_vars[i].token, value);
9114 freeSetupFileHash(setup_file_hash);
9117 void LoadMenuDesignSettings()
9119 char *filename_base = UNDEFINED_FILENAME, *filename_local;
9121 InitMenuDesignSettings_Static();
9122 InitMenuDesignSettings_SpecialPreProcessing();
9125 if (!GFX_OVERRIDE_ARTWORK(ARTWORK_TYPE_GRAPHICS))
9127 if (!SETUP_OVERRIDE_ARTWORK(setup, ARTWORK_TYPE_GRAPHICS))
9130 /* first look for special settings configured in level series config */
9131 filename_base = getCustomArtworkLevelConfigFilename(ARTWORK_TYPE_GRAPHICS);
9133 if (fileExists(filename_base))
9134 LoadMenuDesignSettingsFromFilename(filename_base);
9137 filename_local = getCustomArtworkConfigFilename(ARTWORK_TYPE_GRAPHICS);
9139 if (filename_local != NULL && !strEqual(filename_base, filename_local))
9140 LoadMenuDesignSettingsFromFilename(filename_local);
9142 InitMenuDesignSettings_SpecialPostProcessing();
9145 void LoadUserDefinedEditorElementList(int **elements, int *num_elements)
9147 char *filename = getEditorSetupFilename();
9148 SetupFileList *setup_file_list, *list;
9149 SetupFileHash *element_hash;
9150 int num_unknown_tokens = 0;
9153 if ((setup_file_list = loadSetupFileList(filename)) == NULL)
9156 element_hash = newSetupFileHash();
9158 for (i = 0; i < NUM_FILE_ELEMENTS; i++)
9159 setHashEntry(element_hash, element_info[i].token_name, i_to_a(i));
9161 /* determined size may be larger than needed (due to unknown elements) */
9163 for (list = setup_file_list; list != NULL; list = list->next)
9166 /* add space for up to 3 more elements for padding that may be needed */
9169 /* free memory for old list of elements, if needed */
9170 checked_free(*elements);
9172 /* allocate memory for new list of elements */
9173 *elements = checked_malloc(*num_elements * sizeof(int));
9176 for (list = setup_file_list; list != NULL; list = list->next)
9178 char *value = getHashEntry(element_hash, list->token);
9180 if (value == NULL) /* try to find obsolete token mapping */
9182 char *mapped_token = get_mapped_token(list->token);
9184 if (mapped_token != NULL)
9186 value = getHashEntry(element_hash, mapped_token);
9194 (*elements)[(*num_elements)++] = atoi(value);
9198 if (num_unknown_tokens == 0)
9200 Error(ERR_INFO_LINE, "-");
9201 Error(ERR_INFO, "warning: unknown token(s) found in config file:");
9202 Error(ERR_INFO, "- config file: '%s'", filename);
9204 num_unknown_tokens++;
9207 Error(ERR_INFO, "- token: '%s'", list->token);
9211 if (num_unknown_tokens > 0)
9212 Error(ERR_INFO_LINE, "-");
9214 while (*num_elements % 4) /* pad with empty elements, if needed */
9215 (*elements)[(*num_elements)++] = EL_EMPTY;
9217 freeSetupFileList(setup_file_list);
9218 freeSetupFileHash(element_hash);
9221 for (i = 0; i < *num_elements; i++)
9222 printf("editor: element '%s' [%d]\n",
9223 element_info[(*elements)[i]].token_name, (*elements)[i]);
9227 static struct MusicFileInfo *get_music_file_info_ext(char *basename, int music,
9230 SetupFileHash *setup_file_hash = NULL;
9231 struct MusicFileInfo tmp_music_file_info, *new_music_file_info;
9232 char *filename_music, *filename_prefix, *filename_info;
9238 token_to_value_ptr[] =
9240 { "title_header", &tmp_music_file_info.title_header },
9241 { "artist_header", &tmp_music_file_info.artist_header },
9242 { "album_header", &tmp_music_file_info.album_header },
9243 { "year_header", &tmp_music_file_info.year_header },
9245 { "title", &tmp_music_file_info.title },
9246 { "artist", &tmp_music_file_info.artist },
9247 { "album", &tmp_music_file_info.album },
9248 { "year", &tmp_music_file_info.year },
9254 filename_music = (is_sound ? getCustomSoundFilename(basename) :
9255 getCustomMusicFilename(basename));
9257 if (filename_music == NULL)
9260 /* ---------- try to replace file extension ---------- */
9262 filename_prefix = getStringCopy(filename_music);
9263 if (strrchr(filename_prefix, '.') != NULL)
9264 *strrchr(filename_prefix, '.') = '\0';
9265 filename_info = getStringCat2(filename_prefix, ".txt");
9268 printf("trying to load file '%s'...\n", filename_info);
9271 if (fileExists(filename_info))
9272 setup_file_hash = loadSetupFileHash(filename_info);
9274 free(filename_prefix);
9275 free(filename_info);
9277 if (setup_file_hash == NULL)
9279 /* ---------- try to add file extension ---------- */
9281 filename_prefix = getStringCopy(filename_music);
9282 filename_info = getStringCat2(filename_prefix, ".txt");
9285 printf("trying to load file '%s'...\n", filename_info);
9288 if (fileExists(filename_info))
9289 setup_file_hash = loadSetupFileHash(filename_info);
9291 free(filename_prefix);
9292 free(filename_info);
9295 if (setup_file_hash == NULL)
9298 /* ---------- music file info found ---------- */
9300 clear_mem(&tmp_music_file_info, sizeof(struct MusicFileInfo));
9302 for (i = 0; token_to_value_ptr[i].token != NULL; i++)
9304 char *value = getHashEntry(setup_file_hash, token_to_value_ptr[i].token);
9306 *token_to_value_ptr[i].value_ptr =
9307 getStringCopy(value != NULL && *value != '\0' ? value : UNKNOWN_NAME);
9310 tmp_music_file_info.basename = getStringCopy(basename);
9311 tmp_music_file_info.music = music;
9312 tmp_music_file_info.is_sound = is_sound;
9314 new_music_file_info = checked_malloc(sizeof(struct MusicFileInfo));
9315 *new_music_file_info = tmp_music_file_info;
9317 return new_music_file_info;
9320 static struct MusicFileInfo *get_music_file_info(char *basename, int music)
9322 return get_music_file_info_ext(basename, music, FALSE);
9325 static struct MusicFileInfo *get_sound_file_info(char *basename, int sound)
9327 return get_music_file_info_ext(basename, sound, TRUE);
9330 static boolean music_info_listed_ext(struct MusicFileInfo *list,
9331 char *basename, boolean is_sound)
9333 for (; list != NULL; list = list->next)
9334 if (list->is_sound == is_sound && strEqual(list->basename, basename))
9340 static boolean music_info_listed(struct MusicFileInfo *list, char *basename)
9342 return music_info_listed_ext(list, basename, FALSE);
9345 static boolean sound_info_listed(struct MusicFileInfo *list, char *basename)
9347 return music_info_listed_ext(list, basename, TRUE);
9350 void LoadMusicInfo()
9352 char *music_directory = getCustomMusicDirectory();
9353 int num_music = getMusicListSize();
9354 int num_music_noconf = 0;
9355 int num_sounds = getSoundListSize();
9357 struct dirent *dir_entry;
9358 struct FileInfo *music, *sound;
9359 struct MusicFileInfo *next, **new;
9362 while (music_file_info != NULL)
9364 next = music_file_info->next;
9366 checked_free(music_file_info->basename);
9368 checked_free(music_file_info->title_header);
9369 checked_free(music_file_info->artist_header);
9370 checked_free(music_file_info->album_header);
9371 checked_free(music_file_info->year_header);
9373 checked_free(music_file_info->title);
9374 checked_free(music_file_info->artist);
9375 checked_free(music_file_info->album);
9376 checked_free(music_file_info->year);
9378 free(music_file_info);
9380 music_file_info = next;
9383 new = &music_file_info;
9385 for (i = 0; i < num_music; i++)
9387 music = getMusicListEntry(i);
9389 if (music->filename == NULL)
9392 if (strEqual(music->filename, UNDEFINED_FILENAME))
9395 /* a configured file may be not recognized as music */
9396 if (!FileIsMusic(music->filename))
9400 printf("::: -> '%s' (configured)\n", music->filename);
9403 if (!music_info_listed(music_file_info, music->filename))
9405 *new = get_music_file_info(music->filename, i);
9407 new = &(*new)->next;
9411 if ((dir = opendir(music_directory)) == NULL)
9413 Error(ERR_WARN, "cannot read music directory '%s'", music_directory);
9417 while ((dir_entry = readdir(dir)) != NULL) /* loop until last dir entry */
9419 char *basename = dir_entry->d_name;
9420 boolean music_already_used = FALSE;
9423 /* skip all music files that are configured in music config file */
9424 for (i = 0; i < num_music; i++)
9426 music = getMusicListEntry(i);
9428 if (music->filename == NULL)
9431 if (strEqual(basename, music->filename))
9433 music_already_used = TRUE;
9438 if (music_already_used)
9441 if (!FileIsMusic(basename))
9445 printf("::: -> '%s' (found in directory)\n", basename);
9448 if (!music_info_listed(music_file_info, basename))
9450 *new = get_music_file_info(basename, MAP_NOCONF_MUSIC(num_music_noconf));
9452 new = &(*new)->next;
9460 for (i = 0; i < num_sounds; i++)
9462 sound = getSoundListEntry(i);
9464 if (sound->filename == NULL)
9467 if (strEqual(sound->filename, UNDEFINED_FILENAME))
9470 /* a configured file may be not recognized as sound */
9471 if (!FileIsSound(sound->filename))
9475 printf("::: -> '%s' (configured)\n", sound->filename);
9478 if (!sound_info_listed(music_file_info, sound->filename))
9480 *new = get_sound_file_info(sound->filename, i);
9482 new = &(*new)->next;
9487 for (next = music_file_info; next != NULL; next = next->next)
9488 printf("::: title == '%s'\n", next->title);
9492 void add_helpanim_entry(int element, int action, int direction, int delay,
9493 int *num_list_entries)
9495 struct HelpAnimInfo *new_list_entry;
9496 (*num_list_entries)++;
9499 checked_realloc(helpanim_info,
9500 *num_list_entries * sizeof(struct HelpAnimInfo));
9501 new_list_entry = &helpanim_info[*num_list_entries - 1];
9503 new_list_entry->element = element;
9504 new_list_entry->action = action;
9505 new_list_entry->direction = direction;
9506 new_list_entry->delay = delay;
9509 void print_unknown_token(char *filename, char *token, int token_nr)
9513 Error(ERR_INFO_LINE, "-");
9514 Error(ERR_INFO, "warning: unknown token(s) found in config file:");
9515 Error(ERR_INFO, "- config file: '%s'", filename);
9518 Error(ERR_INFO, "- token: '%s'", token);
9521 void print_unknown_token_end(int token_nr)
9524 Error(ERR_INFO_LINE, "-");
9527 void LoadHelpAnimInfo()
9529 char *filename = getHelpAnimFilename();
9530 SetupFileList *setup_file_list = NULL, *list;
9531 SetupFileHash *element_hash, *action_hash, *direction_hash;
9532 int num_list_entries = 0;
9533 int num_unknown_tokens = 0;
9536 if (fileExists(filename))
9537 setup_file_list = loadSetupFileList(filename);
9539 if (setup_file_list == NULL)
9541 /* use reliable default values from static configuration */
9542 SetupFileList *insert_ptr;
9544 insert_ptr = setup_file_list =
9545 newSetupFileList(helpanim_config[0].token,
9546 helpanim_config[0].value);
9548 for (i = 1; helpanim_config[i].token; i++)
9549 insert_ptr = addListEntry(insert_ptr,
9550 helpanim_config[i].token,
9551 helpanim_config[i].value);
9554 element_hash = newSetupFileHash();
9555 action_hash = newSetupFileHash();
9556 direction_hash = newSetupFileHash();
9558 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
9559 setHashEntry(element_hash, element_info[i].token_name, i_to_a(i));
9561 for (i = 0; i < NUM_ACTIONS; i++)
9562 setHashEntry(action_hash, element_action_info[i].suffix,
9563 i_to_a(element_action_info[i].value));
9565 /* do not store direction index (bit) here, but direction value! */
9566 for (i = 0; i < NUM_DIRECTIONS_FULL; i++)
9567 setHashEntry(direction_hash, element_direction_info[i].suffix,
9568 i_to_a(1 << element_direction_info[i].value));
9570 for (list = setup_file_list; list != NULL; list = list->next)
9572 char *element_token, *action_token, *direction_token;
9573 char *element_value, *action_value, *direction_value;
9574 int delay = atoi(list->value);
9576 if (strEqual(list->token, "end"))
9578 add_helpanim_entry(HELPANIM_LIST_NEXT, -1, -1, -1, &num_list_entries);
9583 /* first try to break element into element/action/direction parts;
9584 if this does not work, also accept combined "element[.act][.dir]"
9585 elements (like "dynamite.active"), which are unique elements */
9587 if (strchr(list->token, '.') == NULL) /* token contains no '.' */
9589 element_value = getHashEntry(element_hash, list->token);
9590 if (element_value != NULL) /* element found */
9591 add_helpanim_entry(atoi(element_value), -1, -1, delay,
9595 /* no further suffixes found -- this is not an element */
9596 print_unknown_token(filename, list->token, num_unknown_tokens++);
9602 /* token has format "<prefix>.<something>" */
9604 action_token = strchr(list->token, '.'); /* suffix may be action ... */
9605 direction_token = action_token; /* ... or direction */
9607 element_token = getStringCopy(list->token);
9608 *strchr(element_token, '.') = '\0';
9610 element_value = getHashEntry(element_hash, element_token);
9612 if (element_value == NULL) /* this is no element */
9614 element_value = getHashEntry(element_hash, list->token);
9615 if (element_value != NULL) /* combined element found */
9616 add_helpanim_entry(atoi(element_value), -1, -1, delay,
9619 print_unknown_token(filename, list->token, num_unknown_tokens++);
9621 free(element_token);
9626 action_value = getHashEntry(action_hash, action_token);
9628 if (action_value != NULL) /* action found */
9630 add_helpanim_entry(atoi(element_value), atoi(action_value), -1, delay,
9633 free(element_token);
9638 direction_value = getHashEntry(direction_hash, direction_token);
9640 if (direction_value != NULL) /* direction found */
9642 add_helpanim_entry(atoi(element_value), -1, atoi(direction_value), delay,
9645 free(element_token);
9650 if (strchr(action_token + 1, '.') == NULL)
9652 /* no further suffixes found -- this is not an action nor direction */
9654 element_value = getHashEntry(element_hash, list->token);
9655 if (element_value != NULL) /* combined element found */
9656 add_helpanim_entry(atoi(element_value), -1, -1, delay,
9659 print_unknown_token(filename, list->token, num_unknown_tokens++);
9661 free(element_token);
9666 /* token has format "<prefix>.<suffix>.<something>" */
9668 direction_token = strchr(action_token + 1, '.');
9670 action_token = getStringCopy(action_token);
9671 *strchr(action_token + 1, '.') = '\0';
9673 action_value = getHashEntry(action_hash, action_token);
9675 if (action_value == NULL) /* this is no action */
9677 element_value = getHashEntry(element_hash, list->token);
9678 if (element_value != NULL) /* combined element found */
9679 add_helpanim_entry(atoi(element_value), -1, -1, delay,
9682 print_unknown_token(filename, list->token, num_unknown_tokens++);
9684 free(element_token);
9690 direction_value = getHashEntry(direction_hash, direction_token);
9692 if (direction_value != NULL) /* direction found */
9694 add_helpanim_entry(atoi(element_value), atoi(action_value),
9695 atoi(direction_value), delay, &num_list_entries);
9697 free(element_token);
9703 /* this is no direction */
9705 element_value = getHashEntry(element_hash, list->token);
9706 if (element_value != NULL) /* combined element found */
9707 add_helpanim_entry(atoi(element_value), -1, -1, delay,
9710 print_unknown_token(filename, list->token, num_unknown_tokens++);
9712 free(element_token);
9716 print_unknown_token_end(num_unknown_tokens);
9718 add_helpanim_entry(HELPANIM_LIST_NEXT, -1, -1, -1, &num_list_entries);
9719 add_helpanim_entry(HELPANIM_LIST_END, -1, -1, -1, &num_list_entries);
9721 freeSetupFileList(setup_file_list);
9722 freeSetupFileHash(element_hash);
9723 freeSetupFileHash(action_hash);
9724 freeSetupFileHash(direction_hash);
9727 for (i = 0; i < num_list_entries; i++)
9728 printf("::: '%s': %d, %d, %d => %d\n",
9729 EL_NAME(helpanim_info[i].element),
9730 helpanim_info[i].element,
9731 helpanim_info[i].action,
9732 helpanim_info[i].direction,
9733 helpanim_info[i].delay);
9737 void LoadHelpTextInfo()
9739 char *filename = getHelpTextFilename();
9742 if (helptext_info != NULL)
9744 freeSetupFileHash(helptext_info);
9745 helptext_info = NULL;
9748 if (fileExists(filename))
9749 helptext_info = loadSetupFileHash(filename);
9751 if (helptext_info == NULL)
9753 /* use reliable default values from static configuration */
9754 helptext_info = newSetupFileHash();
9756 for (i = 0; helptext_config[i].token; i++)
9757 setHashEntry(helptext_info,
9758 helptext_config[i].token,
9759 helptext_config[i].value);
9763 BEGIN_HASH_ITERATION(helptext_info, itr)
9765 printf("::: '%s' => '%s'\n",
9766 HASH_ITERATION_TOKEN(itr), HASH_ITERATION_VALUE(itr));
9768 END_HASH_ITERATION(hash, itr)
9773 /* ------------------------------------------------------------------------- */
9774 /* convert levels */
9775 /* ------------------------------------------------------------------------- */
9777 #define MAX_NUM_CONVERT_LEVELS 1000
9779 void ConvertLevels()
9781 static LevelDirTree *convert_leveldir = NULL;
9782 static int convert_level_nr = -1;
9783 static int num_levels_handled = 0;
9784 static int num_levels_converted = 0;
9785 static boolean levels_failed[MAX_NUM_CONVERT_LEVELS];
9788 convert_leveldir = getTreeInfoFromIdentifier(leveldir_first,
9789 global.convert_leveldir);
9791 if (convert_leveldir == NULL)
9792 Error(ERR_EXIT, "no such level identifier: '%s'",
9793 global.convert_leveldir);
9795 leveldir_current = convert_leveldir;
9797 if (global.convert_level_nr != -1)
9799 convert_leveldir->first_level = global.convert_level_nr;
9800 convert_leveldir->last_level = global.convert_level_nr;
9803 convert_level_nr = convert_leveldir->first_level;
9805 printf_line("=", 79);
9806 printf("Converting levels\n");
9807 printf_line("-", 79);
9808 printf("Level series identifier: '%s'\n", convert_leveldir->identifier);
9809 printf("Level series name: '%s'\n", convert_leveldir->name);
9810 printf("Level series author: '%s'\n", convert_leveldir->author);
9811 printf("Number of levels: %d\n", convert_leveldir->levels);
9812 printf_line("=", 79);
9815 for (i = 0; i < MAX_NUM_CONVERT_LEVELS; i++)
9816 levels_failed[i] = FALSE;
9818 while (convert_level_nr <= convert_leveldir->last_level)
9820 char *level_filename;
9823 level_nr = convert_level_nr++;
9825 printf("Level %03d: ", level_nr);
9827 LoadLevel(level_nr);
9828 if (level.no_valid_file)
9830 printf("(no level)\n");
9834 printf("converting level ... ");
9836 level_filename = getDefaultLevelFilename(level_nr);
9837 new_level = !fileExists(level_filename);
9841 SaveLevel(level_nr);
9843 num_levels_converted++;
9845 printf("converted.\n");
9849 if (level_nr >= 0 && level_nr < MAX_NUM_CONVERT_LEVELS)
9850 levels_failed[level_nr] = TRUE;
9852 printf("NOT CONVERTED -- LEVEL ALREADY EXISTS.\n");
9855 num_levels_handled++;
9859 printf_line("=", 79);
9860 printf("Number of levels handled: %d\n", num_levels_handled);
9861 printf("Number of levels converted: %d (%d%%)\n", num_levels_converted,
9862 (num_levels_handled ?
9863 num_levels_converted * 100 / num_levels_handled : 0));
9864 printf_line("-", 79);
9865 printf("Summary (for automatic parsing by scripts):\n");
9866 printf("LEVELDIR '%s', CONVERTED %d/%d (%d%%)",
9867 convert_leveldir->identifier, num_levels_converted,
9869 (num_levels_handled ?
9870 num_levels_converted * 100 / num_levels_handled : 0));
9872 if (num_levels_handled != num_levels_converted)
9874 printf(", FAILED:");
9875 for (i = 0; i < MAX_NUM_CONVERT_LEVELS; i++)
9876 if (levels_failed[i])
9881 printf_line("=", 79);
9887 /* ------------------------------------------------------------------------- */
9888 /* create and save images for use in level sketches (raw BMP format) */
9889 /* ------------------------------------------------------------------------- */
9891 void CreateLevelSketchImages()
9893 #if defined(TARGET_SDL)
9898 InitElementPropertiesGfxElement();
9900 bitmap1 = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
9901 bitmap2 = CreateBitmap(MINI_TILEX, MINI_TILEY, DEFAULT_DEPTH);
9903 for (i = 0; i < NUM_FILE_ELEMENTS; i++)
9907 int element = getMappedElement(i);
9908 int graphic = el2edimg(element);
9914 sprintf(basename1, "%03d.bmp", i);
9915 sprintf(basename2, "%03ds.bmp", i);
9917 filename1 = getPath2(global.create_images_dir, basename1);
9918 filename2 = getPath2(global.create_images_dir, basename2);
9920 getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
9921 BlitBitmap(src_bitmap, bitmap1, src_x, src_y, TILEX, TILEY, 0, 0);
9923 if (SDL_SaveBMP(bitmap1->surface, filename1) != 0)
9924 Error(ERR_EXIT, "cannot save level sketch image file '%s'", filename1);
9926 getMiniGraphicSource(graphic, &src_bitmap, &src_x, &src_y);
9927 BlitBitmap(src_bitmap, bitmap2, src_x, src_y, MINI_TILEX, MINI_TILEY, 0, 0);
9929 if (SDL_SaveBMP(bitmap2->surface, filename2) != 0)
9930 Error(ERR_EXIT, "cannot save level sketch image file '%s'", filename2);
9936 printf("%03d `%03d%c", i, i, (i % 10 < 9 ? ' ' : '\n'));
9939 FreeBitmap(bitmap1);
9940 FreeBitmap(bitmap2);
9945 Error(ERR_INFO, "%d normal and small images created", NUM_FILE_ELEMENTS);
9952 /* ------------------------------------------------------------------------- */
9953 /* create and save images for custom and group elements (raw BMP format) */
9954 /* ------------------------------------------------------------------------- */
9956 void CreateCustomElementImages()
9958 #if defined(TARGET_SDL)
9959 char *filename = "graphics.classic/RocksCE.bmp";
9962 int dummy_graphic = IMG_CUSTOM_99;
9964 int yoffset_ge = (TILEY * NUM_CUSTOM_ELEMENTS / 16);
9968 bitmap = CreateBitmap(TILEX * 16 * 2,
9969 TILEY * (NUM_CUSTOM_ELEMENTS + NUM_GROUP_ELEMENTS) / 16,
9972 getGraphicSource(dummy_graphic, 0, &src_bitmap, &src_x, &src_y);
9974 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
9981 BlitBitmap(src_bitmap, bitmap, 0, 0, TILEX, TILEY,
9982 TILEX * x, TILEY * y + yoffset_ce);
9984 BlitBitmap(src_bitmap, bitmap, 0, TILEY, TILEX, TILEY,
9985 TILEX * x + TILEX * 16, TILEY * y + yoffset_ce);
9987 for (j = 2; j >= 0; j--)
9991 BlitBitmap(src_bitmap, bitmap, TILEX + c * 7, 0, 6, 10,
9992 TILEX * x + 6 + j * 7,
9993 TILEY * y + 11 + yoffset_ce);
9995 BlitBitmap(src_bitmap, bitmap, TILEX + c * 8, TILEY, 6, 10,
9996 TILEX * 16 + TILEX * x + 6 + j * 8,
9997 TILEY * y + 10 + yoffset_ce);
10003 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
10010 BlitBitmap(src_bitmap, bitmap, 0, 0, TILEX, TILEY,
10011 TILEX * x, TILEY * y + yoffset_ge);
10013 BlitBitmap(src_bitmap, bitmap, 0, TILEY, TILEX, TILEY,
10014 TILEX * x + TILEX * 16, TILEY * y + yoffset_ge);
10016 for (j = 1; j >= 0; j--)
10020 BlitBitmap(src_bitmap, bitmap, TILEX + c * 10, 11, 10, 10,
10021 TILEX * x + 6 + j * 10,
10022 TILEY * y + 11 + yoffset_ge);
10024 BlitBitmap(src_bitmap, bitmap, TILEX + c * 8, TILEY + 12, 6, 10,
10025 TILEX * 16 + TILEX * x + 10 + j * 8,
10026 TILEY * y + 10 + yoffset_ge);
10032 if (SDL_SaveBMP(bitmap->surface, filename) != 0)
10033 Error(ERR_EXIT, "cannot save CE graphics file '%s'", filename);
10035 FreeBitmap(bitmap);
10037 CloseAllAndExit(0);
10042 void CreateLevelSketchImages_TEST()
10044 void CreateCustomElementImages()