* mattacku: monster attacks you * returns 1 if monster dies (e.g. "yellow light"), 0 otherwise * Note: if you're displaced or invisible the monster might attack the * wrong position... * Assumption: it's attacking you or an empty square; if there's another * monster which it attacks by mistake, the caller had better * take care of it...
| 488 | * take care of it... |
| 489 | */ |
| 490 | int |
| 491 | mattacku(struct monst *mtmp) |
| 492 | { |
| 493 | struct attack *mattk, alt_attk; |
| 494 | int i, j = 0, tmp, sum[NATTK]; |
| 495 | struct permonst *mdat = mtmp->data; |
| 496 | /* |
| 497 | * ranged: Is it near you? Affects your actions. |
| 498 | * range2: Does it think it's near you? Affects its actions. |
| 499 | * foundyou: Is it attacking you or your image? |
| 500 | * youseeit: Can you observe the attack? It might be attacking your |
| 501 | * image around the corner, or invisible, or you might be blind. |
| 502 | * skipnonmagc: Are further physical attack attempts useless? (After |
| 503 | * a wild miss--usually due to attacking displaced image. Avoids |
| 504 | * excessively verbose miss feedback when monster can do multiple |
| 505 | * attacks and would miss the same wrong spot each time.) |
| 506 | */ |
| 507 | boolean ranged, range2, foundyou, firstfoundyou, youseeit, |
| 508 | skipnonmagc = FALSE; |
| 509 | |
| 510 | calc_mattacku_vars(mtmp, &ranged, &range2, &foundyou, &youseeit); |
| 511 | |
| 512 | if (!ranged) |
| 513 | nomul(0); |
| 514 | if (DEADMONSTER(mtmp)) |
| 515 | return 1; |
| 516 | if (Underwater && !is_swimmer(mtmp->data)) |
| 517 | return 0; |
| 518 | |
| 519 | /* If swallowed, can only be affected by u.ustuck */ |
| 520 | if (u.uswallow) { |
| 521 | if (mtmp != u.ustuck) |
| 522 | return 0; |
| 523 | u.ustuck->mux = u.ux; |
| 524 | u.ustuck->muy = u.uy; |
| 525 | if (u.uinvulnerable) |
| 526 | return 0; /* stomachs can't hurt you! */ |
| 527 | range2 = 0; |
| 528 | foundyou = 1; |
| 529 | } else if (u.usteed) { |
| 530 | if (mtmp == u.usteed) |
| 531 | /* Your steed won't attack you */ |
| 532 | return 0; |
| 533 | /* Orcs like to steal and eat horses and the like */ |
| 534 | if (!rn2(is_orc(mtmp->data) ? 2 : 4) && m_next2u(mtmp)) { |
| 535 | /* attack your steed instead; 'bhitpos' and 'notonhead' are |
| 536 | already set from targeting hero */ |
| 537 | i = mattackm(mtmp, u.usteed); |
| 538 | if ((i & M_ATTK_AGR_DIED) != 0) |
| 539 | return 1; |
| 540 | /* make sure steed is still alive and within range */ |
| 541 | if ((i & M_ATTK_DEF_DIED) != 0 || !u.usteed |
| 542 | || !m_next2u(mtmp)) |
| 543 | return 0; |
| 544 | /* Let your steed retaliate */ |
| 545 | gb.bhitpos.x = mtmp->mx, gb.bhitpos.y = mtmp->my; |
| 546 | gn.notonhead = FALSE; |
| 547 | return !!(mattackm(u.usteed, mtmp) & M_ATTK_DEF_DIED); |
no test coverage detected