set dog's goal -- gtyp, gx, gy; returns -1/0/1 (dog's desire to approach player) or -2 (abort move) */
| 480 | /* set dog's goal -- gtyp, gx, gy; |
| 481 | returns -1/0/1 (dog's desire to approach player) or -2 (abort move) */ |
| 482 | staticfn int |
| 483 | dog_goal( |
| 484 | struct monst *mtmp, |
| 485 | struct edog *edog, |
| 486 | int after, int udist, int whappr) |
| 487 | { |
| 488 | coordxy omx, omy; |
| 489 | boolean in_masters_sight, dog_has_minvent; |
| 490 | struct obj *obj; |
| 491 | xint16 otyp; |
| 492 | int appr; |
| 493 | |
| 494 | /* Steeds don't move on their own will */ |
| 495 | if (mtmp == u.usteed) |
| 496 | return -2; |
| 497 | |
| 498 | omx = mtmp->mx; |
| 499 | omy = mtmp->my; |
| 500 | |
| 501 | in_masters_sight = couldsee(omx, omy); |
| 502 | dog_has_minvent = (droppables(mtmp) != 0); |
| 503 | |
| 504 | if (!edog || mtmp->mleashed) { /* he's not going anywhere... */ |
| 505 | gg.gtyp = APPORT; |
| 506 | gg.gx = u.ux; |
| 507 | gg.gy = u.uy; |
| 508 | } else { |
| 509 | #define DDIST(x, y) (dist2(x, y, omx, omy)) |
| 510 | #define SQSRCHRADIUS 5 |
| 511 | int min_x, max_x, min_y, max_y; |
| 512 | coordxy nx, ny; |
| 513 | |
| 514 | gg.gtyp = UNDEF; /* no goal as yet */ |
| 515 | gg.gx = gg.gy = 0; /* suppress 'used before set' message */ |
| 516 | |
| 517 | if ((min_x = omx - SQSRCHRADIUS) < 1) |
| 518 | min_x = 1; |
| 519 | if ((max_x = omx + SQSRCHRADIUS) >= COLNO) |
| 520 | max_x = COLNO - 1; |
| 521 | if ((min_y = omy - SQSRCHRADIUS) < 0) |
| 522 | min_y = 0; |
| 523 | if ((max_y = omy + SQSRCHRADIUS) >= ROWNO) |
| 524 | max_y = ROWNO - 1; |
| 525 | |
| 526 | /* nearby food is the first choice, then other objects */ |
| 527 | for (obj = fobj; obj; obj = obj->nobj) { |
| 528 | nx = obj->ox; |
| 529 | ny = obj->oy; |
| 530 | if (nx >= min_x && nx <= max_x && ny >= min_y && ny <= max_y) { |
| 531 | otyp = dogfood(mtmp, obj); |
| 532 | /* skip inferior goals */ |
| 533 | if (otyp > gg.gtyp || otyp == UNDEF) |
| 534 | continue; |
| 535 | /* avoid cursed items unless starving */ |
| 536 | if (cursed_object_at(nx, ny) |
| 537 | && !(edog->mhpmax_penalty && otyp < MANFOOD)) |
| 538 | continue; |
| 539 | /* skip completely unreachable goals */ |
no test coverage detected