Browse Source

Clean up some players references

pull/2752/head
Anders Jenbo 5 years ago
parent
commit
4044fadeb5
  1. 13
      Source/control.cpp
  2. 2
      Source/debug.cpp
  3. 21
      Source/diablo.cpp
  4. 18
      Source/inv.cpp
  5. 4
      Source/inv.h
  6. 82
      Source/items.cpp
  7. 19
      Source/items.h
  8. 43
      Source/loadsave.cpp
  9. 2
      Source/menu.cpp
  10. 15
      Source/missiles.cpp
  11. 16
      Source/msg.cpp
  12. 4
      Source/multi.cpp
  13. 2
      Source/objects.cpp
  14. 10
      Source/pack.cpp
  15. 2
      Source/pack.h
  16. 12
      Source/pfile.cpp
  17. 2
      Source/pfile.h
  18. 148
      Source/player.cpp
  19. 14
      Source/player.h
  20. 4
      Source/spells.cpp
  21. 23
      Source/stores.cpp
  22. 2
      test/writehero_test.cpp

13
Source/control.cpp

@ -571,10 +571,8 @@ void ControlUpDown(int v)
}
}
void RemoveGold(int pnum, int goldIndex)
void RemoveGold(PlayerStruct &player, int goldIndex)
{
auto &player = Players[pnum];
int gi = goldIndex - INVITEM_INV_FIRST;
player.InvList[gi]._ivalue -= dropGoldValue;
if (player.InvList[gi]._ivalue > 0)
@ -582,7 +580,7 @@ void RemoveGold(int pnum, int goldIndex)
else
player.RemoveInvItem(gi);
SetPlrHandItem(player.HoldItem, IDI_GOLD);
GetGoldSeed(pnum, &player.HoldItem);
SetGoldSeed(player, player.HoldItem);
player.HoldItem._ivalue = dropGoldValue;
player.HoldItem._iStatFlag = true;
ControlSetGoldCurs(player);
@ -1864,19 +1862,20 @@ void DrawGoldSplit(const Surface &out, int amount)
void control_drop_gold(char vkey)
{
char input[6];
auto &myPlayer = Players[MyPlayerId];
if (Players[MyPlayerId]._pHitPoints >> 6 <= 0) {
if (myPlayer._pHitPoints >> 6 <= 0) {
dropGoldFlag = false;
dropGoldValue = 0;
return;
}
char input[6];
memset(input, 0, sizeof(input));
snprintf(input, sizeof(input), "%i", dropGoldValue);
if (vkey == DVL_VK_RETURN) {
if (dropGoldValue > 0)
RemoveGold(MyPlayerId, initialDropGoldIndex);
RemoveGold(myPlayer, initialDropGoldIndex);
dropGoldFlag = false;
} else if (vkey == DVL_VK_ESCAPE) {
dropGoldFlag = false;

2
Source/debug.cpp

@ -129,7 +129,7 @@ std::string DebugCmdGiveGoldCheat(const string_view parameter)
myPlayer._pGold += GOLD_MAX_LIMIT;
itemId = myPlayer._pNumInv;
}
CalcPlrInv(MyPlayerId, true);
CalcPlrInv(myPlayer, true);
return "You are now rich! If only this was as easy in real life...";
}

21
Source/diablo.cpp

@ -1615,9 +1615,11 @@ bool TryIconCurs()
return true;
}
auto &myPlayer = Players[MyPlayerId];
if (pcurs == CURSOR_IDENTIFY) {
if (pcursinvitem != -1)
CheckIdentify(MyPlayerId, pcursinvitem);
CheckIdentify(myPlayer, pcursinvitem);
else
NewCursor(CURSOR_HAND);
return true;
@ -1625,7 +1627,7 @@ bool TryIconCurs()
if (pcurs == CURSOR_REPAIR) {
if (pcursinvitem != -1)
DoRepair(MyPlayerId, pcursinvitem);
DoRepair(myPlayer, pcursinvitem);
else
NewCursor(CURSOR_HAND);
return true;
@ -1633,7 +1635,7 @@ bool TryIconCurs()
if (pcurs == CURSOR_RECHARGE) {
if (pcursinvitem != -1)
DoRecharge(MyPlayerId, pcursinvitem);
DoRecharge(myPlayer, pcursinvitem);
else
NewCursor(CURSOR_HAND);
return true;
@ -1641,14 +1643,13 @@ bool TryIconCurs()
if (pcurs == CURSOR_OIL) {
if (pcursinvitem != -1)
DoOil(MyPlayerId, pcursinvitem);
DoOil(myPlayer, pcursinvitem);
else
NewCursor(CURSOR_HAND);
return true;
}
if (pcurs == CURSOR_TELEPORT) {
auto &myPlayer = Players[MyPlayerId];
if (pcursmonst != -1)
NetSendCmdParam3(true, CMD_TSPELLID, pcursmonst, myPlayer._pTSpell, GetSpellLevel(MyPlayerId, myPlayer._pTSpell));
else if (pcursplr != -1)
@ -1882,12 +1883,11 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
IncProgress();
for (int i = 0; i < MAX_PLRS; i++) {
auto &player = Players[i];
for (auto &player : Players) {
if (player.plractive && currlevel == player.plrlevel) {
InitPlayerGFX(player);
if (lvldir != ENTRY_LOAD)
InitPlayer(i, firstflag);
InitPlayer(player, firstflag);
}
}
@ -1979,12 +1979,11 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
GetPortalLvlPos();
IncProgress();
for (int i = 0; i < MAX_PLRS; i++) {
auto &player = Players[i];
for (auto &player : Players) {
if (player.plractive && currlevel == player.plrlevel) {
InitPlayerGFX(player);
if (lvldir != ENTRY_LOAD)
InitPlayer(i, firstflag);
InitPlayer(player, firstflag);
}
}
IncProgress();

18
Source/inv.cpp

@ -340,7 +340,7 @@ bool AutoEquip(int playerId, const ItemStruct &item, inv_body_loc bodyLocation,
}
NetSendCmdChItem(false, bodyLocation);
CalcPlrInv(playerId, true);
CalcPlrInv(player, true);
}
return true;
@ -672,7 +672,7 @@ void CheckInvPaste(int pnum, Point cursorPosition)
case ILOC_INVALID:
break;
}
CalcPlrInv(pnum, true);
CalcPlrInv(player, true);
if (pnum == MyPlayerId) {
if (cn == CURSOR_HAND && !IsHardwareCursor())
SetCursorPos(MousePosition.x + (cursW / 2), MousePosition.y + (cursH / 2));
@ -865,7 +865,7 @@ void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove)
player._pGold = CalculateGold(player);
}
CalcPlrInv(pnum, true);
CalcPlrInv(player, true);
CheckItemStats(player);
if (pnum == MyPlayerId) {
@ -1521,14 +1521,12 @@ bool GoldAutoPlaceInInventorySlot(PlayerStruct &player, int slotIndex)
return true;
}
void CheckInvSwap(int pnum, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff)
void CheckInvSwap(PlayerStruct &player, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff)
{
auto &item = Items[MAXITEMS];
memset(&item, 0, sizeof(item));
RecreateItem(item, idx, wCI, seed, 0, (dwBuff & CF_HELLFIRE) != 0);
auto &player = Players[pnum];
player.HoldItem = item;
if (bId) {
@ -1545,18 +1543,16 @@ void CheckInvSwap(int pnum, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId
}
}
CalcPlrInv(pnum, true);
CalcPlrInv(player, true);
}
void inv_update_rem_item(int pnum, BYTE iv)
void inv_update_rem_item(PlayerStruct &player, BYTE iv)
{
auto &player = Players[pnum];
if (iv < NUM_INVLOC) {
player.InvBody[iv]._itype = ITYPE_NONE;
}
CalcPlrInv(pnum, player._pmode != PM_DEATH);
CalcPlrInv(player, player._pmode != PM_DEATH);
}
void CheckInvItem(bool isShiftHeld)

4
Source/inv.h

@ -104,8 +104,8 @@ bool AutoPlaceItemInInventorySlot(PlayerStruct &player, int slotIndex, const Ite
bool AutoPlaceItemInBelt(PlayerStruct &player, const ItemStruct &item, bool persistItem = false);
bool GoldAutoPlace(PlayerStruct &player);
bool GoldAutoPlaceInInventorySlot(PlayerStruct &player, int slotIndex);
void CheckInvSwap(int pnum, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff);
void inv_update_rem_item(int pnum, BYTE iv);
void CheckInvSwap(PlayerStruct &player, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff);
void inv_update_rem_item(PlayerStruct &player, BYTE iv);
void CheckInvItem(bool isShiftHeld = false);
void CheckInvScrn(bool isShiftHeld);
void CheckItemStats(PlayerStruct &player);

82
Source/items.cpp

@ -24,6 +24,7 @@
#include "lighting.h"
#include "missiles.h"
#include "options.h"
#include "player.h"
#include "stores.h"
#include "utils/language.h"
#include "utils/math.h"
@ -126,6 +127,7 @@ enum class PlayerArmorGraphic : uint8_t {
Heavy = 1 << 5,
// clang-format on
};
ItemStruct curruitem;
/** Holds item get records, tracking items being recently looted. This is in an effort to prevent items being picked up more than once. */
@ -2623,10 +2625,8 @@ void InitItems()
initItemGetRecords();
}
void CalcPlrItemVals(int playerId, bool loadgfx)
void CalcPlrItemVals(PlayerStruct &player, bool loadgfx)
{
auto &player = Players[playerId];
int mind = 0; // min damage
int maxd = 0; // max damage
int tac = 0; // accuracy
@ -2754,7 +2754,7 @@ void CalcPlrItemVals(int playerId, bool loadgfx)
lrad = clamp(lrad, 2, 15);
if (player._pLightRad != lrad && playerId == MyPlayerId) {
if (player._pLightRad != lrad && &player == &Players[MyPlayerId]) {
ChangeLightRadius(player._plid, lrad);
ChangeVisionRadius(player._pvid, lrad);
player._pLightRad = lrad;
@ -2863,8 +2863,8 @@ void CalcPlrItemVals(int playerId, bool loadgfx)
player._pMaxHP = ihp + player._pMaxHPBase;
player._pHitPoints = std::min(ihp + player._pHPBase, player._pMaxHP);
if (playerId == MyPlayerId && (player._pHitPoints >> 6) <= 0) {
SetPlayerHitPoints(playerId, 0);
if (&player == &Players[MyPlayerId] && (player._pHitPoints >> 6) <= 0) {
SetPlayerHitPoints(player, 0);
}
player._pMaxMana = imana + player._pMaxManaBase;
@ -2977,7 +2977,7 @@ void CalcPlrItemVals(int playerId, bool loadgfx)
MaxGold = GOLD_MAX_LIMIT;
if (half != MaxGold)
StripTopGold(playerId);
StripTopGold(player);
} else {
MaxGold = GOLD_MAX_LIMIT * 2;
}
@ -2986,15 +2986,13 @@ void CalcPlrItemVals(int playerId, bool loadgfx)
drawhpflag = true;
}
void CalcPlrInv(int playerId, bool loadgfx)
void CalcPlrInv(PlayerStruct &player, bool loadgfx)
{
auto &player = Players[playerId];
CalcPlrItemMin(player);
CalcSelfItems(player);
CalcPlrItemVals(playerId, loadgfx);
CalcPlrItemVals(player, loadgfx);
CalcPlrItemMin(player);
if (playerId == MyPlayerId) {
if (&player == &Players[MyPlayerId]) {
CalcPlrBookVals(player);
player.CalcScrolls();
CalcPlrStaff(player);
@ -3047,12 +3045,7 @@ void GetPlrHandSeed(ItemStruct *h)
h->_iSeed = AdvanceRndSeed();
}
/**
* @brief Set a new unique seed value on the given item
* @param pnum Player id
* @param h Item to update
*/
void GetGoldSeed(int pnum, ItemStruct *h)
void SetGoldSeed(PlayerStruct &player, ItemStruct &gold)
{
int s = 0;
@ -3066,15 +3059,15 @@ void GetGoldSeed(int pnum, ItemStruct *h)
if (item._iSeed == s)
doneflag = false;
}
if (pnum == MyPlayerId) {
for (int i = 0; i < Players[pnum]._pNumInv; i++) {
if (Players[pnum].InvList[i]._iSeed == s)
if (&player == &Players[MyPlayerId]) {
for (int i = 0; i < player._pNumInv; i++) {
if (player.InvList[i]._iSeed == s)
doneflag = false;
}
}
} while (!doneflag);
h->_iSeed = s;
gold._iSeed = s;
}
int GetGoldCursor(int value)
@ -3202,7 +3195,7 @@ void CreatePlrItems(int playerId)
player.InvList[player._pNumInv++] = player.HoldItem;
player.InvGrid[30] = player._pNumInv;
CalcPlrItemVals(playerId, false);
CalcPlrItemVals(player, false);
}
bool ItemSpaceOk(Point position)
@ -3769,28 +3762,26 @@ void GetItemStr(ItemStruct &item)
}
}
void CheckIdentify(int pnum, int cii)
void CheckIdentify(PlayerStruct &player, int cii)
{
ItemStruct *pi;
if (cii >= NUM_INVLOC)
pi = &Players[pnum].InvList[cii - NUM_INVLOC];
pi = &player.InvList[cii - NUM_INVLOC];
else
pi = &Players[pnum].InvBody[cii];
pi = &player.InvBody[cii];
pi->_iIdentified = true;
CalcPlrInv(pnum, true);
CalcPlrInv(player, true);
if (pnum == MyPlayerId)
if (&player == &Players[MyPlayerId])
NewCursor(CURSOR_HAND);
}
void DoRepair(int pnum, int cii)
void DoRepair(PlayerStruct &player, int cii)
{
ItemStruct *pi;
auto &player = Players[pnum];
PlaySfxLoc(IS_REPAIR, player.position.tile);
if (cii >= NUM_INVLOC) {
@ -3800,17 +3791,16 @@ void DoRepair(int pnum, int cii)
}
RepairItem(*pi, player._pLevel);
CalcPlrInv(pnum, true);
CalcPlrInv(player, true);
if (pnum == MyPlayerId)
if (&player == &Players[MyPlayerId])
NewCursor(CURSOR_HAND);
}
void DoRecharge(int pnum, int cii)
void DoRecharge(PlayerStruct &player, int cii)
{
ItemStruct *pi;
auto &player = Players[pnum];
if (cii >= NUM_INVLOC) {
pi = &player.InvList[cii - NUM_INVLOC];
} else {
@ -3820,24 +3810,26 @@ void DoRecharge(int pnum, int cii)
int r = GetSpellBookLevel(pi->_iSpell);
r = GenerateRnd(player._pLevel / r) + 1;
RechargeItem(*pi, r);
CalcPlrInv(pnum, true);
CalcPlrInv(player, true);
}
if (pnum == MyPlayerId)
if (&player == &Players[MyPlayerId])
NewCursor(CURSOR_HAND);
}
void DoOil(int pnum, int cii)
void DoOil(PlayerStruct &player, int cii)
{
if (cii < NUM_INVLOC && cii != INVLOC_HEAD && (cii <= INVLOC_AMULET || cii > INVLOC_CHEST))
return;
auto &player = Players[pnum];
if (!ApplyOilToItem(player.InvBody[cii], player))
ItemStruct *pi;
if (cii >= NUM_INVLOC) {
pi = &player.InvList[cii - NUM_INVLOC];
} else {
pi = &player.InvBody[cii];
}
if (!ApplyOilToItem(*pi, player))
return;
CalcPlrInv(pnum, true);
if (pnum == MyPlayerId) {
CalcPlrInv(player, true);
if (&player == &Players[MyPlayerId])
NewCursor(CURSOR_HAND);
}
}
void PrintItemPower(char plidx, ItemStruct *x)

19
Source/items.h

@ -396,6 +396,8 @@ struct CornerStoneStruct {
ItemStruct item;
};
struct PlayerStruct;
extern ItemStruct Items[MAXITEMS + 1];
extern int ActiveItems[MAXITEMS];
extern int ActiveItemCount;
@ -409,11 +411,14 @@ bool IsItemAvailable(int i);
bool IsUniqueAvailable(int i);
void InitItemGFX();
void InitItems();
void CalcPlrItemVals(int p, bool Loadgfx);
void CalcPlrInv(int p, bool Loadgfx);
void CalcPlrItemVals(PlayerStruct &player, bool Loadgfx);
void CalcPlrInv(PlayerStruct &player, bool Loadgfx);
void SetPlrHandItem(ItemStruct &item, int itemData);
void GetPlrHandSeed(ItemStruct *h);
void GetGoldSeed(int pnum, ItemStruct *h);
/**
* @brief Set a new unique seed value on the given item
*/
void SetGoldSeed(PlayerStruct &player, ItemStruct &gold);
int GetGoldCursor(int value);
void SetPlrHandGoldCurs(ItemStruct &gold);
void CreatePlrItems(int playerId);
@ -443,10 +448,10 @@ void ProcessItems();
void FreeItemGFX();
void GetItemFrm(ItemStruct &item);
void GetItemStr(ItemStruct &item);
void CheckIdentify(int pnum, int cii);
void DoRepair(int pnum, int cii);
void DoRecharge(int pnum, int cii);
void DoOil(int pnum, int cii);
void CheckIdentify(PlayerStruct &player, int cii);
void DoRepair(PlayerStruct &player, int cii);
void DoRecharge(PlayerStruct &player, int cii);
void DoOil(PlayerStruct &player, int cii);
void PrintItemPower(char plidx, ItemStruct *x);
void DrawUniqueInfo(const Surface &out);
void PrintItemDetails(ItemStruct *x);

43
Source/loadsave.cpp

@ -304,10 +304,8 @@ void LoadItems(LoadHelper *file, const int n, ItemStruct *pItem)
}
}
void LoadPlayer(LoadHelper *file, int p)
void LoadPlayer(LoadHelper *file, PlayerStruct &player)
{
auto &player = Players[p];
player._pmode = static_cast<PLR_MODE>(file->NextLE<int32_t>());
for (int8_t &step : player.walkpath) {
@ -516,7 +514,7 @@ void LoadPlayer(LoadHelper *file, int p)
player.pDifficulty = static_cast<_difficulty>(file->NextLE<uint32_t>());
player.pDamAcFlags = file->NextLE<uint32_t>();
file->Skip(20); // Available bytes
CalcPlrItemVals(p, false);
CalcPlrItemVals(player, false);
// Omit pointer _pNData
// Omit pointer _pWData
@ -635,10 +633,8 @@ void LoadMonster(LoadHelper *file, MonsterStruct &monster)
SyncMonsterAnim(monster);
}
void LoadMissile(LoadHelper *file, int i)
void LoadMissile(LoadHelper *file, MissileStruct &missile)
{
auto &missile = Missiles[i];
missile._mitype = static_cast<missile_id>(file->NextLE<int32_t>());
missile.position.tile.x = file->NextLE<int32_t>();
missile.position.tile.y = file->NextLE<int32_t>();
@ -973,10 +969,8 @@ void SaveItems(SaveHelper *file, ItemStruct *pItem, const int n)
}
}
void SavePlayer(SaveHelper *file, int p)
void SavePlayer(SaveHelper *file, PlayerStruct &player)
{
auto &player = Players[p];
file->WriteLE<int32_t>(player._pmode);
for (int8_t step : player.walkpath)
file->WriteLE<int8_t>(step);
@ -1285,10 +1279,8 @@ void SaveMonster(SaveHelper *file, MonsterStruct &monster)
// Omit pointer MData;
}
void SaveMissile(SaveHelper *file, int i)
void SaveMissile(SaveHelper *file, MissileStruct &missile)
{
auto &missile = Missiles[i];
file->WriteLE<int32_t>(missile._mitype);
file->WriteLE<int32_t>(missile.position.tile.x);
file->WriteLE<int32_t>(missile.position.tile.y);
@ -1702,9 +1694,11 @@ void LoadGame(bool firstflag)
file.Skip(4); // Skip loading gnLevelTypeTbl
}
LoadPlayer(&file, MyPlayerId);
auto &myPlayer = Players[MyPlayerId];
sgGameInitInfo.nDifficulty = Players[MyPlayerId].pDifficulty;
LoadPlayer(&file, myPlayer);
sgGameInitInfo.nDifficulty = myPlayer.pDifficulty;
if (sgGameInitInfo.nDifficulty < DIFF_NORMAL || sgGameInitInfo.nDifficulty > DIFF_HELL)
sgGameInitInfo.nDifficulty = DIFF_NORMAL;
@ -1715,7 +1709,7 @@ void LoadGame(bool firstflag)
if (gbIsHellfireSaveGame != gbIsHellfire) {
ConvertLevels();
RemoveEmptyInventory(Players[MyPlayerId]);
RemoveEmptyInventory(myPlayer);
}
LoadGameLevel(firstflag, ENTRY_LOAD);
@ -1742,7 +1736,7 @@ void LoadGame(bool firstflag)
for (int &missileId : AvailableMissiles)
missileId = file.NextLE<int8_t>();
for (int i = 0; i < ActiveMissileCount; i++)
LoadMissile(&file, ActiveMissiles[i]);
LoadMissile(&file, Missiles[ActiveMissiles[i]]);
for (int &objectId : ActiveObjects)
objectId = file.NextLE<int8_t>();
for (int &objectId : AvailableObjects)
@ -1918,8 +1912,9 @@ void SaveGameData()
file.WriteBE<int32_t>(gnLevelTypeTbl[i]);
}
Players[MyPlayerId].pDifficulty = sgGameInitInfo.nDifficulty;
SavePlayer(&file, MyPlayerId);
auto &myPlayer = Players[MyPlayerId];
myPlayer.pDifficulty = sgGameInitInfo.nDifficulty;
SavePlayer(&file, myPlayer);
for (int i = 0; i < giNumberQuests; i++)
SaveQuest(&file, i);
@ -1938,7 +1933,7 @@ void SaveGameData()
for (int missileId : AvailableMissiles)
file.WriteLE<int8_t>(missileId);
for (int i = 0; i < ActiveMissileCount; i++)
SaveMissile(&file, ActiveMissiles[i]);
SaveMissile(&file, Missiles[ActiveMissiles[i]]);
for (int objectId : ActiveObjects)
file.WriteLE<int8_t>(objectId);
for (int objectId : AvailableObjects)
@ -2037,7 +2032,9 @@ void SaveLevel()
{
PFileScopedArchiveWriter scopedWriter;
DoUnVision(Players[MyPlayerId].position.tile, Players[MyPlayerId]._pLightRad); // fix for vision staying on the level
auto &myPlayer = Players[MyPlayerId];
DoUnVision(myPlayer.position.tile, myPlayer._pLightRad); // fix for vision staying on the level
if (currlevel == 0)
glSeedTbl[0] = AdvanceRndSeed();
@ -2111,9 +2108,9 @@ void SaveLevel()
}
if (!setlevel)
Players[MyPlayerId]._pLvlVisited[currlevel] = true;
myPlayer._pLvlVisited[currlevel] = true;
else
Players[MyPlayerId]._pSLvlVisited[setlvlnum] = true;
myPlayer._pSLvlVisited[setlvlnum] = true;
}
void LoadLevel()

2
Source/menu.cpp

@ -115,7 +115,7 @@ bool mainmenu_select_hero_dialog(GameData *gameData)
return false;
}
pfile_read_player_from_save(gSaveNumber, MyPlayerId);
pfile_read_player_from_save(gSaveNumber, Players[MyPlayerId]);
return true;
}

