Fix improve not to spend more money than available

improve() attempted not to spend the last dollar, but screwed up when
improving more than one sector.  This could bankrupt the player.

Replace the flawed code by the same simple method that is used
elsewhere: break the loop when there's not enough money left for the
current sector.
This commit is contained in:
Markus Armbruster 2008-08-03 15:09:15 -04:00
parent 4b696a5c30
commit c20ac26ecc

View file

@ -138,20 +138,11 @@ improve(void)
}
dneeded = intrchr[type].in_dcost * maxup;
natp = getnatp(player->cnum);
if ((natp->nat_money - 1) < dneeded) {
/* Nasty - leave 'em with a buck. :) */
dneeded = natp->nat_money - 1;
if (dneeded < 0)
dneeded = 0;
maxup = dneeded / intrchr[type].in_dcost;
if (maxup <= 0) {
pr("Not enough money left to improve %s\n",
xyas(sect.sct_x, sect.sct_y, player->cnum));
continue;
if (player->dolcost + dneeded > natp->nat_money) {
pr("Not enough money left to improve %s by %d%%\n",
xyas(sect.sct_x, sect.sct_y, player->cnum), maxup);
break;
}
}
if (maxup <= 0)
continue;
lneeded = intrchr[type].in_lcms * maxup;
hneeded = intrchr[type].in_hcms * maxup;
mneeded = intrchr[type].in_mcost * maxup;