diff --git a/Descent3/Mission.cpp b/Descent3/Mission.cpp index 16ba9f0fa..d2eeea59a 100644 --- a/Descent3/Mission.cpp +++ b/Descent3/Mission.cpp @@ -751,7 +751,7 @@ void InitDefaultMissionFromCLI() { int mission_arg = FindArg("-mission"); if (mission_arg > 0) { std::filesystem::path filename = std::filesystem::path(GameArgs[mission_arg + 1]).filename().replace_extension(".mn3"); - LoadMission((const char*)filename.u8string().c_str()); + LoadMission(filename); int level_arg = FindArg("-loadlevel"); if (level_arg > 0) { @@ -902,7 +902,7 @@ bool DemoMission(int mode = 0) { } #endif -bool LoadMission(const char *mssn) { +bool LoadMission(const std::filesystem::path& mssn) { Times_game_restored = 0; LOG_INFO << "In LoadMission()"; #if (defined(OEM) || defined(DEMO)) @@ -942,7 +942,7 @@ bool LoadMission(const char *mssn) { // Open MN3 if filename passed was a mn3 file. if (IS_MN3_FILE(mssn)) { mission = mssn; - pathname = std::filesystem::path("missions") / mission; + pathname = "missions" / mission; } else { mission = mssn; pathname = mssn; @@ -1771,7 +1771,7 @@ bool GetMissionInfo(const std::filesystem::path &msnfile, tMissionInfo *msn) { return true; } -const char *GetMissionName(const char *mission) { +const char *GetMissionName(const std::filesystem::path &mission) { tMissionInfo msninfo{}; static char msnname[MSN_NAMELEN]; msnname[0] = 0; @@ -1783,7 +1783,7 @@ const char *GetMissionName(const char *mission) { return msnname; } -bool IsMissionMultiPlayable(const char *mission) { +bool IsMissionMultiPlayable(const std::filesystem::path &mission) { tMissionInfo msninfo{}; if (GetMissionInfo(mission, &msninfo)) { return msninfo.multi; @@ -1875,8 +1875,8 @@ void mn3_Close() { // Return values: // -1 Bad match -- this level and this mod shouldn't be played together! // MAX_NET_PLAYERS -- This is playable with any number of teams the mod wants -int MissionGetKeywords(const char *mission, char *keywords) { - ASSERT(mission); +int MissionGetKeywords(const std::filesystem::path &mission, char *keywords) { + ASSERT(!mission.empty()); ASSERT(keywords); char msn_keywords[NUM_KEYWORDS][KEYWORD_LEN]; @@ -1893,7 +1893,7 @@ int MissionGetKeywords(const char *mission, char *keywords) { memset(msn_keywords, 0, sizeof(msn_keywords)); memset(mod_keywords, 0, sizeof(mod_keywords)); - LOG_DEBUG.printf("MissionGetKeywords(%s,%s)", mission, keywords); + LOG_DEBUG << "MissionGetKeywords(" << mission << ", " << keywords << ")"; if (!GetMissionInfo(mission, &msn_info)) { return -1; } @@ -1956,7 +1956,7 @@ int MissionGetKeywords(const char *mission, char *keywords) { } // We never found one we needed, so return -1; if (!found_keyword) { - LOG_WARNING.printf("%s keyword needed in %s not found!", mod_keyword, mission); + LOG_WARNING << mod_keyword << " keyword needed in " << mission << " not found!"; return -1; } } diff --git a/Descent3/Mission.h b/Descent3/Mission.h index 916d89752..b85908e26 100644 --- a/Descent3/Mission.h +++ b/Descent3/Mission.h @@ -289,7 +289,7 @@ bool mn3_Open(const std::filesystem::path &mn3file); void mn3_Close(); // Get the name field out of the mission file -const char *GetMissionName(const char *mission); +const char *GetMissionName(const std::filesystem::path &mission); // initializes mission system. void InitMission(); @@ -301,7 +301,7 @@ void InitDefaultMissionFromCLI(); void ResetMission(); // loads and verifies a mission as the current mission, returns if valid of not. -bool LoadMission(const char *msn); +bool LoadMission(const std::filesystem::path& mssn); // initializes a level's script. void InitLevelScript(); @@ -328,7 +328,7 @@ bool InitMissionScript(); void ShowProgressScreen(const char *str, const char *str2 = nullptr, bool flip = true); // See if a mission file is multiplayer playable. -bool IsMissionMultiPlayable(const char *mission); +bool IsMissionMultiPlayable(const std::filesystem::path &mission); /** * Fill information about a mission. @@ -343,7 +343,7 @@ bool GetMissionInfo(const std::filesystem::path &msnfile, tMissionInfo *msn); // Return values: // -1 Bad match -- this level and this mod shouldn't be played together! // MAX_NET_PLAYERS -- This is playable with any number of teams the mod wants -int MissionGetKeywords(const char *mission, char *keywords); +int MissionGetKeywords(const std::filesystem::path &mission, char *keywords); #ifdef EDITOR // Used by editor to load all necessary elements for level playing for systems diff --git a/Descent3/dedicated_server.cpp b/Descent3/dedicated_server.cpp index 15e11b8fe..5070c62bd 100644 --- a/Descent3/dedicated_server.cpp +++ b/Descent3/dedicated_server.cpp @@ -152,8 +152,6 @@ static int RunServerConfigs(); static int DedicatedServerLex(const char *command); static void SetCVarNone(int index); -extern int CheckMissionForScript(char *mission, char *script, int dedicated_server_num_teams); - extern char Multi_message_of_the_day[]; extern char PXO_hosted_lobby_name[]; // These define the types of variables that can be set in the code through diff --git a/Descent3/demofile.cpp b/Descent3/demofile.cpp index 46aed3f28..c0fc13fd8 100644 --- a/Descent3/demofile.cpp +++ b/Descent3/demofile.cpp @@ -774,7 +774,7 @@ int DemoReadHeader() { // Now load the mission Osiris_DisableCreateEvents(); IsRestoredGame = true; - if (LoadMission((const char *)demo_mission)) { + if (LoadMission(demo_mission)) { mng_LoadAddonPages(); SetCurrentLevel(level_num); diff --git a/Descent3/gamesave.h b/Descent3/gamesave.h index 98bfa1ef2..ff7c29ac7 100644 --- a/Descent3/gamesave.h +++ b/Descent3/gamesave.h @@ -275,7 +275,7 @@ bool GetGameStateInfo(const std::filesystem::path &pathname, char *description, int LGSXlateTables(CFILE *fp); // loads in level's mission and level. -int LGSMission(const char *msnname, int level); +int LGSMission(const std::filesystem::path &msnname, int level); // initializes rooms int LGSRooms(CFILE *fp); diff --git a/Descent3/loadstate.cpp b/Descent3/loadstate.cpp index 971d2bd02..041a64a07 100644 --- a/Descent3/loadstate.cpp +++ b/Descent3/loadstate.cpp @@ -493,13 +493,13 @@ int LGSXlateTables(CFILE *fp) { } // loads in level's mission and level. -int LGSMission(const char *msnname, int level) { +int LGSMission(const std::filesystem::path &msnname, int level) { // we will free the mission. // Free any game objects/etc that needs to be done when ending a level here. FreeScriptsForLevel(); Osiris_DisableCreateEvents(); - if (LoadMission((const char *)msnname)) { + if (LoadMission(msnname)) { SetCurrentLevel(level); Player_num = 0; // Reset player num Players[Player_num].ship_index = FindShipName(DEFAULT_SHIP); @@ -509,7 +509,7 @@ int LGSMission(const char *msnname, int level) { mng_LoadAddonPages(); InitPlayerNewShip(Player_num, INVRESET_ALL); - InitCameraViews(1); // Turn off all camera views, including rear views + InitCameraViews(true); // Turn off all camera views, including rear views if (!LoadAndStartCurrentLevel()) { Int3(); diff --git a/Descent3/menu.cpp b/Descent3/menu.cpp index 317418a5d..1390ecd7b 100644 --- a/Descent3/menu.cpp +++ b/Descent3/menu.cpp @@ -1107,40 +1107,28 @@ bool MenuNewGame() { int n_missions, res; bool found = false; bool retval = true; + std::filesystem::path mission_name; + #ifdef DEMO - if (LoadMission("d3demo.mn3")) { - CurrentPilotUpdateMissionStatus(true); - // go into game mode. - SetGameMode(GM_NORMAL); - SetFunctionMode(GAME_MODE); - return true; - } else { - DoMessageBox(TXT_ERROR, TXT_ERRLOADMSN, MSGBOX_OK); - return false; - } + mission_name = "d3demo.mn3"; #else if ((!FindArg("-mission")) && (!FirstGame) && (-1 == Current_pilot.find_mission_data(TRAINING_MISSION_NAME))) { FirstGame = true; - - if (LoadMission("training.mn3")) { - CurrentPilotUpdateMissionStatus(true); - // go into game mode. - SetGameMode(GM_NORMAL); - SetFunctionMode(GAME_MODE); - return true; - } else { - DoMessageBox(TXT_ERROR, TXT_ERRLOADMSN, MSGBOX_OK); - return false; - } + mission_name = "training.mn3"; } else if (FirstGame) { + // Already trained FirstGame = false; #ifdef OEM - if (LoadMission(OEM_MISSION_FILE)) + mission_name = OEM_MISSION_FILE; #else - if (LoadMission("d3.mn3")) -#endif - { + mission_name = "d3.mn3"; +#endif // OEM + } +#endif // DEMO + + if (!mission_name.empty()) { + if (LoadMission(mission_name)) { CurrentPilotUpdateMissionStatus(true); // go into game mode. SetGameMode(GM_NORMAL); @@ -1245,7 +1233,7 @@ bool MenuNewGame() { if (index >= 0 && index < filelist.size()) { nameptr = filelist[index]; } - if (nameptr.empty() || !LoadMission((const char*)nameptr.u8string().c_str())) { + if (nameptr.empty() || !LoadMission(nameptr)) { DoMessageBox(TXT_ERROR, TXT_ERRLOADMSN, MSGBOX_OK); retval = false; } else { @@ -1278,7 +1266,6 @@ bool MenuNewGame() { menu.Destroy(); return retval; -#endif } // DisplayLevelWarpDlg diff --git a/Descent3/multi_dll_mgr.cpp b/Descent3/multi_dll_mgr.cpp index 1ec0e14a4..a1e9af67d 100644 --- a/Descent3/multi_dll_mgr.cpp +++ b/Descent3/multi_dll_mgr.cpp @@ -325,7 +325,6 @@ extern uint8_t NewUIWindow_alpha; extern void DoScreenshot(); extern void UpdateAndPackGameList(void); extern bool Multi_Gamelist_changed; -int CheckMissionForScript(char *mission, char *script, int dedicated_server_num_teams); void ShowNetgameInfo(network_game *game); // The exported DLL function call prototypes #if defined(POSIX) diff --git a/Descent3/multi_server.cpp b/Descent3/multi_server.cpp index a2409e8ae..89671e016 100644 --- a/Descent3/multi_server.cpp +++ b/Descent3/multi_server.cpp @@ -821,14 +821,9 @@ void MultiStartServer(int playing, char *scriptname, int dedicated_server_num_te MultiGetShipChecksum(i); } -// Checks if the selected mission and script are compatible -// Return values: -//-1 Not compatible! -//>=0 Number of teams supported for this mod & level - #define SCRIPTBADFORMISSION (-1) -int CheckMissionForScript(char *mission, char *script, int dedicated_server_num_teams) { +int CheckMissionForScript(const std::filesystem::path &mission, char *script, int dedicated_server_num_teams) { char mod_keys[MAX_KEYWORDLEN]; if (!GetDLLRequirements(script, mod_keys, MAX_KEYWORDLEN)) { return SCRIPTBADFORMISSION; diff --git a/Descent3/multi_server.h b/Descent3/multi_server.h index 857f374ba..e13cbc0b1 100644 --- a/Descent3/multi_server.h +++ b/Descent3/multi_server.h @@ -51,6 +51,15 @@ void MultiDoServerFrame(); // Set the local machine as a server void MultiStartServer(int playing, char *scriptname, int dedicated_server_num_teams = -1); +/** + * Checks if the selected mission and script are compatible + * @param mission requested mission + * @param script script name + * @param dedicated_server_num_teams requested number of teams from dedicated server + * @return number of teams supported for this mod & level (>=0) or -1 if mission incompatible + */ +int CheckMissionForScript(const std::filesystem::path &mission, char *script, int dedicated_server_num_teams); + // Disconnects all players that haven't been heard from in a while // Server only void MultiDisconnectDeadPlayers(); diff --git a/netcon/includes/con_dll.h b/netcon/includes/con_dll.h index edf67e576..d9c40e5b7 100644 --- a/netcon/includes/con_dll.h +++ b/netcon/includes/con_dll.h @@ -444,7 +444,7 @@ MultiStartClient_fp DLLMultiStartClient; typedef void (*rend_GetRenderState_fp)(rendering_state *rstate); rend_GetRenderState_fp DLLrend_GetRenderState; -typedef bool (*LoadMission_fp)(char *msn); +typedef bool (*LoadMission_fp)(const std::filesystem::path& msn); LoadMission_fp DLLLoadMission; typedef void (*ddio_MakePath_fp)(char *newPath, const char *absolutePathHeader, const char *subDir, ...); @@ -476,7 +476,7 @@ HotSpotCreate_fp DLLHotSpotCreate; typedef int (*PollUI_fp)(void); PollUI_fp DLLPollUI; -typedef const char *(*GetMissionName_fp)(const char *mission); +typedef const char *(*GetMissionName_fp)(const std::filesystem::path &mission); GetMissionName_fp DLLGetMissionName; typedef void (*RemoveUITextItem_fp)(void *item); @@ -597,7 +597,7 @@ DatabaseWriteInt_fp DLLDatabaseWriteInt; typedef void (*DoScreenshot_fp)(); DoScreenshot_fp DLLDoScreenshot; -typedef bool (*IsMissionMultiPlayable_fp)(const char *mission); +typedef bool (*IsMissionMultiPlayable_fp)(const std::filesystem::path &mission); IsMissionMultiPlayable_fp DLLIsMissionMultiPlayable; // returns width of text in current font. @@ -690,7 +690,7 @@ MultiLevelSelection_fp DLLMultiLevelSelection; typedef bool (*DoPlayerMouselookCheck_fp)(uint32_t flags); DoPlayerMouselookCheck_fp DLLDoPlayerMouselookCheck; -typedef int (*CheckMissionForScript_fp)(char *mission, char *script, int dedicated_server_num_teams); +typedef int (*CheckMissionForScript_fp)(const std::filesystem::path &mission, char *script, int dedicated_server_num_teams); CheckMissionForScript_fp DLLCheckMissionForScript; typedef void (*ShowNetgameInfo_fp)(network_game *game); @@ -1209,11 +1209,11 @@ int StartMultiplayerGameMenu() { for (auto const &i : search_paths) { DLLddio_DoForeachFile(i.first, i.second, [&mi, &list_1](const std::filesystem::path &path) { std::filesystem::path mission_name = path.filename(); - if (DLLIsMissionMultiPlayable((const char*)mission_name.u8string().c_str()) && + if (DLLIsMissionMultiPlayable(mission_name) && (stricmp("d3_2.mn3", (const char*)mission_name.u8string().c_str()) != 0)) { DLLmprintf(0, "Found a mission: %s\n", (const char*)mission_name.u8string().c_str()); mi = (msn_list *)DLLmem_malloc(sizeof(msn_list)); - strcpy(mi->msn_name, DLLGetMissionName((const char*)mission_name.u8string().c_str())); + strcpy(mi->msn_name, DLLGetMissionName(mission_name)); strcpy(mi->msn_file, (const char*)mission_name.u8string().c_str()); mi->ti = DLLCreateNewUITextItem(mi->msn_name, UICOL_LISTBOX_LO, -1); AddMsnItem(mi);