(prprod): New, factored out of prod().

(prod): Separate enlistment code from production code.  Simplifies
control flow, and thus gets rid of several compiler warnings.
This commit is contained in:
Markus Armbruster 2006-06-05 15:29:28 +00:00
parent 32e4fbd284
commit 08937006d7

View file

@ -47,6 +47,9 @@
#include "optlist.h" #include "optlist.h"
#include "commands.h" #include "commands.h"
static void prprod(struct sctstr *, double, double, int, char,
double, double, double, char[], int[], int[], int);
int int
count_pop(int n) count_pop(int n)
{ {
@ -93,14 +96,15 @@ prod(void)
char cmnem[MAXPRCON]; char cmnem[MAXPRCON];
int cuse[MAXPRCON], cmax[MAXPRCON]; int cuse[MAXPRCON], cmax[MAXPRCON];
int lcms, hcms; int lcms, hcms;
int civs = 0; int civs;
int uws = 0; int uws;
int bwork; int bwork;
int twork; int twork;
int type; int type;
int eff; int eff;
int maxpop; int maxpop;
int otype; int otype;
char mnem;
if (!snxtsct(&nstr, player->argp[1])) if (!snxtsct(&nstr, player->argp[1]))
return RET_SYN; return RET_SYN;
@ -116,8 +120,6 @@ prod(void)
natp = getnatp(sect.sct_own); natp = getnatp(sect.sct_own);
maxpop = max_pop(natp->nat_level[NAT_RLEV], &sect); maxpop = max_pop(natp->nat_level[NAT_RLEV], &sect);
/* This isn't quite right, since research might rise/fall */
/* during the update, but it's the best we can really do */
work = new_work(&sect, work = new_work(&sect,
total_work(sect.sct_work, etu_per_update, total_work(sect.sct_work, etu_per_update,
civs, sect.sct_item[I_MILIT], uws, civs, sect.sct_item[I_MILIT], uws,
@ -140,8 +142,7 @@ prod(void)
type = sect.sct_newtype; type = sect.sct_newtype;
eff = 0; eff = 0;
} }
if (!eff && IS_BIG_CITY(otype) && if (!eff && IS_BIG_CITY(otype) && !IS_BIG_CITY(type)) {
!IS_BIG_CITY(type)) {
natp = getnatp(sect.sct_own); natp = getnatp(sect.sct_own);
maxpop = max_population(natp->nat_level[NAT_RLEV], maxpop = max_population(natp->nat_level[NAT_RLEV],
type, eff); type, eff);
@ -185,7 +186,34 @@ prod(void)
if (p_e > 1.0) if (p_e > 1.0)
p_e = 1.0; p_e = 1.0;
if (dchr[type].d_prd == 0 && type != SCT_ENLIST) if (type == SCT_ENLIST) {
int maxmil;
int enlisted;
if (sect.sct_own != sect.sct_oldown)
continue;
civs = (1.0 + obrate * etu_per_update) * sect.sct_item[I_CIVIL];
natp = getnatp(sect.sct_own);
maxpop = max_pop(natp->nat_level[NAT_RLEV], &sect);
civs = MIN(civs, maxpop);
enlisted = 0;
maxmil = (civs / 2) - sect.sct_item[I_MILIT];
if (maxmil > 0) {
enlisted = (etu_per_update
* (10 + sect.sct_item[I_MILIT])
* 0.05);
if (enlisted > maxmil)
enlisted = maxmil;
}
if (enlisted < 0)
enlisted = 0;
prprod(&sect, p_e, 1.0, work,
ichr[I_MILIT].i_mnem, enlisted, maxmil, enlisted * 3,
"c\0\0", &enlisted, &enlisted, nsect++);
continue;
}
if (dchr[type].d_prd == 0)
continue; continue;
unit_work = 0; unit_work = 0;
pp = &pchr[dchr[type].d_prd]; pp = &pchr[dchr[type].d_prd];
@ -194,10 +222,6 @@ prod(void)
/* /*
* sect p_e (inc improvements) * sect p_e (inc improvements)
*/ */
if (type == SCT_ENLIST && sect.sct_own != sect.sct_oldown)
continue;
if (type == SCT_ENLIST)
goto is_enlist;
if (pp->p_nrndx != 0) { if (pp->p_nrndx != 0) {
unit_work++; unit_work++;
resource = (unsigned char *)&sect + pp->p_nrndx; resource = (unsigned char *)&sect + pp->p_nrndx;
@ -271,66 +295,47 @@ prod(void)
cmax[i] = (int)(mtake * pp->p_camt[i] + 0.5); cmax[i] = (int)(mtake * pp->p_camt[i] + 0.5);
} }
is_enlist: if (pp->p_type != I_NONE)
mnem = ichr[vtype].i_mnem;
else if (pp->p_level == NAT_TLEV || pp->p_level == NAT_RLEV)
mnem = '.';
else
mnem = 0;
prprod(&sect, p_e, prodeff, work,
mnem, real, maxr, cost,
cmnem, cuse, cmax, nsect++);
}
player->simulation = 0;
if (nsect == 0) {
if (player->argp[1])
pr("%s: No sector(s)\n", player->argp[1]);
else
pr("%s: No sector(s)\n", "");
return RET_FAIL;
} else
pr("%d sector%s\n", nsect, splur(nsect));
return RET_OK;
}
if (nsect++ == 0) { void
prprod(struct sctstr *sp, double p_e, double prodeff, int work,
char mnem, double make, double max, double cost,
char cmnem[], int cuse[], int cmax[], int nsect)
{
int i;
if (nsect == 0) {
pr("PRODUCTION SIMULATION\n"); pr("PRODUCTION SIMULATION\n");
pr(" sect des eff avail make p.e. cost use1 use2 use3 max1 max2 max3 max\n"); pr(" sect des eff avail make p.e. cost use1 use2 use3 max1 max2 max3 max\n");
} }
prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); prxy("%4d,%-4d", sp->sct_x, sp->sct_y, player->cnum);
pr(" %c", dchr[type].d_mnem); pr(" %c %3.0f%% %5d", dchr[sp->sct_type].d_mnem, p_e * 100.0, work);
pr(" %3.0f%%", p_e * 100.0); if (mnem == '.')
pr(" %5d", work); pr(" %5.2f", make);
else
if (vtype != I_NONE) { pr(" %4.0f%c", make, mnem ? mnem : ' ');
pr(" %4d%c", (int)(real + 0.5), ichr[vtype].i_mnem); pr(" %.2f $%-5.0f", prodeff, cost);
} else if (type != SCT_ENLIST) {
switch (pp->p_level) {
case NAT_TLEV:
case NAT_RLEV:
pr(" %5.2f", real);
break;
case NAT_ELEV:
case NAT_HLEV:
pr(" %4.0f ", real);
break;
default:
CANT_REACH();
pr(" ??? ");
break;
}
} else {
int maxmil;
int enlisted;
int civs;
civs = (1.0 + obrate * etu_per_update) * sect.sct_item[I_CIVIL];
natp = getnatp(sect.sct_own);
maxpop = max_pop(natp->nat_level[NAT_RLEV], &sect);
civs = MIN(civs, maxpop);
/* This isn't quite right, since research might
rise/fall during the update, but it's the best
we can really do */
enlisted = 0;
maxmil = (civs / 2) - sect.sct_item[I_MILIT];
if (maxmil > 0) {
enlisted = (etu_per_update
* (10 + sect.sct_item[I_MILIT])
* 0.05);
if (enlisted > maxmil)
enlisted = maxmil;
}
if (enlisted < 0)
enlisted = 0;
pr(" %4d%c 1.00 $%-5d%4dc %4dc %5d\n",
enlisted, ichr[I_MILIT].i_mnem, enlisted * 3,
enlisted, enlisted, maxmil);
continue;
}
pr(" %.2f", prodeff);
pr(" $%-5.0f", cost);
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
if (i < MAXPRCON && cmnem[i]) if (i < MAXPRCON && cmnem[i])
pr("%4d%c", cuse[i], cmnem[i]); pr("%4d%c", cuse[i], cmnem[i]);
@ -344,20 +349,8 @@ prod(void)
else else
pr(" "); pr(" ");
} }
if (vtype != I_NONE || pp->p_level == NAT_ELEV if (mnem == '.')
|| pp->p_level == NAT_HLEV) pr(" %5.2f\n", max);
pr(" %5d\n", MIN(999, (int)(max * prodeff + 0.5)));
else else
pr(" %5.2f\n", maxr); pr(" %5.0f\n", max);
}
player->simulation = 0;
if (nsect == 0) {
if (player->argp[1])
pr("%s: No sector(s)\n", player->argp[1]);
else
pr("%s: No sector(s)\n", "");
return RET_FAIL;
} else
pr("%d sector%s\n", nsect, splur(nsect));
return RET_OK;
} }