Browse Source

Remove _pwtype and replace it with UsesRangedWeapon

pull/2415/head
obligaron 5 years ago committed by Anders Jenbo
parent
commit
70db8456ba
  1. 8
      Source/controls/plrctrls.cpp
  2. 2
      Source/diablo.cpp
  3. 2
      Source/items.cpp
  4. 4
      Source/loadsave.cpp
  5. 5
      Source/player.cpp
  6. 14
      Source/player.h
  7. 2
      Source/track.cpp
  8. 2
      test/writehero_test.cpp

8
Source/controls/plrctrls.cpp

@ -303,7 +303,7 @@ void FindMeleeTarget()
void CheckMonstersNearby()
{
if (Players[MyPlayerId]._pwtype == WT_RANGED || HasRangedSpell()) {
if (Players[MyPlayerId].UsesRangedWeapon() || HasRangedSpell()) {
FindRangedTarget();
return;
}
@ -337,7 +337,7 @@ void CheckPlayerNearby()
|| (player._pHitPoints == 0 && spl != SPL_RESURRECT))
continue;
if (myPlayer._pwtype == WT_RANGED || HasRangedSpell() || spl == SPL_HEALOTHER) {
if (myPlayer.UsesRangedWeapon() || HasRangedSpell() || spl == SPL_HEALOTHER) {
newDdistance = GetDistanceRanged(player.position.future);
} else {
newDdistance = GetDistance(player.position.future, distance);
@ -440,13 +440,13 @@ void Interact()
if (leveltype == DTYPE_TOWN && pcursmonst != -1) {
NetSendCmdLocParam1(true, CMD_TALKXY, Towners[pcursmonst].position, pcursmonst);
} else if (pcursmonst != -1) {
if (Players[MyPlayerId]._pwtype != WT_RANGED || CanTalkToMonst(Monsters[pcursmonst])) {
if (!Players[MyPlayerId].UsesRangedWeapon() || CanTalkToMonst(Monsters[pcursmonst])) {
NetSendCmdParam1(true, CMD_ATTACKID, pcursmonst);
} else {
NetSendCmdParam1(true, CMD_RATTACKID, pcursmonst);
}
} else if (leveltype != DTYPE_TOWN && pcursplr != -1 && !gbFriendlyMode) {
NetSendCmdParam1(true, Players[MyPlayerId]._pwtype == WT_RANGED ? CMD_RATTACKPID : CMD_ATTACKPID, pcursplr);
NetSendCmdParam1(true, Players[MyPlayerId].UsesRangedWeapon() ? CMD_RATTACKPID : CMD_ATTACKPID, pcursplr);
}
}

2
Source/diablo.cpp

@ -252,7 +252,7 @@ bool LeftMouseCmd(bool bShift)
NetSendCmdLocParam1(true, invflag ? CMD_GOTOGETITEM : CMD_GOTOAGETITEM, { cursmx, cursmy }, pcursitem);
} else if (pcursobj != -1 && (!objectIsDisabled(pcursobj)) && (!bShift || (bNear && Objects[pcursobj]._oBreak == 1))) {
NetSendCmdLocParam1(true, pcurs == CURSOR_DISARM ? CMD_DISARMXY : CMD_OPOBJXY, { cursmx, cursmy }, pcursobj);
} else if (myPlayer._pwtype == WT_RANGED) {
} else if (myPlayer.UsesRangedWeapon()) {
if (bShift) {
lastLeftMouseButtonAction = MouseActionType::Attack;
NetSendCmdLoc(MyPlayerId, true, CMD_RATTACKXY, { cursmx, cursmy });

2
Source/items.cpp

@ -2880,7 +2880,6 @@ void CalcPlrItemVals(int playerId, bool loadgfx)
if (player.InvBody[INVLOC_HAND_RIGHT]._iClass == ICLASS_WEAPON && player.InvBody[INVLOC_HAND_RIGHT]._iLoc != ILOC_TWOHAND && player.InvBody[INVLOC_HAND_LEFT].isEmpty())
player._pBlockFlag = true;
}
player._pwtype = WT_MELEE;
item_type weaponItemType = item_type::ITYPE_NONE;
bool holdsShield = false;
@ -2914,7 +2913,6 @@ void CalcPlrItemVals(int playerId, bool loadgfx)
animWeaponId = PlayerWeaponGraphic::Axe;
break;
case ITYPE_BOW:
player._pwtype = WT_RANGED;
animWeaponId = PlayerWeaponGraphic::Bow;
break;
case ITYPE_MACE:

4
Source/loadsave.cpp

@ -374,7 +374,7 @@ void LoadPlayer(LoadHelper *file, int p)
for (auto &spellType : player._pSplTHotKey)
spellType = static_cast<spell_type>(file->NextLE<int8_t>());
player._pwtype = static_cast<player_weapon_type>(file->NextLE<int32_t>());
file->Skip<int32_t>(); // Skip _pwtype
player._pBlockFlag = file->NextBool8();
player._pInvincible = file->NextBool8();
player._pLightRad = file->NextLE<int8_t>();
@ -1047,7 +1047,7 @@ void SavePlayer(SaveHelper *file, int p)
for (auto &spellType : player._pSplTHotKey)
file->WriteLE<int8_t>(spellType);
file->WriteLE<int32_t>(player._pwtype);
file->WriteLE<int32_t>(player.UsesRangedWeapon() ? 1 : 0);
file->WriteLE<uint8_t>(player._pBlockFlag ? 1 : 0);
file->WriteLE<uint8_t>(player._pInvincible ? 1 : 0);
file->WriteLE<int8_t>(player._pLightRad);

5
Source/player.cpp

@ -1191,11 +1191,6 @@ void InitPlayer(int pnum, bool firstTime)
player._pSBkSpell = SPL_INVALID;
player._pSpell = player._pRSpell;
player._pSplType = player._pRSplType;
if (static_cast<PlayerWeaponGraphic>((player._pgfxnum & 0xF)) == PlayerWeaponGraphic::Bow) {
player._pwtype = WT_RANGED;
} else {
player._pwtype = WT_MELEE;
}
player.pManaShield = false;
}

14
Source/player.h

@ -144,11 +144,6 @@ enum action_id : int8_t {
// clang-format on
};
enum player_weapon_type : uint8_t {
WT_MELEE,
WT_RANGED,
};
/**
* @brief Contains Data (CelSprites) for a player graphic (player_graphic)
*/
@ -201,7 +196,6 @@ struct PlayerStruct {
uint8_t _pSpellFlags;
spell_id _pSplHotKey[4];
spell_type _pSplTHotKey[4];
player_weapon_type _pwtype;
bool _pBlockFlag;
bool _pInvincible;
int8_t _pLightRad;
@ -432,6 +426,14 @@ struct PlayerStruct {
return _pManaPer;
}
/**
* @brief Does the player currently have a ranged weapon equipped?
*/
bool UsesRangedWeapon() const
{
return static_cast<PlayerWeaponGraphic>(_pgfxnum & 0xF) == PlayerWeaponGraphic::Bow;
};
};
extern int MyPlayerId;

2
Source/track.cpp

@ -44,7 +44,7 @@ static bool RepeatMouseAttack(bool leftButton)
return false;
if (Players[MyPlayerId]._pmode != PM_DEATH && Players[MyPlayerId]._pmode != PM_QUIT && Players[MyPlayerId].destAction == ACTION_NONE && SDL_GetTicks() - *timePressed >= (Uint32)gnTickDelay * 4) {
bool rangedAttack = Players[MyPlayerId]._pwtype == WT_RANGED;
bool rangedAttack = Players[MyPlayerId].UsesRangedWeapon();
*timePressed = SDL_GetTicks();
switch (lastAction) {
case MouseActionType::Attack:

2
test/writehero_test.cpp

@ -306,7 +306,7 @@ static void AssertPlayer(PlayerStruct &player)
ASSERT_EQ(player._pAblSpells, 134217728);
ASSERT_EQ(player._pScrlSpells, 0);
ASSERT_EQ(player._pSpellFlags, 0);
ASSERT_EQ(player._pwtype, 1);
ASSERT_TRUE(player.UsesRangedWeapon());
ASSERT_EQ(player._pBlockFlag, 0);
ASSERT_EQ(player._pLightRad, 11);
ASSERT_EQ(player._pDamageMod, 101);

Loading…
Cancel
Save