From 82c916654cf7b344d24349696a7eb3bb5ecc1b53 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 3 Aug 2008 14:40:13 -0400 Subject: [PATCH] Don't permit convert to spend more money than available 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 | 41 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/src/lib/commands/conv.c b/src/lib/commands/conv.c index 6c78c6235..de3928e4f 100644 --- a/src/lib/commands/conv.c +++ b/src/lib/commands/conv.c @@ -40,41 +40,25 @@ #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, §)) { @@ -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(§); 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; -- 2.43.0