Skip to content

Commit 7eb9b88

Browse files
committed
Simplify code in MenuNewGame()
1 parent 10cc653 commit 7eb9b88

File tree

3 files changed

+20
-43
lines changed

3 files changed

+20
-43
lines changed

Descent3/Mission.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ bool DemoMission(int mode = 0) {
879879
}
880880
#endif
881881

882-
bool LoadMission(const char *mssn) {
882+
bool LoadMission(const std::filesystem::path& mssn) {
883883
Times_game_restored = 0;
884884
LOG_INFO << "In LoadMission()";
885885
#if (defined(OEM) || defined(DEMO))
@@ -919,7 +919,7 @@ bool LoadMission(const char *mssn) {
919919
// Open MN3 if filename passed was a mn3 file.
920920
if (IS_MN3_FILE(mssn)) {
921921
mission = mssn;
922-
pathname = std::filesystem::path("missions") / mission;
922+
pathname = "missions" / mission;
923923
} else {
924924
mission = mssn;
925925
pathname = mssn;

Descent3/Mission.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ void InitMission();
298298
void ResetMission();
299299

300300
// loads and verifies a mission as the current mission, returns if valid of not.
301-
bool LoadMission(const char *msn);
301+
bool LoadMission(const std::filesystem::path& mssn);
302302

303303
// initializes a level's script.
304304
void InitLevelScript();

Descent3/menu.cpp

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,53 +1107,31 @@ bool MenuNewGame() {
11071107
int n_missions, res;
11081108
bool found = false;
11091109
bool retval = true;
1110+
std::filesystem::path mission_name;
1111+
11101112
#ifdef DEMO
1111-
if (LoadMission("d3demo.mn3")) {
1112-
CurrentPilotUpdateMissionStatus(true);
1113-
// go into game mode.
1114-
SetGameMode(GM_NORMAL);
1115-
SetFunctionMode(GAME_MODE);
1116-
return true;
1117-
} else {
1118-
DoMessageBox(TXT_ERROR, TXT_ERRLOADMSN, MSGBOX_OK);
1119-
return false;
1120-
}
1113+
mission_name = "d3demo.mn3";
11211114
#else
11221115
if (int mission_arg = FindArg("-mission")) {
1123-
std::filesystem::path filename = std::filesystem::path(GameArgs[mission_arg + 1]).filename().replace_extension(".mn3");
1124-
if (LoadMission(filename.u8string().c_str())) {
1125-
CurrentPilotUpdateMissionStatus(true);
1126-
// go into game mode.
1127-
SetGameMode(GM_NORMAL);
1128-
SetFunctionMode(GAME_MODE);
1129-
return true;
1130-
} else {
1131-
DoMessageBox(TXT_ERROR, TXT_ERRLOADMSN, MSGBOX_OK);
1132-
return false;
1133-
}
1134-
}
1135-
if ((!FirstGame) && (-1 == Current_pilot.find_mission_data(TRAINING_MISSION_NAME))) {
1136-
1116+
// If direct loading via cmdline option
1117+
mission_name = std::filesystem::path(GameArgs[mission_arg + 1]).filename().replace_extension(".mn3");
1118+
} else if ((!FirstGame) && (-1 == Current_pilot.find_mission_data(TRAINING_MISSION_NAME))) {
1119+
// First time?
11371120
FirstGame = true;
1138-
1139-
if (LoadMission("training.mn3")) {
1140-
CurrentPilotUpdateMissionStatus(true);
1141-
// go into game mode.
1142-
SetGameMode(GM_NORMAL);
1143-
SetFunctionMode(GAME_MODE);
1144-
return true;
1145-
} else {
1146-
DoMessageBox(TXT_ERROR, TXT_ERRLOADMSN, MSGBOX_OK);
1147-
return false;
1148-
}
1121+
mission_name = "training.mn3";
11491122
} else if (FirstGame) {
1123+
// Already trained
11501124
FirstGame = false;
11511125
#ifdef OEM
1152-
if (LoadMission(OEM_MISSION_FILE))
1126+
mission_name = OEM_MISSION_FILE;
11531127
#else
1154-
if (LoadMission("d3.mn3"))
1155-
#endif
1156-
{
1128+
mission_name = "d3.mn3";
1129+
#endif // OEM
1130+
}
1131+
#endif // DEMO
1132+
1133+
if (!mission_name.empty()) {
1134+
if (LoadMission(mission_name)) {
11571135
CurrentPilotUpdateMissionStatus(true);
11581136
// go into game mode.
11591137
SetGameMode(GM_NORMAL);
@@ -1291,7 +1269,6 @@ bool MenuNewGame() {
12911269
menu.Destroy();
12921270

12931271
return retval;
1294-
#endif // DEMO
12951272
}
12961273

12971274
// DisplayLevelWarpDlg

0 commit comments

Comments
 (0)