called from mon_sanity_check(mon.c) */
| 636 | |
| 637 | /* called from mon_sanity_check(mon.c) */ |
| 638 | void |
| 639 | sanity_check_worm(struct monst *worm) |
| 640 | { |
| 641 | struct wseg *curr; |
| 642 | int wnum, x, y; |
| 643 | |
| 644 | if (!worm) { |
| 645 | impossible("worm_sanity: null monster!"); |
| 646 | return; |
| 647 | } |
| 648 | /* note: wormno can't be less than 0 (unsigned bit field) and can't |
| 649 | be greater that MAX_NUM_WORMS - 1 (which uses all available bits) |
| 650 | so checking for 0 is all we can manage for wormno validation; |
| 651 | since caller has already done that, this is rather pointless... */ |
| 652 | if (!worm->wormno) { |
| 653 | impossible("worm_sanity: not a worm!"); |
| 654 | return; |
| 655 | } |
| 656 | |
| 657 | wnum = worm->wormno; |
| 658 | if (!wtails[wnum] || !wheads[wnum]) { |
| 659 | impossible("wormno %d is set without proper tail", wnum); |
| 660 | return; |
| 661 | } |
| 662 | /* if worm is migrating, we can't check its segments against the map */ |
| 663 | if (!worm->mx) |
| 664 | return; |
| 665 | |
| 666 | curr = wtails[wnum]; |
| 667 | while (curr != wheads[wnum]) { |
| 668 | x = curr->wx, y = curr->wy; |
| 669 | if (!isok(x, y)) |
| 670 | impossible("worm seg not isok <%d,%d>", x, y); |
| 671 | else if (svl.level.monsters[x][y] != worm) |
| 672 | impossible("mon (%s) at seg location is not worm (%s)", |
| 673 | fmt_ptr((genericptr_t) svl.level.monsters[x][y]), |
| 674 | fmt_ptr((genericptr_t) worm)); |
| 675 | |
| 676 | curr = curr->nseg; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | /* called from mon_sanity_check(mon.c) */ |
| 681 | void |
no test coverage detected