Skip to content

Commit

Permalink
Rename Player struct variables: plrlevel
Browse files Browse the repository at this point in the history
  • Loading branch information
kphoenix137 committed Jul 27, 2024
1 parent 5ae0e5e commit b4cd485
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 33 deletions.
12 changes: 6 additions & 6 deletions Source/interfac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Cutscenes PickCutscene(interface_mode uMsg)
case WM_DIABPREVLVL:
case WM_DIABTOWNWARP:
case WM_DIABTWARPUP: {
int lvl = MyPlayer->plrlevel;
int lvl = MyPlayer->dungeonLevel;
if (lvl == 1 && uMsg == WM_DIABNEXTLVL)
return CutTown;
if (lvl == 16 && uMsg == WM_DIABNEXTLVL)
Expand Down Expand Up @@ -358,7 +358,7 @@ void ShowProgress(interface_mode uMsg)
IncProgress();
FreeGameMem();
setlevel = false;
currlevel = myPlayer.plrlevel;
currlevel = myPlayer.dungeonLevel;
leveltype = GetLevelType(currlevel);
IncProgress();
LoadGameLevel(false, ENTRY_MAIN);
Expand Down Expand Up @@ -440,7 +440,7 @@ void ShowProgress(interface_mode uMsg)
IncProgress();
FreeGameMem();
setlevel = false;
currlevel = myPlayer.plrlevel;
currlevel = myPlayer.dungeonLevel;
leveltype = GetLevelType(currlevel);
IncProgress();
LoadGameLevel(false, ENTRY_TWARPDN);
Expand All @@ -455,7 +455,7 @@ void ShowProgress(interface_mode uMsg)
}
IncProgress();
FreeGameMem();
currlevel = myPlayer.plrlevel;
currlevel = myPlayer.dungeonLevel;
leveltype = GetLevelType(currlevel);
IncProgress();
LoadGameLevel(false, ENTRY_TWARPUP);
Expand All @@ -471,7 +471,7 @@ void ShowProgress(interface_mode uMsg)
IncProgress();
FreeGameMem();
setlevel = false;
currlevel = myPlayer.plrlevel;
currlevel = myPlayer.dungeonLevel;
leveltype = GetLevelType(currlevel);
IncProgress();
LoadGameLevel(false, ENTRY_MAIN);
Expand Down Expand Up @@ -500,7 +500,7 @@ void ShowProgress(interface_mode uMsg)
assert(previousHandler == DisableInputEventHandler);
IsProgress = false;

NetSendCmdLocParam2(true, CMD_PLAYER_JOINLEVEL, myPlayer.position.tile, myPlayer.plrlevel, myPlayer.plrIsOnSetLevel ? 1 : 0);
NetSendCmdLocParam2(true, CMD_PLAYER_JOINLEVEL, myPlayer.position.tile, myPlayer.dungeonLevel, myPlayer.plrIsOnSetLevel ? 1 : 0);
DelayPlrMessages(SDL_GetTicks() - delayStart);

