Browse Source

Remove _pVar5 and most uses of BFLAG_PLAYERLR

pull/2891/head
obligaron 5 years ago committed by Anders Jenbo
parent
commit
c3c91f6e28
  1. 8
      Source/loadsave.cpp
  2. 24
      Source/player.cpp
  3. 4
      Source/player.h

8
Source/loadsave.cpp

@ -416,7 +416,7 @@ void LoadPlayer(LoadHelper &file, Player &player)
player.position.temp.y = file.NextLE<int32_t>();
player.tempDirection = static_cast<Direction>(file.NextLE<int32_t>());
player._pVar4 = file.NextLE<int32_t>();
player._pVar5 = file.NextLE<int32_t>();
file.Skip(4); // skip _pVar5, was used for storing position of a tile which should have its BFLAG_PLAYERLR flag removed after walking
player.position.offset2.deltaX = file.NextLE<int32_t>();
player.position.offset2.deltaY = file.NextLE<int32_t>();
file.Skip(4); // Skip actionFrame
@ -1091,7 +1091,7 @@ void SavePlayer(SaveHelper &file, const Player &player)
file.WriteLE<int32_t>(player.position.temp.y);
file.WriteLE<int32_t>(static_cast<int32_t>(player.tempDirection));
file.WriteLE<int32_t>(player._pVar4);
file.WriteLE<int32_t>(player._pVar5);
file.Skip<int32_t>(); // skip _pVar5, was used for storing position of a tile which should have its BFLAG_PLAYERLR flag removed after walking
file.WriteLE<int32_t>(player.position.offset2.deltaX);
file.WriteLE<int32_t>(player.position.offset2.deltaY);
file.Skip<int32_t>(); // Skip _pVar8
@ -1772,7 +1772,7 @@ void LoadGame(bool firstflag)
}
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) // NOLINT(modernize-loop-convert)
dFlags[i][j] = file.NextLE<int8_t>();
dFlags[i][j] = file.NextLE<int8_t>() & ~BFLAG_PLAYERLR;
}
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) // NOLINT(modernize-loop-convert)
@ -2159,7 +2159,7 @@ void LoadLevel()
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) // NOLINT(modernize-loop-convert)
dFlags[i][j] = file.NextLE<int8_t>();
dFlags[i][j] = file.NextLE<int8_t>() & ~BFLAG_PLAYERLR;
}
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) // NOLINT(modernize-loop-convert)

24
Source/player.cpp

@ -270,9 +270,6 @@ void WalkSides(int pnum, const DirectionSettings &walkParams)
dPlayer[player.position.tile.x][player.position.tile.y] = -(pnum + 1);
dPlayer[player.position.future.x][player.position.future.y] = pnum + 1;
player._pVar4 = nextPosition.x;
player._pVar5 = nextPosition.y;
dFlags[nextPosition.x][nextPosition.y] |= BFLAG_PLAYERLR;
if (leveltype != DTYPE_TOWN) {
ChangeLightXY(player._plid, nextPosition);
@ -332,11 +329,11 @@ bool PlrDirOK(const Player &player, Direction dir)
}
if (dir == Direction::East) {
return !IsTileSolid(position + Direction::SouthEast) && (dFlags[position.x + 1][position.y] & BFLAG_PLAYERLR) == 0;
return !IsTileSolid(position + Direction::SouthEast);
}
if (dir == Direction::West) {
return !IsTileSolid(position + Direction::SouthWest) && (dFlags[position.x][position.y + 1] & BFLAG_PLAYERLR) == 0;
return !IsTileSolid(position + Direction::SouthWest);
}
return true;
@ -411,7 +408,6 @@ void ClearStateVariables(Player &player)
player.position.temp = { 0, 0 };
player.tempDirection = Direction::South;
player._pVar4 = 0;
player._pVar5 = 0;
player.position.offset2 = { 0, 0 };
player.deathFrame = 0;
}
@ -730,7 +726,6 @@ bool DoWalk(int pnum, int variant)
break;
case PM_WALK3:
dPlayer[player.position.tile.x][player.position.tile.y] = 0;
dFlags[player._pVar4][player._pVar5] &= ~BFLAG_PLAYERLR;
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.
dPlayer[player.position.tile.x][player.position.tile.y] = pnum + 1;
@ -2921,11 +2916,6 @@ void FixPlrWalkTags(int pnum)
}
}
}
if (dx >= 0 && dx < MAXDUNX - 1 && dy >= 0 && dy < MAXDUNY - 1) {
dFlags[dx + 1][dy] &= ~BFLAG_PLAYERLR;
dFlags[dx][dy + 1] &= ~BFLAG_PLAYERLR;
}
}
void RemovePlrFromMap(int pnum)
@ -2933,16 +2923,6 @@ void RemovePlrFromMap(int pnum)
int pp = pnum + 1;
int pn = -(pnum + 1);
for (int y = 1; y < MAXDUNY; y++) {
for (int x = 1; x < MAXDUNX; x++) {
if (dPlayer[x][y - 1] == pn || dPlayer[x - 1][y] == pn) {
if ((dFlags[x][y] & BFLAG_PLAYERLR) != 0) {
dFlags[x][y] &= ~BFLAG_PLAYERLR;
}
}
}
}
for (int y = 0; y < MAXDUNY; y++) {
for (int x = 0; x < MAXDUNX; x++) // NOLINT(modernize-loop-convert)
if (dPlayer[x][y] == pp || dPlayer[x][y] == pn)

4
Source/player.h

@ -242,10 +242,8 @@ struct Player {
bool _pInfraFlag;
/** Player's direction when ending movement. Also used for casting direction of SPL_FIREWALL. */
Direction tempDirection;
/** Used for spell level, and X component of _pVar5 */
/** Used for spell level */
int _pVar4;
/** Used for storing position of a tile which should have its BFLAG_PLAYERLR flag removed after walking. When starting to walk the game places the player in the dPlayer array -1 in the Y coordinate, and uses BFLAG_PLAYERLR to check if it should be using -1 to the Y coordinate when rendering the player (also used for storing the level of a spell when the player casts it) */
int _pVar5;
/** Used for stalling the appearance of the options screen after dying in singleplayer */
int deathFrame;
bool _pLvlVisited[NUMLEVELS];

Loading…
Cancel
Save