Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spell defines and macros #2162

Merged
merged 4 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Source/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Source/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ 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;
}
}
}

void SetSpellLevelCheat(char spl, int spllvl)
{
plr[myplr]._pMemSpells |= (__int64)1 << (spl - 1);
plr[myplr]._pMemSpells |= SPELLBIT(spl);
plr[myplr]._pSplLvl[spl] = spllvl;
}

Expand Down
2 changes: 2 additions & 0 deletions Source/inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))) {
Expand Down Expand Up @@ -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)))) {
Expand Down
16 changes: 8 additions & 8 deletions Source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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)
Expand Down
30 changes: 15 additions & 15 deletions Source/objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
30 changes: 15 additions & 15 deletions Source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down
2 changes: 2 additions & 0 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down