Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions Source/portal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
namespace {

/** Current portal number (a portal array index). */
size_t portalindex;

Check warning on line 22 in Source/portal.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/portal.cpp:22:1 [misc-include-cleaner]

no header providing "size_t" is directly included

/** Coordinate of each player's portal in town. */
Point PortalTownPosition[MAXPORTAL] = {
std::array<Point, MAXPORTAL> ActivePortalPositions = { {

Check warning on line 24 in Source/portal.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/portal.cpp:24:12 [misc-include-cleaner]

no header providing "devilution::Point" is directly included

Check warning on line 24 in Source/portal.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/portal.cpp:24:6 [misc-include-cleaner]

no header providing "std::array" is directly included
{ 57, 40 },
{ 59, 40 },
{ 61, 40 },
{ 63, 40 },
};
} };

} // namespace

Expand All @@ -38,7 +37,7 @@
}
}

void SetPortalStats(int i, bool o, Point position, int lvl, dungeon_type lvltype, bool isSetLevel)

Check warning on line 40 in Source/portal.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/portal.cpp:40:61 [misc-include-cleaner]

no header providing "devilution::dungeon_type" is directly included
{
Portals[i].open = o;
Portals[i].position = position;
Expand All @@ -49,13 +48,13 @@

void AddPortalMissile(const Player &player, Point position, bool sync)
{
auto *missile = AddMissile({ 0, 0 }, position, Direction::South, MissileID::TownPortal, TARGET_MONSTERS, player, 0, 0, /*parent=*/nullptr, SfxID::None);

Check warning on line 51 in Source/portal.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/portal.cpp:51:141 [misc-include-cleaner]

no header providing "devilution::SfxID" is directly included

Check warning on line 51 in Source/portal.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/portal.cpp:51:67 [misc-include-cleaner]

no header providing "devilution::MissileID" is directly included

Check warning on line 51 in Source/portal.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/portal.cpp:51:49 [misc-include-cleaner]

no header providing "devilution::Direction" is directly included
if (missile != nullptr) {
// Don't show portal opening animation if we sync existing portals
if (sync)
missile->setFrameGroup<PortalFrame>(PortalFrame::Idle);

if (leveltype != DTYPE_TOWN)

Check warning on line 57 in Source/portal.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/portal.cpp:57:20 [misc-include-cleaner]

no header providing "devilution::DTYPE_TOWN" is directly included

Check warning on line 57 in Source/portal.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/portal.cpp:57:7 [misc-include-cleaner]

no header providing "devilution::leveltype" is directly included
missile->_mlid = AddLight(missile->position.tile, 15);
}
}
Expand All @@ -67,9 +66,9 @@
continue;
const Player &player = Players[i];
if (leveltype == DTYPE_TOWN)
AddPortalMissile(player, PortalTownPosition[i], true);
AddPortalMissile(player, GetPortalTownPosition(static_cast<size_t>(i)), true);
else {
int lvl = currlevel;

Check warning on line 71 in Source/portal.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/portal.cpp:71:14 [misc-include-cleaner]

no header providing "devilution::currlevel" is directly included
if (setlevel)
lvl = setlvlnum;
if (Portals[i].level == lvl && Portals[i].setlvl == setlevel)
Expand All @@ -80,7 +79,7 @@

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)
Expand Down Expand Up @@ -163,7 +162,7 @@
void GetPortalLvlPos()
{
if (leveltype == DTYPE_TOWN) {
ViewPosition = PortalTownPosition[portalindex] + Displacement { 1, 1 };
ViewPosition = GetPortalTownPosition(portalindex) + Displacement { 1, 1 };
} else {
ViewPosition = Portals[portalindex].position;

Expand All @@ -186,4 +185,16 @@
return false;
}

Point GetPortalTownPosition(size_t portalIndex)
{
if (portalIndex >= MAXPORTAL)
return ActivePortalPositions[0];
return ActivePortalPositions[portalIndex];
}

void SetPortalTownPositions(std::array<Point, MAXPORTAL> positions)
{
ActivePortalPositions = positions;
}

} // namespace devilution
9 changes: 9 additions & 0 deletions Source/portal.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/
#pragma once

#include <array>
#include <cstddef>

#include "engine/point.hpp"
#include "levels/gendung.h"

Expand Down Expand Up @@ -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<Point, MAXPORTAL> positions);

} // namespace devilution
Loading