Browse Source

♻️ Remove all usage of basic WIN32 types

Note that several WinAPI types are still in use (misc.h)
pull/1219/head
Anders Jenbo 5 years ago
parent
commit
31467cc949
  1. 27
      Source/control.cpp
  2. 4
      Source/debug.cpp
  3. 12
      Source/items.cpp
  4. 19
      Source/objects.cpp
  5. 32
      Source/player.cpp
  6. 2
      Source/spells.cpp
  7. 1
      Source/spells.h
  8. 7
      SourceS/miniwin.h
  9. 4
      SourceT/writehero_test.cpp
  10. 1
      defs.h

27
Source/control.cpp

@ -338,7 +338,7 @@ static void DrawSpell(CelOutputBuffer out)
void DrawSpellList(CelOutputBuffer out)
{
int x, y, c, s, t, v, lx, ly, trans;
unsigned __int64 mask, spl;
Uint64 mask, spl;
pSpell = SPL_INVALID;
infostr[0] = '\0';
@ -491,7 +491,7 @@ void SetSpeedSpell(int slot)
void ToggleSpell(int slot)
{
unsigned __int64 spells;
Uint64 spells;
if (plr[myplr]._pSplHotKey[slot] == -1) {
return;
@ -512,7 +512,7 @@ void ToggleSpell(int slot)
break;
}
if (spells & SPELLBIT(plr[myplr]._pSplHotKey[slot])) {
if (spells & GetSpellBitmask(plr[myplr]._pSplHotKey[slot])) {
plr[myplr]._pRSpell = plr[myplr]._pSplHotKey[slot];
plr[myplr]._pRSplType = plr[myplr]._pSplTHotKey[slot];
force_redraw = 255;
@ -855,7 +855,6 @@ void DrawCtrlBtns(CelOutputBuffer out)
*/
void DoSpeedBook()
{
unsigned __int64 spell, spells;
int xo, yo, X, Y, i, j;
spselflag = TRUE;
@ -866,6 +865,7 @@ void DoSpeedBook()
if (plr[myplr]._pRSpell != SPL_INVALID) {
for (i = 0; i < 4; i++) {
Uint64 spells;
switch (i) {
case RSPLTYPE_SKILL:
spells = plr[myplr]._pAblSpells;
@ -880,7 +880,7 @@ void DoSpeedBook()
spells = plr[myplr]._pISpells;
break;
}
spell = (__int64)1;
Uint64 spell = 1;
for (j = 1; j < MAX_SPELLS; j++) {
if (spell & spells) {
if (j == plr[myplr]._pRSpell && i == plr[myplr]._pRSplType) {
@ -893,7 +893,7 @@ void DoSpeedBook()
yo -= SPLICONLENGTH;
}
}
spell <<= (__int64)1;
spell <<= 1ULL;
}
if (spells && xo != PANEL_X + 12 + SPLICONLENGTH * SPLROWICONLS)
xo -= SPLICONLENGTH;
@ -1800,10 +1800,10 @@ char GetSBookTrans(int ii, BOOL townok)
if ((plr[myplr]._pClass == PC_MONK) && (ii == SPL_SEARCH))
return RSPLTYPE_SKILL;
st = RSPLTYPE_SPELL;
if (plr[myplr]._pISpells & SPELLBIT(ii)) {
if (plr[myplr]._pISpells & GetSpellBitmask(ii)) {
st = RSPLTYPE_CHARGES;
}
if (plr[myplr]._pAblSpells & SPELLBIT(ii)) {
if (plr[myplr]._pAblSpells & GetSpellBitmask(ii)) {
st = RSPLTYPE_SKILL;
}
if (st == RSPLTYPE_SPELL) {
@ -1825,7 +1825,6 @@ void DrawSpellBook(CelOutputBuffer out)
{
int i, sn, mana, lvl, yp, min, max;
char st;
unsigned __int64 spl;
CelDrawTo(out, RIGHT_PANEL_X, 351, pSpellBkCel, 1, SPANEL_WIDTH);
if (gbIsHellfire && sbooktab < 5) {
@ -1838,12 +1837,12 @@ void DrawSpellBook(CelOutputBuffer out)
}
CelDrawTo(out, sx, 348, pSBkBtnCel, sbooktab + 1, 76);
}
spl = plr[myplr]._pMemSpells | plr[myplr]._pISpells | plr[myplr]._pAblSpells;
Uint64 spl = plr[myplr]._pMemSpells | plr[myplr]._pISpells | plr[myplr]._pAblSpells;
yp = 55;
for (i = 1; i < 8; i++) {
sn = SpellPages[sbooktab][i - 1];
if (sn != -1 && spl & SPELLBIT(sn)) {
if (sn != -1 && spl & GetSpellBitmask(sn)) {
st = GetSBookTrans(sn, TRUE);
SetSpellTrans(st);
DrawSpellCel(out, RIGHT_PANEL_X + 11, yp, pSBkIconCels, SpellITbl[sn], 37);
@ -1893,12 +1892,12 @@ void CheckSBook()
if (MouseX >= RIGHT_PANEL + 11 && MouseX < RIGHT_PANEL + 48 && MouseY >= 18 && MouseY < 314) {
spell_id sn = SpellPages[sbooktab][(MouseY - 18) / 43];
Uint64 spl = plr[myplr]._pMemSpells | plr[myplr]._pISpells | plr[myplr]._pAblSpells;
if (sn != SPL_INVALID && spl & SPELLBIT(sn)) {
if (sn != SPL_INVALID && spl & GetSpellBitmask(sn)) {
spell_type st = RSPLTYPE_SPELL;
if (plr[myplr]._pISpells & SPELLBIT(sn)) {
if (plr[myplr]._pISpells & GetSpellBitmask(sn)) {
st = RSPLTYPE_CHARGES;
}
if (plr[myplr]._pAblSpells & SPELLBIT(sn)) {
if (plr[myplr]._pAblSpells & GetSpellBitmask(sn)) {
st = RSPLTYPE_SKILL;
}
plr[myplr]._pRSpell = sn;

4
Source/debug.cpp

@ -91,7 +91,7 @@ void MaxSpellsCheat()
for (i = 1; i < maxSpells; i++) {
if (GetSpellBookLevel(i) != -1) {
plr[myplr]._pMemSpells |= SPELLBIT(i);
plr[myplr]._pMemSpells |= GetSpellBitmask(i);
plr[myplr]._pSplLvl[i] = 10;
}
}
@ -99,7 +99,7 @@ void MaxSpellsCheat()
void SetSpellLevelCheat(char spl, int spllvl)
{
plr[myplr]._pMemSpells |= SPELLBIT(spl);
plr[myplr]._pMemSpells |= GetSpellBitmask(spl);
plr[myplr]._pSplLvl[spl] = spllvl;
}

12
Source/items.cpp

@ -689,7 +689,7 @@ void CalcPlrItemVals(int p, BOOL Loadgfx)
int dadd = 0; // added dexterity
int vadd = 0; // added vitality
unsigned __int64 spl = 0; // bitarray for all enabled/active spells
Uint64 spl = 0; // bitarray for all enabled/active spells
int fr = 0; // fire resistance
int lr = 0; // lightning resistance
@ -720,7 +720,7 @@ void CalcPlrItemVals(int p, BOOL Loadgfx)
tac += itm->_iAC;
if (itm->_iSpell != SPL_NULL) {
spl |= SPELLBIT(itm->_iSpell);
spl |= GetSpellBitmask(itm->_iSpell);
}
if (itm->_iMagical == ITEM_QUALITY_NORMAL || itm->_iIdentified) {
@ -1093,14 +1093,14 @@ void CalcPlrScrolls(int p)
for (i = 0; i < plr[p]._pNumInv; i++) {
if (!plr[p].InvList[i].isEmpty() && (plr[p].InvList[i]._iMiscId == IMISC_SCROLL || plr[p].InvList[i]._iMiscId == IMISC_SCROLLT)) {
if (plr[p].InvList[i]._iStatFlag)
plr[p]._pScrlSpells |= SPELLBIT(plr[p].InvList[i]._iSpell);
plr[p]._pScrlSpells |= GetSpellBitmask(plr[p].InvList[i]._iSpell);
}
}
for (j = 0; j < MAXBELTITEMS; j++) {
if (!plr[p].SpdList[j].isEmpty() && (plr[p].SpdList[j]._iMiscId == IMISC_SCROLL || plr[p].SpdList[j]._iMiscId == IMISC_SCROLLT)) {
if (plr[p].SpdList[j]._iStatFlag)
plr[p]._pScrlSpells |= SPELLBIT(plr[p].SpdList[j]._iSpell);
plr[p]._pScrlSpells |= GetSpellBitmask(plr[p].SpdList[j]._iSpell);
}
}
EnsureValidReadiedSpell(plr[p]);
@ -1112,7 +1112,7 @@ void CalcPlrStaff(int p)
if (!plr[p].InvBody[INVLOC_HAND_LEFT].isEmpty()
&& plr[p].InvBody[INVLOC_HAND_LEFT]._iStatFlag
&& plr[p].InvBody[INVLOC_HAND_LEFT]._iCharges > 0) {
plr[p]._pISpells |= SPELLBIT(plr[p].InvBody[INVLOC_HAND_LEFT]._iSpell);
plr[p]._pISpells |= GetSpellBitmask(plr[p].InvBody[INVLOC_HAND_LEFT]._iSpell);
}
}
@ -4338,7 +4338,7 @@ void UseItem(int p, item_misc_id Mid, spell_id spl)
}
break;
case IMISC_BOOK:
plr[p]._pMemSpells |= SPELLBIT(spl);
plr[p]._pMemSpells |= GetSpellBitmask(spl);
if (plr[p]._pSplLvl[spl] < MAX_SPELL_LEVEL)
plr[p]._pSplLvl[spl]++;
if (!(plr[p]._pIFlags & ISPL_NOMANA)) {

19
Source/objects.cpp

@ -2900,7 +2900,7 @@ void OperateBook(int pnum, int i)
return;
if (setlvlnum == SL_BONECHAMB) {
plr[pnum]._pMemSpells |= SPELLBIT(SPL_GUARDIAN);
plr[pnum]._pMemSpells |= GetSpellBitmask(SPL_GUARDIAN);
if (plr[pnum]._pSplLvl[SPL_GUARDIAN] < MAX_SPELL_LEVEL)
plr[pnum]._pSplLvl[SPL_GUARDIAN]++;
quests[Q_SCHAMB]._qactive = QUEST_DONE;
@ -3338,7 +3338,6 @@ void OperateShrine(int pnum, int i, int sType)
DWORD lv, t;
int xx, yy;
int v1, v2, v3, v4;
unsigned __int64 spell, spells;
if (dropGoldFlag) {
dropGoldFlag = FALSE;
@ -3566,9 +3565,9 @@ void OperateShrine(int pnum, int i, int sType)
if (pnum != myplr)
return;
cnt = 0;
spell = 1;
Uint64 spell = 1;
int maxSpells = gbIsHellfire ? MAX_SPELLS : 37;
spells = plr[pnum]._pMemSpells;
Uint64 spells = plr[pnum]._pMemSpells;
for (j = 0; j < maxSpells; j++) {
if (spell & spells)
cnt++;
@ -3585,7 +3584,7 @@ void OperateShrine(int pnum, int i, int sType)
}
do {
r = random_(0, maxSpells);
} while (!(plr[pnum]._pMemSpells & SPELLBIT(r + 1)));
} while (!(plr[pnum]._pMemSpells & GetSpellBitmask(r + 1)));
if (plr[pnum]._pSplLvl[r + 1] >= 2)
plr[pnum]._pSplLvl[r + 1] -= 2;
else
@ -3617,7 +3616,7 @@ void OperateShrine(int pnum, int i, int sType)
return;
if (pnum != myplr)
return;
plr[pnum]._pMemSpells |= SPELLBIT(SPL_FIREBOLT);
plr[pnum]._pMemSpells |= GetSpellBitmask(SPL_FIREBOLT);
if (plr[pnum]._pSplLvl[SPL_FIREBOLT] < MAX_SPELL_LEVEL)
plr[pnum]._pSplLvl[SPL_FIREBOLT]++;
if (plr[pnum]._pSplLvl[SPL_FIREBOLT] < MAX_SPELL_LEVEL)
@ -3750,7 +3749,7 @@ void OperateShrine(int pnum, int i, int sType)
case SHRINE_SACRED:
if (deltaload || pnum != myplr)
return;
plr[pnum]._pMemSpells |= SPELLBIT(SPL_CBOLT);
plr[pnum]._pMemSpells |= GetSpellBitmask(SPL_CBOLT);
if (plr[pnum]._pSplLvl[SPL_CBOLT] < MAX_SPELL_LEVEL)
plr[pnum]._pSplLvl[SPL_CBOLT]++;
if (plr[pnum]._pSplLvl[SPL_CBOLT] < MAX_SPELL_LEVEL)
@ -3853,7 +3852,7 @@ void OperateShrine(int pnum, int i, int sType)
return;
if (pnum != myplr)
return;
plr[pnum]._pMemSpells |= SPELLBIT(SPL_HBOLT);
plr[pnum]._pMemSpells |= GetSpellBitmask(SPL_HBOLT);
if (plr[pnum]._pSplLvl[SPL_HBOLT] < MAX_SPELL_LEVEL)
plr[pnum]._pSplLvl[SPL_HBOLT]++;
if (plr[pnum]._pSplLvl[SPL_HBOLT] < MAX_SPELL_LEVEL)
@ -3978,10 +3977,10 @@ void OperateShrine(int pnum, int i, int sType)
return;
InitDiabloMsg(EMSG_SHRINE_GLOWING);
int playerXP = plr[myplr]._pExperience;
int xpLoss, magicGain;
Sint32 xpLoss, magicGain;
if (playerXP > 5000) {
magicGain = 5;
xpLoss = (signed __int64)((double)playerXP * 0.95);
xpLoss = ((double)playerXP * 0.95);
} else {
magicGain = playerXP / 1000;
xpLoss = 0;

32
Source/player.cpp

@ -749,21 +749,21 @@ void CreatePlayer(int pnum, plr_class c)
plr[pnum]._pInfraFlag = FALSE;
if (c == PC_WARRIOR) {
plr[pnum]._pAblSpells = SPELLBIT(SPL_REPAIR);
plr[pnum]._pAblSpells = GetSpellBitmask(SPL_REPAIR);
} else if (c == PC_ROGUE) {
plr[pnum]._pAblSpells = SPELLBIT(SPL_DISARM);
plr[pnum]._pAblSpells = GetSpellBitmask(SPL_DISARM);
} else if (c == PC_SORCERER) {
plr[pnum]._pAblSpells = SPELLBIT(SPL_RECHARGE);
plr[pnum]._pAblSpells = GetSpellBitmask(SPL_RECHARGE);
} else if (c == PC_MONK) {
plr[pnum]._pAblSpells = SPELLBIT(SPL_SEARCH);
plr[pnum]._pAblSpells = GetSpellBitmask(SPL_SEARCH);
} else if (c == PC_BARD) {
plr[pnum]._pAblSpells = SPELLBIT(SPL_IDENTIFY);
plr[pnum]._pAblSpells = GetSpellBitmask(SPL_IDENTIFY);
} else if (c == PC_BARBARIAN) {
plr[pnum]._pAblSpells = SPELLBIT(SPL_BLODBOIL);
plr[pnum]._pAblSpells = GetSpellBitmask(SPL_BLODBOIL);
}
if (c == PC_SORCERER) {
plr[pnum]._pMemSpells = SPELLBIT(SPL_FIREBOLT);
plr[pnum]._pMemSpells = GetSpellBitmask(SPL_FIREBOLT);
} else {
plr[pnum]._pMemSpells = 0;
}
@ -1055,17 +1055,17 @@ void InitPlayer(int pnum, BOOL FirstTime)
}
if (plr[pnum]._pClass == PC_WARRIOR) {
plr[pnum]._pAblSpells = SPELLBIT(SPL_REPAIR);
plr[pnum]._pAblSpells = GetSpellBitmask(SPL_REPAIR);
} else if (plr[pnum]._pClass == PC_ROGUE) {
plr[pnum]._pAblSpells = SPELLBIT(SPL_DISARM);
plr[pnum]._pAblSpells = GetSpellBitmask(SPL_DISARM);
} else if (plr[pnum]._pClass == PC_SORCERER) {
plr[pnum]._pAblSpells = SPELLBIT(SPL_RECHARGE);
plr[pnum]._pAblSpells = GetSpellBitmask(SPL_RECHARGE);
} else if (plr[pnum]._pClass == PC_MONK) {
plr[pnum]._pAblSpells = SPELLBIT(SPL_SEARCH);
plr[pnum]._pAblSpells = GetSpellBitmask(SPL_SEARCH);
} else if (plr[pnum]._pClass == PC_BARD) {
plr[pnum]._pAblSpells = SPELLBIT(SPL_IDENTIFY);
plr[pnum]._pAblSpells = GetSpellBitmask(SPL_IDENTIFY);
} else if (plr[pnum]._pClass == PC_BARBARIAN) {
plr[pnum]._pAblSpells = SPELLBIT(SPL_BLODBOIL);
plr[pnum]._pAblSpells = GetSpellBitmask(SPL_BLODBOIL);
}
#ifdef _DEBUG
@ -3410,11 +3410,8 @@ BOOL PlrDeathModeOK(int p)
void ValidatePlayer()
{
__int64 msk;
int gt, i, b;
msk = 0;
if ((DWORD)myplr >= MAX_PLRS) {
app_fatal("ValidatePlayer: illegal player %d", myplr);
}
@ -3450,9 +3447,10 @@ void ValidatePlayer()
plr[myplr]._pBaseVit = MaxStats[pc][ATTRIB_VIT];
}
Uint64 msk = 0;
for (b = 1; b < MAX_SPELLS; b++) {
if (GetSpellBookLevel(b) != -1) {
msk |= SPELLBIT(b);
msk |= GetSpellBitmask(b);
if (plr[myplr]._pSplLvl[b] > MAX_SPELL_LEVEL)
plr[myplr]._pSplLvl[b] = MAX_SPELL_LEVEL;
}

2
Source/spells.cpp

@ -95,7 +95,7 @@ void UseMana(int id, int sn)
* @param spellId The id of the spell to get a bitmask for.
* @return A 64bit bitmask representation for the specified spell.
*/
unsigned long long GetSpellBitmask(int spellId)
Uint64 GetSpellBitmask(int spellId)
{
return 1ULL << (spellId - 1);
}

1
Source/spells.h

@ -14,6 +14,7 @@ extern "C" {
int GetManaAmount(int id, int sn);
void UseMana(int id, int sn);
Uint64 GetSpellBitmask(int spellId);
BOOL CheckSpell(int id, int sn, char st, BOOL manaonly);
void EnsureValidReadiedSpell(PlayerStruct &player);
void CastSpell(int id, int spl, int sx, int sy, int dx, int dy, int spllvl);

7
SourceS/miniwin.h

@ -14,13 +14,6 @@
#include <string.h>
#include <time.h>
#ifndef _WIN32
#define __int8 char
#define __int16 short
#define __int32 int
#define __int64 long long __attribute__((aligned(8)))
#endif
#include "miniwin/misc.h"
#include "storm_full.h"

4
SourceT/writehero_test.cpp

@ -174,8 +174,8 @@ static void PackPlayerTest(PkPlayerStruct *pPack)
for (auto i = 0; i < MAXBELTITEMS; i++)
PackItemFullRejuv(pPack->SpdList+i, i);
for (auto i = 1; i < 37; i++) {
if(spelldat_vanilla[i] != -1) {
pPack->pMemSpells |= (__int64)1 << (i-1);
if (spelldat_vanilla[i] != -1) {
pPack->pMemSpells |= 1ULL << (i - 1);
pPack->pSplLvl[i] = 15;
}
}

1
defs.h

@ -21,7 +21,6 @@
#define MAX_LVLMTYPES 24
#define MAX_SPELLS 52
#define MAX_SPELL_LEVEL 15
#define SPELLBIT(s) ((__int64)1 << (s - 1))
#define MAX_CHUNKS (MAX_LVLS + 5)

Loading…
Cancel
Save