]> git.pond.sub.org Git - empserver/commitdiff
Fix improve not to spend more money than available
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 3 Aug 2008 19:09:15 +0000 (15:09 -0400)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 9 Aug 2008 12:40:04 +0000 (08:40 -0400)
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

index c7b00bdee67c9efc9683f053b5f87c1f920763bc..e8fba1b67a70eca38806b7ed2bfbf9cbfd33d953 100644 (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;