From: SHIRAKATA Kentaro Date: Sun, 8 May 2022 11:32:27 +0000 (+0900) Subject: split displaying trap map into separate function X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a377a1fc67e54a269ce961f22cd1620816f42972;p=nethack split displaying trap map into separate function --- diff --git a/src/detect.c b/src/detect.c index 39a92b79e..cbd5f1dec 100644 --- a/src/detect.c +++ b/src/detect.c @@ -21,6 +21,7 @@ static boolean check_map_spot(int, int, char, unsigned); static boolean clear_stale_map(char, unsigned); static void sense_trap(struct trap *, xchar, xchar, int); static int detect_obj_traps(struct obj *, boolean, int); +static void display_trap_map(struct trap *, int); static int furniture_detect(void); static void show_map_spot(int, int); static void findone(int, int, genericptr_t); @@ -908,6 +909,54 @@ detect_obj_traps( return result; } +static void +display_trap_map(struct trap *ttmp, int cursed_src) +{ + struct monst *mon; + int door, glyph, ter_typ = TER_DETECT | TER_TRP; + coord cc; + + cls(); + + (void) unconstrain_map(); + /* show chest traps first, so that subsequent floor trap display + will override if both types are present at the same location */ + (void) detect_obj_traps(fobj, TRUE, cursed_src); + (void) detect_obj_traps(g.level.buriedobjlist, TRUE, cursed_src); + for (mon = fmon; mon; mon = mon->nmon) { + if (DEADMONSTER(mon) || (mon->isgd && !mon->mx)) + continue; + (void) detect_obj_traps(mon->minvent, TRUE, cursed_src); + } + (void) detect_obj_traps(g.invent, TRUE, cursed_src); + + for (ttmp = g.ftrap; ttmp; ttmp = ttmp->ntrap) + sense_trap(ttmp, 0, 0, cursed_src); + + dummytrap.ttyp = TRAPPED_DOOR; + for (door = 0; door < g.doorindex; door++) { + cc = g.doors[door]; + if (levl[cc.x][cc.y].typ == SDOOR) /* see above */ + continue; + if (levl[cc.x][cc.y].doormask & D_TRAPPED) { + dummytrap.tx = cc.x, dummytrap.ty = cc.y; + sense_trap(&dummytrap, cc.x, cc.y, cursed_src); + } + } + + /* redisplay hero unless sense_trap() revealed something at */ + glyph = glyph_at(u.ux, u.uy); + if (!(glyph_is_trap(glyph) || glyph_is_object(glyph))) { + newsym(u.ux, u.uy); + ter_typ |= TER_MON; /* for autodescribe at */ + } + You_feel("%s.", cursed_src ? "very greedy" : "entrapped"); + + browse_map(ter_typ, "trap of interest"); + + map_redisplay(); +} + /* the detections are pulled out so they can * also be used in the crystal ball routine * returns 1 if nothing was detected @@ -919,7 +968,7 @@ trap_detect(struct obj *sobj) /* null if crystal ball, { register struct trap *ttmp; struct monst *mon; - int door, glyph, tr, ter_typ = TER_DETECT | TER_TRP; + int door, tr; int cursed_src = sobj && sobj->cursed; boolean found = FALSE; coord cc; @@ -929,32 +978,36 @@ trap_detect(struct obj *sobj) /* null if crystal ball, /* floor/ceiling traps */ for (ttmp = g.ftrap; ttmp; ttmp = ttmp->ntrap) { - if (ttmp->tx != u.ux || ttmp->ty != u.uy) - goto outtrapmap; - else + if (ttmp->tx != u.ux || ttmp->ty != u.uy) { + display_trap_map(ttmp, cursed_src); + return 0; + } else found = TRUE; } /* chest traps (might be buried or carried) */ if ((tr = detect_obj_traps(fobj, FALSE, 0)) != OTRAP_NONE) { - if (tr & OTRAP_THERE) - goto outtrapmap; - else + if (tr & OTRAP_THERE) { + display_trap_map(ttmp, cursed_src); + return 0; + } else found = TRUE; } if ((tr = detect_obj_traps(g.level.buriedobjlist, FALSE, 0)) != OTRAP_NONE) { - if (tr & OTRAP_THERE) - goto outtrapmap; - else + if (tr & OTRAP_THERE) { + display_trap_map(ttmp, cursed_src); + return 0; + } else found = TRUE; } for (mon = fmon; mon; mon = mon->nmon) { if (DEADMONSTER(mon) || (mon->isgd && !mon->mx)) continue; if ((tr = detect_obj_traps(mon->minvent, FALSE, 0)) != OTRAP_NONE) { - if (tr & OTRAP_THERE) - goto outtrapmap; - else + if (tr & OTRAP_THERE) { + display_trap_map(ttmp, cursed_src); + return 0; + } else found = TRUE; } } @@ -969,9 +1022,10 @@ trap_detect(struct obj *sobj) /* null if crystal ball, if (levl[cc.x][cc.y].typ == SDOOR) continue; if (levl[cc.x][cc.y].doormask & D_TRAPPED) { - if (cc.x != u.ux || cc.y != u.uy) - goto outtrapmap; - else + if (cc.x != u.ux || cc.y != u.uy) { + display_trap_map(ttmp, cursed_src); + return 0; + } else found = TRUE; } } @@ -985,48 +1039,6 @@ trap_detect(struct obj *sobj) /* null if crystal ball, /* traps exist, but only under me - no separate display required */ Your("%s itch.", makeplural(body_part(TOE))); return 0; - - outtrapmap: - cls(); - - (void) unconstrain_map(); - /* show chest traps first, so that subsequent floor trap display - will override if both types are present at the same location */ - (void) detect_obj_traps(fobj, TRUE, cursed_src); - (void) detect_obj_traps(g.level.buriedobjlist, TRUE, cursed_src); - for (mon = fmon; mon; mon = mon->nmon) { - if (DEADMONSTER(mon) || (mon->isgd && !mon->mx)) - continue; - (void) detect_obj_traps(mon->minvent, TRUE, cursed_src); - } - (void) detect_obj_traps(g.invent, TRUE, cursed_src); - - for (ttmp = g.ftrap; ttmp; ttmp = ttmp->ntrap) - sense_trap(ttmp, 0, 0, cursed_src); - - dummytrap.ttyp = TRAPPED_DOOR; - for (door = 0; door < g.doorindex; door++) { - cc = g.doors[door]; - if (levl[cc.x][cc.y].typ == SDOOR) /* see above */ - continue; - if (levl[cc.x][cc.y].doormask & D_TRAPPED) { - dummytrap.tx = cc.x, dummytrap.ty = cc.y; - sense_trap(&dummytrap, cc.x, cc.y, cursed_src); - } - } - - /* redisplay hero unless sense_trap() revealed something at */ - glyph = glyph_at(u.ux, u.uy); - if (!(glyph_is_trap(glyph) || glyph_is_object(glyph))) { - newsym(u.ux, u.uy); - ter_typ |= TER_MON; /* for autodescribe at */ - } - You_feel("%s.", cursed_src ? "very greedy" : "entrapped"); - - browse_map(ter_typ, "trap of interest"); - - map_redisplay(); - return 0; } static int