2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * prod.c: Calculate production levels
29 * Known contributors to this file:
30 * David Muir Sharnoff, 1987
31 * Steve McClure, 1997-2000
32 * Markus Armbruster, 2004-2016
46 static void prprod(struct sctstr *, double, double, char,
47 double, double, double, char[], int[], int[], int);
52 /* FIXME don't duplicate the update's workings, use its code */
59 for (i = 0; (sectp = getsectid(i)); i++) {
60 if (sectp->sct_own == player->cnum) {
61 if (sectp->sct_own == sectp->sct_oldown)
62 pop += sectp->sct_item[I_CIVIL];
66 for (i = 0; (sp = getshipp(i)); i++) {
67 if (sp->shp_own == player->cnum)
68 pop += sp->shp_item[I_CIVIL];
71 for (i = 0; (lp = getlandp(i)); i++) {
72 if (lp->lnd_own == player->cnum)
73 pop += lp->lnd_item[I_CIVIL];
83 struct sctstr sect, scratch_sect;
84 struct nstr_sect nstr;
95 unsigned char *resource;
97 int cuse[MAXPRCON], cmax[MAXPRCON];
100 if (!snxtsct(&nstr, player->argp[1]))
102 player->simulation = 1;
105 while (nxtsct(&nstr, §)) {
111 natp = getnatp(sect.sct_own);
112 do_feed(§, natp, etu_per_update, 1);
114 if (sect.sct_effic < 60)
117 if (sect.sct_type == SCT_ENLIST) {
121 if (sect.sct_own != sect.sct_oldown)
124 maxmil = sect.sct_item[I_CIVIL] / 2 - sect.sct_item[I_MILIT];
126 enlisted = (etu_per_update
127 * (10 + sect.sct_item[I_MILIT])
129 if (enlisted > maxmil)
134 prprod(§, sect.sct_effic / 100.0, 1.0,
135 ichr[I_MILIT].i_mnem, enlisted, maxmil, enlisted * 3,
136 "c\0\0", &enlisted, &enlisted, nsect++);
140 if (dchr[sect.sct_type].d_prd < 0)
142 pp = &pchr[dchr[sect.sct_type].d_prd];
144 resource = (unsigned char *)§ + pp->p_nrndx;
149 p_e = sect.sct_effic / 100.0;
151 p_e *= *resource / 100.0;
153 prodeff = prod_eff(sect.sct_type, natp->nat_level[pp->p_nlndx]);
156 real = prod_output(&scratch_sect, prodeff);
159 for (i = 0; i < MAXPRCON; ++i)
160 scratch_sect.sct_item[pp->p_ctype[i]] = ITEM_MAX;
161 scratch_sect.sct_item[pp->p_type] = 0;
162 maxr = prod_output(&scratch_sect, prodeff);
165 take = real / prodeff;
166 mtake = maxr / prodeff;
170 cost = take * pp->p_cost;
172 if (pp->p_level == NAT_TLEV) {
174 totpop = count_pop();
176 cost *= totpop / 50000.0;
180 for (i = 0; i < MAXPRCON; ++i) {
181 cmnem[i] = cuse[i] = cmax[i] = 0;
185 if (CANT_HAPPEN(it <= I_NONE || I_MAX < it))
187 cmnem[i] = ichr[it].i_mnem;
188 cuse[i] = (int)ceil(take * pp->p_camt[i]);
189 cmax[i] = (int)ceil(mtake * pp->p_camt[i]);
192 if (pp->p_type != I_NONE)
193 mnem = ichr[pp->p_type].i_mnem;
194 else if (pp->p_level == NAT_TLEV || pp->p_level == NAT_RLEV)
198 prprod(§, p_e, prodeff, mnem, real, maxr, cost,
199 cmnem, cuse, cmax, nsect++);
201 player->simulation = 0;
204 pr("%s: No sector(s)\n", player->argp[1]);
206 pr("%s: No sector(s)\n", "");
209 pr("%d sector%s\n", nsect, splur(nsect));
214 prprod(struct sctstr *sp, double p_e, double prodeff,
215 char mnem, double make, double max, double cost,
216 char cmnem[], int cuse[], int cmax[], int nsect)
221 pr("PRODUCTION SIMULATION\n");
222 pr(" sect des eff avail make p.e. cost use1 use2 use3 max1 max2 max3 max\n");
225 prxy("%4d,%-4d", sp->sct_x, sp->sct_y);
226 pr(" %c %3.0f%% %5d",
227 dchr[sp->sct_type].d_mnem, p_e * 100.0, sp->sct_avail);
231 pr(" %4.0f%c", make, mnem ? mnem : ' ');
232 pr(" %.2f $%-5.0f", prodeff, cost);
233 for (i = 0; i < 3; i++) {
234 if (i < MAXPRCON && cmnem[i])
235 pr("%4d%c", cuse[i], cmnem[i]);
240 for (i = 0; i < 3; i++) {
241 if (i < MAXPRCON && cmnem[i])
242 pr("%4d%c", cmax[i], cmnem[i]);