Split out random trap type picking

This commit is contained in:
Pasi Kallinen
2024-01-29 20:10:07 +02:00
parent 594eead50d
commit 95e42bf692
+85 -64
View File
@@ -25,6 +25,8 @@ static void fill_ordinary_room(struct mkroom *, boolean) NONNULLARG1;
static void makelevel(void); static void makelevel(void);
static boolean bydoor(coordxy, coordxy); static boolean bydoor(coordxy, coordxy);
static void mktrap_victim(struct trap *); static void mktrap_victim(struct trap *);
static int traptype_rnd(unsigned);
static int traptype_roguelvl(void);
static struct mkroom *find_branch_room(coord *) NONNULLARG1; static struct mkroom *find_branch_room(coord *) NONNULLARG1;
static struct mkroom *pos_to_room(coordxy, coordxy); static struct mkroom *pos_to_room(coordxy, coordxy);
static boolean cardinal_nextto_room(struct mkroom *, coordxy, coordxy); static boolean cardinal_nextto_room(struct mkroom *, coordxy, coordxy);
@@ -1730,73 +1732,13 @@ mktrap_victim(struct trap *ttmp)
otmp->age -= (TAINT_AGE + 1); /* died too long ago to safely eat */ otmp->age -= (TAINT_AGE + 1); /* died too long ago to safely eat */
} }
/* mktrap(): select trap type and location, then use maketrap() to create it; /* pick a random trap type, return NO_TRAP if "too hard" */
make it at location 'tm' when that isn't Null, otherwise in 'croom' static int
if mktrapflags doesn't have MKTRAP_MAZEFLAG set, else in maze corridor */ traptype_rnd(unsigned mktrapflags)
void
mktrap(
int num, /* if non-zero, specific type of trap to make */
unsigned mktrapflags, /* MKTRAP_{SEEN,MAZEFLAG,NOSPIDERONWEB,NOVICTIM} */
struct mkroom *croom, /* room to hold trap */
coord *tm) /* specific location for trap */
{ {
static int mktrap_err = 0; /* move to struct g? */
struct trap *t;
coord m;
int kind;
unsigned lvl = level_difficulty(); unsigned lvl = level_difficulty();
int kind = rnd(TRAPNUM - 1);
if (!tm && !croom && !(mktrapflags & MKTRAP_MAZEFLAG)) {
/* complain when the combination of arguments will never set 'm' */
if (!mktrap_err++) {
char errbuf[BUFSZ];
Snprintf(errbuf, sizeof errbuf,
"args (%d,%d,%s,%s) are invalid",
num, mktrapflags, "null room", "null location");
paniclog("mktrap", errbuf);
}
return;
}
m.x = m.y = 0;
/* no traps in pools */
if (tm && is_pool(tm->x, tm->y))
return;
if (num > NO_TRAP && num < TRAPNUM) {
kind = num;
} else if (Is_rogue_level(&u.uz)) {
switch (rn2(7)) {
default:
kind = BEAR_TRAP;
break; /* 0 */
case 1:
kind = ARROW_TRAP;
break;
case 2:
kind = DART_TRAP;
break;
case 3:
kind = TRAPDOOR;
break;
case 4:
kind = PIT;
break;
case 5:
kind = SLP_GAS_TRAP;
break;
case 6:
kind = RUST_TRAP;
break;
}
} else if (Inhell && !rn2(5)) {
/* bias the frequency of fire traps in Gehennom */
kind = FIRE_TRAP;
} else {
do {
kind = rnd(TRAPNUM - 1);
/* reject "too hard" traps */
switch (kind) { switch (kind) {
/* these are controlled by the feature or object they guard, /* these are controlled by the feature or object they guard,
not by the map so mustn't be created on it */ not by the map so mustn't be created on it */
@@ -1851,6 +1793,85 @@ mktrap(
kind = NO_TRAP; kind = NO_TRAP;
break; break;
} }
return kind;
}
/* random trap type for the Rogue level */
static int
traptype_roguelvl(void)
{
int kind;
switch (rn2(7)) {
default:
kind = BEAR_TRAP;
break; /* 0 */
case 1:
kind = ARROW_TRAP;
break;
case 2:
kind = DART_TRAP;
break;
case 3:
kind = TRAPDOOR;
break;
case 4:
kind = PIT;
break;
case 5:
kind = SLP_GAS_TRAP;
break;
case 6:
kind = RUST_TRAP;
break;
}
return kind;
}
/* mktrap(): select trap type and location, then use maketrap() to create it;
make it at location 'tm' when that isn't Null, otherwise in 'croom'
if mktrapflags doesn't have MKTRAP_MAZEFLAG set, else in maze corridor */
void
mktrap(
int num, /* if non-zero, specific type of trap to make */
unsigned mktrapflags, /* MKTRAP_{SEEN,MAZEFLAG,NOSPIDERONWEB,NOVICTIM} */
struct mkroom *croom, /* room to hold trap */
coord *tm) /* specific location for trap */
{
static int mktrap_err = 0; /* move to struct g? */
struct trap *t;
coord m;
int kind;
unsigned lvl = level_difficulty();
if (!tm && !croom && !(mktrapflags & MKTRAP_MAZEFLAG)) {
/* complain when the combination of arguments will never set 'm' */
if (!mktrap_err++) {
char errbuf[BUFSZ];
Snprintf(errbuf, sizeof errbuf,
"args (%d,%d,%s,%s) are invalid",
num, mktrapflags, "null room", "null location");
paniclog("mktrap", errbuf);
}
return;
}
m.x = m.y = 0;
/* no traps in pools */
if (tm && is_pool(tm->x, tm->y))
return;
if (num > NO_TRAP && num < TRAPNUM) {
kind = num;
} else if (Is_rogue_level(&u.uz)) {
kind = traptype_roguelvl();
} else if (Inhell && !rn2(5)) {
/* bias the frequency of fire traps in Gehennom */
kind = FIRE_TRAP;
} else {
do {
kind = traptype_rnd(mktrapflags);
} while (kind == NO_TRAP); } while (kind == NO_TRAP);
} }