MCPcopy Create free account
hub / github.com/NetHack/NetHack / losedogs

Function losedogs

src/dog.c:303–416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

301static struct monst *failed_arrivals = 0;
302
303void
304losedogs(void)
305{
306 struct monst *mtmp, **mprev;
307 int dismissKops = 0, xyloc;
308
309 failed_arrivals = 0;
310 /*
311 * First, scan gm.migrating_mons for shopkeepers who want to dismiss Kops,
312 * and scan gm.mydogs for shopkeepers who want to retain kops.
313 * Second, dismiss kops if warranted, making more room for arrival.
314 * Third, replace monsters who went onto migrating_mons in order to
315 * be accessible from other levels but didn't actually leave the level.
316 * Fourth, place monsters accompanying the hero.
317 * Last, place migrating monsters coming to this level.
318 *
319 * Hero might eventually be displaced (due to the third step, but
320 * occurring later), which is the main reason to do the second step
321 * sooner (in turn necessitating the first step, rather than combining
322 * the list scans with monster placement).
323 */
324
325 /* check for returning shk(s) */
326 for (mtmp = gm.migrating_mons; mtmp; mtmp = mtmp->nmon) {
327 if (mtmp->mux != u.uz.dnum || mtmp->muy != u.uz.dlevel)
328 continue;
329 if (mtmp->isshk) {
330 if (ESHK(mtmp)->dismiss_kops) {
331 if (dismissKops == 0)
332 dismissKops = 1;
333 ESHK(mtmp)->dismiss_kops = FALSE; /* reset */
334 } else if (!mtmp->mpeaceful) {
335 /* an unpacified shk is returning; don't dismiss kops
336 even if another pacified one is willing to do so */
337 dismissKops = -1;
338 /* [keep looping; later monsters might need ESHK reset] */
339 }
340 }
341 }
342 /* make the same check for gm.mydogs */
343 for (mtmp = gm.mydogs; mtmp && dismissKops >= 0; mtmp = mtmp->nmon) {
344 if (mtmp->isshk) {
345 /* hostile shk might accompany hero [ESHK(mtmp)->dismiss_kops
346 can't be set here; it's only used for gm.migrating_mons] */
347 if (!mtmp->mpeaceful)
348 dismissKops = -1;
349 }
350 }
351
352 /* when a hostile shopkeeper chases hero to another level
353 and then gets paid off there, get rid of summoned kops
354 here now that he has returned to his shop level */
355 if (dismissKops > 0)
356 make_happy_shoppers(TRUE);
357
358 /* put monsters who went onto migrating_mons in order to be accessible
359 when other levels are active back to their positions on this level;
360 they're handled before mydogs so that monsters accompanying the

Callers 2

goto_levelFunction · 0.85
makemap_prepostFunction · 0.85

Calls 3

make_happy_shoppersFunction · 0.85
mon_arriveFunction · 0.85
m_into_limboFunction · 0.85

Tested by

no test coverage detected