Browse Source

Normalise the player and monster walking function naming (#4877)

Both player and monster walking functions are not named WalkNorthwards, WalkSouthwards and WalkSideways.

Also renames the PLT_MODE enum to follow the same pattern and removes the comments that are now unnecessary
pull/4879/head
Cesar Canassa 4 years ago committed by GitHub
parent
commit
6579aa53c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      Source/automap.cpp
  2. 6
      Source/inv.cpp
  3. 22
      Source/monster.cpp
  4. 42
      Source/player.cpp
  5. 6
      Source/player.h

4
Source/automap.cpp

@ -347,7 +347,7 @@ void SearchAutomapItem(const Surface &out, const Displacement &myPlayerOffset)
{
const Player &player = *MyPlayer;
Point tile = player.position.tile;
if (player._pmode == PM_WALK3) {
if (player._pmode == PM_WALK_SIDEWAYS) {
tile = player.position.future;
if (player._pdir == Direction::West)
tile.x++;
@ -395,7 +395,7 @@ void DrawAutomapPlr(const Surface &out, const Displacement &myPlayerOffset, int
Player &player = Players[playerId];
Point tile = player.position.tile;
if (player._pmode == PM_WALK3) {
if (player._pmode == PM_WALK_SIDEWAYS) {
tile = player.position.future;
}

6
Source/inv.cpp

@ -236,7 +236,7 @@ bool CanWield(Player &player, const Item &item)
*/
bool CanEquip(Player &player, const Item &item, inv_body_loc bodyLocation)
{
if (!CanEquip(item) || player._pmode > PM_WALK3 || !player.InvBody[bodyLocation].isEmpty()) {
if (!CanEquip(item) || player._pmode > PM_WALK_SIDEWAYS || !player.InvBody[bodyLocation].isEmpty()) {
return false;
}
@ -402,7 +402,7 @@ void CheckInvPaste(Player &player, Point cursorPosition)
return;
}
if (player._pmode > PM_WALK3 && IsNoneOf(il, ILOC_UNEQUIPABLE, ILOC_BELT))
if (player._pmode > PM_WALK_SIDEWAYS && IsNoneOf(il, ILOC_UNEQUIPABLE, ILOC_BELT))
return;
if (&player == MyPlayer)
@ -566,7 +566,7 @@ void CheckInvPaste(Player &player, Point cursorPosition)
void CheckInvCut(Player &player, Point cursorPosition, bool automaticMove, bool dropItem)
{
if (player._pmode > PM_WALK3) {
if (player._pmode > PM_WALK_SIDEWAYS) {
return;
}

22
Source/monster.cpp

@ -808,7 +808,7 @@ void StartSpecialStand(Monster &monster, Direction md)
monster.position.old = monster.position.tile;
}
void StartWalkNorthwards(Monster &monster, int xvel, int yvel, int xadd, int yadd, Direction endDir)
void WalkNorthwards(Monster &monster, int xvel, int yvel, 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);
@ -825,7 +825,7 @@ void StartWalkNorthwards(Monster &monster, int xvel, int yvel, int xadd, int yad
monster.position.offset2 = { 0, 0 };
}
void StartWalkSouthwards(Monster &monster, int xvel, int yvel, int xoff, int yoff, int xadd, int yadd, Direction endDir)
void WalkSouthwards(Monster &monster, int xvel, int yvel, int xoff, int yoff, 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);
@ -847,7 +847,7 @@ void StartWalkSouthwards(Monster &monster, int xvel, int yvel, int xoff, int yof
monster.position.offset2 = DisplacementOf<int16_t> { static_cast<int16_t>(16 * xoff), static_cast<int16_t>(16 * yoff) };
}
void StartWalkSideways(Monster &monster, int xvel, int yvel, int xoff, int yoff, int xadd, int yadd, int mapx, int mapy, Direction endDir)
void WalkSideways(Monster &monster, int xvel, int yvel, 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);
@ -4076,28 +4076,28 @@ void M_WalkDir(Monster &monster, Direction md)
int mwi = monster.type().getAnimData(MonsterGraphic::Walk).frames - 1;
switch (md) {
case Direction::North:
StartWalkNorthwards(monster, 0, -MWVel[mwi][1], -1, -1, Direction::North);
WalkNorthwards(monster, 0, -MWVel[mwi][1], -1, -1, Direction::North);
break;
case Direction::NorthEast:
StartWalkNorthwards(monster, MWVel[mwi][1], -MWVel[mwi][0], 0, -1, Direction::NorthEast);
WalkNorthwards(monster, MWVel[mwi][1], -MWVel[mwi][0], 0, -1, Direction::NorthEast);
break;
case Direction::East:
StartWalkSideways(monster, MWVel[mwi][2], 0, -32, -16, 1, -1, 1, 0, Direction::East);
WalkSideways(monster, MWVel[mwi][2], 0, -32, -16, 1, -1, 1, 0, Direction::East);
break;
case Direction::SouthEast:
StartWalkSouthwards(monster, MWVel[mwi][1], MWVel[mwi][0], -32, -16, 1, 0, Direction::SouthEast);
WalkSouthwards(monster, MWVel[mwi][1], MWVel[mwi][0], -32, -16, 1, 0, Direction::SouthEast);
break;
case Direction::South:
StartWalkSouthwards(monster, 0, MWVel[mwi][1], 0, -32, 1, 1, Direction::South);
WalkSouthwards(monster, 0, MWVel[mwi][1], 0, -32, 1, 1, Direction::South);
break;
case Direction::SouthWest:
StartWalkSouthwards(monster, -MWVel[mwi][1], MWVel[mwi][0], 32, -16, 0, 1, Direction::SouthWest);
WalkSouthwards(monster, -MWVel[mwi][1], MWVel[mwi][0], 32, -16, 0, 1, Direction::SouthWest);
break;
case Direction::West:
StartWalkSideways(monster, -MWVel[mwi][2], 0, 32, -16, -1, 1, 0, 1, Direction::West);
WalkSideways(monster, -MWVel[mwi][2], 0, 32, -16, -1, 1, 0, 1, Direction::West);
break;
case Direction::NorthWest:
StartWalkNorthwards(monster, -MWVel[mwi][1], -MWVel[mwi][0], -1, 0, Direction::NorthWest);
WalkNorthwards(monster, -MWVel[mwi][1], -MWVel[mwi][0], -1, 0, Direction::NorthWest);
break;
}
}

42
Source/player.cpp

@ -219,14 +219,14 @@ void PmChangeLightOff(Player &player)
ChangeLightOffset(player._plid, { x, y });
}
void WalkUpwards(int pnum, const DirectionSettings &walkParams)
void WalkNorthwards(int pnum, const DirectionSettings &walkParams)
{
Player &player = Players[pnum];
dPlayer[player.position.future.x][player.position.future.y] = -(pnum + 1);
player.position.temp = WorldTilePosition { static_cast<WorldTileCoord>(walkParams.tileAdd.deltaX), static_cast<WorldTileCoord>(walkParams.tileAdd.deltaY) };
}
void WalkDownwards(int pnum, const DirectionSettings & /*walkParams*/)
void WalkSouthwards(int pnum, const DirectionSettings & /*walkParams*/)
{
Player &player = Players[pnum];
dPlayer[player.position.tile.x][player.position.tile.y] = -(pnum + 1);
@ -238,7 +238,7 @@ void WalkDownwards(int pnum, const DirectionSettings & /*walkParams*/)
PmChangeLightOff(player);
}
void WalkSides(int pnum, const DirectionSettings &walkParams)
void WalkSideways(int pnum, const DirectionSettings &walkParams)
{
Player &player = Players[pnum];
@ -268,14 +268,14 @@ _sfx_id herosounds[enum_size<HeroClass>::value][enum_size<HeroSpeech>::value] =
constexpr std::array<const DirectionSettings, 8> WalkSettings { {
// clang-format off
{ Direction::South, { 1, 1 }, { 0, -32 }, { 0, 0 }, ScrollDirection::South, PM_WALK2, WalkDownwards },
{ Direction::SouthWest, { 0, 1 }, { 32, -16 }, { 0, 0 }, ScrollDirection::SouthWest, PM_WALK2, WalkDownwards },
{ Direction::West, { -1, 1 }, { 32, -16 }, { 0, 1 }, ScrollDirection::West, PM_WALK3, WalkSides },
{ Direction::NorthWest, { -1, 0 }, { 0, 0 }, { 0, 0 }, ScrollDirection::NorthWest, PM_WALK, WalkUpwards },
{ Direction::North, { -1, -1 }, { 0, 0 }, { 0, 0 }, ScrollDirection::North, PM_WALK, WalkUpwards },
{ Direction::NorthEast, { 0, -1 }, { 0, 0 }, { 0, 0 }, ScrollDirection::NorthEast, PM_WALK, WalkUpwards },
{ Direction::East, { 1, -1 }, { -32, -16 }, { 1, 0 }, ScrollDirection::East, PM_WALK3, WalkSides },
{ Direction::SouthEast, { 1, 0 }, { -32, -16 }, { 0, 0 }, ScrollDirection::SouthEast, PM_WALK2, WalkDownwards }
{ Direction::South, { 1, 1 }, { 0, -32 }, { 0, 0 }, ScrollDirection::South, PM_WALK_SOUTHWARDS, WalkSouthwards },
{ Direction::SouthWest, { 0, 1 }, { 32, -16 }, { 0, 0 }, ScrollDirection::SouthWest, PM_WALK_SOUTHWARDS, WalkSouthwards },
{ Direction::West, { -1, 1 }, { 32, -16 }, { 0, 1 }, ScrollDirection::West, PM_WALK_SIDEWAYS, WalkSideways },
{ Direction::NorthWest, { -1, 0 }, { 0, 0 }, { 0, 0 }, ScrollDirection::NorthWest, PM_WALK_NORTHWARDS, WalkNorthwards },
{ Direction::North, { -1, -1 }, { 0, 0 }, { 0, 0 }, ScrollDirection::North, PM_WALK_NORTHWARDS, WalkNorthwards },
{ Direction::NorthEast, { 0, -1 }, { 0, 0 }, { 0, 0 }, ScrollDirection::NorthEast, PM_WALK_NORTHWARDS, WalkNorthwards },
{ Direction::East, { 1, -1 }, { -32, -16 }, { 1, 0 }, ScrollDirection::East, PM_WALK_SIDEWAYS, WalkSideways },
{ Direction::SouthEast, { 1, 0 }, { -32, -16 }, { 0, 0 }, ScrollDirection::SouthEast, PM_WALK_SOUTHWARDS, WalkSouthwards }
// clang-format on
} };
@ -670,15 +670,15 @@ bool DoWalk(int pnum, int variant)
// Update the player's tile position
switch (variant) {
case PM_WALK:
case PM_WALK_NORTHWARDS:
dPlayer[player.position.tile.x][player.position.tile.y] = 0;
player.position.tile += { player.position.temp.x, player.position.temp.y };
dPlayer[player.position.tile.x][player.position.tile.y] = pnum + 1;
break;
case PM_WALK2:
case PM_WALK_SOUTHWARDS:
dPlayer[player.position.temp.x][player.position.temp.y] = 0;
break;
case PM_WALK3:
case PM_WALK_SIDEWAYS:
dPlayer[player.position.tile.x][player.position.tile.y] = 0;
player.position.tile = player.position.temp;
// dPlayer is set here for backwards comparability, without it the player would be invisible if loaded from a vanilla save.
@ -2010,7 +2010,7 @@ void Player::Stop()
bool Player::IsWalking() const
{
return IsAnyOf(_pmode, PM_WALK, PM_WALK2, PM_WALK3);
return IsAnyOf(_pmode, PM_WALK_NORTHWARDS, PM_WALK_SOUTHWARDS, PM_WALK_SIDEWAYS);
}
void Player::Reset()
@ -3367,9 +3367,9 @@ void ProcessPlayers()
case PM_QUIT:
tplayer = false;
break;
case PM_WALK:
case PM_WALK2:
case PM_WALK3:
case PM_WALK_NORTHWARDS:
case PM_WALK_SOUTHWARDS:
case PM_WALK_SIDEWAYS:
tplayer = DoWalk(pnum, player._pmode);
break;
case PM_ATTACK:
@ -3570,9 +3570,9 @@ void SyncPlrAnim(Player &player)
case PM_QUIT:
graphic = player_graphic::Stand;
break;
case PM_WALK:
case PM_WALK2:
case PM_WALK3:
case PM_WALK_NORTHWARDS:
case PM_WALK_SOUTHWARDS:
case PM_WALK_SIDEWAYS:
graphic = player_graphic::Walk;
break;
case PM_ATTACK:

6
Source/player.h

@ -115,9 +115,9 @@ enum class PlayerWeaponGraphic : uint8_t {
enum PLR_MODE : uint8_t {
PM_STAND,
PM_WALK, // Movement towards N, NW, or NE
PM_WALK2, // Movement towards S, SW, or SE
PM_WALK3, // Movement towards W or E
PM_WALK_NORTHWARDS,
PM_WALK_SOUTHWARDS,
PM_WALK_SIDEWAYS,
PM_ATTACK,
PM_RATTACK,
PM_BLOCK,

Loading…
Cancel
Save