diff --git a/common/main/mission.h b/common/main/mission.h index 6c8d09425..2d29685e3 100644 --- a/common/main/mission.h +++ b/common/main/mission.h @@ -212,8 +212,6 @@ extern Mission_ptr Current_mission; // current mission #endif //values for d1 built-in mission -#define BIMD1_LAST_LEVEL 27 -#define BIMD1_LAST_SECRET_LEVEL -3 #define BIMD1_ENDING_FILE_OEM "endsat.txb" #define BIMD1_ENDING_FILE_SHARE "ending.txb" diff --git a/similar/main/mission.cpp b/similar/main/mission.cpp index bf7b3d0d4..01a9e179a 100644 --- a/similar/main/mission.cpp +++ b/similar/main/mission.cpp @@ -251,17 +251,19 @@ static bool null_or_space(char c) } // Allocate the Level_names, Secret_level_names and Secret_level_table arrays -static int allocate_levels(void) +static void allocate_levels(const unsigned count_regular_level, const unsigned count_secret_level) { - Level_names = std::make_unique(Last_level); - if (Last_secret_level) + Level_names = std::make_unique(count_regular_level); + Last_level = count_regular_level; + N_secret_levels = count_secret_level; + Last_secret_level = -static_cast(count_secret_level); + if (count_secret_level) { - N_secret_levels = -Last_secret_level; - Secret_level_names = std::make_unique(N_secret_levels); - Secret_level_table = std::make_unique(N_secret_levels); + auto secret_level_names = std::make_unique(count_secret_level); + auto secret_level_table = std::make_unique(count_secret_level); + Secret_level_names = std::move(secret_level_names); + Secret_level_table = std::move(secret_level_table); } - - return 1; } // @@ -274,17 +276,7 @@ static const char *load_mission_d1() { case D1_SHAREWARE_MISSION_HOGSIZE: case D1_SHAREWARE_10_MISSION_HOGSIZE: - N_secret_levels = 0; - - Last_level = 7; - Last_secret_level = 0; - - if (!allocate_levels()) - { - Current_mission.reset(); - return "Failed to allocate level memory for Descent 1 shareware"; - } - + allocate_levels(7, 0); //build level names for (int i=0;ibuiltin_hogsize) { case MAC_SHARE_MISSION_HOGSIZE: - N_secret_levels = 1; - - Last_level = 4; - Last_secret_level = -1; - - if (!allocate_levels()) - { - Current_mission.reset(); - return "Failed to allocate level memory for Descent 2 Mac shareware"; - } - + allocate_levels(4, 1); // mac demo is using the regular hog and rl2 files Level_names[0] = "d2leva-1.rl2"; Level_names[1] = "d2leva-2.rl2"; @@ -424,19 +377,11 @@ static const char *load_mission_shareware() Int3(); DXX_BOOST_FALLTHROUGH; case SHAREWARE_MISSION_HOGSIZE: - N_secret_levels = 0; - - Last_level = 3; - Last_secret_level = 0; - - if (!allocate_levels()) - { - Current_mission.reset(); - return "Failed to allocate level memory for Descent 2 shareware"; - } + allocate_levels(3, 0); Level_names[0] = "d2leva-1.sl2"; Level_names[1] = "d2leva-2.sl2"; Level_names[2] = "d2leva-3.sl2"; + break; } return nullptr; } @@ -452,16 +397,7 @@ static const char *load_mission_oem() Current_mission->descent_version = Mission::descent_version_type::descent2; Current_mission->anarchy_only_flag = 0; - N_secret_levels = 2; - - Last_level = 8; - Last_secret_level = -2; - - if (!allocate_levels()) - { - Current_mission.reset(); - return "Failed to allocate level memory for Descent 2 OEM"; - } + allocate_levels(8, 2); Level_names[0] = "d2leva-1.rl2"; Level_names[1] = "d2leva-2.rl2"; Level_names[2] = "d2leva-3.rl2";