diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index a7ccc1901..e5be24c49 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -373,7 +373,7 @@ void FindActor() int pcursmissile; int pcurstrig; -int pcursquest; +quest_id pcursquest; void FindTrigger() { @@ -1308,7 +1308,7 @@ void plrctrls_after_check_curs_move() pcursobj = -1; pcursmissile = -1; pcurstrig = -1; - pcursquest = -1; + pcursquest = Q_INVALID; cursmx = -1; cursmy = -1; if (Players[MyPlayerId]._pInvincible) { @@ -1527,7 +1527,7 @@ void PerformSecondaryAction() } else if (pcurstrig != -1) { MakePlrPath(myPlayer, trigs[pcurstrig].position, true); myPlayer.destAction = ACTION_WALK; - } else if (pcursquest != -1) { + } else if (pcursquest != Q_INVALID) { MakePlrPath(myPlayer, Quests[pcursquest].position, true); myPlayer.destAction = ACTION_WALK; } diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 025383e98..d5c0e9626 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -741,13 +741,13 @@ void LoadQuest(LoadHelper *file, int i) QuestStruct *pQuest = &Quests[i]; pQuest->_qlevel = file->NextLE(); - pQuest->_qtype = file->NextLE(); + file->Skip(); // _qtype, identical to _qidx pQuest->_qactive = static_cast(file->NextLE()); pQuest->_qlvltype = static_cast(file->NextLE()); pQuest->position.x = file->NextLE(); pQuest->position.y = file->NextLE(); pQuest->_qslvl = static_cast<_setlevels>(file->NextLE()); - pQuest->_qidx = file->NextLE(); + pQuest->_qidx = static_cast(file->NextLE()); if (gbIsHellfireSaveGame) { file->Skip(2); // Alignment pQuest->_qmsg = static_cast<_speech_id>(file->NextLE()); @@ -1384,7 +1384,7 @@ void SaveQuest(SaveHelper *file, int i) QuestStruct *pQuest = &Quests[i]; file->WriteLE(pQuest->_qlevel); - file->WriteLE(pQuest->_qtype); + file->WriteLE(pQuest->_qidx); // _qtype for compatability, used in DRLG_CheckQuests file->WriteLE(pQuest->_qactive); file->WriteLE(pQuest->_qlvltype); file->WriteLE(pQuest->position.x); diff --git a/Source/quests.cpp b/Source/quests.cpp index 4362dec3e..1a594f5de 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -38,31 +38,31 @@ int ReturnLevel; /** Contains the data related to each quest_id. */ QuestDataStruct QuestData[] = { // clang-format off - // _qdlvl, _qdmultlvl, _qlvlt, _qdtype, _qdrnd, _qslvl, isSinglePlayerOnly, _qdmsg, _qlstr - { 5, -1, DTYPE_NONE, Q_ROCK, 100, SL_NONE, true, TEXT_INFRA5, N_( /* TRANSLATORS: Quest Name Block */ "The Magic Rock") }, - { 9, -1, DTYPE_NONE, Q_MUSHROOM, 100, SL_NONE, true, TEXT_MUSH8, N_("Black Mushroom") }, - { 4, -1, DTYPE_NONE, Q_GARBUD, 100, SL_NONE, true, TEXT_GARBUD1, N_("Gharbad The Weak") }, - { 8, -1, DTYPE_NONE, Q_ZHAR, 100, SL_NONE, true, TEXT_ZHAR1, N_("Zhar the Mad") }, - { 14, -1, DTYPE_NONE, Q_VEIL, 100, SL_NONE, true, TEXT_VEIL9, "Lachdanan" }, - { 15, -1, DTYPE_NONE, Q_DIABLO, 100, SL_NONE, false, TEXT_VILE3, "Diablo" }, - { 2, 2, DTYPE_NONE, Q_BUTCHER, 100, SL_NONE, false, TEXT_BUTCH9, N_("The Butcher") }, - { 4, -1, DTYPE_NONE, Q_LTBANNER, 100, SL_NONE, true, TEXT_BANNER2, N_("Ogden's Sign") }, - { 7, -1, DTYPE_NONE, Q_BLIND, 100, SL_NONE, true, TEXT_BLINDING, N_("Halls of the Blind") }, - { 5, -1, DTYPE_NONE, Q_BLOOD, 100, SL_NONE, true, TEXT_BLOODY, N_("Valor") }, - { 10, -1, DTYPE_NONE, Q_ANVIL, 100, SL_NONE, true, TEXT_ANVIL5, N_("Anvil of Fury") }, - { 13, -1, DTYPE_NONE, Q_WARLORD, 100, SL_NONE, true, TEXT_BLOODWAR, N_("Warlord of Blood") }, - { 3, 3, DTYPE_CATHEDRAL, Q_SKELKING, 100, SL_SKELKING, false, TEXT_KING2, N_("The Curse of King Leoric") }, - { 2, -1, DTYPE_CAVES, Q_PWATER, 100, SL_POISONWATER, true, TEXT_POISON3, N_("Poisoned Water Supply") }, - { 6, -1, DTYPE_CATACOMBS, Q_SCHAMB, 100, SL_BONECHAMB, true, TEXT_BONER, N_("The Chamber of Bone") }, - { 15, 15, DTYPE_CATHEDRAL, Q_BETRAYER, 100, SL_VILEBETRAYER, false, TEXT_VILE1, N_("Archbishop Lazarus") }, - { 17, 17, DTYPE_NONE, Q_GRAVE, 100, SL_NONE, false, TEXT_GRAVE7, N_("Grave Matters") }, - { 9, 9, DTYPE_NONE, Q_FARMER, 100, SL_NONE, false, TEXT_FARMER1, N_("Farmer's Orchard") }, - { 17, -1, DTYPE_NONE, Q_GIRL, 100, SL_NONE, true, TEXT_GIRL2, N_("Little Girl") }, - { 19, -1, DTYPE_NONE, Q_TRADER, 100, SL_NONE, true, TEXT_TRADER, N_("Wandering Trader") }, - { 17, 17, DTYPE_NONE, Q_DEFILER, 100, SL_NONE, false, TEXT_DEFILER1, N_("The Defiler") }, - { 21, 21, DTYPE_NONE, Q_NAKRUL, 100, SL_NONE, false, TEXT_NAKRUL1, "Na-Krul" }, - { 21, -1, DTYPE_NONE, Q_CORNSTN, 100, SL_NONE, true, TEXT_CORNSTN, N_("Cornerstone of the World") }, - { 9, 9, DTYPE_NONE, Q_JERSEY, 100, SL_NONE, false, TEXT_JERSEY4, N_( /* TRANSLATORS: Quest Name Block end*/ "The Jersey's Jersey") }, + // _qdlvl, _qdmultlvl, _qlvlt, _qdrnd, _qslvl, isSinglePlayerOnly, _qdmsg, _qlstr + { 5, -1, DTYPE_NONE, 100, SL_NONE, true, TEXT_INFRA5, N_( /* TRANSLATORS: Quest Name Block */ "The Magic Rock") }, + { 9, -1, DTYPE_NONE, 100, SL_NONE, true, TEXT_MUSH8, N_("Black Mushroom") }, + { 4, -1, DTYPE_NONE, 100, SL_NONE, true, TEXT_GARBUD1, N_("Gharbad The Weak") }, + { 8, -1, DTYPE_NONE, 100, SL_NONE, true, TEXT_ZHAR1, N_("Zhar the Mad") }, + { 14, -1, DTYPE_NONE, 100, SL_NONE, true, TEXT_VEIL9, "Lachdanan" }, + { 15, -1, DTYPE_NONE, 100, SL_NONE, false, TEXT_VILE3, "Diablo" }, + { 2, 2, DTYPE_NONE, 100, SL_NONE, false, TEXT_BUTCH9, N_("The Butcher") }, + { 4, -1, DTYPE_NONE, 100, SL_NONE, true, TEXT_BANNER2, N_("Ogden's Sign") }, + { 7, -1, DTYPE_NONE, 100, SL_NONE, true, TEXT_BLINDING, N_("Halls of the Blind") }, + { 5, -1, DTYPE_NONE, 100, SL_NONE, true, TEXT_BLOODY, N_("Valor") }, + { 10, -1, DTYPE_NONE, 100, SL_NONE, true, TEXT_ANVIL5, N_("Anvil of Fury") }, + { 13, -1, DTYPE_NONE, 100, SL_NONE, true, TEXT_BLOODWAR, N_("Warlord of Blood") }, + { 3, 3, DTYPE_CATHEDRAL, 100, SL_SKELKING, false, TEXT_KING2, N_("The Curse of King Leoric") }, + { 2, -1, DTYPE_CAVES, 100, SL_POISONWATER, true, TEXT_POISON3, N_("Poisoned Water Supply") }, + { 6, -1, DTYPE_CATACOMBS, 100, SL_BONECHAMB, true, TEXT_BONER, N_("The Chamber of Bone") }, + { 15, 15, DTYPE_CATHEDRAL, 100, SL_VILEBETRAYER, false, TEXT_VILE1, N_("Archbishop Lazarus") }, + { 17, 17, DTYPE_NONE, 100, SL_NONE, false, TEXT_GRAVE7, N_("Grave Matters") }, + { 9, 9, DTYPE_NONE, 100, SL_NONE, false, TEXT_FARMER1, N_("Farmer's Orchard") }, + { 17, -1, DTYPE_NONE, 100, SL_NONE, true, TEXT_GIRL2, N_("Little Girl") }, + { 19, -1, DTYPE_NONE, 100, SL_NONE, true, TEXT_TRADER, N_("Wandering Trader") }, + { 17, 17, DTYPE_NONE, 100, SL_NONE, false, TEXT_DEFILER1, N_("The Defiler") }, + { 21, 21, DTYPE_NONE, 100, SL_NONE, false, TEXT_NAKRUL1, "Na-Krul" }, + { 21, -1, DTYPE_NONE, 100, SL_NONE, true, TEXT_CORNSTN, N_("Cornerstone of the World") }, + { 9, 9, DTYPE_NONE, 100, SL_NONE, false, TEXT_JERSEY4, N_( /* TRANSLATORS: Quest Name Block end*/ "The Jersey's Jersey") }, // clang-format on }; @@ -70,7 +70,7 @@ namespace { int qtopline; int qline; -int qlist[MAXQUESTS]; +quest_id qlist[MAXQUESTS]; int numqlines; int WaterDone; @@ -123,7 +123,7 @@ void DrawButcher() DRLG_RectTrans(x + 3, y + 3, x + 10, y + 10); } -void DrawSkelKing(int q, int x, int y) +void DrawSkelKing(quest_id q, int x, int y) { Quests[q].position = { 2 * x + 28, 2 * y + 23 }; } @@ -150,7 +150,7 @@ void DrawWarLord(int x, int y) } } -void DrawSChamber(int q, int x, int y) +void DrawSChamber(quest_id q, int x, int y) { auto dunData = LoadFileInMem("Levels\\L2Data\\Bonestr1.DUN"); @@ -264,54 +264,38 @@ void PrintQLString(const Surface &out, int x, int line, const char *str) void InitQuests() { - if (!gbIsMultiplayer) { - for (auto &quest : Quests) { - quest._qactive = QUEST_NOTAVAIL; - } - } else { - int q = 0; - for (auto &quest : Quests) { - if (QuestData[q].isSinglePlayerOnly) { - quest._qactive = QUEST_NOTAVAIL; - } - q++; - } - } - QuestDialogTable[TOWN_HEALER][Q_MUSHROOM] = TEXT_NONE; QuestDialogTable[TOWN_WITCH][Q_MUSHROOM] = TEXT_MUSH9; QuestLogIsOpen = false; WaterDone = 0; - int initiatedQuests = 0; + int initiatedQuests = 0; int q = 0; for (auto &quest : Quests) { - if (!gbIsMultiplayer || !QuestData[q].isSinglePlayerOnly) { - quest._qtype = QuestData[q]._qdtype; - if (gbIsMultiplayer) { - quest._qlevel = QuestData[q]._qdmultlvl; - if (!delta_quest_inited(initiatedQuests)) { - quest._qactive = QUEST_INIT; - quest._qvar1 = 0; - quest._qlog = false; - } - initiatedQuests++; - } else { + quest._qidx = static_cast(q); + auto &questData = QuestData[q]; + q++; + + quest._qactive = QUEST_NOTAVAIL; + quest.position = { 0, 0 }; + quest._qlvltype = questData._qlvlt; + quest._qslvl = questData._qslvl; + quest._qvar1 = 0; + quest._qvar2 = 0; + quest._qlog = false; + quest._qmsg = questData._qdmsg; + + if (!gbIsMultiplayer) { + quest._qlevel = questData._qdlvl; + quest._qactive = QUEST_INIT; + } else if (!questData.isSinglePlayerOnly) { + quest._qlevel = questData._qdmultlvl; + if (!delta_quest_inited(initiatedQuests)) { quest._qactive = QUEST_INIT; - quest._qlevel = QuestData[q]._qdlvl; - quest._qvar1 = 0; - quest._qlog = false; } - - quest._qslvl = QuestData[q]._qslvl; - quest.position = { 0, 0 }; - quest._qidx = q; - quest._qlvltype = QuestData[q]._qlvlt; - quest._qvar2 = 0; - quest._qmsg = QuestData[q]._qdmsg; + initiatedQuests++; } - q++; } if (!gbIsMultiplayer && sgOptions.Gameplay.bRandomizeQuests) { @@ -505,8 +489,8 @@ void CheckQuestKill(const MonsterStruct &monster, bool sendmsg) void DRLG_CheckQuests(int x, int y) { for (auto &quest : Quests) { - if (Quests[static_cast(quest._qidx)].IsAvailable()) { - switch (quest._qtype) { + if (quest.IsAvailable()) { + switch (quest._qidx) { case Q_BUTCHER: DrawButcher(); break; @@ -528,6 +512,8 @@ void DRLG_CheckQuests(int x, int y) case Q_SCHAMB: DrawSChamber(quest._qidx, x, y); break; + default: + break; } } } diff --git a/Source/quests.h b/Source/quests.h index 89d524f8c..931516834 100644 --- a/Source/quests.h +++ b/Source/quests.h @@ -45,17 +45,16 @@ enum quest_state : uint8_t { }; struct QuestStruct { - uint8_t _qlevel; - uint8_t _qtype; + quest_id _qidx; quest_state _qactive; - dungeon_type _qlvltype; + uint8_t _qlevel; Point position; + dungeon_type _qlvltype; _setlevels _qslvl; - uint8_t _qidx; + bool _qlog; _speech_id _qmsg; uint8_t _qvar1; uint8_t _qvar2; - bool _qlog; bool IsAvailable(); }; @@ -64,7 +63,6 @@ struct QuestDataStruct { uint8_t _qdlvl; int8_t _qdmultlvl; dungeon_type _qlvlt; - uint8_t _qdtype; uint8_t _qdrnd; _setlevels _qslvl; bool isSinglePlayerOnly;