The function handles setting lava lit, and removing ice melt timers.
/* ### mkmaze.c ### */
+extern boolean set_levltyp(xchar, xchar, schar);
+extern boolean set_levltyp_lit(xchar, xchar, schar, schar);
extern void create_maze(int, int, boolean);
extern void wallification(int, int, int, int);
extern void fix_wall_spines(int, int, int, int);
Bitfield(candig, 1); /* Exception to Can_dig_down; was a trapdoor */
};
+/* light states for terrain replacements, for set_levltyp_lit */
+#define SET_LIT_RANDOM -1
+#define SET_LIT_NOCHANGE -2
+
+#define CAN_OVERWRITE_TERRAIN(ttyp) \
+ (iflags.debug_overwrite_stairs || !((ttyp) == LADDER || (ttyp) == STAIRS))
+
/*
* Add wall angle viewing by defining "modes" for each wall type. Each
* mode describes which parts of a wall are finished (seen as as wall)
#define SEL_GRADIENT_RADIAL 0
#define SEL_GRADIENT_SQUARE 1
-/* light states for terrain replacements, specifically for SET_TYPLIT
- * (not used for init_level) */
-#define SET_LIT_RANDOM -1
-#define SET_LIT_NOCHANGE -2
-
#define SP_COORD_IS_RANDOM 0x01000000L
/* Humidity flags for get_location() and friends, used with
* SP_COORD_PACK_RANDOM() */
char *data;
};
-#define CAN_OVERWRITE_TERRAIN(ttyp) \
- (iflags.debug_overwrite_stairs || !((ttyp) == LADDER || (ttyp) == STAIRS))
-
-#define SET_TYPLIT(x, y, ttyp, llit) \
- do { \
- if ((x) >= 1 && (y) >= 0 && (x) < COLNO && (y) < ROWNO) { \
- if ((ttyp) < MAX_TYPE \
- && CAN_OVERWRITE_TERRAIN(levl[(x)][(y)].typ)) \
- levl[(x)][(y)].typ = (ttyp); \
- if ((ttyp) == LAVAPOOL) \
- levl[(x)][(y)].lit = 1; \
- else if ((schar)(llit) != SET_LIT_NOCHANGE) { \
- if ((schar)(llit) == SET_LIT_RANDOM) \
- levl[(x)][(y)].lit = rn2(2); \
- else \
- levl[(x)][(y)].lit = (llit); \
- } \
- } \
- } while (0)
-
#endif /* SP_LEV_H */
if ((levl[x][y].typ != ROOM && levl[x][y].typ != GRAVE) || t_at(x, y))
return;
/* Make the grave */
- levl[x][y].typ = GRAVE;
+ if (!set_levltyp(x, y, GRAVE))
+ return;
/* Engrave the headstone */
del_engr_at(x, y);
if (!str)
else {
/* inaccessible niches occasionally have iron bars */
if (!rn2(5) && IS_WALL(levl[xx][yy].typ)) {
- levl[xx][yy].typ = IRONBARS;
+ (void) set_levltyp(xx, yy, IRONBARS);
if (rn2(3))
(void) mkcorpstat(CORPSE, (struct monst *) 0,
mkclass(S_HUMAN, 0), xx,
: !br->end1_up;
stairway_add(x, y, goes_up, FALSE, dest);
+ (void) set_levltyp(x, y, STAIRS);
levl[x][y].ladder = goes_up ? LA_UP : LA_DOWN;
- levl[x][y].typ = STAIRS;
}
/*
* Set made_branch to TRUE even if we didn't make a stairwell (i.e.
dest.dlevel = u.uz.dlevel + (up ? -1 : 1);
stairway_add(x, y, up ? TRUE : FALSE, FALSE, &dest);
- if (levl[x][y].typ == ICE)
- spot_stop_timers(x, y, MELT_ICE_AWAY);
-
- levl[x][y].typ = STAIRS;
+ (void) set_levltyp(x,y, STAIRS);
levl[x][y].ladder = up ? LA_UP : LA_DOWN;
}
} while (occupied(m.x, m.y) || bydoor(m.x, m.y));
/* Put a fountain at m.x, m.y */
- levl[m.x][m.y].typ = FOUNTAIN;
+ if (!set_levltyp(m.x, m.y, FOUNTAIN))
+ return;
/* Is it a "blessed" fountain? (affects drinking from fountain) */
if (!rn2(7))
levl[m.x][m.y].blessedftn = 1;
return;
/* Put a sink at m.x, m.y */
- levl[m.x][m.y].typ = SINK;
+ if (!set_levltyp(m.x, m.y, SINK))
+ return;
g.level.flags.nsinks++;
}
return;
/* Put an altar at m.x, m.y */
- levl[m.x][m.y].typ = ALTAR;
+ if (!set_levltyp(m.x, m.y, ALTAR))
+ return;
/* -1 - A_CHAOTIC, 0 - A_NEUTRAL, 1 - A_LAWFUL */
al = rn2((int) A_LAWFUL + 2) - 1;
return (boolean) (!isok(x, y) || IS_STWALL(levl[x][y].typ));
}
+/* set map terrain type, handling lava lit, ice melt timers, etc */
+boolean
+set_levltyp(xchar x, xchar y, schar typ)
+{
+ if (isok(x, y)) {
+ if ((typ < MAX_TYPE) && CAN_OVERWRITE_TERRAIN(levl[x][y].typ)) {
+ boolean was_ice = (levl[x][y].typ == ICE);
+
+ levl[x][y].typ = typ;
+
+ if (typ == LAVAPOOL)
+ levl[x][y].lit = 1;
+
+ if (was_ice && typ != ICE)
+ spot_stop_timers(x, y, MELT_ICE_AWAY);
+ return TRUE;
+ }
+#ifdef EXTRA_SANITY_CHECKS
+ } else {
+ impossible("set_levltyp(%i,%i,%i) !isok", x, y, typ);
+#endif /*EXTRA_SANITY_CHECKS*/
+ }
+ return FALSE;
+}
+
+/* set map terrain type and light state */
+boolean
+set_levltyp_lit(xchar x, xchar y, schar typ, schar lit)
+{
+ boolean ret = set_levltyp(x, y, typ);
+
+ if (ret && isok(x, y)) {
+ /* LAVAPOOL handled in set_levltyp */
+ if ((typ != LAVAPOOL) && (lit != SET_LIT_NOCHANGE)) {
+#ifdef EXTRA_SANITY_CHECKS
+ if (lit < SET_LIT_NOCHANGE || lit > 1)
+ impossible("set_levltyp_lit(%i,%i,%i,%i)", x, y, typ, lit);
+#endif /*EXTRA_SANITY_CHECKS*/
+ if (lit == SET_LIT_RANDOM)
+ lit = rn2(2);
+ levl[x][y].lit = lit;
+ }
+ }
+ return ret;
+}
+
/*
* Return 1 (not TRUE - we're doing bit vectors here) if we want to extend
* a wall spine in the (dx,dy) direction. Return 0 otherwise.
for (x = 2; x <= g.x_maze_max; x++)
for (y = 0; y <= g.y_maze_max; y++) {
- SET_TYPLIT(x, y, filling, lit);
+ if (!set_levltyp_lit(x, y, filling, lit))
+ continue;
/* TODO: consolidate this w lspo_map ? */
levl[x][y].flags = 0;
levl[x][y].horizontal = 0;
for (y = 0; y <= g.y_maze_max; y += 2) {
int c = 0;
- SET_TYPLIT(x, y, fg, lit);
+ (void) set_levltyp_lit(x, y, fg, lit);
if (levl[x + 1][y].typ == bg)
++c;
if (levl[x][y + 1].typ == bg)
if (c == 3) {
switch (rn2(3)) {
case 0:
- SET_TYPLIT(x + 1,y, fg, lit);
+ (void) set_levltyp_lit(x + 1,y, fg, lit);
break;
case 1:
- SET_TYPLIT(x, y + 1, fg, lit);
+ (void) set_levltyp_lit(x, y + 1, fg, lit);
break;
case 2:
- SET_TYPLIT(x + 1, y + 1, fg, lit);
+ (void) set_levltyp_lit(x + 1, y + 1, fg, lit);
break;
default:
break;
impossible("create_door: Can't find a proper place!");
return;
}
- levl[x][y].typ = (dd->secret ? SDOOR : DOOR);
+ if (!set_levltyp(x, y, (dd->secret ? SDOOR : DOOR)))
+ return;
levl[x][y].doormask = dd->mask;
}
xchar x = -1, y = -1;
unsigned int amask;
boolean croom_is_temple = TRUE;
- int oldtyp;
if (croom) {
get_free_room_loc(&x, &y, croom, a->coord);
}
/* check for existing features */
- oldtyp = levl[x][y].typ;
- if (!CAN_OVERWRITE_TERRAIN(oldtyp))
+ if (!set_levltyp(x, y, ALTAR))
return;
amask = sp_amask_to_amask(a->sp_amask);
- levl[x][y].typ = ALTAR;
levl[x][y].altarmask = amask;
if (a->shrine < 0)
terrain terr;
terr = *(terrain *) arg;
- SET_TYPLIT(x, y, terr.ter, terr.tlit);
+ if (!set_levltyp_lit(x, y, terr.ter, terr.tlit))
+ return;
+ /* TODO: move this below into set_levltyp? */
/* handle doors and secret doors */
if (levl[x][y].typ == SDOOR || IS_DOOR(levl[x][y].typ)) {
if (levl[x][y].typ == SDOOR)
if (selection_getpoint(x, y,sel)) {
if (mf) {
if (mapfrag_match(mf, x, y) && (rn2(100)) < chance)
- SET_TYPLIT(x, y, totyp, tolit);
+ (void) set_levltyp_lit(x, y, totyp, tolit);
} else {
if (levl[x][y].typ == fromtyp && rn2(100) < chance)
- SET_TYPLIT(x, y, totyp, tolit);
+ (void) set_levltyp_lit(x, y, totyp, tolit);
}
}
boolean oldplace;
struct trap *ttmp;
struct rm *lev = &levl[x][y];
- boolean was_ice = (lev->typ == ICE);
if ((ttmp = t_at(x, y)) != 0) {
if (undestroyable_trap(ttmp->ttyp))
: 0L);
lev->doormask = 0; /* subsumes altarmask, icedpool... */
if (IS_ROOM(lev->typ)) /* && !IS_AIR(lev->typ) */
- lev->typ = ROOM;
+ (void) set_levltyp(x, y, ROOM);
/*
* some cases which can happen when digging
* down while phazing thru solid areas
*/
else if (lev->typ == STONE || lev->typ == SCORR)
- lev->typ = CORR;
+ (void) set_levltyp(x, y, CORR);
else if (IS_WALL(lev->typ) || lev->typ == SDOOR)
- lev->typ = g.level.flags.is_maze_lev ? ROOM
- : g.level.flags.is_cavernous_lev ? CORR
- : DOOR;
+ (void) set_levltyp(x, y, g.level.flags.is_maze_lev ? ROOM
+ : g.level.flags.is_cavernous_lev ? CORR
+ : DOOR);
unearth_objs(x, y);
- if (was_ice && lev->typ != ICE)
- spot_stop_timers(x, y, MELT_ICE_AWAY);
break;
}