15
Source/missiles.cpp

@ -1226,7 +1226,7 @@ void InitMissiles()
if (missile._mitype == MIS_INFRA) {
int src = missile._misource;
if (src == MyPlayerId)
CalcPlrItemVals(MyPlayerId, true);
CalcPlrItemVals(myPlayer, true);
}
}
}
@ -1240,7 +1240,7 @@ void InitMissiles()
if (missile._mitype == MIS_BLODBOIL) {
if (missile._misource == MyPlayerId) {
int missingHP = myPlayer._pMaxHP - myPlayer._pHitPoints;
CalcPlrItemVals(MyPlayerId, true);
CalcPlrItemVals(myPlayer, true);
ApplyPlrDamage(MyPlayerId, 0, 1, missingHP + missile.var2);
}
}
@ -1505,7 +1505,7 @@ void AddManaTrap(MissileStruct &missile, Point /*dst*/, Direction /*midir*/)
player._pMana = 0;
player._pManaBase = player._pMana + player._pMaxManaBase - player._pMaxMana;
CalcPlrInv(pid, false);
CalcPlrInv(player, false);
drawmanaflag = true;
PlaySfxLoc(TSFX_COW7, target);
}
@ -2619,7 +2619,7 @@ void AddBlodboil(MissileStruct &missile, Point /*dst*/, Direction /*midir*/)
missile.var2 = tmp;
int lvl = player._pLevel * 2;
missile._mirange = lvl + 10 * missile._mispllvl + 245;
CalcPlrItemVals(missile._misource, true);
CalcPlrItemVals(player, true);
force_redraw = 255;
player.Say(HeroSpeech::Aaaaargh);
}
@ -3881,11 +3881,12 @@ void MI_FirewallC(MissileStruct &missile)
void MI_Infra(MissileStruct &missile)
{
auto &player = Players[missile._misource];
missile._mirange--;
Players[missile._misource]._pInfraFlag = true;
player._pInfraFlag = true;
if (missile._mirange == 0) {
missile._miDelFlag = true;
CalcPlrItemVals(missile._misource, true);
CalcPlrItemVals(player, true);
}
}
@ -4014,7 +4015,7 @@ void MI_Blodboil(MissileStruct &missile)
hpdif += missile.var2;
}
CalcPlrItemVals(id, true);
CalcPlrItemVals(player, true);
ApplyPlrDamage(id, 0, 1, hpdif);
force_redraw = 255;
player.Say(HeroSpeech::HeavyBreathing);

