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
50 static void prprod(struct sctstr *, double, double, int, char,
51 double, double, double, char[], int[], int[], int);
60 for (i = 0; NULL != (sp = getsectid(i)); i++) {
63 if (sp->sct_oldown != n)
65 pop += sp->sct_item[I_CIVIL];
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/infinite materials */
91 int unit_work; /* sum of component amounts */
92 int used; /* production w/infinite workforce */
95 unsigned char *resource;
97 int cuse[MAXPRCON], cmax[MAXPRCON];
109 if (!snxtsct(&nstr, player->argp[1]))
111 player->simulation = 1;
114 while (nxtsct(&nstr, §)) {
118 civs = (1.0 + obrate * etu_per_update) * sect.sct_item[I_CIVIL];
119 uws = (1.0 + uwbrate * etu_per_update) * sect.sct_item[I_UW];
120 natp = getnatp(sect.sct_own);
121 maxpop = max_pop(natp->nat_level[NAT_RLEV], §);
123 work = new_work(§,
124 total_work(sect.sct_work, etu_per_update,
125 civs, sect.sct_item[I_MILIT], uws,
131 type = sect.sct_type;
132 eff = sect.sct_effic;
133 if (sect.sct_newtype != type) {
134 twork = (eff + 3) / 4;
142 type = sect.sct_newtype;
145 if (!eff && IS_BIG_CITY(otype) && !IS_BIG_CITY(type)) {
146 natp = getnatp(sect.sct_own);
147 maxpop = max_population(natp->nat_level[NAT_RLEV],
149 work = new_work(§,
150 total_work(sect.sct_work, etu_per_update,
151 civs, sect.sct_item[I_MILIT],
153 bwork = MIN(work / 2, bwork);
159 if (dchr[type].d_lcms > 0) {
160 lcms = sect.sct_item[I_LCM];
161 lcms /= dchr[type].d_lcms;
165 if (dchr[type].d_hcms > 0) {
166 hcms = sect.sct_item[I_HCM];
167 hcms /= dchr[type].d_hcms;
173 } else if (eff < 100) {
181 work = (work + 1) / 2 + bwork;
189 if (type == SCT_ENLIST) {
193 if (sect.sct_own != sect.sct_oldown)
195 civs = (1.0 + obrate * etu_per_update) * sect.sct_item[I_CIVIL];
196 natp = getnatp(sect.sct_own);
197 maxpop = max_pop(natp->nat_level[NAT_RLEV], §);
198 civs = MIN(civs, maxpop);
200 maxmil = (civs / 2) - sect.sct_item[I_MILIT];
202 enlisted = (etu_per_update
203 * (10 + sect.sct_item[I_MILIT])
205 if (enlisted > maxmil)
210 prprod(§, p_e, 1.0, work,
211 ichr[I_MILIT].i_mnem, enlisted, maxmil, enlisted * 3,
212 "c\0\0", &enlisted, &enlisted, nsect++);
216 if (dchr[type].d_prd == 0)
219 pp = &pchr[dchr[type].d_prd];
221 natp = getnatp(sect.sct_own);
223 * sect p_e (inc improvements)
225 if (pp->p_nrndx != 0) {
227 resource = (unsigned char *)§ + pp->p_nrndx;
228 p_e = (*resource * p_e) / 100.0;
233 prodeff = prod_eff(type, natp->nat_level[pp->p_nlndx]);
238 for (i = 0; i < MAXPRCON; ++i) {
242 if (CANT_HAPPEN(it <= I_NONE || I_MAX < it))
244 used = MIN(used, sect.sct_item[it] / pp->p_camt[i]);
245 unit_work += pp->p_camt[i];
250 * is production limited by resources or
253 max = (int)(work * p_e / (double)unit_work + 0.5);
254 if (pp->p_nrdep != 0 && vtype != I_NONE) {
255 if (*resource * 100 < pp->p_nrdep * max)
256 max = *resource * 100 / pp->p_nrdep;
258 act = MIN(used, max);
260 real = MIN(999.0, (double)act * prodeff);
261 maxr = MIN(999.0, (double)max * prodeff);
263 if (vtype != I_NONE) {
266 /* production backlog? */
267 there = MIN(ITEM_MAX, sect.sct_item[vtype]);
268 real = MIN(real, ITEM_MAX - there);
272 take = real / prodeff;
273 mtake = maxr / prodeff;
277 cost = take * pp->p_cost;
279 if (pp->p_level == NAT_TLEV) {
280 totpop = count_pop(sect.sct_own);
282 cost *= totpop / 50000.0;
286 for (i = 0; i < MAXPRCON; ++i) {
287 cmnem[i] = cuse[i] = cmax[i] = 0;
291 if (CANT_HAPPEN(it <= I_NONE || I_MAX < it))
293 cmnem[i] = ichr[it].i_mnem;
294 cuse[i] = (int)(take * pp->p_camt[i] + 0.5);
295 cmax[i] = (int)(mtake * pp->p_camt[i] + 0.5);
298 if (pp->p_type != I_NONE)
299 mnem = ichr[vtype].i_mnem;
300 else if (pp->p_level == NAT_TLEV || pp->p_level == NAT_RLEV)
304 prprod(§, p_e, prodeff, work,
305 mnem, real, maxr, cost,
306 cmnem, cuse, cmax, nsect++);
308 player->simulation = 0;
311 pr("%s: No sector(s)\n", player->argp[1]);
313 pr("%s: No sector(s)\n", "");
316 pr("%d sector%s\n", nsect, splur(nsect));
321 prprod(struct sctstr *sp, double p_e, double prodeff, int work,
322 char mnem, double make, double max, double cost,
323 char cmnem[], int cuse[], int cmax[], int nsect)
328 pr("PRODUCTION SIMULATION\n");
329 pr(" sect des eff avail make p.e. cost use1 use2 use3 max1 max2 max3 max\n");
332 prxy("%4d,%-4d", sp->sct_x, sp->sct_y, player->cnum);
333 pr(" %c %3.0f%% %5d", dchr[sp->sct_type].d_mnem, p_e * 100.0, work);
337 pr(" %4.0f%c", make, mnem ? mnem : ' ');
338 pr(" %.2f $%-5.0f", prodeff, cost);
339 for (i = 0; i < 3; i++) {
340 if (i < MAXPRCON && cmnem[i])
341 pr("%4d%c", cuse[i], cmnem[i]);
346 for (i = 0; i < 3; i++) {
347 if (i < MAXPRCON && cmnem[i])
348 pr("%4d%c", cmax[i], cmnem[i]);