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

Function detect_obj_traps

src/detect.c:906–953  ·  view source on GitHub ↗

check a list of objects for chest traps; return 1 if found at , 2 if found at some other spot, 3 if both, 0 otherwise; optionally update the map to show where such traps were found */

Source from the content-addressed store, hash-verified

904 2 if found at some other spot, 3 if both, 0 otherwise; optionally
905 update the map to show where such traps were found */
906staticfn int
907detect_obj_traps(
908 struct obj *objlist,
909 boolean show_them,
910 int how, /* 1 for misleading map feedback */
911 struct found_things *ft) /* being called by findone() when non-Null */
912{
913 struct obj *otmp;
914 coordxy x, y;
915 int trapglyph, result = OTRAP_NONE;
916
917 /*
918 * TODO? Display locations of unarmed land mine and beartrap objects.
919 * If so, should they be displayed as objects or as traps?
920 */
921
922 dummytrap.ttyp = TRAPPED_CHEST;
923 trapglyph = ft ? trap_to_glyph(&dummytrap) : GLYPH_NOTHING;
924 for (otmp = objlist; otmp; otmp = otmp->nobj) {
925 x = y = 0; /* lint suppression */
926 if ((Is_box(otmp) && otmp->otrapped) || Has_contents(otmp)) {
927 /* !get_obj_location and !isok should both be impossible here */
928 if (!get_obj_location(otmp, &x, &y, BURIED_TOO | CONTAINED_TOO)
929 || !isok(x, y)
930 || (ft && (x != ft->ft_cc.x || y != ft->ft_cc.y)))
931 continue;
932 }
933 if (Is_box(otmp) && otmp->otrapped) {
934 otmp->tknown = 1;
935 observe_object(otmp);
936 result |= u_at(x, y) ? OTRAP_HERE : OTRAP_THERE;
937 if (ft) {
938 flash_glyph_at(x, y, trapglyph, FOUND_FLASH_COUNT);
939 }
940 if (show_them) {
941 dummytrap.tx = x, dummytrap.ty = y;
942 sense_trap(&dummytrap, x, y, how);
943 }
944 if (ft) {
945 foundone(x, y, trapglyph);
946 ft->num_traps++;
947 }
948 }
949 if (Has_contents(otmp))
950 result |= detect_obj_traps(otmp->cobj, show_them, how, ft);
951 }
952 return result;
953}
954
955staticfn void
956display_trap_map(int cursed_src)

Callers 3

display_trap_mapFunction · 0.85
trap_detectFunction · 0.85
findoneFunction · 0.85

Calls 6

get_obj_locationFunction · 0.85
isokFunction · 0.85
observe_objectFunction · 0.85
flash_glyph_atFunction · 0.85
sense_trapFunction · 0.85
foundoneFunction · 0.85

Tested by

no test coverage detected