diff --git a/data b/data index 229394cd..cbd7b5b4 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 229394cda28955dfa6ec554c58365d11c647f55c +Subproject commit cbd7b5b46a2098b8d88a96370cc8d9aeb05a71f7 diff --git a/src/level/level_category.cpp b/src/level/level_category.cpp index e2eab7df..c9274550 100644 --- a/src/level/level_category.cpp +++ b/src/level/level_category.cpp @@ -30,10 +30,6 @@ const std::map CATEGORY_DIR_MAP = { { LevelCategory::Challenges, "challenges" }, { LevelCategory::CodeBattles, "battles" }, { LevelCategory::CustomLevels, "custom" }, - - { LevelCategory::Win, "win" }, - { LevelCategory::Lost, "lost" }, - { LevelCategory::Perso, "perso" }, }; std::string GetLevelCategoryDir(LevelCategory category) diff --git a/src/level/level_category.h b/src/level/level_category.h index 1db6bccb..4001b674 100644 --- a/src/level/level_category.h +++ b/src/level/level_category.h @@ -30,11 +30,6 @@ enum class LevelCategory CodeBattles, CustomLevels, Max, - - // These are special types not runnable by the user - Win, - Lost, - Perso, }; std::string GetLevelCategoryDir(LevelCategory category); diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index e41a0605..2990ceb4 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -228,8 +228,6 @@ CRobotMain::CRobotMain() m_tooltipName.clear(); m_tooltipTime = 0.0f; - m_endingWinRank = 0; - m_endingLostRank = 0; m_winTerminate = false; m_globalMagnifyDamage = 1.0f; @@ -570,14 +568,14 @@ void CRobotMain::ChangePhase(Phase phase) if (m_phase == PHASE_WIN) { m_sound->StopAll(); - if (m_endingWinRank == -1) + if (m_endingWin.empty()) { ChangePhase(PHASE_LEVEL_LIST); } else { - m_winTerminate = (m_endingWinRank == 904); - SetLevel(LevelCategory::Win, 0, m_endingWinRank); + m_winTerminate = (m_endingWin.substr(m_endingWin.find_last_of("/")+1) == "win904.txt"); + m_levelFile = m_endingWin; try { CreateScene(false, true, false); // sets scene @@ -614,14 +612,14 @@ void CRobotMain::ChangePhase(Phase phase) if (m_phase == PHASE_LOST) { m_sound->StopAll(); - if (m_endingLostRank == -1) + if (m_endingLost.empty()) { ChangePhase(PHASE_LEVEL_LIST); } else { m_winTerminate = false; - SetLevel(LevelCategory::Lost, 0, m_endingLostRank); + m_levelFile = m_endingLost; try { CreateScene(false, true, false); // sets scene @@ -2793,7 +2791,7 @@ void CRobotMain::ScenePerso() m_lightMan->FlushLights(); m_particle->FlushParticle(); - SetLevel(LevelCategory::Perso, 0, 0); + m_levelFile = "levels/other/perso000.txt"; try { CreateScene(false, true, false); // sets scene @@ -2844,8 +2842,8 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_displayText->SetEnable(true); m_immediatSatCom = false; m_lockedSatCom = false; - m_endingWinRank = 0; - m_endingLostRank = 0; + m_endingWin = ""; + m_endingLost = ""; m_audioChange.clear(); m_endTake.clear(); m_endTakeImmediat = false; @@ -2890,7 +2888,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_missionResultFromScript = false; } - //NOTE: Reset timer always, even when only resetting object positions + // NOTE: Reset timer always, even when only resetting object positions m_missionTimerEnabled = false; m_missionTimerStarted = false; m_missionTimer = 0.0f; @@ -2905,7 +2903,9 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) try { m_ui->GetLoadingScreen()->SetProgress(0.05f, RT_LOADING_PROCESSING); - CLevelParser levelParser(m_levelCategory, m_levelChap, m_levelRank); + GetLogger()->Info("Loading level: %s\n", m_levelFile.c_str()); + CLevelParser levelParser(m_levelFile); + levelParser.SetLevelPaths(m_levelCategory, m_levelChap, m_levelRank); levelParser.Load(); int numObjects = levelParser.CountLines("CreateObject"); m_ui->GetLoadingScreen()->SetProgress(0.1f, RT_LOADING_LEVEL_SETTINGS); @@ -2913,11 +2913,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) int rankObj = 0; CObject* sel = nullptr; - /* - * NOTE: Moving frequently used lines to the top - * may speed up loading - */ - for (auto& line : levelParser.GetLines()) { if (line->GetCommand() == "Title" && !resetObject) @@ -2979,9 +2974,36 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (line->GetCommand() == "EndingFile" && !resetObject) { - // NOTE: The old default was 0, but I think -1 is more correct - 0 means "ending file 000", while -1 means "no ending file" - m_endingWinRank = line->GetParam("win")->AsInt(-1); - m_endingLostRank = line->GetParam("lost")->AsInt(-1); + auto Process = [&](const std::string& type) -> std::string + { + if (line->GetParam(type)->IsDefined()) + { + try + { + int rank = boost::lexical_cast(line->GetParam(type)->GetValue()); + if (rank >= 0) + { + GetLogger()->Warn("This level is using deprecated way of defining %1$s scene. Please change the %1$s= parameter in EndingFile from %2$d to \"levels/other/%1$s%2$03d.txt\".\n", type.c_str(), rank); + std::stringstream ss; + ss << "levels/other/" << type << std::setfill('0') << std::setw(3) << rank << ".txt"; + return ss.str(); + } + else + { + GetLogger()->Warn("This level is using deprecated way of defining %1$s scene. Please remove the %1$s= parameter in EndingFile.\n", type.c_str()); + return ""; + } + + } + catch (boost::bad_lexical_cast &e) + { + return line->GetParam(type)->AsPath("levels"); + } + } + return ""; + }; + m_endingWin = Process("win"); + m_endingLost = Process("lost"); continue; } @@ -5288,9 +5310,11 @@ float CRobotMain::GetPersoAngle() void CRobotMain::SetLevel(LevelCategory cat, int chap, int rank) { + GetLogger()->Debug("Change level to %s %d %d\n", GetLevelCategoryDir(cat).c_str(), chap, rank); m_levelCategory = cat; m_levelChap = chap; m_levelRank = rank; + m_levelFile = CLevelParser::BuildScenePath(m_levelCategory, m_levelChap, m_levelRank); } LevelCategory CRobotMain::GetLevelCategory() diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 3247813d..505b5b9a 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -458,6 +458,8 @@ protected: LevelCategory m_levelCategory; int m_levelChap = 0; int m_levelRank = 0; + //! if set, loads this file instead of building from category/chap/rank + std::string m_levelFile = ""; std::string m_sceneReadPath; float m_winDelay = 0.0f; @@ -517,8 +519,8 @@ protected: std::string m_scriptName = ""; std::string m_scriptFile = ""; - int m_endingWinRank = 0; - int m_endingLostRank = 0; + std::string m_endingWin = ""; + std::string m_endingLost = ""; bool m_winTerminate = false; float m_globalMagnifyDamage = 0.0f; diff --git a/src/ui/screen/screen_level_list.cpp b/src/ui/screen/screen_level_list.cpp index ee91369d..38110358 100644 --- a/src/ui/screen/screen_level_list.cpp +++ b/src/ui/screen/screen_level_list.cpp @@ -47,7 +47,6 @@ namespace Ui CScreenLevelList::CScreenLevelList(CMainDialog* mainDialog) : m_dialog(mainDialog), m_category{}, - m_listCategory{}, m_sceneSoluce{false}, m_maxList{0}, m_accessChap{0} @@ -57,15 +56,6 @@ CScreenLevelList::CScreenLevelList(CMainDialog* mainDialog) void CScreenLevelList::SetLevelCategory(LevelCategory category) { m_category = category; - - if ( static_cast(m_category) >= static_cast(LevelCategory::Max) ) - { - m_category = m_listCategory; - } - else - { - m_listCategory = m_category; - } } void CScreenLevelList::CreateInterface() diff --git a/src/ui/screen/screen_level_list.h b/src/ui/screen/screen_level_list.h index 2073e546..b27f88c1 100644 --- a/src/ui/screen/screen_level_list.h +++ b/src/ui/screen/screen_level_list.h @@ -63,7 +63,6 @@ protected: Ui::CMainDialog* m_dialog; LevelCategory m_category; - LevelCategory m_listCategory; bool m_sceneSoluce;