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

Function bagotricks

src/makemon.c:2553–2601  ·  view source on GitHub ↗

release monster from bag of tricks; return number of monsters created */

Source from the content-addressed store, hash-verified

2551
2552/* release monster from bag of tricks; return number of monsters created */
2553int
2554bagotricks(
2555 struct obj *bag,
2556 boolean tipping, /* caller emptying entirely; affects shop handling */
2557 int *seencount) /* secondary output */
2558{
2559 int moncount = 0;
2560
2561 if (!bag || bag->otyp != BAG_OF_TRICKS) {
2562 impossible("bad bag o' tricks");
2563 } else if (bag->spe < 1) {
2564 /* if tipping known empty bag, give normal empty container message */
2565 pline1((tipping && bag->cknown) ? "It's empty." : nothing_happens);
2566 /* now known to be empty if sufficiently discovered */
2567 if (bag->dknown && objects[bag->otyp].oc_name_known) {
2568 bag->cknown = 1;
2569 update_inventory(); /* for perm_invent */
2570 }
2571 } else {
2572 struct monst *mtmp;
2573 int creatcnt = 1, seecount = 0;
2574
2575 consume_obj_charge(bag, !tipping);
2576
2577 if (!rn2(23))
2578 creatcnt += rnd(7);
2579 do {
2580 mtmp = makemon((struct permonst *) 0, u.ux, u.uy, NO_MM_FLAGS);
2581 if (mtmp) {
2582 ++moncount;
2583 if ((canseemon(mtmp) && (M_AP_TYPE(mtmp) == M_AP_NOTHING
2584 || M_AP_TYPE(mtmp) == M_AP_MONSTER))
2585 || sensemon(mtmp))
2586 ++seecount;
2587 }
2588 } while (--creatcnt > 0);
2589 if (seecount) {
2590 if (seencount)
2591 *seencount += seecount;
2592 if (bag->dknown) {
2593 makeknown(BAG_OF_TRICKS);
2594 update_inventory(); /* for perm_invent */
2595 }
2596 } else if (!tipping) {
2597 pline1(!moncount ? nothing_happens : nothing_seems_to_happen);
2598 }
2599 }
2600 return moncount;
2601}
2602
2603/* create some or all remaining erinyes around the player */
2604void

Callers 2

tipcontainer_checksFunction · 0.85
doapplyFunction · 0.85

Calls 8

update_inventoryFunction · 0.85
consume_obj_chargeFunction · 0.85
rn2Function · 0.85
rndFunction · 0.85
makemonFunction · 0.85
canseemonFunction · 0.85
sensemonFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected