Browse Source

Scope all for loops

This caused 7 of the loops to be rewriteen using range by clang-tidy
pull/2328/head
Anders Jenbo 5 years ago
parent
commit
903d4bd2e1
  1. 3
      Source/capture.cpp
  2. 6
      Source/codec.cpp
  3. 6
      Source/debug.cpp
  4. 14
      Source/effects.cpp
  5. 4
      Source/error.cpp
  6. 4
      Source/gendung.cpp
  7. 10
      Source/inv.cpp
  8. 76
      Source/items.cpp
  9. 4
      Source/loadsave.cpp
  10. 12
      Source/monster.cpp
  11. 21
      Source/msg.cpp
  12. 4
      Source/objects.cpp
  13. 7
      Source/palette.cpp
  14. 20
      Source/path.cpp
  15. 6
      Source/platform/vita/keyboard.cpp
  16. 16
      Source/player.cpp
  17. 12
      Source/plrmsg.cpp
  18. 73
      Source/portal.cpp
  19. 2
      Source/portal.h
  20. 8
      Source/quests.cpp
  21. 8
      Source/scrollrt.cpp
  22. 7
      Source/setmaps.cpp
  23. 5
      Source/sha.cpp
  24. 12
      Source/stores.cpp
  25. 12
      Source/themes.cpp
  26. 12
      Source/trigs.cpp
  27. 16
      Source/utils/sdl2_to_1_2_backports.cpp

3
Source/capture.cpp

