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

Function money2mon

src/shk.c:156–178  ·  view source on GitHub ↗

* Transfer money from inventory to monster when paying * shopkeepers, priests, oracle, succubus, and other demons. * Simple with only gold coins. * This routine will handle money changing when multiple * coin types is implemented, only appropriate * monsters will pay change. (Peaceful shopkeepers, priests * and the oracle try to maintain goodwill while selling * their wares or serv

Source from the content-addressed store, hash-verified

154 * if the monster kept the change.
155 */
156long
157money2mon(struct monst *mon, long amount)
158{
159 struct obj *ygold = findgold(gi.invent);
160
161 if (amount <= 0) {
162 impossible("%s payment in money2mon!", amount ? "negative" : "zero");
163 return 0L;
164 }
165 if (!ygold || ygold->quan < amount) {
166 impossible("Paying without %s gold?", ygold ? "enough" : "");
167 return 0L;
168 }
169
170 if (ygold->quan > amount)
171 ygold = splitobj(ygold, amount);
172 else if (ygold->owornmask)
173 remove_worn_item(ygold, FALSE); /* quiver */
174 freeinv(ygold);
175 add_to_minv(mon, ygold);
176 disp.botl = TRUE;
177 return amount;
178}
179
180/*
181 * Transfer money from monster to inventory.

Callers 8

bribeFunction · 0.85
doseduceFunction · 0.85
payFunction · 0.85
dopayFunction · 0.85
inheritsFunction · 0.85
finish_paybillFunction · 0.85
pay_for_damageFunction · 0.85
doconsultFunction · 0.85

Calls 6

findgoldFunction · 0.85
splitobjFunction · 0.85
remove_worn_itemFunction · 0.85
freeinvFunction · 0.85
add_to_minvFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected