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().
This commit is contained in:
parent
cc4cf23273
commit
82c916654c
1 changed files with 11 additions and 30 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue