]> git.pond.sub.org Git - empserver/commitdiff
Don't permit convert to spend more money than available
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 3 Aug 2008 18:40:13 +0000 (14:40 -0400)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 9 Aug 2008 12:38:07 +0000 (08:38 -0400)
Complicated by the fact that conv() ran the conversion code twice,
first for adding up the cost for chkmoney(), then for actually
converting.  chkmoney() asks the player to confirm when he's about to
spend more than half his cash.  Get rid of that, not worth the
complexity.  This merges do_conv() back into conv().

src/lib/commands/conv.c

index 6c78c6235e6c8c16075c799a0bef6b1d51aa7de3..de3928e4fd1bc5e29869f394ed5484dbaf8bc2f5 100644 (file)
 #include "commands.h"
 #include "land.h"
 
-static long do_conv(struct nstr_sect nstr, int uwtoconvert, int for_real);
-
 int
 conv(void)
 {
     struct natstr *natp;
-    long cash;
-    long cost;
+    struct sctstr sect;
     struct nstr_sect nstr;
-    int uwtoconvert;
+    int uwtoconvert, newuw, totaluw, uw;
+    int maxpop, civ, mil, adj_mob, mob;
+    double security_extra = 1.0;
+    struct lndstr land;
+    struct nstr_item ni;
+
 
     natp = getnatp(player->cnum);
-    cash = natp->nat_money;
     if (!snxtsct(&nstr, player->argp[1]))
        return RET_SYN;
     uwtoconvert = onearg(player->argp[2], "Number to convert: ");
     if (uwtoconvert < 0)
        return RET_SYN;
-    cost = do_conv(nstr, uwtoconvert, 0);
-    if (chkmoney(cost, cash, player->argp[3]))
-       return RET_SYN;
-    return (int)do_conv(nstr, uwtoconvert, 1);
-}
-
-static long
-do_conv(struct nstr_sect nstr, int uwtoconvert, int for_real)
-{
-    struct natstr *natp;
-    struct sctstr sect;
-    int newuw, totaluw, uw;
-    int maxpop, civ, mil, adj_mob, mob;
-    double security_extra = 1.0;
-    struct lndstr land;
-    struct nstr_item ni;
-    long cost = 0;
 
     totaluw = 0;
     while (nxtsct(&nstr, &sect)) {
@@ -106,8 +90,6 @@ do_conv(struct nstr_sect nstr, int uwtoconvert, int for_real)
                 */
                security_extra += .1;
                land.lnd_mobil -= 10;
-               if (for_real)
-                   putland(land.lnd_uid, &land);
                mil += land.lnd_item[I_MILIT];
            }
        }
@@ -138,9 +120,10 @@ do_conv(struct nstr_sect nstr, int uwtoconvert, int for_real)
            newuw = adj_mob;
        if (newuw <= 0)
            continue;
-       if (!for_real) {
-           cost += newuw * 1.5;
-           continue;
+       if (player->dolcost + newuw * 1.5 > natp->nat_money) {
+           pr("You can't afford to convert %d civilians in %s!\n",
+              newuw, xyas(sect.sct_x, sect.sct_y, player->cnum));
+           break;
        }
        player->btused += (newuw - 1) / 100 + 1;
        player->dolcost += newuw * 1.5;
@@ -163,8 +146,6 @@ do_conv(struct nstr_sect nstr, int uwtoconvert, int for_real)
        putsect(&sect);
        totaluw += newuw;
     }
-    if (!for_real)
-       return cost;
     pr("Total civilians converted: %d\n", totaluw);
     pr("Paperwork at conversion places ... %d\n", player->btused);
     return RET_OK;