From bc59218d0dc9525b045dfb13a57851897db04e4b Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 4 Jul 2021 19:33:10 +0200 Subject: [PATCH] More clang-tidy/Android Studio cleanups --- Source/drlg_l1.cpp | 5 --- Source/drlg_l2.cpp | 8 ----- Source/drlg_l3.cpp | 4 --- Source/drlg_l4.cpp | 4 --- Source/effects.cpp | 24 +++++++------ Source/gendung.cpp | 6 +--- Source/gendung.h | 4 +-- Source/gmenu.cpp | 4 +-- Source/inv.cpp | 38 ++++++++++---------- Source/items.cpp | 86 ++++++++++++++++++++------------------------- Source/lighting.cpp | 10 +++--- Source/lighting.h | 2 -- Source/loadsave.cpp | 6 ++-- Source/minitext.cpp | 21 +++++------ Source/monster.cpp | 2 +- Source/textdat.cpp | 2 +- Source/textdat.h | 2 +- Source/themes.cpp | 5 +-- Source/towners.cpp | 23 +----------- Source/towners.h | 7 ---- 20 files changed, 98 insertions(+), 165 deletions(-) diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index a0c6f51a0..cbc3adb26 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -855,11 +855,6 @@ static int DrlgPlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int ViewY = 2 * sy + 20; } - if (ldir == 0) { - LvlViewX = 2 * sx + 19; - LvlViewY = 2 * sy + 20; - } - if (sx < cx && sy < cy) return 0; if (sx > cx && sy < cy) diff --git a/Source/drlg_l2.cpp b/Source/drlg_l2.cpp index 113074629..c81ccb426 100644 --- a/Source/drlg_l2.cpp +++ b/Source/drlg_l2.cpp @@ -1685,14 +1685,6 @@ static bool DrlgL2PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, ViewX = 2 * sx + 21; ViewY = 2 * sy + 22; } - if (ldir == 0) { - LvlViewX = 2 * sx + 21; - LvlViewY = 2 * sy + 22; - } - if (ldir == 6) { - LvlViewX = 2 * sx + 21; - LvlViewY = 2 * sy + 22; - } return true; } diff --git a/Source/drlg_l3.cpp b/Source/drlg_l3.cpp index 297baedcb..18e936899 100644 --- a/Source/drlg_l3.cpp +++ b/Source/drlg_l3.cpp @@ -1670,10 +1670,6 @@ static bool DrlgL3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, ViewX = 2 * sx + 17; ViewY = 2 * sy + 19; } - if (ldir == 0) { - LvlViewX = 2 * sx + 17; - LvlViewY = 2 * sy + 19; - } return false; } diff --git a/Source/drlg_l4.cpp b/Source/drlg_l4.cpp index ff1d1fd33..900865a14 100644 --- a/Source/drlg_l4.cpp +++ b/Source/drlg_l4.cpp @@ -1172,10 +1172,6 @@ static bool DrlgL4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, ViewX = 2 * sx + 21; ViewY = 2 * sy + 22; } - if (ldir == 0) { - LvlViewX = 2 * sx + 21; - LvlViewY = 2 * sy + 22; - } return true; } diff --git a/Source/effects.cpp b/Source/effects.cpp index 1f4af812e..33b944b36 100644 --- a/Source/effects.cpp +++ b/Source/effects.cpp @@ -1329,7 +1329,7 @@ static void PrivSoundInit(BYTE bLoadMask) void sound_init() { - BYTE mask = sfx_MISC; + uint8_t mask = sfx_MISC; if (gbIsMultiplayer) { mask |= sfx_WARRIOR; if (!gbIsSpawn) @@ -1337,20 +1337,22 @@ void sound_init() if (gbIsHellfire) mask |= sfx_MONK; } else { - auto &myPlayer = plr[myplr]; - if (myPlayer._pClass == HeroClass::Warrior) { + switch (plr[myplr]._pClass) { + case HeroClass::Warrior: + case HeroClass::Barbarian: mask |= sfx_WARRIOR; - } else if (myPlayer._pClass == HeroClass::Rogue) { + break; + case HeroClass::Rogue: + case HeroClass::Bard: mask |= sfx_ROGUE; - } else if (myPlayer._pClass == HeroClass::Sorcerer) { + break; + case HeroClass::Sorcerer: mask |= sfx_SORCERER; - } else if (myPlayer._pClass == HeroClass::Monk) { + break; + case HeroClass::Monk: mask |= sfx_MONK; - } else if (myPlayer._pClass == HeroClass::Bard) { - mask |= sfx_ROGUE; - } else if (myPlayer._pClass == HeroClass::Barbarian) { - mask |= sfx_WARRIOR; - } else { + break; + default: app_fatal("effects:1"); } } diff --git a/Source/gendung.cpp b/Source/gendung.cpp index 12d15b860..4989f57f9 100644 --- a/Source/gendung.cpp +++ b/Source/gendung.cpp @@ -62,10 +62,6 @@ int ViewX; /** Specifies the player viewpoint Y-coordinate of the map. */ int ViewY; ScrollStruct ScrollInfo; -/** Specifies the level viewpoint X-coordinate of the map. */ -int LvlViewX; -/** Specifies the level viewpoint Y-coordinate of the map. */ -int LvlViewY; int MicroTileLen; char TransVal; /** Specifies the active transparency indices. */ @@ -99,7 +95,7 @@ char dObject[MAXDUNX][MAXDUNY]; /** Contains the item numbers (items array indices) of the map. */ int8_t dItem[MAXDUNX][MAXDUNY]; /** Contains the missile numbers (missiles array indices) of the map. */ -char dMissile[MAXDUNX][MAXDUNY]; +int8_t dMissile[MAXDUNX][MAXDUNY]; /** * Contains the arch frame numbers of the map from the special tileset * (e.g. "levels/l1data/l1s.cel"). Note, the special tileset of Tristram (i.e. diff --git a/Source/gendung.h b/Source/gendung.h index 88f346840..b64b45ee7 100644 --- a/Source/gendung.h +++ b/Source/gendung.h @@ -168,8 +168,6 @@ extern dungeon_type setlvltype; extern int ViewX; extern int ViewY; extern ScrollStruct ScrollInfo; -extern int LvlViewX; -extern int LvlViewY; extern int MicroTileLen; extern char TransVal; extern bool TransList[256]; @@ -184,7 +182,7 @@ extern int16_t dMonster[MAXDUNX][MAXDUNY]; extern int8_t dDead[MAXDUNX][MAXDUNY]; extern char dObject[MAXDUNX][MAXDUNY]; extern int8_t dItem[MAXDUNX][MAXDUNY]; -extern char dMissile[MAXDUNX][MAXDUNY]; +extern int8_t dMissile[MAXDUNX][MAXDUNY]; extern char dSpecial[MAXDUNX][MAXDUNY]; extern int themeCount; extern THEME_LOC themeLoc[MAXTHEMES]; diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 2308aa77d..6eaa6777f 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -30,7 +30,6 @@ bool mouseNavigation; TMenuItem *sgpCurrItem; int LogoAnim_tick; BYTE LogoAnim_frame; -int PentSpin_tick; void (*gmenu_current_option)(); TMenuItem *sgpCurrentMenu; int sgCurrentMenuIdx; @@ -130,9 +129,8 @@ void gmenu_set_items(TMenuItem *pItem, void (*gmFunc)()) mouseNavigation = false; sgpCurrentMenu = pItem; gmenu_current_option = gmFunc; - if (gmFunc != nullptr) { + if (gmenu_current_option != nullptr) { gmenu_current_option(); - pItem = sgpCurrentMenu; } sgCurrentMenuIdx = 0; if (sgpCurrentMenu != nullptr) { diff --git a/Source/inv.cpp b/Source/inv.cpp index d384352f5..a478ef895 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -863,13 +863,13 @@ void CheckInvPaste(int pnum, Point cursorPosition) } } - int it = 0; + int8_t it = 0; if (il == ILOC_UNEQUIPABLE) { done = true; int ii = r - SLOTXY_INV_FIRST; if (player.HoldItem._itype == ITYPE_GOLD) { if (player.InvGrid[ii] != 0) { - int iv = player.InvGrid[ii]; + int8_t iv = player.InvGrid[ii]; if (iv > 0) { if (player.InvList[iv - 1]._itype != ITYPE_GOLD) { it = iv; @@ -893,7 +893,7 @@ void CheckInvPaste(int pnum, Point cursorPosition) done = false; } else { if (player.InvGrid[xx + yy] != 0) { - int iv = player.InvGrid[xx + yy]; + int8_t iv = player.InvGrid[xx + yy]; if (iv < 0) iv = -iv; if (it != 0) { @@ -1053,30 +1053,30 @@ void CheckInvPaste(int pnum, Point cursorPosition) if (player.HoldItem._itype == ITYPE_GOLD && it == 0) { int ii = r - SLOTXY_INV_FIRST; if (player.InvGrid[ii] > 0) { - int il = player.InvGrid[ii] - 1; - int gt = player.InvList[il]._ivalue; + int invIndex = player.InvGrid[ii] - 1; + int gt = player.InvList[invIndex]._ivalue; int ig = player.HoldItem._ivalue + gt; if (ig <= MaxGold) { - player.InvList[il]._ivalue = ig; + player.InvList[invIndex]._ivalue = ig; player._pGold += player.HoldItem._ivalue; - SetPlrHandGoldCurs(&player.InvList[il]); + SetPlrHandGoldCurs(&player.InvList[invIndex]); } else { ig = MaxGold - gt; player._pGold += ig; player.HoldItem._ivalue -= ig; - player.InvList[il]._ivalue = MaxGold; - player.InvList[il]._iCurs = ICURS_GOLD_LARGE; + player.InvList[invIndex]._ivalue = MaxGold; + player.InvList[invIndex]._iCurs = ICURS_GOLD_LARGE; // BUGFIX: incorrect values here are leftover from beta (fixed) cn = GetGoldCursor(player.HoldItem._ivalue); cn += CURSOR_FIRSTITEM; } } else { - int il = player._pNumInv; - player.InvList[il] = player.HoldItem; + int invIndex = player._pNumInv; + player.InvList[invIndex] = player.HoldItem; player._pNumInv++; player.InvGrid[ii] = player._pNumInv; player._pGold += player.HoldItem._ivalue; - SetPlrHandGoldCurs(&player.InvList[il]); + SetPlrHandGoldCurs(&player.InvList[invIndex]); } } else { if (it == 0) { @@ -1084,10 +1084,10 @@ void CheckInvPaste(int pnum, Point cursorPosition) player._pNumInv++; it = player._pNumInv; } else { - int il = it - 1; + int invIndex = it - 1; if (player.HoldItem._itype == ITYPE_GOLD) player._pGold += player.HoldItem._ivalue; - cn = SwapItem(&player.InvList[il], &player.HoldItem); + cn = SwapItem(&player.InvList[invIndex], &player.HoldItem); if (player.HoldItem._itype == ITYPE_GOLD) player._pGold = CalculateGold(player); for (i = 0; i < NUM_INV_GRID_ELEM; i++) { @@ -1301,7 +1301,7 @@ void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove) if (r >= SLOTXY_INV_FIRST && r <= SLOTXY_INV_LAST) { int ig = r - SLOTXY_INV_FIRST; - int ii = player.InvGrid[ig]; + int8_t ii = player.InvGrid[ig]; if (ii != 0) { int iv = (ii < 0) ? -ii : ii; @@ -1421,13 +1421,13 @@ static void CheckBookLevel(PlayerStruct &player) return; player.HoldItem._iMinMag = spelldata[player.HoldItem._iSpell].sMinInt; - int slvl = player._pSplLvl[player.HoldItem._iSpell]; - while (slvl != 0) { + int8_t spellLevel = player._pSplLvl[player.HoldItem._iSpell]; + while (spellLevel != 0) { player.HoldItem._iMinMag += 20 * player.HoldItem._iMinMag / 100; - slvl--; + spellLevel--; if (player.HoldItem._iMinMag + 20 * player.HoldItem._iMinMag / 100 > 255) { player.HoldItem._iMinMag = -1; - slvl = 0; + spellLevel = 0; } } } diff --git a/Source/items.cpp b/Source/items.cpp index 7da5b7e02..281c47907 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -999,14 +999,14 @@ void CalcPlrBookVals(PlayerStruct &player) for (int i = 0; i < player._pNumInv; i++) { if (player.InvList[i]._itype == ITYPE_MISC && player.InvList[i]._iMiscId == IMISC_BOOK) { player.InvList[i]._iMinMag = spelldata[player.InvList[i]._iSpell].sMinInt; - int slvl = player._pSplLvl[player.InvList[i]._iSpell]; + int8_t spellLevel = player._pSplLvl[player.InvList[i]._iSpell]; - while (slvl != 0) { + while (spellLevel != 0) { player.InvList[i]._iMinMag += 20 * player.InvList[i]._iMinMag / 100; - slvl--; + spellLevel--; if (player.InvList[i]._iMinMag + 20 * player.InvList[i]._iMinMag / 100 > 255) { player.InvList[i]._iMinMag = 255; - slvl = 0; + spellLevel = 0; } } player.InvList[i]._iStatFlag = ItemMinStats(player, &player.InvList[i]); @@ -1569,7 +1569,7 @@ void GetStaffSpell(int i, int lvl, bool onlygood) void GetOilType(int i, int maxLvl) { int cnt = 2; - char rnd[32] = { 5, 6 }; + int8_t rnd[32] = { 5, 6 }; if (!gbIsMultiplayer) { if (maxLvl == 0) @@ -1584,7 +1584,7 @@ void GetOilType(int i, int maxLvl) } } - int t = rnd[GenerateRnd(cnt)]; + int8_t t = rnd[GenerateRnd(cnt)]; strcpy(items[i]._iName, _(OilNames[t])); strcpy(items[i]._iIName, _(OilNames[t])); @@ -2524,7 +2524,7 @@ void SpawnItem(int m, Point position, bool sendmsg) GetSuperItemSpace(position, ii); int uper = monster[m]._uniqtype != 0 ? 15 : 1; - int mLevel = monster[m].MData->mLevel; + int8_t mLevel = monster[m].MData->mLevel; if (!gbIsHellfire && monster[m].MType->mtype == MT_DIABLO) mLevel -= 15; @@ -3161,7 +3161,7 @@ static bool OilItem(ItemStruct *x, PlayerStruct &player) } break; case IMISC_OILFORT: - if (x->_iMaxDur != 255 && x->_iMaxDur < 200) { + if (x->_iMaxDur != DUR_INDESTRUCTIBLE && x->_iMaxDur < 200) { r = GenerateRnd(41) + 10; x->_iMaxDur += r; x->_iDurability += r; @@ -3266,9 +3266,6 @@ void PrintItemOil(char iDidx) AddPanelString(tempstr); break; case IMISC_RUNEL: - strcpy(tempstr, _("sets lightning trap")); - AddPanelString(tempstr); - break; case IMISC_GR_RUNEL: strcpy(tempstr, _("sets lightning trap")); AddPanelString(tempstr); @@ -3322,9 +3319,6 @@ void PrintItemOil(char iDidx) AddPanelString(tempstr); break; case IMISC_ELIXWEAK: - strcpy(tempstr, _("decrease strength")); - AddPanelString(tempstr); - break; case IMISC_ELIXDIS: strcpy(tempstr, _("decrease strength")); AddPanelString(tempstr); @@ -3368,11 +3362,9 @@ void PrintItemPower(char plidx, ItemStruct *x) strcpy(tempstr, fmt::format(_("{:+d}% armor"), x->_iPLAC).c_str()); break; case IPL_SETAC: - strcpy(tempstr, fmt::format(_("armor class: {:d}"), x->_iAC).c_str()); - break; case IPL_AC_CURSE: strcpy(tempstr, fmt::format(_("armor class: {:d}"), x->_iAC).c_str()); - break; + break; case IPL_FIRERES: case IPL_FIRERES_CURSE: if (x->_iPLFR < 75) @@ -4124,17 +4116,17 @@ int RndSmithItem(int lvl) return RndVendorItem(0, lvl); } -void SortVendor(ItemStruct *items) +void SortVendor(ItemStruct *itemList) { int count = 1; - while (!items[count].isEmpty()) + while (!itemList[count].isEmpty()) count++; auto cmp = [](const ItemStruct &a, const ItemStruct &b) { return a.IDidx < b.IDidx; }; - std::sort(items, items + count, cmp); + std::sort(itemList, itemList + count, cmp); } void SpawnSmith(int lvl) @@ -4197,17 +4189,17 @@ int RndPremiumItem(int minlvl, int maxlvl) return RndVendorItem(minlvl, maxlvl); } -static void SpawnOnePremium(int i, int plvl, int myplr) +static void SpawnOnePremium(int i, int plvl, int playerId) { - int ivalue = 0; - bool keepgoing = false; - ItemStruct holditem = items[0]; + int itemValue = 0; + bool keepGoing = false; + ItemStruct tempItem = items[0]; - auto &myPlayer = plr[myplr]; + auto &player = plr[playerId]; - int strength = std::max(myPlayer.GetMaximumAttributeValue(CharacterAttribute::Strength), myPlayer._pStrength); - int dexterity = std::max(myPlayer.GetMaximumAttributeValue(CharacterAttribute::Dexterity), myPlayer._pDexterity); - int magic = std::max(myPlayer.GetMaximumAttributeValue(CharacterAttribute::Magic), myPlayer._pMagic); + int strength = std::max(player.GetMaximumAttributeValue(CharacterAttribute::Strength), player._pStrength); + int dexterity = std::max(player.GetMaximumAttributeValue(CharacterAttribute::Dexterity), player._pDexterity); + int magic = std::max(player.GetMaximumAttributeValue(CharacterAttribute::Magic), player._pMagic); strength += strength / 5; dexterity += dexterity / 5; magic += magic / 5; @@ -4217,16 +4209,16 @@ static void SpawnOnePremium(int i, int plvl, int myplr) int count = 0; do { - keepgoing = false; + keepGoing = false; memset(&items[0], 0, sizeof(*items)); items[0]._iSeed = AdvanceRndSeed(); - int itype = RndPremiumItem(plvl / 4, plvl) - 1; - GetItemAttrs(0, itype, plvl); + int itemType = RndPremiumItem(plvl / 4, plvl) - 1; + GetItemAttrs(0, itemType, plvl); GetItemBonus(0, plvl / 2, plvl, true, !gbIsHellfire); if (!gbIsHellfire) { if (items[0]._iIvalue > 140000) { - keepgoing = true; // prevent breaking the do/while loop too early by failing hellfire's condition in while + keepGoing = true; // prevent breaking the do/while loop too early by failing hellfire's condition in while continue; } break; @@ -4236,14 +4228,14 @@ static void SpawnOnePremium(int i, int plvl, int myplr) case ITYPE_LARMOR: case ITYPE_MARMOR: case ITYPE_HARMOR: { - const auto *const mostValuablePlayerArmor = myPlayer.GetMostValuableItem( + const auto *const mostValuablePlayerArmor = player.GetMostValuableItem( [](const ItemStruct &item) { return item._itype == ITYPE_LARMOR || item._itype == ITYPE_MARMOR || item._itype == ITYPE_HARMOR; }); - ivalue = mostValuablePlayerArmor == nullptr ? 0 : mostValuablePlayerArmor->_iIvalue; + itemValue = mostValuablePlayerArmor == nullptr ? 0 : mostValuablePlayerArmor->_iIvalue; break; } case ITYPE_SHIELD: @@ -4255,37 +4247,37 @@ static void SpawnOnePremium(int i, int plvl, int myplr) case ITYPE_STAFF: case ITYPE_RING: case ITYPE_AMULET: { - const auto *const mostValuablePlayerItem = myPlayer.GetMostValuableItem( + const auto *const mostValuablePlayerItem = player.GetMostValuableItem( [](const ItemStruct &item) { return item._itype == items[0]._itype; }); - ivalue = mostValuablePlayerItem == nullptr ? 0 : mostValuablePlayerItem->_iIvalue; + itemValue = mostValuablePlayerItem == nullptr ? 0 : mostValuablePlayerItem->_iIvalue; break; } default: - ivalue = 0; + itemValue = 0; break; } - ivalue *= 0.8; + itemValue *= 0.8; count++; - } while (keepgoing - || (( + } while (keepGoing + || (( items[0]._iIvalue > 200000 || items[0]._iMinStr > strength || items[0]._iMinMag > magic || items[0]._iMinDex > dexterity - || items[0]._iIvalue < ivalue) + || items[0]._iIvalue < itemValue) && count < 150)); premiumitems[i] = items[0]; premiumitems[i]._iCreateInfo = plvl | CF_SMITHPREMIUM; premiumitems[i]._iIdentified = true; premiumitems[i]._iStatFlag = StoreStatOk(&premiumitems[i]); - items[0] = holditem; + items[0] = tempItem; } void SpawnPremium(int pnum) { - int lvl = plr[pnum]._pLevel; + int8_t lvl = plr[pnum]._pLevel; int maxItems = gbIsHellfire ? SMITH_PREMIUM_ITEMS : 6; if (numpremium < maxItems) { for (int i = 0; i < maxItems; i++) { @@ -4350,13 +4342,13 @@ void WitchBookLevel(int ii) if (witchitem[ii]._iMiscId != IMISC_BOOK) return; witchitem[ii]._iMinMag = spelldata[witchitem[ii]._iSpell].sMinInt; - int slvl = plr[myplr]._pSplLvl[witchitem[ii]._iSpell]; - while (slvl > 0) { + int8_t spellLevel = plr[myplr]._pSplLvl[witchitem[ii]._iSpell]; + while (spellLevel > 0) { witchitem[ii]._iMinMag += 20 * witchitem[ii]._iMinMag / 100; - slvl--; + spellLevel--; if (witchitem[ii]._iMinMag + 20 * witchitem[ii]._iMinMag / 100 > 255) { witchitem[ii]._iMinMag = 255; - slvl = 0; + spellLevel = 0; } } } diff --git a/Source/lighting.cpp b/Source/lighting.cpp index 2260a2b83..40b0aa473 100644 --- a/Source/lighting.cpp +++ b/Source/lighting.cpp @@ -548,7 +548,7 @@ void DoLighting(Point position, int nRadius, int lnum) if (radiusBlock < 128) { int tempX = position.x + x; int tempY = position.y + y; - int v = lightradius[nRadius][radiusBlock]; + int8_t v = lightradius[nRadius][radiusBlock]; if (tempX >= 0 && tempX < MAXDUNX && tempY >= 0 && tempY < MAXDUNY) if (v < GetLight(tempX, tempY)) SetLight(tempX, tempY, v); @@ -563,7 +563,7 @@ void DoLighting(Point position, int nRadius, int lnum) if (radiusBlock < 128) { int tempX = position.x + y; int tempY = position.y - x; - int v = lightradius[nRadius][radiusBlock]; + int8_t v = lightradius[nRadius][radiusBlock]; if (tempX >= 0 && tempX < MAXDUNX && tempY >= 0 && tempY < MAXDUNY) if (v < GetLight(tempX, tempY)) SetLight(tempX, tempY, v); @@ -578,7 +578,7 @@ void DoLighting(Point position, int nRadius, int lnum) if (radiusBlock < 128) { int tempX = position.x - x; int tempY = position.y - y; - int v = lightradius[nRadius][radiusBlock]; + int8_t v = lightradius[nRadius][radiusBlock]; if (tempX >= 0 && tempX < MAXDUNX && tempY >= 0 && tempY < MAXDUNY) if (v < GetLight(tempX, tempY)) SetLight(tempX, tempY, v); @@ -593,7 +593,7 @@ void DoLighting(Point position, int nRadius, int lnum) if (radiusBlock < 128) { int tempX = position.x - y; int tempY = position.y + x; - int v = lightradius[nRadius][radiusBlock]; + int8_t v = lightradius[nRadius][radiusBlock]; if (tempX >= 0 && tempX < MAXDUNX && tempY >= 0 && tempY < MAXDUNY) if (v < GetLight(tempX, tempY)) SetLight(tempX, tempY, v); @@ -731,7 +731,7 @@ void DoVision(Point position, int nRadius, bool doautomap, bool visible) } dFlags[nCrawlX][nCrawlY] |= BFLAG_VISIBLE; if (!nBlockerFlag) { - int nTrans = dTransVal[nCrawlX][nCrawlY]; + int8_t nTrans = dTransVal[nCrawlX][nCrawlY]; if (nTrans != 0) { TransList[nTrans] = true; } diff --git a/Source/lighting.h b/Source/lighting.h index c286d1d48..2d863e91a 100644 --- a/Source/lighting.h +++ b/Source/lighting.h @@ -50,8 +50,6 @@ extern bool lightflag; void DoLighting(Point position, int nRadius, int Lnum); void DoUnVision(Point position, int nRadius); void DoVision(Point position, int nRadius, bool doautomap, bool visible); -void FreeLightTable(); -void InitLightTable(); void MakeLightTable(); #ifdef _DEBUG void ToggleLighting(); diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 0d0dae6b3..37e4f5009 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -1055,7 +1055,7 @@ void RemoveEmptyInventory(PlayerStruct &player) if (idx > 0 && player.InvList[idx - 1].isEmpty()) { player.RemoveInvItem(idx - 1); } - }; + } } void RemoveEmptyLevelItems() @@ -1850,8 +1850,8 @@ const int HellfireItemSaveSize = 372; void SaveHeroItems(PlayerStruct &player) { - size_t items = NUM_INVLOC + NUM_INV_GRID_ELEM + MAXBELTITEMS; - SaveHelper file("heroitems", items * (gbIsHellfire ? HellfireItemSaveSize : DiabloItemSaveSize) + sizeof(uint8_t)); + size_t itemCount = NUM_INVLOC + NUM_INV_GRID_ELEM + MAXBELTITEMS; + SaveHelper file("heroitems", itemCount * (gbIsHellfire ? HellfireItemSaveSize : DiabloItemSaveSize) + sizeof(uint8_t)); file.WriteLE(gbIsHellfire ? 1 : 0); diff --git a/Source/minitext.cpp b/Source/minitext.cpp index 2ddb371c0..868a09ffc 100644 --- a/Source/minitext.cpp +++ b/Source/minitext.cpp @@ -62,20 +62,21 @@ void LoadText(const char *text) * @param nSFX The index of the sound in the sgSFX table * @return ms/px */ -int CalculateTextSpeed(int nSFX) +uint32_t CalculateTextSpeed(int nSFX) { const int numLines = TextLines.size(); #ifndef NOSOUND Uint32 sfxFrames = GetSFXLength(nSFX); - assert(sfxFrames != 0); #else // Sound is disabled -- estimate length from the number of lines. Uint32 sfxFrames = numLines * 3000; #endif + assert(sfxFrames != 0); - int textHeight = LineHeight * numLines; + uint32_t textHeight = LineHeight * numLines; textHeight += LineHeight * 5; // adjust so when speaker is done two line are left + assert(textHeight != 0); return sfxFrames / textHeight; } @@ -106,8 +107,8 @@ void DrawQTextContent(const Surface &out) const unsigned int skipLines = y / LineHeight; for (int i = 0; i < 8; i++) { - const int lineNumber = skipLines + i; - if (lineNumber < 0 || lineNumber >= (int)TextLines.size()) { + const unsigned int lineNumber = skipLines + i; + if (lineNumber >= TextLines.size()) { continue; } @@ -141,18 +142,18 @@ void InitQuestText() /** * @brief Start the given naration - * @param m Index of narration from the alltext table + * @param m Index of narration from the Texts table */ void InitQTextMsg(_speech_id m) { - if (alltext[m].scrlltxt) { + if (Texts[m].scrlltxt) { questlog = false; - LoadText(_(alltext[m].txtstr)); + LoadText(_(Texts[m].txtstr)); qtextflag = true; - qtextSpd = CalculateTextSpeed(alltext[m].sfxnr); + qtextSpd = CalculateTextSpeed(Texts[m].sfxnr); ScrollStart = SDL_GetTicks(); } - PlaySFX(alltext[m].sfxnr); + PlaySFX(Texts[m].sfxnr); } void DrawQTextBack(const Surface &out) diff --git a/Source/monster.cpp b/Source/monster.cpp index e35fafa57..374dd3cce 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -2350,7 +2350,7 @@ bool M_DoTalk(int i) MonsterStruct *monst = &monster[i]; M_StartStand(i, monster[i]._mdir); monst->_mgoal = MGOAL_TALKING; // CODEFIX: apply Monst instead of monster[i] in the rest of the function - if (effect_is_playing(alltext[monster[i].mtalkmsg].sfxnr)) + if (effect_is_playing(Texts[monster[i].mtalkmsg].sfxnr)) return false; InitQTextMsg(monster[i].mtalkmsg); if (monster[i]._uniqtype - 1 == UMT_GARBUD) { diff --git a/Source/textdat.cpp b/Source/textdat.cpp index 84dcbbfeb..0153b1600 100644 --- a/Source/textdat.cpp +++ b/Source/textdat.cpp @@ -11,7 +11,7 @@ namespace devilution { /* todo: move text out of struct */ /** Contains the data related to each speech ID. */ -const TextDataStruct alltext[] = { +const TextDataStruct Texts[] = { { N_(/* TRANSLATORS: Quest dialog spoken by Cain */ " Ahh, the story of our King, is it? The tragic fall of Leoric was a harsh blow to this land. The people always loved the King, and now they live in mortal fear of him. The question that I keep asking myself is how he could have fallen so far from the Light, as Leoric had always been the holiest of men. Only the vilest powers of Hell could so utterly destroy a man from within..."), true, TSFX_STORY1 }, { N_(/* TRANSLATORS: Quest dialog spoken by Ogden */ "The village needs your help, good master! Some months ago King Leoric's son, Prince Albrecht, was kidnapped. The King went into a rage and scoured the village for his missing child. With each passing day, Leoric seemed to slip deeper into madness. He sought to blame innocent townsfolk for the boy's disappearance and had them brutally executed. Less than half of us survived his insanity...\n \nThe King's Knights and Priests tried to placate him, but he turned against them and sadly, they were forced to kill him. With his dying breath the King called down a terrible curse upon his former followers. He vowed that they would serve him in darkness forever...\n \nThis is where things take an even darker twist than I thought possible! Our former King has risen from his eternal sleep and now commands a legion of undead minions within the Labyrinth. His body was buried in a tomb three levels beneath the Cathedral. Please, good master, put his soul at ease by destroying his now cursed form..."), diff --git a/Source/textdat.h b/Source/textdat.h index dd05cc9f4..a81ec29d9 100644 --- a/Source/textdat.h +++ b/Source/textdat.h @@ -428,6 +428,6 @@ struct TextDataStruct { _sfx_id sfxnr; }; -extern const TextDataStruct alltext[]; +extern const TextDataStruct Texts[]; } // namespace devilution diff --git a/Source/themes.cpp b/Source/themes.cpp index e8a5c3d8e..2660482ec 100644 --- a/Source/themes.cpp +++ b/Source/themes.cpp @@ -28,7 +28,6 @@ int themeVar1; ThemeStruct themes[MAXTHEMES]; bool pFountainFlag; bool bFountainFlag; -bool bCrossFlag; /** Specifies the set of special theme IDs from which one will be selected at random. */ theme_id ThemeGood[4] = { THEME_GOATSHRINE, THEME_SHRINE, THEME_SKELROOM, THEME_LIBRARY }; @@ -406,7 +405,6 @@ void InitThemes() pFountainFlag = true; tFountainFlag = true; treasureFlag = true; - bCrossFlag = false; weaponFlag = true; if (currlevel == 16) @@ -466,7 +464,7 @@ void HoldThemeRooms() } for (int i = 0; i < numthemes; i++) { - uint8_t v = themes[i].ttval; + int8_t v = themes[i].ttval; for (int y = 0; y < MAXDUNY; y++) { for (int x = 0; x < MAXDUNX; x++) { if (dTransVal[x][y] == v) { @@ -926,7 +924,6 @@ void Theme_BrnCross(int t) } } PlaceThemeMonsts(t, monstrnd[leveltype - 1]); - bCrossFlag = true; } /** diff --git a/Source/towners.cpp b/Source/towners.cpp index 7a9ef26dd..f674a3c0b 100644 --- a/Source/towners.cpp +++ b/Source/towners.cpp @@ -57,15 +57,6 @@ void InitTownerInfo(int i, const TownerInit &initData) initData.init(towner, initData); } -void InitQstSnds(TownerStruct &towner, _talker_id type) -{ - for (int i = 0; i < MAXQUESTS; i++) { - towner.qsts[i]._qsttype = quests[i]._qtype; - towner.qsts[i]._qstmsg = Qtalklist[type][i]; - towner.qsts[i]._qstmsgact = Qtalklist[type][i] != TEXT_NONE; - } -} - void LoadTownerAnimations(TownerStruct &towner, const char *path, int frames, Direction dir, int delay) { towner._tNData = LoadFileInMem(path); @@ -80,7 +71,6 @@ void LoadTownerAnimations(TownerStruct &towner, const char *path, int frames, Di */ void InitSmith(TownerStruct &towner, const TownerInit &initData) { - InitQstSnds(towner, initData.type); towner._tAnimWidth = 96; static const uint8_t AnimOrder[] = { // clang-format off @@ -101,7 +91,6 @@ void InitSmith(TownerStruct &towner, const TownerInit &initData) void InitBarOwner(TownerStruct &towner, const TownerInit &initData) { - InitQstSnds(towner, initData.type); towner._tAnimWidth = 96; static const uint8_t AnimOrder[] = { // clang-format off @@ -124,7 +113,6 @@ void InitBarOwner(TownerStruct &towner, const TownerInit &initData) void InitTownDead(TownerStruct &towner, const TownerInit &initData) { - InitQstSnds(towner, initData.type); towner._tAnimWidth = 96; towner.animOrder = nullptr; towner.animOrderSize = 0; @@ -134,7 +122,6 @@ void InitTownDead(TownerStruct &towner, const TownerInit &initData) void InitWitch(TownerStruct &towner, const TownerInit &initData) { - InitQstSnds(towner, initData.type); towner._tAnimWidth = 96; static const uint8_t AnimOrder[] = { // clang-format off @@ -157,7 +144,6 @@ void InitWitch(TownerStruct &towner, const TownerInit &initData) void InitBarmaid(TownerStruct &towner, const TownerInit &initData) { - InitQstSnds(towner, initData.type); towner._tAnimWidth = 96; towner.animOrder = nullptr; towner.animOrderSize = 0; @@ -167,7 +153,6 @@ void InitBarmaid(TownerStruct &towner, const TownerInit &initData) void InitBoy(TownerStruct &towner, const TownerInit &initData) { - InitQstSnds(towner, initData.type); towner._tAnimWidth = 96; towner.animOrder = nullptr; towner.animOrderSize = 0; @@ -177,7 +162,6 @@ void InitBoy(TownerStruct &towner, const TownerInit &initData) void InitHealer(TownerStruct &towner, const TownerInit &initData) { - InitQstSnds(towner, initData.type); towner._tAnimWidth = 96; static const uint8_t AnimOrder[] = { // clang-format off @@ -200,7 +184,6 @@ void InitHealer(TownerStruct &towner, const TownerInit &initData) void InitTeller(TownerStruct &towner, const TownerInit &initData) { - InitQstSnds(towner, initData.type); towner._tAnimWidth = 96; static const uint8_t AnimOrder[] = { // clang-format off @@ -218,7 +201,6 @@ void InitTeller(TownerStruct &towner, const TownerInit &initData) void InitDrunk(TownerStruct &towner, const TownerInit &initData) { - InitQstSnds(towner, initData.type); towner._tAnimWidth = 96; static const uint8_t AnimOrder[] = { // clang-format off @@ -258,7 +240,6 @@ void InitCows(TownerStruct &towner, const TownerInit &initData) void InitFarmer(TownerStruct &towner, const TownerInit &initData) { - InitQstSnds(towner, initData.type); towner._tAnimWidth = 96; towner.animOrder = nullptr; towner.animOrderSize = 0; @@ -268,7 +249,6 @@ void InitFarmer(TownerStruct &towner, const TownerInit &initData) void InitCowFarmer(TownerStruct &towner, const TownerInit &initData) { - InitQstSnds(towner, initData.type); const char *celPath = "Towners\\Farmer\\cfrmrn2.CEL"; if (quests[Q_JERSEY]._qactive == QUEST_DONE) { celPath = "Towners\\Farmer\\mfrmrn2.CEL"; @@ -282,7 +262,6 @@ void InitCowFarmer(TownerStruct &towner, const TownerInit &initData) void InitGirl(TownerStruct &towner, const TownerInit &initData) { - InitQstSnds(towner, initData.type); const char *celPath = "Towners\\Girl\\Girlw1.CEL"; if (quests[Q_GIRL]._qactive == QUEST_DONE) { celPath = "Towners\\Girl\\Girls1.CEL"; @@ -764,7 +743,7 @@ void TalkToGirl(PlayerStruct &player, TownerStruct &girl) InitQTextMsg(TEXT_GIRL3); return; default: - PlaySFX(alltext[TEXT_GIRL1].sfxnr); + PlaySFX(Texts[TEXT_GIRL1].sfxnr); return; } } diff --git a/Source/towners.h b/Source/towners.h index 6c24b2c0e..959260404 100644 --- a/Source/towners.h +++ b/Source/towners.h @@ -35,12 +35,6 @@ enum _talker_id : uint8_t { NUM_TOWNER_TYPES, }; -struct TNQ { - uint8_t _qsttype; - uint8_t _qstmsg; - bool _qstmsgact; -}; - struct TownerStruct { byte *_tNAnim[8]; std::unique_ptr _tNData; @@ -56,7 +50,6 @@ struct TownerStruct { uint8_t _tAnimFrame; // Current frame of animation. uint8_t _tAnimFrameCnt; string_view _tName; - TNQ qsts[MAXQUESTS]; /** Specifies the animation frame sequence. */ const uint8_t *animOrder; // unowned std::size_t animOrderSize;