if (gbSomebodyWonGameKludge && myPlayer.isOnLevel(16)) {
Expand Down
4 changes: 2 additions & 2 deletions Source/loadsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ void LoadPlayer(LoadHelper &file, Player &player)
// Omit pointer _pBData
// Omit pointer pReserved

// Ensure plrIsOnSetLevel and plrlevel is correctly initialized, cause in vanilla sometimes plrlevel is not updated to setlvlnum
// Ensure plrIsOnSetLevel and dungeonLevel is correctly initialized, cause in vanilla sometimes dungeonLevel is not updated to setlvlnum
if (setlevel)
player.setLevel(setlvlnum);
else
Expand Down Expand Up @@ -1171,7 +1171,7 @@ void SavePlayer(SaveHelper &file, const Player &player)
file.WriteLE<int32_t>(player.destParam2);
file.WriteLE<int32_t>(static_cast<int32_t>(player.destParam3));
file.WriteLE<int32_t>(player.destParam4);
file.WriteLE<uint32_t>(player.plrlevel);
file.WriteLE<uint32_t>(player.dungeonLevel);
file.WriteLE<int32_t>(player.position.tile.x);
file.WriteLE<int32_t>(player.position.tile.y);
file.WriteLE<int32_t>(player.position.future.x);
Expand Down
2 changes: 1 addition & 1 deletion Source/lua/modules/dev/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ std::string DebugCmdPlayerInfo(std::optional<uint8_t> id)

const Point target = player.GetTargetPosition();
return StrCat("Plr ", playerId, " is ", player._pName,
"\nLvl: ", player.plrlevel, " Changing: ", player._pLvlChanging,
"\nLvl: ", player.dungeonLevel, " Changing: ", player._pLvlChanging,
"\nTile.x: ", player.position.tile.x, " Tile.y: ", player.position.tile.y, " Target.x: ", target.x, " Target.y: ", target.y,
"\nMode: ", player._pmode, " destAction: ", player.destAction, " walkpath[0]: ", player.walkpath[0],
"\nInvincible: ", player._pInvincible ? 1 : 0, " HitPoints: ", player._pHitPoints);
Expand Down
4 changes: 2 additions & 2 deletions Source/msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ size_t OnKillGolem(const TCmd *pCmd, Player &player)
Monster &monster = Monsters[player.getId()];
if (player.isOnActiveLevel())
M_SyncStartKill(monster, position, player);
delta_kill_monster(monster, position, player); // BUGFIX: should be p->wParam1, plrlevel will be incorrect if golem is killed because player changed levels
delta_kill_monster(monster, position, player); // BUGFIX: should be p->wParam1, dungeonLevel will be incorrect if golem is killed because player changed levels
}
} else {
SendPacket(player, &message, sizeof(message));
Expand Down Expand Up @@ -2672,7 +2672,7 @@ void DeltaSaveLevel()

uint8_t GetLevelForMultiplayer(const Player &player)
{
return GetLevelForMultiplayer(player.plrlevel, player.plrIsOnSetLevel);
return GetLevelForMultiplayer(player.dungeonLevel, player.plrIsOnSetLevel);
}

bool IsValidLevelForMultiplayer(uint8_t level)
Expand Down
2 changes: 1 addition & 1 deletion Source/multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ bool IsNetPlayerValid(const Player &player)
// we no longer check character level here, players with out-of-range clevels are not allowed to join the game and we don't observe change clevel messages that would set it out of range
// (there's no code path that would result in _pLevel containing an out of range value in the DevilutionX code)
return static_cast<uint8_t>(player._pClass) < enum_size<HeroClass>::value
&& player.plrlevel < NUMLEVELS
&& player.dungeonLevel < NUMLEVELS
&& InDungeonBounds(player.position.tile)
&& !std::string_view(player._pName).empty();
}
Expand Down
10 changes: 5 additions & 5 deletions Source/pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void PackPlayer(PlayerPack &packed, const Player &player)
packed.destAction = player.destAction;
packed.destParam1 = player.destParam1;
packed.destParam2 = player.destParam2;
packed.plrlevel = player.plrlevel;
packed.dungeonLevel = player.dungeonLevel;
packed.px = player.position.tile.x;
packed.py = player.position.tile.y;
if (gbVanilla) {
Expand Down Expand Up @@ -316,7 +316,7 @@ void PackNetItem(const Item &item, ItemNetPack &packedItem)

void PackNetPlayer(PlayerNetPack &packed, const Player &player)
{
packed.plrlevel = player.plrlevel;
packed.dungeonLevel = player.dungeonLevel;
packed.px = player.position.tile.x;
packed.py = player.position.tile.y;
CopyUtf8(packed.pName, player._pName, sizeof(packed.pName));
Expand Down Expand Up @@ -454,7 +454,7 @@ void UnPackPlayer(const PlayerPack &packed, Player &player)
player._pHitPoints = player._pHPBase;
player.position.tile = position;
player.position.future = position;
player.setLevel(std::clamp<int8_t>(packed.plrlevel, 0, NUMLEVELS));
player.setLevel(std::clamp<int8_t>(packed.dungeonLevel, 0, NUMLEVELS));

player._pClass = static_cast<HeroClass>(std::clamp<uint8_t>(packed.pClass, 0, enum_size<HeroClass>::value - 1));

Expand Down Expand Up @@ -566,7 +566,7 @@ bool UnPackNetPlayer(const PlayerNetPack &packed, Player &player)

Point position { packed.px, packed.py };
ValidateFields(position.x, position.y, InDungeonBounds(position));
ValidateField(packed.plrlevel, packed.plrlevel < NUMLEVELS);
ValidateField(packed.dungeonLevel, packed.dungeonLevel < NUMLEVELS);
ValidateField(packed.pLevel, packed.pLevel >= 1 && packed.pLevel <= player.getMaxCharacterLevel());

int32_t baseHpMax = SDL_SwapLE32(packed.pMaxHPBase);
Expand All @@ -588,7 +588,7 @@ bool UnPackNetPlayer(const PlayerNetPack &packed, Player &player)
player.setCharacterLevel(packed.pLevel);
player.position.tile = position;
player.position.future = position;
player.plrlevel = packed.plrlevel;
player.dungeonLevel = packed.dungeonLevel;
player.plrIsOnSetLevel = packed.isOnSetLevel != 0;
player._pMaxHPBase = baseHpMax;
player._pHPBase = baseHp;
Expand Down
4 changes: 2 additions & 2 deletions Source/pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct PlayerPack {
int8_t destAction;
int8_t destParam1;
int8_t destParam2;
uint8_t plrlevel;
uint8_t dungeonLevel;
uint8_t px;
uint8_t py;
uint8_t targx;
Expand Down Expand Up @@ -86,7 +86,7 @@ union ItemNetPack {
};

struct PlayerNetPack {
uint8_t plrlevel;
uint8_t dungeonLevel;
uint8_t px;
uint8_t py;
char pName[PlayerNameLength];
Expand Down
4 changes: 2 additions & 2 deletions Source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void InitLevelChange(Player &player)
if (&player == MyPlayer) {
player.occupyTile(player.position.tile, false);
} else {
player._pLvlVisited[player.plrlevel] = true;
player._pLvlVisited[player.dungeonLevel] = true;
}

ClrPlrPath(player);
Expand Down Expand Up @@ -2046,7 +2046,7 @@ bool Player::isLevelOwnedByLocalClient() const
continue;
if (other._pmode == PM_NEWLVL)
continue;
if (other.plrlevel != this->plrlevel)
if (other.dungeonLevel != this->dungeonLevel)
continue;
if (other.plrIsOnSetLevel != this->plrIsOnSetLevel)
continue;
Expand Down
12 changes: 6 additions & 6 deletions Source/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ struct Player {
int8_t _pBFrames;
int8_t InvGrid[InventoryGridCells];

uint8_t plrlevel;
uint8_t dungeonLevel; // plrlevel
bool plrIsOnSetLevel;
ActorPosition position;
Direction _pdir; // Direction faced by player (direction enum)
Expand Down Expand Up @@ -856,26 +856,26 @@ struct Player {
/** @brief Checks if the player is on the corresponding level. */
bool isOnLevel(uint8_t level) const
{
return !this->plrIsOnSetLevel && this->plrlevel == level;
return !this->plrIsOnSetLevel && this->dungeonLevel == level;
}
/** @brief Checks if the player is on the corresponding level. */
bool isOnLevel(_setlevels level) const
{
return this->plrIsOnSetLevel && this->plrlevel == static_cast<uint8_t>(level);
return this->plrIsOnSetLevel && this->dungeonLevel == static_cast<uint8_t>(level);
}
/** @brief Checks if the player is on a arena level. */
bool isOnArenaLevel() const
{
return plrIsOnSetLevel && IsArenaLevel(static_cast<_setlevels>(plrlevel));
return plrIsOnSetLevel && IsArenaLevel(static_cast<_setlevels>(dungeonLevel));
}
void setLevel(uint8_t level)
{
this->plrlevel = level;
this->dungeonLevel = level;
this->plrIsOnSetLevel = false;
}
void setLevel(_setlevels level)
{
this->plrlevel = static_cast<uint8_t>(level);
this->dungeonLevel = static_cast<uint8_t>(level);
this->plrIsOnSetLevel = true;
}

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/memory_map/hero.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ R 32 dwHighDateTime
R 8 destAction
R 8 destParam1
R 8 destParam2
R 8 plrlevel
R 8 dungeonLevel
R 8 px
R 8 py
R 8 targx
Expand Down
4 changes: 2 additions & 2 deletions test/pack_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,9 +1004,9 @@ TEST_F(NetPackTest, UnPackNetPlayer_invalid_oob)
ASSERT_FALSE(TestNetPackValidation());
}

TEST_F(NetPackTest, UnPackNetPlayer_invalid_plrlevel)
TEST_F(NetPackTest, UnPackNetPlayer_invalid_dungeonLevel)
{
MyPlayer->plrlevel = NUMLEVELS;
MyPlayer->dungeonLevel = NUMLEVELS;
ASSERT_FALSE(TestNetPackValidation());
}

Expand Down
2 changes: 1 addition & 1 deletion test/player_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static void AssertPlayer(Player &player)
ASSERT_EQ(player.position.tile.y, 0);
ASSERT_EQ(player.position.future.x, 0);
ASSERT_EQ(player.position.future.y, 0);
ASSERT_EQ(player.plrlevel, 0);
ASSERT_EQ(player.dungeonLevel, 0);
ASSERT_EQ(player.destAction, 0);
ASSERT_STREQ(player._pName, "");
ASSERT_EQ(player._pClass, HeroClass::Rogue);
Expand Down
4 changes: 2 additions & 2 deletions test/writehero_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void PackPlayerTest(PlayerPack *pPack)
pPack->destAction = -1;
pPack->destParam1 = 0;
pPack->destParam2 = 0;
pPack->plrlevel = 0;
pPack->dungeonLevel = 0;
pPack->pExperience = 1583495809;
pPack->pLevel = 50;
pPack->px = 75;
Expand Down Expand Up @@ -269,7 +269,7 @@ void AssertPlayer(Player &player)
ASSERT_EQ(player.position.tile.y, 68);
ASSERT_EQ(player.position.future.x, 75);
ASSERT_EQ(player.position.future.y, 68);
ASSERT_EQ(player.plrlevel, 0);
ASSERT_EQ(player.dungeonLevel, 0);
ASSERT_EQ(player.destAction, -1);
ASSERT_STREQ(player._pName, "TestPlayer");
ASSERT_EQ(player._pClass, HeroClass::Rogue);
Expand Down

0 comments on commit b4cd485

Please sign in to comment.