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

Function strategy

src/wizard.c:269–327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

267}
268
269staticfn unsigned long
270strategy(struct monst *mtmp)
271{
272 unsigned long strat, dstrat;
273
274 if (!is_covetous(mtmp->data)
275 /* perhaps a shopkeeper has been polymorphed into a master
276 lich; we don't want it teleporting to the stairs to heal
277 because that will leave its shop untended */
278 || (mtmp->isshk && inhishop(mtmp))
279 /* likewise for temple priests */
280 || (mtmp->ispriest && inhistemple(mtmp)))
281 return (unsigned long) STRAT_NONE;
282
283 switch ((mtmp->mhp * 3) / mtmp->mhpmax) { /* 0-3 */
284
285 default:
286 case 0: /* panic time - mtmp is almost snuffed */
287 return (unsigned long) STRAT_HEAL;
288
289 case 1: /* the wiz is less cautious */
290 if (mtmp->data != &mons[PM_WIZARD_OF_YENDOR])
291 return (unsigned long) STRAT_HEAL;
292 FALLTHROUGH;
293 /* FALLTHRU */
294 case 2:
295 dstrat = STRAT_HEAL;
296 break;
297
298 case 3:
299 dstrat = STRAT_NONE;
300 break;
301 }
302
303 if (svc.context.made_amulet)
304 if ((strat = target_on(M3_WANTSAMUL, mtmp)) != STRAT_NONE)
305 return strat;
306
307 if (u.uevent.invoked) { /* priorities change once gate opened */
308 if ((strat = target_on(M3_WANTSARTI, mtmp)) != STRAT_NONE)
309 return strat;
310 if ((strat = target_on(M3_WANTSBOOK, mtmp)) != STRAT_NONE)
311 return strat;
312 if ((strat = target_on(M3_WANTSBELL, mtmp)) != STRAT_NONE)
313 return strat;
314 if ((strat = target_on(M3_WANTSCAND, mtmp)) != STRAT_NONE)
315 return strat;
316 } else {
317 if ((strat = target_on(M3_WANTSBOOK, mtmp)) != STRAT_NONE)
318 return strat;
319 if ((strat = target_on(M3_WANTSBELL, mtmp)) != STRAT_NONE)
320 return strat;
321 if ((strat = target_on(M3_WANTSCAND, mtmp)) != STRAT_NONE)
322 return strat;
323 if ((strat = target_on(M3_WANTSARTI, mtmp)) != STRAT_NONE)
324 return strat;
325 }
326 return dstrat;

Callers 1

tacticsFunction · 0.85

Calls 3

inhishopFunction · 0.85
inhistempleFunction · 0.85
target_onFunction · 0.85

Tested by

no test coverage detected