return True if magr is allowed to swallow mdef, False otherwise */
| 804 | |
| 805 | /* return True if magr is allowed to swallow mdef, False otherwise */ |
| 806 | boolean |
| 807 | engulf_target(struct monst *magr, struct monst *mdef) |
| 808 | { |
| 809 | struct rm *lev; |
| 810 | int ax, ay, dx, dy; |
| 811 | boolean uatk = (magr == &gy.youmonst), |
| 812 | udef = (mdef == &gy.youmonst); |
| 813 | |
| 814 | /* can't swallow something that's too big */ |
| 815 | if (mdef->data->msize >= MZ_HUGE |
| 816 | || (magr->data->msize < mdef->data->msize && !is_whirly(magr->data))) |
| 817 | return FALSE; |
| 818 | |
| 819 | /* can't (move to) swallow if trapped. TODO: could do some? */ |
| 820 | if (mdef->mtrapped || magr->mtrapped) |
| 821 | return FALSE; |
| 822 | |
| 823 | /* if attacker is phasing in solid rock and defender can't move there, |
| 824 | or vice versa, don't allow engulf to succeed; otherwise expelling |
| 825 | might not be able to place attacker and defender both back on map; |
| 826 | when defender is the hero, a sanity_check complaint about placing |
| 827 | the hero on top of a monster can occur */ |
| 828 | dx = (mdef == &gy.youmonst) ? u.ux : mdef->mx; |
| 829 | dy = (mdef == &gy.youmonst) ? u.uy : mdef->my; |
| 830 | lev = &levl[dx][dy]; |
| 831 | if (!(udef ? Passes_walls : passes_walls(mdef->data)) |
| 832 | && (IS_OBSTRUCTED(lev->typ) || closed_door(dx, dy) || IS_TREE(lev->typ) |
| 833 | /* not passes_bars(); engulfer isn't squeezing through */ |
| 834 | || (lev->typ == IRONBARS && !is_whirly(magr->data)))) |
| 835 | return FALSE; |
| 836 | ax = (magr == &gy.youmonst) ? u.ux : magr->mx; |
| 837 | ay = (magr == &gy.youmonst) ? u.uy : magr->my; |
| 838 | lev = &levl[ax][ay]; |
| 839 | if (!(uatk ? Passes_walls : passes_walls(magr->data)) |
| 840 | && (IS_OBSTRUCTED(lev->typ) || closed_door(ax, ay) || IS_TREE(lev->typ) |
| 841 | || (lev->typ == IRONBARS && !is_whirly(mdef->data)))) |
| 842 | return FALSE; |
| 843 | |
| 844 | return TRUE; |
| 845 | } |
| 846 | |
| 847 | /* Returns the same values as mattackm(). */ |
| 848 | staticfn int |
no test coverage detected