diff --git a/Source/control.cpp b/Source/control.cpp index dfd17db13..24582d01e 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -675,7 +675,7 @@ void ToggleSpell(int slot) break; } - if (spells & (__int64)1 << (plr[myplr]._pSplHotKey[slot] - 1)) { + if (spells & SPELLBIT(plr[myplr]._pSplHotKey[slot])) { plr[myplr]._pRSpell = plr[myplr]._pSplHotKey[slot]; plr[myplr]._pRSplType = plr[myplr]._pSplTHotKey[slot]; force_redraw = 255; @@ -2462,13 +2462,13 @@ char GetSBookTrans(int ii, BOOL townok) return RSPLTYPE_SKILL; #endif st = RSPLTYPE_SPELL; - if (plr[myplr]._pISpells & (__int64)1 << (ii - 1)) { + if (plr[myplr]._pISpells & SPELLBIT(ii)) { st = RSPLTYPE_CHARGES; } #ifdef HELLFIRE - if (plr[myplr]._pAblSpells & (__int64)1 << (ii - 1)) { + if (plr[myplr]._pAblSpells & SPELLBIT(ii)) { #else - if (plr[myplr]._pAblSpells & 1 << (ii - 1)) { /// BUGFIX: missing (__int64) + if (plr[myplr]._pAblSpells & 1 << (ii - 1)) { /// BUGFIX: missing (__int64) - use SPELLBIT(ii) macro #endif st = RSPLTYPE_SKILL; } @@ -2506,7 +2506,7 @@ void DrawSpellBook() yp = 55 + SCREEN_Y; for (i = 1; i < 8; i++) { sn = SpellPages[sbooktab][i - 1]; - if (sn != -1 && spl & (__int64)1 << (sn - 1)) { + if (sn != -1 && spl & SPELLBIT(sn)) { st = GetSBookTrans(sn, TRUE); SetSpellTrans(st); DrawSpellCel(RIGHT_PANEL_X + 11, yp, pSBkIconCels, SpellITbl[sn], 37); @@ -2560,12 +2560,12 @@ void CheckSBook() if (MouseX >= RIGHT_PANEL + 11 && MouseX < RIGHT_PANEL + 48 && MouseY >= 18 && MouseY < 314) { sn = SpellPages[sbooktab][(MouseY - 18) / 43]; spl = plr[myplr]._pMemSpells | plr[myplr]._pISpells | plr[myplr]._pAblSpells; - if (sn != -1 && spl & (__int64)1 << (sn - 1)) { + if (sn != -1 && spl & SPELLBIT(sn)) { st = RSPLTYPE_SPELL; - if (plr[myplr]._pISpells & (__int64)1 << (sn - 1)) { + if (plr[myplr]._pISpells & SPELLBIT(sn)) { st = RSPLTYPE_CHARGES; } - if (plr[myplr]._pAblSpells & (__int64)1 << (sn - 1)) { + if (plr[myplr]._pAblSpells & SPELLBIT(sn)) { st = RSPLTYPE_SKILL; } plr[myplr]._pRSpell = sn; diff --git a/Source/debug.cpp b/Source/debug.cpp index 3dda266b6..feb910a7c 100644 --- a/Source/debug.cpp +++ b/Source/debug.cpp @@ -160,7 +160,7 @@ void MaxSpellsCheat() for (i = 1; i < MAX_SPELLS; i++) { if (spelldata[i].sBookLvl != -1) { - plr[myplr]._pMemSpells |= (__int64)1 << (i - 1); + plr[myplr]._pMemSpells |= SPELLBIT(i); plr[myplr]._pSplLvl[i] = 10; } } @@ -168,7 +168,7 @@ void MaxSpellsCheat() void SetSpellLevelCheat(char spl, int spllvl) { - plr[myplr]._pMemSpells |= (__int64)1 << (spl - 1); + plr[myplr]._pMemSpells |= SPELLBIT(spl); plr[myplr]._pSplLvl[spl] = spllvl; } diff --git a/Source/inv.cpp b/Source/inv.cpp index da20fae26..d1f938bdf 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -1697,6 +1697,7 @@ void RemoveInvItem(int pnum, int iv) if (plr[pnum]._pRSpell != SPL_INVALID) { // BUGFIX: Cast the literal `1` to `unsigned __int64` to make that bitshift 64bit // this causes the last 4 skills to not reset correctly after use + // replace with SPELLBIT(plr[pnum]._pRSpell) if (!( plr[pnum]._pScrlSpells & (1 << (plr[pnum]._pRSpell - 1)))) { @@ -1761,6 +1762,7 @@ void RemoveSpdBarItem(int pnum, int iv) if (plr[pnum]._pRSpell != SPL_INVALID) { // BUGFIX: Cast the literal `1` to `unsigned __int64` to make that bitshift 64bit // this causes the last 4 skills to not reset correctly after use + // replace with SPELLBIT(plr[pnum]._pRSpell) if (!( plr[pnum]._pScrlSpells & (1 << (plr[pnum]._pRSpell - 1)))) { diff --git a/Source/items.cpp b/Source/items.cpp index 056f0aa9b..e6fa18e74 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -727,7 +727,7 @@ void CalcPlrItemVals(int p, BOOL Loadgfx) maxd += itm->_iMaxDam; if (itm->_iSpell != SPL_NULL) { - spl |= (unsigned __int64)1 << (itm->_iSpell - 1); + spl |= SPELLBIT(itm->_iSpell); } if (itm->_iMagical == ITEM_QUALITY_NORMAL || itm->_iIdentified) { @@ -906,7 +906,7 @@ void CalcPlrItemVals(int p, BOOL Loadgfx) // check if the current RSplType is a valid/allowed spell if (plr[p]._pRSplType == RSPLTYPE_CHARGES - && !(spl & ((unsigned __int64)1 << (plr[p]._pRSpell - 1)))) { + && !(spl & SPELLBIT(plr[p]._pRSpell))) { plr[p]._pRSpell = SPL_INVALID; plr[p]._pRSplType = RSPLTYPE_INVALID; force_redraw = 255; @@ -1154,18 +1154,18 @@ void CalcPlrScrolls(int p) for (i = 0; i < plr[p]._pNumInv; i++) { if (plr[p].InvList[i]._itype != ITYPE_NONE && (plr[p].InvList[i]._iMiscId == IMISC_SCROLL || plr[p].InvList[i]._iMiscId == IMISC_SCROLLT)) { if (plr[p].InvList[i]._iStatFlag) - plr[p]._pScrlSpells |= (__int64)1 << (plr[p].InvList[i]._iSpell - 1); + plr[p]._pScrlSpells |= SPELLBIT(plr[p].InvList[i]._iSpell); } } for (j = 0; j < MAXBELTITEMS; j++) { if (plr[p].SpdList[j]._itype != ITYPE_NONE && (plr[p].SpdList[j]._iMiscId == IMISC_SCROLL || plr[p].SpdList[j]._iMiscId == IMISC_SCROLLT)) { if (plr[p].SpdList[j]._iStatFlag) - plr[p]._pScrlSpells |= (__int64)1 << (plr[p].SpdList[j]._iSpell - 1); + plr[p]._pScrlSpells |= SPELLBIT(plr[p].SpdList[j]._iSpell); } } if (plr[p]._pRSplType == RSPLTYPE_SCROLL) { - if (!(plr[p]._pScrlSpells & 1 << (plr[p]._pRSpell - 1))) { + if (!(plr[p]._pScrlSpells & 1 << (plr[p]._pRSpell - 1))) { // BUGFIX: apply SPELLBIT macro plr[p]._pRSpell = SPL_INVALID; plr[p]._pRSplType = RSPLTYPE_INVALID; force_redraw = 255; @@ -1179,7 +1179,7 @@ void CalcPlrStaff(int p) if (plr[p].InvBody[INVLOC_HAND_LEFT]._itype != ITYPE_NONE && plr[p].InvBody[INVLOC_HAND_LEFT]._iStatFlag && plr[p].InvBody[INVLOC_HAND_LEFT]._iCharges > 0) { - plr[p]._pISpells |= (__int64)1 << (plr[p].InvBody[INVLOC_HAND_LEFT]._iSpell - 1); + plr[p]._pISpells |= SPELLBIT(plr[p].InvBody[INVLOC_HAND_LEFT]._iSpell); } } @@ -4681,8 +4681,8 @@ void UseItem(int p, int Mid, int spl) } break; case IMISC_BOOK: - plr[p]._pMemSpells |= (__int64)1 << (spl - 1); - if (plr[p]._pSplLvl[spl] < 15) + plr[p]._pMemSpells |= SPELLBIT(spl); + if (plr[p]._pSplLvl[spl] < MAX_SPELL_LEVEL) plr[p]._pSplLvl[spl]++; plr[p]._pMana += spelldata[spl].sManaCost << 6; if (plr[p]._pMana > plr[p]._pMaxMana) diff --git a/Source/objects.cpp b/Source/objects.cpp index 023f5651a..edab7e061 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -3064,8 +3064,8 @@ void OperateBook(int pnum, int i) return; if (setlvlnum == SL_BONECHAMB) { - plr[myplr]._pMemSpells |= ((__int64)1 << (SPL_GUARDIAN - 1)); - if (plr[pnum]._pSplLvl[SPL_GUARDIAN] < 15) + plr[myplr]._pMemSpells |= SPELLBIT(SPL_GUARDIAN); + if (plr[pnum]._pSplLvl[SPL_GUARDIAN] < MAX_SPELL_LEVEL) plr[myplr]._pSplLvl[SPL_GUARDIAN]++; quests[Q_SCHAMB]._qactive = QUEST_DONE; if (!deltaload) @@ -3743,22 +3743,22 @@ void OperateShrine(int pnum, int i, int sType) spell = 1; spells = plr[pnum]._pMemSpells; for (j = 0; j < MAX_SPELLS; j++) { - if (spells & spell) + if (spell & spells) cnt++; spell <<= 1; } if (cnt > 1) { spell = 1; - for (j = 1; j <= MAX_SPELLS; j++) { + for (j = SPL_FIREBOLT; j <= MAX_SPELLS; j++) { // BUGFIX: < MAX_SPELLS, there is no spell with MAX_SPELLS index if (plr[pnum]._pMemSpells & spell) { - if (plr[pnum]._pSplLvl[j] < 15) + if (plr[pnum]._pSplLvl[j] < MAX_SPELL_LEVEL) plr[pnum]._pSplLvl[j]++; } spell <<= 1; } do { r = random_(0, MAX_SPELLS); - } while (!(plr[pnum]._pMemSpells & ((__int64)1 << r))); + } while (!(plr[pnum]._pMemSpells & SPELLBIT(r + 1))); if (plr[pnum]._pSplLvl[r] >= 2) plr[pnum]._pSplLvl[r] -= 2; else @@ -3789,10 +3789,10 @@ void OperateShrine(int pnum, int i, int sType) return; if (pnum != myplr) return; - plr[pnum]._pMemSpells |= (__int64)1 << (SPL_FIREBOLT - 1); - if (plr[pnum]._pSplLvl[SPL_FIREBOLT] < 15) + plr[pnum]._pMemSpells |= SPELLBIT(SPL_FIREBOLT); + if (plr[pnum]._pSplLvl[SPL_FIREBOLT] < MAX_SPELL_LEVEL) plr[pnum]._pSplLvl[SPL_FIREBOLT]++; - if (plr[pnum]._pSplLvl[SPL_FIREBOLT] < 15) + if (plr[pnum]._pSplLvl[SPL_FIREBOLT] < MAX_SPELL_LEVEL) plr[pnum]._pSplLvl[SPL_FIREBOLT]++; t = plr[pnum]._pMaxManaBase / 10; v1 = plr[pnum]._pMana - plr[pnum]._pManaBase; @@ -3922,10 +3922,10 @@ void OperateShrine(int pnum, int i, int sType) case SHRINE_SACRED: if (deltaload || pnum != myplr) return; - plr[pnum]._pMemSpells |= (__int64)1 << (SPL_CBOLT - 1); - if (plr[pnum]._pSplLvl[SPL_CBOLT] < 15) + plr[pnum]._pMemSpells |= SPELLBIT(SPL_CBOLT); + if (plr[pnum]._pSplLvl[SPL_CBOLT] < MAX_SPELL_LEVEL) plr[pnum]._pSplLvl[SPL_CBOLT]++; - if (plr[pnum]._pSplLvl[SPL_CBOLT] < 15) + if (plr[pnum]._pSplLvl[SPL_CBOLT] < MAX_SPELL_LEVEL) plr[pnum]._pSplLvl[SPL_CBOLT]++; t = plr[pnum]._pMaxManaBase / 10; v1 = plr[pnum]._pMana - plr[pnum]._pManaBase; @@ -4025,10 +4025,10 @@ void OperateShrine(int pnum, int i, int sType) return; if (pnum != myplr) return; - plr[pnum]._pMemSpells |= (__int64)1 << (SPL_HBOLT - 1); - if (plr[pnum]._pSplLvl[SPL_HBOLT] < 15) + plr[pnum]._pMemSpells |= SPELLBIT(SPL_HBOLT); + if (plr[pnum]._pSplLvl[SPL_HBOLT] < MAX_SPELL_LEVEL) plr[pnum]._pSplLvl[SPL_HBOLT]++; - if (plr[pnum]._pSplLvl[SPL_HBOLT] < 15) + if (plr[pnum]._pSplLvl[SPL_HBOLT] < MAX_SPELL_LEVEL) plr[pnum]._pSplLvl[SPL_HBOLT]++; t = plr[pnum]._pMaxManaBase / 10; v1 = plr[pnum]._pMana - plr[pnum]._pManaBase; diff --git a/Source/player.cpp b/Source/player.cpp index 23a285e7a..3dbd23826 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -819,17 +819,17 @@ void CreatePlayer(int pnum, char c) plr[pnum]._pInfraFlag = FALSE; if (c == PC_WARRIOR) { - plr[pnum]._pAblSpells = (__int64)1 << (SPL_REPAIR - 1); + plr[pnum]._pAblSpells = SPELLBIT(SPL_REPAIR); #ifndef SPAWN } else if (c == PC_ROGUE) { - plr[pnum]._pAblSpells = (__int64)1 << (SPL_DISARM - 1); + plr[pnum]._pAblSpells = SPELLBIT(SPL_DISARM); } else if (c == PC_SORCERER) { - plr[pnum]._pAblSpells = (__int64)1 << (SPL_RECHARGE - 1); + plr[pnum]._pAblSpells = SPELLBIT(SPL_RECHARGE); #endif } if (c == PC_SORCERER) { - plr[pnum]._pMemSpells = (__int64)1 << (SPL_FIREBOLT - 1); + plr[pnum]._pMemSpells = SPELLBIT(SPL_FIREBOLT); } else { plr[pnum]._pMemSpells = 0; } @@ -1123,19 +1123,19 @@ void InitPlayer(int pnum, BOOL FirstTime) } if (plr[pnum]._pClass == PC_WARRIOR) { - plr[pnum]._pAblSpells = 1 << (SPL_REPAIR - 1); + plr[pnum]._pAblSpells = SPELLBIT(SPL_REPAIR); #ifndef SPAWN } else if (plr[pnum]._pClass == PC_ROGUE) { - plr[pnum]._pAblSpells = 1 << (SPL_DISARM - 1); + plr[pnum]._pAblSpells = SPELLBIT(SPL_DISARM); } else if (plr[pnum]._pClass == PC_SORCERER) { - plr[pnum]._pAblSpells = 1 << (SPL_RECHARGE - 1); + plr[pnum]._pAblSpells = SPELLBIT(SPL_RECHARGE); #ifdef HELLFIRE } else if (plr[pnum]._pClass == PC_MONK) { - plr[pnum]._pAblSpells = (unsigned __int64)1 << (SPL_SEARCH - 1); + plr[pnum]._pAblSpells = SPELLBIT(SPL_SEARCH); } else if (plr[pnum]._pClass == PC_BARD) { - plr[pnum]._pAblSpells = 1 << (SPL_IDENTIFY - 1); + plr[pnum]._pAblSpells = SPELLBIT(SPL_IDENTIFY); } else if (plr[pnum]._pClass == PC_BARBARIAN) { - plr[pnum]._pAblSpells = 1 << (SPL_BLODBOIL - 1); + plr[pnum]._pAblSpells = SPELLBIT(SPL_BLODBOIL); #endif #endif } @@ -3269,7 +3269,7 @@ BOOL PM_DoSpell(int pnum) if (!plr[pnum]._pSplFrom) { if (plr[pnum]._pRSplType == RSPLTYPE_SCROLL) { if (!(plr[pnum]._pScrlSpells - & (unsigned __int64)1 << (plr[pnum]._pRSpell - 1))) { + & SPELLBIT(plr[pnum]._pRSpell))) { plr[pnum]._pRSpell = SPL_INVALID; plr[pnum]._pRSplType = RSPLTYPE_INVALID; force_redraw = 255; @@ -3278,7 +3278,7 @@ BOOL PM_DoSpell(int pnum) if (plr[pnum]._pRSplType == RSPLTYPE_CHARGES) { if (!(plr[pnum]._pISpells - & (unsigned __int64)1 << (plr[pnum]._pRSpell - 1))) { + & SPELLBIT(plr[pnum]._pRSpell))) { plr[pnum]._pRSpell = SPL_INVALID; plr[pnum]._pRSplType = RSPLTYPE_INVALID; force_redraw = 255; @@ -3780,9 +3780,9 @@ void ValidatePlayer() for (b = 1; b < MAX_SPELLS; b++) { if (spelldata[b].sBookLvl != -1) { - msk |= (__int64)1 << (b - 1); - if (plr[myplr]._pSplLvl[b] > 15) - plr[myplr]._pSplLvl[b] = 15; + msk |= SPELLBIT(b); + if (plr[myplr]._pSplLvl[b] > MAX_SPELL_LEVEL) + plr[myplr]._pSplLvl[b] = MAX_SPELL_LEVEL; } } diff --git a/defs.h b/defs.h index c81519c23..82982badf 100644 --- a/defs.h +++ b/defs.h @@ -43,6 +43,8 @@ #define MAX_LVLMTYPES 16 #define MAX_SPELLS 37 #endif +#define MAX_SPELL_LEVEL 15 +#define SPELLBIT(s) ((__int64)1 << (s - 1)) #define MAX_CHUNKS (MAX_LVLS + 5)