Browse Source

Source/drlg_l[23].cpp: Use std::min/max instead of ternaries

Follow-up to #169

Also fixes a typo in drlg_l3.cpp
pull/405/head^2
Gleb Mazovetskiy 6 years ago committed by Anders Jenbo
parent
commit
329c6b89bc
  1. 7
      Source/drlg_l2.cpp
  2. 7
      Source/drlg_l3.cpp

7
Source/drlg_l2.cpp

@ -1,4 +1,7 @@
#ifndef SPAWN
#include <algorithm>
#include "diablo.h"
DEVILUTION_BEGIN_NAMESPACE
@ -349,8 +352,8 @@ static void DRLG_L2PlaceRndSet(BYTE *miniset, int rndper)
}
kk = sw * sh + 2;
if (found == TRUE) {
for (yy = (sy - sh > 0 ? sy - sh : 0); yy < (sy + 2 * sh < DMAXY ? sy + 2 * sh : DMAXY) && found == TRUE; yy++) {
for (xx = (sx - sw > 0 ? sx - sw : 0); xx < (sx + 2 * sw < DMAXX ? sx + 2 * sw : DMAXX); xx++) {
for (yy = std::max(sy - sh, 0); yy < std::min(sy + 2 * sh, DMAXY) && found == TRUE; yy++) {
for (xx = std::max(sx - sw, 0); xx < std::min(sx + 2 * sw, DMAXX); xx++) {
// BUGFIX: yy and xx can go out of bounds (fixed)
if (dungeon[xx][yy] == miniset[kk]) {
found = FALSE;

7
Source/drlg_l3.cpp

@ -1,4 +1,7 @@
#ifndef SPAWN
#include <algorithm>
#include "diablo.h"
DEVILUTION_BEGIN_NAMESPACE
@ -792,8 +795,8 @@ static void DRLG_L3Pool()
found = TRUE;
}
poolchance = random_(0, 100);
for (j = (duny - totarea > 0 ? duny - totarea : 0); j < (duny + totarea < DMAXY ? duny + totarea : DMAXY); j++) {
for (i = (dunx - totarea > 0 ? dunx - totarea : 0); i < (dunx + totarea < DMAXY ? dunx + totarea : DMAXY); i++) {
for (j = std::max(duny - totarea, 0); j < std::min(duny + totarea, DMAXY); j++) {
for (i = std::max(dunx - totarea, 0); i < std::min(dunx + totarea, DMAXX); i++) {
// BUGFIX: In the following swap the order to first do the
// index checks and only then access dungeon[i][j] (fixed)
if (dungeon[i][j] & 0x80) {

Loading…
Cancel
Save