Skip to content

Commit

Permalink
Fix NetSend* related MSVC Warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
obligaron committed Dec 2, 2023
1 parent 34adaa6 commit 6052aa1
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Source/controls/plrctrls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ void Interact()
}

if (leveltype != DTYPE_TOWN && PlayerUnderCursor != nullptr && !myPlayer.friendlyMode) {
NetSendCmdParam1(true, myPlayer.UsesRangedWeapon() ? CMD_RATTACKPID : CMD_ATTACKPID, PlayerUnderCursor->getId());
NetSendCmdParam1(true, myPlayer.UsesRangedWeapon() ? CMD_RATTACKPID : CMD_ATTACKPID, static_cast<uint16_t>(PlayerUnderCursor->getId()));
LastMouseButtonAction = MouseActionType::AttackPlayerTarget;
return;
}
Expand Down
10 changes: 5 additions & 5 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void LeftMouseCmd(bool bShift)
}
} else if (PlayerUnderCursor != nullptr && !myPlayer.friendlyMode) {
LastMouseButtonAction = MouseActionType::AttackPlayerTarget;
NetSendCmdParam1(true, CMD_RATTACKPID, PlayerUnderCursor->getId());
NetSendCmdParam1(true, CMD_RATTACKPID, static_cast<uint16_t>(PlayerUnderCursor->getId()));
}
} else {
if (bShift) {
Expand All @@ -293,7 +293,7 @@ void LeftMouseCmd(bool bShift)
NetSendCmdParam1(true, CMD_ATTACKID, pcursmonst);
} else if (PlayerUnderCursor != nullptr && !myPlayer.friendlyMode) {
LastMouseButtonAction = MouseActionType::AttackPlayerTarget;
NetSendCmdParam1(true, CMD_ATTACKPID, PlayerUnderCursor->getId());
NetSendCmdParam1(true, CMD_ATTACKPID, static_cast<uint16_t>(PlayerUnderCursor->getId()));
}
}
if (!bShift && pcursitem == -1 && ObjectUnderCursor == nullptr && pcursmonst == -1 && PlayerUnderCursor == nullptr) {
Expand Down Expand Up @@ -2497,7 +2497,7 @@ bool TryIconCurs()
{
if (pcurs == CURSOR_RESURRECT) {
if (PlayerUnderCursor != nullptr) {
NetSendCmdParam1(true, CMD_RESURRECT, PlayerUnderCursor->getId());
NetSendCmdParam1(true, CMD_RESURRECT, static_cast<uint16_t>(PlayerUnderCursor->getId()));
NewCursor(CURSOR_HAND);
return true;
}
Expand All @@ -2507,7 +2507,7 @@ bool TryIconCurs()

if (pcurs == CURSOR_HEALOTHER) {
if (PlayerUnderCursor != nullptr) {
NetSendCmdParam1(true, CMD_HEALOTHER, PlayerUnderCursor->getId());
NetSendCmdParam1(true, CMD_HEALOTHER, static_cast<uint16_t>(PlayerUnderCursor->getId()));
NewCursor(CURSOR_HAND);
return true;
}
Expand Down Expand Up @@ -2579,7 +2579,7 @@ bool TryIconCurs()
} else if (pcursmonst != -1) {
NetSendCmdParam5(true, CMD_SPELLID, pcursmonst, static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellLevel, spellFrom);
} else if (PlayerUnderCursor != nullptr && !myPlayer.friendlyMode) {
NetSendCmdParam5(true, CMD_SPELLPID, PlayerUnderCursor->getId(), static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellLevel, spellFrom);
NetSendCmdParam5(true, CMD_SPELLPID, static_cast<uint16_t>(PlayerUnderCursor->getId()), static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellLevel, spellFrom);
} else {
NetSendCmdLocParam4(true, CMD_SPELLXY, cursPosition, static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellLevel, spellFrom);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2131,7 +2131,7 @@ void DoTelekinesis()
if (ObjectUnderCursor != nullptr && !ObjectUnderCursor->IsDisabled())
NetSendCmdLoc(MyPlayerId, true, CMD_OPOBJT, cursPosition);
if (pcursitem != -1)
NetSendCmdGItem(true, CMD_REQUESTAGITEM, static_cast<uint8_t>(MyPlayerId), pcursitem);
NetSendCmdGItem(true, CMD_REQUESTAGITEM, *MyPlayer, pcursitem);
if (pcursmonst != -1) {
auto &monter = Monsters[pcursmonst];
if (!M_Talker(monter) && monter.talkMsg == TEXT_NONE)
Expand Down
10 changes: 4 additions & 6 deletions Source/missiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,8 @@ bool MonsterMHit(int pnum, int monsterId, int mindam, int maxdam, int dist, Miss
return true;
}

bool Plr2PlrMHit(const Player &player, int p, int mindam, int maxdam, int dist, MissileID mtype, DamageType damageType, bool shift, bool *blocked)
bool Plr2PlrMHit(const Player &player, Player &target, int mindam, int maxdam, int dist, MissileID mtype, DamageType damageType, bool shift, bool *blocked)
{
Player &target = Players[p];

if (sgGameInitInfo.bFriendlyFire == 0 && player.friendlyMode)
return false;

Expand Down Expand Up @@ -366,7 +364,7 @@ bool Plr2PlrMHit(const Player &player, int p, int mindam, int maxdam, int dist,
if (resper > 0) {
dam -= (dam * resper) / 100;
if (&player == MyPlayer)
NetSendCmdDamage(true, p, dam, damageType);
NetSendCmdDamage(true, target, dam, damageType);
target.Say(HeroSpeech::ArghClang);
return true;
}
Expand All @@ -376,7 +374,7 @@ bool Plr2PlrMHit(const Player &player, int p, int mindam, int maxdam, int dist,
*blocked = true;
} else {
if (&player == MyPlayer)
NetSendCmdDamage(true, p, dam, damageType);
NetSendCmdDamage(true, target, dam, damageType);
StartPlrHit(target, dam, false);
}

Expand Down Expand Up @@ -441,7 +439,7 @@ void CheckMissileCol(Missile &missile, DamageType damageType, int minDamage, int
if (missile._micaster != TARGET_BOTH && !missile.IsTrap()) {
if (missile._micaster == TARGET_MONSTERS) {
if ((pid - 1) != missile._misource)
isPlayerHit = Plr2PlrMHit(Players[missile._misource], pid - 1, minDamage, maxDamage, missile._midist, missile._mitype, damageType, isDamageShifted, &blocked);
isPlayerHit = Plr2PlrMHit(Players[missile._misource], Players[pid - 1], minDamage, maxDamage, missile._midist, missile._mitype, damageType, isDamageShifted, &blocked);
} else {
Monster &monster = Monsters[missile._misource];
isPlayerHit = PlayerMHit(pid - 1, &monster, missile._midist, minDamage, maxDamage, missile._mitype, damageType, isDamageShifted, DeathReason::MonsterOrTrap, &blocked);
Expand Down
20 changes: 11 additions & 9 deletions Source/msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,14 +878,14 @@ void NetSendCmdGItem2(bool usonly, _cmd_id bCmd, uint8_t mast, uint8_t pnum, con
tmsg_add((std::byte *)&cmd, sizeof(cmd));
}

bool NetSendCmdReq2(_cmd_id bCmd, uint8_t mast, uint8_t pnum, const TCmdGItem &item)
bool NetSendCmdReq2(_cmd_id bCmd, const Player &player, uint8_t pnum, const TCmdGItem &item)
{
TCmdGItem cmd;

memcpy(&cmd, &item, sizeof(cmd));
cmd.bCmd = bCmd;
cmd.bPnum = pnum;
cmd.bMaster = mast;
cmd.bMaster = static_cast<uint8_t>(player.getId());

int ticks = SDL_GetTicks();
if (cmd.dwTime == 0)
Expand Down Expand Up @@ -1162,13 +1162,13 @@ size_t OnRequestGetItem(const TCmd *pCmd, Player &player)
}

if (ii != -1) {
NetSendCmdGItem2(false, CMD_GETITEM, MyPlayerId, message.bPnum, message);
NetSendCmdGItem2(false, CMD_GETITEM, static_cast<uint8_t>(MyPlayerId), message.bPnum, message);
if (message.bPnum != MyPlayerId)
SyncGetItem(position, dwSeed, wIndx, wCI);
else
InvGetItem(*MyPlayer, ii);
SetItemRecord(dwSeed, wCI, wIndx);
} else if (!NetSendCmdReq2(CMD_REQUESTGITEM, MyPlayerId, message.bPnum, message)) {
} else if (!NetSendCmdReq2(CMD_REQUESTGITEM, *MyPlayer, message.bPnum, message)) {
NetSendCmdExtra(message);
}
}
Expand Down Expand Up @@ -1238,13 +1238,13 @@ size_t OnRequestAutoGetItem(const TCmd *pCmd, Player &player)
const _item_indexes wIndx = static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx));
if (GetItemRecord(dwSeed, wCI, wIndx)) {
if (FindGetItem(dwSeed, wIndx, wCI) != -1) {
NetSendCmdGItem2(false, CMD_AGETITEM, MyPlayerId, message.bPnum, message);
NetSendCmdGItem2(false, CMD_AGETITEM, static_cast<uint8_t>(MyPlayerId), message.bPnum, message);
if (message.bPnum != MyPlayerId)
SyncGetItem(position, dwSeed, wIndx, wCI);
else
AutoGetItem(*MyPlayer, &Items[message.bCursitem], message.bCursitem);
SetItemRecord(dwSeed, wCI, wIndx);
} else if (!NetSendCmdReq2(CMD_REQUESTAGITEM, MyPlayerId, message.bPnum, message)) {
} else if (!NetSendCmdReq2(CMD_REQUESTAGITEM, *MyPlayer, message.bPnum, message)) {
NetSendCmdExtra(message);
}
}
Expand Down Expand Up @@ -2968,8 +2968,10 @@ void NetSendCmdQuest(bool bHiPri, const Quest &quest)
NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
}

void NetSendCmdGItem(bool bHiPri, _cmd_id bCmd, uint8_t pnum, uint8_t ii)
void NetSendCmdGItem(bool bHiPri, _cmd_id bCmd, const Player &player, uint8_t ii)
{
uint8_t pnum = static_cast<uint8_t>(player.getId());

TCmdGItem cmd;

cmd.bCmd = bCmd;
Expand Down Expand Up @@ -3080,12 +3082,12 @@ void NetSendCmdChBeltItem(bool bHiPri, int beltIndex)
NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd));
}

void NetSendCmdDamage(bool bHiPri, uint8_t bPlr, uint32_t dwDam, DamageType damageType)
void NetSendCmdDamage(bool bHiPri, const Player &player, uint32_t dwDam, DamageType damageType)
{
TCmdDamage cmd;

cmd.bCmd = CMD_PLRDAMAGE;
cmd.bPlr = bPlr;
cmd.bPlr = static_cast<uint8_t>(player.getId());
cmd.dwDam = dwDam;
cmd.damageType = damageType;
if (bHiPri)
Expand Down
4 changes: 2 additions & 2 deletions Source/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -753,14 +753,14 @@ void NetSendCmdParam1(bool bHiPri, _cmd_id bCmd, uint16_t wParam1);
void NetSendCmdParam2(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wParam2);
void NetSendCmdParam5(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wParam2, uint16_t wParam3, uint16_t wParam4, uint16_t wParam5);
void NetSendCmdQuest(bool bHiPri, const Quest &quest);
void NetSendCmdGItem(bool bHiPri, _cmd_id bCmd, uint8_t pnum, uint8_t ii);
void NetSendCmdGItem(bool bHiPri, _cmd_id bCmd, const Player &player, uint8_t ii);
void NetSendCmdPItem(bool bHiPri, _cmd_id bCmd, Point position, const Item &item);
void NetSyncInvItem(const Player &player, int invListIndex);
void NetSendCmdChItem(bool bHiPri, uint8_t bLoc, bool forceSpellChange = false);
void NetSendCmdDelItem(bool bHiPri, uint8_t bLoc);
void NetSendCmdChInvItem(bool bHiPri, int invGridIndex);
void NetSendCmdChBeltItem(bool bHiPri, int invGridIndex);
void NetSendCmdDamage(bool bHiPri, uint8_t bPlr, uint32_t dwDam, DamageType damageType);
void NetSendCmdDamage(bool bHiPri, const Player &player, uint32_t dwDam, DamageType damageType);
void NetSendCmdMonDmg(bool bHiPri, uint16_t wMon, uint32_t dwDam);
void NetSendCmdString(uint32_t pmask, const char *pszStr);
void delta_close_portal(const Player &player);
Expand Down
12 changes: 5 additions & 7 deletions Source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ void WalkNorthwards(Player &player, const DirectionSettings &walkParams)

void WalkSouthwards(Player &player, const DirectionSettings & /*walkParams*/)
{
const size_t playerId = player.getId();
player.position.temp = player.position.tile;
player.position.tile = player.position.future; // Move player to the next tile to maintain correct render order
player.occupyTile(player.position.temp, true);
Expand All @@ -97,7 +96,6 @@ void WalkSideways(Player &player, const DirectionSettings &walkParams)
{
Point const nextPosition = player.position.tile + walkParams.map;

const size_t playerId = player.getId();
player.occupyTile(player.position.tile, true);
player.occupyTile(player.position.future, false);

Expand Down Expand Up @@ -798,7 +796,7 @@ bool PlrHitPlr(Player &attacker, Player &target)
RedrawComponent(PanelDrawComponent::Health);
}
if (&attacker == MyPlayer) {
NetSendCmdDamage(true, target.getId(), skdam, DamageType::Physical);
NetSendCmdDamage(true, target, skdam, DamageType::Physical);
}
StartPlrHit(target, skdam, false);

Expand Down Expand Up @@ -1343,7 +1341,7 @@ void CheckNewPath(Player &player, bool pmWillBeCalled)
x = std::abs(player.position.tile.x - item->position.x);
y = std::abs(player.position.tile.y - item->position.y);
if (x <= 1 && y <= 1 && pcurs == CURSOR_HAND && !item->_iRequest) {
NetSendCmdGItem(true, CMD_REQUESTGITEM, player.getId(), targetId);
NetSendCmdGItem(true, CMD_REQUESTGITEM, player, targetId);
item->_iRequest = true;
}
}
Expand All @@ -1353,7 +1351,7 @@ void CheckNewPath(Player &player, bool pmWillBeCalled)
x = std::abs(player.position.tile.x - item->position.x);
y = std::abs(player.position.tile.y - item->position.y);
if (x <= 1 && y <= 1 && pcurs == CURSOR_HAND) {
NetSendCmdGItem(true, CMD_REQUESTAGITEM, player.getId(), targetId);
NetSendCmdGItem(true, CMD_REQUESTAGITEM, player, targetId);
}
}
break;
Expand Down Expand Up @@ -1614,7 +1612,7 @@ void Player::RemoveInvItem(int iv, bool calcScrolls)
for (size_t i = 0; i < InventoryGridCells; i++) {
int8_t itemIndex = InvGrid[i];
if (std::abs(itemIndex) - 1 == iv) {
NetSendCmdParam1(false, CMD_DELINVITEMS, i);
NetSendCmdParam1(false, CMD_DELINVITEMS, static_cast<uint16_t>(i));
break;
}
}
Expand Down Expand Up @@ -3213,7 +3211,7 @@ void CheckPlrSpell(bool isShiftHeld, SpellID spellID, SpellType spellType)
NetSendCmdParam5(true, CMD_SPELLID, pcursmonst, static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellLevel, spellFrom);
} else if (PlayerUnderCursor != nullptr && !isShiftHeld && !myPlayer.friendlyMode) {
LastMouseButtonAction = MouseActionType::SpellPlayerTarget;
NetSendCmdParam5(true, CMD_SPELLPID, PlayerUnderCursor->getId(), static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellLevel, spellFrom);
NetSendCmdParam5(true, CMD_SPELLPID, static_cast<uint16_t>(PlayerUnderCursor->getId()), static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellLevel, spellFrom);
} else {
LastMouseButtonAction = MouseActionType::Spell;
NetSendCmdLocParam4(true, CMD_SPELLXY, cursPosition, static_cast<int8_t>(spellID), static_cast<uint8_t>(spellType), spellLevel, spellFrom);
Expand Down
2 changes: 1 addition & 1 deletion Source/qol/autopickup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void AutoPickup(const Player &player)
int itemIndex = dItem[tile.x][tile.y] - 1;
auto &item = Items[itemIndex];
if (DoPickup(item)) {
NetSendCmdGItem(true, CMD_REQUESTAGITEM, static_cast<uint8_t>(player.getId()), itemIndex);
NetSendCmdGItem(true, CMD_REQUESTAGITEM, player, itemIndex);
item._iRequest = true;
}
}
Expand Down

0 comments on commit 6052aa1

Please sign in to comment.