2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program 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 2 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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * prod.c: Calculate production levels
30 * Known contributors to this file:
31 * David Muir Sharnoff, 1987
32 * Steve McClure, 1997-2000
49 count_pop(register int n)
55 for (i = 0; NULL != (sp = getsectid(i)); i++) {
58 if (sp->sct_oldown != n)
60 pop += sp->sct_item[I_CIVIL];
70 struct nstr_sect nstr;
73 double maxr; /* floating version of max */
76 double real; /* floating pt version of act */
79 int act; /* actual production */
82 int max; /* production w/infinate materials */
88 int unit_work; /* sum of component amounts */
89 int used; /* production w/infinite workforce */
92 u_short *amount; /* amount for component pointer */
93 u_char *comp; /* component pointer */
110 if (!snxtsct(&nstr, player->argp[1]))
112 player->simulation = 1;
115 while (nxtsct(&nstr, §)) {
119 civs = min(9999, (int)((obrate * etu_per_update + 1.0)
120 * sect.sct_item[I_CIVIL]));
121 uws = min(9999, (int)((uwbrate * etu_per_update + 1.0)
122 * sect.sct_item[I_UW]));
124 natp = getnatp(sect.sct_own);
125 maxpop = max_pop((float)natp->nat_level[NAT_RLEV], §);
126 civs = min(civs, maxpop);
127 uws = min(uws, maxpop);
128 } else { /* now RES_POP */
129 civs = min(999, civs);
133 /* This isn't quite right, since research might rise/fall */
134 /* during the update, but it's the best we can really do */
135 wforce = (int)(((double)civs * sect.sct_work) / 100.0
137 + sect.sct_item[I_MILIT] * 2.0 / 5.0);
138 work = new_work(§, wforce * etu_per_update / 100);
143 type = sect.sct_type;
144 eff = sect.sct_effic;
145 if (sect.sct_newtype != type) {
146 twork = (eff + 3) / 4;
154 type = sect.sct_newtype;
158 if (!eff && dchr[otype].d_pkg == UPKG &&
159 dchr[type].d_pkg != UPKG) {
161 natp = getnatp(sect.sct_own);
164 max_pop(natp->nat_level[NAT_RLEV], 0));
167 max_pop(natp->nat_level[NAT_RLEV], 0));
169 civs = min(9999, civs);
170 uws = min(9999, uws);
172 wforce = (int)(((double)civs * sect.sct_work) / 100.0
174 + sect.sct_item[I_MILIT] * 2 / 5.0);
175 work = etu_per_update * wforce / 100.0;
176 bwork = min((int)(work / 2), bwork);
183 if (dchr[type].d_lcms > 0) {
184 lcms = sect.sct_item[I_LCM];
185 lcms /= dchr[type].d_lcms;
189 if (dchr[type].d_hcms > 0) {
190 hcms = sect.sct_item[I_HCM];
191 hcms /= dchr[type].d_hcms;
197 } else if (eff < 100) {
205 work = (work + 1) / 2 + bwork;
206 if (eff < 60 || (type != SCT_ENLIST && eff < 61))
213 if (dchr[type].d_prd == 0 && type != SCT_ENLIST)
216 pp = &pchr[dchr[type].d_prd];
218 natp = getnatp(sect.sct_own);
220 * sect p_e (inc improvements)
222 if (type == SCT_ENLIST && sect.sct_own != sect.sct_oldown)
224 if (type == SCT_ENLIST)
226 if (pp->p_nrndx != 0) {
228 resource = ((s_char *)§) + pp->p_nrndx;
229 p_e = (*resource * p_e) / 100.0;
230 if (pp->p_nrdep > 0) {
231 maxtake = (*resource * 100.0) / pp->p_nrdep;
239 if (pp->p_nlndx >= 0) {
240 level_p_e = natp->nat_level[pp->p_nlndx] - pp->p_nlmin;
241 if (level_p_e < 0.0) {
244 level_p_e = level_p_e / (level_p_e + pp->p_nllag);
250 endcomp = pp->p_vtype + pp->p_nv;
252 while (comp < endcomp) {
256 used = min(used, sect.sct_item[(int)*comp] / *amount);
257 unit_work += *amount;
265 * is production limited by resources or
268 max = (int)((work * p_e / (double)unit_work) + 0.5);
269 act = min(used, max);
271 * some things are easier to make.. food,
274 act = (int)(((double)pp->p_effic * 0.01 * (double)act) + 0.5);
275 max = (int)(((double)pp->p_effic * 0.01 * (double)max) + 0.5);
277 real = (double)act * level_p_e;
278 maxr = (double)max * level_p_e;
283 /* production backlog? */
284 there = min(ITEM_MAX, sect.sct_item[vtype]);
285 act = min(act, ITEM_MAX - there);
286 max = min(max, ITEM_MAX - there);
289 if (level_p_e != 0) {
290 take = real / level_p_e;
291 mtake = maxr / level_p_e;
300 take = (double)take / ((double)pp->p_effic * 0.01);
301 mtake = (double)mtake / ((double)pp->p_effic * 0.01);
303 cost = (int)(take * (double)pp->p_cost);
305 if (pp->p_level == NAT_TLEV) {
306 totpop = count_pop(sect.sct_own);
308 cost = (int)((double)cost * (double)totpop / 50000.0);
315 while (comp < endcomp) {
316 it = unitem((int)*comp);
317 if (it > 0 && it <= I_MAX && ichr[it].i_name != 0)
318 c = ichr[it].i_name[0];
321 (void)sprintf(use[i], " %3d%c",
322 (int)((take * (double)(*amount)) + 0.5), c);
323 (void)sprintf(maxc[i], " %3d%c",
324 (int)((mtake * (double)(*amount)) + 0.5), c);
331 strcpy(maxc[i], " ");
338 pr("PRODUCTION SIMULATION\n");
339 pr(" sect des eff wkfc will make- p.e. cost use1 use2 use3 max1 max2 max3 max\n");
342 prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
343 pr(" %c", dchr[type].d_mnem);
344 pr(" %3.0f%%", p_e * 100.0);
348 pr(" %4d", (int)(real + 0.5));
349 } else if (type != SCT_ENLIST) {
350 switch (pp->p_level) {
368 civs = min(999, (int)((obrate * etu_per_update + 1.0)
369 * sect.sct_item[I_CIVIL]));
370 natp = getnatp(sect.sct_own);
371 maxpop = max_pop((float)natp->nat_level[NAT_RLEV], §);
372 civs = min(civs, maxpop);
373 /* This isn't quite right, since research might
374 rise/fall during the update, but it's the best
377 maxmil = (civs / 2) - sect.sct_item[I_MILIT];
379 enlisted = (etu_per_update
380 * (10 + sect.sct_item[I_MILIT])
382 if (enlisted > maxmil)
387 if (natp->nat_priorities[type] == 0) {
390 pr(" %4d mil 1.00 $%-5d%3dc",
391 enlisted, enlisted * 3, enlisted);
397 pr(" %-5.5s", pp->p_sname);
398 prodeff = level_p_e * (double)pp->p_effic * 0.01;
399 pr(" %.2f", prodeff);
401 for (i = 0; i < 3; i++) {
405 for (i = 0; i < 3; i++) {
408 if (natp->nat_priorities[type] == 0) {
412 if (vtype != 0 || pp->p_level == NAT_ELEV
413 || pp->p_level == NAT_HLEV)
414 pr(" %4d\n", min(999, (int)(max * prodeff + 0.05)));
416 pr(" %1.2f\n", maxr);
418 player->simulation = 0;
421 pr("%s: No sector(s)\n", player->argp[1]);
423 pr("%s: No sector(s)\n", "");
426 pr("%d sector%s\n", nsect, splur(nsect));