more GOLDOBJ

The earlier patch made sure that bribe() didn't pass an
invalid value to money2mon().  This one changes money2mon() so
that if some other code else does so, reporting the impossible
situation won't be followed by a splitobj panic.  Most of this
patch is reformatting though.
This commit is contained in:
nethack.rankin
2002-01-24 02:54:06 +00:00
parent 659f5be714
commit ef8f180fbc
2 changed files with 55 additions and 52 deletions
+7 -7
View File
@@ -186,19 +186,19 @@ struct monst *mtmp;
} else if (offer >= u.ugold) { } else if (offer >= u.ugold) {
You("give %s all your gold.", mon_nam(mtmp)); You("give %s all your gold.", mon_nam(mtmp));
offer = u.ugold; offer = u.ugold;
} else You("give %s %ld %s.", mon_nam(mtmp), offer, } else {
currency(offer)); You("give %s %ld %s.", mon_nam(mtmp), offer, currency(offer));
}
u.ugold -= offer; u.ugold -= offer;
mtmp->mgold += offer; mtmp->mgold += offer;
#else #else
} else if (offer >= umoney) { } else if (offer >= umoney) {
You("give %s all your gold.", mon_nam(mtmp)); You("give %s all your gold.", mon_nam(mtmp));
offer = umoney; offer = umoney;
} else You("give %s %ld %s.", mon_nam(mtmp), offer, } else {
currency(offer)); You("give %s %ld %s.", mon_nam(mtmp), offer, currency(offer));
}
money2mon(mtmp, offer); (void) money2mon(mtmp, offer);
#endif #endif
flags.botl = 1; flags.botl = 1;
return(offer); return(offer);
+12 -9
View File
@@ -87,23 +87,24 @@ static void FDECL(rob_shop, (struct monst *));
will keep anything they get their hands on. will keep anything they get their hands on.
Returns the amount actually paid, so we can know Returns the amount actually paid, so we can know
if the monster kept the change. if the monster kept the change.
*/ */
long money2mon(mon, amount) long money2mon(mon, amount)
struct monst *mon; struct monst *mon;
long amount; long amount;
{ {
struct obj *ygold = findgold(invent); struct obj *ygold = findgold(invent);
if (ygold && ygold == uquiver) uqwepgone(); if (amount <= 0) {
impossible("%s payment in money2mon!", amount ? "negative" : "zero");
if (amount <= 0) impossible("%s payment in money2mon!", return 0L;
amount ? "negative" : "zero"); }
if (!ygold || ygold->quan < amount) { if (!ygold || ygold->quan < amount) {
impossible("Paying without %s money?", ygold ? "enough" : ""); impossible("Paying without %s money?", ygold ? "enough" : "");
return 0; return 0L;
} }
if (ygold->quan > amount) ygold = splitobj(ygold, amount); if (ygold->quan > amount) ygold = splitobj(ygold, amount);
else if (ygold->owornmask) remove_worn_item(ygold); /* quiver */
freeinv(ygold); freeinv(ygold);
add_to_minv(mon, ygold); add_to_minv(mon, ygold);
flags.botl = 1; flags.botl = 1;
@@ -115,7 +116,7 @@ long amount;
Transfer money from monster to inventory. Transfer money from monster to inventory.
Used when the shopkeeper pay for items, and when Used when the shopkeeper pay for items, and when
the priest gives you money for an ale. the priest gives you money for an ale.
*/ */
void void
money2u(mon, amount) money2u(mon, amount)
struct monst *mon; struct monst *mon;
@@ -123,8 +124,10 @@ long amount;
{ {
struct obj *mongold = findgold(mon->minvent); struct obj *mongold = findgold(mon->minvent);
if (amount <= 0) impossible("%s payment in money2u!", if (amount <= 0) {
amount ? "negative" : "zero"); impossible("%s payment in money2u!", amount ? "negative" : "zero");
return;
}
if (!mongold || mongold->quan < amount) { if (!mongold || mongold->quan < amount) {
impossible("%s paying without %s money?", a_monnam(mon), impossible("%s paying without %s money?", a_monnam(mon),
mongold ? "enough" : ""); mongold ? "enough" : "");