diff --git a/Source/portal.cpp b/Source/portal.cpp index 4d02adda5f6..afbb53bae6a 100644 --- a/Source/portal.cpp +++ b/Source/portal.cpp @@ -21,13 +21,12 @@ namespace { /** Current portal number (a portal array index). */ size_t portalindex; -/** Coordinate of each player's portal in town. */ -Point PortalTownPosition[MAXPORTAL] = { +std::array ActivePortalPositions = { { { 57, 40 }, { 59, 40 }, { 61, 40 }, { 63, 40 }, -}; +} }; } // namespace @@ -67,7 +66,7 @@ void SyncPortals() continue; const Player &player = Players[i]; if (leveltype == DTYPE_TOWN) - AddPortalMissile(player, PortalTownPosition[i], true); + AddPortalMissile(player, GetPortalTownPosition(static_cast(i)), true); else { int lvl = currlevel; if (setlevel) @@ -80,7 +79,7 @@ void SyncPortals() void AddPortalInTown(const Player &player) { - AddPortalMissile(player, PortalTownPosition[player.getId()], false); + AddPortalMissile(player, GetPortalTownPosition(player.getId()), false); } void ActivatePortal(const Player &player, Point position, int lvl, dungeon_type dungeonType, bool isSetLevel) @@ -163,7 +162,7 @@ void GetPortalLevel() void GetPortalLvlPos() { if (leveltype == DTYPE_TOWN) { - ViewPosition = PortalTownPosition[portalindex] + Displacement { 1, 1 }; + ViewPosition = GetPortalTownPosition(portalindex) + Displacement { 1, 1 }; } else { ViewPosition = Portals[portalindex].position; @@ -186,4 +185,16 @@ bool PosOkPortal(int lvl, Point position) return false; } +Point GetPortalTownPosition(size_t portalIndex) +{ + if (portalIndex >= MAXPORTAL) + return ActivePortalPositions[0]; + return ActivePortalPositions[portalIndex]; +} + +void SetPortalTownPositions(std::array positions) +{ + ActivePortalPositions = positions; +} + } // namespace devilution diff --git a/Source/portal.h b/Source/portal.h index 30e05f6a8e0..866ca89dec7 100644 --- a/Source/portal.h +++ b/Source/portal.h @@ -5,6 +5,9 @@ */ #pragma once +#include +#include + #include "engine/point.hpp" #include "levels/gendung.h" @@ -39,4 +42,10 @@ void GetPortalLevel(); void GetPortalLvlPos(); bool PosOkPortal(int lvl, Point position); +/** Returns the town-map position for portal slot `portalIndex`. */ +Point GetPortalTownPosition(size_t portalIndex); + +/** Overrides all portal positions for the current town. */ +void SetPortalTownPositions(std::array positions); + } // namespace devilution