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

Function tactics

src/wizard.c:366–468  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

364}
365
366DISABLE_WARNING_UNREACHABLE_CODE
367
368int
369tactics(struct monst *mtmp)
370{
371 unsigned long strat = strategy(mtmp);
372 coordxy sx = 0, sy = 0, mx, my;
373
374 mtmp->mstrategy =
375 (mtmp->mstrategy & (STRAT_WAITMASK | STRAT_APPEARMSG)) | strat;
376
377 switch (strat) {
378 case STRAT_HEAL: /* hide and recover */
379 mx = mtmp->mx, my = mtmp->my;
380
381 if (u.uswallow && u.ustuck == mtmp)
382 expels(mtmp, mtmp->data, TRUE);
383
384 /* if wounded, hole up on or near the stairs (to block them) */
385 choose_stairs(&sx, &sy, (mtmp->m_id % 2));
386 mtmp->mavenge = 1; /* covetous monsters attack while fleeing */
387 if (In_W_tower(mx, my, &u.uz)
388 || (mtmp->iswiz && !sx && !mon_has_amulet(mtmp))) {
389 if (!noteleport_level(mtmp) &&
390 !rn2(3 + mtmp->mhp / 10))
391 (void) rloc(mtmp, RLOC_MSG);
392 } else if (sx && (mx != sx || my != sy)) {
393 if (!noteleport_level(mtmp) &&
394 !mnearto(mtmp, sx, sy, TRUE, RLOC_MSG)) {
395 /* couldn't move to the target spot for some reason,
396 so stay where we are (don't actually need rloc_to()
397 because mtmp is still on the map at <mx,my>... */
398 rloc_to(mtmp, mx, my);
399 return 0;
400 }
401 mx = mtmp->mx, my = mtmp->my; /* update cached location */
402 }
403 /* if you're not around, cast healing spells */
404 if (distu(mx, my) > (BOLT_LIM * BOLT_LIM))
405 if (mtmp->mhp <= mtmp->mhpmax - 8) {
406 healmon(mtmp, rnd(8), 0);
407 return 1;
408 }
409 FALLTHROUGH;
410 /*FALLTHRU*/
411
412 case STRAT_NONE: /* harass */
413 if (!noteleport_level(mtmp) && !rn2(!mtmp->mflee ? 5 : 33))
414 mnexto(mtmp, RLOC_MSG);
415 return 0;
416
417 default: /* kill, maim, pillage! */
418 {
419 long where = (strat & STRAT_STRATMASK);
420 coordxy tx = mtmp->mgoal.x, ty = mtmp->mgoal.y;
421 int targ = (int) (strat & STRAT_GOAL);
422 struct obj *otmp;
423

Callers 1

dochugFunction · 0.85

Calls 15

strategyFunction · 0.85
expelsFunction · 0.85
choose_stairsFunction · 0.85
In_W_towerFunction · 0.85
mon_has_amuletFunction · 0.85
noteleport_levelFunction · 0.85
rn2Function · 0.85
rlocFunction · 0.85
mneartoFunction · 0.85
rloc_toFunction · 0.85
healmonFunction · 0.85
rndFunction · 0.85

Tested by

no test coverage detected