MCPcopy Index your code
hub / github.com/NetHack/NetHack / trap_detect

Function trap_detect

src/detect.c:1010–1088  ·  view source on GitHub ↗

the detections are pulled out so they can * also be used in the crystal ball routine * returns 1 if nothing was detected * returns 0 if something was detected */

Source from the content-addressed store, hash-verified

1008 * returns 0 if something was detected
1009 */
1010int
1011trap_detect(
1012 struct obj *sobj) /* Null if crystal ball, scroll if gold detection */
1013{
1014 struct trap *ttmp;
1015 struct monst *mon;
1016 int door, tr;
1017 int cursed_src = sobj && sobj->cursed;
1018 boolean found = FALSE;
1019 coord cc;
1020
1021 if (u.usteed)
1022 u.usteed->mx = u.ux, u.usteed->my = u.uy;
1023
1024 /* floor/ceiling traps */
1025 for (ttmp = gf.ftrap; ttmp; ttmp = ttmp->ntrap) {
1026 if (ttmp->tx != u.ux || ttmp->ty != u.uy) {
1027 display_trap_map(cursed_src);
1028 return 0;
1029 }
1030 found = TRUE;
1031 }
1032 /* chest traps (might be buried or carried) */
1033 if ((tr = detect_obj_traps(fobj, FALSE, 0, NULL)) != OTRAP_NONE) {
1034 if (tr & OTRAP_THERE) {
1035 display_trap_map(cursed_src);
1036 return 0;
1037 }
1038 found = TRUE;
1039 }
1040 if ((tr = detect_obj_traps(svl.level.buriedobjlist, FALSE, 0, NULL))
1041 != OTRAP_NONE) {
1042 if (tr & OTRAP_THERE) {
1043 display_trap_map(cursed_src);
1044 return 0;
1045 }
1046 found = TRUE;
1047 }
1048 for (mon = fmon; mon; mon = mon->nmon) {
1049 if (DEADMONSTER(mon) || (mon->isgd && !mon->mx))
1050 continue;
1051 if ((tr = detect_obj_traps(mon->minvent, FALSE, 0, NULL))
1052 != OTRAP_NONE) {
1053 if (tr & OTRAP_THERE) {
1054 display_trap_map(cursed_src);
1055 return 0;
1056 }
1057 found = TRUE;
1058 }
1059 }
1060 if (detect_obj_traps(gi.invent, FALSE, 0, NULL) != OTRAP_NONE)
1061 found = TRUE;
1062 /* door traps */
1063 for (door = 0; door < gd.doorindex; door++) {
1064 cc = svd.doors[door];
1065 /* levl[][].doormask and .wall_info both overlay levl[][].flags;
1066 the bit in doormask for D_TRAPPED is also a bit in wall_info;
1067 secret doors use wall_info so can't be marked as trapped */

Callers 2

use_crystal_ballFunction · 0.85
seffect_gold_detectionFunction · 0.85

Calls 6

display_trap_mapFunction · 0.85
detect_obj_trapsFunction · 0.85
makepluralFunction · 0.85
body_partFunction · 0.85
strange_feelingFunction · 0.85
YourFunction · 0.85

Tested by

no test coverage detected