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)
73 struct nstr_sect nstr;
76 double maxr; /* floating version of max */
78 double real; /* floating pt version of act */
81 int act; /* actual production */
84 int max; /* production w/infinate materials */
90 int totcomp; /* sum of component amounts */
91 int used; /* production w/infinite workforce */
94 u_short *amount; /* amount for component pointer */
95 u_char *comp; /* component pointer */
102 int items[I_MAX + 1];
103 int vec[I_MAX + 1], lcms, hcms;
113 if (!snxtsct(&nstr, player->argp[1]))
115 player->simulation = 1;
118 while (nxtsct(&nstr, §)) {
121 getvec(VT_ITEM, items, (s_char *)§, EF_SECTOR);
123 civs = min(9999, (int)((obrate * (double)etu_per_update + 1.0)
124 * (double)items[I_CIVIL]));
125 uws = min(9999, (int)((uwbrate * (double)etu_per_update + 1.0)
126 * (double)items[I_UW]));
128 natp = getnatp(sect.sct_own);
129 maxpop = max_pop((float)natp->nat_level[NAT_RLEV], §);
130 civs = min(civs, maxpop);
131 uws = min(uws, maxpop);
132 } else { /* now RES_POP */
133 civs = min(999, civs);
137 /* This isn't quite right, since research might rise/fall */
138 /* during the update, but it's the best we can really do */
139 wforce = (int)(((double)civs * (double)sect.sct_work)
140 / 100.0 + (double)uws +
141 (double)items[I_MILIT] * 2.0 / 5.0);
142 work = (double)etu_per_update *(double)wforce / 100.0;
143 if (opt_ROLLOVER_AVAIL) {
144 if (sect.sct_type == sect.sct_newtype) {
145 work += sect.sct_avail;
147 if (work > 999) work = 999;
149 bwork = (int)((double)work / 2.0);
153 type = sect.sct_type;
154 eff = sect.sct_effic;
155 if (sect.sct_newtype != type) {
156 twork = (eff + 3) / 4;
164 type = sect.sct_newtype;
168 if (!eff && dchr[otype].d_pkg == UPKG &&
169 dchr[type].d_pkg != UPKG) {
171 natp = getnatp(sect.sct_own);
174 max_pop(natp->nat_level[NAT_RLEV], 0));
177 max_pop(natp->nat_level[NAT_RLEV], 0));
179 civs = min(9999, civs);
180 uws = min(9999, uws);
183 (int)((civs * sect.sct_work) / 100.0 + uws +
184 items[I_MILIT] * 2 / 5.0);
185 work = etu_per_update * wforce / 100.0;
186 bwork = min((int)(work / 2), bwork);
193 getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);
194 if (dchr[type].d_lcms > 0) {
196 lcms /= dchr[type].d_lcms;
200 if (dchr[type].d_hcms > 0) {
202 hcms /= dchr[type].d_hcms;
208 } else if (eff < 100) {
216 work = work / 2 + bwork;
217 if (eff < 60 || (type != SCT_ENLIST && eff < 61))
224 if (dchr[type].d_prd == 0 && type != SCT_ENLIST)
227 pp = &pchr[dchr[type].d_prd];
229 natp = getnatp(sect.sct_own);
231 * sect effic (inc improvements)
233 if (type == SCT_ENLIST && sect.sct_own != sect.sct_oldown)
235 if (type == SCT_ENLIST)
237 if (pp->p_nrndx != 0) {
239 resource = ((s_char *)§) + pp->p_nrndx;
240 effic = (*resource * effic) / 100.0;
241 if (pp->p_nrdep > 0) {
242 maxtake = (*resource * 100.0) / pp->p_nrdep;
250 if (pp->p_nlndx >= 0) {
251 prodeff = natp->nat_level[pp->p_nlndx] - pp->p_nlmin;
255 prodeff = prodeff / (prodeff + pp->p_nllag);
261 endcomp = pp->p_vtype + pp->p_nv;
263 while (comp < endcomp) {
267 used = min(used, (int)(getvar((int)*comp, (s_char *)§,
268 EF_SECTOR) / *amount));
277 * is production limited by resources or
280 max = (int)(work * effic / (double)totcomp) + 0.5;
281 act = min(used, max);
283 * some things are easier to make.. food,
286 act = (int)(((double)pp->p_effic * 0.01 * (double)act) + 0.5);
287 max = (int)(((double)pp->p_effic * 0.01 * (double)max) + 0.5);
289 real = (double)act *(double)prodeff;
290 maxr = (double)max *(double)prodeff;
295 /* production backlog? */
297 getvar((int)vtype, (s_char *)§, EF_SECTOR)) >= 9999) {
300 act = min(act, (9999 - there));
301 max = min(max, (9999 - there));
305 take = real / prodeff;
306 mtake = maxr / prodeff;
315 take = (double)take / ((double)pp->p_effic * 0.01);
316 mtake = (double)mtake / ((double)pp->p_effic * 0.01);
318 cost = (int)(take * (double)pp->p_cost);
320 if (pp->p_level == NAT_TLEV) {
321 totpop = count_pop(sect.sct_own);
323 cost = (int)((double)cost * (double)totpop / 50000.0);
330 while (comp < endcomp) {
331 it = unitem((int)*comp);
332 if (it > 0 && it <= I_MAX && ichr[it].i_name != 0)
333 c = ichr[it].i_name[0];
336 (void)sprintf(use[i], " %3d%c",
337 (int)((take * (double)(*amount)) + 0.5), c);
338 (void)sprintf(maxc[i], " %3d%c",
339 (int)((mtake * (double)(*amount)) + 0.5), c);
346 strcpy(maxc[i], " ");
353 pr("PRODUCTION SIMULATION\n");
354 pr(" sect des eff wkfc will make- p.e. cost use1 use2 use3 max1 max2 max3 max\n");
357 prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
358 pr(" %c", dchr[type].d_mnem);
359 pr(" %3.0f%%", effic * 100.0);
363 pr(" %4d", (int)(real + 0.5));
364 } else if (type != SCT_ENLIST) {
365 switch (pp->p_level) {
383 civs = min(999, (int)((obrate * (double)etu_per_update + 1.0)
384 * (double)items[I_CIVIL]));
385 natp = getnatp(sect.sct_own);
386 maxpop = max_pop((float)natp->nat_level[NAT_RLEV], §);
387 civs = min(civs, maxpop);
388 /* This isn't quite right, since research might
389 rise/fall during the update, but it's the best
392 maxmil = (civs / 2) - items[I_MILIT];
394 enlisted = (etu_per_update * (10 + items[I_MILIT]) * 0.05);
395 if (enlisted > maxmil)
400 if (natp->nat_priorities[type] == 0) {
403 pr(" %4d mil 1.00 $%-5d%3dc",
404 enlisted, enlisted * 3, enlisted);
406 enlisted, maxmil, maxmil);
410 pr(" %-5.5s", pp->p_sname);
411 prodeff = prodeff * (double)pp->p_effic * 0.01;
412 pr(" %.2f", prodeff);
414 for (i = 0; i < 3; i++) {
418 for (i = 0; i < 3; i++) {
421 if (natp->nat_priorities[type] == 0) {
425 if (vtype != 0 || pp->p_level == NAT_ELEV
426 || pp->p_level == NAT_HLEV)
427 pr(" %4d\n", min(999, (int)(max * prodeff + 0.05)));
429 pr(" %1.2f\n", maxr);
431 player->simulation = 0;
434 pr("%s: No sector(s)\n", player->argp[1]);
436 pr("%s: No sector(s)\n", "");
439 pr("%d sector%s\n", nsect, splur(nsect));