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 */
87 int unit_work; /* sum of component amounts */
88 int used; /* production w/infinite workforce */
91 u_short *amount; /* amount for component pointer */
92 u_char *comp; /* component pointer */
109 if (!snxtsct(&nstr, player->argp[1]))
111 player->simulation = 1;
114 while (nxtsct(&nstr, §)) {
118 civs = min(9999, (int)((obrate * etu_per_update + 1.0)
119 * sect.sct_item[I_CIVIL]));
120 uws = min(9999, (int)((uwbrate * etu_per_update + 1.0)
121 * sect.sct_item[I_UW]));
123 natp = getnatp(sect.sct_own);
124 maxpop = max_pop((float)natp->nat_level[NAT_RLEV], §);
125 civs = min(civs, maxpop);
126 uws = min(uws, maxpop);
127 } else { /* now RES_POP */
128 civs = min(999, civs);
132 /* This isn't quite right, since research might rise/fall */
133 /* during the update, but it's the best we can really do */
134 wforce = (int)(((double)civs * sect.sct_work) / 100.0
136 + sect.sct_item[I_MILIT] * 2.0 / 5.0);
137 work = new_work(§, wforce * etu_per_update / 100);
142 type = sect.sct_type;
143 eff = sect.sct_effic;
144 if (sect.sct_newtype != type) {
145 twork = (eff + 3) / 4;
153 type = sect.sct_newtype;
157 if (!eff && dchr[otype].d_pkg == UPKG &&
158 dchr[type].d_pkg != UPKG) {
160 natp = getnatp(sect.sct_own);
162 max_pop(natp->nat_level[NAT_RLEV], 0));
164 max_pop(natp->nat_level[NAT_RLEV], 0));
166 civs = min(9999, civs);
167 uws = min(9999, uws);
169 wforce = (int)(((double)civs * sect.sct_work) / 100.0
171 + sect.sct_item[I_MILIT] * 2 / 5.0);
172 work = etu_per_update * wforce / 100;
173 bwork = min((int)(work / 2), bwork);
180 if (dchr[type].d_lcms > 0) {
181 lcms = sect.sct_item[I_LCM];
182 lcms /= dchr[type].d_lcms;
186 if (dchr[type].d_hcms > 0) {
187 hcms = sect.sct_item[I_HCM];
188 hcms /= dchr[type].d_hcms;
194 } else if (eff < 100) {
202 work = (work + 1) / 2 + bwork;
203 if (eff < 60 || (type != SCT_ENLIST && eff < 61))
210 if (dchr[type].d_prd == 0 && type != SCT_ENLIST)
213 pp = &pchr[dchr[type].d_prd];
215 natp = getnatp(sect.sct_own);
217 * sect p_e (inc improvements)
219 if (type == SCT_ENLIST && sect.sct_own != sect.sct_oldown)
221 if (type == SCT_ENLIST)
223 if (pp->p_nrndx != 0) {
225 resource = ((s_char *)§) + pp->p_nrndx;
226 p_e = (*resource * p_e) / 100.0;
231 if (pp->p_nlndx >= 0) {
232 level_p_e = natp->nat_level[pp->p_nlndx] - pp->p_nlmin;
233 if (level_p_e < 0.0) {
236 level_p_e = level_p_e / (level_p_e + pp->p_nllag);
245 endcomp = pp->p_vtype + pp->p_nv;
246 for (comp = pp->p_vtype; comp < endcomp; comp++, amount++) {
249 used = min(used, sect.sct_item[(int)*comp] / *amount);
250 unit_work += *amount;
255 * is production limited by resources or
258 max = (int)(work * p_e / (double)unit_work + 0.5);
259 act = min(used, max);
261 * some things are easier to make.. food,
264 act = (int)(((double)pp->p_effic * 0.01 * (double)act) + 0.5);
265 max = (int)(((double)pp->p_effic * 0.01 * (double)max) + 0.5);
267 real = dmin(999.0, (double)act * level_p_e);
268 maxr = dmin(999.0, (double)max * level_p_e);
273 /* production backlog? */
274 there = min(ITEM_MAX, sect.sct_item[vtype]);
275 real = dmin(real, ITEM_MAX - there);
278 if (level_p_e != 0) {
279 take = real / level_p_e;
280 mtake = maxr / level_p_e;
284 take = (double)take / ((double)pp->p_effic * 0.01);
285 mtake = (double)mtake / ((double)pp->p_effic * 0.01);
287 cost = (int)(take * (double)pp->p_cost);
289 if (pp->p_level == NAT_TLEV) {
290 totpop = count_pop(sect.sct_own);
292 cost = (int)((double)cost * (double)totpop / 50000.0);
299 while (comp < endcomp) {
300 it = unitem((int)*comp);
301 if (it > 0 && it <= I_MAX && ichr[it].i_name != 0)
302 c = ichr[it].i_name[0];
305 (void)sprintf(use[i], " %3d%c",
306 (int)((take * (double)(*amount)) + 0.5), c);
307 (void)sprintf(maxc[i], " %3d%c",
308 (int)((mtake * (double)(*amount)) + 0.5), c);
315 strcpy(maxc[i], " ");
322 pr("PRODUCTION SIMULATION\n");
323 pr(" sect des eff wkfc will make- p.e. cost use1 use2 use3 max1 max2 max3 max\n");
326 prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
327 pr(" %c", dchr[type].d_mnem);
328 pr(" %3.0f%%", p_e * 100.0);
332 pr(" %4d", (int)(real + 0.5));
333 } else if (type != SCT_ENLIST) {
334 switch (pp->p_level) {
352 civs = min(999, (int)((obrate * etu_per_update + 1.0)
353 * sect.sct_item[I_CIVIL]));
354 natp = getnatp(sect.sct_own);
355 maxpop = max_pop((float)natp->nat_level[NAT_RLEV], §);
356 civs = min(civs, maxpop);
357 /* This isn't quite right, since research might
358 rise/fall during the update, but it's the best
361 maxmil = (civs / 2) - sect.sct_item[I_MILIT];
363 enlisted = (etu_per_update
364 * (10 + sect.sct_item[I_MILIT])
366 if (enlisted > maxmil)
371 if (natp->nat_priorities[type] == 0) {
374 pr(" %4d mil 1.00 $%-5d%3dc",
375 enlisted, enlisted * 3, enlisted);
381 pr(" %-5.5s", pp->p_sname);
382 prodeff = level_p_e * (double)pp->p_effic * 0.01;
383 pr(" %.2f", prodeff);
385 for (i = 0; i < 3; i++) {
389 for (i = 0; i < 3; i++) {
392 if (natp->nat_priorities[type] == 0) {
396 if (vtype != 0 || pp->p_level == NAT_ELEV
397 || pp->p_level == NAT_HLEV)
398 pr(" %4d\n", min(999, (int)(max * prodeff + 0.05)));
400 pr(" %1.2f\n", maxr);
402 player->simulation = 0;
405 pr("%s: No sector(s)\n", player->argp[1]);
407 pr("%s: No sector(s)\n", "");
410 pr("%d sector%s\n", nsect, splur(nsect));