Skip to content

Commit

Permalink
simplify the loops in AddTown and in MI_Guardian
Browse files Browse the repository at this point in the history
  • Loading branch information
pionere committed Sep 2, 2024
1 parent 912399e commit 4cebe83
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions Source/missiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2422,23 +2422,22 @@ int AddTown(int mi, int sx, int sy, int dx, int dy, int midir, int micaster, int
// ((unsigned)misource < MAX_PLRS);
// the position of portals in town and recreated portals are fixed
if (currLvl._dType != DTYPE_TOWN && spllvl >= 0) {
const int RANGE = 6;
static_assert(DBORDERX >= RANGE - 1 && DBORDERY >= RANGE - 1, "AddTown expects a large enough border.");
static_assert(lengthof(CrawlNum) >= RANGE, "AddShroud uses CrawlTable/CrawlNum up to radius 5.");
for (i = 0; i < RANGE; i++) {
static_assert(DBORDERX >= 5 && DBORDERY >= 5, "AddTown expects a large enough border.");
static_assert(lengthof(CrawlNum) > 5, "AddShroud uses CrawlTable/CrawlNum up to radius 5.");
for (i = 0; i <= 5; i++) {
cr = &CrawlTable[CrawlNum[i]];
for (j = (BYTE)*cr; j > 0; j--) {
tx = dx + *++cr;
ty = dy + *++cr;
assert(IN_DUNGEON_AREA(tx, ty));
if (PosOkMissile(tx, ty) && !CheckIfTrig(tx, ty) && LineClear(sx, sy, tx, ty)) {
i = RANGE;
break;
goto done;
}
}
}
if (i == RANGE)
return MIRES_FAIL_DELETE;
return MIRES_FAIL_DELETE;
done:
;
} else {
tx = dx;
ty = dy;
Expand Down Expand Up @@ -4406,19 +4405,19 @@ void MI_Guardian(int mi)
// check for an enemy
mis->_miRange--;
if (mis->_miRange >= 0) {
ex = false;
static_assert(DBORDERX >= 6 && DBORDERY >= 6, "MI_Guardian expects a large enough border.");
static_assert(lengthof(CrawlNum) > 6, "MI_Guardian uses CrawlTable/CrawlNum up to radius 6.");
for (i = 6; i >= 0 && !ex; i--) {
for (i = 6; i >= 0; i--) {
cr = &CrawlTable[CrawlNum[i]];
for (j = *cr; j > 0; j--) {
tx = mis->_mix + *++cr;
ty = mis->_miy + *++cr;
ex = Sentfire(mi, tx, ty);
if (ex)
break;
if (Sentfire(mi, tx, ty))
goto done;
}
}
done:
;
} else {
// start collapse
SetMissDir(mi, 0);
Expand Down

0 comments on commit 4cebe83

Please sign in to comment.