Skip to content

Commit

Permalink
Change some functions to Player reference
Browse files Browse the repository at this point in the history
  • Loading branch information
obligaron authored and AJenbo committed Dec 5, 2023
1 parent b42b722 commit 2da492d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
14 changes: 6 additions & 8 deletions Source/controls/plrctrls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,13 +1274,11 @@ bool IsPathBlocked(Point position, Direction dir)
return !PosOkPlayer(myPlayer, leftStep) && !PosOkPlayer(myPlayer, rightStep);
}

void WalkInDir(size_t playerId, AxisDirection dir)
void WalkInDir(Player &player, AxisDirection dir)
{
Player &player = Players[playerId];

if (dir.x == AxisDirectionX_NONE && dir.y == AxisDirectionY_NONE) {
if (ControlMode != ControlTypes::KeyboardAndMouse && player.walkpath[0] != WALK_NONE && player.destAction == ACTION_NONE)
NetSendCmdLoc(playerId, true, CMD_WALKXY, player.position.future); // Stop walking
NetSendCmdLoc(player.getId(), true, CMD_WALKXY, player.position.future); // Stop walking
return;
}

Expand All @@ -1302,7 +1300,7 @@ void WalkInDir(size_t playerId, AxisDirection dir)
return; // Don't start backtrack around obstacles
}

NetSendCmdLoc(playerId, true, CMD_WALKXY, delta);
NetSendCmdLoc(player.getId(), true, CMD_WALKXY, delta);
}

void QuestLogMove(AxisDirection moveDir)
Expand Down Expand Up @@ -1360,13 +1358,13 @@ void ProcessLeftStickOrDPadGameUI()
handler(GetLeftStickOrDpadDirection(false));
}

void Movement(size_t playerId)
void Movement(Player &player)
{
if (PadMenuNavigatorActive || PadHotspellMenuActive || InGameMenu())
return;

if (GetLeftStickOrDPadGameUIHandler() == nullptr) {
WalkInDir(playerId, GetMoveDirection());
WalkInDir(player, GetMoveDirection());
}
}

Expand Down Expand Up @@ -1779,7 +1777,7 @@ void plrctrls_every_frame()

void plrctrls_after_game_logic()
{
Movement(MyPlayerId);
Movement(*MyPlayer);
}

void UseBeltItem(int type)
Expand Down
2 changes: 1 addition & 1 deletion Source/inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,7 @@ bool UseInvItem(int cii)
else if (&player == MyPlayer)
PlaySFX(ItemInvSnds[idata]);

UseItem(player.getId(), item->_iMiscId, item->_iSpell, cii);
UseItem(player, item->_iMiscId, item->_iSpell, cii);

if (speedlist) {
if (player.SpdList[c]._iMiscId == IMISC_NOTE) {
Expand Down
3 changes: 1 addition & 2 deletions Source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3981,9 +3981,8 @@ void PrintItemDur(const Item &item)
PrintItemInfo(item);
}

void UseItem(size_t pnum, item_misc_id mid, SpellID spellID, int spellFrom)
void UseItem(Player &player, item_misc_id mid, SpellID spellID, int spellFrom)
{
Player &player = Players[pnum];
std::optional<SpellID> prepareSpellID;

switch (mid) {
Expand Down
2 changes: 1 addition & 1 deletion Source/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ bool DoOil(Player &player, int cii);
void DrawUniqueInfo(const Surface &out);
void PrintItemDetails(const Item &item);
void PrintItemDur(const Item &item);
void UseItem(size_t pnum, item_misc_id Mid, SpellID spellID, int spellFrom);
void UseItem(Player &player, item_misc_id Mid, SpellID spellID, int spellFrom);
bool UseItemOpensHive(const Item &item, Point position);
bool UseItemOpensGrave(const Item &item, Point position);
void SpawnSmith(int lvl);
Expand Down
2 changes: 1 addition & 1 deletion Source/qol/stash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ bool UseStashItem(uint16_t c)
else
PlaySFX(ItemInvSnds[ItemCAnimTbl[item->_iCurs]]);

UseItem(MyPlayerId, item->_iMiscId, item->_iSpell, -1);
UseItem(*MyPlayer, item->_iMiscId, item->_iSpell, -1);

if (Stash.stashList[c]._iMiscId == IMISC_MAPOFDOOM)
return true;
Expand Down

0 comments on commit 2da492d

Please sign in to comment.