2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, 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
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;
72 double maxr; /* floating version of max */
74 double real; /* floating pt version of act */
77 int act; /* actual production */
80 int max; /* production w/infinite materials */
85 int unit_work; /* sum of component amounts */
86 int used; /* production w/infinite workforce */
91 s_char maxc[MAXPRCON][10];
92 s_char use[MAXPRCON][10];
103 if (!snxtsct(&nstr, player->argp[1]))
105 player->simulation = 1;
108 while (nxtsct(&nstr, §)) {
112 civs = min(9999, (int)((obrate * etu_per_update + 1.0)
113 * sect.sct_item[I_CIVIL]));
114 uws = min(9999, (int)((uwbrate * etu_per_update + 1.0)
115 * sect.sct_item[I_UW]));
117 natp = getnatp(sect.sct_own);
118 maxpop = max_pop((float)natp->nat_level[NAT_RLEV], §);
119 civs = min(civs, maxpop);
120 uws = min(uws, maxpop);
121 } else { /* now RES_POP */
122 civs = min(999, civs);
126 /* This isn't quite right, since research might rise/fall */
127 /* during the update, but it's the best we can really do */
128 wforce = (int)(((double)civs * sect.sct_work) / 100.0
130 + sect.sct_item[I_MILIT] * 2.0 / 5.0);
131 work = new_work(§, wforce * etu_per_update / 100);
136 type = sect.sct_type;
137 eff = sect.sct_effic;
138 if (sect.sct_newtype != type) {
139 twork = (eff + 3) / 4;
147 type = sect.sct_newtype;
151 if (!eff && dchr[otype].d_pkg == UPKG &&
152 dchr[type].d_pkg != UPKG) {
154 natp = getnatp(sect.sct_own);
156 max_pop(natp->nat_level[NAT_RLEV], 0));
158 max_pop(natp->nat_level[NAT_RLEV], 0));
160 civs = min(9999, civs);
161 uws = min(9999, uws);
163 wforce = (int)(((double)civs * sect.sct_work) / 100.0
165 + sect.sct_item[I_MILIT] * 2 / 5.0);
166 work = etu_per_update * wforce / 100;
167 bwork = min((int)(work / 2), bwork);
174 if (dchr[type].d_lcms > 0) {
175 lcms = sect.sct_item[I_LCM];
176 lcms /= dchr[type].d_lcms;
180 if (dchr[type].d_hcms > 0) {
181 hcms = sect.sct_item[I_HCM];
182 hcms /= dchr[type].d_hcms;
188 } else if (eff < 100) {
196 work = (work + 1) / 2 + bwork;
197 if (eff < 60 || (type != SCT_ENLIST && eff < 61))
204 if (dchr[type].d_prd == 0 && type != SCT_ENLIST)
207 pp = &pchr[dchr[type].d_prd];
209 natp = getnatp(sect.sct_own);
211 * sect p_e (inc improvements)
213 if (type == SCT_ENLIST && sect.sct_own != sect.sct_oldown)
215 if (type == SCT_ENLIST)
217 if (pp->p_nrndx != 0) {
219 resource = ((s_char *)§) + pp->p_nrndx;
220 p_e = (*resource * p_e) / 100.0;
225 prodeff = prod_eff(pp, natp->nat_level[pp->p_nlndx]);
230 for (j = 0; j < MAXPRCON; ++j) {
234 if (CANT_HAPPEN(it <= I_NONE || I_MAX < it))
236 used = min(used, sect.sct_item[it] / pp->p_camt[j]);
237 unit_work += pp->p_camt[j];
242 * is production limited by resources or
245 max = (int)(work * p_e / (double)unit_work + 0.5);
246 act = min(used, max);
248 real = dmin(999.0, (double)act * prodeff);
249 maxr = dmin(999.0, (double)max * prodeff);
251 if (vtype != I_NONE) {
254 /* production backlog? */
255 there = min(ITEM_MAX, sect.sct_item[vtype]);
256 real = dmin(real, ITEM_MAX - there);
260 take = real / prodeff;
261 mtake = maxr / prodeff;
265 cost = (int)(take * (double)pp->p_cost);
267 if (pp->p_level == NAT_TLEV) {
268 totpop = count_pop(sect.sct_own);
270 cost = (int)((double)cost * (double)totpop / 50000.0);
275 for (j = 0; j < MAXPRCON; ++j) {
277 if (it > I_NONE && it <= I_MAX && ichr[it].i_name != 0) {
278 if (CANT_HAPPEN(i >= 3))
280 sprintf(use[i], " %3d%c",
281 (int)((take * (double)pp->p_camt[j]) + 0.5),
283 sprintf(maxc[i], " %3d%c",
284 (int)((mtake * (double)pp->p_camt[j]) + 0.5),
291 strcpy(maxc[i], " ");
298 pr("PRODUCTION SIMULATION\n");
299 pr(" sect des eff wkfc will make- p.e. cost use1 use2 use3 max1 max2 max3 max\n");
302 prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
303 pr(" %c", dchr[type].d_mnem);
304 pr(" %3.0f%%", p_e * 100.0);
307 if (vtype != I_NONE) {
308 pr(" %4d", (int)(real + 0.5));
309 } else if (type != SCT_ENLIST) {
310 switch (pp->p_level) {
328 civs = min(999, (int)((obrate * etu_per_update + 1.0)
329 * sect.sct_item[I_CIVIL]));
330 natp = getnatp(sect.sct_own);
331 maxpop = max_pop((float)natp->nat_level[NAT_RLEV], §);
332 civs = min(civs, maxpop);
333 /* This isn't quite right, since research might
334 rise/fall during the update, but it's the best
337 maxmil = (civs / 2) - sect.sct_item[I_MILIT];
339 enlisted = (etu_per_update
340 * (10 + sect.sct_item[I_MILIT])
342 if (enlisted > maxmil)
347 if (natp->nat_priorities[type] == 0) {
350 pr(" %4d mil 1.00 $%-5d%3dc",
351 enlisted, enlisted * 3, enlisted);
357 pr(" %-5.5s", pp->p_sname);
358 pr(" %.2f", prodeff);
360 for (i = 0; i < 3; i++) {
364 for (i = 0; i < 3; i++) {
367 if (natp->nat_priorities[type] == 0) {
371 if (vtype != I_NONE || pp->p_level == NAT_ELEV
372 || pp->p_level == NAT_HLEV)
373 pr(" %4d\n", min(999, (int)(max * prodeff + 0.5)));
375 pr(" %1.2f\n", maxr);
377 player->simulation = 0;
380 pr("%s: No sector(s)\n", player->argp[1]);
382 pr("%s: No sector(s)\n", "");
385 pr("%d sector%s\n", nsect, splur(nsect));