From: Holger Schemel Date: Sat, 3 Jan 2004 02:06:01 +0000 (+0100) Subject: rnd-20040103-1-src X-Git-Tag: 3.1.0^2~106 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=9c285b0e8e4d81c5559815c5f7142685ce865206;p=rocksndiamonds.git rnd-20040103-1-src --- diff --git a/Makefile b/Makefile index 0c0c57f4..e97587db 100644 --- a/Makefile +++ b/Makefile @@ -96,22 +96,22 @@ clean: auto-conf: @$(MAKE_CMD) auto-conf -run: - @$(MAKE_CMD) TARGET=$(DEFAULT_TARGET) && ./rocksndiamonds --verbose +run: all + @./rocksndiamonds --verbose -gdb: - @$(MAKE_CMD) TARGET=$(DEFAULT_TARGET) && gdb ./rocksndiamonds +gdb: all + @gdb ./rocksndiamonds -valgrind: - valgrind -v --leak-check=yes ./rocksndiamonds 2> valgrind.out +valgrind: all + @valgrind -v --leak-check=yes ./rocksndiamonds 2> valgrind.out -enginetest: +enginetest: all ./Scripts/make_enginetest.sh -enginetestcustom: +enginetestcustom: all ./Scripts/make_enginetest.sh custom -enginetestfast: +enginetestfast: all ./Scripts/make_enginetest.sh fast backup: diff --git a/src/conftime.h b/src/conftime.h index a4b8f923..87863205 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2003-12-31 01:13]" +#define COMPILE_DATE_STRING "[2004-01-03 01:58]" diff --git a/src/editor.c b/src/editor.c index c9f86cc3..27eba8b6 100644 --- a/src/editor.c +++ b/src/editor.c @@ -1074,12 +1074,11 @@ static struct ValueTextInfo options_move_pattern[] = { MV_TURNING_RIGHT_LEFT, "turning right, left" }, { MV_TURNING_RANDOM, "turning random" }, { MV_WHEN_PUSHED, "when pushed" }, + { MV_WHEN_DROPPED, "when dropped" }, #if 1 { MV_MAZE_RUNNER, "maze runner style" }, { MV_MAZE_HUNTER, "maze hunter style" }, #endif - { MV_PROJECTILE, "projectile style" }, - { MV_PROJECTILE, "projectile style" }, { -1, NULL } }; @@ -7205,7 +7204,8 @@ static void HandleTextbuttonGadgets(struct GadgetInfo *gi) } else if (type_id == ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE) { - boolean new_template = (!LevelFileExists(-1)); + char *template_filename = getDefaultLevelFilename(-1); + boolean new_template = !fileExists(template_filename); if (new_template || Request("Save this template and kill the old ?", REQ_ASK)) @@ -7293,7 +7293,9 @@ static void HandleCheckbuttons(struct GadgetInfo *gi) } else if (type_id == ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE) { - if (level.use_custom_template && !LevelFileExists(-1)) + char *template_filename = getDefaultLevelFilename(-1); + + if (level.use_custom_template && !fileExists(template_filename)) { Request("No level template found !", REQ_CONFIRM); @@ -7576,7 +7578,8 @@ static void HandleControlButtons(struct GadgetInfo *gi) Request("No Level without Gregor Mc Duffin please !", REQ_CONFIRM); else { - boolean new_level = (!LevelFileExists(level_nr)); + char *level_filename = getDefaultLevelFilename(level_nr); + boolean new_level = !fileExists(level_filename); if (new_level || Request("Save this level and kill the old ?", REQ_ASK)) diff --git a/src/events.c b/src/events.c index f86d9ed3..366acd1a 100644 --- a/src/events.c +++ b/src/events.c @@ -487,23 +487,60 @@ static void HandleKeysCheating(Key key) printf("::: '%s' [%d]\n", cheat_input, cheat_input_len); #endif -#if 1 - if (is_string_suffix(cheat_input, ":insert-solution-tape")) - InsertSolutionTape(); -#else - if (is_string_suffix(cheat_input, ":ist")) - InsertSolutionTape(); -#endif - + if (game_status == GAME_MODE_MAIN) + { + if (is_string_suffix(cheat_input, ":insert-solution-tape") || + is_string_suffix(cheat_input, ":ist")) + { + InsertSolutionTape(); + } + else if (is_string_suffix(cheat_input, ":reload-graphics") || + is_string_suffix(cheat_input, ":rg")) + { + ReloadCustomArtwork(1 << ARTWORK_TYPE_GRAPHICS); + DrawMainMenu(); + } + else if (is_string_suffix(cheat_input, ":reload-sounds") || + is_string_suffix(cheat_input, ":rs")) + { + ReloadCustomArtwork(1 << ARTWORK_TYPE_SOUNDS); + DrawMainMenu(); + } + else if (is_string_suffix(cheat_input, ":reload-music") || + is_string_suffix(cheat_input, ":rm")) + { + ReloadCustomArtwork(1 << ARTWORK_TYPE_MUSIC); + DrawMainMenu(); + } + else if (is_string_suffix(cheat_input, ":reload-artwork") || + is_string_suffix(cheat_input, ":ra")) + { + ReloadCustomArtwork(1 << ARTWORK_TYPE_GRAPHICS | + 1 << ARTWORK_TYPE_SOUNDS | + 1 << ARTWORK_TYPE_MUSIC); + DrawMainMenu(); + } + else if (is_string_suffix(cheat_input, ":dump-level") || + is_string_suffix(cheat_input, ":dl")) + { + DumpLevel(&level); + } + else if (is_string_suffix(cheat_input, ":dump-tape") || + is_string_suffix(cheat_input, ":dt")) + { + DumpTape(&tape); + } + } + else if (game_status == GAME_MODE_PLAYING) + { #ifdef DEBUG - else if (is_string_suffix(cheat_input, ":dump-tape")) - DumpTape(&tape); - else if (is_string_suffix(cheat_input, ".q")) - for (i = 0; i < MAX_INVENTORY_SIZE; i++) - if (local_player->inventory_size < MAX_INVENTORY_SIZE) - local_player->inventory_element[local_player->inventory_size++] = - EL_DYNAMITE; + if (is_string_suffix(cheat_input, ".q")) + for (i = 0; i < MAX_INVENTORY_SIZE; i++) + if (local_player->inventory_size < MAX_INVENTORY_SIZE) + local_player->inventory_element[local_player->inventory_size++] = + EL_DYNAMITE; #endif + } } void HandleKey(Key key, int key_status) @@ -614,16 +651,35 @@ void HandleKey(Key key, int key_status) if (key_status == KEY_RELEASED) return; - if ((key == KSYM_Return || key == setup.shortcut.toggle_pause) && - game_status == GAME_MODE_PLAYING && AllPlayersGone) + if (game_status == GAME_MODE_PLAYING && AllPlayersGone && + (key == KSYM_Return || key == setup.shortcut.toggle_pause)) { CloseDoor(DOOR_CLOSE_1); game_status = GAME_MODE_MAIN; DrawMainMenu(); + + return; + } + + if (game_status == GAME_MODE_MAIN && key == setup.shortcut.toggle_pause) + { + if (setup.autorecord) + TapeStartRecording(); + +#if defined(PLATFORM_UNIX) + if (options.network) + SendToServer_StartPlaying(); + else +#endif + { + game_status = GAME_MODE_PLAYING; + StopAnimation(); + InitGame(); + } + return; } - /* special key shortcuts */ if (game_status == GAME_MODE_MAIN || game_status == GAME_MODE_PLAYING) { if (key == setup.shortcut.save_game) diff --git a/src/files.c b/src/files.c index 811b4200..ae43afc8 100644 --- a/src/files.c +++ b/src/files.c @@ -47,6 +47,17 @@ #define TAPE_COOKIE_TMPL "ROCKSNDIAMONDS_TAPE_FILE_VERSION_x.x" #define SCORE_COOKIE "ROCKSNDIAMONDS_SCORE_FILE_VERSION_1.2" +/* values for level file type identifier */ +#define LEVEL_FILE_TYPE_UNKNOWN 0 +#define LEVEL_FILE_TYPE_RND 1 +#define LEVEL_FILE_TYPE_EM 2 + +#define LEVEL_FILE_TYPE_RND_PACKED (10 + LEVEL_FILE_TYPE_RND) +#define LEVEL_FILE_TYPE_EM_PACKED (10 + LEVEL_FILE_TYPE_EM) + +#define IS_SINGLE_LEVEL_FILE(x) (x < 10) +#define IS_PACKED_LEVEL_FILE(x) (x > 10) + /* ========================================================================= */ /* level file functions */ @@ -268,13 +279,109 @@ static void ActivateLevelTemplate() level data, while all other variables do not change. */ } -boolean LevelFileExists(int level_nr) +static char *getLevelFilenameFromBasename(char *basename) +{ + static char *filename = NULL; + + checked_free(filename); + + filename = getPath2(getCurrentLevelDir(), basename); + + return filename; +} + +static char *getSingleLevelBasename(int nr, int type) +{ + static char basename[MAX_FILENAME_LEN]; + + switch (type) + { + case LEVEL_FILE_TYPE_RND: + if (nr < 0) + sprintf(basename, "template.%s", LEVELFILE_EXTENSION); + else + sprintf(basename, "%03d.%s", nr, LEVELFILE_EXTENSION); + break; + + case LEVEL_FILE_TYPE_EM: + sprintf(basename, "%d", nr); + break; + + default: + strcpy(basename, UNDEFINED_FILENAME); + break; + } + + return basename; +} + +static char *getPackedLevelBasename(int type) +{ + static char basename[MAX_FILENAME_LEN]; + + switch (type) + { + default: + strcpy(basename, UNDEFINED_FILENAME); + break; + } + + return basename; +} + +static char *getSingleLevelFilename(int nr, int type) { - char *filename = getLevelFilename(level_nr); + return getLevelFilenameFromBasename(getSingleLevelBasename(nr, type)); +} - return (access(filename, F_OK) == 0); +static char *getPackedLevelFilename(int type) +{ + return getLevelFilenameFromBasename(getPackedLevelBasename(type)); } +char *getDefaultLevelFilename(int nr) +{ + return getSingleLevelFilename(nr, LEVEL_FILE_TYPE_RND); +} + +static struct LevelFileInfo *getLevelFileInfo(int nr) +{ + static struct LevelFileInfo level_file_info; + + level_file_info.nr = nr; + + /* special case: level template */ + if (nr < 0) + { + level_file_info.type = LEVEL_FILE_TYPE_RND; + level_file_info.filename = getDefaultLevelFilename(nr); + + return &level_file_info; + } + + /* 1st try: check for native Rocks'n'Diamonds level file */ + level_file_info.type = LEVEL_FILE_TYPE_RND; + level_file_info.filename = getSingleLevelFilename(nr, level_file_info.type); + if (fileExists(level_file_info.filename)) + return &level_file_info; + + /* 2nd try: check for classic Emerald Mine level file */ + level_file_info.type = LEVEL_FILE_TYPE_EM; + level_file_info.filename = getSingleLevelFilename(nr, level_file_info.type); + if (fileExists(level_file_info.filename)) + return &level_file_info; + + /* no known level file found -- use default values */ + level_file_info.type = LEVEL_FILE_TYPE_RND; + level_file_info.filename = getSingleLevelFilename(nr, level_file_info.type); + + return &level_file_info; +} + +/* ------------------------------------------------------------------------- */ +/* functions for loading R'n'D level */ +/* ------------------------------------------------------------------------- */ + static int checkLevelElement(int element) { /* map some (historic, now obsolete) elements */ @@ -797,8 +904,10 @@ static int LoadLevel_CUS4(FILE *file, int chunk_size, struct LevelInfo *level) return chunk_size; } -void LoadLevelFromFilename(struct LevelInfo *level, char *filename) +static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, + struct LevelFileInfo *level_file_info) { + char *filename = level_file_info->filename; char cookie[MAX_LINE_LEN]; char chunk_name[CHUNK_ID_LEN + 1]; int chunk_size; @@ -812,7 +921,7 @@ void LoadLevelFromFilename(struct LevelInfo *level, char *filename) level->no_level_file = TRUE; if (level != &level_template) - Error(ERR_WARN, "cannot read level '%s' - creating new level", filename); + Error(ERR_WARN, "cannot read level '%s' - using empty level", filename); return; } @@ -927,6 +1036,338 @@ void LoadLevelFromFilename(struct LevelInfo *level, char *filename) fclose(file); } +/* ------------------------------------------------------------------------- */ +/* functions for loading EM level */ +/* ------------------------------------------------------------------------- */ + +static int map_em_element_yam(int element) +{ + switch (element) + { + case 0x00: return EL_EMPTY; + case 0x01: return EL_EMERALD; + case 0x02: return EL_DIAMOND; + case 0x03: return EL_ROCK; + case 0x04: return EL_ROBOT; + case 0x05: return EL_SPACESHIP_UP; + case 0x06: return EL_BOMB; + case 0x07: return EL_BUG_UP; + case 0x08: return EL_AMOEBA_DROP; + case 0x09: return EL_NUT; + case 0x0a: return EL_YAMYAM; + case 0x0b: return EL_QUICKSAND_FULL; + case 0x0c: return EL_SAND; + case 0x0d: return EL_WALL_SLIPPERY; + case 0x0e: return EL_STEELWALL; + case 0x0f: return EL_WALL; + case 0x10: return EL_EM_KEY_1; + case 0x11: return EL_EM_KEY_2; + case 0x12: return EL_EM_KEY_4; + case 0x13: return EL_EM_KEY_3; + case 0x14: return EL_MAGIC_WALL; + case 0x15: return EL_ROBOT_WHEEL; + case 0x16: return EL_DYNAMITE; + + case 0x17: return EL_EM_KEY_1; /* EMC */ + case 0x18: return EL_BUG_UP; /* EMC */ + case 0x1a: return EL_DIAMOND; /* EMC */ + case 0x1b: return EL_EMERALD; /* EMC */ + case 0x25: return EL_NUT; /* EMC */ + case 0x80: return EL_EMPTY; /* EMC */ + case 0x85: return EL_EM_KEY_1; /* EMC */ + case 0x86: return EL_EM_KEY_2; /* EMC */ + case 0x87: return EL_EM_KEY_4; /* EMC */ + case 0x88: return EL_EM_KEY_3; /* EMC */ + case 0x94: return EL_QUICKSAND_EMPTY; /* EMC */ + case 0x9a: return EL_AMOEBA_WET; /* EMC */ + case 0xaf: return EL_DYNAMITE; /* EMC */ + case 0xbd: return EL_SAND; /* EMC */ + + default: + Error(ERR_WARN, "invalid level element %d", element); + return EL_CHAR_QUESTION; + } +} + +static int map_em_element_field(int element) +{ + if (element >= 0xc8 && element <= 0xe1) + return EL_CHAR_A + (element - 0xc8); + else if (element >= 0xe2 && element <= 0xeb) + return EL_CHAR_0 + (element - 0xe2); + + switch (element) + { + case 0x00: return EL_ROCK; + case 0x02: return EL_DIAMOND; + case 0x03: return EL_DIAMOND; + case 0x04: return EL_ROBOT; + case 0x05: return EL_ROBOT; /* EMC */ + case 0x08: return EL_SPACESHIP_UP; + case 0x09: return EL_SPACESHIP_RIGHT; + case 0x0a: return EL_SPACESHIP_DOWN; + case 0x0b: return EL_SPACESHIP_LEFT; + case 0x0c: return EL_SPACESHIP_UP; + case 0x0d: return EL_SPACESHIP_RIGHT; + case 0x0e: return EL_SPACESHIP_DOWN; + case 0x0f: return EL_SPACESHIP_LEFT; + case 0x10: return EL_BOMB; + case 0x12: return EL_EMERALD; + case 0x13: return EL_EMERALD; + case 0x14: return EL_BUG_UP; + case 0x15: return EL_BUG_RIGHT; + case 0x16: return EL_BUG_DOWN; + case 0x17: return EL_BUG_LEFT; + case 0x18: return EL_BUG_UP; + case 0x19: return EL_BUG_RIGHT; + case 0x1a: return EL_BUG_DOWN; + case 0x1b: return EL_BUG_LEFT; + case 0x1c: return EL_AMOEBA_DROP; + case 0x20: return EL_ROCK; + case 0x24: return EL_MAGIC_WALL; + case 0x25: return EL_NUT; + + /* looks like magic wheel, but is _always_ activated */ + case 0x28: return EL_ROBOT_WHEEL; /* EMC */ + + case 0x29: return EL_YAMYAM; + case 0x2a: return EL_YAMYAM; + case 0x2b: return EL_YAMYAM; /* EMC */ + case 0x2c: return EL_YAMYAM; /* EMC */ + case 0x2d: return EL_QUICKSAND_FULL; + case 0x39: return EL_EXPANDABLE_WALL_HORIZONTAL; /* EMC */ + case 0x3a: return EL_EXPANDABLE_WALL_VERTICAL; /* EMC */ + case 0x3b: return EL_DYNAMITE_ACTIVE; + case 0x3c: return EL_DYNAMITE_ACTIVE; + case 0x3d: return EL_DYNAMITE_ACTIVE; + case 0x3e: return EL_DYNAMITE_ACTIVE; + case 0x3f: return EL_ACID_POOL_BOTTOM; + case 0x40: return EL_EXIT_OPEN; + case 0x41: return EL_EXIT_OPEN; + case 0x42: return EL_EXIT_OPEN; + case 0x43: return EL_BALLOON; + case 0x4e: return EL_INVISIBLE_WALL; + case 0x65: return EL_ACID; /* EMC */ + case 0x73: return EL_SAND; /* EMC */ + case 0x74: return EL_STEELWALL; + case 0x7b: return EL_ACID; + case 0x80: return EL_EMPTY; + case 0x81: return EL_WALL_SLIPPERY; + case 0x82: return EL_SAND; + case 0x83: return EL_STEELWALL; + case 0x84: return EL_WALL; + case 0x85: return EL_EM_KEY_1; + case 0x86: return EL_EM_KEY_2; + case 0x87: return EL_EM_KEY_4; + case 0x88: return EL_EM_KEY_3; + case 0x89: return EL_EM_GATE_1; + case 0x8a: return EL_EM_GATE_2; + case 0x8b: return EL_EM_GATE_4; + case 0x8c: return EL_EM_GATE_3; + case 0x8d: return EL_INVISIBLE_WALL; /* EMC */ + case 0x8e: return EL_EM_GATE_1_GRAY; + case 0x8f: return EL_EM_GATE_2_GRAY; + case 0x90: return EL_EM_GATE_4_GRAY; + case 0x91: return EL_EM_GATE_3_GRAY; + case 0x92: return EL_MAGIC_WALL; + case 0x94: return EL_QUICKSAND_EMPTY; + case 0x95: return EL_ACID_POOL_TOPLEFT; + case 0x96: return EL_ACID_POOL_TOPRIGHT; + case 0x97: return EL_ACID_POOL_BOTTOMLEFT; + case 0x98: return EL_ACID_POOL_BOTTOMRIGHT; + case 0x99: return EL_ACID; + case 0x9a: return EL_AMOEBA_DEAD; + case 0x9b: return EL_AMOEBA_DEAD; + case 0x9c: return EL_AMOEBA_DEAD; + case 0x9d: return EL_AMOEBA_DEAD; + case 0x9e: return EL_EXIT_CLOSED; + case 0x9f: return EL_CHAR_LESS; /* EMC */ + case 0x93: return EL_ROBOT_WHEEL; + + /* looks like normal dust, but behaves like wall */ + case 0xa0: return EL_WALL; /* EMC */ + + case 0xa8: return EL_EMC_WALL_1; /* EMC */ + case 0xa9: return EL_EMC_WALL_2; /* EMC */ + case 0xaa: return EL_EMC_WALL_3; /* EMC */ + case 0xab: return EL_EMC_WALL_7; /* EMC */ + case 0xae: return EL_CHAR_MINUS; /* EMC */ + case 0xaf: return EL_DYNAMITE; + case 0xb0: return EL_EMC_STEELWALL_1; /* EMC */ + case 0xb1: return EL_EMC_WALL_8; /* EMC */ + + /* (exact steel wall) */ + case 0xb3: return EL_STEELWALL; /* EMC */ + + case 0xb4: return EL_WALL_SLIPPERY; /* EMC */ + case 0xb5: return EL_EMC_WALL_6; /* EMC */ + case 0xb6: return EL_EMC_WALL_5; /* EMC */ + case 0xb7: return EL_EMC_WALL_4; /* EMC */ + case 0xb8: return EL_BALLOON_SWITCH_ANY; /* EMC */ + case 0xb9: return EL_BALLOON_SWITCH_RIGHT; /* EMC */ + case 0xba: return EL_BALLOON_SWITCH_DOWN; /* EMC */ + case 0xbb: return EL_BALLOON_SWITCH_LEFT; /* EMC */ + case 0xbc: return EL_BALLOON_SWITCH_UP; /* EMC */ + case 0xbd: return EL_SAND; /* EMC */ + case 0xec: return EL_CHAR_PERIOD; + case 0xed: return EL_CHAR_EXCLAM; + case 0xee: return EL_CHAR_COLON; + case 0xef: return EL_CHAR_QUESTION; + case 0xf0: return EL_CHAR_GREATER; + case 0xf1: return EL_CHAR_COPYRIGHT; + case 0xfe: return EL_PLAYER_1; + case 0xff: return EL_PLAYER_2; + + default: + Error(ERR_WARN, "invalid level element %d", element); + return EL_CHAR_QUESTION; + } +} + +static void LoadLevelFromFileInfo_EM(struct LevelInfo *level, + struct LevelFileInfo *level_file_info) +{ + char *filename = level_file_info->filename; + FILE *file; + unsigned char body[40][64]; + unsigned char *leveldata = &body[0][0]; + unsigned char *header = &leveldata[2048]; + unsigned char code0 = 0x65; + unsigned char code1 = 0x11; + boolean level_is_crypted = FALSE; + int nr = level_file_info->nr; + int jx, jy; + int i, x, y; + + /* always start with reliable default values */ + setLevelInfoToDefaults(level); + + if (!(file = fopen(filename, MODE_READ))) + { + level->no_level_file = TRUE; + + Error(ERR_WARN, "cannot read level '%s' - using empty level", filename); + + return; + } + + for(i = 0; i < 2106; i++) + leveldata[i] = fgetc(file); + + fclose(file); + + /* check if level data is crypted by testing against known starting bytes + of the few existing crypted level files (from Emerald Mine 1 + 2) */ + + if ((leveldata[0] == 0xf1 || + leveldata[0] == 0xf5) && leveldata[2] == 0xe7 && leveldata[3] == 0xee) + { + level_is_crypted = TRUE; + + if (leveldata[0] == 0xf5) /* error in crypted Emerald Mine 2 levels */ + leveldata[0] = 0xf1; + } + + if (level_is_crypted) /* decode crypted level data */ + { + for(i = 0; i < 2106; i++) + { + leveldata[i] ^= code0; + leveldata[i] -= code1; + + code0 = (code0 + 7) & 0xff; + } + } + + level->fieldx = 64; + level->fieldy = 32; + + level->time = header[46] * 10; + level->gems_needed = header[47]; + + /* The original Emerald Mine levels have their level number stored + at the second byte of the level file... + Do not trust this information at other level files, e.g. EMC, + but correct it anyway (normally the first row is completely + steel wall, so the correction does not hurt anyway). */ + + if (leveldata[1] == nr) + leveldata[1] = leveldata[2]; /* correct level number field */ + + sprintf(level->name, "Level %d", nr); + + level->score[SC_EMERALD] = header[36]; + level->score[SC_DIAMOND] = header[37]; + level->score[SC_ROBOT] = header[38]; + level->score[SC_SPACESHIP] = header[39]; + level->score[SC_BUG] = header[40]; + level->score[SC_YAMYAM] = header[41]; + level->score[SC_NUT] = header[42]; + level->score[SC_DYNAMITE] = header[43]; + level->score[SC_TIME_BONUS] = header[44]; + + level->num_yamyam_contents = 4; + + for(i = 0; i < level->num_yamyam_contents; i++) + for(y = 0; y < 3; y++) + for(x = 0; x < 3; x++) + level->yamyam_content[i][x][y] = + map_em_element_yam(header[i * 9 + y * 3 + x]); + + level->amoeba_speed = (header[52] * 256 + header[53]) % 256; + level->time_magic_wall = (header[54] * 256 + header[55]) * 16 / 100; + level->time_wheel = (header[56] * 256 + header[57]) * 16 / 100; + level->amoeba_content = EL_DIAMOND; + + for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++) + { + int new_element = map_em_element_field(body[y][x]); + + if (new_element == EL_AMOEBA_DEAD && level->amoeba_speed) + new_element = EL_AMOEBA_WET; + + level->field[x][y] = new_element; + } + + jx = (header[48] * 256 + header[49]) % 64; + jy = (header[48] * 256 + header[49]) / 64; + level->field[jx][jy] = EL_PLAYER_1; + + jx = (header[50] * 256 + header[51]) % 64; + jy = (header[50] * 256 + header[51]) / 64; + level->field[jx][jy] = EL_PLAYER_2; +} + +void LoadLevelFromFileInfo(struct LevelInfo *level, + struct LevelFileInfo *level_file_info) +{ + switch (level_file_info->type) + { + case LEVEL_FILE_TYPE_RND: + LoadLevelFromFileInfo_RND(level, level_file_info); + break; + + case LEVEL_FILE_TYPE_EM: + LoadLevelFromFileInfo_EM(level, level_file_info); + break; + + default: + LoadLevelFromFileInfo_RND(level, level_file_info); + break; + } +} + +void LoadLevelFromFilename(struct LevelInfo *level, char *filename) +{ + static struct LevelFileInfo level_file_info; + + level_file_info.nr = 0; /* unknown */ + level_file_info.type = LEVEL_FILE_TYPE_RND; /* no others supported yet */ + level_file_info.filename = filename; + + LoadLevelFromFileInfo(level, &level_file_info); +} + static void LoadLevel_InitVersion(struct LevelInfo *level, char *filename) { if (leveldir_current == NULL) /* only when dumping level */ @@ -1156,11 +1597,18 @@ static void LoadLevel_InitPlayfield(struct LevelInfo *level, char *filename) SetBorderElement(); } -void LoadLevelTemplate(int level_nr) +void LoadLevelTemplate(int nr) { - char *filename = getLevelFilename(level_nr); +#if 1 + struct LevelFileInfo *level_file_info = getLevelFileInfo(nr); + char *filename = level_file_info->filename; + + LoadLevelFromFileInfo(&level, level_file_info); +#else + char *filename = getDefaultLevelFilename(nr); - LoadLevelFromFilename(&level_template, filename); + LoadLevelFromFilename_RND(&level_template, filename); +#endif LoadLevel_InitVersion(&level, filename); LoadLevel_InitElements(&level, filename); @@ -1168,11 +1616,18 @@ void LoadLevelTemplate(int level_nr) ActivateLevelTemplate(); } -void LoadLevel(int level_nr) +void LoadLevel(int nr) { - char *filename = getLevelFilename(level_nr); +#if 1 + struct LevelFileInfo *level_file_info = getLevelFileInfo(nr); + char *filename = level_file_info->filename; + + LoadLevelFromFileInfo(&level, level_file_info); +#else + char *filename = getLevelFilename(nr); - LoadLevelFromFilename(&level, filename); + LoadLevelFromFilename_RND(&level, filename); +#endif if (level.use_custom_template) LoadLevelTemplate(-1); @@ -1658,16 +2113,16 @@ static void SaveLevelFromFilename(struct LevelInfo *level, char *filename) SetFilePermissions(filename, PERMS_PRIVATE); } -void SaveLevel(int level_nr) +void SaveLevel(int nr) { - char *filename = getLevelFilename(level_nr); + char *filename = getDefaultLevelFilename(nr); SaveLevelFromFilename(&level, filename); } void SaveLevelTemplate() { - char *filename = getLevelFilename(-1); + char *filename = getDefaultLevelFilename(-1); SaveLevelFromFilename(&level, filename); } @@ -2004,16 +2459,16 @@ void LoadTapeFromFilename(char *filename) #endif } -void LoadTape(int level_nr) +void LoadTape(int nr) { - char *filename = getTapeFilename(level_nr); + char *filename = getTapeFilename(nr); LoadTapeFromFilename(filename); } -void LoadSolutionTape(int level_nr) +void LoadSolutionTape(int nr) { - char *filename = getSolutionTapeFilename(level_nr); + char *filename = getSolutionTapeFilename(nr); LoadTapeFromFilename(filename); } @@ -2073,9 +2528,9 @@ static void SaveTape_BODY(FILE *file, struct TapeInfo *tape) } } -void SaveTape(int level_nr) +void SaveTape(int nr) { - char *filename = getTapeFilename(level_nr); + char *filename = getTapeFilename(nr); FILE *file; boolean new_tape = TRUE; int num_participating_players = 0; @@ -2186,10 +2641,10 @@ void DumpTape(struct TapeInfo *tape) /* score file functions */ /* ========================================================================= */ -void LoadScore(int level_nr) +void LoadScore(int nr) { int i; - char *filename = getScoreFilename(level_nr); + char *filename = getScoreFilename(nr); char cookie[MAX_LINE_LEN]; char line[MAX_LINE_LEN]; char *line_ptr; @@ -2239,17 +2694,17 @@ void LoadScore(int level_nr) fclose(file); } -void SaveScore(int level_nr) +void SaveScore(int nr) { int i; - char *filename = getScoreFilename(level_nr); + char *filename = getScoreFilename(nr); FILE *file; InitScoreDirectory(leveldir_current->filename); if (!(file = fopen(filename, MODE_WRITE))) { - Error(ERR_WARN, "cannot save score for level %d", level_nr); + Error(ERR_WARN, "cannot save score for level %d", nr); return; } diff --git a/src/files.h b/src/files.h index aa9c03e3..fe7be5ca 100644 --- a/src/files.h +++ b/src/files.h @@ -19,7 +19,8 @@ void setElementChangePages(struct ElementInfo *, int); void setElementChangeInfoToDefaults(struct ElementChangeInfo *); -boolean LevelFileExists(int); +char *getDefaultLevelFilename(int); + void LoadLevelFromFilename(struct LevelInfo *, char *); void LoadLevel(int); void LoadLevelTemplate(int); diff --git a/src/game.c b/src/game.c index 7ce333bc..8629abd6 100644 --- a/src/game.c +++ b/src/game.c @@ -1076,6 +1076,7 @@ void InitGame() player->is_collecting = FALSE; player->is_pushing = FALSE; player->is_switching = FALSE; + player->is_dropping = FALSE; player->is_bored = FALSE; player->is_sleeping = FALSE; @@ -3072,6 +3073,10 @@ void Impact(int x, int y) MovDir[x][y + 1] != MV_DOWN || MovPos[x][y + 1] <= TILEY / 2)); +#if 0 + object_hit = !IS_FREE(x, y + 1); +#endif + /* do not smash moving elements that left the smashed field in time */ if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) && ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX) @@ -3845,7 +3850,8 @@ inline static void TurnRoundExt(int x, int y) MovDir[x][y] = old_move_dir; } } - else if (move_pattern == MV_WHEN_PUSHED) + else if (move_pattern == MV_WHEN_PUSHED || + move_pattern == MV_WHEN_DROPPED) { if (!IN_LEV_FIELD_AND_IS_FREE(move_x, move_y)) MovDir[x][y] = MV_NO_MOVING; @@ -4164,6 +4170,11 @@ void StartMoving(int x, int y) element; also, the case of the player being the element to smash was simply not covered here... :-/ ) */ +#if 0 + WasJustMoving[x][y] = 0; + WasJustFalling[x][y] = 0; +#endif + Impact(x, y); } else if (IS_FREE(x, y + 1) && element == EL_SPRING && use_spring_bug) @@ -4294,10 +4305,25 @@ void StartMoving(int x, int y) HAS_ANY_CHANGE_EVENT(element, CE_OTHER_GETS_HIT)); #endif +#if 1 + WasJustMoving[x][y] = 0; +#endif + TestIfElementHitsCustomElement(x, y, MovDir[x][y]); +#if 0 + if (Feld[x][y] != element) /* element has changed */ + { + element = Feld[x][y]; + move_pattern = element_info[element].move_pattern; + + if (!CAN_MOVE(element)) + return; + } +#else if (Feld[x][y] != element) /* element has changed */ return; +#endif } #endif @@ -6142,7 +6168,11 @@ static void ChangeElement(int x, int y, int page) ChangePage[x][y] = -1; } +#if 0 + if (IS_MOVING(x, y) && !change->explode) +#else if (IS_MOVING(x, y)) /* never change a running system ;-) */ +#endif { ChangeDelay[x][y] = 1; /* try change after next move step */ ChangePage[x][y] = page; /* remember page to use for change */ @@ -6503,6 +6533,8 @@ static byte PlayerActions(struct PlayerInfo *player, byte player_action) if (player->MovPos == 0) /* needed for tape.playing */ player->is_moving = FALSE; + player->is_dropping = FALSE; + return 0; } @@ -7409,8 +7441,27 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy) int old_jx = jx, old_jy = jy; int moved = MF_NO_ACTION; +#if 1 + if (!player->active) + return FALSE; + + if (!dx && !dy) + { + if (player->MovPos == 0) + { + player->is_moving = FALSE; + player->is_digging = FALSE; + player->is_collecting = FALSE; + player->is_snapping = FALSE; + player->is_pushing = FALSE; + } + + return FALSE; + } +#else if (!player->active || (!dx && !dy)) return FALSE; +#endif #if 0 if (!FrameReached(&player->move_delay, player->move_delay_value) && @@ -7565,6 +7616,8 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy) player->is_switching = FALSE; #endif + player->is_dropping = FALSE; + #if 1 { @@ -7915,10 +7968,22 @@ void TestIfElementHitsCustomElement(int x, int y, int direction) int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0); int hitx = x + dx, hity = y + dy; int hitting_element = Feld[x][y]; +#if 0 + boolean object_hit = (IN_LEV_FIELD(hitx, hity) && + !IS_FREE(hitx, hity) && + (!IS_MOVING(hitx, hity) || + MovDir[hitx][hity] != direction || + ABS(MovPos[hitx][hity]) <= TILEY / 2)); +#endif if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity)) return; +#if 0 + if (IN_LEV_FIELD(hitx, hity) && !object_hit) + return; +#endif + CheckElementSideChange(x, y, hitting_element, direction, CE_HITTING_SOMETHING, -1); @@ -7936,11 +8001,13 @@ void TestIfElementHitsCustomElement(int x, int y, int direction) int hitting_side = direction; int touched_side = opposite_direction; int touched_element = MovingOrBlocked2Element(hitx, hity); +#if 1 boolean object_hit = (!IS_MOVING(hitx, hity) || MovDir[hitx][hity] != direction || ABS(MovPos[hitx][hity]) <= TILEY / 2); object_hit = TRUE; +#endif if (object_hit) { @@ -8997,6 +9064,8 @@ boolean SnapField(struct PlayerInfo *player, int dx, int dy) player->is_digging = FALSE; player->is_collecting = FALSE; + player->is_dropping = FALSE; + if (DigField(player, x, y, 0, 0, DF_SNAP) == MF_NO_ACTION) return FALSE; @@ -9094,7 +9163,7 @@ boolean DropElement(struct PlayerInfo *player) new_element = Feld[jx][jy]; if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) && - element_info[new_element].move_pattern == MV_PROJECTILE) + element_info[new_element].move_pattern == MV_WHEN_DROPPED) { int move_stepsize = element_info[new_element].move_stepsize; int direction, dx, dy, nextx, nexty; @@ -9138,6 +9207,7 @@ boolean DropElement(struct PlayerInfo *player) #endif + player->is_dropping = TRUE; return TRUE; diff --git a/src/game.h b/src/game.h index 40470ea7..8a402dcc 100644 --- a/src/game.h +++ b/src/game.h @@ -16,22 +16,6 @@ #include "main.h" -/* score for elements (also used by editor.c) */ -#define SC_EMERALD 0 -#define SC_DIAMOND 1 -#define SC_BUG 2 -#define SC_SPACESHIP 3 -#define SC_YAMYAM 4 -#define SC_ROBOT 5 -#define SC_PACMAN 6 -#define SC_NUT 7 -#define SC_DYNAMITE 8 -#define SC_KEY 9 -#define SC_TIME_BONUS 10 -#define SC_CRYSTAL 11 -#define SC_PEARL 12 -#define SC_SHIELD 13 - void GetPlayerConfig(void); void DrawGameDoorValues(void); void InitGameSound(); diff --git a/src/init.c b/src/init.c index 864d0b3b..b8f21640 100644 --- a/src/init.c +++ b/src/init.c @@ -3825,14 +3825,17 @@ static char *getNewArtworkIdentifier(int type) return artwork_new_identifier; } -void ReloadCustomArtwork() +void ReloadCustomArtwork(int force_reload) { char *gfx_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_GRAPHICS); char *snd_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_SOUNDS); char *mus_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_MUSIC); + boolean force_reload_gfx = (force_reload & (1 << ARTWORK_TYPE_GRAPHICS)); + boolean force_reload_snd = (force_reload & (1 << ARTWORK_TYPE_SOUNDS)); + boolean force_reload_mus = (force_reload & (1 << ARTWORK_TYPE_MUSIC)); boolean redraw_screen = FALSE; - if (gfx_new_identifier != NULL) + if (gfx_new_identifier != NULL || force_reload_gfx) { #if 0 printf("RELOADING GRAPHICS '%s' -> '%s' ['%s', '%s']\n", @@ -3857,7 +3860,7 @@ void ReloadCustomArtwork() redraw_screen = TRUE; } - if (snd_new_identifier != NULL) + if (snd_new_identifier != NULL || force_reload_snd) { ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE); @@ -3866,7 +3869,7 @@ void ReloadCustomArtwork() redraw_screen = TRUE; } - if (mus_new_identifier != NULL) + if (mus_new_identifier != NULL || force_reload_mus) { ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE); diff --git a/src/init.h b/src/init.h index 67fc835d..79880f11 100644 --- a/src/init.h +++ b/src/init.h @@ -19,7 +19,7 @@ void InitElementPropertiesStatic(void); void InitElementPropertiesEngine(int); -void ReloadCustomArtwork(void); +void ReloadCustomArtwork(int); void KeyboardAutoRepeatOffUnlessAutoplay(); diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 905c890e..4106c32a 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -154,7 +154,7 @@ static char *getLevelDirFromTreeInfo(TreeInfo *node) return level_dir; } -static char *getCurrentLevelDir() +char *getCurrentLevelDir() { return getLevelDirFromTreeInfo(leveldir_current); } @@ -349,23 +349,6 @@ inline static char *getLevelArtworkDir(int type) return LEVELDIR_ARTWORK_PATH(leveldir_current, type); } -char *getLevelFilename(int nr) -{ - static char *filename = NULL; - char basename[MAX_FILENAME_LEN]; - - checked_free(filename); - - if (nr < 0) - sprintf(basename, "template.%s", LEVELFILE_EXTENSION); - else - sprintf(basename, "%03d.%s", nr, LEVELFILE_EXTENSION); - - filename = getPath2(getCurrentLevelDir(), basename); - - return filename; -} - char *getTapeFilename(int nr) { static char *filename = NULL; diff --git a/src/libgame/setup.h b/src/libgame/setup.h index 1f46cc20..6e0636ea 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -194,7 +194,6 @@ typedef struct hashtable SetupFileHash; char *setLevelArtworkDir(TreeInfo *); -char *getLevelFilename(int); char *getTapeFilename(int); char *getSolutionTapeFilename(int); char *getScoreFilename(int); @@ -234,6 +233,8 @@ void sortTreeInfo(TreeInfo **, char *getUserDataDir(void); char *getCommonDataDir(void); char *getSetupDir(void); +char *getCurrentLevelDir(void); + void createDirectory(char *, char *, int); void InitUserDataDirectory(void); void SetFilePermissions(char *, int); diff --git a/src/main.h b/src/main.h index 83442acf..7edb064d 100644 --- a/src/main.h +++ b/src/main.h @@ -230,7 +230,7 @@ #define MV_BIT_WHEN_PUSHED 10 #define MV_BIT_MAZE_RUNNER 11 #define MV_BIT_MAZE_HUNTER 12 -#define MV_BIT_PROJECTILE 13 +#define MV_BIT_WHEN_DROPPED 13 #define MV_BIT_TURNING_LEFT_RIGHT 14 #define MV_BIT_TURNING_RIGHT_LEFT 15 #define MV_BIT_TURNING_RANDOM 16 @@ -250,7 +250,7 @@ #define MV_MAZE_RUNNER (1 << MV_BIT_MAZE_RUNNER) #define MV_MAZE_HUNTER (1 << MV_BIT_MAZE_HUNTER) #define MV_MAZE_RUNNER_STYLE (MV_MAZE_RUNNER | MV_MAZE_HUNTER) -#define MV_PROJECTILE (1 << MV_BIT_PROJECTILE) +#define MV_WHEN_DROPPED (1 << MV_BIT_WHEN_DROPPED) #define MV_TURNING_LEFT_RIGHT (1 << MV_BIT_TURNING_LEFT_RIGHT) #define MV_TURNING_RIGHT_LEFT (1 << MV_BIT_TURNING_RIGHT_LEFT) #define MV_TURNING_RANDOM (1 << MV_BIT_TURNING_RANDOM) @@ -464,6 +464,23 @@ #define MICROLABEL_YPOS (MICROLEV_YPOS + MICROLEV_YSIZE + 7) +/* score for elements */ +#define SC_EMERALD 0 +#define SC_DIAMOND 1 +#define SC_BUG 2 +#define SC_SPACESHIP 3 +#define SC_YAMYAM 4 +#define SC_ROBOT 5 +#define SC_PACMAN 6 +#define SC_NUT 7 +#define SC_DYNAMITE 8 +#define SC_KEY 9 +#define SC_TIME_BONUS 10 +#define SC_CRYSTAL 11 +#define SC_PEARL 12 +#define SC_SHIELD 13 + + /* "real" level file elements */ #define EL_UNDEFINED -1 @@ -1217,6 +1234,7 @@ struct PlayerInfo boolean is_collecting; boolean is_pushing; boolean is_switching; + boolean is_dropping; boolean is_bored; boolean is_sleeping; @@ -1269,6 +1287,13 @@ struct LevelSetInfo int music[MAX_LEVELS]; }; +struct LevelFileInfo +{ + int nr; + int type; + char *filename; +}; + struct LevelInfo { int file_version; /* file format version the level is stored with */ diff --git a/src/screens.c b/src/screens.c index c4aa62df..50c8685a 100644 --- a/src/screens.c +++ b/src/screens.c @@ -270,7 +270,7 @@ void DrawMainMenu() leveldir_last_valid = leveldir_current; /* needed if last screen (level choice) changed graphics, sounds or music */ - ReloadCustomArtwork(); + ReloadCustomArtwork(0); #ifdef TARGET_SDL SetDrawtoField(DRAW_BACKBUFFER); @@ -1869,7 +1869,7 @@ static void execSetupArtwork() setup.music_set = artwork.mus_current->identifier; /* needed if last screen (setup choice) changed graphics, sounds or music */ - ReloadCustomArtwork(); + ReloadCustomArtwork(0); /* needed for displaying artwork name instead of artwork identifier */ graphics_set_name = artwork.gfx_current->name; diff --git a/src/tools.c b/src/tools.c index 3f7c0735..aa399caa 100644 --- a/src/tools.c +++ b/src/tools.c @@ -633,6 +633,7 @@ void DrawPlayer(struct PlayerInfo *player) player->is_collecting ? ACTION_COLLECTING : player->is_moving ? ACTION_MOVING : player->is_snapping ? ACTION_SNAPPING : + player->is_dropping ? ACTION_DROPPING : player->is_waiting ? player->action_waiting : ACTION_DEFAULT); InitPlayerGfxAnimation(player, action, move_dir);