diff --git a/Source/control.cpp b/Source/control.cpp index 1d8f3a501..36d660e83 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -481,10 +481,8 @@ void SetSpell() void SetSpeedSpell(int slot) { - int i; - if (pSpell != SPL_INVALID) { - for (i = 0; i < 4; ++i) { + for (int i = 0; i < 4; ++i) { if (plr[myplr]._pSplHotKey[i] == pSpell && plr[myplr]._pSplTHotKey[i] == pSplType) plr[myplr]._pSplHotKey[i] = SPL_INVALID; } diff --git a/Source/inv.cpp b/Source/inv.cpp index 9c93eadae..867e73b18 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -660,9 +660,8 @@ bool AutoPlaceItemInBelt(int playerNumber, const ItemStruct &item, bool persistI */ bool CanEquip(const ItemStruct &item) { - return - item.isEquipment() && - item._iStatFlag; + return item.isEquipment() + && item._iStatFlag; } /** @@ -702,23 +701,20 @@ bool CanWield(int playerNumber, const ItemStruct &item) // Bard can dual wield swords and maces, so we allow equiping one-handed weapons in her free slot as long as her occupied // slot is another one-handed weapon. if (player._pClass == PC_BARD) { - bool occupiedHandIsOneHandedSwordOrMace = - occupiedHand._iLoc == ILOC_ONEHAND && - (occupiedHand._itype == ITYPE_SWORD || occupiedHand._itype == ITYPE_MACE); + bool occupiedHandIsOneHandedSwordOrMace = occupiedHand._iLoc == ILOC_ONEHAND + && (occupiedHand._itype == ITYPE_SWORD || occupiedHand._itype == ITYPE_MACE); - bool weaponToEquipIsOneHandedSwordOrMace = - item._iLoc == ILOC_ONEHAND && - (item._itype == ITYPE_SWORD || item._itype == ITYPE_MACE); + bool weaponToEquipIsOneHandedSwordOrMace = item._iLoc == ILOC_ONEHAND + && (item._itype == ITYPE_SWORD || item._itype == ITYPE_MACE); if (occupiedHandIsOneHandedSwordOrMace && weaponToEquipIsOneHandedSwordOrMace) { return true; } } - return - item._iLoc == ILOC_ONEHAND && - occupiedHand._iLoc == ILOC_ONEHAND && - item._iClass != occupiedHand._iClass; + return item._iLoc == ILOC_ONEHAND + && occupiedHand._iLoc == ILOC_ONEHAND + && item._iClass != occupiedHand._iClass; } /** @@ -1776,12 +1772,10 @@ void CheckInvCut(int pnum, int mx, int my, bool automaticMove) case PC_BARBARIAN: PlaySFX(PS_WARR15, false); break; - case PC_ROGUE: case PC_BARD: PlaySFX(PS_ROGUE15, false); break; - case PC_SORCERER: PlaySFX(PS_MAGE15, false); break; diff --git a/Source/items.cpp b/Source/items.cpp index 0e21b05f5..e5b4e751b 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -4602,28 +4602,22 @@ int RndPremiumItem(int minlvl, int maxlvl) static void SpawnOnePremium(int i, int plvl, int myplr) { - int itype; - ItemStruct holditem; - - holditem = item[0]; - int ivalue; - int count = 0; + ItemStruct holditem = item[0]; int strength = get_max_strength(plr[myplr]._pClass); - int dexterity = get_max_dexterity(plr[myplr]._pClass); - int magic = get_max_magic(plr[myplr]._pClass); - if (strength < plr[myplr]._pStrength) { strength = plr[myplr]._pStrength; } strength *= 1.2; + int dexterity = get_max_dexterity(plr[myplr]._pClass); if (dexterity < plr[myplr]._pDexterity) { dexterity = plr[myplr]._pDexterity; } dexterity *= 1.2; + int magic = get_max_magic(plr[myplr]._pClass); if (magic < plr[myplr]._pMagic) { magic = plr[myplr]._pMagic; } @@ -4634,11 +4628,13 @@ static void SpawnOnePremium(int i, int plvl, int myplr) if (plvl < 1) plvl = 1; + int count = 0; + do { memset(&item[0], 0, sizeof(*item)); item[0]._iSeed = AdvanceRndSeed(); SetRndSeed(item[0]._iSeed); - itype = RndPremiumItem(plvl >> 2, plvl) - 1; + int itype = RndPremiumItem(plvl >> 2, plvl) - 1; GetItemAttrs(0, itype, plvl); GetItemBonus(0, itype, plvl >> 1, plvl, TRUE, !gbIsHellfire); diff --git a/Source/monster.cpp b/Source/monster.cpp index bd1af1bd9..365533983 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -1191,7 +1191,6 @@ void SetMapMonsters(BYTE *pMap, int startx, int starty) } lm = (WORD *)pMap; rw = SDL_SwapLE16(*lm++); - lm; rh = SDL_SwapLE16(*lm++); lm += rw * rh; rw = rw << 1; diff --git a/Source/multi.cpp b/Source/multi.cpp index ed606a840..7b99595c8 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -433,7 +433,7 @@ static void multi_process_tmsgs() int cnt; TPkt pkt; - while (cnt = tmsg_get((BYTE *)&pkt, 512)) { + while ((cnt = tmsg_get((BYTE *)&pkt, 512)) != 0) { multi_handle_all_packets(myplr, (BYTE *)&pkt, cnt); } } diff --git a/Source/player.cpp b/Source/player.cpp index 24e7e136a..9b103d348 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -3491,8 +3491,6 @@ static void CheckCheatStats(int pnum) void ProcessPlayers() { - int pnum; - if ((DWORD)myplr >= MAX_PLRS) { app_fatal("ProcessPlayers: illegal player %d", myplr); } @@ -3525,7 +3523,7 @@ void ProcessPlayers() ValidatePlayer(); - for (pnum = 0; pnum < MAX_PLRS; pnum++) { + for (int pnum = 0; pnum < MAX_PLRS; pnum++) { if (plr[pnum].plractive && currlevel == plr[pnum].plrlevel && (pnum == myplr || !plr[pnum]._pLvlChanging)) { CheckCheatStats(pnum); diff --git a/Source/plrmsg.cpp b/Source/plrmsg.cpp index a547207bd..0962f76e3 100644 --- a/Source/plrmsg.cpp +++ b/Source/plrmsg.cpp @@ -61,8 +61,8 @@ void SendPlrMsg(int pnum, const char *pszStr) plr_msg_slot = (plr_msg_slot + 1) & (PMSG_COUNT - 1); pMsg->player = pnum; pMsg->time = SDL_GetTicks(); - strlen(plr[pnum]._pName); /* these are used in debug */ - strlen(pszStr); + assert(strlen(plr[pnum]._pName) < PLR_NAME_LEN); + assert(strlen(pszStr) < MAX_SEND_STR_LEN); sprintf(pMsg->str, "%s (lvl %d): %s", plr[pnum]._pName, plr[pnum]._pLevel, pszStr); } diff --git a/SourceT/writehero_test.cpp b/SourceT/writehero_test.cpp index ab0c6069d..d3ea6bdb4 100644 --- a/SourceT/writehero_test.cpp +++ b/SourceT/writehero_test.cpp @@ -8,15 +8,17 @@ using namespace dvl; -int spelldat_vanilla[] = {0, 1, 1, 4, 5, -1, 3, 3, 6, -1, 7, 6, 8, 9, - 8, 9, -1, -1, -1, -1, 3, 11, -1, 14, -1, -1, - -1, -1, -1, 8, 1, 1, -1, 2, 1, 14, 9}; +int spelldat_vanilla[] = { + 0, 1, 1, 4, 5, -1, 3, 3, 6, -1, 7, 6, 8, 9, + 8, 9, -1, -1, -1, -1, 3, 11, -1, 14, -1, -1, + -1, -1, -1, 8, 1, 1, -1, 2, 1, 14, 9 +}; static void PackItemUnique(PkItemStruct *id, int idx) { id->idx = idx; id->iCreateInfo = 0x2DE; - id->bId = 1+2*ITEM_QUALITY_UNIQUE; + id->bId = 1 + 2 * ITEM_QUALITY_UNIQUE; id->bDur = 40; id->bMDur = 40; id->bCh = 0; @@ -28,7 +30,7 @@ static void PackItemStaff(PkItemStruct *id) { id->idx = 150; id->iCreateInfo = 0x2010; - id->bId = 1+2*ITEM_QUALITY_MAGIC; + id->bId = 1 + 2 * ITEM_QUALITY_MAGIC; id->bDur = 75; id->bMDur = 75; id->bCh = 12; @@ -40,7 +42,7 @@ static void PackItemBow(PkItemStruct *id) { id->idx = 145; id->iCreateInfo = 0x0814; - id->bId = 1+2*ITEM_QUALITY_MAGIC; + id->bId = 1 + 2 * ITEM_QUALITY_MAGIC; id->bDur = 60; id->bMDur = 60; id->bCh = 0; @@ -52,7 +54,7 @@ static void PackItemSword(PkItemStruct *id) { id->idx = 122; id->iCreateInfo = 0x081E; - id->bId = 1+2*ITEM_QUALITY_MAGIC; + id->bId = 1 + 2 * ITEM_QUALITY_MAGIC; id->bDur = 60; id->bMDur = 60; id->bCh = 0; @@ -64,7 +66,7 @@ static void PackItemRing1(PkItemStruct *id) { id->idx = 153; id->iCreateInfo = 0xDE; - id->bId = 1+2*ITEM_QUALITY_MAGIC; + id->bId = 1 + 2 * ITEM_QUALITY_MAGIC; id->bDur = 0; id->bMDur = 0; id->bCh = 0; @@ -76,7 +78,7 @@ static void PackItemRing2(PkItemStruct *id) { id->idx = 153; id->iCreateInfo = 0xDE; - id->bId = 1+2*ITEM_QUALITY_MAGIC; + id->bId = 1 + 2 * ITEM_QUALITY_MAGIC; id->bDur = 0; id->bMDur = 0; id->bCh = 0; @@ -88,7 +90,7 @@ static void PackItemAmulet(PkItemStruct *id) { id->idx = 155; id->iCreateInfo = 0xDE; - id->bId = 1+2*ITEM_QUALITY_MAGIC; + id->bId = 1 + 2 * ITEM_QUALITY_MAGIC; id->bDur = 0; id->bMDur = 0; id->bCh = 0; @@ -100,7 +102,7 @@ static void PackItemArmor(PkItemStruct *id) { id->idx = 70; id->iCreateInfo = 0xDE; - id->bId = 1+2*ITEM_QUALITY_MAGIC; + id->bId = 1 + 2 * ITEM_QUALITY_MAGIC; id->bDur = 90; id->bMDur = 90; id->bCh = 0; @@ -110,41 +112,41 @@ static void PackItemArmor(PkItemStruct *id) static void PackItemFullRejuv(PkItemStruct *id, int i) { - const Uint32 seeds[] = {0x7C253335, 0x3EEFBFF8, 0x76AFB1A9, 0x38EB45FE, 0x1154E197, 0x5964B644, 0x76B58BEB, 0x002A6E5A}; + const Uint32 seeds[] = { 0x7C253335, 0x3EEFBFF8, 0x76AFB1A9, 0x38EB45FE, 0x1154E197, 0x5964B644, 0x76B58BEB, 0x002A6E5A }; id->idx = ItemMiscIdIdx(IMISC_FULLREJUV); id->iSeed = seeds[i]; id->iCreateInfo = 0; - id->bId = 2*ITEM_QUALITY_NORMAL; + id->bId = 2 * ITEM_QUALITY_NORMAL; id->bDur = 0; id->bMDur = 0; id->bCh = 0; id->bMCh = 0; } -static int PrepareInvSlot(PkPlayerStruct *pPack, int pos, int size, int start=0) +static int PrepareInvSlot(PkPlayerStruct *pPack, int pos, int size, int start = 0) { static char ret = 0; - if(start) + if (start) ret = 0; ++ret; - if(size == 0) { + if (size == 0) { pPack->InvGrid[pos] = ret; - } else if(size == 1) { + } else if (size == 1) { pPack->InvGrid[pos] = ret; - pPack->InvGrid[pos-10] = -ret; - pPack->InvGrid[pos-20] = -ret; - } else if(size == 2) { + pPack->InvGrid[pos - 10] = -ret; + pPack->InvGrid[pos - 20] = -ret; + } else if (size == 2) { pPack->InvGrid[pos] = ret; - pPack->InvGrid[pos+1] = -ret; - pPack->InvGrid[pos-10] = -ret; - pPack->InvGrid[pos-10+1] = -ret; - pPack->InvGrid[pos-20] = -ret; - pPack->InvGrid[pos-20+1] = -ret; - } else if(size == 3) { + pPack->InvGrid[pos + 1] = -ret; + pPack->InvGrid[pos - 10] = -ret; + pPack->InvGrid[pos - 10 + 1] = -ret; + pPack->InvGrid[pos - 20] = -ret; + pPack->InvGrid[pos - 20 + 1] = -ret; + } else if (size == 3) { pPack->InvGrid[pos] = ret; - pPack->InvGrid[pos+1] = -ret; - pPack->InvGrid[pos-10] = -ret; - pPack->InvGrid[pos-10+1] = -ret; + pPack->InvGrid[pos + 1] = -ret; + pPack->InvGrid[pos - 10] = -ret; + pPack->InvGrid[pos - 10 + 1] = -ret; } else { abort(); } @@ -172,7 +174,7 @@ static void PackPlayerTest(PkPlayerStruct *pPack) for (auto i = 0; i < 7; i++) pPack->InvBody[i].idx = -1; for (auto i = 0; i < MAXBELTITEMS; i++) - PackItemFullRejuv(pPack->SpdList+i, i); + PackItemFullRejuv(pPack->SpdList + i, i); for (auto i = 1; i < 37; i++) { if (spelldat_vanilla[i] != -1) { pPack->pMemSpells |= 1ULL << (i - 1); @@ -187,25 +189,26 @@ static void PackPlayerTest(PkPlayerStruct *pPack) pPack->pBaseMag = 15 + 55; pPack->pBaseDex = 30 + 220; pPack->pBaseVit = 20 + 60; - pPack->pHPBase = ((20+10)<<6)+((20+10)<<5) + 48*128 + (60<<6); + pPack->pHPBase = ((20 + 10) << 6) + ((20 + 10) << 5) + 48 * 128 + (60 << 6); pPack->pMaxHPBase = pPack->pHPBase; - pPack->pManaBase = (15<<6)+(15<<5) + 48*128 + (55<<6); + pPack->pManaBase = (15 << 6) + (15 << 5) + 48 * 128 + (55 << 6); pPack->pMaxManaBase = pPack->pManaBase; - PackItemUnique(pPack->InvBody+INVLOC_HEAD, 52); - PackItemRing1(pPack->InvBody+INVLOC_RING_LEFT); - PackItemRing2(pPack->InvBody+INVLOC_RING_RIGHT); - PackItemAmulet(pPack->InvBody+INVLOC_AMULET); - PackItemArmor(pPack->InvBody+INVLOC_CHEST); - PackItemBow(pPack->InvBody+INVLOC_HAND_LEFT); + PackItemUnique(pPack->InvBody + INVLOC_HEAD, 52); + PackItemRing1(pPack->InvBody + INVLOC_RING_LEFT); + PackItemRing2(pPack->InvBody + INVLOC_RING_RIGHT); + PackItemAmulet(pPack->InvBody + INVLOC_AMULET); + PackItemArmor(pPack->InvBody + INVLOC_CHEST); + PackItemBow(pPack->InvBody + INVLOC_HAND_LEFT); - PackItemStaff(pPack->InvList+PrepareInvSlot(pPack, 28, 2, 1)); - PackItemSword(pPack->InvList+PrepareInvSlot(pPack, 20, 1)); + PackItemStaff(pPack->InvList + PrepareInvSlot(pPack, 28, 2, 1)); + PackItemSword(pPack->InvList + PrepareInvSlot(pPack, 20, 1)); pPack->_pNumInv = 2; } -TEST(Writehero, pfile_write_hero) { +TEST(Writehero, pfile_write_hero) +{ SetPrefPath("."); std::remove("multi_0.sv"); @@ -215,7 +218,7 @@ TEST(Writehero, pfile_write_hero) { gbIsHellfireSaveGame = false; myplr = 0; - _uiheroinfo info{}; + _uiheroinfo info {}; strcpy(info.name, "TestPlayer"); info.heroclass = PC_ROGUE; pfile_ui_save_create(&info); @@ -228,5 +231,5 @@ TEST(Writehero, pfile_write_hero) { std::vector s(picosha2::k_digest_size); picosha2::hash256(f, s.begin(), s.end()); EXPECT_EQ(picosha2::bytes_to_hex_string(s.begin(), s.end()), - "08e9807d1281e4273268f4e265757b4429cfec7c3e8b6deb89dfa109d6797b1c"); + "08e9807d1281e4273268f4e265757b4429cfec7c3e8b6deb89dfa109d6797b1c"); }