@ -53,10 +53,9 @@ static bool CaptureHdr(int16_t width, int16_t height, std::ofstream *out)
static bool CapturePal(SDL_Color *palette, std::ofstream *out)
{
BYTE pcxPalette[1 + 256 * 3];
int i;
pcxPalette[0] = 12;
for (i = 0; i < 256; i++) {
for (int i = 0; i < 256; i++) {
pcxPalette[1 + 3 * i + 0] = palette[i].r;
pcxPalette[1 + 3 * i + 1] = palette[i].g;
pcxPalette[1 + 3 * i + 2] = palette[i].b;

6
Source/codec.cpp

@ -58,8 +58,6 @@ std::size_t codec_decode(byte *pbSrcDst, std::size_t size, const char *pszPasswo
{
char buf[128];
char dst[SHA1HashSize];
int i;
CodecSignature *sig;
CodecInitKey(pszPassword);
if (size <= sizeof(CodecSignature))
@ -67,7 +65,7 @@ std::size_t codec_decode(byte *pbSrcDst, std::size_t size, const char *pszPasswo
size -= sizeof(CodecSignature);
if (size % BlockSize != 0)
return 0;
for (i = size; i != 0; pbSrcDst += BlockSize, i -= BlockSize) {
for (int i = size; i != 0; pbSrcDst += BlockSize, i -= BlockSize) {
memcpy(buf, pbSrcDst, BlockSize);
SHA1Result(0, dst);
for (int j = 0; j < BlockSize; j++) {
@ -79,7 +77,7 @@ std::size_t codec_decode(byte *pbSrcDst, std::size_t size, const char *pszPasswo
}
memset(buf, 0, sizeof(buf));
sig = (CodecSignature *)pbSrcDst;
auto *sig = (CodecSignature *)pbSrcDst;
if (sig->error > 0) {
goto error;
}

6
Source/debug.cpp

@ -178,8 +178,6 @@ void PrintDebugQuest()
void PrintDebugMonster(int m)
{
bool bActive;
int i;
char dstr[128];
sprintf(dstr, "Monster %i = %s", m, _(Monsters[m].mName));
@ -191,9 +189,9 @@ void PrintDebugMonster(int m)
sprintf(dstr, "Mode = %i, Var1 = %i", Monsters[m]._mmode, Monsters[m]._mVar1);
NetSendCmdString(1 << MyPlayerId, dstr);
bActive = false;
bool bActive = false;
for (i = 0; i < ActiveMonsterCount; i++) {
for (int i = 0; i < ActiveMonsterCount; i++) {
if (ActiveMonsters[i] == m)
bActive = true;
}

14
Source/effects.cpp

@ -1300,30 +1300,28 @@ void effects_cleanup_sfx()
static void PrivSoundInit(BYTE bLoadMask)
{
DWORD i;
if (!gbSndInited) {
return;
}
for (i = 0; i < sizeof(sgSFX) / sizeof(TSFX); i++) {
if (sgSFX[i].pSnd != nullptr) {
for (auto &sfx : sgSFX) {
if (sfx.pSnd != nullptr) {
continue;
}
if ((sgSFX[i].bFlags & sfx_STREAM) != 0) {
if ((sfx.bFlags & sfx_STREAM) != 0) {
continue;
}
if ((sgSFX[i].bFlags & bLoadMask) == 0) {
if ((sfx.bFlags & bLoadMask) == 0) {
continue;
}
if (!gbIsHellfire && (sgSFX[i].bFlags & sfx_HELLFIRE) != 0) {
if (!gbIsHellfire && (sfx.bFlags & sfx_HELLFIRE) != 0) {
continue;
}
sgSFX[i].pSnd = sound_file_load(sgSFX[i].pszName);
sfx.pSnd = sound_file_load(sfx.pszName);
}
}

4
Source/error.cpp

@ -79,12 +79,10 @@ const char *const MsgStrings[] = {
void InitDiabloMsg(diablo_message e)
{
int i;
if (msgcnt >= sizeof(msgtable))
return;
for (i = 0; i < msgcnt; i++) {
for (int i = 0; i < msgcnt; i++) {
if (msgtable[i] == e)
return;
}

4
Source/gendung.cpp

@ -504,9 +504,7 @@ void DRLG_HoldThemeRooms()
bool SkipThemeRoom(int x, int y)
{
int i;
for (i = 0; i < themeCount; i++) {
for (int i = 0; i < themeCount; i++) {
if (x >= themeLoc[i].x - 2 && x <= themeLoc[i].x + themeLoc[i].width + 2
&& y >= themeLoc[i].y - 2 && y <= themeLoc[i].y + themeLoc[i].height + 2)
return false;

10
Source/inv.cpp

@ -1090,11 +1090,11 @@ void CheckInvPaste(int pnum, Point cursorPosition)
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++) {
if (player.InvGrid[i] == it)
player.InvGrid[i] = 0;
if (player.InvGrid[i] == -it)
player.InvGrid[i] = 0;
for (auto &itemId : player.InvGrid) {
if (itemId == it)
itemId = 0;
if (itemId == -it)
itemId = 0;
}
}
int ii = r - SLOTXY_INV_FIRST;

76
Source/items.cpp

@ -510,15 +510,13 @@ static void SpawnNote()
void InitItems()
{
int i;
memset(&Items[0], 0, sizeof(*Items));
GetItemAttrs(0, IDI_GOLD, 1);
golditem = Items[0];
golditem._iStatFlag = true;
ActiveItemCount = 0;
for (i = 0; i < MAXITEMS; i++) {
for (int i = 0; i < MAXITEMS; i++) {
Items[i]._itype = ITYPE_NONE;
Items[i].position = { 0, 0 };
Items[i]._iAnimFlag = false;
@ -527,7 +525,7 @@ void InitItems()
Items[i]._iPostDraw = false;
}
for (i = 0; i < MAXITEMS; i++) {
for (int i = 0; i < MAXITEMS; i++) {
AvailableItems[i] = i;
ActiveItems[i] = 0;
}
@ -560,7 +558,6 @@ void CalcPlrItemVals(int playerId, bool loadgfx)
int tac = 0; // accuracy
int g;
int i;
int bdam = 0; // bonus damage
int btohit = 0; // bonus chance to hit
@ -597,49 +594,48 @@ void CalcPlrItemVals(int playerId, bool loadgfx)
int lmin = 0; // minimum lightning damage
int lmax = 0; // maximum lightning damage
for (i = 0; i < NUM_INVLOC; i++) {
ItemStruct *itm = &player.InvBody[i];
if (!itm->isEmpty() && itm->_iStatFlag) {
for (auto &item : player.InvBody) {
if (!item.isEmpty() && item._iStatFlag) {
mind += itm->_iMinDam;
maxd += itm->_iMaxDam;
tac += itm->_iAC;
mind += item._iMinDam;
maxd += item._iMaxDam;
tac += item._iAC;
if (itm->_iSpell != SPL_NULL) {
spl |= GetSpellBitmask(itm->_iSpell);
if (item._iSpell != SPL_NULL) {
spl |= GetSpellBitmask(item._iSpell);
}
if (itm->_iMagical == ITEM_QUALITY_NORMAL || itm->_iIdentified) {
bdam += itm->_iPLDam;
btohit += itm->_iPLToHit;
if (itm->_iPLAC != 0) {
int tmpac = itm->_iAC;
tmpac *= itm->_iPLAC;
if (item._iMagical == ITEM_QUALITY_NORMAL || item._iIdentified) {
bdam += item._iPLDam;
btohit += item._iPLToHit;
if (item._iPLAC != 0) {
int tmpac = item._iAC;
tmpac *= item._iPLAC;
tmpac /= 100;
if (tmpac == 0)
tmpac = math::Sign(itm->_iPLAC);
tmpac = math::Sign(item._iPLAC);
bac += tmpac;
}
iflgs |= itm->_iFlags;
pDamAcFlags |= itm->_iDamAcFlags;
sadd += itm->_iPLStr;
madd += itm->_iPLMag;
dadd += itm->_iPLDex;
vadd += itm->_iPLVit;
fr += itm->_iPLFR;
lr += itm->_iPLLR;
mr += itm->_iPLMR;
dmod += itm->_iPLDamMod;
ghit += itm->_iPLGetHit;
lrad += itm->_iPLLight;
ihp += itm->_iPLHP;
imana += itm->_iPLMana;
spllvladd += itm->_iSplLvlAdd;
enac += itm->_iPLEnAc;
fmin += itm->_iFMinDam;
fmax += itm->_iFMaxDam;
lmin += itm->_iLMinDam;
lmax += itm->_iLMaxDam;
iflgs |= item._iFlags;
pDamAcFlags |= item._iDamAcFlags;
sadd += item._iPLStr;
madd += item._iPLMag;
dadd += item._iPLDex;
vadd += item._iPLVit;
fr += item._iPLFR;
lr += item._iPLLR;
mr += item._iPLMR;
dmod += item._iPLDamMod;
ghit += item._iPLGetHit;
lrad += item._iPLLight;
ihp += item._iPLHP;
imana += item._iPLMana;
spllvladd += item._iSplLvlAdd;
enac += item._iPLEnAc;
fmin += item._iFMinDam;
fmax += item._iFMaxDam;
lmin += item._iLMinDam;
lmax += item._iLMaxDam;
}
}
}

4
Source/loadsave.cpp

@ -807,7 +807,7 @@ static void LoadLighting(LoadHelper *file, LightStruct *pLight)
static void LoadPortal(LoadHelper *file, int i)
{
PortalStruct *pPortal = &portal[i];
PortalStruct *pPortal = &Portals[i];
pPortal->open = file->NextBool32();
pPortal->position.x = file->NextLE<int32_t>();
@ -1843,7 +1843,7 @@ static void SaveLighting(SaveHelper *file, LightStruct *pLight)
static void SavePortal(SaveHelper *file, int i)
{
PortalStruct *pPortal = &portal[i];
PortalStruct *pPortal = &Portals[i];
file->WriteLE<uint32_t>(pPortal->open ? 1 : 0);
file->WriteLE<int32_t>(pPortal->position.x);

12
Source/monster.cpp

@ -249,8 +249,6 @@ int AddMonsterType(_monster_id type, placeflag placeflag)
void GetLevelMTypes()
{
int i;
// this array is merged with skeltypes down below.
_monster_id typelist[MAXMONSTERS];
_monster_id skeltypes[NUM_MTYPES];
@ -307,7 +305,7 @@ void GetLevelMTypes()
AddMonsterType(MT_SKING, PLACE_UNIQUE);
nt = 0;
for (i = MT_WSKELAX; i <= MT_WSKELAX + numskeltypes; i++) {
for (int i = MT_WSKELAX; i <= MT_WSKELAX + numskeltypes; i++) {
if (IsSkel(i)) {
minl = 15 * MonsterData[i].mMinDLvl / 30 + 1;
maxl = 15 * MonsterData[i].mMaxDLvl / 30 + 1;
@ -323,7 +321,7 @@ void GetLevelMTypes()
}
nt = 0;
for (i = MT_NZOMBIE; i < NUM_MTYPES; i++) {
for (int i = MT_NZOMBIE; i < NUM_MTYPES; i++) {
minl = 15 * MonsterData[i].mMinDLvl / 30 + 1;
maxl = 15 * MonsterData[i].mMaxDLvl / 30 + 1;
@ -336,14 +334,14 @@ void GetLevelMTypes()
#ifdef _DEBUG
if (monstdebug) {
for (i = 0; i < debugmonsttypes; i++)
for (int i = 0; i < debugmonsttypes; i++)
AddMonsterType(DebugMonsters[i], PLACE_SCATTER);
} else
#endif
{
while (nt > 0 && LevelMonsterTypeCount < MAX_LVLMTYPES && monstimgtot < 4000) {
for (i = 0; i < nt;) {
for (int i = 0; i < nt;) {
if (MonsterData[typelist[i]].mImage > 4000 - monstimgtot) {
typelist[i] = typelist[--nt];
continue;
@ -353,7 +351,7 @@ void GetLevelMTypes()
}
if (nt != 0) {
i = GenerateRnd(nt);
int i = GenerateRnd(nt);
AddMonsterType(typelist[i], PLACE_SCATTER);
typelist[i] = typelist[--nt];
}

21
Source/msg.cpp

@ -412,13 +412,11 @@ void DeltaSyncObject(int oi, _cmd_id bCmd, BYTE bLevel)
bool DeltaGetItem(TCmdGItem *pI, BYTE bLevel)
{
int i;
if (!gbIsMultiplayer)
return true;
TCmdPItem *pD = sgLevels[bLevel].item;
for (i = 0; i < MAXITEMS; i++, pD++) {
for (int i = 0; i < MAXITEMS; i++, pD++) {
if (pD->bCmd == CMD_INVALID || pD->wIndx != pI->wIndx || pD->wCI != pI->wCI || pD->dwSeed != pI->dwSeed)
continue;
@ -443,7 +441,7 @@ bool DeltaGetItem(TCmdGItem *pI, BYTE bLevel)
return false;
pD = sgLevels[bLevel].item;
for (i = 0; i < MAXITEMS; i++, pD++) {
for (int i = 0; i < MAXITEMS; i++, pD++) {
if (pD->bCmd == CMD_INVALID) {
sgbDeltaChanged = true;
pD->bCmd = CMD_WALKXY;
@ -473,13 +471,11 @@ bool DeltaGetItem(TCmdGItem *pI, BYTE bLevel)
void DeltaPutItem(TCmdPItem *pI, int x, int y, BYTE bLevel)
{
int i;
if (!gbIsMultiplayer)
return;
TCmdPItem *pD = sgLevels[bLevel].item;
for (i = 0; i < MAXITEMS; i++, pD++) {
for (int i = 0; i < MAXITEMS; i++, pD++) {
if (pD->bCmd != CMD_WALKXY
&& pD->bCmd != 0xFF
&& pD->wIndx == pI->wIndx
@ -492,7 +488,7 @@ void DeltaPutItem(TCmdPItem *pI, int x, int y, BYTE bLevel)
}
pD = sgLevels[bLevel].item;
for (i = 0; i < MAXITEMS; i++, pD++) {
for (int i = 0; i < MAXITEMS; i++, pD++) {
if (pD->bCmd == 0xFF) {
sgbDeltaChanged = true;
memcpy(pD, pI, sizeof(TCmdPItem));
@ -1300,10 +1296,9 @@ DWORD OnAwakeGolem(TCmd *pCmd, int pnum)
else if (currlevel != Players[pnum].plrlevel)
DeltaSyncGolem(p, pnum, p->_currlevel);
else if (pnum != MyPlayerId) {
int i;
// check if this player already has an active golem
bool addGolem = true;
for (i = 0; i < ActiveMissileCount; i++) {
for (int i = 0; i < ActiveMissileCount; i++) {
int mi = ActiveMissiles[i];
if (Missiles[mi]._mitype == MIS_GOLEM && Missiles[mi]._misource == pnum) {
addGolem = false;
@ -1947,13 +1942,11 @@ bool delta_quest_inited(int i)
void DeltaAddItem(int ii)
{
int i;
if (!gbIsMultiplayer)
return;
TCmdPItem *pD = sgLevels[currlevel].item;
for (i = 0; i < MAXITEMS; i++, pD++) {
for (int i = 0; i < MAXITEMS; i++, pD++) {
if (pD->bCmd != 0xFF
&& pD->wIndx == Items[ii].IDidx
&& pD->wCI == Items[ii]._iCreateInfo
@ -1964,7 +1957,7 @@ void DeltaAddItem(int ii)
}
pD = sgLevels[currlevel].item;
for (i = 0; i < MAXITEMS; i++, pD++) {
for (int i = 0; i < MAXITEMS; i++, pD++) {
if (pD->bCmd == 0xFF) {
sgbDeltaChanged = true;
pD->bCmd = CMD_STAND;

4
Source/objects.cpp

@ -325,9 +325,7 @@ void InitObjectGFX()
void FreeObjectGFX()
{
int i;
for (i = 0; i < numobjfiles; i++) {
for (int i = 0; i < numobjfiles; i++) {
pObjCels[i] = nullptr;
}
numobjfiles = 0;

7
Source/palette.cpp

@ -35,12 +35,9 @@ void palette_update()
void ApplyGamma(SDL_Color *dst, const SDL_Color *src, int n)
{
int i;
double g;
double g = sgOptions.Graphics.nGammaCorrection / 100.0;
g = sgOptions.Graphics.nGammaCorrection / 100.0;
for (i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
dst[i].r = static_cast<Uint8>(pow(src[i].r / 256.0, g) * 256.0);
dst[i].g = static_cast<Uint8>(pow(src[i].g / 256.0, g) * 256.0);
dst[i].b = static_cast<Uint8>(pow(src[i].b / 256.0, g) * 256.0);

20
Source/path.cpp

@ -208,16 +208,13 @@ bool path_get_path(bool (*posOk)(int, Point), int posOkArg, PATHNODE *pPath, int
*/
bool path_parent_path(PATHNODE *pPath, int dx, int dy, int sx, int sy)
{
int nextG;
PATHNODE *dxdy;
int i;
nextG = pPath->g + path_check_equal(pPath, dx, dy);
int nextG = pPath->g + path_check_equal(pPath, dx, dy);
// 3 cases to consider
// case 1: (dx,dy) is already on the frontier
dxdy = path_get_node1(dx, dy);
PATHNODE *dxdy = path_get_node1(dx, dy);
if (dxdy != nullptr) {
int i;
for (i = 0; i < 8; i++) {
if (pPath->Child[i] == nullptr)
break;
@ -235,6 +232,7 @@ bool path_parent_path(PATHNODE *pPath, int dx, int dy, int sx, int sy)
// case 2: (dx,dy) was already visited
dxdy = path_get_node2(dx, dy);
if (dxdy != nullptr) {
int i;
for (i = 0; i < 8; i++) {
if (pPath->Child[i] == nullptr)
break;
@ -261,6 +259,7 @@ bool path_parent_path(PATHNODE *pPath, int dx, int dy, int sx, int sy)
// add it to the frontier
path_next_node(dxdy);
int i;
for (i = 0; i < 8; i++) {
if (pPath->Child[i] == nullptr)
break;
@ -325,16 +324,11 @@ void path_next_node(PATHNODE *pPath)
*/
void path_set_coords(PATHNODE *pPath)
{
PATHNODE *pathOld;
PATHNODE *pathAct;
int i;
path_push_active_step(pPath);
// while there are path nodes to check
while (gdwCurPathStep > 0) {
pathOld = path_pop_active_step();
for (i = 0; i < 8; i++) {
pathAct = pathOld->Child[i];
PATHNODE *pathOld = path_pop_active_step();
for (auto *pathAct : pathOld->Child) {
if (pathAct == nullptr)
break;

6
Source/platform/vita/keyboard.cpp

@ -7,8 +7,7 @@
static void utf16_to_utf8(const uint16_t *src, uint8_t *dst)
{
int i;
for (i = 0; src[i]; i++) {
for (int i = 0; src[i]; i++) {
if ((src[i] & 0xFF80) == 0) {
*(dst++) = src[i] & 0xFF;
} else if ((src[i] & 0xF800) == 0) {
@ -32,8 +31,7 @@ static void utf16_to_utf8(const uint16_t *src, uint8_t *dst)
static void utf8_to_utf16(const uint8_t *src, uint16_t *dst)
{
int i;
for (i = 0; src[i];) {
for (int i = 0; src[i];) {
if ((src[i] & 0xE0) == 0xE0) {
*(dst++) = ((src[i] & 0x0F) << 12) | ((src[i + 1] & 0x3F) << 6) | (src[i + 2] & 0x3F);
i += 3;

16
Source/player.cpp

@ -1175,8 +1175,6 @@ void AddPlrMonstExper(int lvl, int exp, char pmask)
void InitPlayer(int pnum, bool firstTime)
{
DWORD i;
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("InitPlayer: illegal player %i", pnum);
}
@ -1226,6 +1224,7 @@ void InitPlayer(int pnum, bool firstTime)
player.position.tile = { ViewX, ViewY };
}
} else {
DWORD i;
for (i = 0; i < 8 && !PosOkPlayer(pnum, player.position.tile + Displacement { plrxoff2[i], plryoff2[i] }); i++)
;
player.position.tile.x += plrxoff2[i];
@ -1695,10 +1694,6 @@ __attribute__((no_sanitize("shift-base")))
void
StartPlayerKill(int pnum, int earflag)
{
bool diablolevel;
int i;
ItemStruct ear;
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("StartPlayerKill: illegal player %i", pnum);
}
@ -1712,7 +1707,7 @@ StartPlayerKill(int pnum, int earflag)
NetSendCmdParam1(true, CMD_PLRDEAD, earflag);
}
diablolevel = gbIsMultiplayer && player.plrlevel == 16;
bool diablolevel = gbIsMultiplayer && player.plrlevel == 16;
player.Say(HeroSpeech::OofAh);
@ -1731,8 +1726,8 @@ StartPlayerKill(int pnum, int earflag)
player.deathFrame = 1;
if (pnum != MyPlayerId && earflag == 0 && !diablolevel) {
for (i = 0; i < NUM_INVLOC; i++) {
player.InvBody[i]._itype = ITYPE_NONE;
for (auto &item : player.InvBody) {
item._itype = ITYPE_NONE;
}
CalcPlrInv(pnum, false);
}
@ -1756,6 +1751,7 @@ StartPlayerKill(int pnum, int earflag)
DropHalfPlayersGold(pnum);
if (earflag != -1) {
if (earflag != 0) {
ItemStruct ear;
SetPlrHandItem(&ear, IDI_EAR);
strcpy(ear._iName, fmt::format(_("Ear of {:s}"), player._pName).c_str());
switch (player._pClass) {
@ -2071,7 +2067,7 @@ void StartWarpLvl(int pnum, int pidx)
if (player.plrlevel != 0) {
player.plrlevel = 0;
} else {
player.plrlevel = portal[pidx].level;
player.plrlevel = Portals[pidx].level;
}
}

12
Source/plrmsg.cpp

@ -24,8 +24,6 @@ const UiFlags TextColorFromPlayerId[MAX_PLRS + 1] = { UIS_SILVER, UIS_SILVER, UI
void plrmsg_delay(bool delay)
{
int i;
_plrmsg *pMsg;
static DWORD plrmsgTicks;
if (delay) {
@ -34,8 +32,8 @@ void plrmsg_delay(bool delay)
}
plrmsgTicks += SDL_GetTicks();
pMsg = plr_msgs;
for (i = 0; i < PMSG_COUNT; i++, pMsg++)
_plrmsg *pMsg = plr_msgs;
for (int i = 0; i < PMSG_COUNT; i++, pMsg++)
pMsg->time += plrmsgTicks;
}
@ -77,11 +75,10 @@ void SendPlrMsg(int pnum, const char *pszStr)
void ClearPlrMsg()
{
int i;
_plrmsg *pMsg = plr_msgs;
DWORD tick = SDL_GetTicks();
for (i = 0; i < PMSG_COUNT; i++, pMsg++) {
for (int i = 0; i < PMSG_COUNT; i++, pMsg++) {
if ((int)(tick - pMsg->time) > 10000)
pMsg->str[0] = '\0';
}
@ -106,7 +103,6 @@ static void PrintPlrMsg(const Surface &out, int x, int y, int width, char *text,
void DrawPlrMsg(const Surface &out)
{
int i;
DWORD x = 10;
DWORD y = 70;
DWORD width = gnScreenWidth - 20;
@ -123,7 +119,7 @@ void DrawPlrMsg(const Surface &out)
return;
pMsg = plr_msgs;
for (i = 0; i < PMSG_COUNT; i++) {
for (int i = 0; i < PMSG_COUNT; i++) {
if (pMsg->str[0] != '\0')
PrintPlrMsg(out, x, y, width, pMsg->str, TextColorFromPlayerId[pMsg->player]);
pMsg++;

73
Source/portal.cpp

@ -14,7 +14,7 @@
namespace devilution {
/** In-game state of portals. */
PortalStruct portal[MAXPORTAL];
PortalStruct Portals[MAXPORTAL];
/** Current portal number (a portal array index). */
int portalindex;
@ -25,21 +25,19 @@ int WarpDropY[MAXPORTAL] = { 40, 40, 40, 40 };
void InitPortals()
{
int i;
for (i = 0; i < MAXPORTAL; i++) {
for (int i = 0; i < MAXPORTAL; i++) {
if (delta_portal_inited(i))
portal[i].open = false;
Portals[i].open = false;
}
}
void SetPortalStats(int i, bool o, int x, int y, int lvl, dungeon_type lvltype)
{
portal[i].open = o;
portal[i].position = { x, y };
portal[i].level = lvl;
portal[i].ltype = lvltype;
portal[i].setlvl = false;
Portals[i].open = o;
Portals[i].position = { x, y };
Portals[i].level = lvl;
Portals[i].ltype = lvltype;
Portals[i].setlvl = false;
}
void AddWarpMissile(int i, int x, int y)
@ -62,10 +60,8 @@ void AddWarpMissile(int i, int x, int y)
void SyncPortals()
{
int i;
for (i = 0; i < MAXPORTAL; i++) {
if (!portal[i].open)
for (int i = 0; i < MAXPORTAL; i++) {
if (!Portals[i].open)
continue;
if (currlevel == 0)
AddWarpMissile(i, WarpDropX[i], WarpDropY[i]);
@ -73,8 +69,8 @@ void SyncPortals()
int lvl = currlevel;
if (setlevel)
lvl = setlvlnum;
if (portal[i].level == lvl && portal[i].setlvl == setlevel)
AddWarpMissile(i, portal[i].position.x, portal[i].position.y);
if (Portals[i].level == lvl && Portals[i].setlvl == setlevel)
AddWarpMissile(i, Portals[i].position.x, Portals[i].position.y);
}
}
}
@ -86,24 +82,24 @@ void AddInTownPortal(int i)
void ActivatePortal(int i, int x, int y, int lvl, dungeon_type lvltype, bool sp)
{
portal[i].open = true;
Portals[i].open = true;
if (lvl != 0) {
portal[i].position = { x, y };
portal[i].level = lvl;
portal[i].ltype = lvltype;
portal[i].setlvl = sp;
Portals[i].position = { x, y };
Portals[i].level = lvl;
Portals[i].ltype = lvltype;
Portals[i].setlvl = sp;
}
}
void DeactivatePortal(int i)
{
portal[i].open = false;
Portals[i].open = false;
}
bool PortalOnLevel(int i)
{
if (portal[i].level == currlevel)
if (Portals[i].level == currlevel)
return true;
return currlevel == 0;
@ -111,16 +107,13 @@ bool PortalOnLevel(int i)
void RemovePortalMissile(int id)
{
int i;
int mi;
for (i = 0; i < ActiveMissileCount; i++) {
mi = ActiveMissiles[i];
for (int i = 0; i < ActiveMissileCount; i++) {
int mi = ActiveMissiles[i];
if (Missiles[mi]._mitype == MIS_TOWN && Missiles[mi]._misource == id) {
dFlags[Missiles[mi].position.tile.x][Missiles[mi].position.tile.y] &= ~BFLAG_MISSILE;
dMissile[Missiles[mi].position.tile.x][Missiles[mi].position.tile.y] = 0;
if (portal[id].level != 0)
if (Portals[id].level != 0)
AddUnLight(Missiles[mi]._mlid);
DeleteMissile(mi, i);
@ -143,17 +136,17 @@ void GetPortalLevel()
return;
}
if (portal[portalindex].setlvl) {
if (Portals[portalindex].setlvl) {
setlevel = true;
setlvlnum = (_setlevels)portal[portalindex].level;
currlevel = portal[portalindex].level;
setlvlnum = (_setlevels)Portals[portalindex].level;
currlevel = Portals[portalindex].level;
Players[MyPlayerId].plrlevel = setlvlnum;
leveltype = portal[portalindex].ltype;
leveltype = Portals[portalindex].ltype;
} else {
setlevel = false;
currlevel = portal[portalindex].level;
currlevel = Portals[portalindex].level;
Players[MyPlayerId].plrlevel = currlevel;
leveltype = portal[portalindex].ltype;
leveltype = Portals[portalindex].ltype;
}
if (portalindex == MyPlayerId) {
@ -168,8 +161,8 @@ void GetPortalLvlPos()
ViewX = WarpDropX[portalindex] + 1;
ViewY = WarpDropY[portalindex] + 1;
} else {
ViewX = portal[portalindex].position.x;
ViewY = portal[portalindex].position.y;
ViewX = Portals[portalindex].position.x;
ViewY = Portals[portalindex].position.y;
if (portalindex != MyPlayerId) {
ViewX++;
@ -180,10 +173,8 @@ void GetPortalLvlPos()
bool PosOkPortal(int lvl, int x, int y)
{
int i;
for (i = 0; i < MAXPORTAL; i++) {
if (portal[i].open && portal[i].level == lvl && ((portal[i].position.x == x && portal[i].position.y == y) || (portal[i].position.x == x - 1 && portal[i].position.y == y - 1)))
for (auto &portal : Portals) {
if (portal.open && portal.level == lvl && ((portal.position.x == x && portal.position.y == y) || (portal.position.x == x - 1 && portal.position.y == y - 1)))
return true;
}
return false;

2
Source/portal.h

@ -20,7 +20,7 @@ struct PortalStruct {
bool setlvl;
};
extern PortalStruct portal[MAXPORTAL];
extern PortalStruct Portals[MAXPORTAL];
void InitPortals();
void SetPortalStats(int i, bool o, int x, int y, int lvl, dungeon_type lvltype);

8
Source/quests.cpp

@ -488,9 +488,7 @@ void DrawBlood(int x, int y)
void DRLG_CheckQuests(int x, int y)
{
int i;
for (i = 0; i < MAXQUESTS; i++) {
for (int i = 0; i < MAXQUESTS; i++) {
if (QuestStatus(i)) {
switch (Quests[i]._qtype) {
case Q_BUTCHER:
@ -729,10 +727,8 @@ void DrawQuestLog(const Surface &out)
void StartQuestlog()
{
DWORD i;
numqlines = 0;
for (i = 0; i < MAXQUESTS; i++) {
for (int i = 0; i < MAXQUESTS; i++) {
if (Quests[i]._qactive == QUEST_ACTIVE && Quests[i]._qlog) {
qlist[numqlines] = i;
numqlines++;

8
Source/scrollrt.cpp

@ -75,9 +75,7 @@ bool CouldMissileCollide(Point tile, bool checkPlayerAndMonster)
if (!Objects[oid]._oMissFlag)
return true;
}
if (nMissileTable[dPiece[tile.x][tile.y]])
return true;
return false;
return nMissileTable[dPiece[tile.x][tile.y]];
}
void UpdateMissileRendererData(MissileStruct &m)
@ -127,9 +125,9 @@ void UpdateMissileRendererData(MissileStruct &m)
// We search the last offset that is in the old (valid) tile.
// Implementation note: If someone knows the correct math to calculate this without the loop, I would really appreciate it.
while (m.position.tile != m.position.tileForRendering) {
fProgress -= 0.01f;
fProgress -= 0.01F;
if (fProgress <= 0.0f) {
if (fProgress <= 0.0F) {
m.position.tileForRendering = m.position.tile;
m.position.offsetForRendering = m.position.offset;
return;

7
Source/setmaps.cpp

@ -84,11 +84,8 @@ const char *const QuestLevelNames[] = {
int ObjIndex(int x, int y)
{
int i;
int oi;
for (i = 0; i < ActiveObjectCount; i++) {
oi = ActiveObjects[i];
for (int i = 0; i < ActiveObjectCount; i++) {
int oi = ActiveObjects[i];
if (Objects[oi].position.x == x && Objects[oi].position.y == y)
return oi;
}

5
Source/sha.cpp

@ -133,12 +133,11 @@ void SHA1Clear()
void SHA1Result(int n, char messageDigest[SHA1HashSize])
{
std::uint32_t *messageDigestBlock;
int i;
messageDigestBlock = (std::uint32_t *)messageDigest;
if (messageDigest != nullptr) {
for (i = 0; i < 5; i++) {
*messageDigestBlock = SDL_SwapLE32(sgSHA1[n].state[i]);
for (auto &block : sgSHA1[n].state) {
*messageDigestBlock = SDL_SwapLE32(block);
messageDigestBlock++;
}
}

12
Source/stores.cpp

@ -375,12 +375,10 @@ bool SmithSellOk(int i)
void ScrollSmithSell(int idx)
{
int l;
ClearSText(5, 21);
stextup = 5;
for (l = 5; l < 20; l += 4) {
for (int l = 5; l < 20; l += 4) {
if (idx >= storenumh)
break;
if (!storehold[idx].isEmpty()) {
@ -629,8 +627,6 @@ void ScrollWitchBuy(int idx)
void StartWitchBuy()
{
int i;
stextsize = true;
stextscrl = true;
stextsval = 0;
@ -647,7 +643,7 @@ void StartWitchBuy()
OffsetSTextY(22, 6);
storenumh = 0;
for (i = 0; !witchitem[i].isEmpty(); i++) {
for (int i = 0; !witchitem[i].isEmpty(); i++) {
storenumh++;
}
stextsmax = storenumh - 4;
@ -992,11 +988,9 @@ void StartHealer()
void ScrollHealerBuy(int idx)
{
int l;
ClearSText(5, 21);
stextup = 5;
for (l = 5; l < 20; l += 4) {
for (int l = 5; l < 20; l += 4) {
if (!healitem[idx].isEmpty()) {
uint16_t iclr = healitem[idx].getTextColorWithStatCheck();

12
Source/themes.cpp

@ -151,13 +151,11 @@ bool TFit_Obj5(int t)
bool TFit_SkelRoom(int t)
{
int i;
if (leveltype != DTYPE_CATHEDRAL && leveltype != DTYPE_CATACOMBS) {
return false;
}
for (i = 0; i < LevelMonsterTypeCount; i++) {
for (int i = 0; i < LevelMonsterTypeCount; i++) {
if (IsSkel(LevelMonsterTypes[i].mtype)) {
themeVar1 = i;
return TFit_Obj5(t);
@ -169,9 +167,7 @@ bool TFit_SkelRoom(int t)
bool TFit_GoatShrine(int t)
{
int i;
for (i = 0; i < LevelMonsterTypeCount; i++) {
for (int i = 0; i < LevelMonsterTypeCount; i++) {
if (IsGoat(LevelMonsterTypes[i].mtype)) {
themeVar1 = i;
return TFit_Obj5(t);
@ -183,9 +179,7 @@ bool TFit_GoatShrine(int t)
bool CheckThemeObj3(int xp, int yp, int t, int f)
{
int i;
for (i = 0; i < 9; i++) {
for (int i = 0; i < 9; i++) {
if (xp + trm3x[i] < 0 || yp + trm3y[i] < 0)
return false;
if (nSolidTable[dPiece[xp + trm3x[i]][yp + trm3y[i]]])

12
Source/trigs.cpp

@ -695,9 +695,7 @@ void Freeupstairs()
bool ForceSKingTrig()
{
int i;
for (i = 0; L1UpList[i] != -1; i++) {
for (int i = 0; L1UpList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L1UpList[i]) {
strcpy(infostr, fmt::format(_("Back to Level {:d}"), Quests[Q_SKELKING]._qlevel).c_str());
cursmx = trigs[0].position.x;
@ -712,9 +710,7 @@ bool ForceSKingTrig()
bool ForceSChambTrig()
{
int i;
for (i = 0; L2DownList[i] != -1; i++) {
for (int i = 0; L2DownList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L2DownList[i]) {
strcpy(infostr, fmt::format(_("Back to Level {:d}"), Quests[Q_SCHAMB]._qlevel).c_str());
cursmx = trigs[0].position.x;
@ -729,9 +725,7 @@ bool ForceSChambTrig()
bool ForcePWaterTrig()
{
int i;
for (i = 0; L3DownList[i] != -1; i++) {
for (int i = 0; L3DownList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L3DownList[i]) {
strcpy(infostr, fmt::format(_("Back to Level {:d}"), Quests[Q_PWATER]._qlevel).c_str());
cursmx = trigs[0].position.x;

16
Source/utils/sdl2_to_1_2_backports.cpp

@ -166,13 +166,11 @@ namespace {
#define DEFINE_COPY_ROW(name, type) \
void name(type *src, int src_w, type *dst, int dst_w) \
{ \
int i; \
int pos, inc; \
type pixel = 0; \
\
pos = 0x10000; \
inc = (src_w << 16) / dst_w; \
for (i = dst_w; i > 0; --i) { \
int pos = 0x10000; \
int inc = (src_w << 16) / dst_w; \
for (int i = dst_w; i > 0; i--) { \
while (pos >= 0x10000L) { \
pixel = *src++; \
pos -= 0x10000L; \
@ -187,13 +185,11 @@ DEFINE_COPY_ROW(copy_row4, Uint32)
void copy_row3(Uint8 *src, int src_w, Uint8 *dst, int dst_w)
{
int i;
int pos, inc;
Uint8 pixel[3] = { 0, 0, 0 };
pos = 0x10000;
inc = (src_w << 16) / dst_w;
for (i = dst_w; i > 0; --i) {
int pos = 0x10000;
int inc = (src_w << 16) / dst_w;
for (int i = dst_w; i > 0; --i) {
while (pos >= 0x10000L) {
pixel[0] = *src++;
pixel[1] = *src++;

Loading…
Cancel
Save