2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2016, 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
44 static void prprod(struct sctstr *, double, double, char,
45 double, double, double, char[], int[], int[], int);
54 for (i = 0; NULL != (sp = getsectid(i)); i++) {
57 if (sp->sct_oldown != n)
59 pop += sp->sct_item[I_CIVIL];
69 struct nstr_sect nstr;
74 double material_consume; /* actual production */
77 double max_consume; /* production w/infinite materials */
82 int unit_work; /* sum of component amounts */
83 double mat_limit, worker_limit, res_limit;
86 unsigned char *resource;
88 int cuse[MAXPRCON], cmax[MAXPRCON];
91 if (!snxtsct(&nstr, player->argp[1]))
93 player->simulation = 1;
96 while (nxtsct(&nstr, §)) {
102 natp = getnatp(sect.sct_own);
103 do_feed(§, natp, etu_per_update, 1);
105 if (sect.sct_effic < 60)
108 if (sect.sct_type == SCT_ENLIST) {
112 if (sect.sct_own != sect.sct_oldown)
115 maxmil = sect.sct_item[I_CIVIL] / 2 - sect.sct_item[I_MILIT];
117 enlisted = (etu_per_update
118 * (10 + sect.sct_item[I_MILIT])
120 if (enlisted > maxmil)
125 prprod(§, sect.sct_effic / 100.0, 1.0,
126 ichr[I_MILIT].i_mnem, enlisted, maxmil, enlisted * 3,
127 "c\0\0", &enlisted, &enlisted, nsect++);
131 if (dchr[sect.sct_type].d_prd < 0)
133 pp = &pchr[dchr[sect.sct_type].d_prd];
136 resource = (unsigned char *)§ + pp->p_nrndx;
140 mat_limit = prod_materials_cost(pp, sect.sct_item, &unit_work);
143 p_e = sect.sct_effic / 100.0;
146 p_e *= *resource / 100.0;
151 worker_limit = sect.sct_avail * p_e / (double)unit_work;
152 res_limit = prod_resource_limit(pp, resource);
154 max_consume = res_limit;
155 if (max_consume > worker_limit)
156 max_consume = worker_limit;
157 material_consume = MIN(max_consume, mat_limit);
159 prodeff = prod_eff(sect.sct_type, natp->nat_level[pp->p_nlndx]);
160 real = material_consume * prodeff;
161 maxr = max_consume * prodeff;
163 if (vtype != I_NONE) {
166 real = MIN(999.0, real);
167 maxr = MIN(999.0, maxr);
168 if (CANT_HAPPEN(real < 0.0))
170 if (CANT_HAPPEN(maxr < 0.0))
172 /* production backlog? */
173 there = MIN(ITEM_MAX, sect.sct_item[vtype]);
174 real = MIN(real, ITEM_MAX - there);
178 take = real / prodeff;
179 mtake = maxr / prodeff;
183 cost = take * pp->p_cost;
185 if (pp->p_level == NAT_TLEV) {
186 totpop = count_pop(sect.sct_own);
188 cost *= totpop / 50000.0;
192 for (i = 0; i < MAXPRCON; ++i) {
193 cmnem[i] = cuse[i] = cmax[i] = 0;
197 if (CANT_HAPPEN(it <= I_NONE || I_MAX < it))
199 cmnem[i] = ichr[it].i_mnem;
200 cuse[i] = (int)ceil(take * pp->p_camt[i]);
201 cmax[i] = (int)ceil(mtake * pp->p_camt[i]);
204 if (pp->p_type != I_NONE)
205 mnem = ichr[vtype].i_mnem;
206 else if (pp->p_level == NAT_TLEV || pp->p_level == NAT_RLEV)
210 prprod(§, p_e, prodeff, mnem, real, maxr, cost,
211 cmnem, cuse, cmax, nsect++);
213 player->simulation = 0;
216 pr("%s: No sector(s)\n", player->argp[1]);
218 pr("%s: No sector(s)\n", "");
221 pr("%d sector%s\n", nsect, splur(nsect));
226 prprod(struct sctstr *sp, double p_e, double prodeff,
227 char mnem, double make, double max, double cost,
228 char cmnem[], int cuse[], int cmax[], int nsect)
233 pr("PRODUCTION SIMULATION\n");
234 pr(" sect des eff avail make p.e. cost use1 use2 use3 max1 max2 max3 max\n");
237 prxy("%4d,%-4d", sp->sct_x, sp->sct_y);
238 pr(" %c %3.0f%% %5d",
239 dchr[sp->sct_type].d_mnem, p_e * 100.0, sp->sct_avail);
243 pr(" %4.0f%c", make, mnem ? mnem : ' ');
244 pr(" %.2f $%-5.0f", prodeff, cost);
245 for (i = 0; i < 3; i++) {
246 if (i < MAXPRCON && cmnem[i])
247 pr("%4d%c", cuse[i], cmnem[i]);
252 for (i = 0; i < 3; i++) {
253 if (i < MAXPRCON && cmnem[i])
254 pr("%4d%c", cmax[i], cmnem[i]);