#include "tools.h"
#include "tape.h"
#include "config.h"
+#include "api.h"
#define ENABLE_UNUSED_CODE 0 // currently unused functions
#define ENABLE_HISTORIC_CHUNKS 0 // only for historic reference
// (element number only)
#define LEVEL_CHUNK_GRPX_UNCHANGED 2
+#define LEVEL_CHUNK_EMPX_UNCHANGED 2
#define LEVEL_CHUNK_NOTE_UNCHANGED 2
// (nothing at all if unchanged)
#define TAPE_CHUNK_VERS_SIZE 8 // size of file version chunk
#define TAPE_CHUNK_HEAD_SIZE 20 // size of tape file header
-#define TAPE_CHUNK_HEAD_UNUSED 1 // unused tape header bytes
+#define TAPE_CHUNK_SCRN_SIZE 2 // size of screen size chunk
+
+#define SCORE_CHUNK_VERS_SIZE 8 // size of file version chunk
#define LEVEL_CHUNK_CNT3_SIZE(x) (LEVEL_CHUNK_CNT3_HEADER + (x))
#define LEVEL_CHUNK_CUS3_SIZE(x) (2 + (x) * LEVEL_CPART_CUS3_SIZE)
// file identifier strings
#define LEVEL_COOKIE_TMPL "ROCKSNDIAMONDS_LEVEL_FILE_VERSION_x.x"
#define TAPE_COOKIE_TMPL "ROCKSNDIAMONDS_TAPE_FILE_VERSION_x.x"
-#define SCORE_COOKIE "ROCKSNDIAMONDS_SCORE_FILE_VERSION_1.2"
+#define SCORE_COOKIE_TMPL "ROCKSNDIAMONDS_SCORE_FILE_VERSION_x.x"
// values for deciding when (not) to save configuration data
#define SAVE_CONF_NEVER 0
CONF_CONTENT_NUM_BYTES : 1)
#define CONF_ELEMENT_BYTE_POS(i) ((i) * CONF_ELEMENT_NUM_BYTES)
-#define CONF_ELEMENTS_ELEMENT(b,i) ((b[CONF_ELEMENT_BYTE_POS(i)] << 8) | \
+#define CONF_ELEMENTS_ELEMENT(b, i) ((b[CONF_ELEMENT_BYTE_POS(i)] << 8) | \
(b[CONF_ELEMENT_BYTE_POS(i) + 1]))
#define CONF_CONTENT_ELEMENT_POS(c,x,y) ((c) * CONF_CONTENT_NUM_ELEMENTS + \
TYPE_INTEGER, CONF_VALUE_8_BIT(1),
&li.game_engine_type, GAME_ENGINE_TYPE_RND
},
-
{
-1, SAVE_CONF_ALWAYS,
TYPE_INTEGER, CONF_VALUE_16_BIT(1),
TYPE_INTEGER, CONF_VALUE_16_BIT(2),
&li.fieldy, STD_LEV_FIELDY
},
-
{
-1, SAVE_CONF_ALWAYS,
TYPE_INTEGER, CONF_VALUE_16_BIT(3),
&li.time, 100
},
-
{
-1, SAVE_CONF_ALWAYS,
TYPE_INTEGER, CONF_VALUE_16_BIT(4),
&li.gems_needed, 0
},
-
{
-1, -1,
TYPE_INTEGER, CONF_VALUE_32_BIT(2),
&li.random_seed, 0
},
-
{
-1, -1,
TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
&li.use_step_counter, FALSE
},
-
{
-1, -1,
TYPE_BITFIELD, CONF_VALUE_8_BIT(4),
&li.wind_direction_initial, MV_NONE
},
-
{
-1, -1,
TYPE_BOOLEAN, CONF_VALUE_8_BIT(5),
&li.em_slippery_gems, FALSE
},
-
{
-1, -1,
TYPE_BOOLEAN, CONF_VALUE_8_BIT(6),
&li.use_custom_template, FALSE
},
-
{
-1, -1,
TYPE_BITFIELD, CONF_VALUE_32_BIT(1),
&li.can_move_into_acid_bits, ~0 // default: everything can
},
-
{
-1, -1,
TYPE_BITFIELD, CONF_VALUE_8_BIT(7),
&li.dont_collide_with_bits, ~0 // default: always deadly
},
-
{
-1, -1,
TYPE_BOOLEAN, CONF_VALUE_8_BIT(8),
&li.em_explodes_by_fire, FALSE
},
-
{
-1, -1,
TYPE_INTEGER, CONF_VALUE_16_BIT(5),
&li.score[SC_TIME_BONUS], 1
},
-
{
-1, -1,
TYPE_BOOLEAN, CONF_VALUE_8_BIT(9),
&li.auto_exit_sokoban, FALSE
},
-
{
-1, -1,
TYPE_BOOLEAN, CONF_VALUE_8_BIT(10),
&li.auto_count_gems, FALSE
},
-
{
-1, -1,
TYPE_BOOLEAN, CONF_VALUE_8_BIT(11),
&li.solved_by_one_player, FALSE
},
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(12),
+ &li.time_score_base, 1
+ },
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(13),
+ &li.rate_time_over_score, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(14),
+ &li.bd_intermission, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(15),
+ &li.bd_scheduling_type, GD_SCHEDULING_MILLISECONDS
+ },
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(16),
+ &li.bd_pal_timing, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(6),
+ &li.bd_cycle_delay_ms, 200
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(17),
+ &li.bd_cycle_delay_c64, 0
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(18),
+ &li.bd_hatching_delay_cycles, 21
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(19),
+ &li.bd_hatching_delay_seconds, 2
+ },
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(20),
+ &li.bd_line_shifting_borders, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(21),
+ &li.bd_scan_first_and_last_row, TRUE
+ },
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(22),
+ &li.bd_short_explosions, TRUE
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(23),
+ &li.bd_cave_random_seed_c64, 0
+ },
{
-1, -1,
TYPE_BOOLEAN, CONF_VALUE_8_BIT(15),
&li.lazy_relocation, FALSE
},
+ {
+ EL_PLAYER_1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(16),
+ &li.finish_dig_collect, TRUE
+ },
+ {
+ EL_PLAYER_1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(17),
+ &li.keep_walkable_ce, FALSE
+ },
// (these values are different for each player)
{
&li.initial_inventory_size[3], 1, MAX_INITIAL_INVENTORY_SIZE
},
+ // (these values are only valid for BD style levels)
+ // (some values for BD style amoeba following below)
{
- EL_EMERALD, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.score[SC_EMERALD], 10
+ EL_BD_PLAYER, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &li.bd_diagonal_movements, FALSE
},
-
{
- EL_DIAMOND, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.score[SC_DIAMOND], 10
+ EL_BD_PLAYER, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
+ &li.bd_topmost_player_active, TRUE
},
-
{
- EL_BUG, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.score[SC_BUG], 10
+ EL_BD_PLAYER, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(3),
+ &li.bd_pushing_prob, 25
},
-
{
- EL_SPACESHIP, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.score[SC_SPACESHIP], 10
+ EL_BD_PLAYER, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(4),
+ &li.bd_pushing_prob_with_sweet, 100
},
-
{
- EL_PACMAN, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.score[SC_PACMAN], 10
+ EL_BD_PLAYER, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(5),
+ &li.bd_push_mega_rock_with_sweet, FALSE
},
-
{
- EL_NUT, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.score[SC_NUT], 10
+ EL_BD_PLAYER, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(6),
+ &li.bd_snap_element, EL_EMPTY
},
{
- EL_DYNAMITE, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.score[SC_DYNAMITE], 10
+ EL_BD_SAND, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_sand_looks_like, EL_BD_SAND
},
{
- EL_KEY_1, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.score[SC_KEY], 10
+ EL_BD_ROCK, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_rock_turns_to_on_falling, EL_BD_ROCK_FALLING
+ },
+ {
+ EL_BD_ROCK, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(2),
+ &li.bd_rock_turns_to_on_impact, EL_BD_ROCK
},
{
- EL_PEARL, -1,
+ EL_BD_DIAMOND, -1,
TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.score[SC_PEARL], 10
+ &li.score[SC_DIAMOND_EXTRA], 20
+ },
+ {
+ EL_BD_DIAMOND, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(2),
+ &li.bd_diamond_turns_to_on_falling, EL_BD_DIAMOND_FALLING
+ },
+ {
+ EL_BD_DIAMOND, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(3),
+ &li.bd_diamond_turns_to_on_impact, EL_BD_DIAMOND
},
{
- EL_CRYSTAL, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.score[SC_CRYSTAL], 10
+ EL_BD_FIREFLY, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_firefly_explodes_to, EL_BD_EXPLODING_1
},
{
- EL_BD_AMOEBA, -1,
+ EL_BD_FIREFLY_2, -1,
TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
- &li.amoeba_content, EL_DIAMOND
+ &li.bd_firefly_2_explodes_to, EL_BD_EXPLODING_1
},
+
{
- EL_BD_AMOEBA, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(2),
- &li.amoeba_speed, 10
+ EL_BD_BUTTERFLY, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_butterfly_explodes_to, EL_BD_DIAMOND_GROWING_1
},
+
{
- EL_BD_AMOEBA, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
- &li.grow_into_diggable, TRUE
+ EL_BD_BUTTERFLY_2, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_butterfly_2_explodes_to, EL_BD_DIAMOND_GROWING_1
},
{
- EL_YAMYAM, -1,
- TYPE_CONTENT_LIST, CONF_VALUE_BYTES(1),
- &li.yamyam_content, EL_ROCK, NULL,
- &li.num_yamyam_contents, 4, MAX_ELEMENT_CONTENTS
+ EL_BD_STONEFLY, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_stonefly_explodes_to, EL_BD_ROCK_GROWING_1
},
+
{
- EL_YAMYAM, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.score[SC_YAMYAM], 10
+ EL_BD_DRAGONFLY, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_dragonfly_explodes_to, EL_BD_EXPLODING_1
},
{
- EL_ROBOT, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.score[SC_ROBOT], 10
+ EL_BD_DIAMOND_GROWING_5, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_diamond_birth_turns_to, EL_BD_DIAMOND
},
+
{
- EL_ROBOT, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(2),
- &li.slurp_score, 10
+ EL_BD_BOMB_EXPLODING_4, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_bomb_explosion_turns_to, EL_BD_WALL
},
{
- EL_ROBOT_WHEEL, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.time_wheel, 10
+ EL_BD_NITRO_PACK_EXPLODING_4, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_nitro_explosion_turns_to, EL_EMPTY
},
{
- EL_MAGIC_WALL, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.time_magic_wall, 10
+ EL_BD_EXPLODING_5, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_explosion_turns_to, EL_EMPTY
},
{
- EL_GAME_OF_LIFE, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(1),
- &li.game_of_life[0], 2
+ EL_BD_MAGIC_WALL, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &li.bd_magic_wall_wait_hatching, FALSE
},
{
- EL_GAME_OF_LIFE, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(2),
- &li.game_of_life[1], 3
+ EL_BD_MAGIC_WALL, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
+ &li.bd_magic_wall_stops_amoeba, TRUE
},
{
- EL_GAME_OF_LIFE, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(3),
- &li.game_of_life[2], 3
+ EL_BD_MAGIC_WALL, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_magic_wall_diamond_to, EL_BD_ROCK_FALLING
},
{
- EL_GAME_OF_LIFE, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(4),
- &li.game_of_life[3], 3
+ EL_BD_MAGIC_WALL, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(2),
+ &li.bd_magic_wall_rock_to, EL_BD_DIAMOND_FALLING
},
{
- EL_GAME_OF_LIFE, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(5),
- &li.use_life_bugs, FALSE
+ EL_BD_MAGIC_WALL, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(3),
+ &li.bd_magic_wall_mega_rock_to, EL_BD_NITRO_PACK_FALLING
},
-
{
- EL_BIOMAZE, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(1),
- &li.biomaze[0], 2
+ EL_BD_MAGIC_WALL, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(4),
+ &li.bd_magic_wall_nut_to, EL_BD_NUT_FALLING
},
{
- EL_BIOMAZE, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(2),
- &li.biomaze[1], 3
+ EL_BD_MAGIC_WALL, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(5),
+ &li.bd_magic_wall_nitro_pack_to, EL_BD_MEGA_ROCK_FALLING
},
{
- EL_BIOMAZE, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(3),
- &li.biomaze[2], 3
+ EL_BD_MAGIC_WALL, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(6),
+ &li.bd_magic_wall_flying_diamond_to, EL_BD_FLYING_ROCK_FLYING
},
{
- EL_BIOMAZE, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(4),
- &li.biomaze[3], 3
+ EL_BD_MAGIC_WALL, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(7),
+ &li.bd_magic_wall_flying_rock_to, EL_BD_FLYING_DIAMOND_FLYING
},
{
- EL_TIMEGATE_SWITCH, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.time_timegate, 10
+ EL_BD_CLOCK, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(1),
+ &li.bd_clock_extra_time, 30
},
{
- EL_LIGHT_SWITCH_ACTIVE, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.time_light, 10
+ EL_BD_VOODOO_DOLL, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &li.bd_voodoo_collects_diamonds, FALSE
},
-
{
- EL_SHIELD_NORMAL, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.shield_normal_time, 10
+ EL_BD_VOODOO_DOLL, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
+ &li.bd_voodoo_hurt_kills_player, FALSE
},
{
- EL_SHIELD_NORMAL, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(2),
- &li.score[SC_SHIELD], 10
+ EL_BD_VOODOO_DOLL, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(3),
+ &li.bd_voodoo_dies_by_rock, FALSE
},
-
{
- EL_SHIELD_DEADLY, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.shield_deadly_time, 10
+ EL_BD_VOODOO_DOLL, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(4),
+ &li.bd_voodoo_vanish_by_explosion, TRUE
},
{
- EL_SHIELD_DEADLY, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(2),
- &li.score[SC_SHIELD], 10
+ EL_BD_VOODOO_DOLL, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(5),
+ &li.bd_voodoo_penalty_time, 30
},
{
- EL_EXTRA_TIME, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.extra_time, 10
+ EL_BD_SLIME, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &li.bd_slime_is_predictable, TRUE
},
{
- EL_EXTRA_TIME, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(2),
- &li.extra_time_score, 10
+ EL_BD_SLIME, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(2),
+ &li.bd_slime_permeability_rate, 100
},
-
{
- EL_TIME_ORB_FULL, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.time_orb_time, 10
+ EL_BD_SLIME, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(3),
+ &li.bd_slime_permeability_bits_c64, 0
},
{
- EL_TIME_ORB_FULL, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
- &li.use_time_orb_bug, FALSE
+ EL_BD_SLIME, -1,
+ TYPE_INTEGER, CONF_VALUE_32_BIT(1),
+ &li.bd_slime_random_seed_c64, -1
},
-
{
- EL_SPRING, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
- &li.use_spring_bug, FALSE
+ EL_BD_SLIME, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_slime_eats_element_1, EL_BD_DIAMOND
},
-
{
- EL_EMC_ANDROID, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.android_move_time, 10
+ EL_BD_SLIME, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(2),
+ &li.bd_slime_converts_to_element_1, EL_BD_DIAMOND_FALLING
},
{
- EL_EMC_ANDROID, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(2),
- &li.android_clone_time, 10
+ EL_BD_SLIME, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(3),
+ &li.bd_slime_eats_element_2, EL_BD_ROCK
},
{
- EL_EMC_ANDROID, SAVE_CONF_NEVER,
- TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(1),
- &li.android_clone_element[0], EL_EMPTY, NULL,
- &li.num_android_clone_elements, 1, MAX_ANDROID_ELEMENTS_OLD
+ EL_BD_SLIME, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(4),
+ &li.bd_slime_converts_to_element_2, EL_BD_ROCK_FALLING
},
{
- EL_EMC_ANDROID, -1,
- TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(2),
- &li.android_clone_element[0], EL_EMPTY, NULL,
- &li.num_android_clone_elements, 1, MAX_ANDROID_ELEMENTS
+ EL_BD_SLIME, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(5),
+ &li.bd_slime_eats_element_3, EL_BD_NUT
},
-
{
- EL_EMC_LENSES, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.lenses_score, 10
+ EL_BD_SLIME, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(6),
+ &li.bd_slime_converts_to_element_3, EL_BD_NUT_FALLING
},
+
{
- EL_EMC_LENSES, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(2),
- &li.lenses_time, 10
+ EL_BD_ACID, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_acid_eats_element, EL_BD_SAND
+ },
+ {
+ EL_BD_ACID, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(1),
+ &li.bd_acid_spread_rate, 3
+ },
+ {
+ EL_BD_ACID, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(2),
+ &li.bd_acid_turns_to_element, EL_BD_EXPLODING_3
},
{
- EL_EMC_MAGNIFIER, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.magnify_score, 10
+ EL_BD_BITER, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(1),
+ &li.bd_biter_move_delay, 0
},
{
- EL_EMC_MAGNIFIER, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(2),
- &li.magnify_time, 10
+ EL_BD_BITER, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_biter_eats_element, EL_BD_DIAMOND
},
{
- EL_EMC_MAGIC_BALL, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.ball_time, 10
+ EL_BD_BLADDER, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_bladder_converts_by_element, EL_BD_VOODOO_DOLL
},
+
{
- EL_EMC_MAGIC_BALL, -1,
+ EL_BD_EXPANDABLE_WALL_ANY, -1,
TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
- &li.ball_random, FALSE
+ &li.bd_change_expanding_wall, FALSE
},
{
- EL_EMC_MAGIC_BALL, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
- &li.ball_active_initial, FALSE
+ EL_BD_EXPANDABLE_WALL_ANY, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_expanding_wall_looks_like, EL_BD_WALL
},
+
{
- EL_EMC_MAGIC_BALL, -1,
- TYPE_CONTENT_LIST, CONF_VALUE_BYTES(1),
- &li.ball_content, EL_EMPTY, NULL,
- &li.num_ball_contents, 4, MAX_ELEMENT_CONTENTS
+ EL_BD_REPLICATOR, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &li.bd_replicators_active, TRUE
+ },
+ {
+ EL_BD_REPLICATOR, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(2),
+ &li.bd_replicator_create_delay, 4
},
{
- EL_SOKOBAN_FIELD_EMPTY, -1,
+ EL_BD_CONVEYOR_LEFT, -1,
TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
- &li.sb_fields_needed, TRUE
+ &li.bd_conveyor_belts_active, TRUE
+ },
+ {
+ EL_BD_CONVEYOR_LEFT, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
+ &li.bd_conveyor_belts_changed, FALSE
},
{
- EL_SOKOBAN_OBJECT, -1,
+ EL_BD_WATER, -1,
TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
- &li.sb_objects_needed, TRUE
+ &li.bd_water_cannot_flow_down, FALSE
},
{
- EL_MM_MCDUFFIN, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
- &li.mm_laser_red, FALSE
+ EL_BD_NUT, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.bd_nut_content, EL_BD_NUT_BREAKING_1
},
+
{
- EL_MM_MCDUFFIN, -1,
+ EL_BD_PNEUMATIC_HAMMER, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(1),
+ &li.bd_hammer_walls_break_delay, 5
+ },
+ {
+ EL_BD_PNEUMATIC_HAMMER, -1,
TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
- &li.mm_laser_green, FALSE
+ &li.bd_hammer_walls_reappear, FALSE
},
{
- EL_MM_MCDUFFIN, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(3),
- &li.mm_laser_blue, TRUE
+ EL_BD_PNEUMATIC_HAMMER, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(3),
+ &li.bd_hammer_walls_reappear_delay, 100
},
{
- EL_DF_LASER, -1,
+ EL_BD_SKELETON, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(1),
+ &li.bd_num_skeletons_needed_for_pot, 5
+ },
+ {
+ EL_BD_SKELETON, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(2),
+ &li.bd_skeleton_worth_num_diamonds, 0
+ },
+
+ {
+ EL_BD_CREATURE_SWITCH, -1,
TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
- &li.df_laser_red, TRUE
+ &li.bd_creatures_start_backwards, FALSE
},
{
- EL_DF_LASER, -1,
+ EL_BD_CREATURE_SWITCH, -1,
TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
- &li.df_laser_green, TRUE
+ &li.bd_creatures_turn_on_hatching, FALSE
},
{
- EL_DF_LASER, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(3),
- &li.df_laser_blue, FALSE
+ EL_BD_CREATURE_SWITCH, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.bd_creatures_auto_turn_delay, 0
},
{
- EL_MM_FUSE_ACTIVE, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.mm_time_fuse, 25
+ EL_BD_GRAVITY_SWITCH, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(1),
+ &li.bd_gravity_direction, GD_MV_DOWN
},
{
- EL_MM_BOMB, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.mm_time_bomb, 75
+ EL_BD_GRAVITY_SWITCH, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
+ &li.bd_gravity_switch_active, FALSE
},
{
- EL_MM_GRAY_BALL, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.mm_time_ball, 75
+ EL_BD_GRAVITY_SWITCH, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(3),
+ &li.bd_gravity_switch_delay, 10
},
{
- EL_MM_STEEL_BLOCK, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.mm_time_block, 75
+ EL_BD_GRAVITY_SWITCH, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(4),
+ &li.bd_gravity_affects_all, TRUE
},
+
+ // (the following values are related to various game elements)
+
{
- EL_MM_LIGHTBALL, -1,
+ EL_EMERALD, -1,
TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.score[SC_ELEM_BONUS], 10
+ &li.score[SC_EMERALD], 10
},
- // ---------- unused values -------------------------------------------------
-
{
- EL_UNKNOWN, SAVE_CONF_NEVER,
+ EL_DIAMOND, -1,
TYPE_INTEGER, CONF_VALUE_16_BIT(1),
- &li.score[SC_UNKNOWN_15], 10
+ &li.score[SC_DIAMOND], 10
},
{
- -1, -1,
- -1, -1,
- NULL, -1
- }
-};
+ EL_BUG, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.score[SC_BUG], 10
+ },
-static struct LevelFileConfigInfo chunk_config_NOTE[] =
-{
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(1),
- &xx_envelope.xsize, MAX_ENVELOPE_XSIZE,
+ EL_SPACESHIP, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.score[SC_SPACESHIP], 10
},
+
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(2),
- &xx_envelope.ysize, MAX_ENVELOPE_YSIZE,
+ EL_PACMAN, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.score[SC_PACMAN], 10
},
{
- -1, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(3),
- &xx_envelope.autowrap, FALSE
+ EL_NUT, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.score[SC_NUT], 10
},
+
{
- -1, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(4),
- &xx_envelope.centered, FALSE
+ EL_DYNAMITE, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.score[SC_DYNAMITE], 10
},
{
- -1, -1,
- TYPE_STRING, CONF_VALUE_BYTES(1),
- &xx_envelope.text, -1, NULL,
- &xx_string_length_unused, -1, MAX_ENVELOPE_TEXT_LEN,
- &xx_default_string_empty[0]
+ EL_KEY_1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.score[SC_KEY], 10
},
{
- -1, -1,
- -1, -1,
- NULL, -1
- }
-};
+ EL_PEARL, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.score[SC_PEARL], 10
+ },
-static struct LevelFileConfigInfo chunk_config_CUSX_base[] =
-{
{
- -1, -1,
- TYPE_STRING, CONF_VALUE_BYTES(1),
- &xx_ei.description[0], -1,
- &yy_ei.description[0],
- &xx_string_length_unused, -1, MAX_ELEMENT_NAME_LEN,
- &xx_default_description[0]
+ EL_CRYSTAL, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.score[SC_CRYSTAL], 10
},
+ // (amoeba values used by R'n'D game engine only)
{
- -1, -1,
- TYPE_BITFIELD, CONF_VALUE_32_BIT(1),
- &xx_ei.properties[EP_BITFIELD_BASE_NR], EP_BITMASK_BASE_DEFAULT,
- &yy_ei.properties[EP_BITFIELD_BASE_NR]
+ EL_BD_AMOEBA, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.amoeba_content, EL_DIAMOND
},
-#if ENABLE_RESERVED_CODE
- // (reserved for later use)
{
- -1, -1,
- TYPE_BITFIELD, CONF_VALUE_32_BIT(2),
- &xx_ei.properties[EP_BITFIELD_BASE_NR + 1], EP_BITMASK_DEFAULT,
- &yy_ei.properties[EP_BITFIELD_BASE_NR + 1]
+ EL_BD_AMOEBA, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(2),
+ &li.amoeba_speed, 10
},
-#endif
-
{
- -1, -1,
+ EL_BD_AMOEBA, -1,
TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
- &xx_ei.use_gfx_element, FALSE,
- &yy_ei.use_gfx_element
+ &li.grow_into_diggable, TRUE
},
+ // (amoeba values used by BD game engine only)
{
- -1, -1,
- TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
- &xx_ei.gfx_element_initial, EL_EMPTY_SPACE,
- &yy_ei.gfx_element_initial
+ EL_BD_AMOEBA, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
+ &li.bd_amoeba_wait_for_hatching, FALSE
},
-
{
- -1, -1,
- TYPE_BITFIELD, CONF_VALUE_8_BIT(2),
- &xx_ei.access_direction, MV_ALL_DIRECTIONS,
- &yy_ei.access_direction
+ EL_BD_AMOEBA, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(3),
+ &li.bd_amoeba_start_immediately, TRUE
},
-
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(2),
- &xx_ei.collect_score_initial, 10,
- &yy_ei.collect_score_initial
+ EL_BD_AMOEBA, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(4),
+ &li.bd_amoeba_2_explode_by_amoeba, TRUE
},
{
- -1, -1,
+ EL_BD_AMOEBA, -1,
TYPE_INTEGER, CONF_VALUE_16_BIT(3),
- &xx_ei.collect_count_initial, 1,
- &yy_ei.collect_count_initial
+ &li.bd_amoeba_threshold_too_big, 200
},
-
{
- -1, -1,
+ EL_BD_AMOEBA, -1,
TYPE_INTEGER, CONF_VALUE_16_BIT(4),
- &xx_ei.ce_value_fixed_initial, 0,
- &yy_ei.ce_value_fixed_initial
+ &li.bd_amoeba_slow_growth_time, 200
},
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(5),
- &xx_ei.ce_value_random_initial, 0,
- &yy_ei.ce_value_random_initial
+ EL_BD_AMOEBA, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(5),
+ &li.bd_amoeba_slow_growth_rate, 3
},
{
- -1, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(3),
- &xx_ei.use_last_ce_value, FALSE,
- &yy_ei.use_last_ce_value
+ EL_BD_AMOEBA, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(6),
+ &li.bd_amoeba_fast_growth_rate, 25
},
-
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(6),
- &xx_ei.push_delay_fixed, 8,
- &yy_ei.push_delay_fixed
+ EL_BD_AMOEBA, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(5),
+ &li.bd_amoeba_content_too_big, EL_BD_ROCK
},
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(7),
- &xx_ei.push_delay_random, 8,
- &yy_ei.push_delay_random
+ EL_BD_AMOEBA, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(6),
+ &li.bd_amoeba_content_enclosed, EL_BD_DIAMOND
},
+
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(8),
- &xx_ei.drop_delay_fixed, 0,
- &yy_ei.drop_delay_fixed
+ EL_BD_AMOEBA_2, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(3),
+ &li.bd_amoeba_2_threshold_too_big, 200
},
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(9),
- &xx_ei.drop_delay_random, 0,
- &yy_ei.drop_delay_random
+ EL_BD_AMOEBA_2, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(4),
+ &li.bd_amoeba_2_slow_growth_time, 200
},
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(10),
- &xx_ei.move_delay_fixed, 0,
- &yy_ei.move_delay_fixed
- },
- {
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(11),
- &xx_ei.move_delay_random, 0,
- &yy_ei.move_delay_random
- },
-
- {
- -1, -1,
- TYPE_BITFIELD, CONF_VALUE_32_BIT(3),
- &xx_ei.move_pattern, MV_ALL_DIRECTIONS,
- &yy_ei.move_pattern
+ EL_BD_AMOEBA_2, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(5),
+ &li.bd_amoeba_2_slow_growth_rate, 3
},
{
- -1, -1,
- TYPE_BITFIELD, CONF_VALUE_8_BIT(4),
- &xx_ei.move_direction_initial, MV_START_AUTOMATIC,
- &yy_ei.move_direction_initial
+ EL_BD_AMOEBA_2, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(6),
+ &li.bd_amoeba_2_fast_growth_rate, 25
},
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(5),
- &xx_ei.move_stepsize, TILEX / 8,
- &yy_ei.move_stepsize
+ EL_BD_AMOEBA_2, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(5),
+ &li.bd_amoeba_2_content_too_big, EL_BD_ROCK
},
-
{
- -1, -1,
- TYPE_ELEMENT, CONF_VALUE_16_BIT(12),
- &xx_ei.move_enter_element, EL_EMPTY_SPACE,
- &yy_ei.move_enter_element
+ EL_BD_AMOEBA_2, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(6),
+ &li.bd_amoeba_2_content_enclosed, EL_BD_DIAMOND
},
{
- -1, -1,
- TYPE_ELEMENT, CONF_VALUE_16_BIT(13),
- &xx_ei.move_leave_element, EL_EMPTY_SPACE,
- &yy_ei.move_leave_element
+ EL_BD_AMOEBA_2, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(7),
+ &li.bd_amoeba_2_content_exploding, EL_EMPTY
},
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(6),
- &xx_ei.move_leave_type, LEAVE_TYPE_UNLIMITED,
- &yy_ei.move_leave_type
+ EL_BD_AMOEBA_2, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(8),
+ &li.bd_amoeba_2_content_looks_like, EL_BD_AMOEBA_2
},
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(7),
- &xx_ei.slippery_type, SLIPPERY_ANY_RANDOM,
- &yy_ei.slippery_type
+ EL_YAMYAM, -1,
+ TYPE_CONTENT_LIST, CONF_VALUE_BYTES(1),
+ &li.yamyam_content, EL_ROCK, NULL,
+ &li.num_yamyam_contents, 4, MAX_ELEMENT_CONTENTS
},
-
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(8),
- &xx_ei.explosion_type, EXPLODES_3X3,
- &yy_ei.explosion_type
+ EL_YAMYAM, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.score[SC_YAMYAM], 10
},
+
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(14),
- &xx_ei.explosion_delay, 16,
- &yy_ei.explosion_delay
+ EL_ROBOT, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.score[SC_ROBOT], 10
},
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(15),
- &xx_ei.ignition_delay, 8,
- &yy_ei.ignition_delay
+ EL_ROBOT, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(2),
+ &li.slurp_score, 10
},
{
- -1, -1,
- TYPE_CONTENT_LIST, CONF_VALUE_BYTES(2),
- &xx_ei.content, EL_EMPTY_SPACE,
- &yy_ei.content,
- &xx_num_contents, 1, 1
+ EL_ROBOT_WHEEL, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.time_wheel, 10
},
- // ---------- "num_change_pages" must be the last entry ---------------------
-
{
- -1, SAVE_CONF_ALWAYS,
- TYPE_INTEGER, CONF_VALUE_8_BIT(9),
- &xx_ei.num_change_pages, 1,
- &yy_ei.num_change_pages
+ EL_MAGIC_WALL, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.time_magic_wall, 10
},
{
- -1, -1,
- -1, -1,
- NULL, -1,
- NULL
- }
-};
-
-static struct LevelFileConfigInfo chunk_config_CUSX_change[] =
-{
- // ---------- "current_change_page" must be the first entry -----------------
-
- {
- -1, SAVE_CONF_ALWAYS,
+ EL_GAME_OF_LIFE, -1,
TYPE_INTEGER, CONF_VALUE_8_BIT(1),
- &xx_current_change_page, -1
+ &li.game_of_life[0], 2
},
-
- // ---------- (the remaining entries can be in any order) -------------------
-
{
- -1, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
- &xx_change.can_change, FALSE
+ EL_GAME_OF_LIFE, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(2),
+ &li.game_of_life[1], 3
},
-
{
- -1, -1,
- TYPE_BITFIELD, CONF_VALUE_32_BIT(1),
- &xx_event_bits[0], 0
+ EL_GAME_OF_LIFE, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(3),
+ &li.game_of_life[2], 3
},
{
- -1, -1,
- TYPE_BITFIELD, CONF_VALUE_32_BIT(2),
- &xx_event_bits[1], 0
+ EL_GAME_OF_LIFE, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(4),
+ &li.game_of_life[3], 3
+ },
+ {
+ EL_GAME_OF_LIFE, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(5),
+ &li.use_life_bugs, FALSE
},
{
- -1, -1,
- TYPE_BITFIELD, CONF_VALUE_8_BIT(3),
- &xx_change.trigger_player, CH_PLAYER_ANY
+ EL_BIOMAZE, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(1),
+ &li.biomaze[0], 2
},
{
- -1, -1,
- TYPE_BITFIELD, CONF_VALUE_8_BIT(4),
- &xx_change.trigger_side, CH_SIDE_ANY
+ EL_BIOMAZE, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(2),
+ &li.biomaze[1], 3
},
{
- -1, -1,
- TYPE_BITFIELD, CONF_VALUE_32_BIT(3),
- &xx_change.trigger_page, CH_PAGE_ANY
+ EL_BIOMAZE, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(3),
+ &li.biomaze[2], 3
},
-
{
- -1, -1,
- TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
- &xx_change.target_element, EL_EMPTY_SPACE
+ EL_BIOMAZE, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(4),
+ &li.biomaze[3], 3
},
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(2),
- &xx_change.delay_fixed, 0
+ EL_TIMEGATE_SWITCH, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.time_timegate, 10
},
+
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(3),
- &xx_change.delay_random, 0
+ EL_LIGHT_SWITCH_ACTIVE, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.time_light, 10
},
+
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(4),
- &xx_change.delay_frames, FRAMES_PER_SECOND
+ EL_SHIELD_NORMAL, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.shield_normal_time, 10
},
-
{
- -1, -1,
- TYPE_ELEMENT, CONF_VALUE_16_BIT(5),
- &xx_change.initial_trigger_element, EL_EMPTY_SPACE
+ EL_SHIELD_NORMAL, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(2),
+ &li.score[SC_SHIELD], 10
},
{
- -1, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(6),
- &xx_change.explode, FALSE
+ EL_SHIELD_DEADLY, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.shield_deadly_time, 10
},
{
- -1, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(7),
- &xx_change.use_target_content, FALSE
+ EL_SHIELD_DEADLY, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(2),
+ &li.score[SC_SHIELD], 10
},
+
{
- -1, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(8),
- &xx_change.only_if_complete, FALSE
+ EL_EXTRA_TIME, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.extra_time, 10
},
{
- -1, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(9),
- &xx_change.use_random_replace, FALSE
+ EL_EXTRA_TIME, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(2),
+ &li.extra_time_score, 10
},
+
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(10),
- &xx_change.random_percentage, 100
+ EL_TIME_ORB_FULL, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.time_orb_time, 10
},
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(11),
- &xx_change.replace_when, CP_WHEN_EMPTY
+ EL_TIME_ORB_FULL, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &li.use_time_orb_bug, FALSE
},
{
- -1, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(12),
- &xx_change.has_action, FALSE
+ EL_SPRING, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &li.use_spring_bug, FALSE
},
+
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(13),
- &xx_change.action_type, CA_NO_ACTION
+ EL_EMC_ANDROID, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.android_move_time, 10
},
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(14),
- &xx_change.action_mode, CA_MODE_UNDEFINED
+ EL_EMC_ANDROID, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(2),
+ &li.android_clone_time, 10
},
{
- -1, -1,
- TYPE_INTEGER, CONF_VALUE_16_BIT(6),
- &xx_change.action_arg, CA_ARG_UNDEFINED
+ EL_EMC_ANDROID, SAVE_CONF_NEVER,
+ TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(1),
+ &li.android_clone_element[0], EL_EMPTY, NULL,
+ &li.num_android_clone_elements, 1, MAX_ANDROID_ELEMENTS_OLD
},
-
{
- -1, -1,
- TYPE_ELEMENT, CONF_VALUE_16_BIT(7),
- &xx_change.action_element, EL_EMPTY_SPACE
+ EL_EMC_ANDROID, -1,
+ TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(2),
+ &li.android_clone_element[0], EL_EMPTY, NULL,
+ &li.num_android_clone_elements, 1, MAX_ANDROID_ELEMENTS
},
{
- -1, -1,
+ EL_EMC_LENSES, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.lenses_score, 10
+ },
+ {
+ EL_EMC_LENSES, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(2),
+ &li.lenses_time, 10
+ },
+
+ {
+ EL_EMC_MAGNIFIER, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.magnify_score, 10
+ },
+ {
+ EL_EMC_MAGNIFIER, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(2),
+ &li.magnify_time, 10
+ },
+
+ {
+ EL_EMC_MAGIC_BALL, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.ball_time, 10
+ },
+ {
+ EL_EMC_MAGIC_BALL, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &li.ball_random, FALSE
+ },
+ {
+ EL_EMC_MAGIC_BALL, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
+ &li.ball_active_initial, FALSE
+ },
+ {
+ EL_EMC_MAGIC_BALL, -1,
TYPE_CONTENT_LIST, CONF_VALUE_BYTES(1),
- &xx_change.target_content, EL_EMPTY_SPACE, NULL,
- &xx_num_contents, 1, 1
+ &li.ball_content, EL_EMPTY, NULL,
+ &li.num_ball_contents, 4, MAX_ELEMENT_CONTENTS
+ },
+
+ {
+ EL_SOKOBAN_FIELD_EMPTY, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &li.sb_fields_needed, TRUE
+ },
+
+ {
+ EL_SOKOBAN_OBJECT, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &li.sb_objects_needed, TRUE
+ },
+
+ {
+ EL_MM_MCDUFFIN, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &li.mm_laser_red, FALSE
+ },
+ {
+ EL_MM_MCDUFFIN, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
+ &li.mm_laser_green, FALSE
+ },
+ {
+ EL_MM_MCDUFFIN, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(3),
+ &li.mm_laser_blue, TRUE
+ },
+
+ {
+ EL_DF_LASER, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &li.df_laser_red, TRUE
+ },
+ {
+ EL_DF_LASER, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
+ &li.df_laser_green, TRUE
+ },
+ {
+ EL_DF_LASER, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(3),
+ &li.df_laser_blue, FALSE
+ },
+
+ {
+ EL_MM_FUSE_ACTIVE, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.mm_time_fuse, 25
+ },
+ {
+ EL_MM_BOMB, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.mm_time_bomb, 75
+ },
+
+ {
+ EL_MM_GRAY_BALL, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.mm_time_ball, 75
+ },
+ {
+ EL_MM_GRAY_BALL, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(1),
+ &li.mm_ball_choice_mode, ANIM_RANDOM
+ },
+ {
+ EL_MM_GRAY_BALL, -1,
+ TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(1),
+ &li.mm_ball_content, EL_EMPTY, NULL,
+ &li.num_mm_ball_contents, 8, MAX_MM_BALL_CONTENTS
+ },
+ {
+ EL_MM_GRAY_BALL, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(3),
+ &li.rotate_mm_ball_content, TRUE
+ },
+ {
+ EL_MM_GRAY_BALL, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
+ &li.explode_mm_ball, FALSE
+ },
+
+ {
+ EL_MM_STEEL_BLOCK, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.mm_time_block, 75
+ },
+ {
+ EL_MM_LIGHTBALL, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(1),
+ &li.score[SC_ELEM_BONUS], 10
},
{
}
};
-static struct LevelFileConfigInfo chunk_config_GRPX[] =
+static struct LevelFileConfigInfo chunk_config_NOTE[] =
{
{
-1, -1,
- TYPE_STRING, CONF_VALUE_BYTES(1),
- &xx_ei.description[0], -1, NULL,
- &xx_string_length_unused, -1, MAX_ELEMENT_NAME_LEN,
- &xx_default_description[0]
+ TYPE_INTEGER, CONF_VALUE_8_BIT(1),
+ &xx_envelope.xsize, MAX_ENVELOPE_XSIZE,
},
-
{
-1, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
- &xx_ei.use_gfx_element, FALSE
+ TYPE_INTEGER, CONF_VALUE_8_BIT(2),
+ &xx_envelope.ysize, MAX_ENVELOPE_YSIZE,
},
+
{
-1, -1,
- TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
- &xx_ei.gfx_element_initial, EL_EMPTY_SPACE
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(3),
+ &xx_envelope.autowrap, FALSE
},
-
{
-1, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(2),
- &xx_group.choice_mode, ANIM_RANDOM
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(4),
+ &xx_envelope.centered, FALSE
},
{
-1, -1,
- TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(2),
- &xx_group.element[0], EL_EMPTY_SPACE, NULL,
- &xx_group.num_elements, 1, MAX_ELEMENTS_IN_GROUP
+ TYPE_STRING, CONF_VALUE_BYTES(1),
+ &xx_envelope.text, -1, NULL,
+ &xx_string_length_unused, -1, MAX_ENVELOPE_TEXT_LEN,
+ &xx_default_string_empty[0]
},
{
}
};
-static struct LevelFileConfigInfo chunk_config_CONF[] = // (OBSOLETE)
+static struct LevelFileConfigInfo chunk_config_CUSX_base[] =
{
{
- EL_PLAYER_1, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(9),
- &li.block_snap_field, TRUE
+ -1, -1,
+ TYPE_STRING, CONF_VALUE_BYTES(1),
+ &xx_ei.description[0], -1,
+ &yy_ei.description[0],
+ &xx_string_length_unused, -1, MAX_ELEMENT_NAME_LEN,
+ &xx_default_description[0]
},
+
{
- EL_PLAYER_1, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(13),
- &li.continuous_snapping, TRUE
+ -1, -1,
+ TYPE_BITFIELD, CONF_VALUE_32_BIT(1),
+ &xx_ei.properties[EP_BITFIELD_BASE_NR], EP_BITMASK_BASE_DEFAULT,
+ &yy_ei.properties[EP_BITFIELD_BASE_NR]
},
+#if ENABLE_RESERVED_CODE
+ // (reserved for later use)
{
- EL_PLAYER_1, -1,
- TYPE_INTEGER, CONF_VALUE_8_BIT(1),
- &li.initial_player_stepsize[0], STEPSIZE_NORMAL
+ -1, -1,
+ TYPE_BITFIELD, CONF_VALUE_32_BIT(2),
+ &xx_ei.properties[EP_BITFIELD_BASE_NR + 1], EP_BITMASK_DEFAULT,
+ &yy_ei.properties[EP_BITFIELD_BASE_NR + 1]
},
+#endif
+
{
- EL_PLAYER_1, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(10),
- &li.use_start_element[0], FALSE
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &xx_ei.use_gfx_element, FALSE,
+ &yy_ei.use_gfx_element
},
{
- EL_PLAYER_1, -1,
+ -1, -1,
TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
- &li.start_element[0], EL_PLAYER_1
+ &xx_ei.gfx_element_initial, EL_EMPTY_SPACE,
+ &yy_ei.gfx_element_initial
},
+
{
- EL_PLAYER_1, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(11),
- &li.use_artwork_element[0], FALSE
+ -1, -1,
+ TYPE_BITFIELD, CONF_VALUE_8_BIT(2),
+ &xx_ei.access_direction, MV_ALL_DIRECTIONS,
+ &yy_ei.access_direction
},
+
{
- EL_PLAYER_1, -1,
- TYPE_ELEMENT, CONF_VALUE_16_BIT(2),
- &li.artwork_element[0], EL_PLAYER_1
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(2),
+ &xx_ei.collect_score_initial, 10,
+ &yy_ei.collect_score_initial
},
{
- EL_PLAYER_1, -1,
- TYPE_BOOLEAN, CONF_VALUE_8_BIT(12),
- &li.use_explosion_element[0], FALSE
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(3),
+ &xx_ei.collect_count_initial, 1,
+ &yy_ei.collect_count_initial
},
+
{
- EL_PLAYER_1, -1,
- TYPE_ELEMENT, CONF_VALUE_16_BIT(3),
- &li.explosion_element[0], EL_PLAYER_1
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(4),
+ &xx_ei.ce_value_fixed_initial, 0,
+ &yy_ei.ce_value_fixed_initial
},
-
{
-1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(5),
+ &xx_ei.ce_value_random_initial, 0,
+ &yy_ei.ce_value_random_initial
+ },
+ {
-1, -1,
- NULL, -1
- }
-};
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(3),
+ &xx_ei.use_last_ce_value, FALSE,
+ &yy_ei.use_last_ce_value
+ },
-static struct
-{
- int filetype;
- char *id;
-}
-filetype_id_list[] =
-{
- { LEVEL_FILE_TYPE_RND, "RND" },
- { LEVEL_FILE_TYPE_BD, "BD" },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(6),
+ &xx_ei.push_delay_fixed, 8,
+ &yy_ei.push_delay_fixed
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(7),
+ &xx_ei.push_delay_random, 8,
+ &yy_ei.push_delay_random
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(8),
+ &xx_ei.drop_delay_fixed, 0,
+ &yy_ei.drop_delay_fixed
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(9),
+ &xx_ei.drop_delay_random, 0,
+ &yy_ei.drop_delay_random
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(10),
+ &xx_ei.move_delay_fixed, 0,
+ &yy_ei.move_delay_fixed
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(11),
+ &xx_ei.move_delay_random, 0,
+ &yy_ei.move_delay_random
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(16),
+ &xx_ei.step_delay_fixed, 0,
+ &yy_ei.step_delay_fixed
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(17),
+ &xx_ei.step_delay_random, 0,
+ &yy_ei.step_delay_random
+ },
+
+ {
+ -1, -1,
+ TYPE_BITFIELD, CONF_VALUE_32_BIT(3),
+ &xx_ei.move_pattern, MV_ALL_DIRECTIONS,
+ &yy_ei.move_pattern
+ },
+ {
+ -1, -1,
+ TYPE_BITFIELD, CONF_VALUE_8_BIT(4),
+ &xx_ei.move_direction_initial, MV_START_AUTOMATIC,
+ &yy_ei.move_direction_initial
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(5),
+ &xx_ei.move_stepsize, TILEX / 8,
+ &yy_ei.move_stepsize
+ },
+
+ {
+ -1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(12),
+ &xx_ei.move_enter_element, EL_EMPTY_SPACE,
+ &yy_ei.move_enter_element
+ },
+ {
+ -1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(13),
+ &xx_ei.move_leave_element, EL_EMPTY_SPACE,
+ &yy_ei.move_leave_element
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(6),
+ &xx_ei.move_leave_type, LEAVE_TYPE_UNLIMITED,
+ &yy_ei.move_leave_type
+ },
+
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(7),
+ &xx_ei.slippery_type, SLIPPERY_ANY_RANDOM,
+ &yy_ei.slippery_type
+ },
+
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(8),
+ &xx_ei.explosion_type, EXPLODES_3X3,
+ &yy_ei.explosion_type
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(14),
+ &xx_ei.explosion_delay, 16,
+ &yy_ei.explosion_delay
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(15),
+ &xx_ei.ignition_delay, 8,
+ &yy_ei.ignition_delay
+ },
+
+ {
+ -1, -1,
+ TYPE_CONTENT_LIST, CONF_VALUE_BYTES(2),
+ &xx_ei.content, EL_EMPTY_SPACE,
+ &yy_ei.content,
+ &xx_num_contents, 1, 1
+ },
+
+ // ---------- "num_change_pages" must be the last entry ---------------------
+
+ {
+ -1, SAVE_CONF_ALWAYS,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(9),
+ &xx_ei.num_change_pages, 1,
+ &yy_ei.num_change_pages
+ },
+
+ {
+ -1, -1,
+ -1, -1,
+ NULL, -1,
+ NULL
+ }
+};
+
+static struct LevelFileConfigInfo chunk_config_CUSX_change[] =
+{
+ // ---------- "current_change_page" must be the first entry -----------------
+
+ {
+ -1, SAVE_CONF_ALWAYS,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(1),
+ &xx_current_change_page, -1
+ },
+
+ // ---------- (the remaining entries can be in any order) -------------------
+
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
+ &xx_change.can_change, FALSE
+ },
+
+ {
+ -1, -1,
+ TYPE_BITFIELD, CONF_VALUE_32_BIT(1),
+ &xx_event_bits[0], 0
+ },
+ {
+ -1, -1,
+ TYPE_BITFIELD, CONF_VALUE_32_BIT(2),
+ &xx_event_bits[1], 0
+ },
+
+ {
+ -1, -1,
+ TYPE_BITFIELD, CONF_VALUE_8_BIT(3),
+ &xx_change.trigger_player, CH_PLAYER_ANY
+ },
+ {
+ -1, -1,
+ TYPE_BITFIELD, CONF_VALUE_8_BIT(4),
+ &xx_change.trigger_side, CH_SIDE_ANY
+ },
+ {
+ -1, -1,
+ TYPE_BITFIELD, CONF_VALUE_32_BIT(3),
+ &xx_change.trigger_page, CH_PAGE_ANY
+ },
+
+ {
+ -1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &xx_change.target_element, EL_EMPTY_SPACE
+ },
+
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(2),
+ &xx_change.delay_fixed, 0
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(3),
+ &xx_change.delay_random, 0
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(4),
+ &xx_change.delay_frames, FRAMES_PER_SECOND
+ },
+
+ {
+ -1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(5),
+ &xx_change.initial_trigger_element, EL_EMPTY_SPACE
+ },
+
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(6),
+ &xx_change.explode, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(7),
+ &xx_change.use_target_content, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(8),
+ &xx_change.only_if_complete, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(9),
+ &xx_change.use_random_replace, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(10),
+ &xx_change.random_percentage, 100
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(11),
+ &xx_change.replace_when, CP_WHEN_EMPTY
+ },
+
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(12),
+ &xx_change.has_action, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(13),
+ &xx_change.action_type, CA_NO_ACTION
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(14),
+ &xx_change.action_mode, CA_MODE_UNDEFINED
+ },
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_16_BIT(6),
+ &xx_change.action_arg, CA_ARG_UNDEFINED
+ },
+
+ {
+ -1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(7),
+ &xx_change.action_element, EL_EMPTY_SPACE
+ },
+
+ {
+ -1, -1,
+ TYPE_CONTENT_LIST, CONF_VALUE_BYTES(1),
+ &xx_change.target_content, EL_EMPTY_SPACE, NULL,
+ &xx_num_contents, 1, 1
+ },
+
+ {
+ -1, -1,
+ -1, -1,
+ NULL, -1
+ }
+};
+
+static struct LevelFileConfigInfo chunk_config_GRPX[] =
+{
+ {
+ -1, -1,
+ TYPE_STRING, CONF_VALUE_BYTES(1),
+ &xx_ei.description[0], -1, NULL,
+ &xx_string_length_unused, -1, MAX_ELEMENT_NAME_LEN,
+ &xx_default_description[0]
+ },
+
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &xx_ei.use_gfx_element, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &xx_ei.gfx_element_initial, EL_EMPTY_SPACE
+ },
+
+ {
+ -1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(2),
+ &xx_group.choice_mode, ANIM_RANDOM
+ },
+
+ {
+ -1, -1,
+ TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(2),
+ &xx_group.element[0], EL_EMPTY_SPACE, NULL,
+ &xx_group.num_elements, 1, MAX_ELEMENTS_IN_GROUP
+ },
+
+ {
+ -1, -1,
+ -1, -1,
+ NULL, -1
+ }
+};
+
+static struct LevelFileConfigInfo chunk_config_EMPX[] =
+{
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &xx_ei.use_gfx_element, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &xx_ei.gfx_element_initial, EL_EMPTY_SPACE
+ },
+
+ {
+ -1, -1,
+ -1, -1,
+ NULL, -1
+ }
+};
+
+static struct LevelFileConfigInfo chunk_config_CONF[] = // (OBSOLETE)
+{
+ {
+ EL_PLAYER_1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(9),
+ &li.block_snap_field, TRUE
+ },
+ {
+ EL_PLAYER_1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(13),
+ &li.continuous_snapping, TRUE
+ },
+ {
+ EL_PLAYER_1, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(1),
+ &li.initial_player_stepsize[0], STEPSIZE_NORMAL
+ },
+ {
+ EL_PLAYER_1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(10),
+ &li.use_start_element[0], FALSE
+ },
+ {
+ EL_PLAYER_1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &li.start_element[0], EL_PLAYER_1
+ },
+ {
+ EL_PLAYER_1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(11),
+ &li.use_artwork_element[0], FALSE
+ },
+ {
+ EL_PLAYER_1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(2),
+ &li.artwork_element[0], EL_PLAYER_1
+ },
+ {
+ EL_PLAYER_1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(12),
+ &li.use_explosion_element[0], FALSE
+ },
+ {
+ EL_PLAYER_1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(3),
+ &li.explosion_element[0], EL_PLAYER_1
+ },
+
+ {
+ -1, -1,
+ -1, -1,
+ NULL, -1
+ }
+};
+
+static struct
+{
+ int filetype;
+ char *id;
+}
+filetype_id_list[] =
+{
+ { LEVEL_FILE_TYPE_RND, "RND" },
+ { LEVEL_FILE_TYPE_BD, "BD" },
{ LEVEL_FILE_TYPE_EM, "EM" },
{ LEVEL_FILE_TYPE_SP, "SP" },
{ LEVEL_FILE_TYPE_DX, "DX" },
setConfigToDefaultsFromConfigList(chunk_config_INFO);
*level = li; // copy temporary buffer back to level data
+ setLevelInfoToDefaults_BD();
setLevelInfoToDefaults_EM();
setLevelInfoToDefaults_SP();
setLevelInfoToDefaults_MM();
+ level->native_bd_level = &native_bd_level;
level->native_em_level = &native_em_level;
level->native_sp_level = &native_sp_level;
level->native_mm_level = &native_mm_level;
int element = i;
struct ElementInfo *ei = &element_info[element];
+ if (element == EL_MM_GRAY_BALL)
+ {
+ struct LevelInfo_MM *level_mm = level->native_mm_level;
+ int j;
+
+ for (j = 0; j < level->num_mm_ball_contents; j++)
+ level->mm_ball_content[j] =
+ map_element_MM_to_RND(level_mm->ball_content[j]);
+ }
+
// never initialize clipboard elements after the very first time
// (to be able to use clipboard elements between several levels)
if (IS_CLIPBOARD_ELEMENT(element) && clipboard_elements_initialized)
setElementChangeInfoToDefaults(ei->change);
if (IS_CUSTOM_ELEMENT(element) ||
- IS_GROUP_ELEMENT(element) ||
- IS_INTERNAL_ELEMENT(element))
+ IS_GROUP_ELEMENT(element))
{
setElementDescriptionToDefault(ei);
*group = xx_group;
}
+
+ if (IS_EMPTY_ELEMENT(element) ||
+ IS_INTERNAL_ELEMENT(element))
+ {
+ xx_ei = *ei; // copy element data into temporary buffer
+
+ setConfigToDefaultsFromConfigList(chunk_config_EMPX);
+
+ *ei = xx_ei;
+ }
}
clipboard_elements_initialized = TRUE;
}
}
+static boolean checkForPackageFromBasename_BD(char *basename)
+{
+ // check for native BD level file extensions
+ if (!strSuffixLower(basename, ".bd") &&
+ !strSuffixLower(basename, ".bdr") &&
+ !strSuffixLower(basename, ".brc") &&
+ !strSuffixLower(basename, ".gds"))
+ return FALSE;
+
+ // check for standard single-level BD files (like "001.bd")
+ if (strSuffixLower(basename, ".bd") &&
+ strlen(basename) == 6 &&
+ basename[0] >= '0' && basename[0] <= '9' &&
+ basename[1] >= '0' && basename[1] <= '9' &&
+ basename[2] >= '0' && basename[2] <= '9')
+ return FALSE;
+
+ // this is a level package in native BD file format
+ return TRUE;
+}
+
static char *getLevelFilenameFromBasename(char *basename)
{
static char *filename = NULL;
strchr(basename, '%') == NULL)
return LEVEL_FILE_TYPE_SB;
+ // check for typical filename of a Boulder Dash (GDash) level package file
+ if (checkForPackageFromBasename_BD(basename))
+ return LEVEL_FILE_TYPE_BD;
+
// ---------- try to determine file type from filesize ----------
checked_free(filename);
if ((dir = openDirectory(directory)) == NULL)
{
- Error(ERR_WARN, "cannot read current level directory '%s'", directory);
+ Warn("cannot read current level directory '%s'", directory);
return basename;
}
if (fileExists(lfi->filename))
return;
+ // check for native Boulder Dash level file
+ setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_BD, "%03d.bd", nr);
+ if (fileExists(lfi->filename))
+ return;
+
// check for Emerald Mine level file (V1)
setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_EM, "a%c%c",
'a' + (nr / 10) % 26, '0' + nr % 10);
// functions for loading R'n'D level
// ----------------------------------------------------------------------------
-static int getMappedElement(int element)
+int getMappedElement(int element)
{
// remap some (historic, now obsolete) elements
default:
if (element >= NUM_FILE_ELEMENTS)
{
- Error(ERR_WARN, "invalid level element %d", element);
+ Warn("invalid level element %d", element);
element = EL_UNKNOWN;
}
}
else
{
- Error(ERR_WARN, "cannot load content for element '%d'", element);
+ Warn("cannot load content for element '%d'", element);
}
return chunk_size;
if (IS_CUSTOM_ELEMENT(element))
element_info[element].properties[EP_BITFIELD_BASE_NR] = properties;
else
- Error(ERR_WARN, "invalid custom element number %d", element);
+ Warn("invalid custom element number %d", element);
// older game versions that wrote level files with CUS1 chunks used
// different default push delay values (not yet stored in level file)
if (IS_CUSTOM_ELEMENT(element))
element_info[element].change->target_element = custom_target_element;
else
- Error(ERR_WARN, "invalid custom element number %d", element);
+ Warn("invalid custom element number %d", element);
}
level->file_has_custom_elements = TRUE;
if (!IS_CUSTOM_ELEMENT(element))
{
- Error(ERR_WARN, "invalid custom element number %d", element);
+ Warn("invalid custom element number %d", element);
element = EL_INTERNAL_DUMMY;
}
for (x = 0; x < 3; x++)
ei->content.e[x][y] = getMappedElement(getFile16BitBE(file));
+ // bits 0 - 31 of "has_event[]"
event_bits = getFile32BitBE(file);
- for (j = 0; j < NUM_CHANGE_EVENTS; j++)
- if (event_bits & (1 << j))
+ for (j = 0; j < MIN(NUM_CHANGE_EVENTS, 32); j++)
+ if (event_bits & (1u << j))
ei->change->has_event[j] = TRUE;
ei->change->target_element = getMappedElement(getFile16BitBE(file));
ei->change->delay_random = getFile16BitBE(file);
ei->change->delay_frames = getFile16BitBE(file);
- ei->change->initial_trigger_element= getMappedElement(getFile16BitBE(file));
+ ei->change->initial_trigger_element = getMappedElement(getFile16BitBE(file));
ei->change->explode = getFile8Bit(file);
ei->change->use_target_content = getFile8Bit(file);
if (!IS_CUSTOM_ELEMENT(element))
{
- Error(ERR_WARN, "invalid custom element number %d", element);
+ Warn("invalid custom element number %d", element);
ReadUnusedBytesFromFile(file, chunk_size - 2);
+
return chunk_size;
}
// bits 0 - 31 of "has_event[]" ...
event_bits = getFile32BitBE(file);
for (j = 0; j < MIN(NUM_CHANGE_EVENTS, 32); j++)
- if (event_bits & (1 << j))
+ if (event_bits & (1u << j))
change->has_event[j] = TRUE;
change->target_element = getMappedElement(getFile16BitBE(file));
// ... bits 32 - 39 of "has_event[]" (not nice, but downward compatible)
event_bits = getFile8Bit(file);
for (j = 32; j < NUM_CHANGE_EVENTS; j++)
- if (event_bits & (1 << (j - 32)))
+ if (event_bits & (1u << (j - 32)))
change->has_event[j] = TRUE;
}
if (!IS_GROUP_ELEMENT(element))
{
- Error(ERR_WARN, "invalid group element number %d", element);
+ Warn("invalid group element number %d", element);
ReadUnusedBytesFromFile(file, chunk_size - 2);
+
return chunk_size;
}
if (num_entities > max_num_entities)
{
- Error(ERR_WARN,
- "truncating number of entities for element %d from %d to %d",
- element, num_entities, max_num_entities);
+ Warn("truncating number of entities for element %d from %d to %d",
+ element, num_entities, max_num_entities);
num_entities = max_num_entities;
}
data_type == TYPE_CONTENT_LIST))
{
// for element and content lists, zero entities are not allowed
- Error(ERR_WARN, "found empty list of entities for element %d",
- element);
+ Warn("found empty list of entities for element %d", element);
// do not set "num_entities" here to prevent reading behind buffer
value = getMappedElement(value);
if (data_type == TYPE_BOOLEAN)
- *(boolean *)(conf[i].value) = value;
+ *(boolean *)(conf[i].value) = (value ? TRUE : FALSE);
else
*(int *) (conf[i].value) = value;
int error_conf_chunk_token = conf_type & CONF_MASK_TOKEN;
int error_element = real_element;
- Error(ERR_WARN, "cannot load micro chunk '%s(%d)' value for element %d ['%s']",
- error_conf_chunk_bytes, error_conf_chunk_token,
- error_element, EL_NAME(error_element));
+ Warn("cannot load micro chunk '%s(%d)' value for element %d ['%s']",
+ error_conf_chunk_bytes, error_conf_chunk_token,
+ error_element, EL_NAME(error_element));
}
return micro_chunk_size;
if (ei->num_change_pages == -1)
{
- Error(ERR_WARN, "LoadLevel_CUSX(): missing 'num_change_pages' for '%s'",
- EL_NAME(element));
+ Warn("LoadLevel_CUSX(): missing 'num_change_pages' for '%s'",
+ EL_NAME(element));
ei->num_change_pages = 1;
while (!checkEndOfFile(file))
{
+ // level file might contain invalid change page number
+ if (xx_current_change_page >= ei->num_change_pages)
+ break;
+
struct ElementChangeInfo *change = &ei->change_page[xx_current_change_page];
xx_change = *change; // copy change data into temporary buffer
struct ElementInfo *ei = &element_info[element];
struct ElementGroupInfo *group = ei->group;
+ if (group == NULL)
+ return -1;
+
xx_ei = *ei; // copy element data into temporary buffer
xx_group = *group; // copy group data into temporary buffer
return real_chunk_size;
}
+static int LoadLevel_EMPX(File *file, int chunk_size, struct LevelInfo *level)
+{
+ int element = getMappedElement(getFile16BitBE(file));
+ int real_chunk_size = 2;
+ struct ElementInfo *ei = &element_info[element];
+
+ xx_ei = *ei; // copy element data into temporary buffer
+
+ while (!checkEndOfFile(file))
+ {
+ real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_EMPX,
+ -1, element);
+
+ if (real_chunk_size >= chunk_size)
+ break;
+ }
+
+ *ei = xx_ei;
+
+ level->file_has_custom_elements = TRUE;
+
+ return real_chunk_size;
+}
+
static void LoadLevelFromFileInfo_RND(struct LevelInfo *level,
struct LevelFileInfo *level_file_info,
boolean level_info_only)
if (level_info_only)
return;
- Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename);
+ Warn("cannot read level '%s' -- using empty level", filename);
if (!setup.editor.use_template_for_new_levels)
return;
{
level->no_valid_file = TRUE;
- Error(ERR_WARN, "unknown format of level file '%s'", filename);
+ Warn("unknown format of level file '%s'", filename);
closeFile(file);
{
level->no_valid_file = TRUE;
- Error(ERR_WARN, "unknown format of level file '%s'", filename);
+ Warn("unknown format of level file '%s'", filename);
closeFile(file);
{
level->no_valid_file = TRUE;
- Error(ERR_WARN, "unsupported version of level file '%s'", filename);
+ Warn("unsupported version of level file '%s'", filename);
closeFile(file);
{ "NOTE", -1, LoadLevel_NOTE },
{ "CUSX", -1, LoadLevel_CUSX },
{ "GRPX", -1, LoadLevel_GRPX },
+ { "EMPX", -1, LoadLevel_EMPX },
{ NULL, 0, NULL }
};
if (chunk_info[i].name == NULL)
{
- Error(ERR_WARN, "unknown chunk '%s' in level file '%s'",
- chunk_name, filename);
+ Warn("unknown chunk '%s' in level file '%s'",
+ chunk_name, filename);
+
ReadUnusedBytesFromFile(file, chunk_size);
}
else if (chunk_info[i].size != -1 &&
chunk_info[i].size != chunk_size)
{
- Error(ERR_WARN, "wrong size (%d) of chunk '%s' in level file '%s'",
- chunk_size, chunk_name, filename);
+ Warn("wrong size (%d) of chunk '%s' in level file '%s'",
+ chunk_size, chunk_name, filename);
+
ReadUnusedBytesFromFile(file, chunk_size);
}
else
{
- // call function to load this level chunk
- int chunk_size_expected =
- (chunk_info[i].loader)(file, chunk_size, level);
+ // call function to load this level chunk
+ int chunk_size_expected =
+ (chunk_info[i].loader)(file, chunk_size, level);
+
+ if (chunk_size_expected < 0)
+ {
+ Warn("error reading chunk '%s' in level file '%s'",
+ chunk_name, filename);
+
+ break;
+ }
+
+ // the size of some chunks cannot be checked before reading other
+ // chunks first (like "HEAD" and "BODY") that contain some header
+ // information, so check them here
+ if (chunk_size_expected != chunk_size)
+ {
+ Warn("wrong size (%d) of chunk '%s' in level file '%s'",
+ chunk_size, chunk_name, filename);
+
+ break;
+ }
+ }
+ }
+ }
+
+ closeFile(file);
+}
+
+
+// ----------------------------------------------------------------------------
+// functions for loading BD level
+// ----------------------------------------------------------------------------
+
+#define LEVEL_TO_CAVE(e) (map_element_RND_to_BD_cave(e))
+#define CAVE_TO_LEVEL(e) (map_element_BD_to_RND_cave(e))
+
+static void CopyNativeLevel_RND_to_BD(struct LevelInfo *level)
+{
+ struct LevelInfo_BD *level_bd = level->native_bd_level;
+ GdCave *cave = NULL; // will be changed below
+ int cave_w = MIN(level->fieldx, MAX_PLAYFIELD_WIDTH);
+ int cave_h = MIN(level->fieldy, MAX_PLAYFIELD_HEIGHT);
+ int x, y;
+
+ setLevelInfoToDefaults_BD_Ext(cave_w, cave_h);
+
+ // cave and map newly allocated when set to defaults above
+ cave = level_bd->cave;
+
+ // level type
+ cave->intermission = level->bd_intermission;
+
+ // level settings
+ cave->level_time[0] = level->time;
+ cave->level_diamonds[0] = level->gems_needed;
+
+ // game timing
+ cave->scheduling = level->bd_scheduling_type;
+ cave->pal_timing = level->bd_pal_timing;
+ cave->level_speed[0] = level->bd_cycle_delay_ms;
+ cave->level_ckdelay[0] = level->bd_cycle_delay_c64;
+ cave->level_hatching_delay_frame[0] = level->bd_hatching_delay_cycles;
+ cave->level_hatching_delay_time[0] = level->bd_hatching_delay_seconds;
+
+ // scores
+ cave->level_timevalue[0] = level->score[SC_TIME_BONUS];
+ cave->diamond_value = level->score[SC_EMERALD];
+ cave->extra_diamond_value = level->score[SC_DIAMOND_EXTRA];
+
+ // compatibility settings
+ cave->lineshift = level->bd_line_shifting_borders;
+ cave->border_scan_first_and_last = level->bd_scan_first_and_last_row;
+ cave->short_explosions = level->bd_short_explosions;
+
+ // player properties
+ cave->diagonal_movements = level->bd_diagonal_movements;
+ cave->active_is_first_found = level->bd_topmost_player_active;
+ cave->pushing_stone_prob = level->bd_pushing_prob * 10000;
+ cave->pushing_stone_prob_sweet = level->bd_pushing_prob_with_sweet * 10000;
+ cave->mega_stones_pushable_with_sweet = level->bd_push_mega_rock_with_sweet;
+ cave->snap_element = LEVEL_TO_CAVE(level->bd_snap_element);
+
+ // element properties
+ cave->level_bonus_time[0] = level->bd_clock_extra_time;
+ cave->voodoo_collects_diamonds = level->bd_voodoo_collects_diamonds;
+ cave->voodoo_any_hurt_kills_player = level->bd_voodoo_hurt_kills_player;
+ cave->voodoo_dies_by_stone = level->bd_voodoo_dies_by_rock;
+ cave->voodoo_disappear_in_explosion = level->bd_voodoo_vanish_by_explosion;
+ cave->level_penalty_time[0] = level->bd_voodoo_penalty_time;
+ cave->level_magic_wall_time[0] = level->time_magic_wall;
+ cave->magic_timer_wait_for_hatching = level->bd_magic_wall_wait_hatching;
+ cave->magic_wall_stops_amoeba = level->bd_magic_wall_stops_amoeba;
+
+ cave->magic_diamond_to = LEVEL_TO_CAVE(level->bd_magic_wall_diamond_to);
+ cave->magic_stone_to = LEVEL_TO_CAVE(level->bd_magic_wall_rock_to);
+ cave->magic_mega_stone_to = LEVEL_TO_CAVE(level->bd_magic_wall_mega_rock_to);
+ cave->magic_nut_to = LEVEL_TO_CAVE(level->bd_magic_wall_nut_to);
+ cave->magic_nitro_pack_to = LEVEL_TO_CAVE(level->bd_magic_wall_nitro_pack_to);
+ cave->magic_flying_diamond_to = LEVEL_TO_CAVE(level->bd_magic_wall_flying_diamond_to);
+ cave->magic_flying_stone_to = LEVEL_TO_CAVE(level->bd_magic_wall_flying_rock_to);
+
+ cave->amoeba_timer_wait_for_hatching = level->bd_amoeba_wait_for_hatching;
+ cave->amoeba_timer_started_immediately= level->bd_amoeba_start_immediately;
+ cave->amoeba_2_explodes_by_amoeba = level->bd_amoeba_2_explode_by_amoeba;
+ cave->level_amoeba_threshold[0] = level->bd_amoeba_threshold_too_big;
+ cave->level_amoeba_time[0] = level->bd_amoeba_slow_growth_time;
+ cave->amoeba_growth_prob = level->bd_amoeba_slow_growth_rate * 10000;
+ cave->amoeba_fast_growth_prob = level->bd_amoeba_fast_growth_rate * 10000;
+ cave->level_amoeba_2_threshold[0] = level->bd_amoeba_2_threshold_too_big;
+ cave->level_amoeba_2_time[0] = level->bd_amoeba_2_slow_growth_time;
+ cave->amoeba_2_growth_prob = level->bd_amoeba_2_slow_growth_rate * 10000;
+ cave->amoeba_2_fast_growth_prob = level->bd_amoeba_2_fast_growth_rate * 10000;
+
+ cave->amoeba_too_big_effect = LEVEL_TO_CAVE(level->bd_amoeba_content_too_big);
+ cave->amoeba_enclosed_effect = LEVEL_TO_CAVE(level->bd_amoeba_content_enclosed);
+ cave->amoeba_2_too_big_effect = LEVEL_TO_CAVE(level->bd_amoeba_2_content_too_big);
+ cave->amoeba_2_enclosed_effect = LEVEL_TO_CAVE(level->bd_amoeba_2_content_enclosed);
+ cave->amoeba_2_explosion_effect = LEVEL_TO_CAVE(level->bd_amoeba_2_content_exploding);
+ cave->amoeba_2_looks_like = LEVEL_TO_CAVE(level->bd_amoeba_2_content_looks_like);
+
+ cave->slime_predictable = level->bd_slime_is_predictable;
+ cave->slime_correct_random = level->bd_slime_correct_random;
+ cave->level_slime_permeability[0] = level->bd_slime_permeability_rate * 10000;
+ cave->level_slime_permeability_c64[0] = level->bd_slime_permeability_bits_c64;
+ cave->level_slime_seed_c64[0] = level->bd_slime_random_seed_c64;
+ cave->level_rand[0] = level->bd_cave_random_seed_c64;
+ cave->slime_eats_1 = LEVEL_TO_CAVE(level->bd_slime_eats_element_1);
+ cave->slime_converts_1 = LEVEL_TO_CAVE(level->bd_slime_converts_to_element_1);
+ cave->slime_eats_2 = LEVEL_TO_CAVE(level->bd_slime_eats_element_2);
+ cave->slime_converts_2 = LEVEL_TO_CAVE(level->bd_slime_converts_to_element_2);
+ cave->slime_eats_3 = LEVEL_TO_CAVE(level->bd_slime_eats_element_3);
+ cave->slime_converts_3 = LEVEL_TO_CAVE(level->bd_slime_converts_to_element_3);
+
+ cave->acid_eats_this = LEVEL_TO_CAVE(level->bd_acid_eats_element);
+ cave->acid_spread_ratio = level->bd_acid_spread_rate * 10000;
+ cave->acid_turns_to = LEVEL_TO_CAVE(level->bd_acid_turns_to_element);
+
+ cave->biter_delay_frame = level->bd_biter_move_delay;
+ cave->biter_eat = LEVEL_TO_CAVE(level->bd_biter_eats_element);
+
+ cave->bladder_converts_by = LEVEL_TO_CAVE(level->bd_bladder_converts_by_element);
+
+ cave->expanding_wall_changed = level->bd_change_expanding_wall;
+
+ cave->replicators_active = level->bd_replicators_active;
+ cave->replicator_delay_frame = level->bd_replicator_create_delay;
+
+ cave->conveyor_belts_active = level->bd_conveyor_belts_active;
+ cave->conveyor_belts_direction_changed= level->bd_conveyor_belts_changed;
+
+ cave->water_does_not_flow_down = level->bd_water_cannot_flow_down;
+
+ cave->nut_turns_to_when_crushed = LEVEL_TO_CAVE(level->bd_nut_content);
+
+ cave->pneumatic_hammer_frame = level->bd_hammer_walls_break_delay;
+ cave->hammered_walls_reappear = level->bd_hammer_walls_reappear;
+ cave->hammered_wall_reappear_frame = level->bd_hammer_walls_reappear_delay;
+
+ cave->skeletons_needed_for_pot = level->bd_num_skeletons_needed_for_pot;
+ cave->skeletons_worth_diamonds = level->bd_skeleton_worth_num_diamonds;
+
+ cave->expanding_wall_looks_like = LEVEL_TO_CAVE(level->bd_expanding_wall_looks_like);
+ cave->dirt_looks_like = LEVEL_TO_CAVE(level->bd_sand_looks_like);
+
+ cave->creatures_backwards = level->bd_creatures_start_backwards;
+ cave->creatures_direction_auto_change_on_start = level->bd_creatures_turn_on_hatching;
+ cave->creatures_direction_auto_change_time = level->bd_creatures_auto_turn_delay;
+
+ cave->gravity = level->bd_gravity_direction;
+ cave->gravity_switch_active = level->bd_gravity_switch_active;
+ cave->gravity_change_time = level->bd_gravity_switch_delay;
+ cave->gravity_affects_all = level->bd_gravity_affects_all;
+
+ cave->stone_falling_effect = LEVEL_TO_CAVE(level->bd_rock_turns_to_on_falling);
+ cave->stone_bouncing_effect = LEVEL_TO_CAVE(level->bd_rock_turns_to_on_impact);
+ cave->diamond_falling_effect = LEVEL_TO_CAVE(level->bd_diamond_turns_to_on_falling);
+ cave->diamond_bouncing_effect = LEVEL_TO_CAVE(level->bd_diamond_turns_to_on_impact);
+
+ cave->firefly_explode_to = LEVEL_TO_CAVE(level->bd_firefly_explodes_to);
+ cave->alt_firefly_explode_to = LEVEL_TO_CAVE(level->bd_firefly_2_explodes_to);
+ cave->butterfly_explode_to = LEVEL_TO_CAVE(level->bd_butterfly_explodes_to);
+ cave->alt_butterfly_explode_to = LEVEL_TO_CAVE(level->bd_butterfly_2_explodes_to);
+ cave->stonefly_explode_to = LEVEL_TO_CAVE(level->bd_stonefly_explodes_to);
+ cave->dragonfly_explode_to = LEVEL_TO_CAVE(level->bd_dragonfly_explodes_to);
+
+ cave->diamond_birth_effect = LEVEL_TO_CAVE(level->bd_diamond_birth_turns_to);
+ cave->bomb_explosion_effect = LEVEL_TO_CAVE(level->bd_bomb_explosion_turns_to);
+ cave->nitro_explosion_effect = LEVEL_TO_CAVE(level->bd_nitro_explosion_turns_to);
+ cave->explosion_effect = LEVEL_TO_CAVE(level->bd_explosion_turns_to);
+
+ // level name
+ strncpy(cave->name, level->name, sizeof(GdString));
+ cave->name[sizeof(GdString) - 1] = '\0';
+
+ // playfield elements
+ for (x = 0; x < cave->w; x++)
+ for (y = 0; y < cave->h; y++)
+ cave->map[y][x] = LEVEL_TO_CAVE(level->field[x][y]);
+}
+
+static void CopyNativeLevel_BD_to_RND(struct LevelInfo *level)
+{
+ struct LevelInfo_BD *level_bd = level->native_bd_level;
+ GdCave *cave = level_bd->cave;
+ int bd_level_nr = level_bd->level_nr;
+ int x, y;
+
+ level->fieldx = MIN(cave->w, MAX_LEV_FIELDX);
+ level->fieldy = MIN(cave->h, MAX_LEV_FIELDY);
+
+ // level type
+ level->bd_intermission = cave->intermission;
+
+ // level settings
+ level->time = cave->level_time[bd_level_nr];
+ level->gems_needed = cave->level_diamonds[bd_level_nr];
+
+ // game timing
+ level->bd_scheduling_type = cave->scheduling;
+ level->bd_pal_timing = cave->pal_timing;
+ level->bd_cycle_delay_ms = cave->level_speed[bd_level_nr];
+ level->bd_cycle_delay_c64 = cave->level_ckdelay[bd_level_nr];
+ level->bd_hatching_delay_cycles = cave->level_hatching_delay_frame[bd_level_nr];
+ level->bd_hatching_delay_seconds = cave->level_hatching_delay_time[bd_level_nr];
+
+ // scores
+ level->score[SC_TIME_BONUS] = cave->level_timevalue[bd_level_nr];
+ level->score[SC_EMERALD] = cave->diamond_value;
+ level->score[SC_DIAMOND_EXTRA] = cave->extra_diamond_value;
+
+ // compatibility settings
+ level->bd_line_shifting_borders = cave->lineshift;
+ level->bd_scan_first_and_last_row = cave->border_scan_first_and_last;
+ level->bd_short_explosions = cave->short_explosions;
+
+ // player properties
+ level->bd_diagonal_movements = cave->diagonal_movements;
+ level->bd_topmost_player_active = cave->active_is_first_found;
+ level->bd_pushing_prob = cave->pushing_stone_prob / 10000;
+ level->bd_pushing_prob_with_sweet = cave->pushing_stone_prob_sweet / 10000;
+ level->bd_push_mega_rock_with_sweet = cave->mega_stones_pushable_with_sweet;
+ level->bd_snap_element = CAVE_TO_LEVEL(cave->snap_element);
+
+ // element properties
+ level->bd_clock_extra_time = cave->level_bonus_time[bd_level_nr];
+ level->bd_voodoo_collects_diamonds = cave->voodoo_collects_diamonds;
+ level->bd_voodoo_hurt_kills_player = cave->voodoo_any_hurt_kills_player;
+ level->bd_voodoo_dies_by_rock = cave->voodoo_dies_by_stone;
+ level->bd_voodoo_vanish_by_explosion = cave->voodoo_disappear_in_explosion;
+ level->bd_voodoo_penalty_time = cave->level_penalty_time[bd_level_nr];
+ level->time_magic_wall = cave->level_magic_wall_time[bd_level_nr];
+ level->bd_magic_wall_wait_hatching = cave->magic_timer_wait_for_hatching;
+ level->bd_magic_wall_stops_amoeba = cave->magic_wall_stops_amoeba;
+
+ level->bd_magic_wall_diamond_to = CAVE_TO_LEVEL(cave->magic_diamond_to);
+ level->bd_magic_wall_rock_to = CAVE_TO_LEVEL(cave->magic_stone_to);
+ level->bd_magic_wall_mega_rock_to = CAVE_TO_LEVEL(cave->magic_mega_stone_to);
+ level->bd_magic_wall_nut_to = CAVE_TO_LEVEL(cave->magic_nut_to);
+ level->bd_magic_wall_nitro_pack_to = CAVE_TO_LEVEL(cave->magic_nitro_pack_to);
+ level->bd_magic_wall_flying_diamond_to= CAVE_TO_LEVEL(cave->magic_flying_diamond_to);
+ level->bd_magic_wall_flying_rock_to = CAVE_TO_LEVEL(cave->magic_flying_stone_to);
+
+ level->bd_amoeba_wait_for_hatching = cave->amoeba_timer_wait_for_hatching;
+ level->bd_amoeba_start_immediately = cave->amoeba_timer_started_immediately;
+ level->bd_amoeba_2_explode_by_amoeba = cave->amoeba_2_explodes_by_amoeba;
+ level->bd_amoeba_threshold_too_big = cave->level_amoeba_threshold[bd_level_nr];
+ level->bd_amoeba_slow_growth_time = cave->level_amoeba_time[bd_level_nr];
+ level->bd_amoeba_slow_growth_rate = cave->amoeba_growth_prob / 10000;
+ level->bd_amoeba_fast_growth_rate = cave->amoeba_fast_growth_prob / 10000;
+ level->bd_amoeba_2_threshold_too_big = cave->level_amoeba_2_threshold[bd_level_nr];
+ level->bd_amoeba_2_slow_growth_time = cave->level_amoeba_2_time[bd_level_nr];
+ level->bd_amoeba_2_slow_growth_rate = cave->amoeba_2_growth_prob / 10000;
+ level->bd_amoeba_2_fast_growth_rate = cave->amoeba_2_fast_growth_prob / 10000;
+
+ level->bd_amoeba_content_too_big = CAVE_TO_LEVEL(cave->amoeba_too_big_effect);
+ level->bd_amoeba_content_enclosed = CAVE_TO_LEVEL(cave->amoeba_enclosed_effect);
+ level->bd_amoeba_2_content_too_big = CAVE_TO_LEVEL(cave->amoeba_2_too_big_effect);
+ level->bd_amoeba_2_content_enclosed = CAVE_TO_LEVEL(cave->amoeba_2_enclosed_effect);
+ level->bd_amoeba_2_content_exploding = CAVE_TO_LEVEL(cave->amoeba_2_explosion_effect);
+ level->bd_amoeba_2_content_looks_like = CAVE_TO_LEVEL(cave->amoeba_2_looks_like);
+
+ level->bd_slime_is_predictable = cave->slime_predictable;
+ level->bd_slime_correct_random = cave->slime_correct_random;
+ level->bd_slime_permeability_rate = cave->level_slime_permeability[bd_level_nr] / 10000;
+ level->bd_slime_permeability_bits_c64 = cave->level_slime_permeability_c64[bd_level_nr];
+ level->bd_slime_random_seed_c64 = cave->level_slime_seed_c64[bd_level_nr];
+ level->bd_cave_random_seed_c64 = cave->level_rand[bd_level_nr];
+ level->bd_slime_eats_element_1 = CAVE_TO_LEVEL(cave->slime_eats_1);
+ level->bd_slime_converts_to_element_1 = CAVE_TO_LEVEL(cave->slime_converts_1);
+ level->bd_slime_eats_element_2 = CAVE_TO_LEVEL(cave->slime_eats_2);
+ level->bd_slime_converts_to_element_2 = CAVE_TO_LEVEL(cave->slime_converts_2);
+ level->bd_slime_eats_element_3 = CAVE_TO_LEVEL(cave->slime_eats_3);
+ level->bd_slime_converts_to_element_3 = CAVE_TO_LEVEL(cave->slime_converts_3);
+
+ level->bd_acid_eats_element = CAVE_TO_LEVEL(cave->acid_eats_this);
+ level->bd_acid_spread_rate = cave->acid_spread_ratio / 10000;
+ level->bd_acid_turns_to_element = CAVE_TO_LEVEL(cave->acid_turns_to);
+
+ level->bd_biter_move_delay = cave->biter_delay_frame;
+ level->bd_biter_eats_element = CAVE_TO_LEVEL(cave->biter_eat);
+
+ level->bd_bladder_converts_by_element = CAVE_TO_LEVEL(cave->bladder_converts_by);
+
+ level->bd_change_expanding_wall = cave->expanding_wall_changed;
+
+ level->bd_replicators_active = cave->replicators_active;
+ level->bd_replicator_create_delay = cave->replicator_delay_frame;
+
+ level->bd_conveyor_belts_active = cave->conveyor_belts_active;
+ level->bd_conveyor_belts_changed = cave->conveyor_belts_direction_changed;
+
+ level->bd_water_cannot_flow_down = cave->water_does_not_flow_down;
+
+ level->bd_nut_content = CAVE_TO_LEVEL(cave->nut_turns_to_when_crushed);
+
+ level->bd_hammer_walls_break_delay = cave->pneumatic_hammer_frame;
+ level->bd_hammer_walls_reappear = cave->hammered_walls_reappear;
+ level->bd_hammer_walls_reappear_delay = cave->hammered_wall_reappear_frame;
+
+ level->bd_num_skeletons_needed_for_pot= cave->skeletons_needed_for_pot;
+ level->bd_skeleton_worth_num_diamonds = cave->skeletons_worth_diamonds;
+
+ level->bd_expanding_wall_looks_like = CAVE_TO_LEVEL(cave->expanding_wall_looks_like);
+ level->bd_sand_looks_like = CAVE_TO_LEVEL(cave->dirt_looks_like);
+
+ level->bd_creatures_start_backwards = cave->creatures_backwards;
+ level->bd_creatures_turn_on_hatching = cave->creatures_direction_auto_change_on_start;
+ level->bd_creatures_auto_turn_delay = cave->creatures_direction_auto_change_time;
+
+ level->bd_gravity_direction = cave->gravity;
+ level->bd_gravity_switch_active = cave->gravity_switch_active;
+ level->bd_gravity_switch_delay = cave->gravity_change_time;
+ level->bd_gravity_affects_all = cave->gravity_affects_all;
+
+ level->bd_rock_turns_to_on_falling = CAVE_TO_LEVEL(cave->stone_falling_effect);
+ level->bd_rock_turns_to_on_impact = CAVE_TO_LEVEL(cave->stone_bouncing_effect);
+ level->bd_diamond_turns_to_on_falling = CAVE_TO_LEVEL(cave->diamond_falling_effect);
+ level->bd_diamond_turns_to_on_impact = CAVE_TO_LEVEL(cave->diamond_bouncing_effect);
+
+ level->bd_firefly_explodes_to = CAVE_TO_LEVEL(cave->firefly_explode_to);
+ level->bd_firefly_2_explodes_to = CAVE_TO_LEVEL(cave->alt_firefly_explode_to);
+ level->bd_butterfly_explodes_to = CAVE_TO_LEVEL(cave->butterfly_explode_to);
+ level->bd_butterfly_2_explodes_to = CAVE_TO_LEVEL(cave->alt_butterfly_explode_to);
+ level->bd_stonefly_explodes_to = CAVE_TO_LEVEL(cave->stonefly_explode_to);
+ level->bd_dragonfly_explodes_to = CAVE_TO_LEVEL(cave->dragonfly_explode_to);
+
+ level->bd_diamond_birth_turns_to = CAVE_TO_LEVEL(cave->diamond_birth_effect);
+ level->bd_bomb_explosion_turns_to = CAVE_TO_LEVEL(cave->bomb_explosion_effect);
+ level->bd_nitro_explosion_turns_to = CAVE_TO_LEVEL(cave->nitro_explosion_effect);
+ level->bd_explosion_turns_to = CAVE_TO_LEVEL(cave->explosion_effect);
+
+ // level name
+ char *cave_name = getStringPrint("%s / %d", cave->name, bd_level_nr + 1);
+
+ strncpy(level->name, cave_name, MAX_LEVEL_NAME_LEN);
+ level->name[MAX_LEVEL_NAME_LEN] = '\0';
+
+ // playfield elements
+ for (x = 0; x < level->fieldx; x++)
+ for (y = 0; y < level->fieldy; y++)
+ level->field[x][y] = CAVE_TO_LEVEL(cave->map[y][x]);
+
+ checked_free(cave_name);
+}
+
+static void setTapeInfoToDefaults(void);
+
+static void CopyNativeTape_BD_to_RND(struct LevelInfo *level)
+{
+ struct LevelInfo_BD *level_bd = level->native_bd_level;
+ GdCave *cave = level_bd->cave;
+ GdReplay *replay = level_bd->replay;
+ int i;
+
+ if (replay == NULL)
+ return;
+
+ // always start with reliable default values
+ setTapeInfoToDefaults();
+
+ tape.level_nr = level_nr; // (currently not used)
+ tape.random_seed = replay->seed;
+
+ TapeSetDateFromIsoDateString(replay->date);
+
+ tape.counter = 0;
+ tape.pos[tape.counter].delay = 0;
+
+ tape.bd_replay = TRUE;
+
+ // all time calculations only used to display approximate tape time
+ int cave_speed = cave->speed;
+ int milliseconds_game = 0;
+ int milliseconds_elapsed = 20;
+
+ for (i = 0; i < replay->movements->len; i++)
+ {
+ int replay_action = replay->movements->data[i];
+ int tape_action = map_action_BD_to_RND(replay_action);
+ byte action[MAX_TAPE_ACTIONS] = { tape_action };
+ boolean success = 0;
+
+ while (1)
+ {
+ success = TapeAddAction(action);
+
+ milliseconds_game += milliseconds_elapsed;
+
+ if (milliseconds_game >= cave_speed)
+ {
+ milliseconds_game -= cave_speed;
- // the size of some chunks cannot be checked before reading other
- // chunks first (like "HEAD" and "BODY") that contain some header
- // information, so check them here
- if (chunk_size_expected != chunk_size)
- {
- Error(ERR_WARN, "wrong size (%d) of chunk '%s' in level file '%s'",
- chunk_size, chunk_name, filename);
- }
+ break;
}
}
+
+ tape.counter++;
+ tape.pos[tape.counter].delay = 0;
+ tape.pos[tape.counter].action[0] = 0;
+
+ if (!success)
+ {
+ Warn("BD replay truncated: size exceeds maximum tape size %d", MAX_TAPE_LEN);
+
+ break;
+ }
}
- closeFile(file);
+ TapeHaltRecording();
}
cav->lenses_time = level->lenses_time;
cav->magnify_time = level->magnify_time;
+ cav->wind_time = 9999;
cav->wind_direction =
map_direction_RND_to_EM(level->wind_direction_initial);
// initialize player positions and delete players from the playfield
for (y = 0; y < cav->height; y++) for (x = 0; x < cav->width; x++)
{
- if (ELEM_IS_PLAYER(level->field[x][y]))
+ if (IS_PLAYER_ELEMENT(level->field[x][y]))
{
int player_nr = GET_PLAYER_NR(level->field[x][y]);
if (jx != -1 && jy != -1)
level->field[jx][jy] = EL_PLAYER_1 + nr;
}
+
+ // time score is counted for each 10 seconds left in Emerald Mine levels
+ level->time_score_base = 10;
}
{
num_invalid_elements++;
- Error(ERR_DEBUG, "invalid element %d at position %d, %d",
+ Debug("level:native:SP", "invalid element %d at position %d, %d",
element_old, x, y);
}
}
if (num_invalid_elements > 0)
- Error(ERR_WARN, "found %d invalid elements%s", num_invalid_elements,
- (!options.debug ? " (use '--debug' for more details)" : ""));
+ Warn("found %d invalid elements%s", num_invalid_elements,
+ (!options.debug ? " (use '--debug' for more details)" : ""));
for (i = 0; i < MAX_PLAYERS; i++)
level->initial_player_gravity[i] =
if (port_x < 0 || port_x >= level->fieldx ||
port_y < 0 || port_y >= level->fieldy)
{
- Error(ERR_WARN, "special port position (%d, %d) out of bounds",
- port_x, port_y);
+ Warn("special port position (%d, %d) out of bounds", port_x, port_y);
continue;
}
if (port_element < EL_SP_GRAVITY_PORT_RIGHT ||
port_element > EL_SP_GRAVITY_PORT_UP)
{
- Error(ERR_WARN, "no special port at position (%d, %d)", port_x, port_y);
+ Warn("no special port at position (%d, %d)", port_x, port_y);
continue;
}
level->time_wheel = 0;
level->amoeba_content = EL_EMPTY;
-#if 1
- // original Supaplex does not use score values -- use default values
-#else
+ // original Supaplex does not use score values -- rate by playing time
for (i = 0; i < LEVEL_SCORE_ELEMENTS; i++)
level->score[i] = 0;
-#endif
+
+ level->rate_time_over_score = TRUE;
// there are no yamyams in supaplex levels
for (i = 0; i < level->num_yamyam_contents; i++)
if (demo->length + demo_entries >= SP_MAX_TAPE_LEN)
{
- Error(ERR_WARN, "tape truncated: size exceeds maximum SP demo size %d",
- SP_MAX_TAPE_LEN);
+ Warn("tape truncated: size exceeds maximum SP demo size %d",
+ SP_MAX_TAPE_LEN);
break;
}
demo->is_available = TRUE;
}
-static void setTapeInfoToDefaults(void);
-
static void CopyNativeTape_SP_to_RND(struct LevelInfo *level)
{
struct LevelInfo_SP *level_sp = level->native_sp_level;
if (!success)
{
- Error(ERR_WARN, "SP demo truncated: size exceeds maximum tape size %d",
- MAX_TAPE_LEN);
+ Warn("SP demo truncated: size exceeds maximum tape size %d",
+ MAX_TAPE_LEN);
break;
}
static void CopyNativeLevel_RND_to_MM(struct LevelInfo *level)
{
struct LevelInfo_MM *level_mm = level->native_mm_level;
- int x, y;
+ int i, x, y;
level_mm->fieldx = MIN(level->fieldx, MM_MAX_PLAYFIELD_WIDTH);
level_mm->fieldy = MIN(level->fieldy, MM_MAX_PLAYFIELD_HEIGHT);
level_mm->kettles_needed = level->gems_needed;
level_mm->auto_count_kettles = level->auto_count_gems;
- level_mm->laser_red = level->mm_laser_red;
- level_mm->laser_green = level->mm_laser_green;
- level_mm->laser_blue = level->mm_laser_blue;
+ level_mm->mm_laser_red = level->mm_laser_red;
+ level_mm->mm_laser_green = level->mm_laser_green;
+ level_mm->mm_laser_blue = level->mm_laser_blue;
+
+ level_mm->df_laser_red = level->df_laser_red;
+ level_mm->df_laser_green = level->df_laser_green;
+ level_mm->df_laser_blue = level->df_laser_blue;
strcpy(level_mm->name, level->name);
strcpy(level_mm->author, level->author);
level_mm->time_ball = level->mm_time_ball;
level_mm->time_block = level->mm_time_block;
+ level_mm->num_ball_contents = level->num_mm_ball_contents;
+ level_mm->ball_choice_mode = level->mm_ball_choice_mode;
+ level_mm->rotate_ball_content = level->rotate_mm_ball_content;
+ level_mm->explode_ball = level->explode_mm_ball;
+
+ for (i = 0; i < level->num_mm_ball_contents; i++)
+ level_mm->ball_content[i] =
+ map_element_RND_to_MM(level->mm_ball_content[i]);
+
for (x = 0; x < level->fieldx; x++)
for (y = 0; y < level->fieldy; y++)
Ur[x][y] =
static void CopyNativeLevel_MM_to_RND(struct LevelInfo *level)
{
struct LevelInfo_MM *level_mm = level->native_mm_level;
- int x, y;
+ int i, x, y;
level->fieldx = MIN(level_mm->fieldx, MAX_LEV_FIELDX);
level->fieldy = MIN(level_mm->fieldy, MAX_LEV_FIELDY);
level->gems_needed = level_mm->kettles_needed;
level->auto_count_gems = level_mm->auto_count_kettles;
- level->mm_laser_red = level_mm->laser_red;
- level->mm_laser_green = level_mm->laser_green;
- level->mm_laser_blue = level_mm->laser_blue;
+ level->mm_laser_red = level_mm->mm_laser_red;
+ level->mm_laser_green = level_mm->mm_laser_green;
+ level->mm_laser_blue = level_mm->mm_laser_blue;
+
+ level->df_laser_red = level_mm->df_laser_red;
+ level->df_laser_green = level_mm->df_laser_green;
+ level->df_laser_blue = level_mm->df_laser_blue;
strcpy(level->name, level_mm->name);
level->mm_time_ball = level_mm->time_ball;
level->mm_time_block = level_mm->time_block;
+ level->num_mm_ball_contents = level_mm->num_ball_contents;
+ level->mm_ball_choice_mode = level_mm->ball_choice_mode;
+ level->rotate_mm_ball_content = level_mm->rotate_ball_content;
+ level->explode_mm_ball = level_mm->explode_ball;
+
+ for (i = 0; i < level->num_mm_ball_contents; i++)
+ level->mm_ball_content[i] =
+ map_element_MM_to_RND(level_mm->ball_content[i]);
+
for (x = 0; x < level->fieldx; x++)
for (y = 0; y < level->fieldy; y++)
level->field[x][y] = map_element_MM_to_RND(level_mm->field[x][y]);
break;
case 0x13f5:
- element = EL_YAMYAM;
+ element = EL_YAMYAM_UP;
break;
case 0x1425:
element = EL_CHAR_PARENRIGHT;
break;
- case 0x1615: // (blue steel)
+ case 0x1615: // (blue steel)
+ element = EL_STEEL_CHAR_A;
+ break;
+
+ case 0x1616: // (blue steel)
+ element = EL_STEEL_CHAR_B;
+ break;
+
+ case 0x1617: // (blue steel)
+ element = EL_STEEL_CHAR_C;
+ break;
+
+ case 0x1618: // (blue steel)
+ element = EL_STEEL_CHAR_D;
+ break;
+
+ case 0x1619: // (blue steel)
+ element = EL_STEEL_CHAR_E;
+ break;
+
+ case 0x161a: // (blue steel)
+ element = EL_STEEL_CHAR_F;
+ break;
+
+ case 0x161b: // (blue steel)
+ element = EL_STEEL_CHAR_G;
+ break;
+
+ case 0x161c: // (blue steel)
+ element = EL_STEEL_CHAR_H;
+ break;
+
+ case 0x161d: // (blue steel)
+ element = EL_STEEL_CHAR_I;
+ break;
+
+ case 0x161e: // (blue steel)
+ element = EL_STEEL_CHAR_J;
+ break;
+
+ case 0x161f: // (blue steel)
+ element = EL_STEEL_CHAR_K;
+ break;
+
+ case 0x1620: // (blue steel)
+ element = EL_STEEL_CHAR_L;
+ break;
+
+ case 0x1621: // (blue steel)
+ element = EL_STEEL_CHAR_M;
+ break;
+
+ case 0x1622: // (blue steel)
+ element = EL_STEEL_CHAR_N;
+ break;
+
+ case 0x1623: // (blue steel)
+ element = EL_STEEL_CHAR_O;
+ break;
+
+ case 0x1624: // (blue steel)
+ element = EL_STEEL_CHAR_P;
+ break;
+
+ case 0x1625: // (blue steel)
+ element = EL_STEEL_CHAR_Q;
+ break;
+
+ case 0x1626: // (blue steel)
+ element = EL_STEEL_CHAR_R;
+ break;
+
+ case 0x1627: // (blue steel)
+ element = EL_STEEL_CHAR_S;
+ break;
+
+ case 0x1628: // (blue steel)
+ element = EL_STEEL_CHAR_T;
+ break;
+
+ case 0x1629: // (blue steel)
+ element = EL_STEEL_CHAR_U;
+ break;
+
+ case 0x162a: // (blue steel)
+ element = EL_STEEL_CHAR_V;
+ break;
+
+ case 0x162b: // (blue steel)
+ element = EL_STEEL_CHAR_W;
+ break;
+
+ case 0x162c: // (blue steel)
+ element = EL_STEEL_CHAR_X;
+ break;
+
+ case 0x162d: // (blue steel)
+ element = EL_STEEL_CHAR_Y;
+ break;
+
+ case 0x162e: // (blue steel)
+ element = EL_STEEL_CHAR_Z;
+ break;
+
+ case 0x162f: // (blue steel)
+ element = EL_STEEL_CHAR_AUMLAUT;
+ break;
+
+ case 0x1630: // (blue steel)
+ element = EL_STEEL_CHAR_OUMLAUT;
+ break;
+
+ case 0x1631: // (blue steel)
+ element = EL_STEEL_CHAR_UUMLAUT;
+ break;
+
+ case 0x1632: // (blue steel)
+ element = EL_STEEL_CHAR_0;
+ break;
+
+ case 0x1633: // (blue steel)
+ element = EL_STEEL_CHAR_1;
+ break;
+
+ case 0x1634: // (blue steel)
+ element = EL_STEEL_CHAR_2;
+ break;
+
+ case 0x1635: // (blue steel)
+ element = EL_STEEL_CHAR_3;
+ break;
+
+ case 0x1636: // (blue steel)
+ element = EL_STEEL_CHAR_4;
+ break;
+
+ case 0x1637: // (blue steel)
+ element = EL_STEEL_CHAR_5;
+ break;
+
+ case 0x1638: // (blue steel)
+ element = EL_STEEL_CHAR_6;
+ break;
+
+ case 0x1639: // (blue steel)
+ element = EL_STEEL_CHAR_7;
+ break;
+
+ case 0x163a: // (blue steel)
+ element = EL_STEEL_CHAR_8;
+ break;
+
+ case 0x163b: // (blue steel)
+ element = EL_STEEL_CHAR_9;
+ break;
+
+ case 0x163c: // (blue steel)
+ element = EL_STEEL_CHAR_PERIOD;
+ break;
+
+ case 0x163d: // (blue steel)
+ element = EL_STEEL_CHAR_EXCLAM;
+ break;
+
+ case 0x163e: // (blue steel)
+ element = EL_STEEL_CHAR_COLON;
+ break;
+
+ case 0x163f: // (blue steel)
+ element = EL_STEEL_CHAR_LESS;
+ break;
+
+ case 0x1640: // (blue steel)
+ element = EL_STEEL_CHAR_GREATER;
+ break;
+
+ case 0x1641: // (blue steel)
+ element = EL_STEEL_CHAR_QUESTION;
+ break;
+
+ case 0x1642: // (blue steel)
+ element = EL_STEEL_CHAR_COPYRIGHT;
+ break;
+
+ case 0x1643: // (blue steel)
+ element = EL_STEEL_CHAR_UP;
+ break;
+
+ case 0x1644: // (blue steel)
+ element = EL_STEEL_CHAR_DOWN;
+ break;
+
+ case 0x1645: // (blue steel)
+ element = EL_STEEL_CHAR_BUTTON;
+ break;
+
+ case 0x1646: // (blue steel)
+ element = EL_STEEL_CHAR_PLUS;
+ break;
+
+ case 0x1647: // (blue steel)
+ element = EL_STEEL_CHAR_MINUS;
+ break;
+
+ case 0x1648: // (blue steel)
+ element = EL_STEEL_CHAR_APOSTROPHE;
+ break;
+
+ case 0x1649: // (blue steel)
+ element = EL_STEEL_CHAR_PARENLEFT;
+ break;
+
+ case 0x164a: // (blue steel)
+ element = EL_STEEL_CHAR_PARENRIGHT;
+ break;
+
+ case 0x164b: // (green steel)
element = EL_STEEL_CHAR_A;
break;
- case 0x1616: // (blue steel)
+ case 0x164c: // (green steel)
element = EL_STEEL_CHAR_B;
break;
- case 0x1617: // (blue steel)
+ case 0x164d: // (green steel)
element = EL_STEEL_CHAR_C;
break;
- case 0x1618: // (blue steel)
+ case 0x164e: // (green steel)
element = EL_STEEL_CHAR_D;
break;
- case 0x1619: // (blue steel)
+ case 0x164f: // (green steel)
element = EL_STEEL_CHAR_E;
break;
- case 0x161a: // (blue steel)
+ case 0x1650: // (green steel)
element = EL_STEEL_CHAR_F;
break;
- case 0x161b: // (blue steel)
+ case 0x1651: // (green steel)
element = EL_STEEL_CHAR_G;
break;
- case 0x161c: // (blue steel)
+ case 0x1652: // (green steel)
element = EL_STEEL_CHAR_H;
break;
- case 0x161d: // (blue steel)
+ case 0x1653: // (green steel)
element = EL_STEEL_CHAR_I;
break;
- case 0x161e: // (blue steel)
+ case 0x1654: // (green steel)
element = EL_STEEL_CHAR_J;
break;
- case 0x161f: // (blue steel)
+ case 0x1655: // (green steel)
element = EL_STEEL_CHAR_K;
break;
- case 0x1620: // (blue steel)
+ case 0x1656: // (green steel)
element = EL_STEEL_CHAR_L;
break;
- case 0x1621: // (blue steel)
+ case 0x1657: // (green steel)
element = EL_STEEL_CHAR_M;
break;
- case 0x1622: // (blue steel)
+ case 0x1658: // (green steel)
element = EL_STEEL_CHAR_N;
break;
- case 0x1623: // (blue steel)
+ case 0x1659: // (green steel)
element = EL_STEEL_CHAR_O;
break;
- case 0x1624: // (blue steel)
+ case 0x165a: // (green steel)
element = EL_STEEL_CHAR_P;
break;
- case 0x1625: // (blue steel)
+ case 0x165b: // (green steel)
element = EL_STEEL_CHAR_Q;
break;
- case 0x1626: // (blue steel)
+ case 0x165c: // (green steel)
element = EL_STEEL_CHAR_R;
break;
- case 0x1627: // (blue steel)
+ case 0x165d: // (green steel)
element = EL_STEEL_CHAR_S;
break;
- case 0x1628: // (blue steel)
+ case 0x165e: // (green steel)
element = EL_STEEL_CHAR_T;
break;
- case 0x1629: // (blue steel)
+ case 0x165f: // (green steel)
element = EL_STEEL_CHAR_U;
break;
- case 0x162a: // (blue steel)
+ case 0x1660: // (green steel)
element = EL_STEEL_CHAR_V;
break;
- case 0x162b: // (blue steel)
+ case 0x1661: // (green steel)
element = EL_STEEL_CHAR_W;
break;
- case 0x162c: // (blue steel)
+ case 0x1662: // (green steel)
element = EL_STEEL_CHAR_X;
break;
- case 0x162d: // (blue steel)
+ case 0x1663: // (green steel)
element = EL_STEEL_CHAR_Y;
break;
- case 0x162e: // (blue steel)
+ case 0x1664: // (green steel)
element = EL_STEEL_CHAR_Z;
break;
- case 0x162f: // (blue steel)
+ case 0x1665: // (green steel)
element = EL_STEEL_CHAR_AUMLAUT;
break;
- case 0x1630: // (blue steel)
+ case 0x1666: // (green steel)
element = EL_STEEL_CHAR_OUMLAUT;
break;
- case 0x1631: // (blue steel)
+ case 0x1667: // (green steel)
element = EL_STEEL_CHAR_UUMLAUT;
break;
- case 0x1632: // (blue steel)
+ case 0x1668: // (green steel)
element = EL_STEEL_CHAR_0;
break;
- case 0x1633: // (blue steel)
+ case 0x1669: // (green steel)
element = EL_STEEL_CHAR_1;
break;
- case 0x1634: // (blue steel)
+ case 0x166a: // (green steel)
element = EL_STEEL_CHAR_2;
break;
- case 0x1635: // (blue steel)
+ case 0x166b: // (green steel)
element = EL_STEEL_CHAR_3;
break;
- case 0x1636: // (blue steel)
+ case 0x166c: // (green steel)
element = EL_STEEL_CHAR_4;
break;
- case 0x1637: // (blue steel)
+ case 0x166d: // (green steel)
element = EL_STEEL_CHAR_5;
break;
- case 0x1638: // (blue steel)
+ case 0x166e: // (green steel)
element = EL_STEEL_CHAR_6;
break;
- case 0x1639: // (blue steel)
+ case 0x166f: // (green steel)
element = EL_STEEL_CHAR_7;
break;
- case 0x163a: // (blue steel)
+ case 0x1670: // (green steel)
element = EL_STEEL_CHAR_8;
break;
- case 0x163b: // (blue steel)
+ case 0x1671: // (green steel)
element = EL_STEEL_CHAR_9;
break;
- case 0x163c: // (blue steel)
+ case 0x1672: // (green steel)
element = EL_STEEL_CHAR_PERIOD;
break;
- case 0x163d: // (blue steel)
+ case 0x1673: // (green steel)
element = EL_STEEL_CHAR_EXCLAM;
break;
- case 0x163e: // (blue steel)
+ case 0x1674: // (green steel)
element = EL_STEEL_CHAR_COLON;
break;
- case 0x163f: // (blue steel)
+ case 0x1675: // (green steel)
element = EL_STEEL_CHAR_LESS;
break;
- case 0x1640: // (blue steel)
+ case 0x1676: // (green steel)
element = EL_STEEL_CHAR_GREATER;
break;
- case 0x1641: // (blue steel)
+ case 0x1677: // (green steel)
element = EL_STEEL_CHAR_QUESTION;
break;
- case 0x1642: // (blue steel)
+ case 0x1678: // (green steel)
element = EL_STEEL_CHAR_COPYRIGHT;
break;
- case 0x1643: // (blue steel)
+ case 0x1679: // (green steel)
element = EL_STEEL_CHAR_UP;
break;
- case 0x1644: // (blue steel)
+ case 0x167a: // (green steel)
element = EL_STEEL_CHAR_DOWN;
break;
- case 0x1645: // (blue steel)
+ case 0x167b: // (green steel)
element = EL_STEEL_CHAR_BUTTON;
break;
- case 0x1646: // (blue steel)
+ case 0x167c: // (green steel)
element = EL_STEEL_CHAR_PLUS;
break;
- case 0x1647: // (blue steel)
+ case 0x167d: // (green steel)
element = EL_STEEL_CHAR_MINUS;
break;
- case 0x1648: // (blue steel)
+ case 0x167e: // (green steel)
element = EL_STEEL_CHAR_APOSTROPHE;
break;
- case 0x1649: // (blue steel)
+ case 0x167f: // (green steel)
element = EL_STEEL_CHAR_PARENLEFT;
break;
- case 0x164a: // (blue steel)
+ case 0x1680: // (green steel)
element = EL_STEEL_CHAR_PARENRIGHT;
break;
- case 0x164b: // (green steel)
- element = EL_STEEL_CHAR_A;
+ case 0x1681: // gate (red)
+ element = EL_EM_GATE_1;
break;
- case 0x164c: // (green steel)
- element = EL_STEEL_CHAR_B;
+ case 0x1682: // secret gate (red)
+ element = EL_EM_GATE_1_GRAY;
break;
- case 0x164d: // (green steel)
- element = EL_STEEL_CHAR_C;
+ case 0x1683: // gate (yellow)
+ element = EL_EM_GATE_2;
break;
- case 0x164e: // (green steel)
- element = EL_STEEL_CHAR_D;
+ case 0x1684: // secret gate (yellow)
+ element = EL_EM_GATE_2_GRAY;
break;
- case 0x164f: // (green steel)
- element = EL_STEEL_CHAR_E;
+ case 0x1685: // gate (blue)
+ element = EL_EM_GATE_4;
break;
- case 0x1650: // (green steel)
- element = EL_STEEL_CHAR_F;
+ case 0x1686: // secret gate (blue)
+ element = EL_EM_GATE_4_GRAY;
break;
- case 0x1651: // (green steel)
- element = EL_STEEL_CHAR_G;
+ case 0x1687: // gate (green)
+ element = EL_EM_GATE_3;
break;
- case 0x1652: // (green steel)
- element = EL_STEEL_CHAR_H;
+ case 0x1688: // secret gate (green)
+ element = EL_EM_GATE_3_GRAY;
break;
- case 0x1653: // (green steel)
- element = EL_STEEL_CHAR_I;
+ case 0x1689: // gate (white)
+ element = EL_DC_GATE_WHITE;
break;
- case 0x1654: // (green steel)
- element = EL_STEEL_CHAR_J;
+ case 0x168a: // secret gate (white)
+ element = EL_DC_GATE_WHITE_GRAY;
break;
- case 0x1655: // (green steel)
- element = EL_STEEL_CHAR_K;
+ case 0x168b: // secret gate (no key)
+ element = EL_DC_GATE_FAKE_GRAY;
break;
- case 0x1656: // (green steel)
- element = EL_STEEL_CHAR_L;
+ case 0x168c:
+ element = EL_ROBOT_WHEEL;
break;
- case 0x1657: // (green steel)
- element = EL_STEEL_CHAR_M;
+ case 0x168d:
+ element = EL_DC_TIMEGATE_SWITCH;
break;
- case 0x1658: // (green steel)
- element = EL_STEEL_CHAR_N;
+ case 0x168e:
+ element = EL_ACID_POOL_BOTTOM;
break;
- case 0x1659: // (green steel)
- element = EL_STEEL_CHAR_O;
+ case 0x168f:
+ element = EL_ACID_POOL_TOPLEFT;
break;
- case 0x165a: // (green steel)
- element = EL_STEEL_CHAR_P;
+ case 0x1690:
+ element = EL_ACID_POOL_TOPRIGHT;
break;
- case 0x165b: // (green steel)
- element = EL_STEEL_CHAR_Q;
+ case 0x1691:
+ element = EL_ACID_POOL_BOTTOMLEFT;
break;
- case 0x165c: // (green steel)
- element = EL_STEEL_CHAR_R;
+ case 0x1692:
+ element = EL_ACID_POOL_BOTTOMRIGHT;
break;
- case 0x165d: // (green steel)
- element = EL_STEEL_CHAR_S;
+ case 0x1693:
+ element = EL_STEELWALL;
break;
- case 0x165e: // (green steel)
- element = EL_STEEL_CHAR_T;
+ case 0x1694:
+ element = EL_STEELWALL_SLIPPERY;
break;
- case 0x165f: // (green steel)
- element = EL_STEEL_CHAR_U;
+ case 0x1695: // steel wall (not round)
+ element = EL_STEELWALL;
break;
- case 0x1660: // (green steel)
- element = EL_STEEL_CHAR_V;
+ case 0x1696: // steel wall (left)
+ element = EL_DC_STEELWALL_1_LEFT;
break;
- case 0x1661: // (green steel)
- element = EL_STEEL_CHAR_W;
+ case 0x1697: // steel wall (bottom)
+ element = EL_DC_STEELWALL_1_BOTTOM;
break;
- case 0x1662: // (green steel)
- element = EL_STEEL_CHAR_X;
+ case 0x1698: // steel wall (right)
+ element = EL_DC_STEELWALL_1_RIGHT;
+ break;
+
+ case 0x1699: // steel wall (top)
+ element = EL_DC_STEELWALL_1_TOP;
+ break;
+
+ case 0x169a: // steel wall (left/bottom)
+ element = EL_DC_STEELWALL_1_BOTTOMLEFT;
+ break;
+
+ case 0x169b: // steel wall (right/bottom)
+ element = EL_DC_STEELWALL_1_BOTTOMRIGHT;
+ break;
+
+ case 0x169c: // steel wall (right/top)
+ element = EL_DC_STEELWALL_1_TOPRIGHT;
+ break;
+
+ case 0x169d: // steel wall (left/top)
+ element = EL_DC_STEELWALL_1_TOPLEFT;
+ break;
+
+ case 0x169e: // steel wall (right/bottom small)
+ element = EL_DC_STEELWALL_1_BOTTOMRIGHT_2;
+ break;
+
+ case 0x169f: // steel wall (left/bottom small)
+ element = EL_DC_STEELWALL_1_BOTTOMLEFT_2;
+ break;
+
+ case 0x16a0: // steel wall (right/top small)
+ element = EL_DC_STEELWALL_1_TOPRIGHT_2;
+ break;
+
+ case 0x16a1: // steel wall (left/top small)
+ element = EL_DC_STEELWALL_1_TOPLEFT_2;
+ break;
+
+ case 0x16a2: // steel wall (left/right)
+ element = EL_DC_STEELWALL_1_VERTICAL;
+ break;
+
+ case 0x16a3: // steel wall (top/bottom)
+ element = EL_DC_STEELWALL_1_HORIZONTAL;
+ break;
+
+ case 0x16a4: // steel wall 2 (left end)
+ element = EL_DC_STEELWALL_2_LEFT;
+ break;
+
+ case 0x16a5: // steel wall 2 (right end)
+ element = EL_DC_STEELWALL_2_RIGHT;
+ break;
+
+ case 0x16a6: // steel wall 2 (top end)
+ element = EL_DC_STEELWALL_2_TOP;
break;
- case 0x1663: // (green steel)
- element = EL_STEEL_CHAR_Y;
+ case 0x16a7: // steel wall 2 (bottom end)
+ element = EL_DC_STEELWALL_2_BOTTOM;
break;
- case 0x1664: // (green steel)
- element = EL_STEEL_CHAR_Z;
+ case 0x16a8: // steel wall 2 (left/right)
+ element = EL_DC_STEELWALL_2_HORIZONTAL;
break;
- case 0x1665: // (green steel)
- element = EL_STEEL_CHAR_AUMLAUT;
+ case 0x16a9: // steel wall 2 (up/down)
+ element = EL_DC_STEELWALL_2_VERTICAL;
break;
- case 0x1666: // (green steel)
- element = EL_STEEL_CHAR_OUMLAUT;
+ case 0x16aa: // steel wall 2 (mid)
+ element = EL_DC_STEELWALL_2_MIDDLE;
break;
- case 0x1667: // (green steel)
- element = EL_STEEL_CHAR_UUMLAUT;
+ case 0x16ab:
+ element = EL_SIGN_EXCLAMATION;
break;
- case 0x1668: // (green steel)
- element = EL_STEEL_CHAR_0;
+ case 0x16ac:
+ element = EL_SIGN_RADIOACTIVITY;
break;
- case 0x1669: // (green steel)
- element = EL_STEEL_CHAR_1;
+ case 0x16ad:
+ element = EL_SIGN_STOP;
break;
- case 0x166a: // (green steel)
- element = EL_STEEL_CHAR_2;
+ case 0x16ae:
+ element = EL_SIGN_WHEELCHAIR;
break;
- case 0x166b: // (green steel)
- element = EL_STEEL_CHAR_3;
+ case 0x16af:
+ element = EL_SIGN_PARKING;
break;
- case 0x166c: // (green steel)
- element = EL_STEEL_CHAR_4;
+ case 0x16b0:
+ element = EL_SIGN_NO_ENTRY;
break;
- case 0x166d: // (green steel)
- element = EL_STEEL_CHAR_5;
+ case 0x16b1:
+ element = EL_SIGN_HEART;
break;
- case 0x166e: // (green steel)
- element = EL_STEEL_CHAR_6;
+ case 0x16b2:
+ element = EL_SIGN_GIVE_WAY;
break;
- case 0x166f: // (green steel)
- element = EL_STEEL_CHAR_7;
+ case 0x16b3:
+ element = EL_SIGN_ENTRY_FORBIDDEN;
break;
- case 0x1670: // (green steel)
- element = EL_STEEL_CHAR_8;
+ case 0x16b4:
+ element = EL_SIGN_EMERGENCY_EXIT;
break;
- case 0x1671: // (green steel)
- element = EL_STEEL_CHAR_9;
+ case 0x16b5:
+ element = EL_SIGN_YIN_YANG;
break;
- case 0x1672: // (green steel)
- element = EL_STEEL_CHAR_PERIOD;
+ case 0x16b6:
+ element = EL_WALL_EMERALD;
break;
- case 0x1673: // (green steel)
- element = EL_STEEL_CHAR_EXCLAM;
+ case 0x16b7:
+ element = EL_WALL_DIAMOND;
break;
- case 0x1674: // (green steel)
- element = EL_STEEL_CHAR_COLON;
+ case 0x16b8:
+ element = EL_WALL_PEARL;
break;
- case 0x1675: // (green steel)
- element = EL_STEEL_CHAR_LESS;
+ case 0x16b9:
+ element = EL_WALL_CRYSTAL;
break;
- case 0x1676: // (green steel)
- element = EL_STEEL_CHAR_GREATER;
+ case 0x16ba:
+ element = EL_INVISIBLE_WALL;
break;
- case 0x1677: // (green steel)
- element = EL_STEEL_CHAR_QUESTION;
+ case 0x16bb:
+ element = EL_INVISIBLE_STEELWALL;
break;
- case 0x1678: // (green steel)
- element = EL_STEEL_CHAR_COPYRIGHT;
+ // 0x16bc - 0x16cb:
+ // EL_INVISIBLE_SAND
+
+ case 0x16cc:
+ element = EL_LIGHT_SWITCH;
break;
- case 0x1679: // (green steel)
- element = EL_STEEL_CHAR_UP;
+ case 0x16cd:
+ element = EL_ENVELOPE_1;
break;
- case 0x167a: // (green steel)
- element = EL_STEEL_CHAR_DOWN;
+ default:
+ if (element >= 0x0117 && element <= 0x036e) // (?)
+ element = EL_DIAMOND;
+ else if (element >= 0x042d && element <= 0x0684) // (?)
+ element = EL_EMERALD;
+ else if (element >= 0x157c && element <= 0x158b)
+ element = EL_SAND;
+ else if (element >= 0x1590 && element <= 0x159f)
+ element = EL_DC_LANDMINE;
+ else if (element >= 0x16bc && element <= 0x16cb)
+ element = EL_INVISIBLE_SAND;
+ else
+ {
+ Warn("unknown Diamond Caves element 0x%04x", element);
+
+ element = EL_UNKNOWN;
+ }
break;
+ }
+
+ return getMappedElement(element);
+}
+
+static void LoadLevelFromFileStream_DC(File *file, struct LevelInfo *level)
+{
+ byte header[DC_LEVEL_HEADER_SIZE];
+ int envelope_size;
+ int envelope_header_pos = 62;
+ int envelope_content_pos = 94;
+ int level_name_pos = 251;
+ int level_author_pos = 292;
+ int envelope_header_len;
+ int envelope_content_len;
+ int level_name_len;
+ int level_author_len;
+ int fieldx, fieldy;
+ int num_yamyam_contents;
+ int i, x, y;
+
+ getDecodedWord_DC(0, TRUE); // initialize DC2 decoding engine
+
+ for (i = 0; i < DC_LEVEL_HEADER_SIZE / 2; i++)
+ {
+ unsigned short header_word = getDecodedWord_DC(getFile16BitBE(file), FALSE);
+
+ header[i * 2 + 0] = header_word >> 8;
+ header[i * 2 + 1] = header_word & 0xff;
+ }
+
+ // read some values from level header to check level decoding integrity
+ fieldx = header[6] | (header[7] << 8);
+ fieldy = header[8] | (header[9] << 8);
+ num_yamyam_contents = header[60] | (header[61] << 8);
+
+ // do some simple sanity checks to ensure that level was correctly decoded
+ if (fieldx < 1 || fieldx > 256 ||
+ fieldy < 1 || fieldy > 256 ||
+ num_yamyam_contents < 1 || num_yamyam_contents > 8)
+ {
+ level->no_valid_file = TRUE;
+
+ Warn("cannot decode level from stream -- using empty level");
+
+ return;
+ }
+
+ // maximum envelope header size is 31 bytes
+ envelope_header_len = header[envelope_header_pos];
+ // maximum envelope content size is 110 (156?) bytes
+ envelope_content_len = header[envelope_content_pos];
+
+ // maximum level title size is 40 bytes
+ level_name_len = MIN(header[level_name_pos], MAX_LEVEL_NAME_LEN);
+ // maximum level author size is 30 (51?) bytes
+ level_author_len = MIN(header[level_author_pos], MAX_LEVEL_AUTHOR_LEN);
+
+ envelope_size = 0;
+
+ for (i = 0; i < envelope_header_len; i++)
+ if (envelope_size < MAX_ENVELOPE_TEXT_LEN)
+ level->envelope[0].text[envelope_size++] =
+ header[envelope_header_pos + 1 + i];
+
+ if (envelope_header_len > 0 && envelope_content_len > 0)
+ {
+ if (envelope_size < MAX_ENVELOPE_TEXT_LEN)
+ level->envelope[0].text[envelope_size++] = '\n';
+ if (envelope_size < MAX_ENVELOPE_TEXT_LEN)
+ level->envelope[0].text[envelope_size++] = '\n';
+ }
+
+ for (i = 0; i < envelope_content_len; i++)
+ if (envelope_size < MAX_ENVELOPE_TEXT_LEN)
+ level->envelope[0].text[envelope_size++] =
+ header[envelope_content_pos + 1 + i];
+
+ level->envelope[0].text[envelope_size] = '\0';
+
+ level->envelope[0].xsize = MAX_ENVELOPE_XSIZE;
+ level->envelope[0].ysize = 10;
+ level->envelope[0].autowrap = TRUE;
+ level->envelope[0].centered = TRUE;
+
+ for (i = 0; i < level_name_len; i++)
+ level->name[i] = header[level_name_pos + 1 + i];
+ level->name[level_name_len] = '\0';
+
+ for (i = 0; i < level_author_len; i++)
+ level->author[i] = header[level_author_pos + 1 + i];
+ level->author[level_author_len] = '\0';
+
+ num_yamyam_contents = header[60] | (header[61] << 8);
+ level->num_yamyam_contents =
+ MIN(MAX(MIN_ELEMENT_CONTENTS, num_yamyam_contents), MAX_ELEMENT_CONTENTS);
+
+ for (i = 0; i < num_yamyam_contents; i++)
+ {
+ for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
+ {
+ unsigned short word = getDecodedWord_DC(getFile16BitBE(file), FALSE);
+ int element_dc = ((word & 0xff) << 8) | ((word >> 8) & 0xff);
+
+ if (i < MAX_ELEMENT_CONTENTS)
+ level->yamyam_content[i].e[x][y] = getMappedElement_DC(element_dc);
+ }
+ }
+
+ fieldx = header[6] | (header[7] << 8);
+ fieldy = header[8] | (header[9] << 8);
+ level->fieldx = MIN(MAX(MIN_LEV_FIELDX, fieldx), MAX_LEV_FIELDX);
+ level->fieldy = MIN(MAX(MIN_LEV_FIELDY, fieldy), MAX_LEV_FIELDY);
+
+ for (y = 0; y < fieldy; y++) for (x = 0; x < fieldx; x++)
+ {
+ unsigned short word = getDecodedWord_DC(getFile16BitBE(file), FALSE);
+ int element_dc = ((word & 0xff) << 8) | ((word >> 8) & 0xff);
+
+ if (x < MAX_LEV_FIELDX && y < MAX_LEV_FIELDY)
+ level->field[x][y] = getMappedElement_DC(element_dc);
+ }
+
+ x = MIN(MAX(0, (header[10] | (header[11] << 8)) - 1), MAX_LEV_FIELDX - 1);
+ y = MIN(MAX(0, (header[12] | (header[13] << 8)) - 1), MAX_LEV_FIELDY - 1);
+ level->field[x][y] = EL_PLAYER_1;
+
+ x = MIN(MAX(0, (header[14] | (header[15] << 8)) - 1), MAX_LEV_FIELDX - 1);
+ y = MIN(MAX(0, (header[16] | (header[17] << 8)) - 1), MAX_LEV_FIELDY - 1);
+ level->field[x][y] = EL_PLAYER_2;
+
+ level->gems_needed = header[18] | (header[19] << 8);
+
+ level->score[SC_EMERALD] = header[20] | (header[21] << 8);
+ level->score[SC_DIAMOND] = header[22] | (header[23] << 8);
+ level->score[SC_PEARL] = header[24] | (header[25] << 8);
+ level->score[SC_CRYSTAL] = header[26] | (header[27] << 8);
+ level->score[SC_NUT] = header[28] | (header[29] << 8);
+ level->score[SC_ROBOT] = header[30] | (header[31] << 8);
+ level->score[SC_SPACESHIP] = header[32] | (header[33] << 8);
+ level->score[SC_BUG] = header[34] | (header[35] << 8);
+ level->score[SC_YAMYAM] = header[36] | (header[37] << 8);
+ level->score[SC_DYNAMITE] = header[38] | (header[39] << 8);
+ level->score[SC_KEY] = header[40] | (header[41] << 8);
+ level->score[SC_TIME_BONUS] = header[42] | (header[43] << 8);
- case 0x167b: // (green steel)
- element = EL_STEEL_CHAR_BUTTON;
- break;
+ level->time = header[44] | (header[45] << 8);
- case 0x167c: // (green steel)
- element = EL_STEEL_CHAR_PLUS;
- break;
+ level->amoeba_speed = header[46] | (header[47] << 8);
+ level->time_light = header[48] | (header[49] << 8);
+ level->time_timegate = header[50] | (header[51] << 8);
+ level->time_wheel = header[52] | (header[53] << 8);
+ level->time_magic_wall = header[54] | (header[55] << 8);
+ level->extra_time = header[56] | (header[57] << 8);
+ level->shield_normal_time = header[58] | (header[59] << 8);
- case 0x167d: // (green steel)
- element = EL_STEEL_CHAR_MINUS;
- break;
+ // shield and extra time elements do not have a score
+ level->score[SC_SHIELD] = 0;
+ level->extra_time_score = 0;
- case 0x167e: // (green steel)
- element = EL_STEEL_CHAR_APOSTROPHE;
- break;
+ // set time for normal and deadly shields to the same value
+ level->shield_deadly_time = level->shield_normal_time;
- case 0x167f: // (green steel)
- element = EL_STEEL_CHAR_PARENLEFT;
- break;
+ // Diamond Caves has the same (strange) behaviour as Emerald Mine that gems
+ // can slip down from flat walls, like normal walls and steel walls
+ level->em_slippery_gems = TRUE;
- case 0x1680: // (green steel)
- element = EL_STEEL_CHAR_PARENRIGHT;
- break;
+ // time score is counted for each 10 seconds left in Diamond Caves levels
+ level->time_score_base = 10;
+}
- case 0x1681: // gate (red)
- element = EL_EM_GATE_1;
- break;
+static void LoadLevelFromFileInfo_DC(struct LevelInfo *level,
+ struct LevelFileInfo *level_file_info,
+ boolean level_info_only)
+{
+ char *filename = level_file_info->filename;
+ File *file;
+ int num_magic_bytes = 8;
+ char magic_bytes[num_magic_bytes + 1];
+ int num_levels_to_skip = level_file_info->nr - leveldir_current->first_level;
- case 0x1682: // secret gate (red)
- element = EL_GATE_1_GRAY;
- break;
+ if (!(file = openFile(filename, MODE_READ)))
+ {
+ level->no_valid_file = TRUE;
- case 0x1683: // gate (yellow)
- element = EL_EM_GATE_2;
- break;
+ if (!level_info_only)
+ Warn("cannot read level '%s' -- using empty level", filename);
- case 0x1684: // secret gate (yellow)
- element = EL_GATE_2_GRAY;
- break;
+ return;
+ }
- case 0x1685: // gate (blue)
- element = EL_EM_GATE_4;
- break;
+ // fseek(file, 0x0000, SEEK_SET);
- case 0x1686: // secret gate (blue)
- element = EL_GATE_4_GRAY;
- break;
+ if (level_file_info->packed)
+ {
+ // read "magic bytes" from start of file
+ if (getStringFromFile(file, magic_bytes, num_magic_bytes + 1) == NULL)
+ magic_bytes[0] = '\0';
- case 0x1687: // gate (green)
- element = EL_EM_GATE_3;
- break;
+ // check "magic bytes" for correct file format
+ if (!strPrefix(magic_bytes, "DC2"))
+ {
+ level->no_valid_file = TRUE;
- case 0x1688: // secret gate (green)
- element = EL_GATE_3_GRAY;
- break;
+ Warn("unknown DC level file '%s' -- using empty level", filename);
- case 0x1689: // gate (white)
- element = EL_DC_GATE_WHITE;
- break;
+ return;
+ }
- case 0x168a: // secret gate (white)
- element = EL_DC_GATE_WHITE_GRAY;
- break;
+ if (strPrefix(magic_bytes, "DC2Win95") ||
+ strPrefix(magic_bytes, "DC2Win98"))
+ {
+ int position_first_level = 0x00fa;
+ int extra_bytes = 4;
+ int skip_bytes;
- case 0x168b: // secret gate (no key)
- element = EL_DC_GATE_FAKE_GRAY;
- break;
+ // advance file stream to first level inside the level package
+ skip_bytes = position_first_level - num_magic_bytes - extra_bytes;
- case 0x168c:
- element = EL_ROBOT_WHEEL;
- break;
+ // each block of level data is followed by block of non-level data
+ num_levels_to_skip *= 2;
- case 0x168d:
- element = EL_DC_TIMEGATE_SWITCH;
- break;
+ // at least skip header bytes, therefore use ">= 0" instead of "> 0"
+ while (num_levels_to_skip >= 0)
+ {
+ // advance file stream to next level inside the level package
+ if (seekFile(file, skip_bytes, SEEK_CUR) != 0)
+ {
+ level->no_valid_file = TRUE;
- case 0x168e:
- element = EL_ACID_POOL_BOTTOM;
- break;
+ Warn("cannot fseek in file '%s' -- using empty level", filename);
- case 0x168f:
- element = EL_ACID_POOL_TOPLEFT;
- break;
+ return;
+ }
- case 0x1690:
- element = EL_ACID_POOL_TOPRIGHT;
- break;
+ // skip apparently unused extra bytes following each level
+ ReadUnusedBytesFromFile(file, extra_bytes);
- case 0x1691:
- element = EL_ACID_POOL_BOTTOMLEFT;
- break;
+ // read size of next level in level package
+ skip_bytes = getFile32BitLE(file);
- case 0x1692:
- element = EL_ACID_POOL_BOTTOMRIGHT;
- break;
+ num_levels_to_skip--;
+ }
+ }
+ else
+ {
+ level->no_valid_file = TRUE;
- case 0x1693:
- element = EL_STEELWALL;
- break;
+ Warn("unknown DC2 level file '%s' -- using empty level", filename);
- case 0x1694:
- element = EL_STEELWALL_SLIPPERY;
- break;
+ return;
+ }
+ }
- case 0x1695: // steel wall (not round)
- element = EL_STEELWALL;
- break;
+ LoadLevelFromFileStream_DC(file, level);
- case 0x1696: // steel wall (left)
- element = EL_DC_STEELWALL_1_LEFT;
- break;
+ closeFile(file);
+}
- case 0x1697: // steel wall (bottom)
- element = EL_DC_STEELWALL_1_BOTTOM;
- break;
- case 0x1698: // steel wall (right)
- element = EL_DC_STEELWALL_1_RIGHT;
- break;
+// ----------------------------------------------------------------------------
+// functions for loading SB level
+// ----------------------------------------------------------------------------
- case 0x1699: // steel wall (top)
- element = EL_DC_STEELWALL_1_TOP;
- break;
+int getMappedElement_SB(int element_ascii, boolean use_ces)
+{
+ static struct
+ {
+ int ascii;
+ int sb;
+ int ce;
+ }
+ sb_element_mapping[] =
+ {
+ { ' ', EL_EMPTY, EL_CUSTOM_1 }, // floor (space)
+ { '#', EL_STEELWALL, EL_CUSTOM_2 }, // wall
+ { '@', EL_PLAYER_1, EL_CUSTOM_3 }, // player
+ { '$', EL_SOKOBAN_OBJECT, EL_CUSTOM_4 }, // box
+ { '.', EL_SOKOBAN_FIELD_EMPTY, EL_CUSTOM_5 }, // goal square
+ { '*', EL_SOKOBAN_FIELD_FULL, EL_CUSTOM_6 }, // box on goal square
+ { '+', EL_SOKOBAN_FIELD_PLAYER, EL_CUSTOM_7 }, // player on goal square
+ { '_', EL_INVISIBLE_STEELWALL, EL_FROM_LEVEL_TEMPLATE }, // floor beyond border
- case 0x169a: // steel wall (left/bottom)
- element = EL_DC_STEELWALL_1_BOTTOMLEFT;
- break;
+ { 0, -1, -1 },
+ };
- case 0x169b: // steel wall (right/bottom)
- element = EL_DC_STEELWALL_1_BOTTOMRIGHT;
- break;
+ int i;
- case 0x169c: // steel wall (right/top)
- element = EL_DC_STEELWALL_1_TOPRIGHT;
- break;
+ for (i = 0; sb_element_mapping[i].ascii != 0; i++)
+ if (element_ascii == sb_element_mapping[i].ascii)
+ return (use_ces ? sb_element_mapping[i].ce : sb_element_mapping[i].sb);
- case 0x169d: // steel wall (left/top)
- element = EL_DC_STEELWALL_1_TOPLEFT;
- break;
+ return EL_UNDEFINED;
+}
- case 0x169e: // steel wall (right/bottom small)
- element = EL_DC_STEELWALL_1_BOTTOMRIGHT_2;
- break;
+static void SetLevelSettings_SB(struct LevelInfo *level)
+{
+ // time settings
+ level->time = 0;
+ level->use_step_counter = TRUE;
- case 0x169f: // steel wall (left/bottom small)
- element = EL_DC_STEELWALL_1_BOTTOMLEFT_2;
- break;
+ // score settings
+ level->score[SC_TIME_BONUS] = 0;
+ level->time_score_base = 1;
+ level->rate_time_over_score = TRUE;
- case 0x16a0: // steel wall (right/top small)
- element = EL_DC_STEELWALL_1_TOPRIGHT_2;
- break;
+ // game settings
+ level->auto_exit_sokoban = TRUE;
+}
- case 0x16a1: // steel wall (left/top small)
- element = EL_DC_STEELWALL_1_TOPLEFT_2;
- break;
+static void LoadLevelFromFileInfo_SB(struct LevelInfo *level,
+ struct LevelFileInfo *level_file_info,
+ boolean level_info_only)
+{
+ char *filename = level_file_info->filename;
+ char line[MAX_LINE_LEN], line_raw[MAX_LINE_LEN], previous_line[MAX_LINE_LEN];
+ char last_comment[MAX_LINE_LEN];
+ char level_name[MAX_LINE_LEN];
+ char *line_ptr;
+ File *file;
+ int num_levels_to_skip = level_file_info->nr - leveldir_current->first_level;
+ boolean read_continued_line = FALSE;
+ boolean reading_playfield = FALSE;
+ boolean got_valid_playfield_line = FALSE;
+ boolean invalid_playfield_char = FALSE;
+ boolean load_xsb_to_ces = check_special_flags("load_xsb_to_ces");
+ int file_level_nr = 0;
+ int x = 0, y = 0; // initialized to make compilers happy
- case 0x16a2: // steel wall (left/right)
- element = EL_DC_STEELWALL_1_VERTICAL;
- break;
+ last_comment[0] = '\0';
+ level_name[0] = '\0';
- case 0x16a3: // steel wall (top/bottom)
- element = EL_DC_STEELWALL_1_HORIZONTAL;
- break;
+ if (!(file = openFile(filename, MODE_READ)))
+ {
+ level->no_valid_file = TRUE;
- case 0x16a4: // steel wall 2 (left end)
- element = EL_DC_STEELWALL_2_LEFT;
- break;
+ if (!level_info_only)
+ Warn("cannot read level '%s' -- using empty level", filename);
+
+ return;
+ }
- case 0x16a5: // steel wall 2 (right end)
- element = EL_DC_STEELWALL_2_RIGHT;
- break;
+ while (!checkEndOfFile(file))
+ {
+ // level successfully read, but next level may follow here
+ if (!got_valid_playfield_line && reading_playfield)
+ {
+ // read playfield from single level file -- skip remaining file
+ if (!level_file_info->packed)
+ break;
- case 0x16a6: // steel wall 2 (top end)
- element = EL_DC_STEELWALL_2_TOP;
- break;
+ if (file_level_nr >= num_levels_to_skip)
+ break;
- case 0x16a7: // steel wall 2 (bottom end)
- element = EL_DC_STEELWALL_2_BOTTOM;
- break;
+ file_level_nr++;
- case 0x16a8: // steel wall 2 (left/right)
- element = EL_DC_STEELWALL_2_HORIZONTAL;
- break;
+ last_comment[0] = '\0';
+ level_name[0] = '\0';
- case 0x16a9: // steel wall 2 (up/down)
- element = EL_DC_STEELWALL_2_VERTICAL;
- break;
+ reading_playfield = FALSE;
+ }
- case 0x16aa: // steel wall 2 (mid)
- element = EL_DC_STEELWALL_2_MIDDLE;
- break;
+ got_valid_playfield_line = FALSE;
- case 0x16ab:
- element = EL_SIGN_EXCLAMATION;
+ // read next line of input file
+ if (!getStringFromFile(file, line, MAX_LINE_LEN))
break;
- case 0x16ac:
- element = EL_SIGN_RADIOACTIVITY;
- break;
+ // cut trailing line break (this can be newline and/or carriage return)
+ for (line_ptr = &line[strlen(line)]; line_ptr >= line; line_ptr--)
+ if ((*line_ptr == '\n' || *line_ptr == '\r') && *(line_ptr + 1) == '\0')
+ *line_ptr = '\0';
- case 0x16ad:
- element = EL_SIGN_STOP;
- break;
+ // copy raw input line for later use (mainly debugging output)
+ strcpy(line_raw, line);
- case 0x16ae:
- element = EL_SIGN_WHEELCHAIR;
- break;
+ if (read_continued_line)
+ {
+ // append new line to existing line, if there is enough space
+ if (strlen(previous_line) + strlen(line_ptr) < MAX_LINE_LEN)
+ strcat(previous_line, line_ptr);
- case 0x16af:
- element = EL_SIGN_PARKING;
- break;
+ strcpy(line, previous_line); // copy storage buffer to line
- case 0x16b0:
- element = EL_SIGN_NO_ENTRY;
- break;
+ read_continued_line = FALSE;
+ }
- case 0x16b1:
- element = EL_SIGN_HEART;
- break;
+ // if the last character is '\', continue at next line
+ if (strlen(line) > 0 && line[strlen(line) - 1] == '\\')
+ {
+ line[strlen(line) - 1] = '\0'; // cut off trailing backslash
+ strcpy(previous_line, line); // copy line to storage buffer
- case 0x16b2:
- element = EL_SIGN_GIVE_WAY;
- break;
+ read_continued_line = TRUE;
- case 0x16b3:
- element = EL_SIGN_ENTRY_FORBIDDEN;
- break;
+ continue;
+ }
- case 0x16b4:
- element = EL_SIGN_EMERGENCY_EXIT;
- break;
+ // skip empty lines
+ if (line[0] == '\0')
+ continue;
- case 0x16b5:
- element = EL_SIGN_YIN_YANG;
- break;
+ // extract comment text from comment line
+ if (line[0] == ';')
+ {
+ for (line_ptr = line; *line_ptr; line_ptr++)
+ if (*line_ptr != ' ' && *line_ptr != '\t' && *line_ptr != ';')
+ break;
- case 0x16b6:
- element = EL_WALL_EMERALD;
- break;
+ strcpy(last_comment, line_ptr);
- case 0x16b7:
- element = EL_WALL_DIAMOND;
- break;
+ continue;
+ }
- case 0x16b8:
- element = EL_WALL_PEARL;
- break;
+ // extract level title text from line containing level title
+ if (line[0] == '\'')
+ {
+ strcpy(level_name, &line[1]);
- case 0x16b9:
- element = EL_WALL_CRYSTAL;
- break;
+ if (strlen(level_name) > 0 && level_name[strlen(level_name) - 1] == '\'')
+ level_name[strlen(level_name) - 1] = '\0';
- case 0x16ba:
- element = EL_INVISIBLE_WALL;
- break;
+ continue;
+ }
- case 0x16bb:
- element = EL_INVISIBLE_STEELWALL;
- break;
+ // skip lines containing only spaces (or empty lines)
+ for (line_ptr = line; *line_ptr; line_ptr++)
+ if (*line_ptr != ' ')
+ break;
+ if (*line_ptr == '\0')
+ continue;
- // 0x16bc - 0x16cb:
- // EL_INVISIBLE_SAND
+ // at this point, we have found a line containing part of a playfield
- case 0x16cc:
- element = EL_LIGHT_SWITCH;
- break;
+ got_valid_playfield_line = TRUE;
- case 0x16cd:
- element = EL_ENVELOPE_1;
- break;
+ if (!reading_playfield)
+ {
+ reading_playfield = TRUE;
+ invalid_playfield_char = FALSE;
- default:
- if (element >= 0x0117 && element <= 0x036e) // (?)
- element = EL_DIAMOND;
- else if (element >= 0x042d && element <= 0x0684) // (?)
- element = EL_EMERALD;
- else if (element >= 0x157c && element <= 0x158b)
- element = EL_SAND;
- else if (element >= 0x1590 && element <= 0x159f)
- element = EL_DC_LANDMINE;
- else if (element >= 0x16bc && element <= 0x16cb)
- element = EL_INVISIBLE_SAND;
- else
- {
- Error(ERR_WARN, "unknown Diamond Caves element 0x%04x", element);
- element = EL_UNKNOWN;
- }
- break;
- }
+ for (x = 0; x < MAX_LEV_FIELDX; x++)
+ for (y = 0; y < MAX_LEV_FIELDY; y++)
+ level->field[x][y] = getMappedElement_SB(' ', load_xsb_to_ces);
- return getMappedElement(element);
-}
+ level->fieldx = 0;
+ level->fieldy = 0;
-static void LoadLevelFromFileStream_DC(File *file, struct LevelInfo *level,
- int nr)
-{
- byte header[DC_LEVEL_HEADER_SIZE];
- int envelope_size;
- int envelope_header_pos = 62;
- int envelope_content_pos = 94;
- int level_name_pos = 251;
- int level_author_pos = 292;
- int envelope_header_len;
- int envelope_content_len;
- int level_name_len;
- int level_author_len;
- int fieldx, fieldy;
- int num_yamyam_contents;
- int i, x, y;
+ // start with topmost tile row
+ y = 0;
+ }
- getDecodedWord_DC(0, TRUE); // initialize DC2 decoding engine
+ // skip playfield line if larger row than allowed
+ if (y >= MAX_LEV_FIELDY)
+ continue;
- for (i = 0; i < DC_LEVEL_HEADER_SIZE / 2; i++)
- {
- unsigned short header_word = getDecodedWord_DC(getFile16BitBE(file), FALSE);
+ // start with leftmost tile column
+ x = 0;
- header[i * 2 + 0] = header_word >> 8;
- header[i * 2 + 1] = header_word & 0xff;
- }
+ // read playfield elements from line
+ for (line_ptr = line; *line_ptr; line_ptr++)
+ {
+ int mapped_sb_element = getMappedElement_SB(*line_ptr, load_xsb_to_ces);
- // read some values from level header to check level decoding integrity
- fieldx = header[6] | (header[7] << 8);
- fieldy = header[8] | (header[9] << 8);
- num_yamyam_contents = header[60] | (header[61] << 8);
+ // stop parsing playfield line if larger column than allowed
+ if (x >= MAX_LEV_FIELDX)
+ break;
- // do some simple sanity checks to ensure that level was correctly decoded
- if (fieldx < 1 || fieldx > 256 ||
- fieldy < 1 || fieldy > 256 ||
- num_yamyam_contents < 1 || num_yamyam_contents > 8)
- {
- level->no_valid_file = TRUE;
+ if (mapped_sb_element == EL_UNDEFINED)
+ {
+ invalid_playfield_char = TRUE;
- Error(ERR_WARN, "cannot decode level from stream -- using empty level");
+ break;
+ }
- return;
- }
+ level->field[x][y] = mapped_sb_element;
- // maximum envelope header size is 31 bytes
- envelope_header_len = header[envelope_header_pos];
- // maximum envelope content size is 110 (156?) bytes
- envelope_content_len = header[envelope_content_pos];
+ // continue with next tile column
+ x++;
- // maximum level title size is 40 bytes
- level_name_len = MIN(header[level_name_pos], MAX_LEVEL_NAME_LEN);
- // maximum level author size is 30 (51?) bytes
- level_author_len = MIN(header[level_author_pos], MAX_LEVEL_AUTHOR_LEN);
+ level->fieldx = MAX(x, level->fieldx);
+ }
- envelope_size = 0;
+ if (invalid_playfield_char)
+ {
+ // if first playfield line, treat invalid lines as comment lines
+ if (y == 0)
+ reading_playfield = FALSE;
- for (i = 0; i < envelope_header_len; i++)
- if (envelope_size < MAX_ENVELOPE_TEXT_LEN)
- level->envelope[0].text[envelope_size++] =
- header[envelope_header_pos + 1 + i];
+ continue;
+ }
- if (envelope_header_len > 0 && envelope_content_len > 0)
- {
- if (envelope_size < MAX_ENVELOPE_TEXT_LEN)
- level->envelope[0].text[envelope_size++] = '\n';
- if (envelope_size < MAX_ENVELOPE_TEXT_LEN)
- level->envelope[0].text[envelope_size++] = '\n';
+ // continue with next tile row
+ y++;
}
- for (i = 0; i < envelope_content_len; i++)
- if (envelope_size < MAX_ENVELOPE_TEXT_LEN)
- level->envelope[0].text[envelope_size++] =
- header[envelope_content_pos + 1 + i];
+ closeFile(file);
- level->envelope[0].text[envelope_size] = '\0';
+ level->fieldy = y;
- level->envelope[0].xsize = MAX_ENVELOPE_XSIZE;
- level->envelope[0].ysize = 10;
- level->envelope[0].autowrap = TRUE;
- level->envelope[0].centered = TRUE;
+ level->fieldx = MIN(MAX(MIN_LEV_FIELDX, level->fieldx), MAX_LEV_FIELDX);
+ level->fieldy = MIN(MAX(MIN_LEV_FIELDY, level->fieldy), MAX_LEV_FIELDY);
- for (i = 0; i < level_name_len; i++)
- level->name[i] = header[level_name_pos + 1 + i];
- level->name[level_name_len] = '\0';
+ if (!reading_playfield)
+ {
+ level->no_valid_file = TRUE;
- for (i = 0; i < level_author_len; i++)
- level->author[i] = header[level_author_pos + 1 + i];
- level->author[level_author_len] = '\0';
+ Warn("cannot read level '%s' -- using empty level", filename);
- num_yamyam_contents = header[60] | (header[61] << 8);
- level->num_yamyam_contents =
- MIN(MAX(MIN_ELEMENT_CONTENTS, num_yamyam_contents), MAX_ELEMENT_CONTENTS);
+ return;
+ }
- for (i = 0; i < num_yamyam_contents; i++)
+ if (*level_name != '\0')
{
- for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
- {
- unsigned short word = getDecodedWord_DC(getFile16BitBE(file), FALSE);
- int element_dc = ((word & 0xff) << 8) | ((word >> 8) & 0xff);
+ strncpy(level->name, level_name, MAX_LEVEL_NAME_LEN);
+ level->name[MAX_LEVEL_NAME_LEN] = '\0';
+ }
+ else if (*last_comment != '\0')
+ {
+ strncpy(level->name, last_comment, MAX_LEVEL_NAME_LEN);
+ level->name[MAX_LEVEL_NAME_LEN] = '\0';
+ }
+ else
+ {
+ sprintf(level->name, "--> Level %d <--", level_file_info->nr);
+ }
- if (i < MAX_ELEMENT_CONTENTS)
- level->yamyam_content[i].e[x][y] = getMappedElement_DC(element_dc);
- }
+ // set all empty fields beyond the border walls to invisible steel wall
+ for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++)
+ {
+ if ((x == 0 || x == level->fieldx - 1 ||
+ y == 0 || y == level->fieldy - 1) &&
+ level->field[x][y] == getMappedElement_SB(' ', load_xsb_to_ces))
+ FloodFillLevel(x, y, getMappedElement_SB('_', load_xsb_to_ces),
+ level->field, level->fieldx, level->fieldy);
}
- fieldx = header[6] | (header[7] << 8);
- fieldy = header[8] | (header[9] << 8);
- level->fieldx = MIN(MAX(MIN_LEV_FIELDX, fieldx), MAX_LEV_FIELDX);
- level->fieldy = MIN(MAX(MIN_LEV_FIELDY, fieldy), MAX_LEV_FIELDY);
+ // set special level settings for Sokoban levels
+ SetLevelSettings_SB(level);
- for (y = 0; y < fieldy; y++) for (x = 0; x < fieldx; x++)
+ if (load_xsb_to_ces)
{
- unsigned short word = getDecodedWord_DC(getFile16BitBE(file), FALSE);
- int element_dc = ((word & 0xff) << 8) | ((word >> 8) & 0xff);
-
- if (x < MAX_LEV_FIELDX && y < MAX_LEV_FIELDY)
- level->field[x][y] = getMappedElement_DC(element_dc);
+ // special global settings can now be set in level template
+ level->use_custom_template = TRUE;
}
+}
- x = MIN(MAX(0, (header[10] | (header[11] << 8)) - 1), MAX_LEV_FIELDX - 1);
- y = MIN(MAX(0, (header[12] | (header[13] << 8)) - 1), MAX_LEV_FIELDY - 1);
- level->field[x][y] = EL_PLAYER_1;
-
- x = MIN(MAX(0, (header[14] | (header[15] << 8)) - 1), MAX_LEV_FIELDX - 1);
- y = MIN(MAX(0, (header[16] | (header[17] << 8)) - 1), MAX_LEV_FIELDY - 1);
- level->field[x][y] = EL_PLAYER_2;
- level->gems_needed = header[18] | (header[19] << 8);
+// -------------------------------------------------------------------------
+// functions for handling native levels
+// -------------------------------------------------------------------------
- level->score[SC_EMERALD] = header[20] | (header[21] << 8);
- level->score[SC_DIAMOND] = header[22] | (header[23] << 8);
- level->score[SC_PEARL] = header[24] | (header[25] << 8);
- level->score[SC_CRYSTAL] = header[26] | (header[27] << 8);
- level->score[SC_NUT] = header[28] | (header[29] << 8);
- level->score[SC_ROBOT] = header[30] | (header[31] << 8);
- level->score[SC_SPACESHIP] = header[32] | (header[33] << 8);
- level->score[SC_BUG] = header[34] | (header[35] << 8);
- level->score[SC_YAMYAM] = header[36] | (header[37] << 8);
- level->score[SC_DYNAMITE] = header[38] | (header[39] << 8);
- level->score[SC_KEY] = header[40] | (header[41] << 8);
- level->score[SC_TIME_BONUS] = header[42] | (header[43] << 8);
+static void LoadLevelFromFileInfo_BD(struct LevelInfo *level,
+ struct LevelFileInfo *level_file_info,
+ boolean level_info_only)
+{
+ int pos = 0;
- level->time = header[44] | (header[45] << 8);
+ // determine position of requested level inside level package
+ if (level_file_info->packed)
+ pos = level_file_info->nr - leveldir_current->first_level;
- level->amoeba_speed = header[46] | (header[47] << 8);
- level->time_light = header[48] | (header[49] << 8);
- level->time_timegate = header[50] | (header[51] << 8);
- level->time_wheel = header[52] | (header[53] << 8);
- level->time_magic_wall = header[54] | (header[55] << 8);
- level->extra_time = header[56] | (header[57] << 8);
- level->shield_normal_time = header[58] | (header[59] << 8);
+ if (!LoadNativeLevel_BD(level_file_info->filename, pos, level_info_only))
+ level->no_valid_file = TRUE;
+}
- // Diamond Caves has the same (strange) behaviour as Emerald Mine that gems
- // can slip down from flat walls, like normal walls and steel walls
- level->em_slippery_gems = TRUE;
+static void LoadLevelFromFileInfo_EM(struct LevelInfo *level,
+ struct LevelFileInfo *level_file_info,
+ boolean level_info_only)
+{
+ if (!LoadNativeLevel_EM(level_file_info->filename, level_info_only))
+ level->no_valid_file = TRUE;
}
-static void LoadLevelFromFileInfo_DC(struct LevelInfo *level,
+static void LoadLevelFromFileInfo_SP(struct LevelInfo *level,
struct LevelFileInfo *level_file_info,
boolean level_info_only)
{
- char *filename = level_file_info->filename;
- File *file;
- int num_magic_bytes = 8;
- char magic_bytes[num_magic_bytes + 1];
- int num_levels_to_skip = level_file_info->nr - leveldir_current->first_level;
+ int pos = 0;
- if (!(file = openFile(filename, MODE_READ)))
- {
+ // determine position of requested level inside level package
+ if (level_file_info->packed)
+ pos = level_file_info->nr - leveldir_current->first_level;
+
+ if (!LoadNativeLevel_SP(level_file_info->filename, pos, level_info_only))
level->no_valid_file = TRUE;
+}
- if (!level_info_only)
- Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename);
+static void LoadLevelFromFileInfo_MM(struct LevelInfo *level,
+ struct LevelFileInfo *level_file_info,
+ boolean level_info_only)
+{
+ if (!LoadNativeLevel_MM(level_file_info->filename, level_info_only))
+ level->no_valid_file = TRUE;
+}
+
+void CopyNativeLevel_RND_to_Native(struct LevelInfo *level)
+{
+ if (level->game_engine_type == GAME_ENGINE_TYPE_BD)
+ CopyNativeLevel_RND_to_BD(level);
+ else if (level->game_engine_type == GAME_ENGINE_TYPE_EM)
+ CopyNativeLevel_RND_to_EM(level);
+ else if (level->game_engine_type == GAME_ENGINE_TYPE_SP)
+ CopyNativeLevel_RND_to_SP(level);
+ else if (level->game_engine_type == GAME_ENGINE_TYPE_MM)
+ CopyNativeLevel_RND_to_MM(level);
+}
+
+void CopyNativeLevel_Native_to_RND(struct LevelInfo *level)
+{
+ if (level->game_engine_type == GAME_ENGINE_TYPE_BD)
+ CopyNativeLevel_BD_to_RND(level);
+ else if (level->game_engine_type == GAME_ENGINE_TYPE_EM)
+ CopyNativeLevel_EM_to_RND(level);
+ else if (level->game_engine_type == GAME_ENGINE_TYPE_SP)
+ CopyNativeLevel_SP_to_RND(level);
+ else if (level->game_engine_type == GAME_ENGINE_TYPE_MM)
+ CopyNativeLevel_MM_to_RND(level);
+}
+void SaveNativeLevel(struct LevelInfo *level)
+{
+ // saving native level files only supported for some game engines
+ if (level->game_engine_type != GAME_ENGINE_TYPE_BD &&
+ level->game_engine_type != GAME_ENGINE_TYPE_SP)
return;
- }
- // fseek(file, 0x0000, SEEK_SET);
+ char *file_ext = (level->game_engine_type == GAME_ENGINE_TYPE_BD ? "bd" :
+ level->game_engine_type == GAME_ENGINE_TYPE_SP ? "sp" : "");
+ char *basename = getSingleLevelBasenameExt(level->file_info.nr, file_ext);
+ char *filename = getLevelFilenameFromBasename(basename);
- if (level_file_info->packed)
+ if (fileExists(filename) && !Request("Native level file already exists! Overwrite it?", REQ_ASK))
+ return;
+
+ boolean success = FALSE;
+
+ if (level->game_engine_type == GAME_ENGINE_TYPE_BD)
{
- // read "magic bytes" from start of file
- if (getStringFromFile(file, magic_bytes, num_magic_bytes + 1) == NULL)
- magic_bytes[0] = '\0';
+ CopyNativeLevel_RND_to_BD(level);
+ // CopyNativeTape_RND_to_BD(level);
- // check "magic bytes" for correct file format
- if (!strPrefix(magic_bytes, "DC2"))
- {
- level->no_valid_file = TRUE;
+ success = SaveNativeLevel_BD(filename);
+ }
+ else if (level->game_engine_type == GAME_ENGINE_TYPE_SP)
+ {
+ CopyNativeLevel_RND_to_SP(level);
+ CopyNativeTape_RND_to_SP(level);
- Error(ERR_WARN, "unknown DC level file '%s' -- using empty level",
- filename);
+ success = SaveNativeLevel_SP(filename);
+ }
- return;
- }
+ if (success)
+ Request("Native level file saved!", REQ_CONFIRM);
+ else
+ Request("Failed to save native level file!", REQ_CONFIRM);
+}
- if (strPrefix(magic_bytes, "DC2Win95") ||
- strPrefix(magic_bytes, "DC2Win98"))
- {
- int position_first_level = 0x00fa;
- int extra_bytes = 4;
- int skip_bytes;
- // advance file stream to first level inside the level package
- skip_bytes = position_first_level - num_magic_bytes - extra_bytes;
+// ----------------------------------------------------------------------------
+// functions for loading generic level
+// ----------------------------------------------------------------------------
- // each block of level data is followed by block of non-level data
- num_levels_to_skip *= 2;
+static void LoadLevelFromFileInfo(struct LevelInfo *level,
+ struct LevelFileInfo *level_file_info,
+ boolean level_info_only)
+{
+ // always start with reliable default values
+ setLevelInfoToDefaults(level, level_info_only, TRUE);
- // at least skip header bytes, therefore use ">= 0" instead of "> 0"
- while (num_levels_to_skip >= 0)
- {
- // advance file stream to next level inside the level package
- if (seekFile(file, skip_bytes, SEEK_CUR) != 0)
- {
- level->no_valid_file = TRUE;
+ switch (level_file_info->type)
+ {
+ case LEVEL_FILE_TYPE_RND:
+ LoadLevelFromFileInfo_RND(level, level_file_info, level_info_only);
+ break;
- Error(ERR_WARN, "cannot fseek in file '%s' -- using empty level",
- filename);
+ case LEVEL_FILE_TYPE_BD:
+ LoadLevelFromFileInfo_BD(level, level_file_info, level_info_only);
+ level->game_engine_type = GAME_ENGINE_TYPE_BD;
+ break;
- return;
- }
+ case LEVEL_FILE_TYPE_EM:
+ LoadLevelFromFileInfo_EM(level, level_file_info, level_info_only);
+ level->game_engine_type = GAME_ENGINE_TYPE_EM;
+ break;
- // skip apparently unused extra bytes following each level
- ReadUnusedBytesFromFile(file, extra_bytes);
+ case LEVEL_FILE_TYPE_SP:
+ LoadLevelFromFileInfo_SP(level, level_file_info, level_info_only);
+ level->game_engine_type = GAME_ENGINE_TYPE_SP;
+ break;
- // read size of next level in level package
- skip_bytes = getFile32BitLE(file);
+ case LEVEL_FILE_TYPE_MM:
+ LoadLevelFromFileInfo_MM(level, level_file_info, level_info_only);
+ level->game_engine_type = GAME_ENGINE_TYPE_MM;
+ break;
- num_levels_to_skip--;
- }
- }
- else
- {
- level->no_valid_file = TRUE;
+ case LEVEL_FILE_TYPE_DC:
+ LoadLevelFromFileInfo_DC(level, level_file_info, level_info_only);
+ break;
- Error(ERR_WARN, "unknown DC2 level file '%s' -- using empty level",
- filename);
+ case LEVEL_FILE_TYPE_SB:
+ LoadLevelFromFileInfo_SB(level, level_file_info, level_info_only);
+ break;
- return;
- }
+ default:
+ LoadLevelFromFileInfo_RND(level, level_file_info, level_info_only);
+ break;
}
- LoadLevelFromFileStream_DC(file, level, level_file_info->nr);
+ // if level file is invalid, restore level structure to default values
+ if (level->no_valid_file)
+ setLevelInfoToDefaults(level, level_info_only, FALSE);
- closeFile(file);
-}
+ if (check_special_flags("use_native_bd_game_engine"))
+ level->game_engine_type = GAME_ENGINE_TYPE_BD;
+ if (level->game_engine_type == GAME_ENGINE_TYPE_UNKNOWN)
+ level->game_engine_type = GAME_ENGINE_TYPE_RND;
-// ----------------------------------------------------------------------------
-// functions for loading SB level
-// ----------------------------------------------------------------------------
+ if (level_file_info->type != LEVEL_FILE_TYPE_RND)
+ CopyNativeLevel_Native_to_RND(level);
+}
-int getMappedElement_SB(int element_ascii, boolean use_ces)
+void LoadLevelFromFilename(struct LevelInfo *level, char *filename)
{
- static struct
- {
- int ascii;
- int sb;
- int ce;
- }
- sb_element_mapping[] =
- {
- { ' ', EL_EMPTY, EL_CUSTOM_1 }, // floor (space)
- { '#', EL_STEELWALL, EL_CUSTOM_2 }, // wall
- { '@', EL_PLAYER_1, EL_CUSTOM_3 }, // player
- { '$', EL_SOKOBAN_OBJECT, EL_CUSTOM_4 }, // box
- { '.', EL_SOKOBAN_FIELD_EMPTY, EL_CUSTOM_5 }, // goal square
- { '*', EL_SOKOBAN_FIELD_FULL, EL_CUSTOM_6 }, // box on goal square
- { '+', EL_SOKOBAN_FIELD_PLAYER, EL_CUSTOM_7 }, // player on goal square
- { '_', EL_INVISIBLE_STEELWALL, EL_FROM_LEVEL_TEMPLATE }, // floor beyond border
+ static struct LevelFileInfo level_file_info;
- { 0, -1, -1 },
- };
+ // always start with reliable default values
+ setFileInfoToDefaults(&level_file_info);
- int i;
+ level_file_info.nr = 0; // unknown level number
+ level_file_info.type = LEVEL_FILE_TYPE_RND; // no others supported yet
- for (i = 0; sb_element_mapping[i].ascii != 0; i++)
- if (element_ascii == sb_element_mapping[i].ascii)
- return (use_ces ? sb_element_mapping[i].ce : sb_element_mapping[i].sb);
+ setString(&level_file_info.filename, filename);
- return EL_UNDEFINED;
+ LoadLevelFromFileInfo(level, &level_file_info, FALSE);
}
-static void LoadLevelFromFileInfo_SB(struct LevelInfo *level,
- struct LevelFileInfo *level_file_info,
- boolean level_info_only)
+static void LoadLevel_InitVersion(struct LevelInfo *level)
{
- char *filename = level_file_info->filename;
- char line[MAX_LINE_LEN], line_raw[MAX_LINE_LEN], previous_line[MAX_LINE_LEN];
- char last_comment[MAX_LINE_LEN];
- char level_name[MAX_LINE_LEN];
- char *line_ptr;
- File *file;
- int num_levels_to_skip = level_file_info->nr - leveldir_current->first_level;
- boolean read_continued_line = FALSE;
- boolean reading_playfield = FALSE;
- boolean got_valid_playfield_line = FALSE;
- boolean invalid_playfield_char = FALSE;
- boolean load_xsb_to_ces = check_special_flags("load_xsb_to_ces");
- int file_level_nr = 0;
- int line_nr = 0;
- int x = 0, y = 0; // initialized to make compilers happy
+ int i, j;
- last_comment[0] = '\0';
- level_name[0] = '\0';
+ if (leveldir_current == NULL) // only when dumping level
+ return;
- if (!(file = openFile(filename, MODE_READ)))
+ // all engine modifications also valid for levels which use latest engine
+ if (level->game_version < VERSION_IDENT(3,2,0,5))
{
- level->no_valid_file = TRUE;
+ // time bonus score was given for 10 s instead of 1 s before 3.2.0-5
+ level->time_score_base = 10;
+ }
- if (!level_info_only)
- Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename);
+ if (leveldir_current->latest_engine)
+ {
+ // ---------- use latest game engine --------------------------------------
+
+ /* For all levels which are forced to use the latest game engine version
+ (normally all but user contributed, private and undefined levels), set
+ the game engine version to the actual version; this allows for actual
+ corrections in the game engine to take effect for existing, converted
+ levels (from "classic" or other existing games) to make the emulation
+ of the corresponding game more accurate, while (hopefully) not breaking
+ existing levels created from other players. */
+
+ level->game_version = GAME_VERSION_ACTUAL;
+
+ /* Set special EM style gems behaviour: EM style gems slip down from
+ normal, steel and growing wall. As this is a more fundamental change,
+ it seems better to set the default behaviour to "off" (as it is more
+ natural) and make it configurable in the level editor (as a property
+ of gem style elements). Already existing converted levels (neither
+ private nor contributed levels) are changed to the new behaviour. */
+
+ if (level->file_version < FILE_VERSION_2_0)
+ level->em_slippery_gems = TRUE;
return;
}
- while (!checkEndOfFile(file))
- {
- // level successfully read, but next level may follow here
- if (!got_valid_playfield_line && reading_playfield)
- {
- // read playfield from single level file -- skip remaining file
- if (!level_file_info->packed)
- break;
+ // ---------- use game engine the level was created with --------------------
- if (file_level_nr >= num_levels_to_skip)
- break;
+ /* For all levels which are not forced to use the latest game engine
+ version (normally user contributed, private and undefined levels),
+ use the version of the game engine the levels were created for.
- file_level_nr++;
+ Since 2.0.1, the game engine version is now directly stored
+ in the level file (chunk "VERS"), so there is no need anymore
+ to set the game version from the file version (except for old,
+ pre-2.0 levels, where the game version is still taken from the
+ file format version used to store the level -- see above). */
- last_comment[0] = '\0';
- level_name[0] = '\0';
+ // player was faster than enemies in 1.0.0 and before
+ if (level->file_version == FILE_VERSION_1_0)
+ for (i = 0; i < MAX_PLAYERS; i++)
+ level->initial_player_stepsize[i] = STEPSIZE_FAST;
- reading_playfield = FALSE;
- }
+ // default behaviour for EM style gems was "slippery" only in 2.0.1
+ if (level->game_version == VERSION_IDENT(2,0,1,0))
+ level->em_slippery_gems = TRUE;
- got_valid_playfield_line = FALSE;
+ // springs could be pushed over pits before (pre-release version) 2.2.0
+ if (level->game_version < VERSION_IDENT(2,2,0,0))
+ level->use_spring_bug = TRUE;
- // read next line of input file
- if (!getStringFromFile(file, line, MAX_LINE_LEN))
- break;
+ if (level->game_version < VERSION_IDENT(3,2,0,5))
+ {
+ // time orb caused limited time in endless time levels before 3.2.0-5
+ level->use_time_orb_bug = TRUE;
- // check if line was completely read and is terminated by line break
- if (strlen(line) > 0 && line[strlen(line) - 1] == '\n')
- line_nr++;
+ // default behaviour for snapping was "no snap delay" before 3.2.0-5
+ level->block_snap_field = FALSE;
- // cut trailing line break (this can be newline and/or carriage return)
- for (line_ptr = &line[strlen(line)]; line_ptr >= line; line_ptr--)
- if ((*line_ptr == '\n' || *line_ptr == '\r') && *(line_ptr + 1) == '\0')
- *line_ptr = '\0';
+ // extra time score was same value as time left score before 3.2.0-5
+ level->extra_time_score = level->score[SC_TIME_BONUS];
+ }
- // copy raw input line for later use (mainly debugging output)
- strcpy(line_raw, line);
+ if (level->game_version < VERSION_IDENT(3,2,0,7))
+ {
+ // default behaviour for snapping was "not continuous" before 3.2.0-7
+ level->continuous_snapping = FALSE;
+ }
- if (read_continued_line)
- {
- // append new line to existing line, if there is enough space
- if (strlen(previous_line) + strlen(line_ptr) < MAX_LINE_LEN)
- strcat(previous_line, line_ptr);
+ // only few elements were able to actively move into acid before 3.1.0
+ // trigger settings did not exist before 3.1.0; set to default "any"
+ if (level->game_version < VERSION_IDENT(3,1,0,0))
+ {
+ // correct "can move into acid" settings (all zero in old levels)
- strcpy(line, previous_line); // copy storage buffer to line
+ level->can_move_into_acid_bits = 0; // nothing can move into acid
+ level->dont_collide_with_bits = 0; // nothing is deadly when colliding
- read_continued_line = FALSE;
- }
+ setMoveIntoAcidProperty(level, EL_ROBOT, TRUE);
+ setMoveIntoAcidProperty(level, EL_SATELLITE, TRUE);
+ setMoveIntoAcidProperty(level, EL_PENGUIN, TRUE);
+ setMoveIntoAcidProperty(level, EL_BALLOON, TRUE);
- // if the last character is '\', continue at next line
- if (strlen(line) > 0 && line[strlen(line) - 1] == '\\')
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ SET_PROPERTY(EL_CUSTOM_START + i, EP_CAN_MOVE_INTO_ACID, TRUE);
+
+ // correct trigger settings (stored as zero == "none" in old levels)
+
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
{
- line[strlen(line) - 1] = '\0'; // cut off trailing backslash
- strcpy(previous_line, line); // copy line to storage buffer
+ int element = EL_CUSTOM_START + i;
+ struct ElementInfo *ei = &element_info[element];
- read_continued_line = TRUE;
+ for (j = 0; j < ei->num_change_pages; j++)
+ {
+ struct ElementChangeInfo *change = &ei->change_page[j];
- continue;
+ change->trigger_player = CH_PLAYER_ANY;
+ change->trigger_page = CH_PAGE_ANY;
+ }
}
+ }
- // skip empty lines
- if (line[0] == '\0')
- continue;
+ // try to detect and fix "Snake Bite" levels, which are broken with 3.2.0
+ {
+ int element = EL_CUSTOM_256;
+ struct ElementInfo *ei = &element_info[element];
+ struct ElementChangeInfo *change = &ei->change_page[0];
- // extract comment text from comment line
- if (line[0] == ';')
- {
- for (line_ptr = line; *line_ptr; line_ptr++)
- if (*line_ptr != ' ' && *line_ptr != '\t' && *line_ptr != ';')
- break;
+ /* This is needed to fix a problem that was caused by a bugfix in function
+ game.c/CreateFieldExt() introduced with 3.2.0 that corrects the behaviour
+ when a custom element changes to EL_SOKOBAN_FIELD_PLAYER (before, it did
+ not replace walkable elements, but instead just placed the player on it,
+ without placing the Sokoban field under the player). Unfortunately, this
+ breaks "Snake Bite" style levels when the snake is halfway through a door
+ that just closes (the snake head is still alive and can be moved in this
+ case). This can be fixed by replacing the EL_SOKOBAN_FIELD_PLAYER by the
+ player (without Sokoban element) which then gets killed as designed). */
+
+ if ((strncmp(leveldir_current->identifier, "snake_bite", 10) == 0 ||
+ strncmp(ei->description, "pause b4 death", 14) == 0) &&
+ change->target_element == EL_SOKOBAN_FIELD_PLAYER)
+ change->target_element = EL_PLAYER_1;
+ }
+
+ // try to detect and fix "Zelda" style levels, which are broken with 3.2.5
+ if (level->game_version < VERSION_IDENT(3,2,5,0))
+ {
+ /* This is needed to fix a problem that was caused by a bugfix in function
+ game.c/CheckTriggeredElementChangeExt() introduced with 3.2.5 that
+ corrects the behaviour when a custom element changes to another custom
+ element with a higher element number that has change actions defined.
+ Normally, only one change per frame is allowed for custom elements.
+ Therefore, it is checked if a custom element already changed in the
+ current frame; if it did, subsequent changes are suppressed.
+ Unfortunately, this is only checked for element changes, but not for
+ change actions, which are still executed. As the function above loops
+ through all custom elements from lower to higher, an element change
+ resulting in a lower CE number won't be checked again, while a target
+ element with a higher number will also be checked, and potential change
+ actions will get executed for this CE, too (which is wrong), while
+ further changes are ignored (which is correct). As this bugfix breaks
+ Zelda II (and introduces graphical bugs to Zelda I, and also breaks a
+ few other levels like Alan Bond's "FMV"), allow the previous, incorrect
+ behaviour for existing levels and tapes that make use of this bug */
+
+ level->use_action_after_change_bug = TRUE;
+ }
+
+ // not centering level after relocating player was default only in 3.2.3
+ if (level->game_version == VERSION_IDENT(3,2,3,0)) // (no pre-releases)
+ level->shifted_relocation = TRUE;
+
+ // EM style elements always chain-exploded in R'n'D engine before 3.2.6
+ if (level->game_version < VERSION_IDENT(3,2,6,0))
+ level->em_explodes_by_fire = TRUE;
- strcpy(last_comment, line_ptr);
+ // levels were solved by the first player entering an exit up to 4.1.0.0
+ if (level->game_version <= VERSION_IDENT(4,1,0,0))
+ level->solved_by_one_player = TRUE;
- continue;
- }
+ // game logic of "game of life" and "biomaze" was buggy before 4.1.1.1
+ if (level->game_version < VERSION_IDENT(4,1,1,1))
+ level->use_life_bugs = TRUE;
- // extract level title text from line containing level title
- if (line[0] == '\'')
- {
- strcpy(level_name, &line[1]);
+ // only Sokoban fields (but not objects) had to be solved before 4.1.1.1
+ if (level->game_version < VERSION_IDENT(4,1,1,1))
+ level->sb_objects_needed = FALSE;
- if (strlen(level_name) > 0 && level_name[strlen(level_name) - 1] == '\'')
- level_name[strlen(level_name) - 1] = '\0';
+ // CE actions were triggered by unfinished digging/collecting up to 4.2.2.0
+ if (level->game_version <= VERSION_IDENT(4,2,2,0))
+ level->finish_dig_collect = FALSE;
- continue;
- }
+ // CE changing to player was kept under the player if walkable up to 4.2.3.1
+ if (level->game_version <= VERSION_IDENT(4,2,3,1))
+ level->keep_walkable_ce = TRUE;
+}
- // skip lines containing only spaces (or empty lines)
- for (line_ptr = line; *line_ptr; line_ptr++)
- if (*line_ptr != ' ')
- break;
- if (*line_ptr == '\0')
- continue;
+static void LoadLevel_InitSettings_SB(struct LevelInfo *level)
+{
+ boolean is_sokoban_level = TRUE; // unless non-Sokoban elements found
+ int x, y;
- // at this point, we have found a line containing part of a playfield
+ // check if this level is (not) a Sokoban level
+ for (y = 0; y < level->fieldy; y++)
+ for (x = 0; x < level->fieldx; x++)
+ if (!IS_SB_ELEMENT(Tile[x][y]))
+ is_sokoban_level = FALSE;
- got_valid_playfield_line = TRUE;
+ if (is_sokoban_level)
+ {
+ // set special level settings for Sokoban levels
+ SetLevelSettings_SB(level);
+ }
+}
- if (!reading_playfield)
- {
- reading_playfield = TRUE;
- invalid_playfield_char = FALSE;
+static void LoadLevel_InitSettings(struct LevelInfo *level)
+{
+ // adjust level settings for (non-native) Sokoban-style levels
+ LoadLevel_InitSettings_SB(level);
- for (x = 0; x < MAX_LEV_FIELDX; x++)
- for (y = 0; y < MAX_LEV_FIELDY; y++)
- level->field[x][y] = getMappedElement_SB(' ', load_xsb_to_ces);
+ // rename levels with title "nameless level" or if renaming is forced
+ if (leveldir_current->empty_level_name != NULL &&
+ (strEqual(level->name, NAMELESS_LEVEL_NAME) ||
+ leveldir_current->force_level_name))
+ snprintf(level->name, MAX_LEVEL_NAME_LEN + 1,
+ leveldir_current->empty_level_name, level_nr);
+}
- level->fieldx = 0;
- level->fieldy = 0;
+static void LoadLevel_InitStandardElements(struct LevelInfo *level)
+{
+ int i, x, y;
- // start with topmost tile row
- y = 0;
- }
+ // map elements that have changed in newer versions
+ level->amoeba_content = getMappedElementByVersion(level->amoeba_content,
+ level->game_version);
+ for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
+ for (x = 0; x < 3; x++)
+ for (y = 0; y < 3; y++)
+ level->yamyam_content[i].e[x][y] =
+ getMappedElementByVersion(level->yamyam_content[i].e[x][y],
+ level->game_version);
- // skip playfield line if larger row than allowed
- if (y >= MAX_LEV_FIELDY)
- continue;
+}
- // start with leftmost tile column
- x = 0;
+static void LoadLevel_InitCustomElements(struct LevelInfo *level)
+{
+ int i, j;
- // read playfield elements from line
- for (line_ptr = line; *line_ptr; line_ptr++)
+ // map custom element change events that have changed in newer versions
+ // (these following values were accidentally changed in version 3.0.1)
+ // (this seems to be needed only for 'ab_levelset3' and 'ab_levelset4')
+ if (level->game_version <= VERSION_IDENT(3,0,0,0))
+ {
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
{
- int mapped_sb_element = getMappedElement_SB(*line_ptr, load_xsb_to_ces);
-
- // stop parsing playfield line if larger column than allowed
- if (x >= MAX_LEV_FIELDX)
- break;
+ int element = EL_CUSTOM_START + i;
- if (mapped_sb_element == EL_UNDEFINED)
+ // order of checking and copying events to be mapped is important
+ // (do not change the start and end value -- they are constant)
+ for (j = CE_BY_OTHER_ACTION; j >= CE_VALUE_GETS_ZERO; j--)
{
- invalid_playfield_char = TRUE;
-
- break;
+ if (HAS_CHANGE_EVENT(element, j - 2))
+ {
+ SET_CHANGE_EVENT(element, j - 2, FALSE);
+ SET_CHANGE_EVENT(element, j, TRUE);
+ }
}
- level->field[x][y] = mapped_sb_element;
+ // order of checking and copying events to be mapped is important
+ // (do not change the start and end value -- they are constant)
+ for (j = CE_PLAYER_COLLECTS_X; j >= CE_HITTING_SOMETHING; j--)
+ {
+ if (HAS_CHANGE_EVENT(element, j - 1))
+ {
+ SET_CHANGE_EVENT(element, j - 1, FALSE);
+ SET_CHANGE_EVENT(element, j, TRUE);
+ }
+ }
+ }
+ }
- // continue with next tile column
- x++;
+ // initialize "can_change" field for old levels with only one change page
+ if (level->game_version <= VERSION_IDENT(3,0,2,0))
+ {
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
- level->fieldx = MAX(x, level->fieldx);
+ if (CAN_CHANGE(element))
+ element_info[element].change->can_change = TRUE;
}
+ }
- if (invalid_playfield_char)
+ // correct custom element values (for old levels without these options)
+ if (level->game_version < VERSION_IDENT(3,1,1,0))
+ {
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
{
- // if first playfield line, treat invalid lines as comment lines
- if (y == 0)
- reading_playfield = FALSE;
+ int element = EL_CUSTOM_START + i;
+ struct ElementInfo *ei = &element_info[element];
- continue;
+ if (ei->access_direction == MV_NO_DIRECTION)
+ ei->access_direction = MV_ALL_DIRECTIONS;
}
-
- // continue with next tile row
- y++;
}
- closeFile(file);
+ // correct custom element values (fix invalid values for all versions)
+ if (1)
+ {
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+ struct ElementInfo *ei = &element_info[element];
- level->fieldy = y;
+ for (j = 0; j < ei->num_change_pages; j++)
+ {
+ struct ElementChangeInfo *change = &ei->change_page[j];
- level->fieldx = MIN(MAX(MIN_LEV_FIELDX, level->fieldx), MAX_LEV_FIELDX);
- level->fieldy = MIN(MAX(MIN_LEV_FIELDY, level->fieldy), MAX_LEV_FIELDY);
+ if (change->trigger_player == CH_PLAYER_NONE)
+ change->trigger_player = CH_PLAYER_ANY;
- if (!reading_playfield)
+ if (change->trigger_side == CH_SIDE_NONE)
+ change->trigger_side = CH_SIDE_ANY;
+ }
+ }
+ }
+
+ // initialize "can_explode" field for old levels which did not store this
+ // !!! CHECK THIS -- "<= 3,1,0,0" IS PROBABLY WRONG !!!
+ if (level->game_version <= VERSION_IDENT(3,1,0,0))
{
- level->no_valid_file = TRUE;
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
- Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename);
+ if (EXPLODES_1X1_OLD(element))
+ element_info[element].explosion_type = EXPLODES_1X1;
- return;
+ SET_PROPERTY(element, EP_CAN_EXPLODE, (EXPLODES_BY_FIRE(element) ||
+ EXPLODES_SMASHED(element) ||
+ EXPLODES_IMPACT(element)));
+ }
}
- if (*level_name != '\0')
- {
- strncpy(level->name, level_name, MAX_LEVEL_NAME_LEN);
- level->name[MAX_LEVEL_NAME_LEN] = '\0';
- }
- else if (*last_comment != '\0')
+ // correct previously hard-coded move delay values for maze runner style
+ if (level->game_version < VERSION_IDENT(3,1,1,0))
{
- strncpy(level->name, last_comment, MAX_LEVEL_NAME_LEN);
- level->name[MAX_LEVEL_NAME_LEN] = '\0';
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+
+ if (element_info[element].move_pattern & MV_MAZE_RUNNER_STYLE)
+ {
+ // previously hard-coded and therefore ignored
+ element_info[element].move_delay_fixed = 9;
+ element_info[element].move_delay_random = 0;
+ }
+ }
}
- else
+
+ // set some other uninitialized values of custom elements in older levels
+ if (level->game_version < VERSION_IDENT(3,1,0,0))
{
- sprintf(level->name, "--> Level %d <--", level_file_info->nr);
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+
+ element_info[element].access_direction = MV_ALL_DIRECTIONS;
+
+ element_info[element].explosion_delay = 17;
+ element_info[element].ignition_delay = 8;
+ }
}
- // set all empty fields beyond the border walls to invisible steel wall
- for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++)
+ // set mouse click change events to work for left/middle/right mouse button
+ if (level->game_version < VERSION_IDENT(4,2,3,0))
{
- if ((x == 0 || x == level->fieldx - 1 ||
- y == 0 || y == level->fieldy - 1) &&
- level->field[x][y] == getMappedElement_SB(' ', load_xsb_to_ces))
- FloodFillLevel(x, y, getMappedElement_SB('_', load_xsb_to_ces),
- level->field, level->fieldx, level->fieldy);
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+ struct ElementInfo *ei = &element_info[element];
+
+ for (j = 0; j < ei->num_change_pages; j++)
+ {
+ struct ElementChangeInfo *change = &ei->change_page[j];
+
+ if (change->has_event[CE_CLICKED_BY_MOUSE] ||
+ change->has_event[CE_PRESSED_BY_MOUSE] ||
+ change->has_event[CE_MOUSE_CLICKED_ON_X] ||
+ change->has_event[CE_MOUSE_PRESSED_ON_X])
+ change->trigger_side = CH_SIDE_ANY;
+ }
+ }
}
+}
- // set special level settings for Sokoban levels
+static void LoadLevel_InitElements(struct LevelInfo *level)
+{
+ LoadLevel_InitStandardElements(level);
- level->time = 0;
- level->use_step_counter = TRUE;
+ if (level->file_has_custom_elements)
+ LoadLevel_InitCustomElements(level);
- if (load_xsb_to_ces)
- {
- // special global settings can now be set in level template
+ // initialize element properties for level editor etc.
+ InitElementPropertiesEngine(level->game_version);
+ InitElementPropertiesGfxElement();
+}
+
+static void LoadLevel_InitPlayfield(struct LevelInfo *level)
+{
+ int x, y;
+
+ // map elements that have changed in newer versions
+ for (y = 0; y < level->fieldy; y++)
+ for (x = 0; x < level->fieldx; x++)
+ level->field[x][y] = getMappedElementByVersion(level->field[x][y],
+ level->game_version);
- level->use_custom_template = TRUE;
- }
-}
+ // clear unused playfield data (nicer if level gets resized in editor)
+ for (x = 0; x < MAX_LEV_FIELDX; x++)
+ for (y = 0; y < MAX_LEV_FIELDY; y++)
+ if (x >= level->fieldx || y >= level->fieldy)
+ level->field[x][y] = EL_EMPTY;
+ // copy elements to runtime playfield array
+ for (x = 0; x < MAX_LEV_FIELDX; x++)
+ for (y = 0; y < MAX_LEV_FIELDY; y++)
+ Tile[x][y] = level->field[x][y];
-// -------------------------------------------------------------------------
-// functions for handling native levels
-// -------------------------------------------------------------------------
+ // initialize level size variables for faster access
+ lev_fieldx = level->fieldx;
+ lev_fieldy = level->fieldy;
-static void LoadLevelFromFileInfo_EM(struct LevelInfo *level,
- struct LevelFileInfo *level_file_info,
- boolean level_info_only)
-{
- if (!LoadNativeLevel_EM(level_file_info->filename, level_info_only))
- level->no_valid_file = TRUE;
+ // determine border element for this level
+ if (level->file_info.type == LEVEL_FILE_TYPE_DC)
+ BorderElement = EL_EMPTY; // (in editor, SetBorderElement() is used)
+ else
+ SetBorderElement();
}
-static void LoadLevelFromFileInfo_SP(struct LevelInfo *level,
- struct LevelFileInfo *level_file_info,
- boolean level_info_only)
+static void LoadLevel_InitNativeEngines(struct LevelInfo *level)
{
- int pos = 0;
-
- // determine position of requested level inside level package
- if (level_file_info->packed)
- pos = level_file_info->nr - leveldir_current->first_level;
+ struct LevelFileInfo *level_file_info = &level->file_info;
- if (!LoadNativeLevel_SP(level_file_info->filename, pos, level_info_only))
- level->no_valid_file = TRUE;
+ if (level_file_info->type == LEVEL_FILE_TYPE_RND)
+ CopyNativeLevel_RND_to_Native(level);
}
-static void LoadLevelFromFileInfo_MM(struct LevelInfo *level,
- struct LevelFileInfo *level_file_info,
- boolean level_info_only)
+static void LoadLevelTemplate_LoadAndInit(void)
{
- if (!LoadNativeLevel_MM(level_file_info->filename, level_info_only))
- level->no_valid_file = TRUE;
-}
+ LoadLevelFromFileInfo(&level_template, &level_template.file_info, FALSE);
-void CopyNativeLevel_RND_to_Native(struct LevelInfo *level)
-{
- if (level->game_engine_type == GAME_ENGINE_TYPE_EM)
- CopyNativeLevel_RND_to_EM(level);
- else if (level->game_engine_type == GAME_ENGINE_TYPE_SP)
- CopyNativeLevel_RND_to_SP(level);
- else if (level->game_engine_type == GAME_ENGINE_TYPE_MM)
- CopyNativeLevel_RND_to_MM(level);
-}
+ LoadLevel_InitVersion(&level_template);
+ LoadLevel_InitElements(&level_template);
+ LoadLevel_InitSettings(&level_template);
-void CopyNativeLevel_Native_to_RND(struct LevelInfo *level)
-{
- if (level->game_engine_type == GAME_ENGINE_TYPE_EM)
- CopyNativeLevel_EM_to_RND(level);
- else if (level->game_engine_type == GAME_ENGINE_TYPE_SP)
- CopyNativeLevel_SP_to_RND(level);
- else if (level->game_engine_type == GAME_ENGINE_TYPE_MM)
- CopyNativeLevel_MM_to_RND(level);
+ ActivateLevelTemplate();
}
-void SaveNativeLevel(struct LevelInfo *level)
+void LoadLevelTemplate(int nr)
{
- if (level->game_engine_type == GAME_ENGINE_TYPE_SP)
+ if (!fileExists(getGlobalLevelTemplateFilename()))
{
- char *basename = getSingleLevelBasenameExt(level->file_info.nr, "sp");
- char *filename = getLevelFilenameFromBasename(basename);
+ Warn("no level template found for this level");
- CopyNativeLevel_RND_to_SP(level);
- CopyNativeTape_RND_to_SP(level);
-
- SaveNativeLevel_SP(filename);
+ return;
}
+
+ setLevelFileInfo(&level_template.file_info, nr);
+
+ LoadLevelTemplate_LoadAndInit();
}
+static void LoadNetworkLevelTemplate(struct NetworkLevelInfo *network_level)
+{
+ copyLevelFileInfo(&network_level->tmpl_info, &level_template.file_info);
-// ----------------------------------------------------------------------------
-// functions for loading generic level
-// ----------------------------------------------------------------------------
+ LoadLevelTemplate_LoadAndInit();
+}
-static void LoadLevelFromFileInfo(struct LevelInfo *level,
- struct LevelFileInfo *level_file_info,
- boolean level_info_only)
+static void LoadLevel_LoadAndInit(struct NetworkLevelInfo *network_level)
{
- // always start with reliable default values
- setLevelInfoToDefaults(level, level_info_only, TRUE);
+ LoadLevelFromFileInfo(&level, &level.file_info, FALSE);
- switch (level_file_info->type)
+ if (level.use_custom_template)
{
- case LEVEL_FILE_TYPE_RND:
- LoadLevelFromFileInfo_RND(level, level_file_info, level_info_only);
- break;
+ if (network_level != NULL)
+ LoadNetworkLevelTemplate(network_level);
+ else
+ LoadLevelTemplate(-1);
+ }
- case LEVEL_FILE_TYPE_EM:
- LoadLevelFromFileInfo_EM(level, level_file_info, level_info_only);
- level->game_engine_type = GAME_ENGINE_TYPE_EM;
- break;
+ LoadLevel_InitVersion(&level);
+ LoadLevel_InitElements(&level);
+ LoadLevel_InitPlayfield(&level);
+ LoadLevel_InitSettings(&level);
- case LEVEL_FILE_TYPE_SP:
- LoadLevelFromFileInfo_SP(level, level_file_info, level_info_only);
- level->game_engine_type = GAME_ENGINE_TYPE_SP;
- break;
+ LoadLevel_InitNativeEngines(&level);
+}
- case LEVEL_FILE_TYPE_MM:
- LoadLevelFromFileInfo_MM(level, level_file_info, level_info_only);
- level->game_engine_type = GAME_ENGINE_TYPE_MM;
- break;
+void LoadLevel(int nr)
+{
+ SetLevelSetInfo(leveldir_current->identifier, nr);
- case LEVEL_FILE_TYPE_DC:
- LoadLevelFromFileInfo_DC(level, level_file_info, level_info_only);
- break;
+ setLevelFileInfo(&level.file_info, nr);
- case LEVEL_FILE_TYPE_SB:
- LoadLevelFromFileInfo_SB(level, level_file_info, level_info_only);
- break;
+ LoadLevel_LoadAndInit(NULL);
+}
- default:
- LoadLevelFromFileInfo_RND(level, level_file_info, level_info_only);
- break;
- }
+void LoadLevelInfoOnly(int nr)
+{
+ setLevelFileInfo(&level.file_info, nr);
- // if level file is invalid, restore level structure to default values
- if (level->no_valid_file)
- setLevelInfoToDefaults(level, level_info_only, FALSE);
+ LoadLevelFromFileInfo(&level, &level.file_info, TRUE);
+}
- if (level->game_engine_type == GAME_ENGINE_TYPE_UNKNOWN)
- level->game_engine_type = GAME_ENGINE_TYPE_RND;
+void LoadNetworkLevel(struct NetworkLevelInfo *network_level)
+{
+ SetLevelSetInfo(network_level->leveldir_identifier,
+ network_level->file_info.nr);
- if (level_file_info->type != LEVEL_FILE_TYPE_RND)
- CopyNativeLevel_Native_to_RND(level);
+ copyLevelFileInfo(&network_level->file_info, &level.file_info);
+
+ LoadLevel_LoadAndInit(network_level);
}
-void LoadLevelFromFilename(struct LevelInfo *level, char *filename)
+static int SaveLevel_VERS(FILE *file, struct LevelInfo *level)
{
- static struct LevelFileInfo level_file_info;
+ int chunk_size = 0;
- // always start with reliable default values
- setFileInfoToDefaults(&level_file_info);
+ chunk_size += putFileVersion(file, level->file_version);
+ chunk_size += putFileVersion(file, level->game_version);
- level_file_info.nr = 0; // unknown level number
- level_file_info.type = LEVEL_FILE_TYPE_RND; // no others supported yet
+ return chunk_size;
+}
- setString(&level_file_info.filename, filename);
+static int SaveLevel_DATE(FILE *file, struct LevelInfo *level)
+{
+ int chunk_size = 0;
- LoadLevelFromFileInfo(level, &level_file_info, FALSE);
+ chunk_size += putFile16BitBE(file, level->creation_date.year);
+ chunk_size += putFile8Bit(file, level->creation_date.month);
+ chunk_size += putFile8Bit(file, level->creation_date.day);
+
+ return chunk_size;
}
-static void LoadLevel_InitVersion(struct LevelInfo *level)
+#if ENABLE_HISTORIC_CHUNKS
+static void SaveLevel_HEAD(FILE *file, struct LevelInfo *level)
{
- int i, j;
+ int i, x, y;
- if (leveldir_current == NULL) // only when dumping level
- return;
+ putFile8Bit(file, level->fieldx);
+ putFile8Bit(file, level->fieldy);
- // all engine modifications also valid for levels which use latest engine
- if (level->game_version < VERSION_IDENT(3,2,0,5))
- {
- // time bonus score was given for 10 s instead of 1 s before 3.2.0-5
- level->score[SC_TIME_BONUS] /= 10;
- }
+ putFile16BitBE(file, level->time);
+ putFile16BitBE(file, level->gems_needed);
- if (leveldir_current->latest_engine)
- {
- // ---------- use latest game engine --------------------------------------
+ for (i = 0; i < MAX_LEVEL_NAME_LEN; i++)
+ putFile8Bit(file, level->name[i]);
- /* For all levels which are forced to use the latest game engine version
- (normally all but user contributed, private and undefined levels), set
- the game engine version to the actual version; this allows for actual
- corrections in the game engine to take effect for existing, converted
- levels (from "classic" or other existing games) to make the emulation
- of the corresponding game more accurate, while (hopefully) not breaking
- existing levels created from other players. */
+ for (i = 0; i < LEVEL_SCORE_ELEMENTS; i++)
+ putFile8Bit(file, level->score[i]);
- level->game_version = GAME_VERSION_ACTUAL;
+ for (i = 0; i < STD_ELEMENT_CONTENTS; i++)
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ putFile8Bit(file, (level->encoding_16bit_yamyam ? EL_EMPTY :
+ level->yamyam_content[i].e[x][y]));
+ putFile8Bit(file, level->amoeba_speed);
+ putFile8Bit(file, level->time_magic_wall);
+ putFile8Bit(file, level->time_wheel);
+ putFile8Bit(file, (level->encoding_16bit_amoeba ? EL_EMPTY :
+ level->amoeba_content));
+ putFile8Bit(file, (level->initial_player_stepsize == STEPSIZE_FAST ? 1 : 0));
+ putFile8Bit(file, (level->initial_gravity ? 1 : 0));
+ putFile8Bit(file, (level->encoding_16bit_field ? 1 : 0));
+ putFile8Bit(file, (level->em_slippery_gems ? 1 : 0));
- /* Set special EM style gems behaviour: EM style gems slip down from
- normal, steel and growing wall. As this is a more fundamental change,
- it seems better to set the default behaviour to "off" (as it is more
- natural) and make it configurable in the level editor (as a property
- of gem style elements). Already existing converted levels (neither
- private nor contributed levels) are changed to the new behaviour. */
+ putFile8Bit(file, (level->use_custom_template ? 1 : 0));
- if (level->file_version < FILE_VERSION_2_0)
- level->em_slippery_gems = TRUE;
+ putFile8Bit(file, (level->block_last_field ? 1 : 0));
+ putFile8Bit(file, (level->sp_block_last_field ? 1 : 0));
+ putFile32BitBE(file, level->can_move_into_acid_bits);
+ putFile8Bit(file, level->dont_collide_with_bits);
- return;
- }
+ putFile8Bit(file, (level->use_spring_bug ? 1 : 0));
+ putFile8Bit(file, (level->use_step_counter ? 1 : 0));
- // ---------- use game engine the level was created with --------------------
+ putFile8Bit(file, (level->instant_relocation ? 1 : 0));
+ putFile8Bit(file, (level->can_pass_to_walkable ? 1 : 0));
+ putFile8Bit(file, (level->grow_into_diggable ? 1 : 0));
- /* For all levels which are not forced to use the latest game engine
- version (normally user contributed, private and undefined levels),
- use the version of the game engine the levels were created for.
+ putFile8Bit(file, level->game_engine_type);
- Since 2.0.1, the game engine version is now directly stored
- in the level file (chunk "VERS"), so there is no need anymore
- to set the game version from the file version (except for old,
- pre-2.0 levels, where the game version is still taken from the
- file format version used to store the level -- see above). */
+ WriteUnusedBytesToFile(file, LEVEL_CHUNK_HEAD_UNUSED);
+}
+#endif
- // player was faster than enemies in 1.0.0 and before
- if (level->file_version == FILE_VERSION_1_0)
- for (i = 0; i < MAX_PLAYERS; i++)
- level->initial_player_stepsize[i] = STEPSIZE_FAST;
+static int SaveLevel_NAME(FILE *file, struct LevelInfo *level)
+{
+ int chunk_size = 0;
+ int i;
- // default behaviour for EM style gems was "slippery" only in 2.0.1
- if (level->game_version == VERSION_IDENT(2,0,1,0))
- level->em_slippery_gems = TRUE;
+ for (i = 0; i < MAX_LEVEL_NAME_LEN; i++)
+ chunk_size += putFile8Bit(file, level->name[i]);
- // springs could be pushed over pits before (pre-release version) 2.2.0
- if (level->game_version < VERSION_IDENT(2,2,0,0))
- level->use_spring_bug = TRUE;
+ return chunk_size;
+}
- if (level->game_version < VERSION_IDENT(3,2,0,5))
- {
- // time orb caused limited time in endless time levels before 3.2.0-5
- level->use_time_orb_bug = TRUE;
+static int SaveLevel_AUTH(FILE *file, struct LevelInfo *level)
+{
+ int chunk_size = 0;
+ int i;
- // default behaviour for snapping was "no snap delay" before 3.2.0-5
- level->block_snap_field = FALSE;
+ for (i = 0; i < MAX_LEVEL_AUTHOR_LEN; i++)
+ chunk_size += putFile8Bit(file, level->author[i]);
- // extra time score was same value as time left score before 3.2.0-5
- level->extra_time_score = level->score[SC_TIME_BONUS];
- }
+ return chunk_size;
+}
- if (level->game_version < VERSION_IDENT(3,2,0,7))
- {
- // default behaviour for snapping was "not continuous" before 3.2.0-7
- level->continuous_snapping = FALSE;
- }
+#if ENABLE_HISTORIC_CHUNKS
+static int SaveLevel_BODY(FILE *file, struct LevelInfo *level)
+{
+ int chunk_size = 0;
+ int x, y;
- // only few elements were able to actively move into acid before 3.1.0
- // trigger settings did not exist before 3.1.0; set to default "any"
- if (level->game_version < VERSION_IDENT(3,1,0,0))
- {
- // correct "can move into acid" settings (all zero in old levels)
+ for (y = 0; y < level->fieldy; y++)
+ for (x = 0; x < level->fieldx; x++)
+ if (level->encoding_16bit_field)
+ chunk_size += putFile16BitBE(file, level->field[x][y]);
+ else
+ chunk_size += putFile8Bit(file, level->field[x][y]);
- level->can_move_into_acid_bits = 0; // nothing can move into acid
- level->dont_collide_with_bits = 0; // nothing is deadly when colliding
+ return chunk_size;
+}
+#endif
- setMoveIntoAcidProperty(level, EL_ROBOT, TRUE);
- setMoveIntoAcidProperty(level, EL_SATELLITE, TRUE);
- setMoveIntoAcidProperty(level, EL_PENGUIN, TRUE);
- setMoveIntoAcidProperty(level, EL_BALLOON, TRUE);
+static int SaveLevel_BODY(FILE *file, struct LevelInfo *level)
+{
+ int chunk_size = 0;
+ int x, y;
- for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
- SET_PROPERTY(EL_CUSTOM_START + i, EP_CAN_MOVE_INTO_ACID, TRUE);
+ for (y = 0; y < level->fieldy; y++)
+ for (x = 0; x < level->fieldx; x++)
+ chunk_size += putFile16BitBE(file, level->field[x][y]);
- // correct trigger settings (stored as zero == "none" in old levels)
+ return chunk_size;
+}
- for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
- {
- int element = EL_CUSTOM_START + i;
- struct ElementInfo *ei = &element_info[element];
+#if ENABLE_HISTORIC_CHUNKS
+static void SaveLevel_CONT(FILE *file, struct LevelInfo *level)
+{
+ int i, x, y;
- for (j = 0; j < ei->num_change_pages; j++)
- {
- struct ElementChangeInfo *change = &ei->change_page[j];
+ putFile8Bit(file, EL_YAMYAM);
+ putFile8Bit(file, level->num_yamyam_contents);
+ putFile8Bit(file, 0);
+ putFile8Bit(file, 0);
- change->trigger_player = CH_PLAYER_ANY;
- change->trigger_page = CH_PAGE_ANY;
- }
- }
- }
+ for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ if (level->encoding_16bit_field)
+ putFile16BitBE(file, level->yamyam_content[i].e[x][y]);
+ else
+ putFile8Bit(file, level->yamyam_content[i].e[x][y]);
+}
+#endif
- // try to detect and fix "Snake Bite" levels, which are broken with 3.2.0
- {
- int element = EL_CUSTOM_256;
- struct ElementInfo *ei = &element_info[element];
- struct ElementChangeInfo *change = &ei->change_page[0];
+#if ENABLE_HISTORIC_CHUNKS
+static void SaveLevel_CNT2(FILE *file, struct LevelInfo *level, int element)
+{
+ int i, x, y;
+ int num_contents, content_xsize, content_ysize;
+ int content_array[MAX_ELEMENT_CONTENTS][3][3];
- /* This is needed to fix a problem that was caused by a bugfix in function
- game.c/CreateFieldExt() introduced with 3.2.0 that corrects the behaviour
- when a custom element changes to EL_SOKOBAN_FIELD_PLAYER (before, it did
- not replace walkable elements, but instead just placed the player on it,
- without placing the Sokoban field under the player). Unfortunately, this
- breaks "Snake Bite" style levels when the snake is halfway through a door
- that just closes (the snake head is still alive and can be moved in this
- case). This can be fixed by replacing the EL_SOKOBAN_FIELD_PLAYER by the
- player (without Sokoban element) which then gets killed as designed). */
+ if (element == EL_YAMYAM)
+ {
+ num_contents = level->num_yamyam_contents;
+ content_xsize = 3;
+ content_ysize = 3;
- if ((strncmp(leveldir_current->identifier, "snake_bite", 10) == 0 ||
- strncmp(ei->description, "pause b4 death", 14) == 0) &&
- change->target_element == EL_SOKOBAN_FIELD_PLAYER)
- change->target_element = EL_PLAYER_1;
+ for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ content_array[i][x][y] = level->yamyam_content[i].e[x][y];
}
-
- // try to detect and fix "Zelda" style levels, which are broken with 3.2.5
- if (level->game_version < VERSION_IDENT(3,2,5,0))
+ else if (element == EL_BD_AMOEBA)
{
- /* This is needed to fix a problem that was caused by a bugfix in function
- game.c/CheckTriggeredElementChangeExt() introduced with 3.2.5 that
- corrects the behaviour when a custom element changes to another custom
- element with a higher element number that has change actions defined.
- Normally, only one change per frame is allowed for custom elements.
- Therefore, it is checked if a custom element already changed in the
- current frame; if it did, subsequent changes are suppressed.
- Unfortunately, this is only checked for element changes, but not for
- change actions, which are still executed. As the function above loops
- through all custom elements from lower to higher, an element change
- resulting in a lower CE number won't be checked again, while a target
- element with a higher number will also be checked, and potential change
- actions will get executed for this CE, too (which is wrong), while
- further changes are ignored (which is correct). As this bugfix breaks
- Zelda II (and introduces graphical bugs to Zelda I, and also breaks a
- few other levels like Alan Bond's "FMV"), allow the previous, incorrect
- behaviour for existing levels and tapes that make use of this bug */
+ num_contents = 1;
+ content_xsize = 1;
+ content_ysize = 1;
- level->use_action_after_change_bug = TRUE;
+ for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ content_array[i][x][y] = EL_EMPTY;
+ content_array[0][0][0] = level->amoeba_content;
}
+ else
+ {
+ // chunk header already written -- write empty chunk data
+ WriteUnusedBytesToFile(file, LEVEL_CHUNK_CNT2_SIZE);
- // not centering level after relocating player was default only in 3.2.3
- if (level->game_version == VERSION_IDENT(3,2,3,0)) // (no pre-releases)
- level->shifted_relocation = TRUE;
+ Warn("cannot save content for element '%d'", element);
- // EM style elements always chain-exploded in R'n'D engine before 3.2.6
- if (level->game_version < VERSION_IDENT(3,2,6,0))
- level->em_explodes_by_fire = TRUE;
+ return;
+ }
- // levels were solved by the first player entering an exit up to 4.1.0.0
- if (level->game_version <= VERSION_IDENT(4,1,0,0))
- level->solved_by_one_player = TRUE;
+ putFile16BitBE(file, element);
+ putFile8Bit(file, num_contents);
+ putFile8Bit(file, content_xsize);
+ putFile8Bit(file, content_ysize);
- // game logic of "game of life" and "biomaze" was buggy before 4.1.1.1
- if (level->game_version < VERSION_IDENT(4,1,1,1))
- level->use_life_bugs = TRUE;
+ WriteUnusedBytesToFile(file, LEVEL_CHUNK_CNT2_UNUSED);
- // only Sokoban fields (but not objects) had to be solved before 4.1.1.1
- if (level->game_version < VERSION_IDENT(4,1,1,1))
- level->sb_objects_needed = FALSE;
+ for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ putFile16BitBE(file, content_array[i][x][y]);
}
+#endif
-static void LoadLevel_InitStandardElements(struct LevelInfo *level)
+#if ENABLE_HISTORIC_CHUNKS
+static int SaveLevel_CNT3(FILE *file, struct LevelInfo *level, int element)
{
- int i, x, y;
+ int envelope_nr = element - EL_ENVELOPE_1;
+ int envelope_len = strlen(level->envelope_text[envelope_nr]) + 1;
+ int chunk_size = 0;
+ int i;
- // map elements that have changed in newer versions
- level->amoeba_content = getMappedElementByVersion(level->amoeba_content,
- level->game_version);
- for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
- for (x = 0; x < 3; x++)
- for (y = 0; y < 3; y++)
- level->yamyam_content[i].e[x][y] =
- getMappedElementByVersion(level->yamyam_content[i].e[x][y],
- level->game_version);
+ chunk_size += putFile16BitBE(file, element);
+ chunk_size += putFile16BitBE(file, envelope_len);
+ chunk_size += putFile8Bit(file, level->envelope_xsize[envelope_nr]);
+ chunk_size += putFile8Bit(file, level->envelope_ysize[envelope_nr]);
+
+ WriteUnusedBytesToFile(file, LEVEL_CHUNK_CNT3_UNUSED);
+ chunk_size += LEVEL_CHUNK_CNT3_UNUSED;
+
+ for (i = 0; i < envelope_len; i++)
+ chunk_size += putFile8Bit(file, level->envelope_text[envelope_nr][i]);
+ return chunk_size;
}
+#endif
-static void LoadLevel_InitCustomElements(struct LevelInfo *level)
+#if ENABLE_HISTORIC_CHUNKS
+static void SaveLevel_CUS1(FILE *file, struct LevelInfo *level,
+ int num_changed_custom_elements)
{
- int i, j;
+ int i, check = 0;
- // map custom element change events that have changed in newer versions
- // (these following values were accidentally changed in version 3.0.1)
- // (this seems to be needed only for 'ab_levelset3' and 'ab_levelset4')
- if (level->game_version <= VERSION_IDENT(3,0,0,0))
- {
- for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
- {
- int element = EL_CUSTOM_START + i;
+ putFile16BitBE(file, num_changed_custom_elements);
- // order of checking and copying events to be mapped is important
- // (do not change the start and end value -- they are constant)
- for (j = CE_BY_OTHER_ACTION; j >= CE_VALUE_GETS_ZERO; j--)
- {
- if (HAS_CHANGE_EVENT(element, j - 2))
- {
- SET_CHANGE_EVENT(element, j - 2, FALSE);
- SET_CHANGE_EVENT(element, j, TRUE);
- }
- }
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
- // order of checking and copying events to be mapped is important
- // (do not change the start and end value -- they are constant)
- for (j = CE_PLAYER_COLLECTS_X; j >= CE_HITTING_SOMETHING; j--)
+ struct ElementInfo *ei = &element_info[element];
+
+ if (ei->properties[EP_BITFIELD_BASE_NR] != EP_BITMASK_DEFAULT)
+ {
+ if (check < num_changed_custom_elements)
{
- if (HAS_CHANGE_EVENT(element, j - 1))
- {
- SET_CHANGE_EVENT(element, j - 1, FALSE);
- SET_CHANGE_EVENT(element, j, TRUE);
- }
+ putFile16BitBE(file, element);
+ putFile32BitBE(file, ei->properties[EP_BITFIELD_BASE_NR]);
}
+
+ check++;
}
}
- // initialize "can_change" field for old levels with only one change page
- if (level->game_version <= VERSION_IDENT(3,0,2,0))
- {
- for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
- {
- int element = EL_CUSTOM_START + i;
+ if (check != num_changed_custom_elements) // should not happen
+ Warn("inconsistent number of custom element properties");
+}
+#endif
- if (CAN_CHANGE(element))
- element_info[element].change->can_change = TRUE;
- }
- }
+#if ENABLE_HISTORIC_CHUNKS
+static void SaveLevel_CUS2(FILE *file, struct LevelInfo *level,
+ int num_changed_custom_elements)
+{
+ int i, check = 0;
- // correct custom element values (for old levels without these options)
- if (level->game_version < VERSION_IDENT(3,1,1,0))
+ putFile16BitBE(file, num_changed_custom_elements);
+
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
{
- for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ int element = EL_CUSTOM_START + i;
+
+ if (element_info[element].change->target_element != EL_EMPTY_SPACE)
{
- int element = EL_CUSTOM_START + i;
- struct ElementInfo *ei = &element_info[element];
+ if (check < num_changed_custom_elements)
+ {
+ putFile16BitBE(file, element);
+ putFile16BitBE(file, element_info[element].change->target_element);
+ }
- if (ei->access_direction == MV_NO_DIRECTION)
- ei->access_direction = MV_ALL_DIRECTIONS;
+ check++;
}
}
- // correct custom element values (fix invalid values for all versions)
- if (1)
+ if (check != num_changed_custom_elements) // should not happen
+ Warn("inconsistent number of custom target elements");
+}
+#endif
+
+#if ENABLE_HISTORIC_CHUNKS
+static void SaveLevel_CUS3(FILE *file, struct LevelInfo *level,
+ int num_changed_custom_elements)
+{
+ int i, j, x, y, check = 0;
+
+ putFile16BitBE(file, num_changed_custom_elements);
+
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
{
- for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
- {
- int element = EL_CUSTOM_START + i;
- struct ElementInfo *ei = &element_info[element];
+ int element = EL_CUSTOM_START + i;
+ struct ElementInfo *ei = &element_info[element];
- for (j = 0; j < ei->num_change_pages; j++)
+ if (ei->modified_settings)
+ {
+ if (check < num_changed_custom_elements)
{
- struct ElementChangeInfo *change = &ei->change_page[j];
+ putFile16BitBE(file, element);
- if (change->trigger_player == CH_PLAYER_NONE)
- change->trigger_player = CH_PLAYER_ANY;
+ for (j = 0; j < MAX_ELEMENT_NAME_LEN; j++)
+ putFile8Bit(file, ei->description[j]);
- if (change->trigger_side == CH_SIDE_NONE)
- change->trigger_side = CH_SIDE_ANY;
- }
- }
- }
+ putFile32BitBE(file, ei->properties[EP_BITFIELD_BASE_NR]);
- // initialize "can_explode" field for old levels which did not store this
- // !!! CHECK THIS -- "<= 3,1,0,0" IS PROBABLY WRONG !!!
- if (level->game_version <= VERSION_IDENT(3,1,0,0))
- {
- for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
- {
- int element = EL_CUSTOM_START + i;
+ // some free bytes for future properties and padding
+ WriteUnusedBytesToFile(file, 7);
- if (EXPLODES_1X1_OLD(element))
- element_info[element].explosion_type = EXPLODES_1X1;
+ putFile8Bit(file, ei->use_gfx_element);
+ putFile16BitBE(file, ei->gfx_element_initial);
- SET_PROPERTY(element, EP_CAN_EXPLODE, (EXPLODES_BY_FIRE(element) ||
- EXPLODES_SMASHED(element) ||
- EXPLODES_IMPACT(element)));
- }
- }
+ putFile8Bit(file, ei->collect_score_initial);
+ putFile8Bit(file, ei->collect_count_initial);
- // correct previously hard-coded move delay values for maze runner style
- if (level->game_version < VERSION_IDENT(3,1,1,0))
- {
- for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
- {
- int element = EL_CUSTOM_START + i;
+ putFile16BitBE(file, ei->push_delay_fixed);
+ putFile16BitBE(file, ei->push_delay_random);
+ putFile16BitBE(file, ei->move_delay_fixed);
+ putFile16BitBE(file, ei->move_delay_random);
- if (element_info[element].move_pattern & MV_MAZE_RUNNER_STYLE)
- {
- // previously hard-coded and therefore ignored
- element_info[element].move_delay_fixed = 9;
- element_info[element].move_delay_random = 0;
- }
- }
- }
+ putFile16BitBE(file, ei->move_pattern);
+ putFile8Bit(file, ei->move_direction_initial);
+ putFile8Bit(file, ei->move_stepsize);
- // set some other uninitialized values of custom elements in older levels
- if (level->game_version < VERSION_IDENT(3,1,0,0))
- {
- for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
- {
- int element = EL_CUSTOM_START + i;
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ putFile16BitBE(file, ei->content.e[x][y]);
- element_info[element].access_direction = MV_ALL_DIRECTIONS;
+ putFile32BitBE(file, ei->change->events);
- element_info[element].explosion_delay = 17;
- element_info[element].ignition_delay = 8;
+ putFile16BitBE(file, ei->change->target_element);
+
+ putFile16BitBE(file, ei->change->delay_fixed);
+ putFile16BitBE(file, ei->change->delay_random);
+ putFile16BitBE(file, ei->change->delay_frames);
+
+ putFile16BitBE(file, ei->change->initial_trigger_element);
+
+ putFile8Bit(file, ei->change->explode);
+ putFile8Bit(file, ei->change->use_target_content);
+ putFile8Bit(file, ei->change->only_if_complete);
+ putFile8Bit(file, ei->change->use_random_replace);
+
+ putFile8Bit(file, ei->change->random_percentage);
+ putFile8Bit(file, ei->change->replace_when);
+
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ putFile16BitBE(file, ei->change->content.e[x][y]);
+
+ putFile8Bit(file, ei->slippery_type);
+
+ // some free bytes for future properties and padding
+ WriteUnusedBytesToFile(file, LEVEL_CPART_CUS3_UNUSED);
+ }
+
+ check++;
}
}
+
+ if (check != num_changed_custom_elements) // should not happen
+ Warn("inconsistent number of custom element properties");
}
+#endif
-static void LoadLevel_InitElements(struct LevelInfo *level)
+#if ENABLE_HISTORIC_CHUNKS
+static void SaveLevel_CUS4(FILE *file, struct LevelInfo *level, int element)
{
- LoadLevel_InitStandardElements(level);
+ struct ElementInfo *ei = &element_info[element];
+ int i, j, x, y;
- if (level->file_has_custom_elements)
- LoadLevel_InitCustomElements(level);
+ // ---------- custom element base property values (96 bytes) ----------------
- // initialize element properties for level editor etc.
- InitElementPropertiesEngine(level->game_version);
- InitElementPropertiesGfxElement();
-}
+ putFile16BitBE(file, element);
-static void LoadLevel_InitPlayfield(struct LevelInfo *level)
-{
- int x, y;
+ for (i = 0; i < MAX_ELEMENT_NAME_LEN; i++)
+ putFile8Bit(file, ei->description[i]);
- // map elements that have changed in newer versions
- for (y = 0; y < level->fieldy; y++)
- for (x = 0; x < level->fieldx; x++)
- level->field[x][y] = getMappedElementByVersion(level->field[x][y],
- level->game_version);
+ putFile32BitBE(file, ei->properties[EP_BITFIELD_BASE_NR]);
- // clear unused playfield data (nicer if level gets resized in editor)
- for (x = 0; x < MAX_LEV_FIELDX; x++)
- for (y = 0; y < MAX_LEV_FIELDY; y++)
- if (x >= level->fieldx || y >= level->fieldy)
- level->field[x][y] = EL_EMPTY;
+ WriteUnusedBytesToFile(file, 4); // reserved for more base properties
+
+ putFile8Bit(file, ei->num_change_pages);
+
+ putFile16BitBE(file, ei->ce_value_fixed_initial);
+ putFile16BitBE(file, ei->ce_value_random_initial);
+ putFile8Bit(file, ei->use_last_ce_value);
+
+ putFile8Bit(file, ei->use_gfx_element);
+ putFile16BitBE(file, ei->gfx_element_initial);
+
+ putFile8Bit(file, ei->collect_score_initial);
+ putFile8Bit(file, ei->collect_count_initial);
+
+ putFile8Bit(file, ei->drop_delay_fixed);
+ putFile8Bit(file, ei->push_delay_fixed);
+ putFile8Bit(file, ei->drop_delay_random);
+ putFile8Bit(file, ei->push_delay_random);
+ putFile16BitBE(file, ei->move_delay_fixed);
+ putFile16BitBE(file, ei->move_delay_random);
+
+ // bits 0 - 15 of "move_pattern" ...
+ putFile16BitBE(file, ei->move_pattern & 0xffff);
+ putFile8Bit(file, ei->move_direction_initial);
+ putFile8Bit(file, ei->move_stepsize);
+
+ putFile8Bit(file, ei->slippery_type);
+
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ putFile16BitBE(file, ei->content.e[x][y]);
+
+ putFile16BitBE(file, ei->move_enter_element);
+ putFile16BitBE(file, ei->move_leave_element);
+ putFile8Bit(file, ei->move_leave_type);
+
+ // ... bits 16 - 31 of "move_pattern" (not nice, but downward compatible)
+ putFile16BitBE(file, (ei->move_pattern >> 16) & 0xffff);
+
+ putFile8Bit(file, ei->access_direction);
+
+ putFile8Bit(file, ei->explosion_delay);
+ putFile8Bit(file, ei->ignition_delay);
+ putFile8Bit(file, ei->explosion_type);
+
+ // some free bytes for future custom property values and padding
+ WriteUnusedBytesToFile(file, 1);
+
+ // ---------- change page property values (48 bytes) ------------------------
- // copy elements to runtime playfield array
- for (x = 0; x < MAX_LEV_FIELDX; x++)
- for (y = 0; y < MAX_LEV_FIELDY; y++)
- Feld[x][y] = level->field[x][y];
+ for (i = 0; i < ei->num_change_pages; i++)
+ {
+ struct ElementChangeInfo *change = &ei->change_page[i];
+ unsigned int event_bits;
- // initialize level size variables for faster access
- lev_fieldx = level->fieldx;
- lev_fieldy = level->fieldy;
+ // bits 0 - 31 of "has_event[]" ...
+ event_bits = 0;
+ for (j = 0; j < MIN(NUM_CHANGE_EVENTS, 32); j++)
+ if (change->has_event[j])
+ event_bits |= (1u << j);
+ putFile32BitBE(file, event_bits);
- // determine border element for this level
- if (level->file_info.type == LEVEL_FILE_TYPE_DC)
- BorderElement = EL_EMPTY; // (in editor, SetBorderElement() is used)
- else
- SetBorderElement();
-}
+ putFile16BitBE(file, change->target_element);
-static void LoadLevel_InitNativeEngines(struct LevelInfo *level)
-{
- struct LevelFileInfo *level_file_info = &level->file_info;
+ putFile16BitBE(file, change->delay_fixed);
+ putFile16BitBE(file, change->delay_random);
+ putFile16BitBE(file, change->delay_frames);
- if (level_file_info->type == LEVEL_FILE_TYPE_RND)
- CopyNativeLevel_RND_to_Native(level);
-}
+ putFile16BitBE(file, change->initial_trigger_element);
-static void LoadLevelTemplate_LoadAndInit(void)
-{
- LoadLevelFromFileInfo(&level_template, &level_template.file_info, FALSE);
+ putFile8Bit(file, change->explode);
+ putFile8Bit(file, change->use_target_content);
+ putFile8Bit(file, change->only_if_complete);
+ putFile8Bit(file, change->use_random_replace);
- LoadLevel_InitVersion(&level_template);
- LoadLevel_InitElements(&level_template);
+ putFile8Bit(file, change->random_percentage);
+ putFile8Bit(file, change->replace_when);
- ActivateLevelTemplate();
-}
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ putFile16BitBE(file, change->target_content.e[x][y]);
-void LoadLevelTemplate(int nr)
-{
- if (!fileExists(getGlobalLevelTemplateFilename()))
- {
- Error(ERR_WARN, "no level template found for this level");
+ putFile8Bit(file, change->can_change);
- return;
- }
+ putFile8Bit(file, change->trigger_side);
- setLevelFileInfo(&level_template.file_info, nr);
+ putFile8Bit(file, change->trigger_player);
+ putFile8Bit(file, (change->trigger_page == CH_PAGE_ANY ? CH_PAGE_ANY_FILE :
+ log_2(change->trigger_page)));
- LoadLevelTemplate_LoadAndInit();
+ putFile8Bit(file, change->has_action);
+ putFile8Bit(file, change->action_type);
+ putFile8Bit(file, change->action_mode);
+ putFile16BitBE(file, change->action_arg);
+
+ // ... bits 32 - 39 of "has_event[]" (not nice, but downward compatible)
+ event_bits = 0;
+ for (j = 32; j < NUM_CHANGE_EVENTS; j++)
+ if (change->has_event[j])
+ event_bits |= (1u << (j - 32));
+ putFile8Bit(file, event_bits);
+ }
}
+#endif
-static void LoadNetworkLevelTemplate(struct NetworkLevelInfo *network_level)
+#if ENABLE_HISTORIC_CHUNKS
+static void SaveLevel_GRP1(FILE *file, struct LevelInfo *level, int element)
{
- copyLevelFileInfo(&network_level->tmpl_info, &level_template.file_info);
+ struct ElementInfo *ei = &element_info[element];
+ struct ElementGroupInfo *group = ei->group;
+ int i;
- LoadLevelTemplate_LoadAndInit();
-}
+ putFile16BitBE(file, element);
-static void LoadLevel_LoadAndInit(struct NetworkLevelInfo *network_level)
-{
- LoadLevelFromFileInfo(&level, &level.file_info, FALSE);
+ for (i = 0; i < MAX_ELEMENT_NAME_LEN; i++)
+ putFile8Bit(file, ei->description[i]);
- if (level.use_custom_template)
- {
- if (network_level != NULL)
- LoadNetworkLevelTemplate(network_level);
- else
- LoadLevelTemplate(-1);
- }
+ putFile8Bit(file, group->num_elements);
- LoadLevel_InitVersion(&level);
- LoadLevel_InitElements(&level);
- LoadLevel_InitPlayfield(&level);
+ putFile8Bit(file, ei->use_gfx_element);
+ putFile16BitBE(file, ei->gfx_element_initial);
- LoadLevel_InitNativeEngines(&level);
+ putFile8Bit(file, group->choice_mode);
+
+ // some free bytes for future values and padding
+ WriteUnusedBytesToFile(file, 3);
+
+ for (i = 0; i < MAX_ELEMENTS_IN_GROUP; i++)
+ putFile16BitBE(file, group->element[i]);
}
+#endif
-void LoadLevel(int nr)
+static int SaveLevel_MicroChunk(FILE *file, struct LevelFileConfigInfo *entry,
+ boolean write_element)
{
- SetLevelSetInfo(leveldir_current->identifier, nr);
+ int save_type = entry->save_type;
+ int data_type = entry->data_type;
+ int conf_type = entry->conf_type;
+ int byte_mask = conf_type & CONF_MASK_BYTES;
+ int element = entry->element;
+ int default_value = entry->default_value;
+ int num_bytes = 0;
+ boolean modified = FALSE;
- setLevelFileInfo(&level.file_info, nr);
+ if (byte_mask != CONF_MASK_MULTI_BYTES)
+ {
+ void *value_ptr = entry->value;
+ int value = (data_type == TYPE_BOOLEAN ? *(boolean *)value_ptr :
+ *(int *)value_ptr);
- LoadLevel_LoadAndInit(NULL);
-}
+ // check if any settings have been modified before saving them
+ if (value != default_value)
+ modified = TRUE;
-void LoadLevelInfoOnly(int nr)
-{
- setLevelFileInfo(&level.file_info, nr);
+ // do not save if explicitly told or if unmodified default settings
+ if ((save_type == SAVE_CONF_NEVER) ||
+ (save_type == SAVE_CONF_WHEN_CHANGED && !modified))
+ return 0;
- LoadLevelFromFileInfo(&level, &level.file_info, TRUE);
-}
+ if (write_element)
+ num_bytes += putFile16BitBE(file, element);
-void LoadNetworkLevel(struct NetworkLevelInfo *network_level)
-{
- SetLevelSetInfo(network_level->leveldir_identifier,
- network_level->file_info.nr);
+ num_bytes += putFile8Bit(file, conf_type);
+ num_bytes += (byte_mask == CONF_MASK_1_BYTE ? putFile8Bit (file, value) :
+ byte_mask == CONF_MASK_2_BYTE ? putFile16BitBE(file, value) :
+ byte_mask == CONF_MASK_4_BYTE ? putFile32BitBE(file, value) :
+ 0);
+ }
+ else if (data_type == TYPE_STRING)
+ {
+ char *default_string = entry->default_string;
+ char *string = (char *)(entry->value);
+ int string_length = strlen(string);
+ int i;
- copyLevelFileInfo(&network_level->file_info, &level.file_info);
+ // check if any settings have been modified before saving them
+ if (!strEqual(string, default_string))
+ modified = TRUE;
- LoadLevel_LoadAndInit(network_level);
-}
+ // do not save if explicitly told or if unmodified default settings
+ if ((save_type == SAVE_CONF_NEVER) ||
+ (save_type == SAVE_CONF_WHEN_CHANGED && !modified))
+ return 0;
-static int SaveLevel_VERS(FILE *file, struct LevelInfo *level)
-{
- int chunk_size = 0;
+ if (write_element)
+ num_bytes += putFile16BitBE(file, element);
- chunk_size += putFileVersion(file, level->file_version);
- chunk_size += putFileVersion(file, level->game_version);
+ num_bytes += putFile8Bit(file, conf_type);
+ num_bytes += putFile16BitBE(file, string_length);
- return chunk_size;
-}
+ for (i = 0; i < string_length; i++)
+ num_bytes += putFile8Bit(file, string[i]);
+ }
+ else if (data_type == TYPE_ELEMENT_LIST)
+ {
+ int *element_array = (int *)(entry->value);
+ int num_elements = *(int *)(entry->num_entities);
+ int i;
-static int SaveLevel_DATE(FILE *file, struct LevelInfo *level)
-{
- int chunk_size = 0;
+ // check if any settings have been modified before saving them
+ for (i = 0; i < num_elements; i++)
+ if (element_array[i] != default_value)
+ modified = TRUE;
- chunk_size += putFile16BitBE(file, level->creation_date.year);
- chunk_size += putFile8Bit(file, level->creation_date.month);
- chunk_size += putFile8Bit(file, level->creation_date.day);
+ // do not save if explicitly told or if unmodified default settings
+ if ((save_type == SAVE_CONF_NEVER) ||
+ (save_type == SAVE_CONF_WHEN_CHANGED && !modified))
+ return 0;
- return chunk_size;
-}
+ if (write_element)
+ num_bytes += putFile16BitBE(file, element);
-#if ENABLE_HISTORIC_CHUNKS
-static void SaveLevel_HEAD(FILE *file, struct LevelInfo *level)
-{
- int i, x, y;
+ num_bytes += putFile8Bit(file, conf_type);
+ num_bytes += putFile16BitBE(file, num_elements * CONF_ELEMENT_NUM_BYTES);
- putFile8Bit(file, level->fieldx);
- putFile8Bit(file, level->fieldy);
+ for (i = 0; i < num_elements; i++)
+ num_bytes += putFile16BitBE(file, element_array[i]);
+ }
+ else if (data_type == TYPE_CONTENT_LIST)
+ {
+ struct Content *content = (struct Content *)(entry->value);
+ int num_contents = *(int *)(entry->num_entities);
+ int i, x, y;
- putFile16BitBE(file, level->time);
- putFile16BitBE(file, level->gems_needed);
+ // check if any settings have been modified before saving them
+ for (i = 0; i < num_contents; i++)
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ if (content[i].e[x][y] != default_value)
+ modified = TRUE;
- for (i = 0; i < MAX_LEVEL_NAME_LEN; i++)
- putFile8Bit(file, level->name[i]);
+ // do not save if explicitly told or if unmodified default settings
+ if ((save_type == SAVE_CONF_NEVER) ||
+ (save_type == SAVE_CONF_WHEN_CHANGED && !modified))
+ return 0;
- for (i = 0; i < LEVEL_SCORE_ELEMENTS; i++)
- putFile8Bit(file, level->score[i]);
+ if (write_element)
+ num_bytes += putFile16BitBE(file, element);
- for (i = 0; i < STD_ELEMENT_CONTENTS; i++)
- for (y = 0; y < 3; y++)
- for (x = 0; x < 3; x++)
- putFile8Bit(file, (level->encoding_16bit_yamyam ? EL_EMPTY :
- level->yamyam_content[i].e[x][y]));
- putFile8Bit(file, level->amoeba_speed);
- putFile8Bit(file, level->time_magic_wall);
- putFile8Bit(file, level->time_wheel);
- putFile8Bit(file, (level->encoding_16bit_amoeba ? EL_EMPTY :
- level->amoeba_content));
- putFile8Bit(file, (level->initial_player_stepsize == STEPSIZE_FAST ? 1 : 0));
- putFile8Bit(file, (level->initial_gravity ? 1 : 0));
- putFile8Bit(file, (level->encoding_16bit_field ? 1 : 0));
- putFile8Bit(file, (level->em_slippery_gems ? 1 : 0));
+ num_bytes += putFile8Bit(file, conf_type);
+ num_bytes += putFile16BitBE(file, num_contents * CONF_CONTENT_NUM_BYTES);
- putFile8Bit(file, (level->use_custom_template ? 1 : 0));
+ for (i = 0; i < num_contents; i++)
+ for (y = 0; y < 3; y++)
+ for (x = 0; x < 3; x++)
+ num_bytes += putFile16BitBE(file, content[i].e[x][y]);
+ }
- putFile8Bit(file, (level->block_last_field ? 1 : 0));
- putFile8Bit(file, (level->sp_block_last_field ? 1 : 0));
- putFile32BitBE(file, level->can_move_into_acid_bits);
- putFile8Bit(file, level->dont_collide_with_bits);
+ return num_bytes;
+}
- putFile8Bit(file, (level->use_spring_bug ? 1 : 0));
- putFile8Bit(file, (level->use_step_counter ? 1 : 0));
+static int SaveLevel_INFO(FILE *file, struct LevelInfo *level)
+{
+ int chunk_size = 0;
+ int i;
- putFile8Bit(file, (level->instant_relocation ? 1 : 0));
- putFile8Bit(file, (level->can_pass_to_walkable ? 1 : 0));
- putFile8Bit(file, (level->grow_into_diggable ? 1 : 0));
+ li = *level; // copy level data into temporary buffer
- putFile8Bit(file, level->game_engine_type);
+ for (i = 0; chunk_config_INFO[i].data_type != -1; i++)
+ chunk_size += SaveLevel_MicroChunk(file, &chunk_config_INFO[i], FALSE);
- WriteUnusedBytesToFile(file, LEVEL_CHUNK_HEAD_UNUSED);
+ return chunk_size;
}
-#endif
-static int SaveLevel_NAME(FILE *file, struct LevelInfo *level)
+static int SaveLevel_ELEM(FILE *file, struct LevelInfo *level)
{
int chunk_size = 0;
int i;
- for (i = 0; i < MAX_LEVEL_NAME_LEN; i++)
- chunk_size += putFile8Bit(file, level->name[i]);
+ li = *level; // copy level data into temporary buffer
+
+ for (i = 0; chunk_config_ELEM[i].data_type != -1; i++)
+ chunk_size += SaveLevel_MicroChunk(file, &chunk_config_ELEM[i], TRUE);
return chunk_size;
}
-static int SaveLevel_AUTH(FILE *file, struct LevelInfo *level)
+static int SaveLevel_NOTE(FILE *file, struct LevelInfo *level, int element)
{
+ int envelope_nr = element - EL_ENVELOPE_1;
int chunk_size = 0;
int i;
- for (i = 0; i < MAX_LEVEL_AUTHOR_LEN; i++)
- chunk_size += putFile8Bit(file, level->author[i]);
+ chunk_size += putFile16BitBE(file, element);
+
+ // copy envelope data into temporary buffer
+ xx_envelope = level->envelope[envelope_nr];
+
+ for (i = 0; chunk_config_NOTE[i].data_type != -1; i++)
+ chunk_size += SaveLevel_MicroChunk(file, &chunk_config_NOTE[i], FALSE);
return chunk_size;
}
-#if ENABLE_HISTORIC_CHUNKS
-static int SaveLevel_BODY(FILE *file, struct LevelInfo *level)
+static int SaveLevel_CUSX(FILE *file, struct LevelInfo *level, int element)
{
+ struct ElementInfo *ei = &element_info[element];
int chunk_size = 0;
- int x, y;
+ int i, j;
- for (y = 0; y < level->fieldy; y++)
- for (x = 0; x < level->fieldx; x++)
- if (level->encoding_16bit_field)
- chunk_size += putFile16BitBE(file, level->field[x][y]);
- else
- chunk_size += putFile8Bit(file, level->field[x][y]);
+ chunk_size += putFile16BitBE(file, element);
+
+ xx_ei = *ei; // copy element data into temporary buffer
+
+ // set default description string for this specific element
+ strcpy(xx_default_description, getDefaultElementDescription(ei));
+
+ for (i = 0; chunk_config_CUSX_base[i].data_type != -1; i++)
+ chunk_size += SaveLevel_MicroChunk(file, &chunk_config_CUSX_base[i], FALSE);
+
+ for (i = 0; i < ei->num_change_pages; i++)
+ {
+ struct ElementChangeInfo *change = &ei->change_page[i];
+
+ xx_current_change_page = i;
+
+ xx_change = *change; // copy change data into temporary buffer
+
+ resetEventBits();
+ setEventBitsFromEventFlags(change);
+
+ for (j = 0; chunk_config_CUSX_change[j].data_type != -1; j++)
+ chunk_size += SaveLevel_MicroChunk(file, &chunk_config_CUSX_change[j],
+ FALSE);
+ }
return chunk_size;
}
-#endif
-static int SaveLevel_BODY(FILE *file, struct LevelInfo *level)
+static int SaveLevel_GRPX(FILE *file, struct LevelInfo *level, int element)
{
+ struct ElementInfo *ei = &element_info[element];
+ struct ElementGroupInfo *group = ei->group;
int chunk_size = 0;
- int x, y;
+ int i;
- for (y = 0; y < level->fieldy; y++)
- for (x = 0; x < level->fieldx; x++)
- chunk_size += putFile16BitBE(file, level->field[x][y]);
+ chunk_size += putFile16BitBE(file, element);
+
+ xx_ei = *ei; // copy element data into temporary buffer
+ xx_group = *group; // copy group data into temporary buffer
+
+ // set default description string for this specific element
+ strcpy(xx_default_description, getDefaultElementDescription(ei));
+
+ for (i = 0; chunk_config_GRPX[i].data_type != -1; i++)
+ chunk_size += SaveLevel_MicroChunk(file, &chunk_config_GRPX[i], FALSE);
return chunk_size;
}
-#if ENABLE_HISTORIC_CHUNKS
-static void SaveLevel_CONT(FILE *file, struct LevelInfo *level)
+static int SaveLevel_EMPX(FILE *file, struct LevelInfo *level, int element)
{
- int i, x, y;
+ struct ElementInfo *ei = &element_info[element];
+ int chunk_size = 0;
+ int i;
- putFile8Bit(file, EL_YAMYAM);
- putFile8Bit(file, level->num_yamyam_contents);
- putFile8Bit(file, 0);
- putFile8Bit(file, 0);
+ chunk_size += putFile16BitBE(file, element);
- for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
- for (y = 0; y < 3; y++)
- for (x = 0; x < 3; x++)
- if (level->encoding_16bit_field)
- putFile16BitBE(file, level->yamyam_content[i].e[x][y]);
- else
- putFile8Bit(file, level->yamyam_content[i].e[x][y]);
+ xx_ei = *ei; // copy element data into temporary buffer
+
+ for (i = 0; chunk_config_EMPX[i].data_type != -1; i++)
+ chunk_size += SaveLevel_MicroChunk(file, &chunk_config_EMPX[i], FALSE);
+
+ return chunk_size;
}
-#endif
-#if ENABLE_HISTORIC_CHUNKS
-static void SaveLevel_CNT2(FILE *file, struct LevelInfo *level, int element)
+static void SaveLevelFromFilename(struct LevelInfo *level, char *filename,
+ boolean save_as_template)
{
- int i, x, y;
- int num_contents, content_xsize, content_ysize;
- int content_array[MAX_ELEMENT_CONTENTS][3][3];
+ int chunk_size;
+ int i;
+ FILE *file;
- if (element == EL_YAMYAM)
+ if (!(file = fopen(filename, MODE_WRITE)))
{
- num_contents = level->num_yamyam_contents;
- content_xsize = 3;
- content_ysize = 3;
+ Warn("cannot save level file '%s'", filename);
- for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
- for (y = 0; y < 3; y++)
- for (x = 0; x < 3; x++)
- content_array[i][x][y] = level->yamyam_content[i].e[x][y];
+ return;
}
- else if (element == EL_BD_AMOEBA)
+
+ level->file_version = FILE_VERSION_ACTUAL;
+ level->game_version = GAME_VERSION_ACTUAL;
+
+ level->creation_date = getCurrentDate();
+
+ putFileChunkBE(file, "RND1", CHUNK_SIZE_UNDEFINED);
+ putFileChunkBE(file, "CAVE", CHUNK_SIZE_NONE);
+
+ chunk_size = SaveLevel_VERS(NULL, level);
+ putFileChunkBE(file, "VERS", chunk_size);
+ SaveLevel_VERS(file, level);
+
+ chunk_size = SaveLevel_DATE(NULL, level);
+ putFileChunkBE(file, "DATE", chunk_size);
+ SaveLevel_DATE(file, level);
+
+ chunk_size = SaveLevel_NAME(NULL, level);
+ putFileChunkBE(file, "NAME", chunk_size);
+ SaveLevel_NAME(file, level);
+
+ chunk_size = SaveLevel_AUTH(NULL, level);
+ putFileChunkBE(file, "AUTH", chunk_size);
+ SaveLevel_AUTH(file, level);
+
+ chunk_size = SaveLevel_INFO(NULL, level);
+ putFileChunkBE(file, "INFO", chunk_size);
+ SaveLevel_INFO(file, level);
+
+ chunk_size = SaveLevel_BODY(NULL, level);
+ putFileChunkBE(file, "BODY", chunk_size);
+ SaveLevel_BODY(file, level);
+
+ chunk_size = SaveLevel_ELEM(NULL, level);
+ if (chunk_size > LEVEL_CHUNK_ELEM_UNCHANGED) // save if changed
{
- num_contents = 1;
- content_xsize = 1;
- content_ysize = 1;
+ putFileChunkBE(file, "ELEM", chunk_size);
+ SaveLevel_ELEM(file, level);
+ }
- for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
- for (y = 0; y < 3; y++)
- for (x = 0; x < 3; x++)
- content_array[i][x][y] = EL_EMPTY;
- content_array[0][0][0] = level->amoeba_content;
+ for (i = 0; i < NUM_ENVELOPES; i++)
+ {
+ int element = EL_ENVELOPE_1 + i;
+
+ chunk_size = SaveLevel_NOTE(NULL, level, element);
+ if (chunk_size > LEVEL_CHUNK_NOTE_UNCHANGED) // save if changed
+ {
+ putFileChunkBE(file, "NOTE", chunk_size);
+ SaveLevel_NOTE(file, level, element);
+ }
}
- else
+
+ // if not using template level, check for non-default custom/group elements
+ if (!level->use_custom_template || save_as_template)
{
- // chunk header already written -- write empty chunk data
- WriteUnusedBytesToFile(file, LEVEL_CHUNK_CNT2_SIZE);
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
- Error(ERR_WARN, "cannot save content for element '%d'", element);
- return;
+ chunk_size = SaveLevel_CUSX(NULL, level, element);
+ if (chunk_size > LEVEL_CHUNK_CUSX_UNCHANGED) // save if changed
+ {
+ putFileChunkBE(file, "CUSX", chunk_size);
+ SaveLevel_CUSX(file, level, element);
+ }
+ }
+
+ for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
+ {
+ int element = EL_GROUP_START + i;
+
+ chunk_size = SaveLevel_GRPX(NULL, level, element);
+ if (chunk_size > LEVEL_CHUNK_GRPX_UNCHANGED) // save if changed
+ {
+ putFileChunkBE(file, "GRPX", chunk_size);
+ SaveLevel_GRPX(file, level, element);
+ }
+ }
+
+ for (i = 0; i < NUM_EMPTY_ELEMENTS_ALL; i++)
+ {
+ int element = GET_EMPTY_ELEMENT(i);
+
+ chunk_size = SaveLevel_EMPX(NULL, level, element);
+ if (chunk_size > LEVEL_CHUNK_EMPX_UNCHANGED) // save if changed
+ {
+ putFileChunkBE(file, "EMPX", chunk_size);
+ SaveLevel_EMPX(file, level, element);
+ }
+ }
}
- putFile16BitBE(file, element);
- putFile8Bit(file, num_contents);
- putFile8Bit(file, content_xsize);
- putFile8Bit(file, content_ysize);
+ fclose(file);
+
+ SetFilePermissions(filename, PERMS_PRIVATE);
+}
+
+void SaveLevel(int nr)
+{
+ char *filename = getDefaultLevelFilename(nr);
+
+ SaveLevelFromFilename(&level, filename, FALSE);
+}
- WriteUnusedBytesToFile(file, LEVEL_CHUNK_CNT2_UNUSED);
+void SaveLevelTemplate(void)
+{
+ char *filename = getLocalLevelTemplateFilename();
- for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
- for (y = 0; y < 3; y++)
- for (x = 0; x < 3; x++)
- putFile16BitBE(file, content_array[i][x][y]);
+ SaveLevelFromFilename(&level, filename, TRUE);
}
-#endif
-#if ENABLE_HISTORIC_CHUNKS
-static int SaveLevel_CNT3(FILE *file, struct LevelInfo *level, int element)
+boolean SaveLevelChecked(int nr)
{
- int envelope_nr = element - EL_ENVELOPE_1;
- int envelope_len = strlen(level->envelope_text[envelope_nr]) + 1;
- int chunk_size = 0;
- int i;
+ char *filename = getDefaultLevelFilename(nr);
+ boolean new_level = !fileExists(filename);
+ boolean level_saved = FALSE;
- chunk_size += putFile16BitBE(file, element);
- chunk_size += putFile16BitBE(file, envelope_len);
- chunk_size += putFile8Bit(file, level->envelope_xsize[envelope_nr]);
- chunk_size += putFile8Bit(file, level->envelope_ysize[envelope_nr]);
+ if (new_level || Request("Save this level and kill the old?", REQ_ASK))
+ {
+ SaveLevel(nr);
- WriteUnusedBytesToFile(file, LEVEL_CHUNK_CNT3_UNUSED);
- chunk_size += LEVEL_CHUNK_CNT3_UNUSED;
+ if (new_level)
+ Request("Level saved!", REQ_CONFIRM);
- for (i = 0; i < envelope_len; i++)
- chunk_size += putFile8Bit(file, level->envelope_text[envelope_nr][i]);
+ level_saved = TRUE;
+ }
- return chunk_size;
+ return level_saved;
}
-#endif
-#if ENABLE_HISTORIC_CHUNKS
-static void SaveLevel_CUS1(FILE *file, struct LevelInfo *level,
- int num_changed_custom_elements)
+void DumpLevel(struct LevelInfo *level)
{
- int i, check = 0;
+ if (level->no_level_file || level->no_valid_file)
+ {
+ Warn("cannot dump -- no valid level file found");
- putFile16BitBE(file, num_changed_custom_elements);
+ return;
+ }
- for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
- {
- int element = EL_CUSTOM_START + i;
+ PrintLine("-", 79);
+ Print("Level xxx (file version %08d, game version %08d)\n",
+ level->file_version, level->game_version);
+ PrintLine("-", 79);
- struct ElementInfo *ei = &element_info[element];
+ Print("Level author: '%s'\n", level->author);
+ Print("Level title: '%s'\n", level->name);
+ Print("\n");
+ Print("Playfield size: %d x %d\n", level->fieldx, level->fieldy);
+ Print("\n");
+ Print("Level time: %d seconds\n", level->time);
+ Print("Gems needed: %d\n", level->gems_needed);
+ Print("\n");
+ Print("Time for magic wall: %d seconds\n", level->time_magic_wall);
+ Print("Time for wheel: %d seconds\n", level->time_wheel);
+ Print("Time for light: %d seconds\n", level->time_light);
+ Print("Time for timegate: %d seconds\n", level->time_timegate);
+ Print("\n");
+ Print("Amoeba speed: %d\n", level->amoeba_speed);
+ Print("\n");
- if (ei->properties[EP_BITFIELD_BASE_NR] != EP_BITMASK_DEFAULT)
+ Print("EM style slippery gems: %s\n", (level->em_slippery_gems ? "yes" : "no"));
+ Print("Player blocks last field: %s\n", (level->block_last_field ? "yes" : "no"));
+ Print("SP player blocks last field: %s\n", (level->sp_block_last_field ? "yes" : "no"));
+ Print("use spring bug: %s\n", (level->use_spring_bug ? "yes" : "no"));
+ Print("use step counter: %s\n", (level->use_step_counter ? "yes" : "no"));
+ Print("rate time over score: %s\n", (level->rate_time_over_score ? "yes" : "no"));
+
+ if (options.debug)
+ {
+ int i, j;
+
+ for (i = 0; i < NUM_ENVELOPES; i++)
{
- if (check < num_changed_custom_elements)
+ char *text = level->envelope[i].text;
+ int text_len = strlen(text);
+ boolean has_text = FALSE;
+
+ for (j = 0; j < text_len; j++)
+ if (text[j] != ' ' && text[j] != '\n')
+ has_text = TRUE;
+
+ if (has_text)
{
- putFile16BitBE(file, element);
- putFile32BitBE(file, ei->properties[EP_BITFIELD_BASE_NR]);
+ Print("\n");
+ Print("Envelope %d:\n'%s'\n", i + 1, text);
}
-
- check++;
}
}
- if (check != num_changed_custom_elements) // should not happen
- Error(ERR_WARN, "inconsistent number of custom element properties");
+ PrintLine("-", 79);
}
-#endif
-#if ENABLE_HISTORIC_CHUNKS
-static void SaveLevel_CUS2(FILE *file, struct LevelInfo *level,
- int num_changed_custom_elements)
+void DumpLevels(void)
{
- int i, check = 0;
+ static LevelDirTree *dumplevel_leveldir = NULL;
- putFile16BitBE(file, num_changed_custom_elements);
+ dumplevel_leveldir = getTreeInfoFromIdentifier(leveldir_first,
+ global.dumplevel_leveldir);
- for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
- {
- int element = EL_CUSTOM_START + i;
+ if (dumplevel_leveldir == NULL)
+ Fail("no such level identifier: '%s'", global.dumplevel_leveldir);
- if (element_info[element].change->target_element != EL_EMPTY_SPACE)
- {
- if (check < num_changed_custom_elements)
- {
- putFile16BitBE(file, element);
- putFile16BitBE(file, element_info[element].change->target_element);
- }
+ if (global.dumplevel_level_nr < dumplevel_leveldir->first_level ||
+ global.dumplevel_level_nr > dumplevel_leveldir->last_level)
+ Fail("no such level number: %d", global.dumplevel_level_nr);
- check++;
- }
- }
+ leveldir_current = dumplevel_leveldir;
- if (check != num_changed_custom_elements) // should not happen
- Error(ERR_WARN, "inconsistent number of custom target elements");
+ LoadLevel(global.dumplevel_level_nr);
+ DumpLevel(&level);
+
+ CloseAllAndExit(0);
}
-#endif
-#if ENABLE_HISTORIC_CHUNKS
-static void SaveLevel_CUS3(FILE *file, struct LevelInfo *level,
- int num_changed_custom_elements)
+
+// ============================================================================
+// tape file functions
+// ============================================================================
+
+static void setTapeInfoToDefaults(void)
{
- int i, j, x, y, check = 0;
+ int i;
- putFile16BitBE(file, num_changed_custom_elements);
+ // always start with reliable default values (empty tape)
+ TapeErase();
- for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
- {
- int element = EL_CUSTOM_START + i;
- struct ElementInfo *ei = &element_info[element];
+ // default values (also for pre-1.2 tapes) with only the first player
+ tape.player_participates[0] = TRUE;
+ for (i = 1; i < MAX_PLAYERS; i++)
+ tape.player_participates[i] = FALSE;
- if (ei->modified_settings)
- {
- if (check < num_changed_custom_elements)
- {
- putFile16BitBE(file, element);
+ // at least one (default: the first) player participates in every tape
+ tape.num_participating_players = 1;
- for (j = 0; j < MAX_ELEMENT_NAME_LEN; j++)
- putFile8Bit(file, ei->description[j]);
+ tape.property_bits = TAPE_PROPERTY_NONE;
- putFile32BitBE(file, ei->properties[EP_BITFIELD_BASE_NR]);
+ tape.level_nr = level_nr;
+ tape.counter = 0;
+ tape.changed = FALSE;
+ tape.solved = FALSE;
- // some free bytes for future properties and padding
- WriteUnusedBytesToFile(file, 7);
+ tape.recording = FALSE;
+ tape.playing = FALSE;
+ tape.pausing = FALSE;
- putFile8Bit(file, ei->use_gfx_element);
- putFile16BitBE(file, ei->gfx_element_initial);
+ tape.scr_fieldx = SCR_FIELDX_DEFAULT;
+ tape.scr_fieldy = SCR_FIELDY_DEFAULT;
- putFile8Bit(file, ei->collect_score_initial);
- putFile8Bit(file, ei->collect_count_initial);
+ tape.no_info_chunk = TRUE;
+ tape.no_valid_file = FALSE;
+}
- putFile16BitBE(file, ei->push_delay_fixed);
- putFile16BitBE(file, ei->push_delay_random);
- putFile16BitBE(file, ei->move_delay_fixed);
- putFile16BitBE(file, ei->move_delay_random);
+static int getTapePosSize(struct TapeInfo *tape)
+{
+ int tape_pos_size = 0;
- putFile16BitBE(file, ei->move_pattern);
- putFile8Bit(file, ei->move_direction_initial);
- putFile8Bit(file, ei->move_stepsize);
+ if (tape->use_key_actions)
+ tape_pos_size += tape->num_participating_players;
- for (y = 0; y < 3; y++)
- for (x = 0; x < 3; x++)
- putFile16BitBE(file, ei->content.e[x][y]);
+ if (tape->use_mouse_actions)
+ tape_pos_size += 3; // x and y position and mouse button mask
- putFile32BitBE(file, ei->change->events);
+ tape_pos_size += 1; // tape action delay value
- putFile16BitBE(file, ei->change->target_element);
+ return tape_pos_size;
+}
- putFile16BitBE(file, ei->change->delay_fixed);
- putFile16BitBE(file, ei->change->delay_random);
- putFile16BitBE(file, ei->change->delay_frames);
+static void setTapeActionFlags(struct TapeInfo *tape, int value)
+{
+ tape->use_key_actions = FALSE;
+ tape->use_mouse_actions = FALSE;
- putFile16BitBE(file, ei->change->initial_trigger_element);
+ if (value != TAPE_USE_MOUSE_ACTIONS_ONLY)
+ tape->use_key_actions = TRUE;
- putFile8Bit(file, ei->change->explode);
- putFile8Bit(file, ei->change->use_target_content);
- putFile8Bit(file, ei->change->only_if_complete);
- putFile8Bit(file, ei->change->use_random_replace);
+ if (value != TAPE_USE_KEY_ACTIONS_ONLY)
+ tape->use_mouse_actions = TRUE;
+}
- putFile8Bit(file, ei->change->random_percentage);
- putFile8Bit(file, ei->change->replace_when);
+static int getTapeActionValue(struct TapeInfo *tape)
+{
+ return (tape->use_key_actions &&
+ tape->use_mouse_actions ? TAPE_USE_KEY_AND_MOUSE_ACTIONS :
+ tape->use_key_actions ? TAPE_USE_KEY_ACTIONS_ONLY :
+ tape->use_mouse_actions ? TAPE_USE_MOUSE_ACTIONS_ONLY :
+ TAPE_ACTIONS_DEFAULT);
+}
- for (y = 0; y < 3; y++)
- for (x = 0; x < 3; x++)
- putFile16BitBE(file, ei->change->content.e[x][y]);
+static int LoadTape_VERS(File *file, int chunk_size, struct TapeInfo *tape)
+{
+ tape->file_version = getFileVersion(file);
+ tape->game_version = getFileVersion(file);
- putFile8Bit(file, ei->slippery_type);
+ return chunk_size;
+}
- // some free bytes for future properties and padding
- WriteUnusedBytesToFile(file, LEVEL_CPART_CUS3_UNUSED);
- }
+static int LoadTape_HEAD(File *file, int chunk_size, struct TapeInfo *tape)
+{
+ int i;
- check++;
+ tape->random_seed = getFile32BitBE(file);
+ tape->date = getFile32BitBE(file);
+ tape->length = getFile32BitBE(file);
+
+ // read header fields that are new since version 1.2
+ if (tape->file_version >= FILE_VERSION_1_2)
+ {
+ byte store_participating_players = getFile8Bit(file);
+ int engine_version;
+
+ // since version 1.2, tapes store which players participate in the tape
+ tape->num_participating_players = 0;
+ for (i = 0; i < MAX_PLAYERS; i++)
+ {
+ tape->player_participates[i] = FALSE;
+
+ if (store_participating_players & (1 << i))
+ {
+ tape->player_participates[i] = TRUE;
+ tape->num_participating_players++;
+ }
}
+
+ setTapeActionFlags(tape, getFile8Bit(file));
+
+ tape->property_bits = getFile8Bit(file);
+ tape->solved = getFile8Bit(file);
+
+ engine_version = getFileVersion(file);
+ if (engine_version > 0)
+ tape->engine_version = engine_version;
+ else
+ tape->engine_version = tape->game_version;
}
- if (check != num_changed_custom_elements) // should not happen
- Error(ERR_WARN, "inconsistent number of custom element properties");
+ return chunk_size;
}
-#endif
-#if ENABLE_HISTORIC_CHUNKS
-static void SaveLevel_CUS4(FILE *file, struct LevelInfo *level, int element)
+static int LoadTape_SCRN(File *file, int chunk_size, struct TapeInfo *tape)
{
- struct ElementInfo *ei = &element_info[element];
- int i, j, x, y;
+ tape->scr_fieldx = getFile8Bit(file);
+ tape->scr_fieldy = getFile8Bit(file);
- // ---------- custom element base property values (96 bytes) ----------------
-
- putFile16BitBE(file, element);
-
- for (i = 0; i < MAX_ELEMENT_NAME_LEN; i++)
- putFile8Bit(file, ei->description[i]);
+ return chunk_size;
+}
- putFile32BitBE(file, ei->properties[EP_BITFIELD_BASE_NR]);
+static int LoadTape_INFO(File *file, int chunk_size, struct TapeInfo *tape)
+{
+ char *level_identifier = NULL;
+ int level_identifier_size;
+ int i;
- WriteUnusedBytesToFile(file, 4); // reserved for more base properties
+ tape->no_info_chunk = FALSE;
- putFile8Bit(file, ei->num_change_pages);
+ level_identifier_size = getFile16BitBE(file);
- putFile16BitBE(file, ei->ce_value_fixed_initial);
- putFile16BitBE(file, ei->ce_value_random_initial);
- putFile8Bit(file, ei->use_last_ce_value);
+ level_identifier = checked_malloc(level_identifier_size);
- putFile8Bit(file, ei->use_gfx_element);
- putFile16BitBE(file, ei->gfx_element_initial);
+ for (i = 0; i < level_identifier_size; i++)
+ level_identifier[i] = getFile8Bit(file);
- putFile8Bit(file, ei->collect_score_initial);
- putFile8Bit(file, ei->collect_count_initial);
+ strncpy(tape->level_identifier, level_identifier, MAX_FILENAME_LEN);
+ tape->level_identifier[MAX_FILENAME_LEN] = '\0';
- putFile8Bit(file, ei->drop_delay_fixed);
- putFile8Bit(file, ei->push_delay_fixed);
- putFile8Bit(file, ei->drop_delay_random);
- putFile8Bit(file, ei->push_delay_random);
- putFile16BitBE(file, ei->move_delay_fixed);
- putFile16BitBE(file, ei->move_delay_random);
+ checked_free(level_identifier);
- // bits 0 - 15 of "move_pattern" ...
- putFile16BitBE(file, ei->move_pattern & 0xffff);
- putFile8Bit(file, ei->move_direction_initial);
- putFile8Bit(file, ei->move_stepsize);
+ tape->level_nr = getFile16BitBE(file);
- putFile8Bit(file, ei->slippery_type);
+ chunk_size = 2 + level_identifier_size + 2;
- for (y = 0; y < 3; y++)
- for (x = 0; x < 3; x++)
- putFile16BitBE(file, ei->content.e[x][y]);
+ return chunk_size;
+}
- putFile16BitBE(file, ei->move_enter_element);
- putFile16BitBE(file, ei->move_leave_element);
- putFile8Bit(file, ei->move_leave_type);
+static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape)
+{
+ int i, j;
+ int tape_pos_size = getTapePosSize(tape);
+ int chunk_size_expected = tape_pos_size * tape->length;
- // ... bits 16 - 31 of "move_pattern" (not nice, but downward compatible)
- putFile16BitBE(file, (ei->move_pattern >> 16) & 0xffff);
+ if (chunk_size_expected != chunk_size)
+ {
+ ReadUnusedBytesFromFile(file, chunk_size);
+ return chunk_size_expected;
+ }
- putFile8Bit(file, ei->access_direction);
+ for (i = 0; i < tape->length; i++)
+ {
+ if (i >= MAX_TAPE_LEN)
+ {
+ Warn("tape truncated -- size exceeds maximum tape size %d",
+ MAX_TAPE_LEN);
- putFile8Bit(file, ei->explosion_delay);
- putFile8Bit(file, ei->ignition_delay);
- putFile8Bit(file, ei->explosion_type);
+ // tape too large; read and ignore remaining tape data from this chunk
+ for (;i < tape->length; i++)
+ ReadUnusedBytesFromFile(file, tape_pos_size);
- // some free bytes for future custom property values and padding
- WriteUnusedBytesToFile(file, 1);
+ break;
+ }
- // ---------- change page property values (48 bytes) ------------------------
+ if (tape->use_key_actions)
+ {
+ for (j = 0; j < MAX_PLAYERS; j++)
+ {
+ tape->pos[i].action[j] = MV_NONE;
- for (i = 0; i < ei->num_change_pages; i++)
- {
- struct ElementChangeInfo *change = &ei->change_page[i];
- unsigned int event_bits;
+ if (tape->player_participates[j])
+ tape->pos[i].action[j] = getFile8Bit(file);
+ }
+ }
- // bits 0 - 31 of "has_event[]" ...
- event_bits = 0;
- for (j = 0; j < MIN(NUM_CHANGE_EVENTS, 32); j++)
- if (change->has_event[j])
- event_bits |= (1 << j);
- putFile32BitBE(file, event_bits);
+ if (tape->use_mouse_actions)
+ {
+ tape->pos[i].action[TAPE_ACTION_LX] = getFile8Bit(file);
+ tape->pos[i].action[TAPE_ACTION_LY] = getFile8Bit(file);
+ tape->pos[i].action[TAPE_ACTION_BUTTON] = getFile8Bit(file);
+ }
- putFile16BitBE(file, change->target_element);
+ tape->pos[i].delay = getFile8Bit(file);
- putFile16BitBE(file, change->delay_fixed);
- putFile16BitBE(file, change->delay_random);
- putFile16BitBE(file, change->delay_frames);
+ if (tape->file_version == FILE_VERSION_1_0)
+ {
+ // eliminate possible diagonal moves in old tapes
+ // this is only for backward compatibility
- putFile16BitBE(file, change->initial_trigger_element);
+ byte joy_dir[4] = { JOY_LEFT, JOY_RIGHT, JOY_UP, JOY_DOWN };
+ byte action = tape->pos[i].action[0];
+ int k, num_moves = 0;
- putFile8Bit(file, change->explode);
- putFile8Bit(file, change->use_target_content);
- putFile8Bit(file, change->only_if_complete);
- putFile8Bit(file, change->use_random_replace);
+ for (k = 0; k < 4; k++)
+ {
+ if (action & joy_dir[k])
+ {
+ tape->pos[i + num_moves].action[0] = joy_dir[k];
+ if (num_moves > 0)
+ tape->pos[i + num_moves].delay = 0;
+ num_moves++;
+ }
+ }
- putFile8Bit(file, change->random_percentage);
- putFile8Bit(file, change->replace_when);
+ if (num_moves > 1)
+ {
+ num_moves--;
+ i += num_moves;
+ tape->length += num_moves;
+ }
+ }
+ else if (tape->file_version < FILE_VERSION_2_0)
+ {
+ // convert pre-2.0 tapes to new tape format
- for (y = 0; y < 3; y++)
- for (x = 0; x < 3; x++)
- putFile16BitBE(file, change->target_content.e[x][y]);
+ if (tape->pos[i].delay > 1)
+ {
+ // action part
+ tape->pos[i + 1] = tape->pos[i];
+ tape->pos[i + 1].delay = 1;
- putFile8Bit(file, change->can_change);
+ // delay part
+ for (j = 0; j < MAX_PLAYERS; j++)
+ tape->pos[i].action[j] = MV_NONE;
+ tape->pos[i].delay--;
- putFile8Bit(file, change->trigger_side);
+ i++;
+ tape->length++;
+ }
+ }
- putFile8Bit(file, change->trigger_player);
- putFile8Bit(file, (change->trigger_page == CH_PAGE_ANY ? CH_PAGE_ANY_FILE :
- log_2(change->trigger_page)));
+ if (checkEndOfFile(file))
+ break;
+ }
- putFile8Bit(file, change->has_action);
- putFile8Bit(file, change->action_type);
- putFile8Bit(file, change->action_mode);
- putFile16BitBE(file, change->action_arg);
+ if (i != tape->length)
+ chunk_size = tape_pos_size * i;
- // ... bits 32 - 39 of "has_event[]" (not nice, but downward compatible)
- event_bits = 0;
- for (j = 32; j < NUM_CHANGE_EVENTS; j++)
- if (change->has_event[j])
- event_bits |= (1 << (j - 32));
- putFile8Bit(file, event_bits);
- }
+ return chunk_size;
}
-#endif
-#if ENABLE_HISTORIC_CHUNKS
-static void SaveLevel_GRP1(FILE *file, struct LevelInfo *level, int element)
+static void LoadTape_SokobanSolution(char *filename)
{
- struct ElementInfo *ei = &element_info[element];
- struct ElementGroupInfo *group = ei->group;
- int i;
-
- putFile16BitBE(file, element);
+ File *file;
+ int move_delay = TILESIZE / level.initial_player_stepsize[0];
- for (i = 0; i < MAX_ELEMENT_NAME_LEN; i++)
- putFile8Bit(file, ei->description[i]);
+ if (!(file = openFile(filename, MODE_READ)))
+ {
+ tape.no_valid_file = TRUE;
- putFile8Bit(file, group->num_elements);
+ return;
+ }
- putFile8Bit(file, ei->use_gfx_element);
- putFile16BitBE(file, ei->gfx_element_initial);
+ while (!checkEndOfFile(file))
+ {
+ unsigned char c = getByteFromFile(file);
- putFile8Bit(file, group->choice_mode);
+ if (checkEndOfFile(file))
+ break;
- // some free bytes for future values and padding
- WriteUnusedBytesToFile(file, 3);
+ switch (c)
+ {
+ case 'u':
+ case 'U':
+ tape.pos[tape.length].action[0] = MV_UP;
+ tape.pos[tape.length].delay = move_delay + (c < 'a' ? 2 : 0);
+ tape.length++;
+ break;
- for (i = 0; i < MAX_ELEMENTS_IN_GROUP; i++)
- putFile16BitBE(file, group->element[i]);
-}
-#endif
+ case 'd':
+ case 'D':
+ tape.pos[tape.length].action[0] = MV_DOWN;
+ tape.pos[tape.length].delay = move_delay + (c < 'a' ? 2 : 0);
+ tape.length++;
+ break;
-static int SaveLevel_MicroChunk(FILE *file, struct LevelFileConfigInfo *entry,
- boolean write_element)
-{
- int save_type = entry->save_type;
- int data_type = entry->data_type;
- int conf_type = entry->conf_type;
- int byte_mask = conf_type & CONF_MASK_BYTES;
- int element = entry->element;
- int default_value = entry->default_value;
- int num_bytes = 0;
- boolean modified = FALSE;
+ case 'l':
+ case 'L':
+ tape.pos[tape.length].action[0] = MV_LEFT;
+ tape.pos[tape.length].delay = move_delay + (c < 'a' ? 2 : 0);
+ tape.length++;
+ break;
- if (byte_mask != CONF_MASK_MULTI_BYTES)
- {
- void *value_ptr = entry->value;
- int value = (data_type == TYPE_BOOLEAN ? *(boolean *)value_ptr :
- *(int *)value_ptr);
+ case 'r':
+ case 'R':
+ tape.pos[tape.length].action[0] = MV_RIGHT;
+ tape.pos[tape.length].delay = move_delay + (c < 'a' ? 2 : 0);
+ tape.length++;
+ break;
- // check if any settings have been modified before saving them
- if (value != default_value)
- modified = TRUE;
+ case '\n':
+ case '\r':
+ case '\t':
+ case ' ':
+ // ignore white-space characters
+ break;
- // do not save if explicitly told or if unmodified default settings
- if ((save_type == SAVE_CONF_NEVER) ||
- (save_type == SAVE_CONF_WHEN_CHANGED && !modified))
- return 0;
+ default:
+ tape.no_valid_file = TRUE;
- if (write_element)
- num_bytes += putFile16BitBE(file, element);
+ Warn("unsupported Sokoban solution file '%s' ['%d']", filename, c);
- num_bytes += putFile8Bit(file, conf_type);
- num_bytes += (byte_mask == CONF_MASK_1_BYTE ? putFile8Bit (file, value) :
- byte_mask == CONF_MASK_2_BYTE ? putFile16BitBE(file, value) :
- byte_mask == CONF_MASK_4_BYTE ? putFile32BitBE(file, value) :
- 0);
+ break;
+ }
}
- else if (data_type == TYPE_STRING)
- {
- char *default_string = entry->default_string;
- char *string = (char *)(entry->value);
- int string_length = strlen(string);
- int i;
-
- // check if any settings have been modified before saving them
- if (!strEqual(string, default_string))
- modified = TRUE;
- // do not save if explicitly told or if unmodified default settings
- if ((save_type == SAVE_CONF_NEVER) ||
- (save_type == SAVE_CONF_WHEN_CHANGED && !modified))
- return 0;
+ closeFile(file);
- if (write_element)
- num_bytes += putFile16BitBE(file, element);
+ if (tape.no_valid_file)
+ return;
- num_bytes += putFile8Bit(file, conf_type);
- num_bytes += putFile16BitBE(file, string_length);
+ tape.length_frames = GetTapeLengthFrames();
+ tape.length_seconds = GetTapeLengthSeconds();
+}
- for (i = 0; i < string_length; i++)
- num_bytes += putFile8Bit(file, string[i]);
- }
- else if (data_type == TYPE_ELEMENT_LIST)
- {
- int *element_array = (int *)(entry->value);
- int num_elements = *(int *)(entry->num_entities);
- int i;
+void LoadTapeFromFilename(char *filename)
+{
+ char cookie[MAX_LINE_LEN];
+ char chunk_name[CHUNK_ID_LEN + 1];
+ File *file;
+ int chunk_size;
- // check if any settings have been modified before saving them
- for (i = 0; i < num_elements; i++)
- if (element_array[i] != default_value)
- modified = TRUE;
+ // always start with reliable default values
+ setTapeInfoToDefaults();
- // do not save if explicitly told or if unmodified default settings
- if ((save_type == SAVE_CONF_NEVER) ||
- (save_type == SAVE_CONF_WHEN_CHANGED && !modified))
- return 0;
+ if (strSuffix(filename, ".sln"))
+ {
+ LoadTape_SokobanSolution(filename);
- if (write_element)
- num_bytes += putFile16BitBE(file, element);
+ return;
+ }
- num_bytes += putFile8Bit(file, conf_type);
- num_bytes += putFile16BitBE(file, num_elements * CONF_ELEMENT_NUM_BYTES);
+ if (!(file = openFile(filename, MODE_READ)))
+ {
+ tape.no_valid_file = TRUE;
- for (i = 0; i < num_elements; i++)
- num_bytes += putFile16BitBE(file, element_array[i]);
+ return;
}
- else if (data_type == TYPE_CONTENT_LIST)
- {
- struct Content *content = (struct Content *)(entry->value);
- int num_contents = *(int *)(entry->num_entities);
- int i, x, y;
- // check if any settings have been modified before saving them
- for (i = 0; i < num_contents; i++)
- for (y = 0; y < 3; y++)
- for (x = 0; x < 3; x++)
- if (content[i].e[x][y] != default_value)
- modified = TRUE;
+ getFileChunkBE(file, chunk_name, NULL);
+ if (strEqual(chunk_name, "RND1"))
+ {
+ getFile32BitBE(file); // not used
- // do not save if explicitly told or if unmodified default settings
- if ((save_type == SAVE_CONF_NEVER) ||
- (save_type == SAVE_CONF_WHEN_CHANGED && !modified))
- return 0;
+ getFileChunkBE(file, chunk_name, NULL);
+ if (!strEqual(chunk_name, "TAPE"))
+ {
+ tape.no_valid_file = TRUE;
- if (write_element)
- num_bytes += putFile16BitBE(file, element);
+ Warn("unknown format of tape file '%s'", filename);
- num_bytes += putFile8Bit(file, conf_type);
- num_bytes += putFile16BitBE(file, num_contents * CONF_CONTENT_NUM_BYTES);
+ closeFile(file);
- for (i = 0; i < num_contents; i++)
- for (y = 0; y < 3; y++)
- for (x = 0; x < 3; x++)
- num_bytes += putFile16BitBE(file, content[i].e[x][y]);
+ return;
+ }
}
+ else // check for pre-2.0 file format with cookie string
+ {
+ strcpy(cookie, chunk_name);
+ if (getStringFromFile(file, &cookie[4], MAX_LINE_LEN - 4) == NULL)
+ cookie[4] = '\0';
+ if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
+ cookie[strlen(cookie) - 1] = '\0';
- return num_bytes;
-}
+ if (!checkCookieString(cookie, TAPE_COOKIE_TMPL))
+ {
+ tape.no_valid_file = TRUE;
-static int SaveLevel_INFO(FILE *file, struct LevelInfo *level)
-{
- int chunk_size = 0;
- int i;
+ Warn("unknown format of tape file '%s'", filename);
- li = *level; // copy level data into temporary buffer
+ closeFile(file);
- for (i = 0; chunk_config_INFO[i].data_type != -1; i++)
- chunk_size += SaveLevel_MicroChunk(file, &chunk_config_INFO[i], FALSE);
+ return;
+ }
- return chunk_size;
-}
+ if ((tape.file_version = getFileVersionFromCookieString(cookie)) == -1)
+ {
+ tape.no_valid_file = TRUE;
-static int SaveLevel_ELEM(FILE *file, struct LevelInfo *level)
-{
- int chunk_size = 0;
- int i;
+ Warn("unsupported version of tape file '%s'", filename);
- li = *level; // copy level data into temporary buffer
+ closeFile(file);
- for (i = 0; chunk_config_ELEM[i].data_type != -1; i++)
- chunk_size += SaveLevel_MicroChunk(file, &chunk_config_ELEM[i], TRUE);
+ return;
+ }
- return chunk_size;
-}
+ // pre-2.0 tape files have no game version, so use file version here
+ tape.game_version = tape.file_version;
+ }
-static int SaveLevel_NOTE(FILE *file, struct LevelInfo *level, int element)
-{
- int envelope_nr = element - EL_ENVELOPE_1;
- int chunk_size = 0;
- int i;
+ if (tape.file_version < FILE_VERSION_1_2)
+ {
+ // tape files from versions before 1.2.0 without chunk structure
+ LoadTape_HEAD(file, TAPE_CHUNK_HEAD_SIZE, &tape);
+ LoadTape_BODY(file, 2 * tape.length, &tape);
+ }
+ else
+ {
+ static struct
+ {
+ char *name;
+ int size;
+ int (*loader)(File *, int, struct TapeInfo *);
+ }
+ chunk_info[] =
+ {
+ { "VERS", TAPE_CHUNK_VERS_SIZE, LoadTape_VERS },
+ { "HEAD", TAPE_CHUNK_HEAD_SIZE, LoadTape_HEAD },
+ { "SCRN", TAPE_CHUNK_SCRN_SIZE, LoadTape_SCRN },
+ { "INFO", -1, LoadTape_INFO },
+ { "BODY", -1, LoadTape_BODY },
+ { NULL, 0, NULL }
+ };
- chunk_size += putFile16BitBE(file, element);
+ while (getFileChunkBE(file, chunk_name, &chunk_size))
+ {
+ int i = 0;
- // copy envelope data into temporary buffer
- xx_envelope = level->envelope[envelope_nr];
+ while (chunk_info[i].name != NULL &&
+ !strEqual(chunk_name, chunk_info[i].name))
+ i++;
- for (i = 0; chunk_config_NOTE[i].data_type != -1; i++)
- chunk_size += SaveLevel_MicroChunk(file, &chunk_config_NOTE[i], FALSE);
+ if (chunk_info[i].name == NULL)
+ {
+ Warn("unknown chunk '%s' in tape file '%s'",
+ chunk_name, filename);
- return chunk_size;
-}
+ ReadUnusedBytesFromFile(file, chunk_size);
+ }
+ else if (chunk_info[i].size != -1 &&
+ chunk_info[i].size != chunk_size)
+ {
+ Warn("wrong size (%d) of chunk '%s' in tape file '%s'",
+ chunk_size, chunk_name, filename);
-static int SaveLevel_CUSX(FILE *file, struct LevelInfo *level, int element)
-{
- struct ElementInfo *ei = &element_info[element];
- int chunk_size = 0;
- int i, j;
+ ReadUnusedBytesFromFile(file, chunk_size);
+ }
+ else
+ {
+ // call function to load this tape chunk
+ int chunk_size_expected =
+ (chunk_info[i].loader)(file, chunk_size, &tape);
- chunk_size += putFile16BitBE(file, element);
+ // the size of some chunks cannot be checked before reading other
+ // chunks first (like "HEAD" and "BODY") that contain some header
+ // information, so check them here
+ if (chunk_size_expected != chunk_size)
+ {
+ Warn("wrong size (%d) of chunk '%s' in tape file '%s'",
+ chunk_size, chunk_name, filename);
+ }
+ }
+ }
+ }
- xx_ei = *ei; // copy element data into temporary buffer
+ closeFile(file);
- // set default description string for this specific element
- strcpy(xx_default_description, getDefaultElementDescription(ei));
+ tape.length_frames = GetTapeLengthFrames();
+ tape.length_seconds = GetTapeLengthSeconds();
- for (i = 0; chunk_config_CUSX_base[i].data_type != -1; i++)
- chunk_size += SaveLevel_MicroChunk(file, &chunk_config_CUSX_base[i], FALSE);
+#if 0
+ Debug("files:LoadTapeFromFilename", "tape file version: %d",
+ tape.file_version);
+ Debug("files:LoadTapeFromFilename", "tape game version: %d",
+ tape.game_version);
+ Debug("files:LoadTapeFromFilename", "tape engine version: %d",
+ tape.engine_version);
+#endif
+}
- for (i = 0; i < ei->num_change_pages; i++)
- {
- struct ElementChangeInfo *change = &ei->change_page[i];
+void LoadTape(int nr)
+{
+ char *filename = getTapeFilename(nr);
- xx_current_change_page = i;
+ LoadTapeFromFilename(filename);
+}
- xx_change = *change; // copy change data into temporary buffer
+void LoadSolutionTape(int nr)
+{
+ char *filename = getSolutionTapeFilename(nr);
- resetEventBits();
- setEventBitsFromEventFlags(change);
+ LoadTapeFromFilename(filename);
- for (j = 0; chunk_config_CUSX_change[j].data_type != -1; j++)
- chunk_size += SaveLevel_MicroChunk(file, &chunk_config_CUSX_change[j],
- FALSE);
+ if (TAPE_IS_EMPTY(tape))
+ {
+ if (level.game_engine_type == GAME_ENGINE_TYPE_BD &&
+ level.native_bd_level->replay != NULL)
+ CopyNativeTape_BD_to_RND(&level);
+ else if (level.game_engine_type == GAME_ENGINE_TYPE_SP &&
+ level.native_sp_level->demo.is_available)
+ CopyNativeTape_SP_to_RND(&level);
}
-
- return chunk_size;
}
-static int SaveLevel_GRPX(FILE *file, struct LevelInfo *level, int element)
+void LoadScoreTape(char *score_tape_basename, int nr)
{
- struct ElementInfo *ei = &element_info[element];
- struct ElementGroupInfo *group = ei->group;
- int chunk_size = 0;
- int i;
+ char *filename = getScoreTapeFilename(score_tape_basename, nr);
- chunk_size += putFile16BitBE(file, element);
+ LoadTapeFromFilename(filename);
+}
- xx_ei = *ei; // copy element data into temporary buffer
- xx_group = *group; // copy group data into temporary buffer
+void LoadScoreCacheTape(char *score_tape_basename, int nr)
+{
+ char *filename = getScoreCacheTapeFilename(score_tape_basename, nr);
- // set default description string for this specific element
- strcpy(xx_default_description, getDefaultElementDescription(ei));
+ LoadTapeFromFilename(filename);
+}
- for (i = 0; chunk_config_GRPX[i].data_type != -1; i++)
- chunk_size += SaveLevel_MicroChunk(file, &chunk_config_GRPX[i], FALSE);
+static boolean checkSaveTape_SCRN(struct TapeInfo *tape)
+{
+ // chunk required for team mode tapes with non-default screen size
+ return (tape->num_participating_players > 1 &&
+ (tape->scr_fieldx != SCR_FIELDX_DEFAULT ||
+ tape->scr_fieldy != SCR_FIELDY_DEFAULT));
+}
- return chunk_size;
+static void SaveTape_VERS(FILE *file, struct TapeInfo *tape)
+{
+ putFileVersion(file, tape->file_version);
+ putFileVersion(file, tape->game_version);
}
-static void SaveLevelFromFilename(struct LevelInfo *level, char *filename,
- boolean save_as_template)
+static void SaveTape_HEAD(FILE *file, struct TapeInfo *tape)
{
- int chunk_size;
int i;
- FILE *file;
-
- if (!(file = fopen(filename, MODE_WRITE)))
- {
- Error(ERR_WARN, "cannot save level file '%s'", filename);
- return;
- }
+ byte store_participating_players = 0;
- level->file_version = FILE_VERSION_ACTUAL;
- level->game_version = GAME_VERSION_ACTUAL;
+ // set bits for participating players for compact storage
+ for (i = 0; i < MAX_PLAYERS; i++)
+ if (tape->player_participates[i])
+ store_participating_players |= (1 << i);
- level->creation_date = getCurrentDate();
+ putFile32BitBE(file, tape->random_seed);
+ putFile32BitBE(file, tape->date);
+ putFile32BitBE(file, tape->length);
- putFileChunkBE(file, "RND1", CHUNK_SIZE_UNDEFINED);
- putFileChunkBE(file, "CAVE", CHUNK_SIZE_NONE);
+ putFile8Bit(file, store_participating_players);
- chunk_size = SaveLevel_VERS(NULL, level);
- putFileChunkBE(file, "VERS", chunk_size);
- SaveLevel_VERS(file, level);
+ putFile8Bit(file, getTapeActionValue(tape));
- chunk_size = SaveLevel_DATE(NULL, level);
- putFileChunkBE(file, "DATE", chunk_size);
- SaveLevel_DATE(file, level);
+ putFile8Bit(file, tape->property_bits);
+ putFile8Bit(file, tape->solved);
- chunk_size = SaveLevel_NAME(NULL, level);
- putFileChunkBE(file, "NAME", chunk_size);
- SaveLevel_NAME(file, level);
+ putFileVersion(file, tape->engine_version);
+}
- chunk_size = SaveLevel_AUTH(NULL, level);
- putFileChunkBE(file, "AUTH", chunk_size);
- SaveLevel_AUTH(file, level);
+static void SaveTape_SCRN(FILE *file, struct TapeInfo *tape)
+{
+ putFile8Bit(file, tape->scr_fieldx);
+ putFile8Bit(file, tape->scr_fieldy);
+}
- chunk_size = SaveLevel_INFO(NULL, level);
- putFileChunkBE(file, "INFO", chunk_size);
- SaveLevel_INFO(file, level);
+static void SaveTape_INFO(FILE *file, struct TapeInfo *tape)
+{
+ int level_identifier_size = strlen(tape->level_identifier) + 1;
+ int i;
- chunk_size = SaveLevel_BODY(NULL, level);
- putFileChunkBE(file, "BODY", chunk_size);
- SaveLevel_BODY(file, level);
+ putFile16BitBE(file, level_identifier_size);
- chunk_size = SaveLevel_ELEM(NULL, level);
- if (chunk_size > LEVEL_CHUNK_ELEM_UNCHANGED) // save if changed
- {
- putFileChunkBE(file, "ELEM", chunk_size);
- SaveLevel_ELEM(file, level);
- }
+ for (i = 0; i < level_identifier_size; i++)
+ putFile8Bit(file, tape->level_identifier[i]);
- for (i = 0; i < NUM_ENVELOPES; i++)
- {
- int element = EL_ENVELOPE_1 + i;
+ putFile16BitBE(file, tape->level_nr);
+}
- chunk_size = SaveLevel_NOTE(NULL, level, element);
- if (chunk_size > LEVEL_CHUNK_NOTE_UNCHANGED) // save if changed
- {
- putFileChunkBE(file, "NOTE", chunk_size);
- SaveLevel_NOTE(file, level, element);
- }
- }
+static void SaveTape_BODY(FILE *file, struct TapeInfo *tape)
+{
+ int i, j;
- // if not using template level, check for non-default custom/group elements
- if (!level->use_custom_template || save_as_template)
+ for (i = 0; i < tape->length; i++)
{
- for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ if (tape->use_key_actions)
{
- int element = EL_CUSTOM_START + i;
-
- chunk_size = SaveLevel_CUSX(NULL, level, element);
- if (chunk_size > LEVEL_CHUNK_CUSX_UNCHANGED) // save if changed
- {
- putFileChunkBE(file, "CUSX", chunk_size);
- SaveLevel_CUSX(file, level, element);
- }
+ for (j = 0; j < MAX_PLAYERS; j++)
+ if (tape->player_participates[j])
+ putFile8Bit(file, tape->pos[i].action[j]);
}
- for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
+ if (tape->use_mouse_actions)
{
- int element = EL_GROUP_START + i;
-
- chunk_size = SaveLevel_GRPX(NULL, level, element);
- if (chunk_size > LEVEL_CHUNK_GRPX_UNCHANGED) // save if changed
- {
- putFileChunkBE(file, "GRPX", chunk_size);
- SaveLevel_GRPX(file, level, element);
- }
+ putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LX]);
+ putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LY]);
+ putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_BUTTON]);
}
- }
-
- fclose(file);
- SetFilePermissions(filename, PERMS_PRIVATE);
+ putFile8Bit(file, tape->pos[i].delay);
+ }
}
-void SaveLevel(int nr)
+void SaveTapeToFilename(char *filename)
{
- char *filename = getDefaultLevelFilename(nr);
-
- SaveLevelFromFilename(&level, filename, FALSE);
-}
+ FILE *file;
+ int tape_pos_size;
+ int info_chunk_size;
+ int body_chunk_size;
-void SaveLevelTemplate(void)
-{
- char *filename = getLocalLevelTemplateFilename();
+ if (!(file = fopen(filename, MODE_WRITE)))
+ {
+ Warn("cannot save level recording file '%s'", filename);
- SaveLevelFromFilename(&level, filename, TRUE);
-}
+ return;
+ }
-boolean SaveLevelChecked(int nr)
-{
- char *filename = getDefaultLevelFilename(nr);
- boolean new_level = !fileExists(filename);
- boolean level_saved = FALSE;
+ tape_pos_size = getTapePosSize(&tape);
- if (new_level || Request("Save this level and kill the old?", REQ_ASK))
- {
- SaveLevel(nr);
+ info_chunk_size = 2 + (strlen(tape.level_identifier) + 1) + 2;
+ body_chunk_size = tape_pos_size * tape.length;
- if (new_level)
- Request("Level saved!", REQ_CONFIRM);
+ putFileChunkBE(file, "RND1", CHUNK_SIZE_UNDEFINED);
+ putFileChunkBE(file, "TAPE", CHUNK_SIZE_NONE);
- level_saved = TRUE;
- }
+ putFileChunkBE(file, "VERS", TAPE_CHUNK_VERS_SIZE);
+ SaveTape_VERS(file, &tape);
- return level_saved;
-}
+ putFileChunkBE(file, "HEAD", TAPE_CHUNK_HEAD_SIZE);
+ SaveTape_HEAD(file, &tape);
-void DumpLevel(struct LevelInfo *level)
-{
- if (level->no_level_file || level->no_valid_file)
+ if (checkSaveTape_SCRN(&tape))
{
- Error(ERR_WARN, "cannot dump -- no valid level file found");
-
- return;
+ putFileChunkBE(file, "SCRN", TAPE_CHUNK_SCRN_SIZE);
+ SaveTape_SCRN(file, &tape);
}
- PrintLine("-", 79);
- Print("Level xxx (file version %08d, game version %08d)\n",
- level->file_version, level->game_version);
- PrintLine("-", 79);
+ putFileChunkBE(file, "INFO", info_chunk_size);
+ SaveTape_INFO(file, &tape);
- Print("Level author: '%s'\n", level->author);
- Print("Level title: '%s'\n", level->name);
- Print("\n");
- Print("Playfield size: %d x %d\n", level->fieldx, level->fieldy);
- Print("\n");
- Print("Level time: %d seconds\n", level->time);
- Print("Gems needed: %d\n", level->gems_needed);
- Print("\n");
- Print("Time for magic wall: %d seconds\n", level->time_magic_wall);
- Print("Time for wheel: %d seconds\n", level->time_wheel);
- Print("Time for light: %d seconds\n", level->time_light);
- Print("Time for timegate: %d seconds\n", level->time_timegate);
- Print("\n");
- Print("Amoeba speed: %d\n", level->amoeba_speed);
- Print("\n");
+ putFileChunkBE(file, "BODY", body_chunk_size);
+ SaveTape_BODY(file, &tape);
- Print("EM style slippery gems: %s\n", (level->em_slippery_gems ? "yes" : "no"));
- Print("Player blocks last field: %s\n", (level->block_last_field ? "yes" : "no"));
- Print("SP player blocks last field: %s\n", (level->sp_block_last_field ? "yes" : "no"));
- Print("use spring bug: %s\n", (level->use_spring_bug ? "yes" : "no"));
- Print("use step counter: %s\n", (level->use_step_counter ? "yes" : "no"));
+ fclose(file);
- PrintLine("-", 79);
+ SetFilePermissions(filename, PERMS_PRIVATE);
}
-
-// ============================================================================
-// tape file functions
-// ============================================================================
-
-static void setTapeInfoToDefaults(void)
+static void SaveTapeExt(char *filename)
{
int i;
- // always start with reliable default values (empty tape)
- TapeErase();
-
- // default values (also for pre-1.2 tapes) with only the first player
- tape.player_participates[0] = TRUE;
- for (i = 1; i < MAX_PLAYERS; i++)
- tape.player_participates[i] = FALSE;
-
- // at least one (default: the first) player participates in every tape
- tape.num_participating_players = 1;
+ tape.file_version = FILE_VERSION_ACTUAL;
+ tape.game_version = GAME_VERSION_ACTUAL;
- tape.property_bits = TAPE_PROPERTY_NONE;
+ tape.num_participating_players = 0;
- tape.level_nr = level_nr;
- tape.counter = 0;
- tape.changed = FALSE;
+ // count number of participating players
+ for (i = 0; i < MAX_PLAYERS; i++)
+ if (tape.player_participates[i])
+ tape.num_participating_players++;
- tape.recording = FALSE;
- tape.playing = FALSE;
- tape.pausing = FALSE;
+ SaveTapeToFilename(filename);
- tape.no_valid_file = FALSE;
+ tape.changed = FALSE;
}
-static int getTapePosSize(struct TapeInfo *tape)
+void SaveTape(int nr)
{
- int tape_pos_size = 0;
+ char *filename = getTapeFilename(nr);
- if (tape->use_key_actions)
- tape_pos_size += tape->num_participating_players;
+ InitTapeDirectory(leveldir_current->subdir);
- if (tape->use_mouse_actions)
- tape_pos_size += 3; // x and y position and mouse button mask
+ SaveTapeExt(filename);
+}
- tape_pos_size += 1; // tape action delay value
+void SaveScoreTape(int nr)
+{
+ char *filename = getScoreTapeFilename(tape.score_tape_basename, nr);
- return tape_pos_size;
+ // used instead of "leveldir_current->subdir" (for network games)
+ InitScoreTapeDirectory(levelset.identifier, nr);
+
+ SaveTapeExt(filename);
}
-static void setTapeActionFlags(struct TapeInfo *tape, int value)
+static boolean SaveTapeCheckedExt(int nr, char *msg_replace, char *msg_saved,
+ unsigned int req_state_added)
{
- tape->use_key_actions = FALSE;
- tape->use_mouse_actions = FALSE;
+ char *filename = getTapeFilename(nr);
+ boolean new_tape = !fileExists(filename);
+ boolean tape_saved = FALSE;
- if (value != TAPE_USE_MOUSE_ACTIONS_ONLY)
- tape->use_key_actions = TRUE;
+ if (new_tape || Request(msg_replace, REQ_ASK | req_state_added))
+ {
+ SaveTape(nr);
- if (value != TAPE_USE_KEY_ACTIONS_ONLY)
- tape->use_mouse_actions = TRUE;
+ if (new_tape)
+ Request(msg_saved, REQ_CONFIRM | req_state_added);
+
+ tape_saved = TRUE;
+ }
+
+ return tape_saved;
}
-static int getTapeActionValue(struct TapeInfo *tape)
+boolean SaveTapeChecked(int nr)
{
- return (tape->use_key_actions &&
- tape->use_mouse_actions ? TAPE_USE_KEY_AND_MOUSE_ACTIONS :
- tape->use_key_actions ? TAPE_USE_KEY_ACTIONS_ONLY :
- tape->use_mouse_actions ? TAPE_USE_MOUSE_ACTIONS_ONLY :
- TAPE_ACTIONS_DEFAULT);
+ return SaveTapeCheckedExt(nr, "Replace old tape?", "Tape saved!", 0);
}
-static int LoadTape_VERS(File *file, int chunk_size, struct TapeInfo *tape)
+boolean SaveTapeChecked_LevelSolved(int nr)
{
- tape->file_version = getFileVersion(file);
- tape->game_version = getFileVersion(file);
-
- return chunk_size;
+ return SaveTapeCheckedExt(nr, "Level solved! Replace old tape?",
+ "Level solved! Tape saved!", REQ_STAY_OPEN);
}
-static int LoadTape_HEAD(File *file, int chunk_size, struct TapeInfo *tape)
+void DumpTape(struct TapeInfo *tape)
{
- int i;
+ int tape_frame_counter;
+ int i, j;
- tape->random_seed = getFile32BitBE(file);
- tape->date = getFile32BitBE(file);
- tape->length = getFile32BitBE(file);
+ if (tape->no_valid_file)
+ {
+ Warn("cannot dump -- no valid tape file found");
- // read header fields that are new since version 1.2
- if (tape->file_version >= FILE_VERSION_1_2)
+ return;
+ }
+
+ PrintLine("-", 79);
+
+ Print("Tape of Level %03d (file version %08d, game version %08d)\n",
+ tape->level_nr, tape->file_version, tape->game_version);
+ Print(" (effective engine version %08d)\n",
+ tape->engine_version);
+ Print("Level series identifier: '%s'\n", tape->level_identifier);
+
+ Print("Solution tape: %s\n",
+ tape->solved ? "yes" :
+ tape->game_version < VERSION_IDENT(4,3,2,3) ? "unknown" : "no");
+
+ Print("Special tape properties: ");
+ if (tape->property_bits == TAPE_PROPERTY_NONE)
+ Print("[none]");
+ if (tape->property_bits & TAPE_PROPERTY_EM_RANDOM_BUG)
+ Print("[em_random_bug]");
+ if (tape->property_bits & TAPE_PROPERTY_GAME_SPEED)
+ Print("[game_speed]");
+ if (tape->property_bits & TAPE_PROPERTY_PAUSE_MODE)
+ Print("[pause]");
+ if (tape->property_bits & TAPE_PROPERTY_SINGLE_STEP)
+ Print("[single_step]");
+ if (tape->property_bits & TAPE_PROPERTY_SNAPSHOT)
+ Print("[snapshot]");
+ if (tape->property_bits & TAPE_PROPERTY_REPLAYED)
+ Print("[replayed]");
+ if (tape->property_bits & TAPE_PROPERTY_TAS_KEYS)
+ Print("[tas_keys]");
+ if (tape->property_bits & TAPE_PROPERTY_SMALL_GRAPHICS)
+ Print("[small_graphics]");
+ Print("\n");
+
+ int year2 = tape->date / 10000;
+ int year4 = (year2 < 70 ? 2000 + year2 : 1900 + year2);
+ int month_index_raw = (tape->date / 100) % 100;
+ int month_index = month_index_raw % 12; // prevent invalid index
+ int month = month_index + 1;
+ int day = tape->date % 100;
+
+ Print("Tape date: %04d-%02d-%02d\n", year4, month, day);
+
+ PrintLine("-", 79);
+
+ tape_frame_counter = 0;
+
+ for (i = 0; i < tape->length; i++)
{
- byte store_participating_players = getFile8Bit(file);
- int engine_version;
+ if (i >= MAX_TAPE_LEN)
+ break;
- // since version 1.2, tapes store which players participate in the tape
- tape->num_participating_players = 0;
- for (i = 0; i < MAX_PLAYERS; i++)
- {
- tape->player_participates[i] = FALSE;
+ Print("%04d: ", i);
- if (store_participating_players & (1 << i))
+ for (j = 0; j < MAX_PLAYERS; j++)
+ {
+ if (tape->player_participates[j])
{
- tape->player_participates[i] = TRUE;
- tape->num_participating_players++;
+ int action = tape->pos[i].action[j];
+
+ Print("%d:%02x ", j, action);
+ Print("[%c%c%c%c|%c%c] - ",
+ (action & JOY_LEFT ? '<' : ' '),
+ (action & JOY_RIGHT ? '>' : ' '),
+ (action & JOY_UP ? '^' : ' '),
+ (action & JOY_DOWN ? 'v' : ' '),
+ (action & JOY_BUTTON_1 ? '1' : ' '),
+ (action & JOY_BUTTON_2 ? '2' : ' '));
}
}
- setTapeActionFlags(tape, getFile8Bit(file));
+ Print("(%03d) ", tape->pos[i].delay);
+ Print("[%05d]\n", tape_frame_counter);
- tape->property_bits = getFile8Bit(file);
+ tape_frame_counter += tape->pos[i].delay;
+ }
- ReadUnusedBytesFromFile(file, TAPE_CHUNK_HEAD_UNUSED);
+ PrintLine("-", 79);
+}
- engine_version = getFileVersion(file);
- if (engine_version > 0)
- tape->engine_version = engine_version;
- else
- tape->engine_version = tape->game_version;
- }
+void DumpTapes(void)
+{
+ static LevelDirTree *dumptape_leveldir = NULL;
- return chunk_size;
+ dumptape_leveldir = getTreeInfoFromIdentifier(leveldir_first,
+ global.dumptape_leveldir);
+
+ if (dumptape_leveldir == NULL)
+ Fail("no such level identifier: '%s'", global.dumptape_leveldir);
+
+ if (global.dumptape_level_nr < dumptape_leveldir->first_level ||
+ global.dumptape_level_nr > dumptape_leveldir->last_level)
+ Fail("no such level number: %d", global.dumptape_level_nr);
+
+ leveldir_current = dumptape_leveldir;
+
+ if (options.mytapes)
+ LoadTape(global.dumptape_level_nr);
+ else
+ LoadSolutionTape(global.dumptape_level_nr);
+
+ DumpTape(&tape);
+
+ CloseAllAndExit(0);
}
-static int LoadTape_INFO(File *file, int chunk_size, struct TapeInfo *tape)
+
+// ============================================================================
+// score file functions
+// ============================================================================
+
+static void setScoreInfoToDefaultsExt(struct ScoreInfo *scores)
{
- int level_identifier_size;
int i;
- level_identifier_size = getFile16BitBE(file);
+ for (i = 0; i < MAX_SCORE_ENTRIES; i++)
+ {
+ strcpy(scores->entry[i].tape_basename, UNDEFINED_FILENAME);
+ strcpy(scores->entry[i].name, EMPTY_PLAYER_NAME);
+ scores->entry[i].score = 0;
+ scores->entry[i].time = 0;
- tape->level_identifier =
- checked_realloc(tape->level_identifier, level_identifier_size);
+ scores->entry[i].id = -1;
+ strcpy(scores->entry[i].tape_date, UNKNOWN_NAME);
+ strcpy(scores->entry[i].platform, UNKNOWN_NAME);
+ strcpy(scores->entry[i].version, UNKNOWN_NAME);
+ strcpy(scores->entry[i].country_name, UNKNOWN_NAME);
+ strcpy(scores->entry[i].country_code, "??");
+ }
- for (i = 0; i < level_identifier_size; i++)
- tape->level_identifier[i] = getFile8Bit(file);
+ scores->num_entries = 0;
+ scores->last_added = -1;
+ scores->last_added_local = -1;
- tape->level_nr = getFile16BitBE(file);
+ scores->updated = FALSE;
+ scores->uploaded = FALSE;
+ scores->tape_downloaded = FALSE;
+ scores->force_last_added = FALSE;
- chunk_size = 2 + level_identifier_size + 2;
+ // The following values are intentionally not reset here:
+ // - last_level_nr
+ // - last_entry_nr
+ // - next_level_nr
+ // - continue_playing
+ // - continue_on_return
+}
- return chunk_size;
+static void setScoreInfoToDefaults(void)
+{
+ setScoreInfoToDefaultsExt(&scores);
}
-static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape)
+static void setServerScoreInfoToDefaults(void)
{
- int i, j;
- int tape_pos_size = getTapePosSize(tape);
- int chunk_size_expected = tape_pos_size * tape->length;
+ setScoreInfoToDefaultsExt(&server_scores);
+}
- if (chunk_size_expected != chunk_size)
+static void LoadScore_OLD(int nr)
+{
+ int i;
+ char *filename = getScoreFilename(nr);
+ char cookie[MAX_LINE_LEN];
+ char line[MAX_LINE_LEN];
+ char *line_ptr;
+ FILE *file;
+
+ if (!(file = fopen(filename, MODE_READ)))
+ return;
+
+ // check file identifier
+ if (fgets(cookie, MAX_LINE_LEN, file) == NULL)
+ cookie[0] = '\0';
+ if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
+ cookie[strlen(cookie) - 1] = '\0';
+
+ if (!checkCookieString(cookie, SCORE_COOKIE_TMPL))
{
- ReadUnusedBytesFromFile(file, chunk_size);
- return chunk_size_expected;
+ Warn("unknown format of score file '%s'", filename);
+
+ fclose(file);
+
+ return;
}
- for (i = 0; i < tape->length; i++)
+ for (i = 0; i < MAX_SCORE_ENTRIES; i++)
{
- if (i >= MAX_TAPE_LEN)
- {
- Error(ERR_WARN, "tape truncated -- size exceeds maximum tape size %d",
- MAX_TAPE_LEN);
+ if (fscanf(file, "%d", &scores.entry[i].score) == EOF)
+ Warn("fscanf() failed; %s", strerror(errno));
- // tape too large; read and ignore remaining tape data from this chunk
- for (;i < tape->length; i++)
- ReadUnusedBytesFromFile(file, tape_pos_size);
+ if (fgets(line, MAX_LINE_LEN, file) == NULL)
+ line[0] = '\0';
- break;
- }
+ if (strlen(line) > 0 && line[strlen(line) - 1] == '\n')
+ line[strlen(line) - 1] = '\0';
- if (tape->use_key_actions)
+ for (line_ptr = line; *line_ptr; line_ptr++)
{
- for (j = 0; j < MAX_PLAYERS; j++)
+ if (*line_ptr != ' ' && *line_ptr != '\t' && *line_ptr != '\0')
{
- tape->pos[i].action[j] = MV_NONE;
-
- if (tape->player_participates[j])
- tape->pos[i].action[j] = getFile8Bit(file);
+ strncpy(scores.entry[i].name, line_ptr, MAX_PLAYER_NAME_LEN);
+ scores.entry[i].name[MAX_PLAYER_NAME_LEN] = '\0';
+ break;
}
}
+ }
- if (tape->use_mouse_actions)
- {
- tape->pos[i].action[TAPE_ACTION_LX] = getFile8Bit(file);
- tape->pos[i].action[TAPE_ACTION_LY] = getFile8Bit(file);
- tape->pos[i].action[TAPE_ACTION_BUTTON] = getFile8Bit(file);
- }
+ fclose(file);
+}
- tape->pos[i].delay = getFile8Bit(file);
+static void ConvertScore_OLD(void)
+{
+ // only convert score to time for levels that rate playing time over score
+ if (!level.rate_time_over_score)
+ return;
- if (tape->file_version == FILE_VERSION_1_0)
- {
- // eliminate possible diagonal moves in old tapes
- // this is only for backward compatibility
+ // convert old score to playing time for score-less levels (like Supaplex)
+ int time_final_max = 999;
+ int i;
- byte joy_dir[4] = { JOY_LEFT, JOY_RIGHT, JOY_UP, JOY_DOWN };
- byte action = tape->pos[i].action[0];
- int k, num_moves = 0;
+ for (i = 0; i < MAX_SCORE_ENTRIES; i++)
+ {
+ int score = scores.entry[i].score;
- for (k = 0; k<4; k++)
- {
- if (action & joy_dir[k])
- {
- tape->pos[i + num_moves].action[0] = joy_dir[k];
- if (num_moves > 0)
- tape->pos[i + num_moves].delay = 0;
- num_moves++;
- }
- }
+ if (score > 0 && score < time_final_max)
+ scores.entry[i].time = (time_final_max - score - 1) * FRAMES_PER_SECOND;
+ }
+}
- if (num_moves > 1)
- {
- num_moves--;
- i += num_moves;
- tape->length += num_moves;
- }
- }
- else if (tape->file_version < FILE_VERSION_2_0)
- {
- // convert pre-2.0 tapes to new tape format
+static int LoadScore_VERS(File *file, int chunk_size, struct ScoreInfo *scores)
+{
+ scores->file_version = getFileVersion(file);
+ scores->game_version = getFileVersion(file);
+
+ return chunk_size;
+}
+
+static int LoadScore_INFO(File *file, int chunk_size, struct ScoreInfo *scores)
+{
+ char *level_identifier = NULL;
+ int level_identifier_size;
+ int i;
- if (tape->pos[i].delay > 1)
- {
- // action part
- tape->pos[i + 1] = tape->pos[i];
- tape->pos[i + 1].delay = 1;
+ level_identifier_size = getFile16BitBE(file);
- // delay part
- for (j = 0; j < MAX_PLAYERS; j++)
- tape->pos[i].action[j] = MV_NONE;
- tape->pos[i].delay--;
+ level_identifier = checked_malloc(level_identifier_size);
- i++;
- tape->length++;
- }
- }
+ for (i = 0; i < level_identifier_size; i++)
+ level_identifier[i] = getFile8Bit(file);
- if (checkEndOfFile(file))
- break;
- }
+ strncpy(scores->level_identifier, level_identifier, MAX_FILENAME_LEN);
+ scores->level_identifier[MAX_FILENAME_LEN] = '\0';
- if (i != tape->length)
- chunk_size = tape_pos_size * i;
+ checked_free(level_identifier);
+
+ scores->level_nr = getFile16BitBE(file);
+ scores->num_entries = getFile16BitBE(file);
+
+ chunk_size = 2 + level_identifier_size + 2 + 2;
return chunk_size;
}
-static void LoadTape_SokobanSolution(char *filename)
+static int LoadScore_NAME(File *file, int chunk_size, struct ScoreInfo *scores)
{
- File *file;
- int move_delay = TILESIZE / level.initial_player_stepsize[0];
+ int i, j;
- if (!(file = openFile(filename, MODE_READ)))
+ for (i = 0; i < scores->num_entries; i++)
{
- tape.no_valid_file = TRUE;
+ for (j = 0; j < MAX_PLAYER_NAME_LEN; j++)
+ scores->entry[i].name[j] = getFile8Bit(file);
- return;
+ scores->entry[i].name[MAX_PLAYER_NAME_LEN] = '\0';
}
- while (!checkEndOfFile(file))
- {
- unsigned char c = getByteFromFile(file);
+ chunk_size = scores->num_entries * MAX_PLAYER_NAME_LEN;
- if (checkEndOfFile(file))
- break;
+ return chunk_size;
+}
- switch (c)
- {
- case 'u':
- case 'U':
- tape.pos[tape.length].action[0] = MV_UP;
- tape.pos[tape.length].delay = move_delay + (c < 'a' ? 2 : 0);
- tape.length++;
- break;
+static int LoadScore_SCOR(File *file, int chunk_size, struct ScoreInfo *scores)
+{
+ int i;
- case 'd':
- case 'D':
- tape.pos[tape.length].action[0] = MV_DOWN;
- tape.pos[tape.length].delay = move_delay + (c < 'a' ? 2 : 0);
- tape.length++;
- break;
+ for (i = 0; i < scores->num_entries; i++)
+ scores->entry[i].score = getFile16BitBE(file);
- case 'l':
- case 'L':
- tape.pos[tape.length].action[0] = MV_LEFT;
- tape.pos[tape.length].delay = move_delay + (c < 'a' ? 2 : 0);
- tape.length++;
- break;
+ chunk_size = scores->num_entries * 2;
- case 'r':
- case 'R':
- tape.pos[tape.length].action[0] = MV_RIGHT;
- tape.pos[tape.length].delay = move_delay + (c < 'a' ? 2 : 0);
- tape.length++;
- break;
+ return chunk_size;
+}
- case '\n':
- case '\r':
- case '\t':
- case ' ':
- // ignore white-space characters
- break;
+static int LoadScore_SC4R(File *file, int chunk_size, struct ScoreInfo *scores)
+{
+ int i;
- default:
- tape.no_valid_file = TRUE;
+ for (i = 0; i < scores->num_entries; i++)
+ scores->entry[i].score = getFile32BitBE(file);
- Error(ERR_WARN, "unsupported Sokoban solution file '%s' ['%d']", filename, c);
+ chunk_size = scores->num_entries * 4;
- break;
- }
- }
+ return chunk_size;
+}
- closeFile(file);
+static int LoadScore_TIME(File *file, int chunk_size, struct ScoreInfo *scores)
+{
+ int i;
- if (tape.no_valid_file)
- return;
+ for (i = 0; i < scores->num_entries; i++)
+ scores->entry[i].time = getFile32BitBE(file);
- tape.length_frames = GetTapeLengthFrames();
- tape.length_seconds = GetTapeLengthSeconds();
+ chunk_size = scores->num_entries * 4;
+
+ return chunk_size;
}
-void LoadTapeFromFilename(char *filename)
+static int LoadScore_TAPE(File *file, int chunk_size, struct ScoreInfo *scores)
+{
+ int i, j;
+
+ for (i = 0; i < scores->num_entries; i++)
+ {
+ for (j = 0; j < MAX_SCORE_TAPE_BASENAME_LEN; j++)
+ scores->entry[i].tape_basename[j] = getFile8Bit(file);
+
+ scores->entry[i].tape_basename[MAX_SCORE_TAPE_BASENAME_LEN] = '\0';
+ }
+
+ chunk_size = scores->num_entries * MAX_SCORE_TAPE_BASENAME_LEN;
+
+ return chunk_size;
+}
+
+void LoadScore(int nr)
{
+ char *filename = getScoreFilename(nr);
char cookie[MAX_LINE_LEN];
char chunk_name[CHUNK_ID_LEN + 1];
- File *file;
int chunk_size;
+ boolean old_score_file_format = FALSE;
+ File *file;
// always start with reliable default values
- setTapeInfoToDefaults();
-
- if (strSuffix(filename, ".sln"))
- {
- LoadTape_SokobanSolution(filename);
-
- return;
- }
+ setScoreInfoToDefaults();
if (!(file = openFile(filename, MODE_READ)))
- {
- tape.no_valid_file = TRUE;
-
return;
- }
getFileChunkBE(file, chunk_name, NULL);
if (strEqual(chunk_name, "RND1"))
getFile32BitBE(file); // not used
getFileChunkBE(file, chunk_name, NULL);
- if (!strEqual(chunk_name, "TAPE"))
+ if (!strEqual(chunk_name, "SCOR"))
{
- tape.no_valid_file = TRUE;
-
- Error(ERR_WARN, "unknown format of tape file '%s'", filename);
+ Warn("unknown format of score file '%s'", filename);
closeFile(file);
return;
}
}
- else // check for pre-2.0 file format with cookie string
+ else // check for old file format with cookie string
{
strcpy(cookie, chunk_name);
if (getStringFromFile(file, &cookie[4], MAX_LINE_LEN - 4) == NULL)
if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
cookie[strlen(cookie) - 1] = '\0';
- if (!checkCookieString(cookie, TAPE_COOKIE_TMPL))
- {
- tape.no_valid_file = TRUE;
-
- Error(ERR_WARN, "unknown format of tape file '%s'", filename);
-
- closeFile(file);
-
- return;
- }
-
- if ((tape.file_version = getFileVersionFromCookieString(cookie)) == -1)
+ if (!checkCookieString(cookie, SCORE_COOKIE_TMPL))
{
- tape.no_valid_file = TRUE;
-
- Error(ERR_WARN, "unsupported version of tape file '%s'", filename);
+ Warn("unknown format of score file '%s'", filename);
closeFile(file);
return;
}
- // pre-2.0 tape files have no game version, so use file version here
- tape.game_version = tape.file_version;
+ old_score_file_format = TRUE;
}
- if (tape.file_version < FILE_VERSION_1_2)
+ if (old_score_file_format)
{
- // tape files from versions before 1.2.0 without chunk structure
- LoadTape_HEAD(file, TAPE_CHUNK_HEAD_SIZE, &tape);
- LoadTape_BODY(file, 2 * tape.length, &tape);
+ // score files from versions before 4.2.4.0 without chunk structure
+ LoadScore_OLD(nr);
+
+ // convert score to time, if possible (mainly for Supaplex levels)
+ ConvertScore_OLD();
}
else
{
{
char *name;
int size;
- int (*loader)(File *, int, struct TapeInfo *);
+ int (*loader)(File *, int, struct ScoreInfo *);
}
chunk_info[] =
{
- { "VERS", TAPE_CHUNK_VERS_SIZE, LoadTape_VERS },
- { "HEAD", TAPE_CHUNK_HEAD_SIZE, LoadTape_HEAD },
- { "INFO", -1, LoadTape_INFO },
- { "BODY", -1, LoadTape_BODY },
+ { "VERS", SCORE_CHUNK_VERS_SIZE, LoadScore_VERS },
+ { "INFO", -1, LoadScore_INFO },
+ { "NAME", -1, LoadScore_NAME },
+ { "SCOR", -1, LoadScore_SCOR },
+ { "SC4R", -1, LoadScore_SC4R },
+ { "TIME", -1, LoadScore_TIME },
+ { "TAPE", -1, LoadScore_TAPE },
+
{ NULL, 0, NULL }
};
if (chunk_info[i].name == NULL)
{
- Error(ERR_WARN, "unknown chunk '%s' in tape file '%s'",
+ Warn("unknown chunk '%s' in score file '%s'",
chunk_name, filename);
+
ReadUnusedBytesFromFile(file, chunk_size);
}
else if (chunk_info[i].size != -1 &&
chunk_info[i].size != chunk_size)
{
- Error(ERR_WARN, "wrong size (%d) of chunk '%s' in tape file '%s'",
+ Warn("wrong size (%d) of chunk '%s' in score file '%s'",
chunk_size, chunk_name, filename);
+
ReadUnusedBytesFromFile(file, chunk_size);
}
else
{
- // call function to load this tape chunk
+ // call function to load this score chunk
int chunk_size_expected =
- (chunk_info[i].loader)(file, chunk_size, &tape);
+ (chunk_info[i].loader)(file, chunk_size, &scores);
// the size of some chunks cannot be checked before reading other
// chunks first (like "HEAD" and "BODY") that contain some header
// information, so check them here
if (chunk_size_expected != chunk_size)
{
- Error(ERR_WARN, "wrong size (%d) of chunk '%s' in tape file '%s'",
+ Warn("wrong size (%d) of chunk '%s' in score file '%s'",
chunk_size, chunk_name, filename);
}
}
}
closeFile(file);
-
- tape.length_frames = GetTapeLengthFrames();
- tape.length_seconds = GetTapeLengthSeconds();
-
-#if 0
- printf("::: tape file version: %d\n", tape.file_version);
- printf("::: tape game version: %d\n", tape.game_version);
- printf("::: tape engine version: %d\n", tape.engine_version);
-#endif
}
-void LoadTape(int nr)
+#if ENABLE_HISTORIC_CHUNKS
+void SaveScore_OLD(int nr)
{
- char *filename = getTapeFilename(nr);
+ int i;
+ char *filename = getScoreFilename(nr);
+ FILE *file;
- LoadTapeFromFilename(filename);
-}
+ // used instead of "leveldir_current->subdir" (for network games)
+ InitScoreDirectory(levelset.identifier);
-void LoadSolutionTape(int nr)
-{
- char *filename = getSolutionTapeFilename(nr);
+ if (!(file = fopen(filename, MODE_WRITE)))
+ {
+ Warn("cannot save score for level %d", nr);
- LoadTapeFromFilename(filename);
+ return;
+ }
- if (TAPE_IS_EMPTY(tape) &&
- level.game_engine_type == GAME_ENGINE_TYPE_SP &&
- level.native_sp_level->demo.is_available)
- CopyNativeTape_SP_to_RND(&level);
+ fprintf(file, "%s\n\n", SCORE_COOKIE);
+
+ for (i = 0; i < MAX_SCORE_ENTRIES; i++)
+ fprintf(file, "%d %s\n", scores.entry[i].score, scores.entry[i].name);
+
+ fclose(file);
+
+ SetFilePermissions(filename, PERMS_PRIVATE);
}
+#endif
-static void SaveTape_VERS(FILE *file, struct TapeInfo *tape)
+static void SaveScore_VERS(FILE *file, struct ScoreInfo *scores)
{
- putFileVersion(file, tape->file_version);
- putFileVersion(file, tape->game_version);
+ putFileVersion(file, scores->file_version);
+ putFileVersion(file, scores->game_version);
}
-static void SaveTape_HEAD(FILE *file, struct TapeInfo *tape)
+static void SaveScore_INFO(FILE *file, struct ScoreInfo *scores)
{
+ int level_identifier_size = strlen(scores->level_identifier) + 1;
int i;
- byte store_participating_players = 0;
- // set bits for participating players for compact storage
- for (i = 0; i < MAX_PLAYERS; i++)
- if (tape->player_participates[i])
- store_participating_players |= (1 << i);
+ putFile16BitBE(file, level_identifier_size);
- putFile32BitBE(file, tape->random_seed);
- putFile32BitBE(file, tape->date);
- putFile32BitBE(file, tape->length);
+ for (i = 0; i < level_identifier_size; i++)
+ putFile8Bit(file, scores->level_identifier[i]);
- putFile8Bit(file, store_participating_players);
+ putFile16BitBE(file, scores->level_nr);
+ putFile16BitBE(file, scores->num_entries);
+}
- putFile8Bit(file, getTapeActionValue(tape));
+static void SaveScore_NAME(FILE *file, struct ScoreInfo *scores)
+{
+ int i, j;
- putFile8Bit(file, tape->property_bits);
+ for (i = 0; i < scores->num_entries; i++)
+ {
+ int name_size = strlen(scores->entry[i].name);
- // unused bytes not at the end here for 4-byte alignment of engine_version
- WriteUnusedBytesToFile(file, TAPE_CHUNK_HEAD_UNUSED);
+ for (j = 0; j < MAX_PLAYER_NAME_LEN; j++)
+ putFile8Bit(file, (j < name_size ? scores->entry[i].name[j] : 0));
+ }
+}
- putFileVersion(file, tape->engine_version);
+static void SaveScore_SCOR(FILE *file, struct ScoreInfo *scores)
+{
+ int i;
+
+ for (i = 0; i < scores->num_entries; i++)
+ putFile16BitBE(file, scores->entry[i].score);
}
-static void SaveTape_INFO(FILE *file, struct TapeInfo *tape)
+static void SaveScore_SC4R(FILE *file, struct ScoreInfo *scores)
{
- int level_identifier_size = strlen(tape->level_identifier) + 1;
int i;
- putFile16BitBE(file, level_identifier_size);
+ for (i = 0; i < scores->num_entries; i++)
+ putFile32BitBE(file, scores->entry[i].score);
+}
- for (i = 0; i < level_identifier_size; i++)
- putFile8Bit(file, tape->level_identifier[i]);
+static void SaveScore_TIME(FILE *file, struct ScoreInfo *scores)
+{
+ int i;
- putFile16BitBE(file, tape->level_nr);
+ for (i = 0; i < scores->num_entries; i++)
+ putFile32BitBE(file, scores->entry[i].time);
}
-static void SaveTape_BODY(FILE *file, struct TapeInfo *tape)
+static void SaveScore_TAPE(FILE *file, struct ScoreInfo *scores)
{
int i, j;
- for (i = 0; i < tape->length; i++)
+ for (i = 0; i < scores->num_entries; i++)
{
- if (tape->use_key_actions)
- {
- for (j = 0; j < MAX_PLAYERS; j++)
- if (tape->player_participates[j])
- putFile8Bit(file, tape->pos[i].action[j]);
- }
-
- if (tape->use_mouse_actions)
- {
- putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LX]);
- putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LY]);
- putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_BUTTON]);
- }
+ int size = strlen(scores->entry[i].tape_basename);
- putFile8Bit(file, tape->pos[i].delay);
+ for (j = 0; j < MAX_SCORE_TAPE_BASENAME_LEN; j++)
+ putFile8Bit(file, (j < size ? scores->entry[i].tape_basename[j] : 0));
}
}
-void SaveTape(int nr)
+static void SaveScoreToFilename(char *filename)
{
- char *filename = getTapeFilename(nr);
FILE *file;
- int tape_pos_size;
int info_chunk_size;
- int body_chunk_size;
+ int name_chunk_size;
+ int scor_chunk_size;
+ int sc4r_chunk_size;
+ int time_chunk_size;
+ int tape_chunk_size;
+ boolean has_large_score_values;
int i;
- InitTapeDirectory(leveldir_current->subdir);
-
if (!(file = fopen(filename, MODE_WRITE)))
{
- Error(ERR_WARN, "cannot save level recording file '%s'", filename);
+ Warn("cannot save score file '%s'", filename);
+
return;
}
- tape.file_version = FILE_VERSION_ACTUAL;
- tape.game_version = GAME_VERSION_ACTUAL;
-
- tape.num_participating_players = 0;
-
- // count number of participating players
- for (i = 0; i < MAX_PLAYERS; i++)
- if (tape.player_participates[i])
- tape.num_participating_players++;
+ info_chunk_size = 2 + (strlen(scores.level_identifier) + 1) + 2 + 2;
+ name_chunk_size = scores.num_entries * MAX_PLAYER_NAME_LEN;
+ scor_chunk_size = scores.num_entries * 2;
+ sc4r_chunk_size = scores.num_entries * 4;
+ time_chunk_size = scores.num_entries * 4;
+ tape_chunk_size = scores.num_entries * MAX_SCORE_TAPE_BASENAME_LEN;
- tape_pos_size = getTapePosSize(&tape);
-
- info_chunk_size = 2 + (strlen(tape.level_identifier) + 1) + 2;
- body_chunk_size = tape_pos_size * tape.length;
+ has_large_score_values = FALSE;
+ for (i = 0; i < scores.num_entries; i++)
+ if (scores.entry[i].score > 0xffff)
+ has_large_score_values = TRUE;
putFileChunkBE(file, "RND1", CHUNK_SIZE_UNDEFINED);
- putFileChunkBE(file, "TAPE", CHUNK_SIZE_NONE);
-
- putFileChunkBE(file, "VERS", TAPE_CHUNK_VERS_SIZE);
- SaveTape_VERS(file, &tape);
+ putFileChunkBE(file, "SCOR", CHUNK_SIZE_NONE);
- putFileChunkBE(file, "HEAD", TAPE_CHUNK_HEAD_SIZE);
- SaveTape_HEAD(file, &tape);
+ putFileChunkBE(file, "VERS", SCORE_CHUNK_VERS_SIZE);
+ SaveScore_VERS(file, &scores);
putFileChunkBE(file, "INFO", info_chunk_size);
- SaveTape_INFO(file, &tape);
+ SaveScore_INFO(file, &scores);
- putFileChunkBE(file, "BODY", body_chunk_size);
- SaveTape_BODY(file, &tape);
+ putFileChunkBE(file, "NAME", name_chunk_size);
+ SaveScore_NAME(file, &scores);
+
+ if (has_large_score_values)
+ {
+ putFileChunkBE(file, "SC4R", sc4r_chunk_size);
+ SaveScore_SC4R(file, &scores);
+ }
+ else
+ {
+ putFileChunkBE(file, "SCOR", scor_chunk_size);
+ SaveScore_SCOR(file, &scores);
+ }
+
+ putFileChunkBE(file, "TIME", time_chunk_size);
+ SaveScore_TIME(file, &scores);
+
+ putFileChunkBE(file, "TAPE", tape_chunk_size);
+ SaveScore_TAPE(file, &scores);
fclose(file);
SetFilePermissions(filename, PERMS_PRIVATE);
-
- tape.changed = FALSE;
}
-static boolean SaveTapeCheckedExt(int nr, char *msg_replace, char *msg_saved,
- unsigned int req_state_added)
+void SaveScore(int nr)
{
- char *filename = getTapeFilename(nr);
- boolean new_tape = !fileExists(filename);
- boolean tape_saved = FALSE;
+ char *filename = getScoreFilename(nr);
+ int i;
- if (new_tape || Request(msg_replace, REQ_ASK | req_state_added))
- {
- SaveTape(nr);
+ // used instead of "leveldir_current->subdir" (for network games)
+ InitScoreDirectory(levelset.identifier);
- if (new_tape)
- Request(msg_saved, REQ_CONFIRM | req_state_added);
+ scores.file_version = FILE_VERSION_ACTUAL;
+ scores.game_version = GAME_VERSION_ACTUAL;
- tape_saved = TRUE;
- }
+ strncpy(scores.level_identifier, levelset.identifier, MAX_FILENAME_LEN);
+ scores.level_identifier[MAX_FILENAME_LEN] = '\0';
+ scores.level_nr = level_nr;
- return tape_saved;
-}
+ for (i = 0; i < MAX_SCORE_ENTRIES; i++)
+ if (scores.entry[i].score == 0 &&
+ scores.entry[i].time == 0 &&
+ strEqual(scores.entry[i].name, EMPTY_PLAYER_NAME))
+ break;
-boolean SaveTapeChecked(int nr)
-{
- return SaveTapeCheckedExt(nr, "Replace old tape?", "Tape saved!", 0);
-}
+ scores.num_entries = i;
-boolean SaveTapeChecked_LevelSolved(int nr)
-{
- return SaveTapeCheckedExt(nr, "Level solved! Replace old tape?",
- "Level solved! Tape saved!", REQ_STAY_OPEN);
+ if (scores.num_entries == 0)
+ return;
+
+ SaveScoreToFilename(filename);
}
-void DumpTape(struct TapeInfo *tape)
+static void LoadServerScoreFromCache(int nr)
{
- int tape_frame_counter;
+ struct ScoreEntry score_entry;
+ struct
+ {
+ void *value;
+ boolean is_string;
+ int string_size;
+ }
+ score_mapping[] =
+ {
+ { &score_entry.score, FALSE, 0 },
+ { &score_entry.time, FALSE, 0 },
+ { score_entry.name, TRUE, MAX_PLAYER_NAME_LEN },
+ { score_entry.tape_basename, TRUE, MAX_FILENAME_LEN },
+ { score_entry.tape_date, TRUE, MAX_ISO_DATE_LEN },
+ { &score_entry.id, FALSE, 0 },
+ { score_entry.platform, TRUE, MAX_PLATFORM_TEXT_LEN },
+ { score_entry.version, TRUE, MAX_VERSION_TEXT_LEN },
+ { score_entry.country_code, TRUE, MAX_COUNTRY_CODE_LEN },
+ { score_entry.country_name, TRUE, MAX_COUNTRY_NAME_LEN },
+
+ { NULL, FALSE, 0 }
+ };
+ char *filename = getScoreCacheFilename(nr);
+ SetupFileHash *score_hash = loadSetupFileHash(filename);
int i, j;
- if (tape->no_valid_file)
- {
- Error(ERR_WARN, "cannot dump -- no valid tape file found");
+ server_scores.num_entries = 0;
+ if (score_hash == NULL)
return;
- }
- PrintLine("-", 79);
- Print("Tape of Level %03d (file version %08d, game version %08d)\n",
- tape->level_nr, tape->file_version, tape->game_version);
- Print(" (effective engine version %08d)\n",
- tape->engine_version);
- Print("Level series identifier: '%s'\n", tape->level_identifier);
- PrintLine("-", 79);
+ for (i = 0; i < MAX_SCORE_ENTRIES; i++)
+ {
+ score_entry = server_scores.entry[i];
- tape_frame_counter = 0;
+ for (j = 0; score_mapping[j].value != NULL; j++)
+ {
+ char token[10];
- for (i = 0; i < tape->length; i++)
- {
- if (i >= MAX_TAPE_LEN)
- break;
+ sprintf(token, "%02d.%d", i, j);
- Print("%04d: ", i);
+ char *value = getHashEntry(score_hash, token);
- for (j = 0; j < MAX_PLAYERS; j++)
- {
- if (tape->player_participates[j])
+ if (value == NULL)
+ continue;
+
+ if (score_mapping[j].is_string)
{
- int action = tape->pos[i].action[j];
+ char *score_value = (char *)score_mapping[j].value;
+ int value_size = score_mapping[j].string_size;
- Print("%d:%02x ", j, action);
- Print("[%c%c%c%c|%c%c] - ",
- (action & JOY_LEFT ? '<' : ' '),
- (action & JOY_RIGHT ? '>' : ' '),
- (action & JOY_UP ? '^' : ' '),
- (action & JOY_DOWN ? 'v' : ' '),
- (action & JOY_BUTTON_1 ? '1' : ' '),
- (action & JOY_BUTTON_2 ? '2' : ' '));
+ strncpy(score_value, value, value_size);
+ score_value[value_size] = '\0';
}
- }
+ else
+ {
+ int *score_value = (int *)score_mapping[j].value;
- Print("(%03d) ", tape->pos[i].delay);
- Print("[%05d]\n", tape_frame_counter);
+ *score_value = atoi(value);
+ }
- tape_frame_counter += tape->pos[i].delay;
+ server_scores.num_entries = i + 1;
+ }
+
+ server_scores.entry[i] = score_entry;
}
- PrintLine("-", 79);
+ freeSetupFileHash(score_hash);
}
-
-// ============================================================================
-// score file functions
-// ============================================================================
-
-void LoadScore(int nr)
+void LoadServerScore(int nr, boolean download_score)
{
- int i;
- char *filename = getScoreFilename(nr);
- char cookie[MAX_LINE_LEN];
- char line[MAX_LINE_LEN];
- char *line_ptr;
- FILE *file;
+ if (!setup.use_api_server)
+ return;
// always start with reliable default values
- for (i = 0; i < MAX_SCORE_ENTRIES; i++)
+ setServerScoreInfoToDefaults();
+
+ // 1st step: load server scores from cache file (which may not exist)
+ // (this should prevent reading it while the thread is writing to it)
+ LoadServerScoreFromCache(nr);
+
+ if (download_score && runtime.use_api_server)
{
- strcpy(highscore[i].Name, EMPTY_PLAYER_NAME);
- highscore[i].Score = 0;
+ // 2nd step: download server scores from score server to cache file
+ // (as thread, as it might time out if the server is not reachable)
+ ApiGetScoreAsThread(nr);
}
+}
- if (!(file = fopen(filename, MODE_READ)))
- return;
+void PrepareScoreTapesForUpload(char *leveldir_subdir)
+{
+ MarkTapeDirectoryUploadsAsIncomplete(leveldir_subdir);
- // check file identifier
- if (fgets(cookie, MAX_LINE_LEN, file) == NULL)
- cookie[0] = '\0';
- if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
- cookie[strlen(cookie) - 1] = '\0';
+ // if score tape not uploaded, ask for uploading missing tapes later
+ if (!setup.has_remaining_tapes)
+ setup.ask_for_remaining_tapes = TRUE;
+
+ setup.provide_uploading_tapes = TRUE;
+ setup.has_remaining_tapes = TRUE;
+
+ SaveSetup_ServerSetup();
+}
- if (!checkCookieString(cookie, SCORE_COOKIE))
+void SaveServerScore(int nr, boolean tape_saved)
+{
+ if (!runtime.use_api_server)
{
- Error(ERR_WARN, "unknown format of score file '%s'", filename);
- fclose(file);
+ PrepareScoreTapesForUpload(leveldir_current->subdir);
+
return;
}
- for (i = 0; i < MAX_SCORE_ENTRIES; i++)
- {
- if (fscanf(file, "%d", &highscore[i].Score) == EOF)
- Error(ERR_WARN, "fscanf() failed; %s", strerror(errno));
- if (fgets(line, MAX_LINE_LEN, file) == NULL)
- line[0] = '\0';
-
- if (strlen(line) > 0 && line[strlen(line) - 1] == '\n')
- line[strlen(line) - 1] = '\0';
+ ApiAddScoreAsThread(nr, tape_saved, NULL);
+}
- for (line_ptr = line; *line_ptr; line_ptr++)
- {
- if (*line_ptr != ' ' && *line_ptr != '\t' && *line_ptr != '\0')
- {
- strncpy(highscore[i].Name, line_ptr, MAX_PLAYER_NAME_LEN);
- highscore[i].Name[MAX_PLAYER_NAME_LEN] = '\0';
- break;
- }
- }
- }
+void SaveServerScoreFromFile(int nr, boolean tape_saved,
+ char *score_tape_filename)
+{
+ if (!runtime.use_api_server)
+ return;
- fclose(file);
+ ApiAddScoreAsThread(nr, tape_saved, score_tape_filename);
}
-void SaveScore(int nr)
+void LoadLocalAndServerScore(int nr, boolean download_score)
{
- int i;
- int permissions = (program.global_scores ? PERMS_PUBLIC : PERMS_PRIVATE);
- char *filename = getScoreFilename(nr);
- FILE *file;
+ int last_added_local = scores.last_added_local;
+ boolean force_last_added = scores.force_last_added;
- // used instead of "leveldir_current->subdir" (for network games)
- InitScoreDirectory(levelset.identifier);
+ // needed if only showing server scores
+ setScoreInfoToDefaults();
- if (!(file = fopen(filename, MODE_WRITE)))
- {
- Error(ERR_WARN, "cannot save score for level %d", nr);
- return;
- }
+ if (!strEqual(setup.scores_in_highscore_list, STR_SCORES_TYPE_SERVER_ONLY))
+ LoadScore(nr);
- fprintf(file, "%s\n\n", SCORE_COOKIE);
+ // restore last added local score entry (before merging server scores)
+ scores.last_added = scores.last_added_local = last_added_local;
- for (i = 0; i < MAX_SCORE_ENTRIES; i++)
- fprintf(file, "%d %s\n", highscore[i].Score, highscore[i].Name);
+ if (setup.use_api_server &&
+ !strEqual(setup.scores_in_highscore_list, STR_SCORES_TYPE_LOCAL_ONLY))
+ {
+ // load server scores from cache file and trigger update from server
+ LoadServerScore(nr, download_score);
- fclose(file);
+ // merge local scores with scores from server
+ MergeServerScore();
+ }
- SetFilePermissions(filename, permissions);
+ if (force_last_added)
+ scores.force_last_added = force_last_added;
}
TYPE_STRING,
&setup.player_name, "player_name"
},
+ {
+ TYPE_SWITCH,
+ &setup.multiple_users, "multiple_users"
+ },
{
TYPE_SWITCH,
&setup.sound, "sound"
TYPE_SWITCH,
&setup.toons, "toons"
},
+ {
+ TYPE_SWITCH,
+ &setup.global_animations, "global_animations"
+ },
{
TYPE_SWITCH,
&setup.scroll_delay, "scroll_delay"
TYPE_SWITCH,
&setup.autorecord, "automatic_tape_recording"
},
+ {
+ TYPE_SWITCH,
+ &setup.autorecord_after_replay, "autorecord_after_replay"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.auto_pause_on_start, "auto_pause_on_start"
+ },
{
TYPE_SWITCH,
&setup.show_titlescreen, "show_titlescreen"
},
{
TYPE_SWITCH,
- &setup.skip_scores_after_game, "skip_scores_after_game"
+ &setup.count_score_after_game, "count_score_after_game"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.show_scores_after_game, "show_scores_after_game"
},
{
TYPE_SWITCH,
TYPE_SWITCH,
&setup.ask_on_game_over, "ask_on_game_over"
},
+ {
+ TYPE_SWITCH,
+ &setup.ask_on_quit_game, "ask_on_quit_game"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.ask_on_quit_program, "ask_on_quit_program"
+ },
{
TYPE_SWITCH,
&setup.quick_switch, "quick_player_switch"
TYPE_SWITCH,
&setup.prefer_lowpass_sounds, "prefer_lowpass_sounds"
},
+ {
+ TYPE_SWITCH,
+ &setup.prefer_extra_panel_items, "prefer_extra_panel_items"
+ },
{
TYPE_SWITCH,
&setup.game_speed_extended, "game_speed_extended"
TYPE_INTEGER,
&setup.game_frame_delay, "game_frame_delay"
},
+ {
+ TYPE_SWITCH,
+ &setup.bd_skip_uncovering, "bd_skip_uncovering"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.bd_skip_hatching, "bd_skip_hatching"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.bd_scroll_delay, "bd_scroll_delay"
+ },
+ {
+ TYPE_SWITCH3,
+ &setup.bd_smooth_movements, "bd_smooth_movements"
+ },
{
TYPE_SWITCH,
&setup.sp_show_border_elements, "sp_show_border_elements"
},
{
TYPE_SWITCH,
- &setup.show_snapshot_buttons, "show_snapshot_buttons"
+ &setup.show_load_save_buttons, "show_load_save_buttons"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.show_undo_redo_buttons, "show_undo_redo_buttons"
+ },
+ {
+ TYPE_STRING,
+ &setup.scores_in_highscore_list, "scores_in_highscore_list"
},
{
TYPE_STRING,
TYPE_INTEGER,
&setup.touch.grid_ysize[1], "touch.virtual_buttons.1.ysize"
},
+ {
+ TYPE_SWITCH,
+ &setup.touch.overlay_buttons, "touch.overlay_buttons"
+ },
};
static struct TokenInfo auto_setup_tokens[] =
},
};
+static struct TokenInfo server_setup_tokens[] =
+{
+ {
+ TYPE_STRING,
+ &setup.player_uuid, "player_uuid"
+ },
+ {
+ TYPE_INTEGER,
+ &setup.player_version, "player_version"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.use_api_server, TEST_PREFIX "use_api_server"
+ },
+ {
+ TYPE_STRING,
+ &setup.api_server_hostname, TEST_PREFIX "api_server_hostname"
+ },
+ {
+ TYPE_STRING,
+ &setup.api_server_password, TEST_PREFIX "api_server_password"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.ask_for_uploading_tapes, TEST_PREFIX "ask_for_uploading_tapes"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.ask_for_remaining_tapes, TEST_PREFIX "ask_for_remaining_tapes"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.provide_uploading_tapes, TEST_PREFIX "provide_uploading_tapes"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.ask_for_using_api_server,TEST_PREFIX "ask_for_using_api_server"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.has_remaining_tapes, TEST_PREFIX "has_remaining_tapes"
+ },
+};
+
static struct TokenInfo editor_setup_tokens[] =
{
{
TYPE_SWITCH,
&setup.editor.show_element_token, "editor.show_element_token"
},
+ {
+ TYPE_SWITCH,
+ &setup.editor.show_read_only_warning, "editor.show_read_only_warning"
+ },
};
static struct TokenInfo editor_cascade_setup_tokens[] =
TYPE_SWITCH,
&setup.editor_cascade.el_bd, "editor.cascade.el_bd"
},
+ {
+ TYPE_SWITCH,
+ &setup.editor_cascade.el_bd_native, "editor.cascade.el_bd_native"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.editor_cascade.el_bd_effects, "editor.cascade.el_bd_effects"
+ },
{
TYPE_SWITCH,
&setup.editor_cascade.el_em, "editor.cascade.el_em"
TYPE_SWITCH,
&setup.editor_cascade.el_ge, "editor.cascade.el_ge"
},
+ {
+ TYPE_SWITCH,
+ &setup.editor_cascade.el_es, "editor.cascade.el_es"
+ },
{
TYPE_SWITCH,
&setup.editor_cascade.el_ref, "editor.cascade.el_ref"
TYPE_KEY_X11,
&setup.shortcut.load_game, "shortcut.load_game"
},
+ {
+ TYPE_KEY_X11,
+ &setup.shortcut.restart_game, "shortcut.restart_game"
+ },
+ {
+ TYPE_KEY_X11,
+ &setup.shortcut.pause_before_end, "shortcut.pause_before_end"
+ },
{
TYPE_KEY_X11,
&setup.shortcut.toggle_pause, "shortcut.toggle_pause"
TYPE_BOOLEAN,
&setup.internal.create_user_levelset, "create_user_levelset"
},
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_screens_from_main, "info_screens_from_main"
+ },
{
TYPE_BOOLEAN,
&setup.internal.menu_game, "menu_game"
},
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.menu_engines, "menu_engines"
+ },
{
TYPE_BOOLEAN,
&setup.internal.menu_editor, "menu_editor"
TYPE_BOOLEAN,
&setup.internal.menu_save_and_exit, "menu_save_and_exit"
},
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.menu_shortcuts_various, "menu_shortcuts_various"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.menu_shortcuts_focus, "menu_shortcuts_focus"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.menu_shortcuts_tape, "menu_shortcuts_tape"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.menu_shortcuts_sound, "menu_shortcuts_sound"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.menu_shortcuts_snap, "menu_shortcuts_snap"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_title, "info_title"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_elements, "info_elements"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_music, "info_music"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_credits, "info_credits"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_program, "info_program"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_version, "info_version"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_levelset, "info_levelset"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_exit, "info_exit"
+ },
};
static struct TokenInfo debug_setup_tokens[] =
TYPE_BOOLEAN,
&setup.debug.show_frames_per_second, "debug.show_frames_per_second"
},
+ {
+ TYPE_SWITCH3,
+ &setup.debug.xsn_mode, "debug.xsn_mode"
+ },
+ {
+ TYPE_INTEGER,
+ &setup.debug.xsn_percent, "debug.xsn_percent"
+ },
};
static struct TokenInfo options_setup_tokens[] =
TYPE_BOOLEAN,
&setup.options.verbose, "options.verbose"
},
+ {
+ TYPE_BOOLEAN,
+ &setup.options.debug, "options.debug"
+ },
+ {
+ TYPE_STRING,
+ &setup.options.debug_mode, "options.debug_mode"
+ },
};
-static char *get_corrected_login_name(char *login_name)
-{
- // needed because player name must be a fixed length string
- char *login_name_new = checked_malloc(MAX_PLAYER_NAME_LEN + 1);
-
- strncpy(login_name_new, login_name, MAX_PLAYER_NAME_LEN);
- login_name_new[MAX_PLAYER_NAME_LEN] = '\0';
-
- if (strlen(login_name) > MAX_PLAYER_NAME_LEN) // name has been cut
- if (strchr(login_name_new, ' '))
- *strchr(login_name_new, ' ') = '\0';
-
- return login_name_new;
-}
-
static void setSetupInfoToDefaults(struct SetupInfo *si)
{
int i;
- si->player_name = get_corrected_login_name(getLoginName());
+ si->player_name = getStringCopy(getDefaultUserName(user.nr));
+
+ si->multiple_users = TRUE;
si->sound = TRUE;
si->sound_loops = TRUE;
si->sound_music = TRUE;
si->sound_simple = TRUE;
si->toons = TRUE;
+ si->global_animations = TRUE;
si->scroll_delay = TRUE;
si->forced_scroll_delay = FALSE;
si->scroll_delay_value = STD_SCROLL_DELAY;
si->engine_snapshot_memory = SNAPSHOT_MEMORY_DEFAULT;
si->fade_screens = TRUE;
si->autorecord = TRUE;
+ si->autorecord_after_replay = TRUE;
+ si->auto_pause_on_start = FALSE;
si->show_titlescreen = TRUE;
si->quick_doors = FALSE;
si->team_mode = FALSE;
si->skip_levels = TRUE;
si->increment_levels = TRUE;
si->auto_play_next_level = TRUE;
- si->skip_scores_after_game = FALSE;
+ si->count_score_after_game = TRUE;
+ si->show_scores_after_game = TRUE;
si->time_limit = TRUE;
si->fullscreen = FALSE;
si->window_scaling_percent = STD_WINDOW_SCALING_PERCENT;
si->ask_on_escape = TRUE;
si->ask_on_escape_editor = TRUE;
si->ask_on_game_over = TRUE;
+ si->ask_on_quit_game = TRUE;
+ si->ask_on_quit_program = TRUE;
si->quick_switch = FALSE;
si->input_on_focus = FALSE;
si->prefer_aga_graphics = TRUE;
si->prefer_lowpass_sounds = FALSE;
+ si->prefer_extra_panel_items = TRUE;
si->game_speed_extended = FALSE;
si->game_frame_delay = GAME_FRAME_DELAY;
+ si->bd_skip_uncovering = FALSE;
+ si->bd_skip_hatching = FALSE;
+ si->bd_scroll_delay = TRUE;
+ si->bd_smooth_movements = AUTO;
si->sp_show_border_elements = FALSE;
si->small_game_graphics = FALSE;
- si->show_snapshot_buttons = FALSE;
+ si->show_load_save_buttons = FALSE;
+ si->show_undo_redo_buttons = FALSE;
+ si->scores_in_highscore_list = getStringCopy(STR_SCORES_TYPE_DEFAULT);
si->graphics_set = getStringCopy(GFX_CLASSIC_SUBDIR);
si->sounds_set = getStringCopy(SND_CLASSIC_SUBDIR);
si->touch.grid_initialized = video.initialized;
+ si->touch.overlay_buttons = FALSE;
+
si->editor.el_boulderdash = TRUE;
+ si->editor.el_boulderdash_native = TRUE;
+ si->editor.el_boulderdash_effects = TRUE;
si->editor.el_emerald_mine = TRUE;
si->editor.el_emerald_mine_club = TRUE;
si->editor.el_more = TRUE;
si->editor.show_element_token = FALSE;
+ si->editor.show_read_only_warning = TRUE;
+
si->editor.use_template_for_new_levels = TRUE;
si->shortcut.save_game = DEFAULT_KEY_SAVE_GAME;
si->shortcut.load_game = DEFAULT_KEY_LOAD_GAME;
+ si->shortcut.restart_game = DEFAULT_KEY_RESTART_GAME;
+ si->shortcut.pause_before_end = DEFAULT_KEY_PAUSE_BEFORE_END;
si->shortcut.toggle_pause = DEFAULT_KEY_TOGGLE_PAUSE;
si->shortcut.focus_player[0] = DEFAULT_KEY_FOCUS_PLAYER_1;
for (i = 0; i < MAX_PLAYERS; i++)
{
si->input[i].use_joystick = FALSE;
- si->input[i].joy.device_name=getStringCopy(getDeviceNameFromJoystickNr(i));
+ si->input[i].joy.device_name = getStringCopy(getDeviceNameFromJoystickNr(i));
si->input[i].joy.xleft = JOYSTICK_XLEFT;
si->input[i].joy.xmiddle = JOYSTICK_XMIDDLE;
si->input[i].joy.xright = JOYSTICK_XRIGHT;
si->internal.choose_from_top_leveldir = FALSE;
si->internal.show_scaling_in_title = TRUE;
si->internal.create_user_levelset = TRUE;
+ si->internal.info_screens_from_main = FALSE;
si->internal.default_window_width = WIN_XSIZE_DEFAULT;
si->internal.default_window_height = WIN_YSIZE_DEFAULT;
si->debug.show_frames_per_second = FALSE;
+ si->debug.xsn_mode = AUTO;
+ si->debug.xsn_percent = 0;
+
si->options.verbose = FALSE;
+ si->options.debug = FALSE;
+ si->options.debug_mode = getStringCopy(ARG_UNDEFINED_STRING);
#if defined(PLATFORM_ANDROID)
si->fullscreen = TRUE;
+ si->touch.overlay_buttons = TRUE;
#endif
+
+ setHideSetupEntry(&setup.debug.xsn_mode);
}
static void setSetupInfoToDefaults_AutoSetup(struct SetupInfo *si)
si->auto_setup.editor_zoom_tilesize = MINI_TILESIZE;
}
+static void setSetupInfoToDefaults_ServerSetup(struct SetupInfo *si)
+{
+ si->player_uuid = NULL; // (will be set later)
+ si->player_version = 1; // (will be set later)
+
+ si->use_api_server = TRUE;
+ si->api_server_hostname = getStringCopy(API_SERVER_HOSTNAME);
+ si->api_server_password = getStringCopy(UNDEFINED_PASSWORD);
+ si->ask_for_uploading_tapes = TRUE;
+ si->ask_for_remaining_tapes = FALSE;
+ si->provide_uploading_tapes = TRUE;
+ si->ask_for_using_api_server = TRUE;
+ si->has_remaining_tapes = FALSE;
+}
+
static void setSetupInfoToDefaults_EditorCascade(struct SetupInfo *si)
{
si->editor_cascade.el_bd = TRUE;
+ si->editor_cascade.el_bd_native = TRUE;
+ si->editor_cascade.el_bd_effects = FALSE;
si->editor_cascade.el_em = TRUE;
si->editor_cascade.el_emc = TRUE;
si->editor_cascade.el_rnd = TRUE;
si->editor_cascade.el_steel_chars = FALSE;
si->editor_cascade.el_ce = FALSE;
si->editor_cascade.el_ge = FALSE;
+ si->editor_cascade.el_es = FALSE;
si->editor_cascade.el_ref = FALSE;
si->editor_cascade.el_user = FALSE;
si->editor_cascade.el_dynamic = FALSE;
{
char *hide_setup_token = getHideSetupToken(setup_value);
+ if (hide_setup_hash == NULL)
+ hide_setup_hash = newSetupFileHash();
+
if (setup_value != NULL)
setHashEntry(hide_setup_hash, hide_setup_token, "");
}
+void removeHideSetupEntry(void *setup_value)
+{
+ char *hide_setup_token = getHideSetupToken(setup_value);
+
+ if (setup_value != NULL)
+ removeHashEntry(hide_setup_hash, hide_setup_token);
+}
+
boolean hideSetupEntry(void *setup_value)
{
char *hide_setup_token = getHideSetupToken(setup_value);
// check if this setup option should be hidden in the setup menu
if (token_hide_value != NULL && get_boolean_from_string(token_hide_value))
setHideSetupEntry(token_info[token_nr].value);
+
+ free(token_hide_text);
}
static void setSetupInfoFromTokenInfo(SetupFileHash *setup_file_hash,
token_info[token_nr].text);
}
-static void decodeSetupFileHash(SetupFileHash *setup_file_hash)
+static void decodeSetupFileHash_Default(SetupFileHash *setup_file_hash)
{
int i, pnr;
if (!setup_file_hash)
return;
- if (hide_setup_hash == NULL)
- hide_setup_hash = newSetupFileHash();
-
for (i = 0; i < ARRAY_SIZE(global_setup_tokens); i++)
setSetupInfoFromTokenInfo(setup_file_hash, global_setup_tokens, i);
auto_setup_tokens[i].text));
}
+static void decodeSetupFileHash_ServerSetup(SetupFileHash *setup_file_hash)
+{
+ int i;
+
+ if (!setup_file_hash)
+ return;
+
+ for (i = 0; i < ARRAY_SIZE(server_setup_tokens); i++)
+ setSetupInfo(server_setup_tokens, i,
+ getHashEntry(setup_file_hash,
+ server_setup_tokens[i].text));
+}
+
static void decodeSetupFileHash_EditorCascade(SetupFileHash *setup_file_hash)
{
int i;
editor_cascade_setup_tokens[i].text));
}
+void LoadUserNames(void)
+{
+ int last_user_nr = user.nr;
+ int i;
+
+ if (global.user_names != NULL)
+ {
+ for (i = 0; i < MAX_PLAYER_NAMES; i++)
+ checked_free(global.user_names[i]);
+
+ checked_free(global.user_names);
+ }
+
+ global.user_names = checked_calloc(MAX_PLAYER_NAMES * sizeof(char *));
+
+ for (i = 0; i < MAX_PLAYER_NAMES; i++)
+ {
+ user.nr = i;
+
+ SetupFileHash *setup_file_hash = loadSetupFileHash(getSetupFilename());
+
+ if (setup_file_hash)
+ {
+ char *player_name = getHashEntry(setup_file_hash, "player_name");
+
+ global.user_names[i] = getFixedUserName(player_name);
+
+ freeSetupFileHash(setup_file_hash);
+ }
+
+ if (global.user_names[i] == NULL)
+ global.user_names[i] = getStringCopy(getDefaultUserName(i));
+ }
+
+ user.nr = last_user_nr;
+}
+
void LoadSetupFromFilename(char *filename)
{
SetupFileHash *setup_file_hash = loadSetupFileHash(filename);
if (setup_file_hash)
{
- decodeSetupFileHash(setup_file_hash);
+ decodeSetupFileHash_Default(setup_file_hash);
freeSetupFileHash(setup_file_hash);
}
else
{
- Error(ERR_DEBUG, "using default setup values");
+ Debug("setup", "using default setup values");
}
}
char *player_name_new;
// needed to work around problems with fixed length strings
- player_name_new = get_corrected_login_name(setup.player_name);
+ player_name_new = getFixedUserName(setup.player_name);
free(setup.player_name);
setup.player_name = player_name_new;
MIN(MAX(MIN_SCROLL_DELAY, setup.scroll_delay_value), MAX_SCROLL_DELAY);
}
-void LoadSetup(void)
+void LoadSetup_Default(void)
{
char *filename;
// try to load setup values from default setup file
filename = getDefaultSetupFilename();
+ if (fileExists(filename))
+ LoadSetupFromFilename(filename);
+
+ // try to load setup values from platform setup file
+ filename = getPlatformSetupFilename();
+
if (fileExists(filename))
LoadSetupFromFilename(filename);
free(filename);
}
+void LoadSetup_ServerSetup(void)
+{
+ char *filename = getPath2(getSetupDir(), SERVERSETUP_FILENAME);
+ SetupFileHash *setup_file_hash = NULL;
+
+ // always start with reliable default values
+ setSetupInfoToDefaults_ServerSetup(&setup);
+
+ setup_file_hash = loadSetupFileHash(filename);
+
+ if (setup_file_hash)
+ {
+ decodeSetupFileHash_ServerSetup(setup_file_hash);
+
+ freeSetupFileHash(setup_file_hash);
+ }
+
+ free(filename);
+
+ if (setup.player_uuid == NULL)
+ {
+ // player UUID does not yet exist in setup file
+ setup.player_uuid = getStringCopy(getUUID());
+ setup.player_version = 2;
+
+ SaveSetup_ServerSetup();
+ }
+}
+
void LoadSetup_EditorCascade(void)
{
char *filename = getPath2(getSetupDir(), EDITORCASCADE_FILENAME);
free(filename);
}
+void LoadSetup(void)
+{
+ LoadSetup_Default();
+ LoadSetup_AutoSetup();
+ LoadSetup_ServerSetup();
+ LoadSetup_EditorCascade();
+}
+
static void addGameControllerMappingToHash(SetupFileHash *mappings_hash,
char *mapping_line)
{
if (!(file = fopen(filename, MODE_READ)))
{
- Error(ERR_WARN, "cannot read game controller mappings file '%s'", filename);
+ Warn("cannot read game controller mappings file '%s'", filename);
return;
}
fclose(file);
}
-void SaveSetup(void)
+void SaveSetup_Default(void)
{
char *filename = getSetupFilename();
FILE *file;
if (!(file = fopen(filename, MODE_WRITE)))
{
- Error(ERR_WARN, "cannot write setup file '%s'", filename);
+ Warn("cannot write setup file '%s'", filename);
+
return;
}
for (i = 0; i < ARRAY_SIZE(global_setup_tokens); i++)
{
// just to make things nicer :)
- if (global_setup_tokens[i].value == &setup.sound ||
+ if (global_setup_tokens[i].value == &setup.multiple_users ||
+ global_setup_tokens[i].value == &setup.sound ||
global_setup_tokens[i].value == &setup.graphics_set ||
global_setup_tokens[i].value == &setup.volume_simple ||
global_setup_tokens[i].value == &setup.network_mode ||
fprintf(file, "\n");
for (i = 0; i < ARRAY_SIZE(debug_setup_tokens); i++)
- fprintf(file, "%s\n", getSetupLine(debug_setup_tokens, "", i));
+ if (!strPrefix(debug_setup_tokens[i].text, "debug.xsn_") ||
+ setup.debug.xsn_mode != AUTO)
+ fprintf(file, "%s\n", getSetupLine(debug_setup_tokens, "", i));
fprintf(file, "\n");
for (i = 0; i < ARRAY_SIZE(options_setup_tokens); i++)
if (!(file = fopen(filename, MODE_WRITE)))
{
- Error(ERR_WARN, "cannot write auto setup file '%s'", filename);
+ Warn("cannot write auto setup file '%s'", filename);
+
free(filename);
+
return;
}
free(filename);
}
+void SaveSetup_ServerSetup(void)
+{
+ char *filename = getPath2(getSetupDir(), SERVERSETUP_FILENAME);
+ FILE *file;
+ int i;
+
+ InitUserDataDirectory();
+
+ if (!(file = fopen(filename, MODE_WRITE)))
+ {
+ Warn("cannot write server setup file '%s'", filename);
+
+ free(filename);
+
+ return;
+ }
+
+ fprintFileHeader(file, SERVERSETUP_FILENAME);
+
+ for (i = 0; i < ARRAY_SIZE(server_setup_tokens); i++)
+ {
+ // just to make things nicer :)
+ if (server_setup_tokens[i].value == &setup.use_api_server)
+ fprintf(file, "\n");
+
+ fprintf(file, "%s\n", getSetupLine(server_setup_tokens, "", i));
+ }
+
+ fclose(file);
+
+ SetFilePermissions(filename, PERMS_PRIVATE);
+
+ free(filename);
+}
+
void SaveSetup_EditorCascade(void)
{
char *filename = getPath2(getSetupDir(), EDITORCASCADE_FILENAME);
if (!(file = fopen(filename, MODE_WRITE)))
{
- Error(ERR_WARN, "cannot write editor cascade state file '%s'", filename);
+ Warn("cannot write editor cascade state file '%s'", filename);
+
free(filename);
+
return;
}
free(filename);
}
+void SaveSetup(void)
+{
+ SaveSetup_Default();
+ SaveSetup_AutoSetup();
+ SaveSetup_ServerSetup();
+ SaveSetup_EditorCascade();
+}
+
static void SaveSetup_WriteGameControllerMappings(SetupFileHash *mappings_hash,
char *filename)
{
if (!(file = fopen(filename, MODE_WRITE)))
{
- Error(ERR_WARN, "cannot write game controller mappings file '%s'",filename);
+ Warn("cannot write game controller mappings file '%s'", filename);
return;
}
if (value != NULL)
return atoi(value);
- Error(ERR_WARN, "unknown element token '%s'", token);
+ Warn("unknown element token '%s'", token);
return EL_UNDEFINED;
}
return gaeli->num_event_values;
}
-// This function checks if a string <s> of the format "string1, string2, ..."
-// exactly contains a string <s_contained>.
+// This function checks if a string <s> of the format "string1, string2, ..."
+// exactly contains a string <s_contained>.
+
+static boolean string_has_parameter(char *s, char *s_contained)
+{
+ char *substring;
+
+ if (s == NULL || s_contained == NULL)
+ return FALSE;
+
+ if (strlen(s_contained) > strlen(s))
+ return FALSE;
+
+ if (strncmp(s, s_contained, strlen(s_contained)) == 0)
+ {
+ char next_char = s[strlen(s_contained)];
+
+ // check if next character is delimiter or whitespace
+ if (next_char == ',' || next_char == '\0' ||
+ next_char == ' ' || next_char == '\t')
+ return TRUE;
+ }
+
+ // check if string contains another parameter string after a comma
+ substring = strchr(s, ',');
+ if (substring == NULL) // string does not contain a comma
+ return FALSE;
+
+ // advance string pointer to next character after the comma
+ substring++;
+
+ // skip potential whitespaces after the comma
+ while (*substring == ' ' || *substring == '\t')
+ substring++;
+
+ return string_has_parameter(substring, s_contained);
+}
+
+static int get_anim_parameter_value_ce(char *s)
+{
+ char *s_ptr = s;
+ char *pattern_1 = "ce_change:custom_";
+ char *pattern_2 = ".page_";
+ int pattern_1_len = strlen(pattern_1);
+ char *matching_char = strstr(s_ptr, pattern_1);
+ int result = ANIM_EVENT_NONE;
+
+ if (matching_char == NULL)
+ return ANIM_EVENT_NONE;
+
+ result = ANIM_EVENT_CE_CHANGE;
+
+ s_ptr = matching_char + pattern_1_len;
+
+ // check for custom element number ("custom_X", "custom_XX" or "custom_XXX")
+ if (*s_ptr >= '0' && *s_ptr <= '9')
+ {
+ int gic_ce_nr = (*s_ptr++ - '0');
+
+ if (*s_ptr >= '0' && *s_ptr <= '9')
+ {
+ gic_ce_nr = 10 * gic_ce_nr + (*s_ptr++ - '0');
+
+ if (*s_ptr >= '0' && *s_ptr <= '9')
+ gic_ce_nr = 10 * gic_ce_nr + (*s_ptr++ - '0');
+ }
+
+ if (gic_ce_nr < 1 || gic_ce_nr > NUM_CUSTOM_ELEMENTS)
+ return ANIM_EVENT_NONE;
+
+ // custom element stored as 0 to 255
+ gic_ce_nr--;
+
+ result |= gic_ce_nr << ANIM_EVENT_CE_BIT;
+ }
+ else
+ {
+ // invalid custom element number specified
+
+ return ANIM_EVENT_NONE;
+ }
+
+ // check for change page number ("page_X" or "page_XX") (optional)
+ if (strPrefix(s_ptr, pattern_2))
+ {
+ s_ptr += strlen(pattern_2);
+
+ if (*s_ptr >= '0' && *s_ptr <= '9')
+ {
+ int gic_page_nr = (*s_ptr++ - '0');
-static boolean string_has_parameter(char *s, char *s_contained)
-{
- char *substring;
+ if (*s_ptr >= '0' && *s_ptr <= '9')
+ gic_page_nr = 10 * gic_page_nr + (*s_ptr++ - '0');
- if (s == NULL || s_contained == NULL)
- return FALSE;
+ if (gic_page_nr < 1 || gic_page_nr > MAX_CHANGE_PAGES)
+ return ANIM_EVENT_NONE;
- if (strlen(s_contained) > strlen(s))
- return FALSE;
+ // change page stored as 1 to 32 (0 means "all change pages")
- if (strncmp(s, s_contained, strlen(s_contained)) == 0)
- {
- char next_char = s[strlen(s_contained)];
+ result |= gic_page_nr << ANIM_EVENT_PAGE_BIT;
+ }
+ else
+ {
+ // invalid animation part number specified
- // check if next character is delimiter or whitespace
- return (next_char == ',' || next_char == '\0' ||
- next_char == ' ' || next_char == '\t' ? TRUE : FALSE);
+ return ANIM_EVENT_NONE;
+ }
}
- // check if string contains another parameter string after a comma
- substring = strchr(s, ',');
- if (substring == NULL) // string does not contain a comma
- return FALSE;
-
- // advance string pointer to next character after the comma
- substring++;
-
- // skip potential whitespaces after the comma
- while (*substring == ' ' || *substring == '\t')
- substring++;
+ // discard result if next character is neither delimiter nor whitespace
+ if (!(*s_ptr == ',' || *s_ptr == '\0' ||
+ *s_ptr == ' ' || *s_ptr == '\t'))
+ return ANIM_EVENT_NONE;
- return string_has_parameter(substring, s_contained);
+ return result;
}
static int get_anim_parameter_value(char *s)
int result = ANIM_EVENT_NONE;
int i;
+ result = get_anim_parameter_value_ce(s);
+
+ if (result != ANIM_EVENT_NONE)
+ return result;
+
for (i = 0; i < ARRAY_SIZE(event_value); i++)
{
matching_char = strstr(s_ptr, pattern_1[i]);
static int get_anim_action_parameter_value(char *token)
{
+ // check most common default case first to massively speed things up
+ if (strEqual(token, ARG_UNDEFINED))
+ return ANIM_EVENT_ACTION_NONE;
+
int result = getImageIDFromToken(token);
if (result == -1)
result = -(int)key;
}
+ if (result == -1)
+ {
+ if (isURL(token))
+ {
+ result = get_hash_from_string(token); // unsigned int => int
+ result = ABS(result); // may be negative now
+ result += (result < MAX_IMAGE_FILES ? MAX_IMAGE_FILES : 0);
+
+ setHashEntry(anim_url_hash, int2str(result, 0), token);
+ }
+ }
+
if (result == -1)
result = ANIM_EVENT_ACTION_NONE;
strEqual(value, "lower") ? POS_LOWER :
strEqual(value, "bottom") ? POS_BOTTOM :
strEqual(value, "any") ? POS_ANY :
+ strEqual(value, "ce") ? POS_CE :
+ strEqual(value, "ce_trigger") ? POS_CE_TRIGGER :
strEqual(value, "last") ? POS_LAST : POS_UNDEFINED);
}
else if (strEqual(suffix, ".align"))
string_has_parameter(value, "pingpong") ? ANIM_PINGPONG :
string_has_parameter(value, "pingpong2") ? ANIM_PINGPONG2 :
string_has_parameter(value, "random") ? ANIM_RANDOM :
+ string_has_parameter(value, "random_static") ? ANIM_RANDOM_STATIC :
string_has_parameter(value, "ce_value") ? ANIM_CE_VALUE :
string_has_parameter(value, "ce_score") ? ANIM_CE_SCORE :
string_has_parameter(value, "ce_delay") ? ANIM_CE_DELAY :
string_has_parameter(value, "vertical") ? ANIM_VERTICAL :
string_has_parameter(value, "centered") ? ANIM_CENTERED :
string_has_parameter(value, "all") ? ANIM_ALL :
+ string_has_parameter(value, "tiled") ? ANIM_TILED :
+ string_has_parameter(value, "level_nr") ? ANIM_LEVEL_NR :
ANIM_DEFAULT);
if (string_has_parameter(value, "once"))
else if (strEqual(suffix, ".class"))
{
result = (strEqual(value, ARG_UNDEFINED) ? ARG_UNDEFINED_VALUE :
- get_hash_from_key(value));
+ get_hash_from_string(value));
}
else if (strEqual(suffix, ".style"))
{
if (string_has_parameter(value, "reverse"))
result |= STYLE_REVERSE;
+ if (string_has_parameter(value, "leftmost_position"))
+ result |= STYLE_LEFTMOST_POSITION;
+
if (string_has_parameter(value, "block_clicks"))
result |= STYLE_BLOCK;
if (string_has_parameter(value, "multiple_actions"))
result |= STYLE_MULTIPLE_ACTIONS;
+
+ if (string_has_parameter(value, "consume_ce_event"))
+ result |= STYLE_CONSUME_CE_EVENT;
}
else if (strEqual(suffix, ".fade_mode"))
{
result = (string_has_parameter(value, "none") ? FADE_MODE_NONE :
string_has_parameter(value, "fade") ? FADE_MODE_FADE :
+ string_has_parameter(value, "fade_in") ? FADE_MODE_FADE_IN :
+ string_has_parameter(value, "fade_out") ? FADE_MODE_FADE_OUT :
string_has_parameter(value, "crossfade") ? FADE_MODE_CROSSFADE :
string_has_parameter(value, "melt") ? FADE_MODE_MELT :
string_has_parameter(value, "curtain") ? FADE_MODE_CURTAIN :
return get_parameter_value(value_raw, suffix, TYPE_INTEGER);
}
-void InitMenuDesignSettings_Static(void)
+void InitMenuDesignSettings_FromHash(SetupFileHash *setup_file_hash,
+ boolean ignore_defaults)
{
int i;
- // always start with reliable default values from static default config
for (i = 0; image_config_vars[i].token != NULL; i++)
{
- char *value = getHashEntry(image_config_hash, image_config_vars[i].token);
+ char *value = getHashEntry(setup_file_hash, image_config_vars[i].token);
+
+ // (ignore definitions set to "[DEFAULT]" which are already initialized)
+ if (ignore_defaults && strEqual(value, ARG_DEFAULT))
+ continue;
if (value != NULL)
*image_config_vars[i].value =
}
}
+void InitMenuDesignSettings_Static(void)
+{
+ // always start with reliable default values from static default config
+ InitMenuDesignSettings_FromHash(image_config_hash, FALSE);
+}
+
static void InitMenuDesignSettings_SpecialPreProcessing(void)
{
int i;
vp_playfield->width = MIN(vp_playfield->width, vp_playfield->max_width);
if (vp_playfield->max_height != -1)
- vp_playfield->height = MIN(vp_playfield->height,vp_playfield->max_height);
+ vp_playfield->height = MIN(vp_playfield->height, vp_playfield->max_height);
// adjust playfield position according to specified alignment
}
}
+static void InitMenuDesignSettings_PreviewPlayers_Ext(SetupFileHash *hash,
+ boolean initialize)
+{
+ // special case: check if network and preview player positions are redefined,
+ // to compare this later against the main menu level preview being redefined
+ struct TokenIntPtrInfo menu_config_players[] =
+ {
+ { "main.network_players.x", &menu.main.network_players.redefined },
+ { "main.network_players.y", &menu.main.network_players.redefined },
+ { "main.preview_players.x", &menu.main.preview_players.redefined },
+ { "main.preview_players.y", &menu.main.preview_players.redefined },
+ { "preview.x", &preview.redefined },
+ { "preview.y", &preview.redefined }
+ };
+ int i;
+
+ if (initialize)
+ {
+ for (i = 0; i < ARRAY_SIZE(menu_config_players); i++)
+ *menu_config_players[i].value = FALSE;
+ }
+ else
+ {
+ for (i = 0; i < ARRAY_SIZE(menu_config_players); i++)
+ if (getHashEntry(hash, menu_config_players[i].token) != NULL)
+ *menu_config_players[i].value = TRUE;
+ }
+}
+
+static void InitMenuDesignSettings_PreviewPlayers(void)
+{
+ InitMenuDesignSettings_PreviewPlayers_Ext(NULL, TRUE);
+}
+
+static void InitMenuDesignSettings_PreviewPlayers_FromHash(SetupFileHash *hash)
+{
+ InitMenuDesignSettings_PreviewPlayers_Ext(hash, FALSE);
+}
+
static void LoadMenuDesignSettingsFromFilename(char *filename)
{
static struct TitleFadingInfo tfi;
{
{ "menu.draw_xoffset.INFO", &menu.draw_xoffset_info[i] },
{ "menu.draw_yoffset.INFO", &menu.draw_yoffset_info[i] },
- { "menu.list_size.INFO", &menu.list_size_info[i] }
+ { "menu.list_size.INFO", &menu.list_size_info[i] },
+ { "menu.list_entry_size.INFO", &menu.list_entry_size_info[i] },
+ { "menu.tile_size.INFO", &menu.tile_size_info[i] }
};
for (j = 0; j < ARRAY_SIZE(menu_config); j++)
struct TokenIntPtrInfo menu_config[] =
{
{ "menu.left_spacing.INFO", &menu.left_spacing_info[i] },
+ { "menu.middle_spacing.INFO", &menu.middle_spacing_info[i] },
{ "menu.right_spacing.INFO", &menu.right_spacing_info[i] },
{ "menu.top_spacing.INFO", &menu.top_spacing_info[i] },
{ "menu.bottom_spacing.INFO", &menu.bottom_spacing_info[i] },
}
}
- // special case: check if network and preview player positions are redefined,
- // to compare this later against the main menu level preview being redefined
- struct TokenIntPtrInfo menu_config_players[] =
- {
- { "main.network_players.x", &menu.main.network_players.redefined },
- { "main.network_players.y", &menu.main.network_players.redefined },
- { "main.preview_players.x", &menu.main.preview_players.redefined },
- { "main.preview_players.y", &menu.main.preview_players.redefined },
- { "preview.x", &preview.redefined },
- { "preview.y", &preview.redefined }
- };
-
- for (i = 0; i < ARRAY_SIZE(menu_config_players); i++)
- *menu_config_players[i].value = FALSE;
-
- for (i = 0; i < ARRAY_SIZE(menu_config_players); i++)
- if (getHashEntry(setup_file_hash, menu_config_players[i].token) != NULL)
- *menu_config_players[i].value = TRUE;
-
// read (and overwrite with) values that may be specified in config file
- for (i = 0; image_config_vars[i].token != NULL; i++)
- {
- char *value = getHashEntry(setup_file_hash, image_config_vars[i].token);
+ InitMenuDesignSettings_FromHash(setup_file_hash, TRUE);
- // (ignore definitions set to "[DEFAULT]" which are already initialized)
- if (value != NULL && !strEqual(value, ARG_DEFAULT))
- *image_config_vars[i].value =
- get_token_parameter_value(image_config_vars[i].token, value);
- }
+ // special case: check if network and preview player positions are redefined
+ InitMenuDesignSettings_PreviewPlayers_FromHash(setup_file_hash);
freeSetupFileHash(setup_file_hash);
}
InitMenuDesignSettings_Static();
InitMenuDesignSettings_SpecialPreProcessing();
+ InitMenuDesignSettings_PreviewPlayers();
if (!GFX_OVERRIDE_ARTWORK(ARTWORK_TYPE_GRAPHICS))
{
InitMenuDesignSettings_SpecialPostProcessing_AfterGraphics();
}
+void InitSoundSettings_FromHash(SetupFileHash *setup_file_hash,
+ boolean ignore_defaults)
+{
+ int i;
+
+ for (i = 0; sound_config_vars[i].token != NULL; i++)
+ {
+ char *value = getHashEntry(setup_file_hash, sound_config_vars[i].token);
+
+ // (ignore definitions set to "[DEFAULT]" which are already initialized)
+ if (ignore_defaults && strEqual(value, ARG_DEFAULT))
+ continue;
+
+ if (value != NULL)
+ *sound_config_vars[i].value =
+ get_token_parameter_value(sound_config_vars[i].token, value);
+ }
+}
+
+void InitSoundSettings_Static(void)
+{
+ // always start with reliable default values from static default config
+ InitSoundSettings_FromHash(sound_config_hash, FALSE);
+}
+
+static void LoadSoundSettingsFromFilename(char *filename)
+{
+ SetupFileHash *setup_file_hash;
+
+ if ((setup_file_hash = loadSetupFileHash(filename)) == NULL)
+ return;
+
+ // read (and overwrite with) values that may be specified in config file
+ InitSoundSettings_FromHash(setup_file_hash, TRUE);
+
+ freeSetupFileHash(setup_file_hash);
+}
+
+void LoadSoundSettings(void)
+{
+ char *filename_base = UNDEFINED_FILENAME, *filename_local;
+
+ InitSoundSettings_Static();
+
+ if (!GFX_OVERRIDE_ARTWORK(ARTWORK_TYPE_SOUNDS))
+ {
+ // first look for special settings configured in level series config
+ filename_base = getCustomArtworkLevelConfigFilename(ARTWORK_TYPE_SOUNDS);
+
+ if (fileExists(filename_base))
+ LoadSoundSettingsFromFilename(filename_base);
+ }
+
+ filename_local = getCustomArtworkConfigFilename(ARTWORK_TYPE_SOUNDS);
+
+ if (filename_local != NULL && !strEqual(filename_base, filename_local))
+ LoadSoundSettingsFromFilename(filename_local);
+}
+
void LoadUserDefinedEditorElementList(int **elements, int *num_elements)
{
char *filename = getEditorSetupFilename();
{
if (num_unknown_tokens == 0)
{
- Error(ERR_INFO_LINE, "-");
- Error(ERR_INFO, "warning: unknown token(s) found in config file:");
- Error(ERR_INFO, "- config file: '%s'", filename);
+ Warn("---");
+ Warn("unknown token(s) found in config file:");
+ Warn("- config file: '%s'", filename);
num_unknown_tokens++;
}
- Error(ERR_INFO, "- token: '%s'", list->token);
+ Warn("- token: '%s'", list->token);
}
}
if (num_unknown_tokens > 0)
- Error(ERR_INFO_LINE, "-");
+ Warn("---");
while (*num_elements % 4) // pad with empty elements, if needed
(*elements)[(*num_elements)++] = EL_EMPTY;
#if 0
for (i = 0; i < *num_elements; i++)
- printf("editor: element '%s' [%d]\n",
- element_info[(*elements)[i]].token_name, (*elements)[i]);
+ Debug("editor", "element '%s' [%d]\n",
+ element_info[(*elements)[i]].token_name, (*elements)[i]);
#endif
}
{ "artist_header", &tmp_music_file_info.artist_header },
{ "album_header", &tmp_music_file_info.album_header },
{ "year_header", &tmp_music_file_info.year_header },
+ { "played_header", &tmp_music_file_info.played_header },
{ "title", &tmp_music_file_info.title },
{ "artist", &tmp_music_file_info.artist },
{ "album", &tmp_music_file_info.album },
{ "year", &tmp_music_file_info.year },
+ { "played", &tmp_music_file_info.played },
{ NULL, NULL },
};
void LoadMusicInfo(void)
{
- char *music_directory = getCustomMusicDirectory();
+ int num_music_noconf = getMusicListSize_NoConf();
int num_music = getMusicListSize();
- int num_music_noconf = 0;
int num_sounds = getSoundListSize();
- Directory *dir;
- DirectoryEntry *dir_entry;
struct FileInfo *music, *sound;
struct MusicFileInfo *next, **new;
+
int i;
while (music_file_info != NULL)
checked_free(music_file_info->artist_header);
checked_free(music_file_info->album_header);
checked_free(music_file_info->year_header);
+ checked_free(music_file_info->played_header);
checked_free(music_file_info->title);
checked_free(music_file_info->artist);
checked_free(music_file_info->album);
checked_free(music_file_info->year);
+ checked_free(music_file_info->played);
free(music_file_info);
new = &music_file_info;
- for (i = 0; i < num_music; i++)
+ // get (configured or unconfigured) music file info for all levels
+ for (i = leveldir_current->first_level;
+ i <= leveldir_current->last_level; i++)
{
- music = getMusicListEntry(i);
+ int music_nr;
- if (music->filename == NULL)
- continue;
+ if (levelset.music[i] != MUS_UNDEFINED)
+ {
+ // get music file info for configured level music
+ music_nr = levelset.music[i];
+ }
+ else if (num_music_noconf > 0)
+ {
+ // get music file info for unconfigured level music
+ int level_pos = i - leveldir_current->first_level;
- if (strEqual(music->filename, UNDEFINED_FILENAME))
+ music_nr = MAP_NOCONF_MUSIC(level_pos % num_music_noconf);
+ }
+ else
+ {
continue;
+ }
- // a configured file may be not recognized as music
- if (!FileIsMusic(music->filename))
+ char *basename = getMusicInfoEntryFilename(music_nr);
+
+ if (basename == NULL)
continue;
- if (!music_info_listed(music_file_info, music->filename))
+ if (!music_info_listed(music_file_info, basename))
{
- *new = get_music_file_info(music->filename, i);
+ *new = get_music_file_info(basename, music_nr);
if (*new != NULL)
new = &(*new)->next;
}
}
- if ((dir = openDirectory(music_directory)) == NULL)
- {
- Error(ERR_WARN, "cannot read music directory '%s'", music_directory);
- return;
- }
-
- while ((dir_entry = readDirectory(dir)) != NULL) // loop all entries
+ // get music file info for all remaining configured music files
+ for (i = 0; i < num_music; i++)
{
- char *basename = dir_entry->basename;
- boolean music_already_used = FALSE;
- int i;
-
- // skip all music files that are configured in music config file
- for (i = 0; i < num_music; i++)
- {
- music = getMusicListEntry(i);
-
- if (music->filename == NULL)
- continue;
+ music = getMusicListEntry(i);
- if (strEqual(basename, music->filename))
- {
- music_already_used = TRUE;
- break;
- }
- }
+ if (music->filename == NULL)
+ continue;
- if (music_already_used)
+ if (strEqual(music->filename, UNDEFINED_FILENAME))
continue;
- if (!FileIsMusic(dir_entry->filename))
+ // a configured file may be not recognized as music
+ if (!FileIsMusic(music->filename))
continue;
- if (!music_info_listed(music_file_info, basename))
+ if (!music_info_listed(music_file_info, music->filename))
{
- *new = get_music_file_info(basename, MAP_NOCONF_MUSIC(num_music_noconf));
+ *new = get_music_file_info(music->filename, i);
if (*new != NULL)
new = &(*new)->next;
}
-
- num_music_noconf++;
}
- closeDirectory(dir);
-
+ // get sound file info for all configured sound files
for (i = 0; i < num_sounds; i++)
{
sound = getSoundListEntry(i);
new = &(*new)->next;
}
}
+
+ // add pointers to previous list nodes
+
+ struct MusicFileInfo *node = music_file_info;
+
+ while (node != NULL)
+ {
+ if (node->next)
+ node->next->prev = node;
+
+ node = node->next;
+ }
}
static void add_helpanim_entry(int element, int action, int direction,
{
if (token_nr == 0)
{
- Error(ERR_INFO_LINE, "-");
- Error(ERR_INFO, "warning: unknown token(s) found in config file:");
- Error(ERR_INFO, "- config file: '%s'", filename);
+ Warn("---");
+ Warn("unknown token(s) found in config file:");
+ Warn("- config file: '%s'", filename);
}
- Error(ERR_INFO, "- token: '%s'", token);
+ Warn("- token: '%s'", token);
}
static void print_unknown_token_end(int token_nr)
{
if (token_nr > 0)
- Error(ERR_INFO_LINE, "-");
+ Warn("---");
}
void LoadHelpAnimInfo(void)
#if 0
for (i = 0; i < num_list_entries; i++)
- printf("::: '%s': %d, %d, %d => %d\n",
- EL_NAME(helpanim_info[i].element),
- helpanim_info[i].element,
- helpanim_info[i].action,
- helpanim_info[i].direction,
- helpanim_info[i].delay);
+ Debug("files:LoadHelpAnimInfo", "'%s': %d, %d, %d => %d",
+ EL_NAME(helpanim_info[i].element),
+ helpanim_info[i].element,
+ helpanim_info[i].action,
+ helpanim_info[i].direction,
+ helpanim_info[i].delay);
#endif
}
#if 0
BEGIN_HASH_ITERATION(helptext_info, itr)
{
- printf("::: '%s' => '%s'\n",
- HASH_ITERATION_TOKEN(itr), HASH_ITERATION_VALUE(itr));
+ Debug("files:LoadHelpTextInfo", "'%s' => '%s'",
+ HASH_ITERATION_TOKEN(itr), HASH_ITERATION_VALUE(itr));
}
END_HASH_ITERATION(hash, itr)
#endif
global.convert_leveldir);
if (convert_leveldir == NULL)
- Error(ERR_EXIT, "no such level identifier: '%s'",
- global.convert_leveldir);
+ Fail("no such level identifier: '%s'", global.convert_leveldir);
leveldir_current = convert_leveldir;
Print("converting level ... ");
+#if 0
+ // special case: conversion of some EMC levels as requested by ACME
+ level.game_engine_type = GAME_ENGINE_TYPE_RND;
+#endif
+
level_filename = getDefaultLevelFilename(level_nr);
new_level = !fileExists(level_filename);
sprintf(basename1, "%04d.bmp", i);
sprintf(basename2, "%04ds.bmp", i);
- filename1 = getPath2(global.create_images_dir, basename1);
- filename2 = getPath2(global.create_images_dir, basename2);
+ filename1 = getPath2(global.create_sketch_images_dir, basename1);
+ filename2 = getPath2(global.create_sketch_images_dir, basename2);
DrawSizedElement(0, 0, element, TILESIZE);
BlitBitmap(drawto, bitmap1, SX, SY, TILEX, TILEY, 0, 0);
if (SDL_SaveBMP(bitmap1->surface, filename1) != 0)
- Error(ERR_EXIT, "cannot save level sketch image file '%s'", filename1);
+ Fail("cannot save level sketch image file '%s'", filename1);
DrawSizedElement(0, 0, element, MINI_TILESIZE);
BlitBitmap(drawto, bitmap2, SX, SY, MINI_TILEX, MINI_TILEY, 0, 0);
if (SDL_SaveBMP(bitmap2->surface, filename2) != 0)
- Error(ERR_EXIT, "cannot save level sketch image file '%s'", filename2);
+ Fail("cannot save level sketch image file '%s'", filename2);
free(filename1);
free(filename2);
if (options.debug)
fprintf(stderr, "\n");
- Error(ERR_INFO, "%d normal and small images created", NUM_FILE_ELEMENTS);
+ Info("%d normal and small images created", NUM_FILE_ELEMENTS);
+
+ CloseAllAndExit(0);
+}
+
+
+// ----------------------------------------------------------------------------
+// create and save images for element collecting animations (raw BMP format)
+// ----------------------------------------------------------------------------
+
+static boolean createCollectImage(int element)
+{
+ return (IS_COLLECTIBLE(element) && !IS_SP_ELEMENT(element));
+}
+
+void CreateCollectElementImages(void)
+{
+ int i, j;
+ int num_steps = 8;
+ int anim_frames = num_steps - 1;
+ int tile_size = TILESIZE;
+ int anim_width = tile_size * anim_frames;
+ int anim_height = tile_size;
+ int num_collect_images = 0;
+ int pos_collect_images = 0;
+
+ for (i = 0; i < MAX_NUM_ELEMENTS; i++)
+ if (createCollectImage(i))
+ num_collect_images++;
+
+ Info("Creating %d element collecting animation images ...",
+ num_collect_images);
+
+ int dst_width = anim_width * 2;
+ int dst_height = anim_height * num_collect_images / 2;
+ Bitmap *dst_bitmap = CreateBitmap(dst_width, dst_height, DEFAULT_DEPTH);
+ char *basename_bmp = "RocksCollect.bmp";
+ char *basename_png = "RocksCollect.png";
+ char *filename_bmp = getPath2(global.create_collect_images_dir, basename_bmp);
+ char *filename_png = getPath2(global.create_collect_images_dir, basename_png);
+ int len_filename_bmp = strlen(filename_bmp);
+ int len_filename_png = strlen(filename_png);
+ int max_command_len = MAX_FILENAME_LEN + len_filename_bmp + len_filename_png;
+ char cmd_convert[max_command_len];
+
+ snprintf(cmd_convert, max_command_len, "convert \"%s\" \"%s\"",
+ filename_bmp,
+ filename_png);
+
+ // force using RGBA surface for destination bitmap
+ SDL_SetColorKey(dst_bitmap->surface, SET_TRANSPARENT_PIXEL,
+ SDL_MapRGB(dst_bitmap->surface->format, 0x00, 0x00, 0x00));
+
+ dst_bitmap->surface =
+ SDL_ConvertSurfaceFormat(dst_bitmap->surface, SDL_PIXELFORMAT_ARGB8888, 0);
+
+ for (i = 0; i < MAX_NUM_ELEMENTS; i++)
+ {
+ if (!createCollectImage(i))
+ continue;
+
+ int dst_x = (pos_collect_images / (num_collect_images / 2)) * anim_width;
+ int dst_y = (pos_collect_images % (num_collect_images / 2)) * anim_height;
+ int graphic = el2img(i);
+ char *token_name = element_info[i].token_name;
+ Bitmap *tmp_bitmap = CreateBitmap(tile_size, tile_size, DEFAULT_DEPTH);
+ Bitmap *src_bitmap;
+ int src_x, src_y;
+
+ Info("- creating collecting image for '%s' ...", token_name);
+
+ getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
+
+ BlitBitmap(src_bitmap, tmp_bitmap, src_x, src_y,
+ tile_size, tile_size, 0, 0);
+
+ // force using RGBA surface for temporary bitmap (using transparent black)
+ SDL_SetColorKey(tmp_bitmap->surface, SET_TRANSPARENT_PIXEL,
+ SDL_MapRGB(tmp_bitmap->surface->format, 0x00, 0x00, 0x00));
+
+ tmp_bitmap->surface =
+ SDL_ConvertSurfaceFormat(tmp_bitmap->surface, SDL_PIXELFORMAT_ARGB8888, 0);
+
+ tmp_bitmap->surface_masked = tmp_bitmap->surface;
+
+ for (j = 0; j < anim_frames; j++)
+ {
+ int frame_size_final = tile_size * (anim_frames - j) / num_steps;
+ int frame_size = frame_size_final * num_steps;
+ int offset = (tile_size - frame_size_final) / 2;
+ Bitmap *frame_bitmap = ZoomBitmap(tmp_bitmap, frame_size, frame_size);
+
+ while (frame_size > frame_size_final)
+ {
+ frame_size /= 2;
+
+ Bitmap *half_bitmap = ZoomBitmap(frame_bitmap, frame_size, frame_size);
+
+ FreeBitmap(frame_bitmap);
+
+ frame_bitmap = half_bitmap;
+ }
+
+ BlitBitmapMasked(frame_bitmap, dst_bitmap, 0, 0,
+ frame_size_final, frame_size_final,
+ dst_x + j * tile_size + offset, dst_y + offset);
+
+ FreeBitmap(frame_bitmap);
+ }
+
+ tmp_bitmap->surface_masked = NULL;
+
+ FreeBitmap(tmp_bitmap);
+
+ pos_collect_images++;
+ }
+
+ if (SDL_SaveBMP(dst_bitmap->surface, filename_bmp) != 0)
+ Fail("cannot save element collecting image file '%s'", filename_bmp);
+
+ FreeBitmap(dst_bitmap);
+
+ Info("Converting image file from BMP to PNG ...");
+
+ if (system(cmd_convert) != 0)
+ Fail("converting image file failed");
+
+ unlink(filename_bmp);
+
+ Info("Done.");
CloseAllAndExit(0);
}
}
if (SDL_SaveBMP(bitmap->surface, dst_filename) != 0)
- Error(ERR_EXIT, "cannot save CE graphics file '%s'", dst_filename);
+ Fail("cannot save CE graphics file '%s'", dst_filename);
FreeBitmap(bitmap);