MCPcopy Index your code
hub / github.com/NetHack/NetHack / mattackm

Function mattackm

src/mhitm.c:292–592  ·  view source on GitHub ↗

* mattackm() -- a monster attacks another monster. * * --------- aggressor died * / ------- defender died * / / ----- defender was hit * / / / * x x x * * 0x8 M_ATTK_AGR_DONE * 0x4 M_ATTK_AGR_DIED * 0x2 M_ATTK_DEF_DIED * 0x1 M_ATTK_HIT * 0x0 M_ATTK_MISS * * Each successive attack has a lower probab

Source from the content-addressed store, hash-verified

290 * In the case of exploding monsters, the monster dies as well.
291 */
292int
293mattackm(
294 struct monst *magr,
295 struct monst *mdef)
296{
297 int i, /* loop counter */
298 tmp, /* armor class difference */
299 strike = 0, /* hit this attack */
300 attk, /* attack attempted this time */
301 struck = 0, /* hit at least once */
302 res[NATTK], /* results of all attacks */
303 dieroll = 0;
304 struct attack *mattk, alt_attk;
305 struct obj *mwep;
306 struct permonst *pa, *pd;
307
308 if (!magr || !mdef)
309 return M_ATTK_MISS; /* mike@genat */
310 if (helpless(magr))
311 return M_ATTK_MISS;
312 pa = magr->data;
313 pd = mdef->data;
314
315 /* Grid bugs cannot attack at an angle. */
316 if (pa == &mons[PM_GRID_BUG] && magr->mx != mdef->mx
317 && magr->my != mdef->my)
318 return M_ATTK_MISS;
319
320 /* Calculate the armour class differential. */
321 tmp = find_mac(mdef) + magr->m_lev;
322 if (mdef->mconf || helpless(mdef)) {
323 tmp += 4;
324 mdef->msleeping = 0;
325 }
326
327 /* mundetected monsters become un-hidden if they are attacked */
328 if (mdef->mundetected) {
329 mdef->mundetected = 0;
330 newsym(mdef->mx, mdef->my);
331 if (canseemon(mdef) && !sensemon(mdef)) {
332 if (Unaware) {
333 boolean justone = (mdef->data->geno & G_UNIQ) != 0L;
334 const char *montype;
335
336 montype = noname_monnam(mdef, justone ? ARTICLE_THE
337 : ARTICLE_NONE);
338 if (!justone)
339 montype = makeplural(montype);
340 You("dream of %s.", montype);
341 } else {
342 if (iflags.last_msg == PLNMSG_HIDE_UNDER
343 && mdef->m_id == gl.last_hider)
344 pline_mon(mdef, "%s emerges from hiding.", Monnam(mdef));
345 else if (mdef->m_id == gl.last_hider)
346 You("notice %s.", mon_nam(mdef));
347 else
348 pline("Suddenly, you notice %s.", a_monnam(mdef));
349 }

Callers 6

fightmFunction · 0.85
pet_ranged_attkFunction · 0.85
dog_moveFunction · 0.85
m_moveFunction · 0.85
m_move_aggressFunction · 0.85
mattackuFunction · 0.85

Calls 15

find_macFunction · 0.85
newsymFunction · 0.85
canseemonFunction · 0.85
sensemonFunction · 0.85
noname_monnamFunction · 0.85
makepluralFunction · 0.85
YouFunction · 0.85
pline_monFunction · 0.85
MonnamFunction · 0.85
mon_namFunction · 0.85
a_monnamFunction · 0.85
getmattkFunction · 0.85

Tested by

no test coverage detected