16
Source/msg.cpp

@ -1446,12 +1446,14 @@ DWORD OnChangePlayerItems(TCmd *pCmd, int pnum)
auto *p = (TCmdChItem *)pCmd;
auto bodyLocation = static_cast<inv_body_loc>(p->bLoc);
auto &player = Players[pnum];
if (gbBufferMsgs == 1)
SendPacket(pnum, p, sizeof(*p));
else if (pnum != MyPlayerId)
CheckInvSwap(pnum, p->bLoc, p->wIndx, p->wCI, p->dwSeed, p->bId != 0, p->dwBuff);
CheckInvSwap(player, p->bLoc, p->wIndx, p->wCI, p->dwSeed, p->bId != 0, p->dwBuff);
Players[pnum].ReadySpellFromEquipment(bodyLocation);
player.ReadySpellFromEquipment(bodyLocation);
return sizeof(*p);
}
@ -1463,7 +1465,7 @@ DWORD OnDeletePlayerItems(TCmd *pCmd, int pnum)
if (gbBufferMsgs == 1)
SendPacket(pnum, p, sizeof(*p));
else if (pnum != MyPlayerId)
inv_update_rem_item(pnum, p->bLoc);
inv_update_rem_item(Players[pnum], p->bLoc);
return sizeof(*p);
}
@ -1616,7 +1618,7 @@ DWORD OnSetStrength(TCmd *pCmd, int pnum)
if (gbBufferMsgs == 1)
SendPacket(pnum, p, sizeof(*p));
else if (p->wParam1 <= 750 && pnum != MyPlayerId)
SetPlrStr(pnum, p->wParam1);
SetPlrStr(Players[pnum], p->wParam1);
return sizeof(*p);
}
@ -1628,7 +1630,7 @@ DWORD OnSetDexterity(TCmd *pCmd, int pnum)
if (gbBufferMsgs == 1)
SendPacket(pnum, p, sizeof(*p));
else if (p->wParam1 <= 750 && pnum != MyPlayerId)
SetPlrDex(pnum, p->wParam1);
SetPlrDex(Players[pnum], p->wParam1);
return sizeof(*p);
}
@ -1640,7 +1642,7 @@ DWORD OnSetMagic(TCmd *pCmd, int pnum)
if (gbBufferMsgs == 1)
SendPacket(pnum, p, sizeof(*p));
else if (p->wParam1 <= 750 && pnum != MyPlayerId)
SetPlrMag(pnum, p->wParam1);
SetPlrMag(Players[pnum], p->wParam1);
return sizeof(*p);
}
@ -1652,7 +1654,7 @@ DWORD OnSetVitality(TCmd *pCmd, int pnum)
if (gbBufferMsgs == 1)
SendPacket(pnum, p, sizeof(*p));
else if (p->wParam1 <= 750 && pnum != MyPlayerId)
SetPlrVit(pnum, p->wParam1);
SetPlrVit(Players[pnum], p->wParam1);
return sizeof(*p);
}

