2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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
56 for (i = 0; NULL != (sp = getsectid(i)); i++) {
59 if (sp->sct_oldown != n)
61 pop += sp->sct_item[I_CIVIL];
71 struct nstr_sect nstr;
74 double maxr; /* floating version of max */
76 double real; /* floating pt version of act */
79 int act; /* actual production */
82 int max; /* production w/infinite materials */
87 int unit_work; /* sum of component amounts */
88 int used; /* production w/infinite workforce */
92 s_char maxc[MAXPRCON][10];
93 s_char use[MAXPRCON][10];
104 if (!snxtsct(&nstr, player->argp[1]))
106 player->simulation = 1;
109 while (nxtsct(&nstr, §)) {
113 civs = (1.0 + obrate * etu_per_update) * sect.sct_item[I_CIVIL];
114 uws = (1.0 + uwbrate * etu_per_update) * sect.sct_item[I_UW];
115 natp = getnatp(sect.sct_own);
116 maxpop = max_pop(natp->nat_level[NAT_RLEV], §);
118 /* This isn't quite right, since research might rise/fall */
119 /* during the update, but it's the best we can really do */
120 work = new_work(§,
121 total_work(sect.sct_work, etu_per_update,
122 civs, sect.sct_item[I_MILIT], uws, maxpop));
127 type = sect.sct_type;
128 eff = sect.sct_effic;
129 if (sect.sct_newtype != type) {
130 twork = (eff + 3) / 4;
138 type = sect.sct_newtype;
141 if (!eff && IS_BIG_CITY(otype) &&
142 !IS_BIG_CITY(type)) {
143 natp = getnatp(sect.sct_own);
144 maxpop = max_population(natp->nat_level[NAT_RLEV],
146 work = new_work(§,
147 total_work(sect.sct_work, etu_per_update,
148 civs, sect.sct_item[I_MILIT],
150 bwork = MIN(work / 2, bwork);
156 if (dchr[type].d_lcms > 0) {
157 lcms = sect.sct_item[I_LCM];
158 lcms /= dchr[type].d_lcms;
162 if (dchr[type].d_hcms > 0) {
163 hcms = sect.sct_item[I_HCM];
164 hcms /= dchr[type].d_hcms;
170 } else if (eff < 100) {
178 work = (work + 1) / 2 + bwork;
186 if (dchr[type].d_prd == 0 && type != SCT_ENLIST)
189 pp = &pchr[dchr[type].d_prd];
191 natp = getnatp(sect.sct_own);
193 * sect p_e (inc improvements)
195 if (type == SCT_ENLIST && sect.sct_own != sect.sct_oldown)
197 if (type == SCT_ENLIST)
199 if (pp->p_nrndx != 0) {
201 resource = (u_char *)§ + pp->p_nrndx;
202 p_e = (*resource * p_e) / 100.0;
207 prodeff = prod_eff(pp, natp->nat_level[pp->p_nlndx]);
212 for (j = 0; j < MAXPRCON; ++j) {
216 if (CANT_HAPPEN(it <= I_NONE || I_MAX < it))
218 used = MIN(used, sect.sct_item[it] / pp->p_camt[j]);
219 unit_work += pp->p_camt[j];
224 * is production limited by resources or
227 max = (int)(work * p_e / (double)unit_work + 0.5);
228 if (pp->p_nrdep != 0 && vtype != I_NONE) {
229 if (*resource * 100 < pp->p_nrdep * max)
230 max = *resource * 100 / pp->p_nrdep;
232 act = MIN(used, max);
234 real = MIN(999.0, (double)act * prodeff);
235 maxr = MIN(999.0, (double)max * prodeff);
237 if (vtype != I_NONE) {
240 /* production backlog? */
241 there = MIN(ITEM_MAX, sect.sct_item[vtype]);
242 real = MIN(real, ITEM_MAX - there);
246 take = real / prodeff;
247 mtake = maxr / prodeff;
251 cost = (int)(take * (double)pp->p_cost);
253 if (pp->p_level == NAT_TLEV) {
254 totpop = count_pop(sect.sct_own);
256 cost = (int)((double)cost * (double)totpop / 50000.0);
261 for (j = 0; j < MAXPRCON; ++j) {
263 if (it > I_NONE && it <= I_MAX && ichr[it].i_mnem != 0) {
264 if (CANT_HAPPEN(i >= 3))
266 sprintf(use[i], "%4d%c",
267 (int)((take * (double)pp->p_camt[j]) + 0.5),
269 sprintf(maxc[i], "%4d%c",
270 (int)((mtake * (double)pp->p_camt[j]) + 0.5),
277 strcpy(maxc[i], " ");
284 pr("PRODUCTION SIMULATION\n");
285 pr(" sect des eff avail make p.e. cost use1 use2 use3 max1 max2 max3 max\n");
288 prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
289 pr(" %c", dchr[type].d_mnem);
290 pr(" %3.0f%%", p_e * 100.0);
293 if (vtype != I_NONE) {
294 pr(" %4d%c", (int)(real + 0.5), ichr[vtype].i_mnem);
295 } else if (type != SCT_ENLIST) {
296 switch (pp->p_level) {
306 CANT_HAPPEN("bad TYPE");
315 civs = (1.0 + obrate * etu_per_update) * sect.sct_item[I_CIVIL];
316 natp = getnatp(sect.sct_own);
317 maxpop = max_pop(natp->nat_level[NAT_RLEV], §);
318 civs = MIN(civs, maxpop);
319 /* This isn't quite right, since research might
320 rise/fall during the update, but it's the best
323 maxmil = (civs / 2) - sect.sct_item[I_MILIT];
325 enlisted = (etu_per_update
326 * (10 + sect.sct_item[I_MILIT])
328 if (enlisted > maxmil)
333 if (natp->nat_priorities[type] == 0) {
336 pr(" %4d%c 1.00 $%-5d%4dc %4dc %5d\n",
337 enlisted, ichr[I_MILIT].i_mnem, enlisted * 3,
338 enlisted, enlisted, maxmil);
342 pr(" %.2f", prodeff);
344 for (i = 0; i < 3; i++) {
348 for (i = 0; i < 3; i++) {
351 if (natp->nat_priorities[type] == 0) {
355 if (vtype != I_NONE || pp->p_level == NAT_ELEV
356 || pp->p_level == NAT_HLEV)
357 pr(" %5d\n", MIN(999, (int)(max * prodeff + 0.5)));
359 pr(" %5.2f\n", maxr);
361 player->simulation = 0;
364 pr("%s: No sector(s)\n", player->argp[1]);
366 pr("%s: No sector(s)\n", "");
369 pr("%d sector%s\n", nsect, splur(nsect));