mktrap(): select trap type and location, then use maketrap() to create it; make it at location 'tm' when that isn't Null, otherwise in 'croom' if mktrapflags doesn't have MKTRAP_MAZEFLAG set, else in maze corridor */
| 2033 | make it at location 'tm' when that isn't Null, otherwise in 'croom' |
| 2034 | if mktrapflags doesn't have MKTRAP_MAZEFLAG set, else in maze corridor */ |
| 2035 | void |
| 2036 | mktrap( |
| 2037 | int num, /* if non-zero, specific type of trap to make */ |
| 2038 | unsigned mktrapflags, /* MKTRAP_{SEEN,MAZEFLAG,NOSPIDERONWEB,NOVICTIM} */ |
| 2039 | struct mkroom *croom, /* room to hold trap */ |
| 2040 | coord *tm) /* specific location for trap */ |
| 2041 | { |
| 2042 | static int mktrap_err = 0; /* move to struct g? */ |
| 2043 | struct trap *t; |
| 2044 | coord m; |
| 2045 | int kind; |
| 2046 | unsigned lvl = level_difficulty(); |
| 2047 | |
| 2048 | if (!tm && !croom && !(mktrapflags & MKTRAP_MAZEFLAG)) { |
| 2049 | /* complain when the combination of arguments will never set 'm' */ |
| 2050 | if (!mktrap_err++) { |
| 2051 | char errbuf[BUFSZ]; |
| 2052 | |
| 2053 | Snprintf(errbuf, sizeof errbuf, |
| 2054 | "args (%d,%d,%s,%s) are invalid", |
| 2055 | num, mktrapflags, "null room", "null location"); |
| 2056 | paniclog("mktrap", errbuf); |
| 2057 | } |
| 2058 | return; |
| 2059 | } |
| 2060 | m.x = m.y = 0; |
| 2061 | |
| 2062 | /* no traps in pools */ |
| 2063 | if (tm && is_pool_or_lava(tm->x, tm->y)) |
| 2064 | return; |
| 2065 | |
| 2066 | if (num > NO_TRAP && num < TRAPNUM) { |
| 2067 | kind = num; |
| 2068 | } else if (Is_rogue_level(&u.uz)) { |
| 2069 | kind = traptype_roguelvl(); |
| 2070 | } else if (Inhell && !rn2(5)) { |
| 2071 | /* bias the frequency of fire traps in Gehennom */ |
| 2072 | kind = FIRE_TRAP; |
| 2073 | } else { |
| 2074 | do { |
| 2075 | kind = traptype_rnd(mktrapflags); |
| 2076 | } while (kind == NO_TRAP); |
| 2077 | } |
| 2078 | |
| 2079 | if (is_hole(kind) && !Can_fall_thru(&u.uz)) |
| 2080 | kind = ROCKTRAP; |
| 2081 | |
| 2082 | if (tm) { |
| 2083 | m = *tm; |
| 2084 | } else { |
| 2085 | int tryct = 0; |
| 2086 | boolean avoid_boulder = (is_pit(kind) || is_hole(kind)); |
| 2087 | |
| 2088 | do { |
| 2089 | if (++tryct > 200) |
| 2090 | return; |
| 2091 | if ((mktrapflags & MKTRAP_MAZEFLAG) != 0) |
| 2092 | mazexy(&m); |
no test coverage detected