diff --git a/Source/debug.cpp b/Source/debug.cpp index dad4c18fc..89defeb36 100644 --- a/Source/debug.cpp +++ b/Source/debug.cpp @@ -1081,7 +1081,7 @@ bool IsDebugGridInMegatiles() bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer) { int info = 0; - Point megaCoords = { (dungeonCoords.x - 16) / 2, (dungeonCoords.y - 16) / 2 }; + Point megaCoords = dungeonCoords.worldToMega(); switch (SelectedDebugGridTextItem) { case DebugGridTextItem::coords: sprintf(debugGridTextBuffer, "%d:%d", dungeonCoords.x, dungeonCoords.y); diff --git a/Source/drlg_l4.cpp b/Source/drlg_l4.cpp index 46d9514f2..d9a35a8aa 100644 --- a/Source/drlg_l4.cpp +++ b/Source/drlg_l4.cpp @@ -1340,8 +1340,8 @@ void CreateL4Dungeon(uint32_t rseed, lvl_entry entry) { SetRndSeed(rseed); - dminPosition = { 16, 16 }; - dmaxPosition = { 96, 96 }; + dminPosition = Point(0, 0).megaToWorld(); + dmaxPosition = Point(40, 40).megaToWorld(); ViewPosition = { 40, 40 }; @@ -1355,8 +1355,8 @@ void CreateL4Dungeon(uint32_t rseed, lvl_entry entry) void LoadL4Dungeon(const char *path, int vx, int vy) { - dminPosition = { 16, 16 }; - dmaxPosition = { 96, 96 }; + dminPosition = Point(0, 0).megaToWorld(); + dmaxPosition = Point(40, 40).megaToWorld(); DRLG_InitTrans(); InitDungeonFlags(); @@ -1376,8 +1376,8 @@ void LoadL4Dungeon(const char *path, int vx, int vy) void LoadPreL4Dungeon(const char *path) { - dminPosition = { 16, 16 }; - dmaxPosition = { 96, 96 }; + dminPosition = Point(0, 0).megaToWorld(); + dmaxPosition = Point(40, 40).megaToWorld(); InitDungeonFlags(); diff --git a/Source/engine/point.hpp b/Source/engine/point.hpp index 227dd396d..b6b5a541f 100644 --- a/Source/engine/point.hpp +++ b/Source/engine/point.hpp @@ -162,13 +162,21 @@ struct Point { } /** - * @brief Converte from mega tile cordinates to dungeon piece cordinates + * @brief Converts a coordinate in megatiles to the northmost of the 4 corresponding world tiles */ - constexpr Point megaToWorld() + constexpr Point megaToWorld() const { return { 16 + 2 * x, 16 + 2 * y }; } + /** + * @brief Converts a coordinate in world tiles back to the corresponding megatile + */ + constexpr Point worldToMega() const + { + return { (x - 16) / 2, (y - 16) / 2 }; + } + #ifdef BUILD_TESTING /** * @brief Format points nicely in test failure messages diff --git a/Source/quests.cpp b/Source/quests.cpp index b3bf67102..864ada8d5 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -133,7 +133,7 @@ void DrawButcher() void DrawSkelKing(quest_id q, Point position) { - Quests[q].position = { 2 * position.x + 28, 2 * position.y + 23 }; + Quests[q].position = position.megaToWorld() + Displacement { 12, 7 }; } void DrawWarLord(Point position) @@ -179,7 +179,7 @@ void DrawSChamber(quest_id q, Point position) } } - Quests[q].position = { 2 * position.x + 22, 2 * position.y + 23 }; + Quests[q].position = position.megaToWorld() + Displacement { 6, 7 }; } void DrawLTBanner(Point position) @@ -375,7 +375,7 @@ void CheckQuests() auto &quest = Quests[Q_BETRAYER]; if (quest.IsAvailable() && gbIsMultiplayer && quest._qvar1 == 2) { - AddObject(OBJ_ALTBOY, { 2 * setpc_x + 20, 2 * setpc_y + 22 }); + AddObject(OBJ_ALTBOY, Point(setpc_x, setpc_y).megaToWorld() + Displacement { 4, 6 }); quest._qvar1 = 3; NetSendCmdQuest(true, quest); } @@ -389,11 +389,8 @@ void CheckQuests() && quest._qvar1 >= 2 && (quest._qactive == QUEST_ACTIVE || quest._qactive == QUEST_DONE) && (quest._qvar2 == 0 || quest._qvar2 == 2)) { - quest.position.x = 2 * quest.position.x + 16; - quest.position.y = 2 * quest.position.y + 16; - int rportx = quest.position.x; - int rporty = quest.position.y; - AddMissile({ rportx, rporty }, { rportx, rporty }, Direction::South, MIS_RPORTAL, TARGET_MONSTERS, MyPlayerId, 0, 0); + Point portalLocation = quest.position.megaToWorld(); + AddMissile(portalLocation, portalLocation, Direction::South, MIS_RPORTAL, TARGET_MONSTERS, MyPlayerId, 0, 0); quest._qvar2 = 1; if (quest._qactive == QUEST_ACTIVE && quest._qvar1 == 2) { quest._qvar1 = 3; @@ -404,9 +401,8 @@ void CheckQuests() && setlevel && setlvlnum == SL_VILEBETRAYER && quest._qvar2 == 4) { - int rportx = 35; - int rporty = 32; - AddMissile({ rportx, rporty }, { rportx, rporty }, Direction::South, MIS_RPORTAL, TARGET_MONSTERS, MyPlayerId, 0, 0); + Point portalLocation { 35, 32 }; + AddMissile(portalLocation, portalLocation, Direction::South, MIS_RPORTAL, TARGET_MONSTERS, MyPlayerId, 0, 0); quest._qvar2 = 3; } @@ -640,7 +636,7 @@ void ResyncMPQuests() NetSendCmdQuest(true, betrayerQuest); } if (betrayerQuest.IsAvailable()) - AddObject(OBJ_ALTBOY, { 2 * setpc_x + 20, 2 * setpc_y + 22 }); + AddObject(OBJ_ALTBOY, Point(setpc_x, setpc_y).megaToWorld() + Displacement { 4, 6 }); auto &cryptQuest = Quests[Q_GRAVE]; if (cryptQuest._qactive == QUEST_INIT && currlevel == cryptQuest._qlevel - 1) {