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)
56 for (i = 0; NULL != (sp = getsectid(i)); i++) {
59 if (sp->sct_oldown != n)
61 if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0)
71 extern double obrate, uwbrate;
72 extern int etu_per_update;
75 struct nstr_sect nstr;
78 double maxr; /* floating version of max */
80 double real; /* floating pt version of act */
83 int act; /* actual production */
86 int max; /* production w/infinate materials */
92 int totcomp; /* sum of component amounts */
93 int used; /* production w/infinite workforce */
96 u_short *amount; /* amount for component pointer */
97 u_char *comp; /* component pointer */
104 int items[I_MAX + 1];
105 int vec[I_MAX + 1], lcms, hcms;
115 if (!snxtsct(&nstr, player->argp[1]))
117 player->simulation = 1;
120 while (nxtsct(&nstr, §)) {
123 getvec(VT_ITEM, items, (s_char *)§, EF_SECTOR);
125 civs = min(9999, (int)((obrate * (double)etu_per_update + 1.0)
126 * (double)items[I_CIVIL]));
127 uws = min(9999, (int)((uwbrate * (double)etu_per_update + 1.0)
128 * (double)items[I_UW]));
130 natp = getnatp(sect.sct_own);
131 maxpop = max_pop((float)natp->nat_level[NAT_RLEV], §);
132 civs = min(civs, maxpop);
133 uws = min(uws, maxpop);
134 } else { /* now RES_POP */
135 civs = min(999, civs);
139 /* This isn't quite right, since research might rise/fall */
140 /* during the update, but it's the best we can really do */
141 wforce = (int)(((double)civs * (double)sect.sct_work)
142 / 100.0 + (double)uws +
143 (double)items[I_MILIT] * 2.0 / 5.0);
144 work = (double)etu_per_update *(double)wforce / 100.0;
145 if (opt_ROLLOVER_AVAIL) {
146 if (sect.sct_type == sect.sct_newtype) {
147 work += sect.sct_avail;
149 if (work > 999) work = 999;
151 bwork = (int)((double)work / 2.0);
155 type = sect.sct_type;
156 eff = sect.sct_effic;
157 if (sect.sct_newtype != type) {
158 twork = (eff + 3) / 4;
166 type = sect.sct_newtype;
170 if (!eff && dchr[otype].d_pkg == UPKG &&
171 dchr[type].d_pkg != UPKG) {
173 natp = getnatp(sect.sct_own);
176 max_pop(natp->nat_level[NAT_RLEV], 0));
179 max_pop(natp->nat_level[NAT_RLEV], 0));
181 civs = min(9999, civs);
182 uws = min(9999, uws);
185 (int)((civs * sect.sct_work) / 100.0 + uws +
186 items[I_MILIT] * 2 / 5.0);
187 work = etu_per_update * wforce / 100.0;
188 bwork = min((int)(work / 2), bwork);
195 getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);
196 if (dchr[type].d_lcms > 0) {
198 lcms /= dchr[type].d_lcms;
202 if (dchr[type].d_hcms > 0) {
204 hcms /= dchr[type].d_hcms;
210 } else if (eff < 100) {
218 work = work / 2 + bwork;
219 if (eff < 60 || (type != SCT_ENLIST && eff < 61))
226 if (dchr[type].d_prd == 0 && type != SCT_ENLIST)
229 pp = &pchr[dchr[type].d_prd];
231 natp = getnatp(sect.sct_own);
233 * sect effic (inc improvements)
235 if (type == SCT_ENLIST && sect.sct_own != sect.sct_oldown)
237 if (type == SCT_ENLIST)
239 if (pp->p_nrndx != 0) {
241 resource = ((s_char *)§) + pp->p_nrndx;
242 effic = (*resource * effic) / 100.0;
243 if (pp->p_nrdep > 0) {
244 maxtake = (*resource * 100.0) / pp->p_nrdep;
252 if (pp->p_nlndx >= 0) {
253 prodeff = natp->nat_level[pp->p_nlndx] - pp->p_nlmin;
257 prodeff = prodeff / (prodeff + pp->p_nllag);
263 endcomp = pp->p_vtype + pp->p_nv;
265 while (comp < endcomp) {
269 used = min(used, (int)(getvar((int)*comp, (s_char *)§,
270 EF_SECTOR) / *amount));
279 * is production limited by resources or
282 max = (int)(work * effic / (double)totcomp) + 0.5;
283 act = min(used, max);
285 * some things are easier to make.. food,
288 act = (int)(((double)pp->p_effic * 0.01 * (double)act) + 0.5);
289 max = (int)(((double)pp->p_effic * 0.01 * (double)max) + 0.5);
291 real = (double)act *(double)prodeff;
292 maxr = (double)max *(double)prodeff;
297 /* production backlog? */
299 getvar((int)vtype, (s_char *)§, EF_SECTOR)) >= 9999) {
302 act = min(act, (9999 - there));
303 max = min(max, (9999 - there));
307 take = real / prodeff;
308 mtake = maxr / prodeff;
317 take = (double)take / ((double)pp->p_effic * 0.01);
318 mtake = (double)mtake / ((double)pp->p_effic * 0.01);
320 cost = (int)(take * (double)pp->p_cost);
322 if (pp->p_level == NAT_TLEV) {
323 totpop = count_pop(sect.sct_own);
325 cost = (int)((double)cost * (double)totpop / 50000.0);
332 while (comp < endcomp) {
333 it = unitem((int)*comp);
334 if (it > 0 && it <= I_MAX && ichr[it].i_name != 0)
335 c = ichr[it].i_name[0];
338 (void)sprintf(use[i], " %3d%c",
339 (int)((take * (double)(*amount)) + 0.5), c);
340 (void)sprintf(maxc[i], " %3d%c",
341 (int)((mtake * (double)(*amount)) + 0.5), c);
348 strcpy(maxc[i], " ");
355 pr("PRODUCTION SIMULATION\n");
356 pr(" sect des eff wkfc will make- p.e. cost use1 use2 use3 max1 max2 max3 max\n");
359 prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
360 pr(" %c", dchr[type].d_mnem);
361 pr(" %3.0f%%", effic * 100.0);
365 pr(" %4d", (int)(real + 0.5));
366 } else if (type != SCT_ENLIST) {
367 switch (pp->p_level) {
385 civs = min(999, (int)((obrate * (double)etu_per_update + 1.0)
386 * (double)items[I_CIVIL]));
387 natp = getnatp(sect.sct_own);
388 maxpop = max_pop((float)natp->nat_level[NAT_RLEV], §);
389 civs = min(civs, maxpop);
390 /* This isn't quite right, since research might
391 rise/fall during the update, but it's the best
394 maxmil = (civs / 2) - items[I_MILIT];
396 enlisted = (etu_per_update * (10 + items[I_MILIT]) * 0.05);
397 if (enlisted > maxmil)
402 if (natp->nat_priorities[type] == 0) {
405 pr(" %4d mil 1.00 $%-5d%3dc",
406 enlisted, enlisted * 3, enlisted);
408 enlisted, maxmil, maxmil);
412 pr(" %-5.5s", pp->p_sname);
413 prodeff = prodeff * (double)pp->p_effic * 0.01;
414 pr(" %.2f", prodeff);
416 for (i = 0; i < 3; i++) {
420 for (i = 0; i < 3; i++) {
423 if (natp->nat_priorities[type] == 0) {
427 if (vtype != 0 || pp->p_level == NAT_ELEV
428 || pp->p_level == NAT_HLEV)
429 pr(" %4d\n", min(999, (int)(max * prodeff + 0.05)));
431 pr(" %1.2f\n", maxr);
433 player->simulation = 0;
436 pr("%s: No sector(s)\n", player->argp[1]);
438 pr("%s: No sector(s)\n", "");
441 pr("%d sector%s\n", nsect, splur(nsect));