diff --git a/Source/msg.cpp b/Source/msg.cpp index 3ad41e3a9..838d5c623 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -2709,13 +2709,12 @@ void DeltaSyncJunk() { for (int i = 0; i < MAXPORTAL; i++) { if (sgJunk.portal[i].x == 0xFF) { - SetPortalStats(i, false, 0, 0, 0, DTYPE_TOWN, false); + SetPortalStats(i, false, { 0, 0 }, 0, DTYPE_TOWN, false); } else { SetPortalStats( i, true, - sgJunk.portal[i].x, - sgJunk.portal[i].y, + { sgJunk.portal[i].x, sgJunk.portal[i].y }, sgJunk.portal[i].level, (dungeon_type)sgJunk.portal[i].ltype, sgJunk.portal[i].setlvl); diff --git a/Source/objects.cpp b/Source/objects.cpp index d8cc11d7f..bc1579151 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -1491,41 +1491,41 @@ void AddTorturedBody(Object &torturedBody) torturedBody._oPreFlag = true; } -void GetRndObjLoc(int randarea, int *xx, int *yy) +Point GetRndObjLoc(int randarea) { if (randarea == 0) - return; + return { 0, 0 }; int tries = 0; + int x; + int y; while (true) { tries++; if (tries > 1000 && randarea > 1) randarea--; - *xx = GenerateRnd(MAXDUNX); - *yy = GenerateRnd(MAXDUNY); + x = GenerateRnd(MAXDUNX); + y = GenerateRnd(MAXDUNY); bool failed = false; for (int i = 0; i < randarea && !failed; i++) { for (int j = 0; j < randarea && !failed; j++) { - failed = !RndLocOk(i + *xx, j + *yy); + failed = !RndLocOk(i + x, j + y); } } if (!failed) break; } + return { x, y }; } void AddMushPatch() { - int y; - int x; - if (ActiveObjectCount < MAXOBJECTS) { int i = AvailableObjects[0]; - GetRndObjLoc(5, &x, &y); - dObject[x + 1][y + 1] = -(i + 1); - dObject[x + 2][y + 1] = -(i + 1); - dObject[x + 1][y + 2] = -(i + 1); - AddObject(OBJ_MUSHPATCH, { x + 2, y + 2 }); + const Point loc = GetRndObjLoc(5); + dObject[loc.x + 1][loc.y + 1] = -(i + 1); + dObject[loc.x + 2][loc.y + 1] = -(i + 1); + dObject[loc.x + 1][loc.y + 2] = -(i + 1); + AddObject(OBJ_MUSHPATCH, { loc.x + 2, loc.y + 2 }); } } @@ -3808,11 +3808,8 @@ void AddCryptObjects(int x1, int y1, int x2, int y2) void AddSlainHero() { - int x; - int y; - - GetRndObjLoc(5, &x, &y); - AddObject(OBJ_SLAINHERO, { x + 2, y + 2 }); + Point rndObjLoc = GetRndObjLoc(5); + AddObject(OBJ_SLAINHERO, rndObjLoc + Displacement { 2, 2 }); } void InitObjects() diff --git a/Source/player.cpp b/Source/player.cpp index 1b2b7b17f..f19160f00 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -3308,7 +3308,7 @@ void SyncInitPlrPos(Player &player) std::optional nearPosition = FindClosestValidPosition( [&player](Point testPosition) { - return PosOkPlayer(player, testPosition) && !PosOkPortal(currlevel, testPosition.x, testPosition.y); + return PosOkPlayer(player, testPosition) && !PosOkPortal(currlevel, testPosition); }, player.position.tile, 1, // skip the starting tile since that was checked in the previous loop diff --git a/Source/portal.cpp b/Source/portal.cpp index e77afe50b..c73077477 100644 --- a/Source/portal.cpp +++ b/Source/portal.cpp @@ -38,10 +38,10 @@ void InitPortals() } } -void SetPortalStats(int i, bool o, int x, int y, int lvl, dungeon_type lvltype, bool isSetLevel) +void SetPortalStats(int i, bool o, Point position, int lvl, dungeon_type lvltype, bool isSetLevel) { Portals[i].open = o; - Portals[i].position = { x, y }; + Portals[i].position = position; Portals[i].level = lvl; Portals[i].ltype = lvltype; Portals[i].setlvl = isSetLevel; @@ -170,10 +170,13 @@ void GetPortalLvlPos() } } -bool PosOkPortal(int lvl, int x, int y) +bool PosOkPortal(int lvl, Point position) { for (auto &portal : Portals) { - if (portal.open && portal.level == lvl && ((portal.position.x == x && portal.position.y == y) || (portal.position.x == x - 1 && portal.position.y == y - 1))) + if (portal.open + && portal.level == lvl + && ((portal.position == position) + || (portal.position == position - Displacement { 1, 1 }))) return true; } return false; diff --git a/Source/portal.h b/Source/portal.h index 3c2e6e3f3..69aa21e7d 100644 --- a/Source/portal.h +++ b/Source/portal.h @@ -23,7 +23,7 @@ struct Portal { extern Portal Portals[MAXPORTAL]; void InitPortals(); -void SetPortalStats(int i, bool o, int x, int y, int lvl, dungeon_type lvltype, bool isSetLevel); +void SetPortalStats(int i, bool o, Point position, int lvl, dungeon_type lvltype, bool isSetLevel); void AddWarpMissile(int i, Point position, bool sync); void SyncPortals(); void AddInTownPortal(int i); @@ -34,6 +34,6 @@ void RemovePortalMissile(int id); void SetCurrentPortal(size_t p); void GetPortalLevel(); void GetPortalLvlPos(); -bool PosOkPortal(int lvl, int x, int y); +bool PosOkPortal(int lvl, Point position); } // namespace devilution