Browse Source

Point mega <-> world conversion helpers

pull/4700/head
Andrew James 4 years ago committed by GitHub
parent
commit
4bd1e06336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      Source/debug.cpp
  2. 12
      Source/drlg_l4.cpp
  3. 12
      Source/engine/point.hpp
  4. 20
      Source/quests.cpp

2
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);

12
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();

12
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

20
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) {

Loading…
Cancel
Save