for magic unlocking; returns true if targeted monster (which might be hero) gets hit by a trap (target might avoid its effect) */
| 6249 | /* for magic unlocking; returns true if targeted monster (which might |
| 6250 | be hero) gets hit by a trap (target might avoid its effect) */ |
| 6251 | boolean |
| 6252 | openfallingtrap( |
| 6253 | struct monst *mon, |
| 6254 | boolean trapdoor_only, |
| 6255 | boolean *noticed) /* set to true iff hero notices the effect; */ |
| 6256 | { /* otherwise left with its previous value intact */ |
| 6257 | struct trap *t; |
| 6258 | boolean ishero = (mon == &gy.youmonst), result; |
| 6259 | |
| 6260 | if (!mon) |
| 6261 | return FALSE; |
| 6262 | if (mon == u.usteed) |
| 6263 | ishero = TRUE; |
| 6264 | t = t_at(ishero ? u.ux : mon->mx, ishero ? u.uy : mon->my); |
| 6265 | /* if no trap here or it's not a falling trap, we're done |
| 6266 | (note: falling rock traps have a trapdoor in the ceiling) */ |
| 6267 | if (!t || ((t->ttyp != TRAPDOOR && t->ttyp != ROCKTRAP) |
| 6268 | && (trapdoor_only || (t->ttyp != HOLE && !is_pit(t->ttyp))))) |
| 6269 | return FALSE; |
| 6270 | |
| 6271 | if (ishero) { |
| 6272 | if (u.utrap) |
| 6273 | return FALSE; /* already trapped */ |
| 6274 | *noticed = TRUE; |
| 6275 | dotrap(t, FORCETRAP); |
| 6276 | result = (u.utrap != 0); |
| 6277 | } else { |
| 6278 | if (mon->mtrapped) |
| 6279 | return FALSE; /* already trapped */ |
| 6280 | /* you notice it if you see the trap close/tremble/whatever |
| 6281 | or if you sense the monster who becomes trapped */ |
| 6282 | *noticed = cansee(t->tx, t->ty) || canspotmon(mon); |
| 6283 | /* monster will be angered; mintrap doesn't handle that */ |
| 6284 | wakeup(mon, TRUE); |
| 6285 | result = (mintrap(mon, FORCETRAP) != Trap_Effect_Finished); |
| 6286 | /* mon might now be on the migrating monsters list */ |
| 6287 | } |
| 6288 | return result; |
| 6289 | } |
| 6290 | |
| 6291 | /* only called when the player is doing something to the chest directly; |
| 6292 | returns True if chest is destroyed, False if it remains in play */ |
no test coverage detected