Browse Source

Cleanup majority of remaning implicit bool conversions (#2234)

pull/2237/head
Anders Jenbo 5 years ago committed by GitHub
parent
commit
2bdb6caa07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      Source/diablo.cpp
  2. 36
      Source/drlg_l3.cpp
  3. 2
      Source/engine/render/dun_render.cpp
  4. 20
      Source/items.cpp
  5. 2
      Source/items.h
  6. 2
      Source/loadsave.cpp
  7. 2
      Source/miniwin/miniwin.h
  8. 28
      Source/miniwin/misc_msg.cpp
  9. 28
      Source/monster.cpp
  10. 32
      Source/mpqapi.cpp
  11. 28
      Source/msg.cpp
  12. 6
      Source/nthread.cpp
  13. 24
      Source/objects.cpp
  14. 2
      Source/pack.cpp
  15. 8
      Source/player.cpp
  16. 4
      Source/scrollrt.cpp
  17. 6
      Source/stores.cpp

8
Source/diablo.cpp

@ -974,7 +974,7 @@ static void PressKey(int vkey)
}
keymapper.keyPressed(vkey);
if (vkey == DVL_VK_RETURN) {
if ((GetAsyncKeyState(DVL_VK_MENU) & 0x8000) != 0)
if (GetAsyncKeyState(DVL_VK_MENU))
dx_reinit();
else
control_type_message();
@ -999,7 +999,7 @@ static void PressKey(int vkey)
return;
}
if (PauseMode == 2) {
if (vkey == DVL_VK_RETURN && (GetAsyncKeyState(DVL_VK_MENU) & 0x8000) != 0)
if (vkey == DVL_VK_RETURN && GetAsyncKeyState(DVL_VK_MENU))
dx_reinit();
return;
}
@ -1007,7 +1007,7 @@ static void PressKey(int vkey)
keymapper.keyPressed(vkey);
if (vkey == DVL_VK_RETURN) {
if ((GetAsyncKeyState(DVL_VK_MENU) & 0x8000) != 0) {
if (GetAsyncKeyState(DVL_VK_MENU)) {
dx_reinit();
} else if (stextflag != STORE_NONE) {
STextEnter();
@ -1728,7 +1728,7 @@ static void game_logic()
}
#ifdef _DEBUG
if (debug_mode_key_inverted_v && (GetAsyncKeyState(DVL_VK_SHIFT) & 0x8000) != 0) {
if (debug_mode_key_inverted_v && GetAsyncKeyState(DVL_VK_SHIFT)) {
ScrollView();
}
#endif

36
Source/drlg_l3.cpp

@ -1451,28 +1451,28 @@ static bool DRLG_L3SpawnEdge(int x, int y, int *totarea)
dungeon[x][y] |= 0x80;
*totarea += 1;
if (spawntable[i] & 8 && DRLG_L3SpawnEdge(x, y - 1, totarea)) {
if ((spawntable[i] & 8) != 0 && DRLG_L3SpawnEdge(x, y - 1, totarea)) {
return true;
}
if (spawntable[i] & 4 && DRLG_L3SpawnEdge(x, y + 1, totarea)) {
if ((spawntable[i] & 4) != 0 && DRLG_L3SpawnEdge(x, y + 1, totarea)) {
return true;
}
if (spawntable[i] & 2 && DRLG_L3SpawnEdge(x + 1, y, totarea)) {
if ((spawntable[i] & 2) != 0 && DRLG_L3SpawnEdge(x + 1, y, totarea)) {
return true;
}
if (spawntable[i] & 1 && DRLG_L3SpawnEdge(x - 1, y, totarea)) {
if ((spawntable[i] & 1) != 0 && DRLG_L3SpawnEdge(x - 1, y, totarea)) {
return true;
}
if (spawntable[i] & 0x80 && DRLG_L3Spawn(x, y - 1, totarea)) {
if ((spawntable[i] & 0x80) != 0 && DRLG_L3Spawn(x, y - 1, totarea)) {
return true;
}
if (spawntable[i] & 0x40 && DRLG_L3Spawn(x, y + 1, totarea)) {
if ((spawntable[i] & 0x40) != 0 && DRLG_L3Spawn(x, y + 1, totarea)) {
return true;
}
if (spawntable[i] & 0x20 && DRLG_L3Spawn(x + 1, y, totarea)) {
if ((spawntable[i] & 0x20) != 0 && DRLG_L3Spawn(x + 1, y, totarea)) {
return true;
}
if (spawntable[i] & 0x10 && DRLG_L3Spawn(x - 1, y, totarea)) {
if ((spawntable[i] & 0x10) != 0 && DRLG_L3Spawn(x - 1, y, totarea)) {
return true;
}
@ -1502,16 +1502,16 @@ static bool DRLG_L3Spawn(int x, int y, int *totarea)
*totarea += 1;
if (i != 8) {
if (spawntable[i] & 8 && DRLG_L3SpawnEdge(x, y - 1, totarea)) {
if ((spawntable[i] & 8) != 0 && DRLG_L3SpawnEdge(x, y - 1, totarea)) {
return true;
}
if (spawntable[i] & 4 && DRLG_L3SpawnEdge(x, y + 1, totarea)) {
if ((spawntable[i] & 4) != 0 && DRLG_L3SpawnEdge(x, y + 1, totarea)) {
return true;
}
if (spawntable[i] & 2 && DRLG_L3SpawnEdge(x + 1, y, totarea)) {
if ((spawntable[i] & 2) != 0 && DRLG_L3SpawnEdge(x + 1, y, totarea)) {
return true;
}
if (spawntable[i] & 1 && DRLG_L3SpawnEdge(x - 1, y, totarea)) {
if ((spawntable[i] & 1) != 0 && DRLG_L3SpawnEdge(x - 1, y, totarea)) {
return true;
}
} else {
@ -2436,10 +2436,14 @@ static void DRLG_L3(lvl_entry entry)
if (currlevel < 17) {
DRLG_L3Pool();
} else {
lavapool += drlg_l3_hive_rnd_piece(byte_48A998, 30);
lavapool += drlg_l3_hive_rnd_piece(byte_48A9C8, 40);
lavapool += drlg_l3_hive_rnd_piece(byte_48A948, 50);
lavapool += drlg_l3_hive_rnd_piece(byte_48A970, 60);
if (drlg_l3_hive_rnd_piece(byte_48A998, 30))
lavapool++;
if (drlg_l3_hive_rnd_piece(byte_48A9C8, 40))
lavapool++;
if (drlg_l3_hive_rnd_piece(byte_48A948, 50))
lavapool++;
if (drlg_l3_hive_rnd_piece(byte_48A970, 60))
lavapool++;
if (lavapool < 3)
lavapool = 0;
}

2
Source/engine/render/dun_render.cpp

@ -1245,7 +1245,7 @@ DVL_ATTRIBUTE_HOT void RenderTileType(TileType tile, std::uint8_t *dst, int dstP
const std::uint32_t *GetMask(TileType tile)
{
#ifdef _DEBUG
if ((GetAsyncKeyState(DVL_VK_MENU) & 0x8000) != 0) {
if (GetAsyncKeyState(DVL_VK_MENU)) {
return &SolidMask[TILE_HEIGHT - 1];
}
#endif

20
Source/items.cpp

@ -2060,7 +2060,7 @@ void SaveItemPower(int i, item_effect_type power, int param1, int param2, int mi
default:
break;
}
if (items[i]._iVAdd1 || items[i]._iVMult1) {
if (items[i]._iVAdd1 != 0 || items[i]._iVMult1 != 0) {
items[i]._iVAdd2 = PLVal(r, param1, param2, minval, maxval);
items[i]._iVMult2 = multval;
} else {
@ -2452,7 +2452,7 @@ void SpawnUnique(_unique_items uid, Point position)
void ItemRndDur(int ii)
{
if (items[ii]._iDurability && items[ii]._iDurability != DUR_INDESTRUCTIBLE)
if (items[ii]._iDurability > 0 && items[ii]._iDurability != DUR_INDESTRUCTIBLE)
items[ii]._iDurability = GenerateRnd(items[ii]._iMaxDur / 2) + (items[ii]._iMaxDur / 4) + 1;
}
@ -2516,7 +2516,7 @@ void SpawnItem(int m, Point position, bool sendmsg)
int idx;
bool onlygood = true;
if (monster[m]._uniqtype || ((monster[m].MData->mTreasure & 0x8000) && gbIsMultiplayer)) {
if (monster[m]._uniqtype != 0 || ((monster[m].MData->mTreasure & 0x8000) != 0 && gbIsMultiplayer)) {
idx = RndUItem(m);
if (idx < 0) {
SpawnUnique((_unique_items) - (idx + 1), position);
@ -2525,7 +2525,7 @@ void SpawnItem(int m, Point position, bool sendmsg)
onlygood = true;
} else if (quests[Q_MUSHROOM]._qactive != QUEST_ACTIVE || quests[Q_MUSHROOM]._qvar1 != QS_MUSHGIVEN) {
idx = RndItem(m);
if (!idx)
if (idx == 0)
return;
if (idx > 0) {
idx--;
@ -2544,7 +2544,7 @@ void SpawnItem(int m, Point position, bool sendmsg)
int ii = AllocateItem();
GetSuperItemSpace(position, ii);
int uper = monster[m]._uniqtype ? 15 : 1;
int uper = monster[m]._uniqtype != 0 ? 15 : 1;
int mLevel = monster[m].MData->mLevel;
if (!gbIsHellfire && monster[m].MType->mtype == MT_DIABLO)
@ -2937,7 +2937,7 @@ void ItemDoppel()
static int idoppely = 16;
for (int idoppelx = 16; idoppelx < 96; idoppelx++) {
if (dItem[idoppelx][idoppely]) {
if (dItem[idoppelx][idoppely] != 0) {
ItemStruct *i = &items[dItem[idoppelx][idoppely] - 1];
if (i->position.x != idoppelx || i->position.y != idoppely)
dItem[idoppelx][idoppely] = 0;
@ -3850,7 +3850,7 @@ void PrintItemDur(ItemStruct *x)
strcpy(tempstr, fmt::format(_("damage: {:d}-{:d} Dur: {:d}/{:d}"), x->_iMinDam, x->_iMaxDam, x->_iDurability, x->_iMaxDur).c_str());
}
AddPanelString(tempstr);
if (x->_iMiscId == IMISC_STAFF && x->_iMaxCharges) {
if (x->_iMiscId == IMISC_STAFF && x->_iMaxCharges > 0) {
strcpy(tempstr, fmt::format(_("Charges: {:d}/{:d}"), x->_iCharges, x->_iMaxCharges).c_str());
AddPanelString(tempstr);
}
@ -3865,7 +3865,7 @@ void PrintItemDur(ItemStruct *x)
AddPanelString(tempstr);
if (x->_iMagical != ITEM_QUALITY_NORMAL)
AddPanelString(_("Not Identified"));
if (x->_iMiscId == IMISC_STAFF && x->_iMaxCharges) {
if (x->_iMiscId == IMISC_STAFF && x->_iMaxCharges > 0) {
strcpy(tempstr, fmt::format(_("Charges: {:d}/{:d}"), x->_iCharges, x->_iMaxCharges).c_str());
AddPanelString(tempstr);
}
@ -4107,7 +4107,7 @@ bool SmithItemOk(int i)
return false;
if (AllItemsList[i].itype == ITYPE_GOLD)
return false;
if (AllItemsList[i].itype == ITYPE_STAFF && (!gbIsHellfire || AllItemsList[i].iSpell))
if (AllItemsList[i].itype == ITYPE_STAFF && (!gbIsHellfire || AllItemsList[i].iSpell != SPL_NULL))
return false;
if (AllItemsList[i].itype == ITYPE_RING)
return false;
@ -4385,7 +4385,7 @@ void WitchBookLevel(int ii)
return;
witchitem[ii]._iMinMag = spelldata[witchitem[ii]._iSpell].sMinInt;
int slvl = plr[myplr]._pSplLvl[witchitem[ii]._iSpell];
while (slvl) {
while (slvl > 0) {
witchitem[ii]._iMinMag += 20 * witchitem[ii]._iMinMag / 100;
slvl--;
if (witchitem[ii]._iMinMag + 20 * witchitem[ii]._iMinMag / 100 > 255) {

2
Source/items.h

@ -184,7 +184,7 @@ struct ItemStruct {
uint8_t _iSelFlag;
bool _iPostDraw;
bool _iIdentified;
int8_t _iMagical;
item_quality _iMagical;
char _iName[64];
char _iIName[64];
enum item_equip_type _iLoc;

2
Source/loadsave.cpp

@ -228,7 +228,7 @@ static void LoadItemData(LoadHelper *file, ItemStruct *pItem)
file->skip(3); // Alignment
pItem->_iPostDraw = file->nextBool32();
pItem->_iIdentified = file->nextBool32();
pItem->_iMagical = file->nextLE<int8_t>();
pItem->_iMagical = static_cast<item_quality>(file->nextLE<int8_t>());
file->nextBytes(pItem->_iName, 64);
file->nextBytes(pItem->_iIName, 64);
pItem->_iLoc = static_cast<item_equip_type>(file->nextLE<int8_t>());

2
Source/miniwin/miniwin.h

@ -39,7 +39,7 @@ struct tagMSG {
void SetCursorPos(int X, int Y);
void FocusOnCharInfo();
uint16_t GetAsyncKeyState(int vKey);
bool GetAsyncKeyState(int vKey);
bool FetchMessage(tagMSG *lpMsg);

28
Source/miniwin/misc_msg.cpp

@ -264,7 +264,7 @@ int32_t PositionForMouse(short x, short y)
int32_t KeystateForMouse(int32_t ret)
{
ret |= (SDL_GetModState() & KMOD_SHIFT) ? DVL_MK_SHIFT : 0;
ret |= (SDL_GetModState() & KMOD_SHIFT) != 0 ? DVL_MK_SHIFT : 0;
// XXX: other DVL_MK_* codes not implemented
return ret;
}
@ -589,7 +589,8 @@ bool TranslateMessage(const tagMSG *lpMsg)
unsigned mod = (DWORD)lpMsg->lParam >> 16;
bool shift = (mod & KMOD_SHIFT) != 0;
bool upper = shift != (mod & KMOD_CAPS);
bool caps = (mod & KMOD_CAPS) != 0;
bool upper = shift != caps;
bool isAlpha = (key >= 'A' && key <= 'Z');
bool isNumeric = (key >= '0' && key <= '9');
@ -688,30 +689,31 @@ bool TranslateMessage(const tagMSG *lpMsg)
return true;
}
uint16_t GetAsyncKeyState(int vKey)
bool GetAsyncKeyState(int vKey)
{
if (vKey == DVL_MK_LBUTTON)
return SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON(SDL_BUTTON_LEFT);
return (SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0;
if (vKey == DVL_MK_RBUTTON)
return SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON(SDL_BUTTON_RIGHT);
return (SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
const Uint8 *state = SDLC_GetKeyState();
switch (vKey) {
case DVL_VK_CONTROL:
return state[SDLC_KEYSTATE_LEFTCTRL] || state[SDLC_KEYSTATE_RIGHTCTRL] ? 0x8000 : 0;
return state[SDLC_KEYSTATE_LEFTCTRL] != 0 || state[SDLC_KEYSTATE_RIGHTCTRL] != 0;
case DVL_VK_SHIFT:
return state[SDLC_KEYSTATE_LEFTSHIFT] || state[SDLC_KEYSTATE_RIGHTSHIFT] ? 0x8000 : 0;
return state[SDLC_KEYSTATE_LEFTSHIFT] != 0 || state[SDLC_KEYSTATE_RIGHTSHIFT] != 0;
case DVL_VK_MENU:
return state[SDLC_KEYSTATE_LALT] || state[SDLC_KEYSTATE_RALT] ? 0x8000 : 0;
return state[SDLC_KEYSTATE_LALT] != 0 || state[SDLC_KEYSTATE_RALT] != 0;
case DVL_VK_LEFT:
return state[SDLC_KEYSTATE_LEFT] ? 0x8000 : 0;
return state[SDLC_KEYSTATE_LEFT] != 0;
case DVL_VK_UP:
return state[SDLC_KEYSTATE_UP] ? 0x8000 : 0;
return state[SDLC_KEYSTATE_UP] != 0;
case DVL_VK_RIGHT:
return state[SDLC_KEYSTATE_RIGHT] ? 0x8000 : 0;
return state[SDLC_KEYSTATE_RIGHT] != 0;
case DVL_VK_DOWN:
return state[SDLC_KEYSTATE_DOWN] ? 0x8000 : 0;
return state[SDLC_KEYSTATE_DOWN] != 0;
default:
return 0;
return false;
}
}

28
Source/monster.cpp

@ -1036,10 +1036,10 @@ void PlaceGroup(int mtype, int num, int leaderf, int leader)
}
j = 0;
for (try2 = 0; j < num && try2 < 100; xp += (Point { 0, 0 } + static_cast<Direction>(GenerateRnd(8))).x, yp += (Point { 0, 0 } + static_cast<Direction>(GenerateRnd(8))).x) { /// BUGFIX: `yp += offset_y`
for (try2 = 0; j < num && try2 < 100; xp += Point::fromDirection(static_cast<Direction>(GenerateRnd(8))).x, yp += Point::fromDirection(static_cast<Direction>(GenerateRnd(8))).x) { /// BUGFIX: `yp += Point.y`
if (!MonstPlace(xp, yp)
|| (dTransVal[xp][yp] != dTransVal[x1][y1])
|| ((leaderf & 2) && ((abs(xp - x1) >= 4) || (abs(yp - y1) >= 4)))) {
|| ((leaderf & 2) != 0 && (abs(xp - x1) >= 4 || abs(yp - y1) >= 4))) {
try2++;
continue;
}
@ -1305,7 +1305,7 @@ void M_Enemy(int i)
best_dist = -1;
bestsameroom = false;
Monst = &monster[i];
if (Monst->_mFlags & MFLAG_BERSERK || !(Monst->_mFlags & MFLAG_GOLEM)) {
if ((Monst->_mFlags & MFLAG_BERSERK) != 0 || (Monst->_mFlags & MFLAG_GOLEM) == 0) {
for (pnum = 0; pnum < MAX_PLRS; pnum++) {
if (!plr[pnum].plractive || currlevel != plr[pnum].plrlevel || plr[pnum]._pLvlChanging
|| (((plr[pnum]._pHitPoints >> 6) == 0) && gbIsMultiplayer))
@ -1669,7 +1669,7 @@ void SpawnLoot(int i, bool sendmsg)
quests[Q_DEFILER]._qlog = false;
SpawnMapOfDoom(Monst->position.tile);
} else if (Monst->_uniqtype - 1 == UMT_HORKDMN) {
if (sgGameInitInfo.bTheoQuest) {
if (sgGameInitInfo.bTheoQuest != 0) {
SpawnTheodore(Monst->position.tile);
} else {
CreateAmulet(Monst->position.tile, 13, false, true);
@ -1677,7 +1677,7 @@ void SpawnLoot(int i, bool sendmsg)
} else if (Monst->MType->mtype == MT_HORKSPWN) {
} else if (Monst->MType->mtype == MT_NAKRUL) {
nSFX = IsUberRoomOpened ? USFX_NAKRUL4 : USFX_NAKRUL5;
if (sgGameInitInfo.bCowQuest)
if (sgGameInitInfo.bCowQuest != 0)
nSFX = USFX_NAKRUL6;
if (effect_is_playing(nSFX))
stream_stop();
@ -1838,7 +1838,7 @@ void M_SyncStartKill(int i, Point position, int pnum)
{
assurance((DWORD)i < MAXMONSTERS, i);
if (monster[i]._mhitpoints == 0 || monster[i]._mmode == MM_DEATH) {
if (monster[i]._mhitpoints > 0 || monster[i]._mmode == MM_DEATH) {
return;
}
@ -2048,7 +2048,7 @@ void M_TryH2HHit(int i, int pnum, int Hit, int MinDam, int MaxDam)
assurance((DWORD)i < MAXMONSTERS, i);
assurance(monster[i].MType != nullptr, i);
if (monster[i]._mFlags & MFLAG_TARGETS_MONSTER) {
if ((monster[i]._mFlags & MFLAG_TARGETS_MONSTER) != 0) {
M_TryM2MHit(i, pnum, Hit, MinDam, MaxDam);
return;
}
@ -2161,7 +2161,7 @@ void M_TryH2HHit(int i, int pnum, int Hit, int MinDam, int MaxDam)
}
ApplyPlrDamage(pnum, 0, 0, dam);
}
if (plr[pnum]._pIFlags & ISPL_THORNS) {
if ((plr[pnum]._pIFlags & ISPL_THORNS) != 0) {
mdam = (GenerateRnd(3) + 1) << 6;
monster[i]._mhitpoints -= mdam;
if (monster[i]._mhitpoints >> 6 <= 0)
@ -2177,7 +2177,7 @@ void M_TryH2HHit(int i, int pnum, int Hit, int MinDam, int MaxDam)
return;
}
StartPlrHit(pnum, dam, false);
if (monster[i]._mFlags & MFLAG_KNOCKBACK) {
if ((monster[i]._mFlags & MFLAG_KNOCKBACK) != 0) {
if (plr[pnum]._pmode != PM_GOTHIT)
StartPlrHit(pnum, 0, true);
@ -2368,7 +2368,7 @@ bool M_DoHeal(int i)
commitment((DWORD)i < MAXMONSTERS, i);
Monst = &monster[i];
if (monster[i]._mFlags & MFLAG_NOHEAL) {
if ((monster[i]._mFlags & MFLAG_NOHEAL) != 0) {
Monst->_mFlags &= ~MFLAG_ALLOW_SPECIAL;
Monst->_mmode = MM_SATTACK;
return false;
@ -2413,14 +2413,14 @@ bool M_DoTalk(int i)
}
if (monster[i]._uniqtype - 1 == UMT_ZHAR
&& monster[i].mtalkmsg == TEXT_ZHAR1
&& !(monster[i]._mFlags & MFLAG_QUEST_COMPLETE)) {
&& (monster[i]._mFlags & MFLAG_QUEST_COMPLETE) == 0) {
quests[Q_ZHAR]._qactive = QUEST_ACTIVE;
quests[Q_ZHAR]._qlog = true;
CreateTypeItem(monster[i].position.tile + Point { 1, 1 }, false, ITYPE_MISC, IMISC_BOOK, true, false);
monster[i]._mFlags |= MFLAG_QUEST_COMPLETE;
}
if (monster[i]._uniqtype - 1 == UMT_SNOTSPIL) {
if (monster[i].mtalkmsg == TEXT_BANNER10 && !(monster[i]._mFlags & MFLAG_QUEST_COMPLETE)) {
if (monster[i].mtalkmsg == TEXT_BANNER10 && (monster[i]._mFlags & MFLAG_QUEST_COMPLETE) == 0) {
ObjChangeMap(setpc_x, setpc_y, (setpc_w / 2) + setpc_x + 2, (setpc_h / 2) + setpc_y - 2);
tren = TransVal;
TransVal = 9;
@ -2440,7 +2440,7 @@ bool M_DoTalk(int i)
quests[Q_VEIL]._qactive = QUEST_ACTIVE;
quests[Q_VEIL]._qlog = true;
}
if (monster[i].mtalkmsg == TEXT_VEIL11 && !(monster[i]._mFlags & MFLAG_QUEST_COMPLETE)) {
if (monster[i].mtalkmsg == TEXT_VEIL11 && (monster[i]._mFlags & MFLAG_QUEST_COMPLETE) == 0) {
SpawnUnique(UITEM_STEELVEIL, monster[i].position.tile + DIR_S);
monster[i]._mFlags |= MFLAG_QUEST_COMPLETE;
}
@ -2677,7 +2677,7 @@ bool M_DoStone(int i)
{
commitment((DWORD)i < MAXMONSTERS, i);
if (!monster[i]._mhitpoints) {
if (monster[i]._mhitpoints <= 0) {
dMonster[monster[i].position.tile.x][monster[i].position.tile.y] = 0;
monster[i]._mDelFlag = true;
}

32
Source/mpqapi.cpp

@ -203,7 +203,7 @@ struct Archive {
exists = FileExists(name);
std::ios::openmode mode = std::ios::in | std::ios::out | std::ios::binary;
if (exists) {
if (GetFileSize(name, &size) == 0) {
if (!GetFileSize(name, &size)) {
Log("GetFileSize(\"{}\") failed with \"{}\"", name, std::strerror(errno));
return false;
}
@ -385,7 +385,7 @@ void mpqapi_alloc_block(uint32_t block_offset, uint32_t block_size)
block = cur_archive.sgpBlockTbl;
i = INDEX_ENTRIES;
while (i-- != 0) {
if (block->offset && !block->flags && !block->sizefile) {
if (block->offset != 0 && block->flags == 0 && block->sizefile == 0) {
if (block->offset + block->sizealloc == block_offset) {
block_offset = block->offset;
block_size += block->sizealloc;
@ -421,7 +421,7 @@ int mpqapi_find_free_block(uint32_t size, uint32_t *block_size)
int result;
_BLOCKENTRY *pBlockTbl = cur_archive.sgpBlockTbl;
for (int i = INDEX_ENTRIES; i--; pBlockTbl++) {
for (int i = 0; i < INDEX_ENTRIES; i++, pBlockTbl++) {
if (pBlockTbl->offset == 0)
continue;
if (pBlockTbl->flags != 0)
@ -495,11 +495,9 @@ void mpqapi_remove_hash_entry(const char *pszName)
void mpqapi_remove_hash_entries(bool (*fnGetName)(uint8_t, char *))
{
DWORD dwIndex, i;
char pszFileName[MAX_PATH];
dwIndex = 1;
for (i = fnGetName(0, pszFileName); i; i = fnGetName(dwIndex++, pszFileName)) {
for (uint8_t i = 0; fnGetName(i, pszFileName); i++) {
mpqapi_remove_hash_entry(pszFileName);
}
}
@ -507,7 +505,7 @@ void mpqapi_remove_hash_entries(bool (*fnGetName)(uint8_t, char *))
static _BLOCKENTRY *mpqapi_add_file(const char *pszName, _BLOCKENTRY *pBlk, int block_index)
{
DWORD h1, h2, h3;
int i, hIdx;
int hIdx;
h1 = Hash(pszName, 0);
h2 = Hash(pszName, 1);
@ -515,14 +513,18 @@ static _BLOCKENTRY *mpqapi_add_file(const char *pszName, _BLOCKENTRY *pBlk, int
if (mpqapi_get_hash_index(h1, h2, h3) != -1)
app_fatal("Hash collision between \"%s\" and existing file\n", pszName);
hIdx = h1 & 0x7FF;
i = INDEX_ENTRIES;
while (i--) {
if (cur_archive.sgpHashTbl[hIdx].block == -1 || cur_archive.sgpHashTbl[hIdx].block == -2)
bool hasSpace = false;
for (int i = 0; i < INDEX_ENTRIES; i++) {
if (cur_archive.sgpHashTbl[hIdx].block == -1 || cur_archive.sgpHashTbl[hIdx].block == -2) {
hasSpace = true;
break;
}
hIdx = (hIdx + 1) & 0x7FF;
}
if (i < 0)
if (!hasSpace)
app_fatal("Out of hash space");
if (pBlk == nullptr)
pBlk = mpqapi_new_block(&block_index);
@ -537,9 +539,9 @@ static _BLOCKENTRY *mpqapi_add_file(const char *pszName, _BLOCKENTRY *pBlk, int
static bool mpqapi_write_file_contents(const char *pszName, const byte *pbData, size_t dwLen, _BLOCKENTRY *pBlk)
{
const char *tmp;
while ((tmp = strchr(pszName, ':')))
while ((tmp = strchr(pszName, ':')) != nullptr)
pszName = tmp + 1;
while ((tmp = strchr(pszName, '\\')))
while ((tmp = strchr(pszName, '\\')) != nullptr)
pszName = tmp + 1;
Hash(pszName, 3);
@ -668,7 +670,7 @@ bool OpenMPQ(const char *pszArchive)
}
cur_archive.sgpBlockTbl = new _BLOCKENTRY[BlockEntrySize / sizeof(_BLOCKENTRY)];
std::memset(cur_archive.sgpBlockTbl, 0, BlockEntrySize);
if (fhdr.blockcount) {
if (fhdr.blockcount > 0) {
if (!cur_archive.stream.read(reinterpret_cast<char *>(cur_archive.sgpBlockTbl), BlockEntrySize))
goto on_error;
key = Hash("(block table)", 3);
@ -676,7 +678,7 @@ bool OpenMPQ(const char *pszArchive)
}
cur_archive.sgpHashTbl = new _HASHENTRY[HashEntrySize / sizeof(_HASHENTRY)];
std::memset(cur_archive.sgpHashTbl, 255, HashEntrySize);
if (fhdr.hashcount) {
if (fhdr.hashcount > 0) {
if (!cur_archive.stream.read(reinterpret_cast<char *>(cur_archive.sgpHashTbl), HashEntrySize))
goto on_error;
key = Hash("(hash table)", 3);

28
Source/msg.cpp

@ -295,7 +295,7 @@ static byte *DeltaExportJunk(byte *dst)
for (i = 0, q = 0; i < MAXQUESTS; i++) {
if (!questlist[i].isSinglePlayerOnly) {
sgJunk.quests[q].qlog = quests[i]._qlog;
sgJunk.quests[q].qlog = quests[i]._qlog ? 1 : 0;
sgJunk.quests[q].qstate = quests[i]._qactive;
sgJunk.quests[q].qvar1 = quests[i]._qvar1;
memcpy(dst, &sgJunk.quests[q], sizeof(MultiQuests));
@ -333,7 +333,7 @@ static void DeltaImportJunk(byte *src)
if (!questlist[i].isSinglePlayerOnly) {
memcpy(&sgJunk.quests[q], src, sizeof(MultiQuests));
src += sizeof(MultiQuests);
quests[i]._qlog = sgJunk.quests[q].qlog;
quests[i]._qlog = sgJunk.quests[q].qlog != 0;
quests[i]._qactive = sgJunk.quests[q].qstate;
quests[i]._qvar1 = sgJunk.quests[q].qvar1;
q++;
@ -671,7 +671,7 @@ void DeltaAddItem(int ii)
pD->wIndx = items[ii].IDidx;
pD->wCI = items[ii]._iCreateInfo;
pD->dwSeed = items[ii]._iSeed;
pD->bId = items[ii]._iIdentified;
pD->bId = items[ii]._iIdentified ? 1 : 0;
pD->bDur = items[ii]._iDurability;
pD->bMDur = items[ii]._iMaxDur;
pD->bCh = items[ii]._iCharges;
@ -738,7 +738,7 @@ void DeltaLoadLevel()
M_UpdateLeader(i);
} else {
decode_enemy(i, sgLevels[currlevel].monster[i]._menemy);
if ((monster[i].position.tile.x && monster[i].position.tile.x != 1) || monster[i].position.tile.y)
if (monster[i].position.tile != Point { 0, 0 } && monster[i].position.tile != Point { 1, 0 })
dMonster[monster[i].position.tile.x][monster[i].position.tile.y] = i + 1;
if (i < MAX_PLRS) {
MAI_Golum(i);
@ -789,7 +789,7 @@ void DeltaLoadLevel()
sgLevels[currlevel].item[i].dwSeed,
sgLevels[currlevel].item[i].wValue,
(sgLevels[currlevel].item[i].dwBuff & CF_HELLFIRE) != 0);
if (sgLevels[currlevel].item[i].bId)
if (sgLevels[currlevel].item[i].bId != 0)
items[ii]._iIdentified = true;
items[ii]._iDurability = sgLevels[currlevel].item[i].bDur;
items[ii]._iMaxDur = sgLevels[currlevel].item[i].bMDur;
@ -983,7 +983,7 @@ void NetSendCmdQuest(bool bHiPri, BYTE q)
cmd.q = q;
cmd.bCmd = CMD_SYNCQUEST;
cmd.qstate = quests[q]._qactive;
cmd.qlog = quests[q]._qlog;
cmd.qlog = quests[q]._qlog ? 1 : 0;
cmd.qvar1 = quests[q]._qvar1;
if (bHiPri)
NetSendHiPri(myplr, (byte *)&cmd, sizeof(cmd));
@ -1018,7 +1018,7 @@ void NetSendCmdGItem(bool bHiPri, _cmd_id bCmd, BYTE mast, BYTE pnum, BYTE ii)
} else {
cmd.wCI = items[ii]._iCreateInfo;
cmd.dwSeed = items[ii]._iSeed;
cmd.bId = items[ii]._iIdentified;
cmd.bId = items[ii]._iIdentified ? 1 : 0;
cmd.bDur = items[ii]._iDurability;
cmd.bMDur = items[ii]._iMaxDur;
cmd.bCh = items[ii]._iCharges;
@ -1116,7 +1116,7 @@ void NetSendCmdPItem(bool bHiPri, _cmd_id bCmd, Point position)
} else {
cmd.wCI = plr[myplr].HoldItem._iCreateInfo;
cmd.dwSeed = plr[myplr].HoldItem._iSeed;
cmd.bId = plr[myplr].HoldItem._iIdentified;
cmd.bId = plr[myplr].HoldItem._iIdentified ? 1 : 0;
cmd.bDur = plr[myplr].HoldItem._iDurability;
cmd.bMDur = plr[myplr].HoldItem._iMaxDur;
cmd.bCh = plr[myplr].HoldItem._iCharges;
@ -1146,7 +1146,7 @@ void NetSendCmdChItem(bool bHiPri, BYTE bLoc)
cmd.wIndx = plr[myplr].HoldItem.IDidx;
cmd.wCI = plr[myplr].HoldItem._iCreateInfo;
cmd.dwSeed = plr[myplr].HoldItem._iSeed;
cmd.bId = plr[myplr].HoldItem._iIdentified;
cmd.bId = plr[myplr].HoldItem._iIdentified ? 1 : 0;
cmd.dwBuff = plr[myplr].HoldItem.dwBuff;
if (bHiPri)
@ -1189,7 +1189,7 @@ void NetSendCmdDItem(bool bHiPri, int ii)
} else {
cmd.wCI = items[ii]._iCreateInfo;
cmd.dwSeed = items[ii]._iSeed;
cmd.bId = items[ii]._iIdentified;
cmd.bId = items[ii]._iIdentified ? 1 : 0;
cmd.bDur = items[ii]._iDurability;
cmd.bMDur = items[ii]._iMaxDur;
cmd.bCh = items[ii]._iCharges;
@ -1283,7 +1283,7 @@ static void delta_open_portal(int pnum, uint8_t x, uint8_t y, uint8_t bLevel, du
sgJunk.portal[pnum].y = y;
sgJunk.portal[pnum].level = bLevel;
sgJunk.portal[pnum].ltype = bLType;
sgJunk.portal[pnum].setlvl = bSetLvl;
sgJunk.portal[pnum].setlvl = bSetLvl ? 1 : 0;
}
void delta_close_portal(int pnum)
@ -2155,7 +2155,7 @@ static DWORD On_CHANGEPLRITEMS(TCmd *pCmd, int pnum)
if (gbBufferMsgs == 1)
msg_send_packet(pnum, p, sizeof(*p));
else if (pnum != myplr)
CheckInvSwap(pnum, p->bLoc, p->wIndx, p->wCI, p->dwSeed, p->bId, p->dwBuff);
CheckInvSwap(pnum, p->bLoc, p->wIndx, p->wCI, p->dwSeed, p->bId != 0, p->dwBuff);
return sizeof(*p);
}
@ -2263,7 +2263,7 @@ static DWORD On_ACTIVATEPORTAL(TCmd *pCmd, int pnum)
if (gbBufferMsgs == 1)
msg_send_packet(pnum, p, sizeof(*p));
else {
ActivatePortal(pnum, p->x, p->y, p->wParam1, (dungeon_type)p->wParam2, p->wParam3);
ActivatePortal(pnum, p->x, p->y, p->wParam1, static_cast<dungeon_type>(p->wParam2), p->wParam3 != 0);
if (pnum != myplr) {
if (currlevel == 0)
AddInTownPortal(pnum);
@ -2281,7 +2281,7 @@ static DWORD On_ACTIVATEPORTAL(TCmd *pCmd, int pnum)
} else
RemovePortalMissile(pnum);
}
delta_open_portal(pnum, p->x, p->y, p->wParam1, (dungeon_type)p->wParam2, p->wParam3);
delta_open_portal(pnum, p->x, p->y, p->wParam1, static_cast<dungeon_type>(p->wParam2), p->wParam3 != 0);
}
return sizeof(*p);

6
Source/nthread.cpp

@ -159,9 +159,9 @@ void nthread_start(bool set_turn_upper_bit)
caps.size = 36;
SNetGetProviderCaps(&caps);
gdwTurnsInTransit = caps.defaultturnsintransit;
if (!caps.defaultturnsintransit)
if (gdwTurnsInTransit == 0)
gdwTurnsInTransit = 1;
if (caps.defaultturnssec <= 20 && caps.defaultturnssec)
if (caps.defaultturnssec <= 20 && caps.defaultturnssec != 0)
sgbNetUpdateRate = 20 / caps.defaultturnssec;
else
sgbNetUpdateRate = 1;
@ -239,7 +239,7 @@ bool nthread_has_500ms_passed()
void nthread_UpdateProgressToNextGameTick()
{
if (!gbRunGame || PauseMode || (!gbIsMultiplayer && gmenu_is_active()) || !gbProcessPlayers) // if game is not running or paused there is no next gametick in the near future
if (!gbRunGame || PauseMode != 0 || (!gbIsMultiplayer && gmenu_is_active()) || !gbProcessPlayers) // if game is not running or paused there is no next gametick in the near future
return;
int currentTickCount = SDL_GetTicks();
int ticksElapsed = last_tick - currentTickCount;

24
Source/objects.cpp

@ -285,7 +285,7 @@ void InitObjectGFX()
char filestr[32];
int i, j;
memset(fileload, false, sizeof(fileload));
memset(fileload, 0, sizeof(fileload));
int lvl = currlevel;
if (currlevel >= 21 && currlevel <= 24)
@ -2997,7 +2997,7 @@ void OperateBookLever(int pnum, int i)
quests[Q_BLOOD]._qactive = QUEST_ACTIVE;
quests[Q_BLOOD]._qlog = true;
quests[Q_BLOOD]._qvar1 = 1;
SpawnQuestItem(IDI_BLDSTONE, { 2 * setpc_x + 25, 2 * setpc_y + 33 }, 0, true);
SpawnQuestItem(IDI_BLDSTONE, { 2 * setpc_x + 25, 2 * setpc_y + 33 }, 0, 1);
}
object[i]._otype = object[i]._otype;
if (object[i]._otype == OBJ_STEELTOME && quests[Q_WARLORD]._qvar1 == 0) {
@ -3142,7 +3142,7 @@ void OperateMushPatch(int pnum, int i)
object[i]._oAnimFrame++;
if (!deltaload) {
Point pos = GetSuperItemLoc(object[i].position);
SpawnQuestItem(IDI_MUSHROOM, pos, 0, false);
SpawnQuestItem(IDI_MUSHROOM, pos, 0, 0);
quests[Q_MUSHROOM]._qvar1 = QS_MUSHSPAWNED;
}
}
@ -3166,7 +3166,7 @@ void OperateInnSignChest(int pnum, int i)
object[i]._oAnimFrame += 2;
if (!deltaload) {
Point pos = GetSuperItemLoc(object[i].position);
SpawnQuestItem(IDI_BANNER, pos, 0, false);
SpawnQuestItem(IDI_BANNER, pos, 0, 0);
}
}
}
@ -3292,13 +3292,13 @@ void OperatePedistal(int pnum, int i)
if (!deltaload)
PlaySfxLoc(LS_PUDDLE, object[i].position);
ObjChangeMap(setpc_x, setpc_y + 3, setpc_x + 2, setpc_y + 7);
SpawnQuestItem(IDI_BLDSTONE, { 2 * setpc_x + 19, 2 * setpc_y + 26 }, 0, true);
SpawnQuestItem(IDI_BLDSTONE, { 2 * setpc_x + 19, 2 * setpc_y + 26 }, 0, 1);
}
if (object[i]._oVar6 == 2) {
if (!deltaload)
PlaySfxLoc(LS_PUDDLE, object[i].position);
ObjChangeMap(setpc_x + 6, setpc_y + 3, setpc_x + setpc_w, setpc_y + 7);
SpawnQuestItem(IDI_BLDSTONE, { 2 * setpc_x + 31, 2 * setpc_y + 26 }, 0, true);
SpawnQuestItem(IDI_BLDSTONE, { 2 * setpc_x + 31, 2 * setpc_y + 26 }, 0, 1);
}
if (object[i]._oVar6 == 3) {
if (!deltaload)
@ -3621,7 +3621,7 @@ bool OperateShrineEnchanted(int pnum)
int r;
do {
r = GenerateRnd(maxSpells);
} while (!(plr[pnum]._pMemSpells & GetSpellBitmask(r + 1)));
} while ((plr[pnum]._pMemSpells & GetSpellBitmask(r + 1)) == 0);
if (plr[pnum]._pSplLvl[r + 1] >= 2)
plr[pnum]._pSplLvl[r + 1] -= 2;
else
@ -4029,15 +4029,15 @@ bool OperateShrineGlimmering(int pnum)
return false;
for (auto &item : plr[pnum].InvBody) {
if (item._iMagical && !item._iIdentified)
if (item._iMagical != ITEM_QUALITY_NORMAL && !item._iIdentified)
item._iIdentified = true;
}
for (int j = 0; j < plr[pnum]._pNumInv; j++) {
if (plr[pnum].InvList[j]._iMagical && !plr[pnum].InvList[j]._iIdentified)
if (plr[pnum].InvList[j]._iMagical != ITEM_QUALITY_NORMAL && !plr[pnum].InvList[j]._iIdentified)
plr[pnum].InvList[j]._iIdentified = true;
}
for (auto &item : plr[pnum].SpdList) {
if (item._iMagical && !item._iIdentified)
if (item._iMagical != ITEM_QUALITY_NORMAL && !item._iIdentified)
item._iIdentified = true; // belt items can't be magical?
}
@ -4487,7 +4487,7 @@ void OperateBookCase(int pnum, int i, bool sendmsg)
&& monster[MAX_PLRS]._mmode == MM_STAND // prevents playing the "angry" message for the second time if zhar got aggroed by losing vision and talking again
&& monster[MAX_PLRS]._uniqtype - 1 == UMT_ZHAR
&& monster[MAX_PLRS]._msquelch == UINT8_MAX
&& monster[MAX_PLRS]._mhitpoints) {
&& monster[MAX_PLRS]._mhitpoints > 0) {
monster[MAX_PLRS].mtalkmsg = TEXT_ZHAR2;
M_StartStand(0, monster[MAX_PLRS]._mdir);
monster[MAX_PLRS]._mgoal = MGOAL_ATTACK2;
@ -4774,7 +4774,7 @@ void OperateLazStand(int pnum, int i)
object[i]._oAnimFrame++;
object[i]._oSelFlag = 0;
Point pos = GetSuperItemLoc(object[i].position);
SpawnQuestItem(IDI_LAZSTAFF, pos, 0, false);
SpawnQuestItem(IDI_LAZSTAFF, pos, 0, 0);
}
}

2
Source/pack.cpp

@ -157,7 +157,7 @@ void UnPackItem(const PkItemStruct *is, ItemStruct *id, bool isHellfire)
} else {
memset(&items[MAXITEMS], 0, sizeof(*items));
RecreateItem(MAXITEMS, idx, SDL_SwapLE16(is->iCreateInfo), SDL_SwapLE32(is->iSeed), SDL_SwapLE16(is->wValue), isHellfire);
items[MAXITEMS]._iMagical = is->bId >> 1;
items[MAXITEMS]._iMagical = static_cast<item_quality>(is->bId >> 1);
items[MAXITEMS]._iIdentified = (is->bId & 1) != 0;
items[MAXITEMS]._iDurability = is->bDur;
items[MAXITEMS]._iMaxDur = is->bMDur;

8
Source/player.cpp

@ -2110,7 +2110,7 @@ bool PM_DoWalk(int pnum, int variant)
auto &player = plr[pnum];
//Play walking sound effect on certain animation frames
if (sgOptions.Audio.bWalkingSound && (currlevel != 0 || !sgGameInitInfo.bRunInTown)) {
if (sgOptions.Audio.bWalkingSound && (currlevel != 0 || sgGameInitInfo.bRunInTown == 0)) {
if (player.AnimInfo.CurrentFrame == 1
|| player.AnimInfo.CurrentFrame == 5) {
PlaySfxLoc(PS_WALK1, player.position.tile);
@ -2174,7 +2174,7 @@ static bool WeaponDurDecay(int pnum, int ii)
{
auto &player = plr[pnum];
if (!player.InvBody[ii].isEmpty() && player.InvBody[ii]._iClass == ICLASS_WEAPON && player.InvBody[ii]._iDamAcFlags & 2) {
if (!player.InvBody[ii].isEmpty() && player.InvBody[ii]._iClass == ICLASS_WEAPON && (player.InvBody[ii]._iDamAcFlags & 2) != 0) {
player.InvBody[ii]._iPLDam -= 5;
if (player.InvBody[ii]._iPLDam <= -100) {
NetSendCmdDelItem(true, ii);
@ -2349,7 +2349,7 @@ bool PlrHitMonst(int pnum, int m)
#else
if (hit < hper) {
#endif
if (player._pIFlags & ISPL_FIREDAM && player._pIFlags & ISPL_LIGHTDAM) {
if ((player._pIFlags & ISPL_FIREDAM) != 0 && (player._pIFlags & ISPL_LIGHTDAM) != 0) {
int midam = player._pIFMinDam + GenerateRnd(player._pIFMaxDam - player._pIFMinDam);
AddMissile(player.position.tile, player.position.temp, player._pdir, MIS_SPECARROW, TARGET_MONSTERS, pnum, midam, 0);
}
@ -2397,7 +2397,7 @@ bool PlrHitMonst(int pnum, int m)
break;
}
if (player.pDamAcFlags & 0x01 && GenerateRnd(100) < 5) {
if ((player.pDamAcFlags & 0x01) != 0 && GenerateRnd(100) < 5) {
dam *= 3;
}

4
Source/scrollrt.cpp

@ -827,13 +827,13 @@ static void scrollrt_draw_dungeon(const CelOutputBuffer &out, int sx, int sy, in
if (bArch != 0) {
cel_transparency_active = TransList[bMap];
#ifdef _DEBUG
if ((GetAsyncKeyState(DVL_VK_MENU) & 0x8000) != 0) {
if (GetAsyncKeyState(DVL_VK_MENU)) {
cel_transparency_active = false; // Turn transparency off here for debugging
}
#endif
CelClippedBlitLightTransTo(out, { dx, dy }, *pSpecialCels, bArch);
#ifdef _DEBUG
if ((GetAsyncKeyState(DVL_VK_MENU) & 0x8000) != 0) {
if (GetAsyncKeyState(DVL_VK_MENU)) {
cel_transparency_active = TransList[bMap]; // Turn transparency back to its normal state
}
#endif

6
Source/stores.cpp

@ -237,7 +237,7 @@ void S_ScrollSBuy(int idx)
if (!smithitem[idx].isEmpty()) {
uint16_t iclr = smithitem[idx].getTextColorWithStatCheck();
if (smithitem[idx]._iMagical != 0) {
if (smithitem[idx]._iMagical != ITEM_QUALITY_NORMAL) {
AddSText(20, l, smithitem[idx]._iIName, iclr, true);
} else {
AddSText(20, l, smithitem[idx]._iName, iclr, true);
@ -385,7 +385,7 @@ void S_ScrollSSell(int idx)
if (!storehold[idx].isEmpty()) {
uint16_t iclr = storehold[idx].getTextColorWithStatCheck();
if (storehold[idx]._iMagical != 0 && storehold[idx]._iIdentified) {
if (storehold[idx]._iMagical != ITEM_QUALITY_NORMAL && storehold[idx]._iIdentified) {
AddSText(20, l, storehold[idx]._iIName, iclr, true);
AddSTextVal(l, storehold[idx]._iIvalue);
} else {
@ -609,7 +609,7 @@ void S_ScrollWBuy(int idx)
if (!witchitem[idx].isEmpty()) {
uint16_t iclr = witchitem[idx].getTextColorWithStatCheck();
if (witchitem[idx]._iMagical != 0) {
if (witchitem[idx]._iMagical != ITEM_QUALITY_NORMAL) {
AddSText(20, l, witchitem[idx]._iIName, iclr, true);
} else {
AddSText(20, l, witchitem[idx]._iName, iclr, true);

Loading…
Cancel
Save