From c20ac26ecc0b757dd6d13ebd74c8e8e4591d4d2e Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 3 Aug 2008 15:09:15 -0400 Subject: [PATCH] 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. --- src/lib/commands/improve.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/lib/commands/improve.c b/src/lib/commands/improve.c index c7b00bde..e8fba1b6 100644 --- a/src/lib/commands/improve.c +++ b/src/lib/commands/improve.c @@ -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;