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-2006
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;
94 int cuse[MAXPRCON], cmax[MAXPRCON];
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,
129 type = sect.sct_type;
130 eff = sect.sct_effic;
131 if (sect.sct_newtype != type) {
132 twork = (eff + 3) / 4;
140 type = sect.sct_newtype;
143 if (!eff && IS_BIG_CITY(otype) &&
144 !IS_BIG_CITY(type)) {
145 natp = getnatp(sect.sct_own);
146 maxpop = max_population(natp->nat_level[NAT_RLEV],
148 work = new_work(§,
149 total_work(sect.sct_work, etu_per_update,
150 civs, sect.sct_item[I_MILIT],
152 bwork = MIN(work / 2, bwork);
158 if (dchr[type].d_lcms > 0) {
159 lcms = sect.sct_item[I_LCM];
160 lcms /= dchr[type].d_lcms;
164 if (dchr[type].d_hcms > 0) {
165 hcms = sect.sct_item[I_HCM];
166 hcms /= dchr[type].d_hcms;
172 } else if (eff < 100) {
180 work = (work + 1) / 2 + bwork;
188 if (dchr[type].d_prd == 0 && type != SCT_ENLIST)
191 pp = &pchr[dchr[type].d_prd];
193 natp = getnatp(sect.sct_own);
195 * sect p_e (inc improvements)
197 if (type == SCT_ENLIST && sect.sct_own != sect.sct_oldown)
199 if (type == SCT_ENLIST)
201 if (pp->p_nrndx != 0) {
203 resource = (unsigned char *)§ + pp->p_nrndx;
204 p_e = (*resource * p_e) / 100.0;
209 prodeff = prod_eff(pp, natp->nat_level[pp->p_nlndx]);
214 for (i = 0; i < MAXPRCON; ++i) {
218 if (CANT_HAPPEN(it <= I_NONE || I_MAX < it))
220 used = MIN(used, sect.sct_item[it] / pp->p_camt[i]);
221 unit_work += pp->p_camt[i];
226 * is production limited by resources or
229 max = (int)(work * p_e / (double)unit_work + 0.5);
230 if (pp->p_nrdep != 0 && vtype != I_NONE) {
231 if (*resource * 100 < pp->p_nrdep * max)
232 max = *resource * 100 / pp->p_nrdep;
234 act = MIN(used, max);
236 real = MIN(999.0, (double)act * prodeff);
237 maxr = MIN(999.0, (double)max * prodeff);
239 if (vtype != I_NONE) {
242 /* production backlog? */
243 there = MIN(ITEM_MAX, sect.sct_item[vtype]);
244 real = MIN(real, ITEM_MAX - there);
248 take = real / prodeff;
249 mtake = maxr / prodeff;
253 cost = take * pp->p_cost;
255 if (pp->p_level == NAT_TLEV) {
256 totpop = count_pop(sect.sct_own);
258 cost *= totpop / 50000.0;
262 for (i = 0; i < MAXPRCON; ++i) {
263 cmnem[i] = cuse[i] = cmax[i] = 0;
267 if (CANT_HAPPEN(it <= I_NONE || I_MAX < it))
269 cmnem[i] = ichr[it].i_mnem;
270 cuse[i] = (int)(take * pp->p_camt[i] + 0.5);
271 cmax[i] = (int)(mtake * pp->p_camt[i] + 0.5);
277 pr("PRODUCTION SIMULATION\n");
278 pr(" sect des eff avail make p.e. cost use1 use2 use3 max1 max2 max3 max\n");
281 prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
282 pr(" %c", dchr[type].d_mnem);
283 pr(" %3.0f%%", p_e * 100.0);
286 if (vtype != I_NONE) {
287 pr(" %4d%c", (int)(real + 0.5), ichr[vtype].i_mnem);
288 } else if (type != SCT_ENLIST) {
289 switch (pp->p_level) {
308 civs = (1.0 + obrate * etu_per_update) * sect.sct_item[I_CIVIL];
309 natp = getnatp(sect.sct_own);
310 maxpop = max_pop(natp->nat_level[NAT_RLEV], §);
311 civs = MIN(civs, maxpop);
312 /* This isn't quite right, since research might
313 rise/fall during the update, but it's the best
316 maxmil = (civs / 2) - sect.sct_item[I_MILIT];
318 enlisted = (etu_per_update
319 * (10 + sect.sct_item[I_MILIT])
321 if (enlisted > maxmil)
326 if (natp->nat_priorities[type] == 0) {
329 pr(" %4d%c 1.00 $%-5d%4dc %4dc %5d\n",
330 enlisted, ichr[I_MILIT].i_mnem, enlisted * 3,
331 enlisted, enlisted, maxmil);
335 pr(" %.2f", prodeff);
336 pr(" $%-5.0f", cost);
337 for (i = 0; i < 3; i++) {
338 if (i < MAXPRCON && cmnem[i])
339 pr("%4d%c", cuse[i], cmnem[i]);
344 for (i = 0; i < 3; i++) {
345 if (i < MAXPRCON && cmnem[i])
346 pr("%4d%c", cmax[i], cmnem[i]);
350 if (natp->nat_priorities[type] == 0) {
354 if (vtype != I_NONE || pp->p_level == NAT_ELEV
355 || pp->p_level == NAT_HLEV)
356 pr(" %5d\n", MIN(999, (int)(max * prodeff + 0.5)));
358 pr(" %5.2f\n", maxr);
360 player->simulation = 0;
363 pr("%s: No sector(s)\n", player->argp[1]);
365 pr("%s: No sector(s)\n", "");
368 pr("%d sector%s\n", nsect, splur(nsect));