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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future 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
33 * Markus Armbruster, 2004-2005
57 for (i = 0; NULL != (sp = getsectid(i)); i++) {
60 if (sp->sct_oldown != n)
62 pop += sp->sct_item[I_CIVIL];
72 struct nstr_sect nstr;
75 double maxr; /* floating version of max */
77 double real; /* floating pt version of act */
80 int act; /* actual production */
83 int max; /* production w/infinite materials */
88 int unit_work; /* sum of component amounts */
89 int used; /* production w/infinite workforce */
92 unsigned char *resource;
93 s_char maxc[MAXPRCON][10];
94 s_char use[MAXPRCON][10];
105 if (!snxtsct(&nstr, player->argp[1]))
107 player->simulation = 1;
110 while (nxtsct(&nstr, §)) {
114 civs = (1.0 + obrate * etu_per_update) * sect.sct_item[I_CIVIL];
115 uws = (1.0 + uwbrate * etu_per_update) * sect.sct_item[I_UW];
116 natp = getnatp(sect.sct_own);
117 maxpop = max_pop(natp->nat_level[NAT_RLEV], §);
119 /* This isn't quite right, since research might rise/fall */
120 /* during the update, but it's the best we can really do */
121 work = new_work(§,
122 total_work(sect.sct_work, etu_per_update,
123 civs, sect.sct_item[I_MILIT], uws, maxpop));
128 type = sect.sct_type;
129 eff = sect.sct_effic;
130 if (sect.sct_newtype != type) {
131 twork = (eff + 3) / 4;
139 type = sect.sct_newtype;
142 if (!eff && IS_BIG_CITY(otype) &&
143 !IS_BIG_CITY(type)) {
144 natp = getnatp(sect.sct_own);
145 maxpop = max_population(natp->nat_level[NAT_RLEV],
147 work = new_work(§,
148 total_work(sect.sct_work, etu_per_update,
149 civs, sect.sct_item[I_MILIT],
151 bwork = MIN(work / 2, bwork);
157 if (dchr[type].d_lcms > 0) {
158 lcms = sect.sct_item[I_LCM];
159 lcms /= dchr[type].d_lcms;
163 if (dchr[type].d_hcms > 0) {
164 hcms = sect.sct_item[I_HCM];
165 hcms /= dchr[type].d_hcms;
171 } else if (eff < 100) {
179 work = (work + 1) / 2 + bwork;
187 if (dchr[type].d_prd == 0 && type != SCT_ENLIST)
190 pp = &pchr[dchr[type].d_prd];
192 natp = getnatp(sect.sct_own);
194 * sect p_e (inc improvements)
196 if (type == SCT_ENLIST && sect.sct_own != sect.sct_oldown)
198 if (type == SCT_ENLIST)
200 if (pp->p_nrndx != 0) {
202 resource = (unsigned char *)§ + pp->p_nrndx;
203 p_e = (*resource * p_e) / 100.0;
208 prodeff = prod_eff(pp, natp->nat_level[pp->p_nlndx]);
213 for (j = 0; j < MAXPRCON; ++j) {
217 if (CANT_HAPPEN(it <= I_NONE || I_MAX < it))
219 used = MIN(used, sect.sct_item[it] / pp->p_camt[j]);
220 unit_work += pp->p_camt[j];
225 * is production limited by resources or
228 max = (int)(work * p_e / (double)unit_work + 0.5);
229 if (pp->p_nrdep != 0 && vtype != I_NONE) {
230 if (*resource * 100 < pp->p_nrdep * max)
231 max = *resource * 100 / pp->p_nrdep;
233 act = MIN(used, max);
235 real = MIN(999.0, (double)act * prodeff);
236 maxr = MIN(999.0, (double)max * prodeff);
238 if (vtype != I_NONE) {
241 /* production backlog? */
242 there = MIN(ITEM_MAX, sect.sct_item[vtype]);
243 real = MIN(real, ITEM_MAX - there);
247 take = real / prodeff;
248 mtake = maxr / prodeff;
252 cost = (int)(take * (double)pp->p_cost);
254 if (pp->p_level == NAT_TLEV) {
255 totpop = count_pop(sect.sct_own);
257 cost = (int)((double)cost * (double)totpop / 50000.0);
262 for (j = 0; j < MAXPRCON; ++j) {
264 if (it > I_NONE && it <= I_MAX && ichr[it].i_mnem != 0) {
265 if (CANT_HAPPEN(i >= 3))
267 sprintf(use[i], "%4d%c",
268 (int)((take * (double)pp->p_camt[j]) + 0.5),
270 sprintf(maxc[i], "%4d%c",
271 (int)((mtake * (double)pp->p_camt[j]) + 0.5),
278 strcpy(maxc[i], " ");
285 pr("PRODUCTION SIMULATION\n");
286 pr(" sect des eff avail make p.e. cost use1 use2 use3 max1 max2 max3 max\n");
289 prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
290 pr(" %c", dchr[type].d_mnem);
291 pr(" %3.0f%%", p_e * 100.0);
294 if (vtype != I_NONE) {
295 pr(" %4d%c", (int)(real + 0.5), ichr[vtype].i_mnem);
296 } else if (type != SCT_ENLIST) {
297 switch (pp->p_level) {
307 CANT_HAPPEN("bad TYPE");
316 civs = (1.0 + obrate * etu_per_update) * sect.sct_item[I_CIVIL];
317 natp = getnatp(sect.sct_own);
318 maxpop = max_pop(natp->nat_level[NAT_RLEV], §);
319 civs = MIN(civs, maxpop);
320 /* This isn't quite right, since research might
321 rise/fall during the update, but it's the best
324 maxmil = (civs / 2) - sect.sct_item[I_MILIT];
326 enlisted = (etu_per_update
327 * (10 + sect.sct_item[I_MILIT])
329 if (enlisted > maxmil)
334 if (natp->nat_priorities[type] == 0) {
337 pr(" %4d%c 1.00 $%-5d%4dc %4dc %5d\n",
338 enlisted, ichr[I_MILIT].i_mnem, enlisted * 3,
339 enlisted, enlisted, maxmil);
343 pr(" %.2f", prodeff);
345 for (i = 0; i < 3; i++) {
349 for (i = 0; i < 3; i++) {
352 if (natp->nat_priorities[type] == 0) {
356 if (vtype != I_NONE || pp->p_level == NAT_ELEV
357 || pp->p_level == NAT_HLEV)
358 pr(" %5d\n", MIN(999, (int)(max * prodeff + 0.5)));
360 pr(" %5.2f\n", maxr);
362 player->simulation = 0;
365 pr("%s: No sector(s)\n", player->argp[1]);
367 pr("%s: No sector(s)\n", "");
370 pr("%d sector%s\n", nsect, splur(nsect));