From 4cdd7ff2d90172d5a29200b66cc0aacaf800240a Mon Sep 17 00:00:00 2001 From: obligaron Date: Sun, 12 Mar 2023 08:18:12 +0100 Subject: [PATCH] Replace ReturnLevel/LevelTyp/LvlPosition --- Source/debug.cpp | 14 ----------- Source/diablo.cpp | 7 ++++-- Source/interfac.cpp | 8 +++++-- Source/levels/trigs.cpp | 2 +- Source/quests.cpp | 52 +++++++++++++++-------------------------- Source/quests.h | 4 ++-- test/drlg_l4_test.cpp | 6 ++--- 7 files changed, 36 insertions(+), 57 deletions(-) diff --git a/Source/debug.cpp b/Source/debug.cpp index 903ddb2c4..4f47c040c 100644 --- a/Source/debug.cpp +++ b/Source/debug.cpp @@ -242,16 +242,6 @@ std::string DebugCmdLoadQuestMap(const string_view parameter) if (level != quest._qslvl) continue; - if (!MyPlayer->isOnLevel(quest._qlevel)) { - StartNewLvl(*MyPlayer, (quest._qlevel != 21) ? interface_mode::WM_DIABNEXTLVL : interface_mode::WM_DIABTOWNWARP, quest._qlevel); - ProcessMessages(); - // Workaround for SDL_PollEvent: - // StartNewLvl pushes a new event with SDL_PushEvent. - // ProcessMessages calls SDL_PollEvent but SDL ignores the new pushed event. - // Calling SDL_PollEvent again fixes this. - ProcessMessages(); - } - setlvltype = quest._qlvltype; StartNewLvl(*MyPlayer, WM_DIABSETLVL, level); @@ -289,10 +279,6 @@ std::string DebugCmdLoadMap(const string_view parameter) if (TestMapPath.empty() || mapType < DTYPE_CATHEDRAL || mapType > DTYPE_LAST || !InDungeonBounds(spawn)) return "Directions not understood"; - ReturnLvlPosition = ViewPosition; - ReturnLevel = currlevel; - ReturnLevelType = leveltype; - setlvltype = static_cast(mapType); ViewPosition = spawn; diff --git a/Source/diablo.cpp b/Source/diablo.cpp index ff4f53080..32e94d39c 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -2759,8 +2759,11 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir) IncProgress(); - if (lvldir == ENTRY_RTNLVL) - GetReturnLvlPos(); + if (lvldir == ENTRY_RTNLVL) { + ViewPosition = GetMapReturnPosition(); + if (Quests[Q_BETRAYER]._qactive == QUEST_DONE) + Quests[Q_BETRAYER]._qvar2 = 2; + } if (lvldir == ENTRY_WARPLVL) GetPortalLvlPos(); diff --git a/Source/interfac.cpp b/Source/interfac.cpp index 43c33d62a..869429813 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -371,7 +371,10 @@ void ShowProgress(interface_mode uMsg) IncProgress(); break; case WM_DIABSETLVL: - SetReturnLvlPos(); + // Note: ReturnLevel, ReturnLevelType and ReturnLvlPosition is only set to ensure vanilla compatibility + ReturnLevel = GetMapReturnLevel(); + ReturnLevelType = GetLevelType(ReturnLevel); + ReturnLvlPosition = GetMapReturnPosition(); IncProgress(); if (!gbIsMultiplayer) { pfile_save_level(); @@ -398,7 +401,8 @@ void ShowProgress(interface_mode uMsg) setlevel = false; FreeGameMem(); IncProgress(); - GetReturnLvlPos(); + currlevel = GetMapReturnLevel(); + leveltype = GetLevelType(currlevel); LoadGameLevel(false, ENTRY_RTNLVL); IncProgress(); break; diff --git a/Source/levels/trigs.cpp b/Source/levels/trigs.cpp index e6ac55ada..222b2d241 100644 --- a/Source/levels/trigs.cpp +++ b/Source/levels/trigs.cpp @@ -881,7 +881,7 @@ void CheckTriggers() StartNewLvl(myPlayer, trigs[i]._tmsg, currlevel - 1); break; case WM_DIABRTNLVL: - StartNewLvl(myPlayer, trigs[i]._tmsg, ReturnLevel); + StartNewLvl(myPlayer, trigs[i]._tmsg, GetMapReturnLevel()); break; case WM_DIABTOWNWARP: if (gbIsMultiplayer) { diff --git a/Source/quests.cpp b/Source/quests.cpp index 716efb704..f09397c26 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -498,50 +498,36 @@ void DRLG_CheckQuests(Point position) } } -void SetReturnLvlPos() +int GetMapReturnLevel() { switch (setlvlnum) { case SL_SKELKING: - ReturnLvlPosition = Quests[Q_SKELKING].position + Direction::SouthEast; - ReturnLevel = Quests[Q_SKELKING]._qlevel; - ReturnLevelType = DTYPE_CATHEDRAL; - break; + return Quests[Q_SKELKING]._qlevel; case SL_BONECHAMB: - ReturnLvlPosition = Quests[Q_SCHAMB].position + Direction::SouthEast; - ReturnLevel = Quests[Q_SCHAMB]._qlevel; - ReturnLevelType = DTYPE_CATACOMBS; - break; - case SL_MAZE: - break; + return Quests[Q_SCHAMB]._qlevel; case SL_POISONWATER: - ReturnLvlPosition = Quests[Q_PWATER].position + Direction::SouthWest; - ReturnLevel = Quests[Q_PWATER]._qlevel; - ReturnLevelType = DTYPE_CATHEDRAL; - break; + return Quests[Q_PWATER]._qlevel; case SL_VILEBETRAYER: - ReturnLvlPosition = Quests[Q_BETRAYER].position + Direction::South; - ReturnLevel = Quests[Q_BETRAYER]._qlevel; - ReturnLevelType = DTYPE_HELL; - break; - case SL_NONE: - break; + return Quests[Q_BETRAYER]._qlevel; default: - if (IsArenaLevel(setlvlnum)) { - ReturnLvlPosition = Towners[TOWN_DRUNK].position + Displacement { 1, 0 }; - ReturnLevel = 0; - ReturnLevelType = DTYPE_TOWN; - } - break; + return 0; } } -void GetReturnLvlPos() +Point GetMapReturnPosition() { - if (Quests[Q_BETRAYER]._qactive == QUEST_DONE) - Quests[Q_BETRAYER]._qvar2 = 2; - ViewPosition = ReturnLvlPosition; - currlevel = ReturnLevel; - leveltype = ReturnLevelType; + switch (setlvlnum) { + case SL_SKELKING: + return Quests[Q_SKELKING].position + Direction::SouthEast; + case SL_BONECHAMB: + return Quests[Q_SCHAMB].position + Direction::SouthEast; + case SL_POISONWATER: + return Quests[Q_PWATER].position + Direction::SouthWest; + case SL_VILEBETRAYER: + return Quests[Q_BETRAYER].position + Direction::South; + default: + return Towners[TOWN_DRUNK].position + Displacement { 1, 0 }; + } } void LoadPWaterPalette() diff --git a/Source/quests.h b/Source/quests.h index b715e7267..e8b2aea98 100644 --- a/Source/quests.h +++ b/Source/quests.h @@ -125,8 +125,8 @@ void CheckQuests(); bool ForceQuests(); void CheckQuestKill(const Monster &monster, bool sendmsg); void DRLG_CheckQuests(Point position); -void SetReturnLvlPos(); -void GetReturnLvlPos(); +int GetMapReturnLevel(); +Point GetMapReturnPosition(); void LoadPWaterPalette(); void UpdatePWaterPalette(); void ResyncMPQuests(); diff --git a/test/drlg_l4_test.cpp b/test/drlg_l4_test.cpp index e82809e10..fe1ad1d61 100644 --- a/test/drlg_l4_test.cpp +++ b/test/drlg_l4_test.cpp @@ -65,7 +65,7 @@ TEST(Drlg_l4, CreateL4Dungeon_diablo_15_1583642716) Quests[Q_BETRAYER]._qactive = QUEST_ACTIVE; TestCreateDungeon(15, 1583642716, ENTRY_MAIN); // Betrayer quest does not change level gen EXPECT_EQ(ViewPosition, Point(44, 26)); - EXPECT_EQ(Quests[Q_BETRAYER].position, Point(34, 24)) << "Ensure the portal to lazarus has a spawn position if the player has activated the quest"; + EXPECT_EQ(Quests[Q_BETRAYER].position, Point(84, 64)) << "Ensure the portal to lazarus has a spawn position if the player has activated the quest"; LoadExpectedLevelData("diablo/15-1583642716-changed.dun"); @@ -74,10 +74,10 @@ TEST(Drlg_l4, CreateL4Dungeon_diablo_15_1583642716) TestCreateDungeon(15, 1583642716, ENTRY_MAIN); EXPECT_EQ(ViewPosition, Point(44, 26)); - EXPECT_EQ(Quests[Q_BETRAYER].position, Point(34, 24)) << "Not really required? current bugfix sets this position anyway"; + EXPECT_EQ(Quests[Q_BETRAYER].position, Point(84, 64)) << "Not really required? current bugfix sets this position anyway"; TestCreateDungeon(15, 1583642716, ENTRY_PREV); EXPECT_EQ(ViewPosition, Point(88, 67)); - EXPECT_EQ(Quests[Q_BETRAYER].position, Point(34, 24)) << "Not really required? current bugfix sets this position anyway"; + EXPECT_EQ(Quests[Q_BETRAYER].position, Point(84, 64)) << "Not really required? current bugfix sets this position anyway"; } TEST(Drlg_l4, CreateL4Dungeon_diablo_15_1256511996)