Browse Source

♻️Unfold a few functions

pull/1907/head
Anders Jenbo 5 years ago
parent
commit
35b2aa4947
  1. 24
      Source/multi.cpp
  2. 15
      Source/player.cpp
  3. 79
      Source/spells.cpp
  4. 2
      Source/spells.h

24
Source/multi.cpp

@ -832,7 +832,6 @@ void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, bool recv)
return;
}
assert((DWORD)pnum < MAX_PLRS);
auto &player = plr[pnum];
if (sgwPackPlrOffsetTbl[pnum] != p->wOffset) {
@ -872,17 +871,20 @@ void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, bool recv)
SyncInitPlr(pnum);
if (player.plrlevel == currlevel) {
if (player._pHitPoints >> 6 > 0) {
StartStand(pnum, DIR_S);
} else {
player._pgfxnum = 0;
player._pmode = PM_DEATH;
NewPlrAnim(player, player_graphic::Death, DIR_S, player._pDFrames, 1);
player.AnimInfo.CurrentFrame = player.AnimInfo.NumberOfFrames - 1;
dFlags[player.position.tile.x][player.position.tile.y] |= BFLAG_DEAD_PLAYER;
}
if (player.plrlevel != currlevel) {
return;
}
if (player._pHitPoints >> 6 > 0) {
StartStand(pnum, DIR_S);
return;
}
player._pgfxnum = 0;
player._pmode = PM_DEATH;
NewPlrAnim(player, player_graphic::Death, DIR_S, player._pDFrames, 1);
player.AnimInfo.CurrentFrame = player.AnimInfo.NumberOfFrames - 1;
dFlags[player.position.tile.x][player.position.tile.y] |= BFLAG_DEAD_PLAYER;
}
} // namespace devilution

15
Source/player.cpp

@ -692,13 +692,14 @@ void InitPlayerGFX(PlayerStruct &player)
if (player._pHitPoints >> 6 == 0) {
player._pgfxnum = 0;
LoadPlrGFX(player, player_graphic::Death);
} else {
for (size_t i = 0; i < enum_size<player_graphic>::value; i++) {
auto graphic = static_cast<player_graphic>(i);
if (graphic == player_graphic::Death)
continue;
LoadPlrGFX(player, graphic);
}
return;
}
for (size_t i = 0; i < enum_size<player_graphic>::value; i++) {
auto graphic = static_cast<player_graphic>(i);
if (graphic == player_graphic::Death)
continue;
LoadPlrGFX(player, graphic);
}
}

79
Source/spells.cpp

@ -154,29 +154,26 @@ void EnsureValidReadiedSpell(PlayerStruct &player)
bool CheckSpell(int id, spell_id sn, spell_type st, bool manaonly)
{
bool result;
#ifdef _DEBUG
if (debug_mode_key_inverted_v)
return true;
#endif
result = true;
if (!manaonly && pcurs != CURSOR_HAND) {
result = false;
} else {
if (st != RSPLTYPE_SKILL) {
if (GetSpellLevel(id, sn) <= 0) {
result = false;
} else {
auto &player = plr[id];
return false;
}
return player._pMana >= GetManaAmount(player, sn);
}
}
if (st == RSPLTYPE_SKILL) {
return true;
}
return result;
if (GetSpellLevel(id, sn) <= 0) {
return false;
}
auto &player = plr[id];
return player._pMana >= GetManaAmount(player, sn);
}
void CastSpell(int id, int spl, int sx, int sy, int dx, int dy, int spllvl)
@ -294,48 +291,42 @@ void DoResurrect(int pnum, int rid)
}
}
void DoHealOther(int pnum, int rid)
void DoHealOther(int pnum, uint16_t rid)
{
int i, j, hp;
if (pnum == myplr) {
NewCursor(CURSOR_HAND);
}
if ((DWORD)pnum >= MAX_PLRS || rid >= MAX_PLRS) {
return;
}
auto &player = plr[pnum];
auto &target = plr[rid];
if ((char)rid != -1 && (target._pHitPoints >> 6) > 0) {
hp = (GenerateRnd(10) + 1) << 6;
for (i = 0; i < player._pLevel; i++) {
hp += (GenerateRnd(4) + 1) << 6;
}
for (j = 0; j < GetSpellLevel(pnum, SPL_HEALOTHER); ++j) {
hp += (GenerateRnd(6) + 1) << 6;
}
if (player._pClass == HeroClass::Warrior || player._pClass == HeroClass::Barbarian) {
hp *= 2;
} else if (player._pClass == HeroClass::Rogue || player._pClass == HeroClass::Bard) {
hp += hp / 2;
} else if (player._pClass == HeroClass::Monk) {
hp *= 3;
}
target._pHitPoints += hp;
if ((target._pHitPoints >> 6) <= 0) {
return;
}
if (target._pHitPoints > target._pMaxHP) {
target._pHitPoints = target._pMaxHP;
}
int hp = (GenerateRnd(10) + 1) << 6;
for (int i = 0; i < player._pLevel; i++) {
hp += (GenerateRnd(4) + 1) << 6;
}
for (int i = 0; i < GetSpellLevel(pnum, SPL_HEALOTHER); i++) {
hp += (GenerateRnd(6) + 1) << 6;
}
target._pHPBase += hp;
if (player._pClass == HeroClass::Warrior || player._pClass == HeroClass::Barbarian) {
hp *= 2;
} else if (player._pClass == HeroClass::Rogue || player._pClass == HeroClass::Bard) {
hp += hp / 2;
} else if (player._pClass == HeroClass::Monk) {
hp *= 3;
}
if (target._pHPBase > target._pMaxHPBase) {
target._pHPBase = target._pMaxHPBase;
}
target._pHitPoints = std::min(target._pHitPoints + hp, target._pMaxHP);
target._pHPBase = std::min(target._pHPBase + hp, target._pMaxHPBase);
if (rid == myplr) {
drawhpflag = true;
}
}

2
Source/spells.h

@ -15,7 +15,7 @@ bool CheckSpell(int id, spell_id sn, spell_type st, bool manaonly);
void EnsureValidReadiedSpell(PlayerStruct &player);
void CastSpell(int id, int spl, int sx, int sy, int dx, int dy, int spllvl);
void DoResurrect(int pnum, int rid);
void DoHealOther(int pnum, int rid);
void DoHealOther(int pnum, uint16_t rid);
int GetSpellBookLevel(spell_id s);
int GetSpellStaffLevel(spell_id s);

Loading…
Cancel
Save