(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:
parent
32e4fbd284
commit
08937006d7
1 changed files with 81 additions and 88 deletions
|
@ -47,6 +47,9 @@
|
|||
#include "optlist.h"
|
||||
#include "commands.h"
|
||||
|
||||
static void prprod(struct sctstr *, double, double, int, char,
|
||||
double, double, double, char[], int[], int[], int);
|
||||
|
||||
int
|
||||
count_pop(int n)
|
||||
{
|
||||
|
@ -93,14 +96,15 @@ prod(void)
|
|||
char cmnem[MAXPRCON];
|
||||
int cuse[MAXPRCON], cmax[MAXPRCON];
|
||||
int lcms, hcms;
|
||||
int civs = 0;
|
||||
int uws = 0;
|
||||
int civs;
|
||||
int uws;
|
||||
int bwork;
|
||||
int twork;
|
||||
int type;
|
||||
int eff;
|
||||
int maxpop;
|
||||
int otype;
|
||||
char mnem;
|
||||
|
||||
if (!snxtsct(&nstr, player->argp[1]))
|
||||
return RET_SYN;
|
||||
|
@ -116,8 +120,6 @@ prod(void)
|
|||
natp = getnatp(sect.sct_own);
|
||||
maxpop = max_pop(natp->nat_level[NAT_RLEV], §);
|
||||
|
||||
/* 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(§,
|
||||
total_work(sect.sct_work, etu_per_update,
|
||||
civs, sect.sct_item[I_MILIT], uws,
|
||||
|
@ -140,8 +142,7 @@ prod(void)
|
|||
type = sect.sct_newtype;
|
||||
eff = 0;
|
||||
}
|
||||
if (!eff && IS_BIG_CITY(otype) &&
|
||||
!IS_BIG_CITY(type)) {
|
||||
if (!eff && IS_BIG_CITY(otype) && !IS_BIG_CITY(type)) {
|
||||
natp = getnatp(sect.sct_own);
|
||||
maxpop = max_population(natp->nat_level[NAT_RLEV],
|
||||
type, eff);
|
||||
|
@ -185,7 +186,34 @@ prod(void)
|
|||
if (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], §);
|
||||
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(§, 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;
|
||||
unit_work = 0;
|
||||
pp = &pchr[dchr[type].d_prd];
|
||||
|
@ -194,10 +222,6 @@ prod(void)
|
|||
/*
|
||||
* 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) {
|
||||
unit_work++;
|
||||
resource = (unsigned char *)§ + pp->p_nrndx;
|
||||
|
@ -271,84 +295,15 @@ prod(void)
|
|||
cmax[i] = (int)(mtake * pp->p_camt[i] + 0.5);
|
||||
}
|
||||
|
||||
is_enlist:
|
||||
|
||||
if (nsect++ == 0) {
|
||||
pr("PRODUCTION SIMULATION\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);
|
||||
pr(" %c", dchr[type].d_mnem);
|
||||
pr(" %3.0f%%", p_e * 100.0);
|
||||
pr(" %5d", work);
|
||||
|
||||
if (vtype != I_NONE) {
|
||||
pr(" %4d%c", (int)(real + 0.5), ichr[vtype].i_mnem);
|
||||
} 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], §);
|
||||
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++) {
|
||||
if (i < MAXPRCON && cmnem[i])
|
||||
pr("%4d%c", cuse[i], cmnem[i]);
|
||||
else
|
||||
pr(" ");
|
||||
}
|
||||
pr(" ");
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (i < MAXPRCON && cmnem[i])
|
||||
pr("%4d%c", cmax[i], cmnem[i]);
|
||||
else
|
||||
pr(" ");
|
||||
}
|
||||
if (vtype != I_NONE || pp->p_level == NAT_ELEV
|
||||
|| pp->p_level == NAT_HLEV)
|
||||
pr(" %5d\n", MIN(999, (int)(max * prodeff + 0.5)));
|
||||
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
|
||||
pr(" %5.2f\n", maxr);
|
||||
mnem = 0;
|
||||
prprod(§, p_e, prodeff, work,
|
||||
mnem, real, maxr, cost,
|
||||
cmnem, cuse, cmax, nsect++);
|
||||
}
|
||||
player->simulation = 0;
|
||||
if (nsect == 0) {
|
||||
|
@ -361,3 +316,41 @@ prod(void)
|
|||
pr("%d sector%s\n", nsect, splur(nsect));
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
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(" sect des eff avail make p.e. cost use1 use2 use3 max1 max2 max3 max\n");
|
||||
}
|
||||
|
||||
prxy("%4d,%-4d", sp->sct_x, sp->sct_y, player->cnum);
|
||||
pr(" %c %3.0f%% %5d", dchr[sp->sct_type].d_mnem, p_e * 100.0, work);
|
||||
if (mnem == '.')
|
||||
pr(" %5.2f", make);
|
||||
else
|
||||
pr(" %4.0f%c", make, mnem ? mnem : ' ');
|
||||
pr(" %.2f $%-5.0f", prodeff, cost);
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (i < MAXPRCON && cmnem[i])
|
||||
pr("%4d%c", cuse[i], cmnem[i]);
|
||||
else
|
||||
pr(" ");
|
||||
}
|
||||
pr(" ");
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (i < MAXPRCON && cmnem[i])
|
||||
pr("%4d%c", cmax[i], cmnem[i]);
|
||||
else
|
||||
pr(" ");
|
||||
}
|
||||
if (mnem == '.')
|
||||
pr(" %5.2f\n", max);
|
||||
else
|
||||
pr(" %5.0f\n", max);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue