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

Function paybill

src/shk.c:2484–2570  ·  view source on GitHub ↗

routine called after dying (or quitting) */

Source from the content-addressed store, hash-verified

2482
2483/* routine called after dying (or quitting) */
2484boolean
2485paybill(
2486 int croaked, /* -1: escaped dungeon; 0: quit; 1: died */
2487 boolean silently) /* maybe avoid messages */
2488{
2489 struct monst *mtmp, *mtmp2, *firstshk, *resident, *creditor, *hostile,
2490 *localshk;
2491 struct eshk *eshkp;
2492 boolean taken = FALSE, local;
2493 int numsk = 0;
2494
2495 /* if we escaped from the dungeon, shopkeepers can't reach us;
2496 shops don't occur on level 1, but this could happen if hero
2497 level teleports out of the dungeon and manages not to die */
2498 if (croaked < 0)
2499 return FALSE;
2500 /* [should probably also return false when dead hero has been
2501 petrified since shk shouldn't be able to grab inventory
2502 which has been shut inside a statue] */
2503
2504 /* this is where inventory will end up if any shk takes it */
2505 gr.repo.location.x = gr.repo.location.y = 0;
2506 gr.repo.shopkeeper = 0;
2507
2508 /*
2509 * Scan all shopkeepers on the level, to prioritize them:
2510 * 1) keeper of shop hero is inside and who is owed money,
2511 * 2) keeper of shop hero is inside who isn't owed any money,
2512 * 3) other shk who is owed money, 4) other shk who is angry,
2513 * 5) any shk local to this level, and if none is found,
2514 * 6) first shk on monster list (last resort; unlikely, since
2515 * any nonlocal shk will probably be in the owed category
2516 * and almost certainly be in the angry category).
2517 */
2518 resident = creditor = hostile = localshk = (struct monst *) 0;
2519 for (mtmp = next_shkp(fmon, FALSE); mtmp;
2520 mtmp = next_shkp(mtmp2, FALSE)) {
2521 mtmp2 = mtmp->nmon;
2522 eshkp = ESHK(mtmp);
2523 local = on_level(&eshkp->shoplevel, &u.uz);
2524 if (local && strchr(u.ushops, eshkp->shoproom)) {
2525 /* inside this shk's shop [there might be more than one
2526 resident shk if hero is standing in a breech of a shared
2527 wall, so give priority to one who's also owed money] */
2528 if (!resident || eshkp->billct || eshkp->debit || eshkp->robbed)
2529 resident = mtmp;
2530 } else if (eshkp->billct || eshkp->debit || eshkp->robbed) {
2531 /* owe this shopkeeper money (might also owe others) */
2532 if (!creditor)
2533 creditor = mtmp;
2534 } else if (eshkp->following || ANGRY(mtmp)) {
2535 /* this shopkeeper is antagonistic (others might be too) */
2536 if (!hostile)
2537 hostile = mtmp;
2538 } else if (local) {
2539 /* this shopkeeper's shop is on current level */
2540 if (!localshk)
2541 localshk = mtmp;

Callers 1

really_doneFunction · 0.85

Calls 4

next_shkpFunction · 0.85
on_levelFunction · 0.85
inheritsFunction · 0.85
mongoneFunction · 0.85

Tested by

no test coverage detected