diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index e8aa73b4..fec56625 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -945,13 +945,13 @@ void LoadQuestSetPieces() { L5setloadflag = false; - if (QuestStatus(Q_BUTCHER)) { + if (Quests[Q_BUTCHER].IsAvailable()) { L5pSetPiece = LoadFileInMem("Levels\\L1Data\\rnd6.DUN"); L5setloadflag = true; - } else if (QuestStatus(Q_SKELKING) && !gbIsMultiplayer) { + } else if (Quests[Q_SKELKING].IsAvailable() && !gbIsMultiplayer) { L5pSetPiece = LoadFileInMem("Levels\\L1Data\\SKngDO.DUN"); L5setloadflag = true; - } else if (QuestStatus(Q_LTBANNER)) { + } else if (Quests[Q_LTBANNER].IsAvailable()) { L5pSetPiece = LoadFileInMem("Levels\\L1Data\\Banner2.DUN"); L5setloadflag = true; } @@ -2202,7 +2202,7 @@ void GenerateLevel(lvl_entry entry) doneflag = true; - if (QuestStatus(Q_PWATER)) { + if (Quests[Q_PWATER].IsAvailable()) { if (entry == ENTRY_MAIN) { if (PlaceMiniSet(PWATERIN, 1, 1, 0, 0, true, -1) < 0) doneflag = false; @@ -2212,7 +2212,7 @@ void GenerateLevel(lvl_entry entry) ViewY--; } } - if (QuestStatus(Q_LTBANNER)) { + if (Quests[Q_LTBANNER].IsAvailable()) { if (entry == ENTRY_MAIN) { if (PlaceMiniSet(STAIRSUP, 1, 1, 0, 0, true, -1) < 0) doneflag = false; diff --git a/Source/drlg_l2.cpp b/Source/drlg_l2.cpp index 276609c4..49170921 100644 --- a/Source/drlg_l2.cpp +++ b/Source/drlg_l2.cpp @@ -1775,15 +1775,15 @@ void LoadQuestSetPieces() { setloadflag = false; - if (QuestStatus(Q_BLIND)) { + if (Quests[Q_BLIND].IsAvailable()) { pSetPiece = LoadFileInMem("Levels\\L2Data\\Blind1.DUN"); pSetPiece[13] = SDL_SwapLE16(154); // Close outer wall pSetPiece[100] = SDL_SwapLE16(154); // Close outer wall setloadflag = true; - } else if (QuestStatus(Q_BLOOD)) { + } else if (Quests[Q_BLOOD].IsAvailable()) { pSetPiece = LoadFileInMem("Levels\\L2Data\\Blood1.DUN"); setloadflag = true; - } else if (QuestStatus(Q_SCHAMB)) { + } else if (Quests[Q_SCHAMB].IsAvailable()) { pSetPiece = LoadFileInMem("Levels\\L2Data\\Bonestr2.DUN"); setloadflag = true; } diff --git a/Source/drlg_l3.cpp b/Source/drlg_l3.cpp index 6046fdb0..bf39b23d 100644 --- a/Source/drlg_l3.cpp +++ b/Source/drlg_l3.cpp @@ -2239,7 +2239,7 @@ void GenerateLevel(lvl_entry entry) CreateBlock(x2, y1, 2, 1); CreateBlock(x1, y2, 2, 2); CreateBlock(x1, y1, 2, 3); - if (QuestStatus(Q_ANVIL)) { + if (Quests[Q_ANVIL].IsAvailable()) { x1 = GenerateRnd(10) + 10; y1 = GenerateRnd(10) + 10; x2 = x1 + 12; @@ -2324,7 +2324,7 @@ void GenerateLevel(lvl_entry entry) } } } - if (!genok && QuestStatus(Q_ANVIL)) { + if (!genok && Quests[Q_ANVIL].IsAvailable()) { genok = Anvil(); } } while (genok); @@ -2372,7 +2372,7 @@ void GenerateLevel(lvl_entry entry) if (currlevel < 17) River(); - if (QuestStatus(Q_ANVIL)) { + if (Quests[Q_ANVIL].IsAvailable()) { dungeon[setpc_x + 7][setpc_y + 5] = 7; dungeon[setpc_x + 8][setpc_y + 5] = 7; dungeon[setpc_x + 9][setpc_y + 5] = 7; diff --git a/Source/drlg_l4.cpp b/Source/drlg_l4.cpp index a7471fe3..c0e5688d 100644 --- a/Source/drlg_l4.cpp +++ b/Source/drlg_l4.cpp @@ -254,7 +254,7 @@ bool PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool void LoadQuestSetPieces() { setloadflag = false; - if (QuestStatus(Q_WARLORD)) { + if (Quests[Q_WARLORD].IsAvailable()) { pSetPiece = LoadFileInMem("Levels\\L4Data\\Warlord.DUN"); setloadflag = true; } @@ -419,7 +419,7 @@ void FirstRoom() l4holdx = x; l4holdy = y; } - if (QuestStatus(Q_WARLORD) || (currlevel == Quests[Q_BETRAYER]._qlevel && gbIsMultiplayer)) { + if (Quests[Q_WARLORD].IsAvailable() || (currlevel == Quests[Q_BETRAYER]._qlevel && gbIsMultiplayer)) { SP4x1 = x + 1; SP4y1 = y + 1; SP4x2 = SP4x1 + w; @@ -1325,7 +1325,7 @@ void GenerateLevel(lvl_entry entry) if (currlevel == 16) { SaveQuads(); } - if (QuestStatus(Q_WARLORD) || (currlevel == Quests[Q_BETRAYER]._qlevel && gbIsMultiplayer)) { + if (Quests[Q_WARLORD].IsAvailable() || (currlevel == Quests[Q_BETRAYER]._qlevel && gbIsMultiplayer)) { for (int spi = SP4x1; spi < SP4x2; spi++) { for (int spj = SP4y1; spj < SP4y2; spj++) { dflags[spi][spj] = 1; @@ -1341,7 +1341,7 @@ void GenerateLevel(lvl_entry entry) if (currlevel == 16) { LoadDiabQuads(true); } - if (QuestStatus(Q_WARLORD)) { + if (Quests[Q_WARLORD].IsAvailable()) { if (entry == ENTRY_MAIN) { doneflag = PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true); if (doneflag && currlevel == 13) { @@ -1427,7 +1427,7 @@ void GenerateLevel(lvl_entry entry) Substitution(); DRLG_Init_Globals(); - if (QuestStatus(Q_WARLORD)) { + if (Quests[Q_WARLORD].IsAvailable()) { for (int j = 0; j < DMAXY; j++) { for (int i = 0; i < DMAXX; i++) { pdungeon[i][j] = dungeon[i][j]; diff --git a/Source/items.cpp b/Source/items.cpp index fda4c6f5..74cd5ec1 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -2593,9 +2593,9 @@ void InitItems() if (!setlevel) { AdvanceRndSeed(); /* unused */ - if (QuestStatus(Q_ROCK)) + if (Quests[Q_ROCK].IsAvailable()) SpawnRock(); - if (QuestStatus(Q_ANVIL)) + if (Quests[Q_ANVIL].IsAvailable()) SpawnQuestItem(IDI_ANVIL, { 2 * setpc_x + 27, 2 * setpc_y + 27 }, 0, 1); if (sgGameInitInfo.bCowQuest != 0 && currlevel == 20) SpawnQuestItem(IDI_BROWNSUIT, { 25, 25 }, 3, 1); diff --git a/Source/monster.cpp b/Source/monster.cpp index fa3625f3..8209d8b4 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -690,7 +690,7 @@ void PlaceQuestMonsters() int skeltype; if (!setlevel) { - if (QuestStatus(Q_BUTCHER)) { + if (Quests[Q_BUTCHER].IsAvailable()) { PlaceUniqueMonst(UMT_BUTCHER, 0, 0); } @@ -706,31 +706,31 @@ void PlaceQuestMonsters() PlaceUniqueMonst(UMT_SKELKING, skeltype, 30); } - if (QuestStatus(Q_LTBANNER)) { + if (Quests[Q_LTBANNER].IsAvailable()) { auto dunData = LoadFileInMem("Levels\\L1Data\\Banner1.DUN"); SetMapMonsters(dunData.get(), Point { setpc_x, setpc_y } * 2); } - if (QuestStatus(Q_BLOOD)) { + if (Quests[Q_BLOOD].IsAvailable()) { auto dunData = LoadFileInMem("Levels\\L2Data\\Blood2.DUN"); SetMapMonsters(dunData.get(), Point { setpc_x, setpc_y } * 2); } - if (QuestStatus(Q_BLIND)) { + if (Quests[Q_BLIND].IsAvailable()) { auto dunData = LoadFileInMem("Levels\\L2Data\\Blind2.DUN"); SetMapMonsters(dunData.get(), Point { setpc_x, setpc_y } * 2); } - if (QuestStatus(Q_ANVIL)) { + if (Quests[Q_ANVIL].IsAvailable()) { auto dunData = LoadFileInMem("Levels\\L3Data\\Anvil.DUN"); SetMapMonsters(dunData.get(), Point { setpc_x + 2, setpc_y + 2 } * 2); } - if (QuestStatus(Q_WARLORD)) { + if (Quests[Q_WARLORD].IsAvailable()) { auto dunData = LoadFileInMem("Levels\\L4Data\\Warlord.DUN"); SetMapMonsters(dunData.get(), Point { setpc_x, setpc_y } * 2); AddMonsterType(UniqMonst[UMT_WARLORD].mtype, PLACE_SCATTER); } - if (QuestStatus(Q_VEIL)) { + if (Quests[Q_VEIL].IsAvailable()) { AddMonsterType(UniqMonst[UMT_LACHDAN].mtype, PLACE_SCATTER); } - if (QuestStatus(Q_ZHAR) && zharlib == -1) { + if (Quests[Q_ZHAR].IsAvailable() && zharlib == -1) { Quests[Q_ZHAR]._qactive = QUEST_NOTAVAIL; } @@ -1094,7 +1094,7 @@ void DiabloDeath(MonsterStruct &diablo, bool sendmsg) void SpawnLoot(MonsterStruct &monster, bool sendmsg) { - if (QuestStatus(Q_GARBUD) && monster._uniqtype - 1 == UMT_GARBUD) { + if (Quests[Q_GARBUD].IsAvailable() && monster._uniqtype - 1 == UMT_GARBUD) { CreateTypeItem(monster.position.tile + Displacement { 1, 1 }, true, ITYPE_MACE, IMISC_NONE, true, false); } else if (monster._uniqtype - 1 == UMT_DEFILER) { if (effect_is_playing(USFX_DEFILER8)) @@ -3642,17 +3642,17 @@ void GetLevelMTypes() } if (!setlevel) { - if (QuestStatus(Q_BUTCHER)) + if (Quests[Q_BUTCHER].IsAvailable()) AddMonsterType(MT_CLEAVER, PLACE_SPECIAL); - if (QuestStatus(Q_GARBUD)) + if (Quests[Q_GARBUD].IsAvailable()) AddMonsterType(UniqMonst[UMT_GARBUD].mtype, PLACE_UNIQUE); - if (QuestStatus(Q_ZHAR)) + if (Quests[Q_ZHAR].IsAvailable()) AddMonsterType(UniqMonst[UMT_ZHAR].mtype, PLACE_UNIQUE); - if (QuestStatus(Q_LTBANNER)) + if (Quests[Q_LTBANNER].IsAvailable()) AddMonsterType(UniqMonst[UMT_SNOTSPIL].mtype, PLACE_UNIQUE); - if (QuestStatus(Q_VEIL)) + if (Quests[Q_VEIL].IsAvailable()) AddMonsterType(UniqMonst[UMT_LACHDAN].mtype, PLACE_UNIQUE); - if (QuestStatus(Q_WARLORD)) + if (Quests[Q_WARLORD].IsAvailable()) AddMonsterType(UniqMonst[UMT_WARLORD].mtype, PLACE_UNIQUE); if (gbIsMultiplayer && currlevel == Quests[Q_SKELKING]._qlevel) { @@ -4956,14 +4956,14 @@ void TalktoMonster(MonsterStruct &monster) return; } - if (QuestStatus(Q_LTBANNER) && Quests[Q_LTBANNER]._qvar1 == 2) { + if (Quests[Q_LTBANNER].IsAvailable() && Quests[Q_LTBANNER]._qvar1 == 2) { if (player.TryRemoveInvItemById(IDI_BANNER)) { Quests[Q_LTBANNER]._qactive = QUEST_DONE; monster.mtalkmsg = TEXT_BANNER12; monster._mgoal = MGOAL_INQUIRING; } } - if (QuestStatus(Q_VEIL) && monster.mtalkmsg >= TEXT_VEIL9) { + if (Quests[Q_VEIL].IsAvailable() && monster.mtalkmsg >= TEXT_VEIL9) { if (player.TryRemoveInvItemById(IDI_GLDNELIX)) { monster.mtalkmsg = TEXT_VEIL11; monster._mgoal = MGOAL_INQUIRING; diff --git a/Source/objects.cpp b/Source/objects.cpp index f2c3e571..43fcb818 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -462,11 +462,11 @@ void AddBookLever(Rectangle affectedArea, _speech_id msg) } } - if (QuestStatus(Q_BLIND)) + if (Quests[Q_BLIND].IsAvailable()) AddObject(OBJ_BLINDBOOK, { xp, yp }); - if (QuestStatus(Q_WARLORD)) + if (Quests[Q_WARLORD].IsAvailable()) AddObject(OBJ_STEELTOME, { xp, yp }); - if (QuestStatus(Q_BLOOD)) { + if (Quests[Q_BLOOD].IsAvailable()) { xp = 2 * setpc_x + 25; yp = 2 * setpc_y + 40; AddObject(OBJ_BLOODBOOK, { xp, yp }); @@ -3791,7 +3791,7 @@ void OperateBookCase(int pnum, int i, bool sendmsg) SetRndSeed(Objects[i]._oRndSeed); CreateTypeItem(Objects[i].position, false, ITYPE_MISC, IMISC_BOOK, sendmsg, false); - if (QuestStatus(Q_ZHAR)) { + if (Quests[Q_ZHAR].IsAvailable()) { auto &zhar = Monsters[MAX_PLRS]; if (zhar._mmode == MM_STAND // prevents playing the "angry" message for the second time if zhar got aggroed by losing vision and talking again && zhar._uniqtype - 1 == UMT_ZHAR @@ -4420,7 +4420,7 @@ void InitObjectGFX() } if (AllObjects[i].oquest != -1) { - if (QuestStatus(AllObjects[i].oquest)) + if (Quests[AllObjects[i].oquest].IsAvailable()) fileload[AllObjects[i].ofindex] = true; } } @@ -4514,11 +4514,11 @@ void InitObjects() AddNakrulGate(); } if (leveltype == DTYPE_CATHEDRAL) { - if (QuestStatus(Q_BUTCHER)) + if (Quests[Q_BUTCHER].IsAvailable()) AddTortures(); - if (QuestStatus(Q_PWATER)) + if (Quests[Q_PWATER].IsAvailable()) AddCandles(); - if (QuestStatus(Q_LTBANNER)) + if (Quests[Q_LTBANNER].IsAvailable()) AddObject(OBJ_SIGNCHEST, { 2 * setpc_x + 26, 2 * setpc_y + 19 }); InitRndLocBigObj(10, 15, OBJ_SARC); if (currlevel >= 21) @@ -4528,13 +4528,13 @@ void InitObjects() InitRndBarrels(); } if (leveltype == DTYPE_CATACOMBS) { - if (QuestStatus(Q_ROCK)) + if (Quests[Q_ROCK].IsAvailable()) InitRndLocObj5x5(1, 1, OBJ_STAND); - if (QuestStatus(Q_SCHAMB)) + if (Quests[Q_SCHAMB].IsAvailable()) InitRndLocObj5x5(1, 1, OBJ_BOOK2R); AddL2Objs(0, 0, MAXDUNX, MAXDUNY); AddL2Torches(); - if (QuestStatus(Q_BLIND)) { + if (Quests[Q_BLIND].IsAvailable()) { _speech_id spId; switch (Players[MyPlayerId]._pClass) { case HeroClass::Warrior: @@ -4560,7 +4560,7 @@ void InitObjects() AddBookLever({ { setpc_x, setpc_y }, { setpc_w + 1, setpc_h + 1 } }, spId); LoadMapObjs("Levels\\L2Data\\Blind2.DUN", { 2 * setpc_x, 2 * setpc_y }); } - if (QuestStatus(Q_BLOOD)) { + if (Quests[Q_BLOOD].IsAvailable()) { _speech_id spId; switch (Players[MyPlayerId]._pClass) { case HeroClass::Warrior: @@ -4593,7 +4593,7 @@ void InitObjects() InitRndBarrels(); } if (leveltype == DTYPE_HELL) { - if (QuestStatus(Q_WARLORD)) { + if (Quests[Q_WARLORD].IsAvailable()) { _speech_id spId; switch (Players[MyPlayerId]._pClass) { case HeroClass::Warrior: @@ -4619,7 +4619,7 @@ void InitObjects() AddBookLever({ { setpc_x, setpc_y }, { setpc_w, setpc_h } }, spId); LoadMapObjs("Levels\\L4Data\\Warlord.DUN", { 2 * setpc_x, 2 * setpc_y }); } - if (QuestStatus(Q_BETRAYER) && !gbIsMultiplayer) + if (Quests[Q_BETRAYER].IsAvailable() && !gbIsMultiplayer) AddLazStand(); InitRndBarrels(); AddL4Goodies(); diff --git a/Source/quests.cpp b/Source/quests.cpp index b2a69509..7fa78931 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -357,7 +357,7 @@ void CheckQuests() if (gbIsSpawn) return; - if (QuestStatus(Q_BETRAYER) && gbIsMultiplayer && Quests[Q_BETRAYER]._qvar1 == 2) { + if (Quests[Q_BETRAYER].IsAvailable() && gbIsMultiplayer && Quests[Q_BETRAYER]._qvar1 == 2) { AddObject(OBJ_ALTBOY, { 2 * setpc_x + 20, 2 * setpc_y + 22 }); Quests[Q_BETRAYER]._qvar1 = 3; NetSendCmdQuest(true, Q_BETRAYER); @@ -449,19 +449,6 @@ bool ForceQuests() return false; } -bool QuestStatus(quest_id questId) -{ - if (setlevel) - return false; - if (currlevel != Quests[questId]._qlevel) - return false; - if (Quests[questId]._qactive == QUEST_NOTAVAIL) - return false; - if (gbIsMultiplayer && QuestData[questId].isSinglePlayerOnly) - return false; - return true; -} - void CheckQuestKill(const MonsterStruct &monster, bool sendmsg) { if (gbIsSpawn) @@ -522,7 +509,7 @@ void CheckQuestKill(const MonsterStruct &monster, bool sendmsg) void DRLG_CheckQuests(int x, int y) { for (auto &quest : Quests) { - if (QuestStatus(static_cast(quest._qidx))) { + if (Quests[static_cast(quest._qidx)].IsAvailable()) { switch (quest._qtype) { case Q_BUTCHER: DrawButcher(); @@ -636,7 +623,7 @@ void ResyncMPQuests() Quests[Q_BETRAYER]._qactive = QUEST_ACTIVE; NetSendCmdQuest(true, Q_BETRAYER); } - if (QuestStatus(Q_BETRAYER)) + if (Quests[Q_BETRAYER].IsAvailable()) AddObject(OBJ_ALTBOY, { 2 * setpc_x + 20, 2 * setpc_y + 22 }); if (Quests[Q_GRAVE]._qactive == QUEST_INIT && currlevel == Quests[Q_GRAVE]._qlevel - 1) { Quests[Q_GRAVE]._qactive = QUEST_ACTIVE; @@ -661,7 +648,7 @@ void ResyncQuests() if (gbIsSpawn) return; - if (QuestStatus(Q_LTBANNER)) { + if (Quests[Q_LTBANNER].IsAvailable()) { if (Quests[Q_LTBANNER]._qvar1 == 1) { ObjChangeMapResync( setpc_w + setpc_x - 2, @@ -833,4 +820,18 @@ void SetMultiQuest(int q, quest_state s, bool log, int v1) } } +bool QuestStruct::IsAvailable() +{ + if (setlevel) + return false; + if (currlevel != _qlevel) + return false; + if (_qactive == QUEST_NOTAVAIL) + return false; + if (gbIsMultiplayer && QuestData[_qidx].isSinglePlayerOnly) + return false; + + return true; +} + } // namespace devilution diff --git a/Source/quests.h b/Source/quests.h index 47ff6a45..89d524f8 100644 --- a/Source/quests.h +++ b/Source/quests.h @@ -56,6 +56,8 @@ struct QuestStruct { uint8_t _qvar1; uint8_t _qvar2; bool _qlog; + + bool IsAvailable(); }; struct QuestDataStruct { @@ -88,7 +90,6 @@ void InitQuests(); void InitialiseQuestPools(uint32_t seed, QuestStruct quests[]); void CheckQuests(); bool ForceQuests(); -bool QuestStatus(quest_id questId); void CheckQuestKill(const MonsterStruct &monster, bool sendmsg); void DRLG_CheckQuests(int x, int y); void SetReturnLvlPos(); diff --git a/Source/themes.cpp b/Source/themes.cpp index b7aea4d5..9693426d 100644 --- a/Source/themes.cpp +++ b/Source/themes.cpp @@ -421,7 +421,7 @@ void InitThemes() if (leveltype == DTYPE_CATACOMBS || leveltype == DTYPE_CAVES || leveltype == DTYPE_HELL) { for (int i = 0; i < themeCount; i++) themes[i].ttype = THEME_NONE; - if (QuestStatus(Q_ZHAR)) { + if (Quests[Q_ZHAR].IsAvailable()) { for (int j = 0; j < themeCount; j++) { themes[j].ttval = themeLoc[j].ttval; if (SpecialThemeFit(j, THEME_LIBRARY)) { @@ -723,7 +723,7 @@ void Theme_Library(int t) } } - if (QuestStatus(Q_ZHAR)) { + if (Quests[Q_ZHAR].IsAvailable()) { if (t == zharlib) { return; }