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 */
| 1008 | * returns 0 if something was detected |
| 1009 | */ |
| 1010 | int |
| 1011 | trap_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 */ |
no test coverage detected