Browse Source

Consolidate walk functions

pull/7046/head^2
KPhoenix 2 years ago committed by Anders Jenbo
parent
commit
fee49ea061
  1. 3
      Source/automap.cpp
  2. 4
      Source/engine/actor_position.cpp
  3. 3
      Source/engine/render/scrollrt.cpp
  4. 40
      Source/monster.cpp
  5. 34
      Source/player.cpp

3
Source/automap.cpp

@ -1320,9 +1320,6 @@ void DrawAutomapPlr(const Surface &out, const Displacement &myPlayerOffset, cons
const uint8_t playerColor = MapColorsPlayer + (8 * player.getId()) % 128;
Point tile = player.position.tile;
if (player._pmode == PM_WALK_SIDEWAYS) {
tile = player.position.future;
}
int px = tile.x - 2 * AutomapOffset.deltaX - ViewPosition.x;
int py = tile.y - 2 * AutomapOffset.deltaY - ViewPosition.y;

4
Source/engine/actor_position.cpp

@ -94,11 +94,11 @@ constexpr std::array<const WalkParameter, 8> WalkParameters { {
// Direction startingOffset, VelocityX, VelocityY
{ /* South */ { 0, 0 }, VelocityToUse::None, VelocityToUse::Half },
{ /* SouthWest */ { 0, 0 }, VelocityToUse::NegativeHalf, VelocityToUse::Quarter },
{ /* West */ { 512, -256 }, VelocityToUse::NegativeFull, VelocityToUse::None },
{ /* West */ { 0, 0 }, VelocityToUse::NegativeFull, VelocityToUse::None },
{ /* NorthWest */ { 0, 0 }, VelocityToUse::NegativeHalf, VelocityToUse::NegativeQuarter },
{ /* North */ { 0, 0 }, VelocityToUse::None, VelocityToUse::NegativeHalf },
{ /* NorthEast */ { 0, 0 }, VelocityToUse::Half, VelocityToUse::NegativeQuarter },
{ /* East */ { -512, -256 }, VelocityToUse::Full, VelocityToUse::None },
{ /* East */ { 0, 0 }, VelocityToUse::Full, VelocityToUse::None },
{ /* SouthEast */ { 0, 0 }, VelocityToUse::Half, VelocityToUse::Quarter }
// clang-format on
} };

3
Source/engine/render/scrollrt.cpp

@ -1334,7 +1334,6 @@ Displacement GetOffsetForWalking(const AnimationInfo &animationInfo, const Direc
{
// clang-format off
// South, SouthWest, West, NorthWest, North, NorthEast, East, SouthEast,
constexpr Displacement StartOffset[8] = { { 0, 0 }, { 0, 0 }, { 64, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { -64, 0 }, { 0, 0 } };
constexpr Displacement MovingOffset[8] = { { 0, 32 }, { -32, 16 }, { -64, 0 }, { -32, -16 }, { 0, -32 }, { 32, -16 }, { 64, 0 }, { 32, 16 } };
// clang-format on
@ -1345,8 +1344,6 @@ Displacement GetOffsetForWalking(const AnimationInfo &animationInfo, const Direc
if (cameraMode) {
offset = -offset;
} else {
offset += StartOffset[static_cast<size_t>(dir)];
}
return offset;

40
Source/monster.cpp

@ -710,7 +710,7 @@ void StartSpecialStand(Monster &monster, Direction md)
monster.position.old = monster.position.tile;
}
void WalkNonSideways(Monster &monster, int xadd, int yadd, Direction endDir)
void Walk(Monster &monster, int xadd, int yadd, Direction endDir)
{
const auto fx = static_cast<WorldTileCoord>(xadd + monster.position.tile.x);
const auto fy = static_cast<WorldTileCoord>(yadd + monster.position.tile.y);
@ -725,28 +725,6 @@ void WalkNonSideways(Monster &monster, int xadd, int yadd, Direction endDir)
NewMonsterAnim(monster, MonsterGraphic::Walk, endDir, AnimationDistributionFlags::ProcessAnimationPending, -1);
}
void WalkSideways(Monster &monster, int xoff, int yoff, int xadd, int yadd, int mapx, int mapy, Direction endDir)
{
const auto fx = static_cast<WorldTileCoord>(xadd + monster.position.tile.x);
const auto fy = static_cast<WorldTileCoord>(yadd + monster.position.tile.y);
const auto x = static_cast<WorldTileCoord>(mapx + monster.position.tile.x);
const auto y = static_cast<WorldTileCoord>(mapy + monster.position.tile.y);
if (monster.lightId != NO_LIGHT)
ChangeLightXY(monster.lightId, { x, y });
monster.position.temp = { x, y };
monster.position.old = monster.position.tile;
monster.position.future = { fx, fy };
monster.occupyTile(monster.position.tile, true);
monster.occupyTile(monster.position.future, false);
monster.mode = MonsterMode::MoveSideways;
monster.var1 = fx;
monster.var2 = fy;
monster.var3 = static_cast<int>(endDir);
NewMonsterAnim(monster, MonsterGraphic::Walk, endDir, AnimationDistributionFlags::ProcessAnimationPending, -1);
}
void StartAttack(Monster &monster)
{
Direction md = GetMonsterDirection(monster);
@ -3954,28 +3932,28 @@ bool Walk(Monster &monster, Direction md)
switch (md) {
case Direction::North:
WalkNonSideways(monster, -1, -1, Direction::North);
Walk(monster, -1, -1, Direction::North);
break;
case Direction::NorthEast:
WalkNonSideways(monster, 0, -1, Direction::NorthEast);
Walk(monster, 0, -1, Direction::NorthEast);
break;
case Direction::East:
WalkSideways(monster, -32, -16, 1, -1, 1, 0, Direction::East);
Walk(monster, 1, -1, Direction::East);
break;
case Direction::SouthEast:
WalkNonSideways(monster, 1, 0, Direction::SouthEast);
Walk(monster, 1, 0, Direction::SouthEast);
break;
case Direction::South:
WalkNonSideways(monster, 1, 1, Direction::South);
Walk(monster, 1, 1, Direction::South);
break;
case Direction::SouthWest:
WalkNonSideways(monster, 0, 1, Direction::SouthWest);
Walk(monster, 0, 1, Direction::SouthWest);
break;
case Direction::West:
WalkSideways(monster, 32, -16, -1, 1, 0, 1, Direction::West);
Walk(monster, -1, 1, Direction::West);
break;
case Direction::NorthWest:
WalkNonSideways(monster, -1, 0, Direction::NorthWest);
Walk(monster, -1, 0, Direction::NorthWest);
break;
case Direction::NoDirection:
break;

34
Source/player.cpp

@ -61,7 +61,6 @@ namespace {
struct DirectionSettings {
Direction dir;
DisplacementOf<int8_t> tileAdd;
DisplacementOf<int8_t> map;
PLR_MODE walkMode;
void (*walkModeHandler)(Player &, const DirectionSettings &);
};
@ -75,37 +74,22 @@ void UpdatePlayerLightOffset(Player &player)
ChangeLightOffset(player.lightId, offset.screenToLight());
}
void WalkNonSideways(Player &player, const DirectionSettings &walkParams)
void Walk(Player &player, const DirectionSettings &walkParams)
{
player.occupyTile(player.position.future, true);
player.position.temp = player.position.tile + walkParams.tileAdd;
}
void WalkSideways(Player &player, const DirectionSettings &walkParams)
{
Point const nextPosition = player.position.tile + walkParams.map;
player.occupyTile(player.position.tile, true);
player.occupyTile(player.position.future, false);
if (leveltype != DTYPE_TOWN) {
ChangeLightXY(player.lightId, nextPosition);
UpdatePlayerLightOffset(player);
}
player.position.temp = player.position.future;
}
constexpr std::array<const DirectionSettings, 8> WalkSettings { {
// clang-format off
{ Direction::South, { 1, 1 }, { 0, 0 }, PM_WALK_SOUTHWARDS, WalkNonSideways },
{ Direction::SouthWest, { 0, 1 }, { 0, 0 }, PM_WALK_SOUTHWARDS, WalkNonSideways },
{ Direction::West, { -1, 1 }, { 0, 1 }, PM_WALK_SIDEWAYS, WalkSideways },
{ Direction::NorthWest, { -1, 0 }, { 0, 0 }, PM_WALK_NORTHWARDS, WalkNonSideways },
{ Direction::North, { -1, -1 }, { 0, 0 }, PM_WALK_NORTHWARDS, WalkNonSideways },
{ Direction::NorthEast, { 0, -1 }, { 0, 0 }, PM_WALK_NORTHWARDS, WalkNonSideways },
{ Direction::East, { 1, -1 }, { 1, 0 }, PM_WALK_SIDEWAYS, WalkSideways },
{ Direction::SouthEast, { 1, 0 }, { 0, 0 }, PM_WALK_SOUTHWARDS, WalkNonSideways }
{ Direction::South, { 1, 1 }, PM_WALK_SOUTHWARDS, Walk },
{ Direction::SouthWest, { 0, 1 }, PM_WALK_SOUTHWARDS, Walk },
{ Direction::West, { -1, 1 }, PM_WALK_SIDEWAYS, Walk },
{ Direction::NorthWest, { -1, 0 }, PM_WALK_NORTHWARDS, Walk },
{ Direction::North, { -1, -1 }, PM_WALK_NORTHWARDS, Walk },
{ Direction::NorthEast, { 0, -1 }, PM_WALK_NORTHWARDS, Walk },
{ Direction::East, { 1, -1 }, PM_WALK_SIDEWAYS, Walk },
{ Direction::SouthEast, { 1, 0 }, PM_WALK_SOUTHWARDS, Walk }
// clang-format on
} };

Loading…
Cancel
Save