4
Source/multi.cpp

@ -454,7 +454,7 @@ bool InitMulti(GameData *gameData)
MyPlayerId = playerId;
gbIsMultiplayer = true;
pfile_read_player_from_save(gSaveNumber, MyPlayerId);
pfile_read_player_from_save(gSaveNumber, Players[MyPlayerId]);
return true;
}
@ -802,7 +802,7 @@ void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, bool recv)
sgwPackPlrOffsetTbl[pnum] = 0;
PlayerLeftMsg(pnum, false);
UnPackPlayer(&netplr[pnum], pnum, true);
UnPackPlayer(&netplr[pnum], player, true);
if (!recv) {
return;

2
Source/objects.cpp

@ -3711,7 +3711,7 @@ void OperateShrine(int pnum, int i, _sfx_id sType)
break;
}
CalcPlrInv(pnum, true);
CalcPlrInv(Players[pnum], true);
force_redraw = 255;
if (pnum == MyPlayerId)

10
Source/pack.cpp

@ -197,10 +197,8 @@ void UnPackItem(const PkItemStruct *is, ItemStruct *id, bool isHellfire)
*id = item;
}
void UnPackPlayer(const PkPlayerStruct *pPack, int pnum, bool netSync)
void UnPackPlayer(const PkPlayerStruct *pPack, PlayerStruct &player, bool netSync)
{
auto &player = Players[pnum];
player.position.tile = { pPack->px, pPack->py };
player.position.future = { pPack->px, pPack->py };
player.plrlevel = pPack->plrlevel;
@ -208,7 +206,7 @@ void UnPackPlayer(const PkPlayerStruct *pPack, int pnum, bool netSync)
player.destAction = ACTION_NONE;
strcpy(player._pName, pPack->pName);
player._pClass = (HeroClass)pPack->pClass;
InitPlayer(pnum, true);
InitPlayer(player, true);
player._pBaseStr = pPack->pBaseStr;
player._pStrength = pPack->pBaseStr;
player._pBaseMag = pPack->pBaseMag;
@ -261,12 +259,12 @@ void UnPackPlayer(const PkPlayerStruct *pPack, int pnum, bool netSync)
UnPackItem(&packedItem, &player.SpdList[i], isHellfire);
}
if (pnum == MyPlayerId) {
if (&player == &Players[MyPlayerId]) {
for (int i = 0; i < 20; i++)
witchitem[i]._itype = ITYPE_NONE;
}
CalcPlrInv(pnum, false);
CalcPlrInv(player, false);
player.wReflections = SDL_SwapLE16(pPack->wReflections);
player.pTownWarps = 0;
player.pDungMsgs = 0;

2
Source/pack.h

@ -80,7 +80,7 @@ struct PkPlayerStruct {
#pragma pack(pop)
void PackPlayer(PkPlayerStruct *pPack, const PlayerStruct &player, bool manashield);
void UnPackPlayer(const PkPlayerStruct *pPack, int pnum, bool netSync);
void UnPackPlayer(const PkPlayerStruct *pPack, PlayerStruct &player, bool netSync);
void PackItem(PkItemStruct *id, const ItemStruct *is);
void UnPackItem(const PkItemStruct *is, ItemStruct *id, bool isHellfire);

12
Source/pfile.cpp

@ -300,12 +300,12 @@ bool pfile_ui_set_hero_infos(bool (*uiAddHeroInfo)(_uiheroinfo *))
pkplr.bIsHellfire = gbIsHellfireSaveGame ? 1 : 0;
auto &player = Players[0];
UnPackPlayer(&pkplr, 0, false);
UnPackPlayer(&pkplr, player, false);
CloseArchive(&archive);
LoadHeroItems(player);
RemoveEmptyInventory(player);
CalcPlrInv(0, false);
CalcPlrInv(player, false);
Game2UiPlayer(player, &uihero, hasSaveGame);
uiAddHeroInfo(&uihero);
@ -375,7 +375,7 @@ bool pfile_delete_save(_uiheroinfo *heroInfo)
return true;
}
void pfile_read_player_from_save(uint32_t saveNum, int playerId)
void pfile_read_player_from_save(uint32_t saveNum, PlayerStruct &player)
{
HANDLE archive;
PkPlayerStruct pkplr;
@ -392,13 +392,11 @@ void pfile_read_player_from_save(uint32_t saveNum, int playerId)
CloseArchive(&archive);
auto &player = Players[playerId];
UnPackPlayer(&pkplr, playerId, false);
UnPackPlayer(&pkplr, player, false);
LoadHeroItems(player);
RemoveEmptyInventory(player);
CalcPlrInv(playerId, false);
CalcPlrInv(player, false);
}
bool LevelFileExists()

2
Source/pfile.h

@ -34,7 +34,7 @@ void pfile_ui_set_class_stats(unsigned int playerClass, _uidefaultstats *classSt
uint32_t pfile_ui_get_first_unused_save_num();
bool pfile_ui_save_create(_uiheroinfo *heroinfo);
bool pfile_delete_save(_uiheroinfo *heroInfo);
void pfile_read_player_from_save(uint32_t saveNum, int playerId);
void pfile_read_player_from_save(uint32_t saveNum, PlayerStruct &player);
bool LevelFileExists();
void GetTempLevelNames(char *szTemp);
void GetPermLevelNames(char *szPerm);

148
Source/player.cpp

@ -625,7 +625,7 @@ int DropGold(int pnum, int amount, bool skipFullStacks)
if (amount < item._ivalue) {
item._ivalue -= amount;
SetPlrHandItem(player.HoldItem, IDI_GOLD);
GetGoldSeed(pnum, &player.HoldItem);
SetGoldSeed(player, player.HoldItem);
SetPlrHandGoldCurs(player.HoldItem);
player.HoldItem._ivalue = amount;
DeadItem(player, &player.HoldItem, { 0, 0 });
@ -635,7 +635,7 @@ int DropGold(int pnum, int amount, bool skipFullStacks)
amount -= item._ivalue;
player.RemoveInvItem(i);
SetPlrHandItem(player.HoldItem, IDI_GOLD);
GetGoldSeed(pnum, &player.HoldItem);
SetGoldSeed(player, player.HoldItem);
SetPlrHandGoldCurs(player.HoldItem);
player.HoldItem._ivalue = item._ivalue;
DeadItem(player, &player.HoldItem, { 0, 0 });
@ -768,19 +768,17 @@ bool DoWalk(int pnum, int variant)
return false;
}
bool WeaponDecay(int pnum, int ii)
bool WeaponDecay(PlayerStruct &player, int ii)
{
auto &player = Players[pnum];
if (!player.InvBody[ii].isEmpty() && player.InvBody[ii]._iClass == ICLASS_WEAPON && (player.InvBody[ii]._iDamAcFlags & ISPLHF_DECAY) != 0) {
player.InvBody[ii]._iPLDam -= 5;
if (player.InvBody[ii]._iPLDam <= -100) {
NetSendCmdDelItem(true, ii);
player.InvBody[ii]._itype = ITYPE_NONE;
CalcPlrInv(pnum, true);
CalcPlrInv(player, true);
return true;
}
CalcPlrInv(pnum, true);
CalcPlrInv(player, true);
}
return false;
}
@ -791,20 +789,20 @@ bool DamageWeapon(int pnum, int durrnd)
return false;
}
if (WeaponDecay(pnum, INVLOC_HAND_LEFT))
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("WeaponDur: illegal player %i", pnum);
}
auto &player = Players[pnum];
if (WeaponDecay(player, INVLOC_HAND_LEFT))
return true;
if (WeaponDecay(pnum, INVLOC_HAND_RIGHT))
if (WeaponDecay(player, INVLOC_HAND_RIGHT))
return true;
if (GenerateRnd(durrnd) != 0) {
return false;
}
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("WeaponDur: illegal player %i", pnum);
}
auto &player = Players[pnum];
if (!player.InvBody[INVLOC_HAND_LEFT].isEmpty() && player.InvBody[INVLOC_HAND_LEFT]._iClass == ICLASS_WEAPON) {
if (player.InvBody[INVLOC_HAND_LEFT]._iDurability == DUR_INDESTRUCTIBLE) {
return false;
@ -814,7 +812,7 @@ bool DamageWeapon(int pnum, int durrnd)
if (player.InvBody[INVLOC_HAND_LEFT]._iDurability <= 0) {
NetSendCmdDelItem(true, INVLOC_HAND_LEFT);
player.InvBody[INVLOC_HAND_LEFT]._itype = ITYPE_NONE;
CalcPlrInv(pnum, true);
CalcPlrInv(player, true);
return true;
}
}
@ -828,7 +826,7 @@ bool DamageWeapon(int pnum, int durrnd)
if (player.InvBody[INVLOC_HAND_RIGHT]._iDurability == 0) {
NetSendCmdDelItem(true, INVLOC_HAND_RIGHT);
player.InvBody[INVLOC_HAND_RIGHT]._itype = ITYPE_NONE;
CalcPlrInv(pnum, true);
CalcPlrInv(player, true);
return true;
}
}
@ -842,7 +840,7 @@ bool DamageWeapon(int pnum, int durrnd)
if (player.InvBody[INVLOC_HAND_RIGHT]._iDurability == 0) {
NetSendCmdDelItem(true, INVLOC_HAND_RIGHT);
player.InvBody[INVLOC_HAND_RIGHT]._itype = ITYPE_NONE;
CalcPlrInv(pnum, true);
CalcPlrInv(player, true);
return true;
}
}
@ -856,7 +854,7 @@ bool DamageWeapon(int pnum, int durrnd)
if (player.InvBody[INVLOC_HAND_LEFT]._iDurability == 0) {
NetSendCmdDelItem(true, INVLOC_HAND_LEFT);
player.InvBody[INVLOC_HAND_LEFT]._itype = ITYPE_NONE;
CalcPlrInv(pnum, true);
CalcPlrInv(player, true);
return true;
}
}
@ -1362,7 +1360,7 @@ void ShieldDur(int pnum)
if (player.InvBody[INVLOC_HAND_LEFT]._iDurability == 0) {
NetSendCmdDelItem(true, INVLOC_HAND_LEFT);
player.InvBody[INVLOC_HAND_LEFT]._itype = ITYPE_NONE;
CalcPlrInv(pnum, true);
CalcPlrInv(player, true);
}
}
@ -1372,7 +1370,7 @@ void ShieldDur(int pnum)
if (player.InvBody[INVLOC_HAND_RIGHT]._iDurability == 0) {
NetSendCmdDelItem(true, INVLOC_HAND_RIGHT);
player.InvBody[INVLOC_HAND_RIGHT]._itype = ITYPE_NONE;
CalcPlrInv(pnum, true);
CalcPlrInv(player, true);
}
}
}
@ -1444,7 +1442,7 @@ void DamageArmor(int pnum)
NetSendCmdDelItem(true, INVLOC_HEAD);
}
pi->_itype = ITYPE_NONE;
CalcPlrInv(pnum, true);
CalcPlrInv(player, true);
}
bool DoSpell(int pnum)
@ -2571,7 +2569,7 @@ void NextPlrLevel(int pnum)
player._pLevel++;
player._pMaxLvl++;
CalcPlrInv(pnum, true);
CalcPlrInv(player, true);
if (CalcStatDiff(player) < 5) {
player._pStatPts = CalcStatDiff(player);
@ -2618,7 +2616,7 @@ void NextPlrLevel(int pnum)
if (sgbControllerActive)
FocusOnCharInfo();
CalcPlrInv(pnum, true);
CalcPlrInv(player, true);
}
void AddPlrExperience(int pnum, int lvl, int exp)
@ -2692,18 +2690,14 @@ void AddPlrMonstExper(int lvl, int exp, char pmask)
}
}
void InitPlayer(int pnum, bool firstTime)
void InitPlayer(PlayerStruct &player, bool firstTime)
{
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("InitPlayer: illegal player %i", pnum);
}
auto &player = Players[pnum];
auto &myPlayer = Players[MyPlayerId];
if (firstTime) {
player._pRSplType = RSPLTYPE_INVALID;
player._pRSpell = SPL_INVALID;
if (pnum == MyPlayerId)
if (&player == &myPlayer)
LoadHotkeys();
player._pSBkSpell = SPL_INVALID;
player._pSpell = player._pRSpell;
@ -2734,7 +2728,7 @@ void InitPlayer(int pnum, bool firstTime)
player._pdir = DIR_S;
if (pnum == MyPlayerId) {
if (&player == &myPlayer) {
if (!firstTime || currlevel != 0) {
player.position.tile = { ViewX, ViewY };
}
@ -2750,13 +2744,13 @@ void InitPlayer(int pnum, bool firstTime)
player.walkpath[0] = WALK_NONE;
player.destAction = ACTION_NONE;
if (pnum == MyPlayerId) {
if (&player == &myPlayer) {
player._plid = AddLight(player.position.tile, player._pLightRad);
ChangeLightXY(myPlayer._plid, myPlayer.position.tile); // fix for a bug where old light is still visible at the entrance after reentering level
} else {
player._plid = NO_LIGHT;
}
player._pvid = AddVision(player.position.tile, player._pLightRad, pnum == MyPlayerId);
player._pvid = AddVision(player.position.tile, player._pLightRad, &player == &myPlayer);
}
if (player._pClass == HeroClass::Warrior) {
@ -2782,7 +2776,7 @@ void InitPlayer(int pnum, bool firstTime)
player._pNextExper = ExpLvlsTbl[player._pLevel];
player._pInvincible = false;
if (pnum == MyPlayerId) {
if (&player == &myPlayer) {
deathdelay = 0;
MyPlayerIsDead = false;
ScrollInfo.offset = { 0, 0 };
@ -3026,14 +3020,14 @@ StartPlayerKill(int pnum, int earflag)
player._pBlockFlag = false;
player._pmode = PM_DEATH;
player._pInvincible = true;
SetPlayerHitPoints(pnum, 0);
SetPlayerHitPoints(player, 0);
player.deathFrame = 1;
if (pnum != MyPlayerId && earflag == 0 && !diablolevel) {
for (auto &item : player.InvBody) {
item._itype = ITYPE_NONE;
}
CalcPlrInv(pnum, false);
CalcPlrInv(player, false);
}
if (player.plrlevel == currlevel) {
@ -3087,22 +3081,17 @@ StartPlayerKill(int pnum, int earflag)
DeadItem(player, &item, Displacement::fromDirection(pdd));
}
CalcPlrInv(pnum, false);
CalcPlrInv(player, false);
}
}
}
}
}
SetPlayerHitPoints(pnum, 0);
SetPlayerHitPoints(player, 0);
}
void StripTopGold(int pnum)
void StripTopGold(PlayerStruct &player)
{
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("StripTopGold: illegal player %i", pnum);
}
auto &player = Players[pnum];
ItemStruct tmpItem = player.HoldItem;
for (int i = 0; i < player._pNumInv; i++) {
@ -3111,7 +3100,7 @@ void StripTopGold(int pnum)
int val = player.InvList[i]._ivalue - MaxGold;
player.InvList[i]._ivalue = MaxGold;
SetPlrHandItem(player.HoldItem, 0);
GetGoldSeed(pnum, &player.HoldItem);
SetGoldSeed(player, player.HoldItem);
player.HoldItem._ivalue = val;
SetPlrHandGoldCurs(player.HoldItem);
if (!GoldAutoPlace(player))
@ -3162,7 +3151,7 @@ void ApplyPlrDamage(int pnum, int dam, int minHP /*= 0*/, int frac /*= 0*/, int
}
int minHitPoints = minHP << 6;
if (player._pHitPoints < minHitPoints) {
SetPlayerHitPoints(pnum, minHitPoints);
SetPlayerHitPoints(player, minHitPoints);
}
if (player._pHitPoints >> 6 <= 0) {
SyncPlrKill(pnum, earflag);
@ -3174,11 +3163,11 @@ void SyncPlrKill(int pnum, int earflag)
auto &player = Players[pnum];
if (player._pHitPoints <= 0 && currlevel == 0) {
SetPlayerHitPoints(pnum, 64);
SetPlayerHitPoints(player, 64);
return;
}
SetPlayerHitPoints(pnum, 0);
SetPlayerHitPoints(player, 0);
StartPlayerKill(pnum, earflag);
}
@ -3261,12 +3250,12 @@ void RestartTownLvl(int pnum)
player.plrlevel = 0;
player._pInvincible = false;
SetPlayerHitPoints(pnum, 64);
SetPlayerHitPoints(player, 64);
player._pMana = 0;
player._pManaBase = player._pMana - (player._pMaxMana - player._pMaxManaBase);
CalcPlrInv(pnum, false);
CalcPlrInv(player, false);
if (pnum == MyPlayerId) {
player._pmode = PM_NEWLVL;
@ -3701,7 +3690,7 @@ void ModifyPlrStr(int p, int l)
player._pStrength += l;
player._pBaseStr += l;
CalcPlrInv(p, true);
CalcPlrInv(player, true);
if (p == MyPlayerId) {
NetSendCmdParam1(false, CMD_SETSTR, player._pBaseStr);
@ -3737,7 +3726,7 @@ void ModifyPlrMag(int p, int l)
player._pMana += ms;
}
CalcPlrInv(p, true);
CalcPlrInv(player, true);
if (p == MyPlayerId) {
NetSendCmdParam1(false, CMD_SETMAG, player._pBaseMag);
@ -3758,7 +3747,7 @@ void ModifyPlrDex(int p, int l)
player._pDexterity += l;
player._pBaseDex += l;
CalcPlrInv(p, true);
CalcPlrInv(player, true);
if (p == MyPlayerId) {
NetSendCmdParam1(false, CMD_SETDEX, player._pBaseDex);
@ -3790,51 +3779,34 @@ void ModifyPlrVit(int p, int l)
player._pHitPoints += ms;
player._pMaxHP += ms;
CalcPlrInv(p, true);
CalcPlrInv(player, true);
if (p == MyPlayerId) {
NetSendCmdParam1(false, CMD_SETVIT, player._pBaseVit);
}
}
void SetPlayerHitPoints(int pnum, int val)
void SetPlayerHitPoints(PlayerStruct &player, int val)
{
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("SetPlayerHitPoints: illegal player %i", pnum);
}
auto &player = Players[pnum];
player._pHitPoints = val;
player._pHPBase = val + player._pMaxHPBase - player._pMaxHP;
if (pnum == MyPlayerId) {
if (&player == &Players[MyPlayerId]) {
drawhpflag = true;
}
}
void SetPlrStr(int p, int v)
void SetPlrStr(PlayerStruct &player, int v)
{
if ((DWORD)p >= MAX_PLRS) {
app_fatal("SetPlrStr: illegal player %i", p);
}
auto &player = Players[p];
player._pBaseStr = v;
CalcPlrInv(p, true);
CalcPlrInv(player, true);
}
void SetPlrMag(int p, int v)
void SetPlrMag(PlayerStruct &player, int v)
{
int m;
if ((DWORD)p >= MAX_PLRS) {
app_fatal("SetPlrMag: illegal player %i", p);
}
auto &player = Players[p];
player._pBaseMag = v;
m = v << 6;
int m = v << 6;
if (player._pClass == HeroClass::Sorcerer) {
m *= 2;
} else if (player._pClass == HeroClass::Bard) {
@ -3843,39 +3815,27 @@ void SetPlrMag(int p, int v)
player._pMaxManaBase = m;
player._pMaxMana = m;
CalcPlrInv(p, true);
CalcPlrInv(player, true);
}
void SetPlrDex(int p, int v)
void SetPlrDex(PlayerStruct &player, int v)
{
if ((DWORD)p >= MAX_PLRS) {
app_fatal("SetPlrDex: illegal player %i", p);
}
auto &player = Players[p];
player._pBaseDex = v;
CalcPlrInv(p, true);
CalcPlrInv(player, true);
}
void SetPlrVit(int p, int v)
void SetPlrVit(PlayerStruct &player, int v)
{
int hp;
if ((DWORD)p >= MAX_PLRS) {
app_fatal("SetPlrVit: illegal player %i", p);
}
auto &player = Players[p];
player._pBaseVit = v;
hp = v << 6;
int hp = v << 6;
if (player._pClass == HeroClass::Warrior || player._pClass == HeroClass::Barbarian) {
hp *= 2;
}
player._pHPBase = hp;
player._pMaxHPBase = hp;
CalcPlrInv(p, true);
CalcPlrInv(player, true);
}
void InitDungMsgs(PlayerStruct &player)

14
Source/player.h

@ -597,7 +597,7 @@ void NextPlrLevel(int pnum);
void AddPlrExperience(int pnum, int lvl, int exp);
void AddPlrMonstExper(int lvl, int exp, char pmask);
void ApplyPlrDamage(int pnum, int dam, int minHP = 0, int frac = 0, int earflag = 0);
void InitPlayer(int pnum, bool FirstTime);
void InitPlayer(PlayerStruct &player, bool FirstTime);
void InitMultiView();
void PlrClrTrans(Point position);
void PlrDoTrans(Point position);
@ -609,7 +609,7 @@ void FixPlrWalkTags(int pnum);
void RemovePlrFromMap(int pnum);
void StartPlrHit(int pnum, int dam, bool forcehit);
void StartPlayerKill(int pnum, int earflag);
void StripTopGold(int pnum);
void StripTopGold(PlayerStruct &player);
void SyncPlrKill(int pnum, int earflag);
void RemovePlrMissiles(int pnum);
void StartNewLvl(int pnum, interface_mode fom, int lvl);
@ -629,11 +629,11 @@ void ModifyPlrStr(int p, int l);
void ModifyPlrMag(int p, int l);
void ModifyPlrDex(int p, int l);
void ModifyPlrVit(int p, int l);
void SetPlayerHitPoints(int pnum, int val);
void SetPlrStr(int p, int v);
void SetPlrMag(int p, int v);
void SetPlrDex(int p, int v);
void SetPlrVit(int p, int v);
void SetPlayerHitPoints(PlayerStruct &player, int val);
void SetPlrStr(PlayerStruct &player, int v);
void SetPlrMag(PlayerStruct &player, int v);
void SetPlrDex(PlayerStruct &player, int v);
void SetPlrVit(PlayerStruct &player, int v);
void InitDungMsgs(PlayerStruct &player);
void PlayDungMsgs();

4
Source/spells.cpp

@ -285,13 +285,13 @@ void DoResurrect(int pnum, uint16_t rid)
if (target._pMaxHPBase < (10 << 6)) {
hp = target._pMaxHPBase;
}
SetPlayerHitPoints(rid, hp);
SetPlayerHitPoints(target, hp);
target._pHPBase = target._pHitPoints + (target._pMaxHPBase - target._pMaxHP); // CODEFIX: does the same stuff as SetPlayerHitPoints above, can be removed
target._pMana = 0;
target._pManaBase = target._pMana + (target._pMaxManaBase - target._pMaxMana);
CalcPlrInv(rid, true);
CalcPlrInv(target, true);
if (target.plrlevel == currlevel) {
StartStand(rid, target._pdir);

23
Source/stores.cpp

@ -1302,7 +1302,8 @@ void SmithEnter()
*/
void SmithBuyItem()
{
auto &item = Players[MyPlayerId].HoldItem;
auto &myPlayer = Players[MyPlayerId];
auto &item = myPlayer.HoldItem;
TakePlrsMoney(item._iIvalue);
if (item._iMagical == ITEM_QUALITY_NORMAL)
@ -1317,7 +1318,7 @@ void SmithBuyItem()
}
smithitem[idx]._itype = ITYPE_NONE;
}
CalcPlrInv(MyPlayerId, true);
CalcPlrInv(myPlayer, true);
}
void SmitBuyEnter()
@ -1469,7 +1470,7 @@ void PlaceStoreGold(int v)
for (auto &gridNum : myPlayer.InvGrid) {
if (gridNum == 0) {
int ii = myPlayer._pNumInv;
GetGoldSeed(MyPlayerId, &golditem);
SetGoldSeed(myPlayer, golditem);
myPlayer.InvList[ii] = golditem;
myPlayer._pNumInv++;
gridNum = myPlayer._pNumInv;
@ -1649,7 +1650,7 @@ void WitchBuyItem()
}
}
CalcPlrInv(MyPlayerId, true);
CalcPlrInv(myPlayer, true);
}
void WitchBuyEnter()
@ -1723,7 +1724,7 @@ void WitchRechargeItem()
else
myPlayer.InvList[i]._iCharges = myPlayer.InvList[i]._iMaxCharges;
CalcPlrInv(MyPlayerId, true);
CalcPlrInv(myPlayer, true);
}
void WitchRechargeEnter()
@ -1778,11 +1779,12 @@ void BoyEnter()
void BoyBuyItem()
{
TakePlrsMoney(Players[MyPlayerId].HoldItem._iIvalue);
auto &myPlayer = Players[MyPlayerId];
TakePlrsMoney(myPlayer.HoldItem._iIvalue);
StoreAutoPlace();
boyitem._itype = ITYPE_NONE;
stextshold = STORE_BOY;
CalcPlrInv(MyPlayerId, true);
CalcPlrInv(myPlayer, true);
stextlhold = 12;
}
@ -1791,7 +1793,8 @@ void BoyBuyItem()
*/
void HealerBuyItem()
{
auto &item = Players[MyPlayerId].HoldItem;
auto &myPlayer = Players[MyPlayerId];
auto &item = myPlayer.HoldItem;
int idx = stextvhold + ((stextlhold - stextup) / 4);
if (!gbIsMultiplayer) {
@ -1823,7 +1826,7 @@ void HealerBuyItem()
}
healitem[idx]._itype = ITYPE_NONE;
}
CalcPlrInv(MyPlayerId, true);
CalcPlrInv(myPlayer, true);
}
void BoyBuyEnter()
@ -1892,7 +1895,7 @@ void StorytellerIdentifyItem()
}
myPlayer.HoldItem._iIdentified = true;
TakePlrsMoney(myPlayer.HoldItem._iIvalue);
CalcPlrInv(MyPlayerId, true);
CalcPlrInv(myPlayer, true);
}
void ConfirmEnter()

2
test/writehero_test.cpp

@ -339,7 +339,7 @@ TEST(Writehero, pfile_write_hero)
pfile_ui_save_create(&info);
PkPlayerStruct pks;
PackPlayerTest(&pks);
UnPackPlayer(&pks, MyPlayerId, true);
UnPackPlayer(&pks, Players[MyPlayerId], true);
AssertPlayer(Players[0]);
pfile_write_hero();

Loading…
Cancel
Save