Browse Source

♻️ Extract quest entrance boundary check to a member function on QuestStruct

pull/2845/head
Juliano Leal Goncalves 5 years ago committed by Anders Jenbo
parent
commit
8a93087fb7
  1. 26
      Source/quests.cpp
  2. 6
      Source/quests.h

26
Source/quests.cpp

@ -85,12 +85,6 @@ int topY;
int lineSpacing;
int act2finSpacing;
/**
* Specifies a displacement from the quest entrance for
* which the hover text of the cursor will be visible.
*/
Displacement questEntranceOffsets[7] = { { 0, 0 }, { -1, 0 }, { 0, -1 }, { -1, -1 }, { -2, -1 }, { -1, -2 }, { -2, -2 } };
const char *const QuestTriggerNames[5] = {
N_(/* TRANSLATORS: Quest Map*/ "King Leoric's Tomb"),
N_(/* TRANSLATORS: Quest Map*/ "The Chamber of Bone"),
@ -451,12 +445,10 @@ bool ForceQuests()
if (quest._qidx != Q_BETRAYER && currlevel == quest._qlevel && quest._qslvl != 0) {
int ql = quest._qslvl - 1;
for (int j = 0; j < 7; j++) {
if (quest.position + questEntranceOffsets[j] == cursPosition) {
strcpy(infostr, fmt::format(_(/* TRANSLATORS: Used for Quest Portals. {:s} is a Map Name */ "To {:s}"), _(QuestTriggerNames[ql])).c_str());
cursPosition = quest.position;
return true;
}
if (quest.EntranceBoundaryContains(cursPosition)) {
strcpy(infostr, fmt::format(_(/* TRANSLATORS: Used for Quest Portals. {:s} is a Map Name */ "To {:s}"), _(QuestTriggerNames[ql])).c_str());
cursPosition = quest.position;
return true;
}
}
}
@ -889,4 +881,14 @@ bool Quest::IsAvailable()
return true;
}
bool Quest::EntranceBoundaryContains(Point position) const
{
constexpr Displacement questEntranceOffsets[7] = { { 0, 0 }, { -1, 0 }, { 0, -1 }, { -1, -1 }, { -2, -1 }, { -1, -2 }, { -2, -2 } };
return std::any_of(
std::begin(questEntranceOffsets),
std::end(questEntranceOffsets),
[&](auto offset) { return this->position + offset == position; });
}
} // namespace devilution

6
Source/quests.h

@ -57,6 +57,12 @@ struct Quest {
uint8_t _qvar2;
bool IsAvailable();
/**
* @brief Gets a value indicating whether the provided position is in the entrance boundary of the quest.
* @param position The position to check against this quest's entrance boundary.
*/
bool EntranceBoundaryContains(Point position) const;
};
struct QuestData {

Loading…
Cancel
Save