2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2007, 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
43 static void prprod(coord, coord, int, double, double, int, char,
44 double, double, double, char[], int[], int[], int);
53 for (i = 0; NULL != (sp = getsectid(i)); i++) {
56 if (sp->sct_oldown != n)
58 pop += sp->sct_item[I_CIVIL];
68 struct nstr_sect nstr;
71 double maxr; /* floating version of max */
73 double real; /* floating pt version of act */
76 int act; /* actual production */
79 int max; /* production w/infinite materials */
84 int unit_work; /* sum of component amounts */
85 int used; /* production w/infinite workforce */
88 unsigned char *resource;
90 int cuse[MAXPRCON], cmax[MAXPRCON];
102 if (!snxtsct(&nstr, player->argp[1]))
104 player->simulation = 1;
107 while (nxtsct(&nstr, §)) {
111 civs = (1.0 + obrate * etu_per_update) * sect.sct_item[I_CIVIL];
112 uws = (1.0 + uwbrate * etu_per_update) * sect.sct_item[I_UW];
113 natp = getnatp(sect.sct_own);
114 maxpop = max_pop(natp->nat_level[NAT_RLEV], §);
116 work = new_work(§,
117 total_work(sect.sct_work, etu_per_update,
118 civs, sect.sct_item[I_MILIT], uws,
124 type = sect.sct_type;
125 eff = sect.sct_effic;
126 if (sect.sct_newtype != type) {
127 twork = (eff + 3) / 4;
135 type = sect.sct_newtype;
138 if (!eff && IS_BIG_CITY(otype) && !IS_BIG_CITY(type)) {
139 natp = getnatp(sect.sct_own);
140 maxpop = max_population(natp->nat_level[NAT_RLEV],
142 work = new_work(§,
143 total_work(sect.sct_work, etu_per_update,
144 civs, sect.sct_item[I_MILIT],
146 bwork = MIN(work / 2, bwork);
152 if (dchr[type].d_lcms > 0) {
153 lcms = sect.sct_item[I_LCM];
154 lcms /= dchr[type].d_lcms;
158 if (dchr[type].d_hcms > 0) {
159 hcms = sect.sct_item[I_HCM];
160 hcms /= dchr[type].d_hcms;
166 } else if (eff < 100) {
174 work = (work + 1) / 2 + bwork;
182 if (type == SCT_ENLIST) {
186 if (sect.sct_own != sect.sct_oldown)
188 civs = (1.0 + obrate * etu_per_update) * sect.sct_item[I_CIVIL];
189 natp = getnatp(sect.sct_own);
190 maxpop = max_pop(natp->nat_level[NAT_RLEV], §);
191 civs = MIN(civs, maxpop);
193 maxmil = (civs / 2) - sect.sct_item[I_MILIT];
195 enlisted = (etu_per_update
196 * (10 + sect.sct_item[I_MILIT])
198 if (enlisted > maxmil)
203 prprod(sect.sct_x, sect.sct_y, type, p_e, 1.0, work,
204 ichr[I_MILIT].i_mnem, enlisted, maxmil, enlisted * 3,
205 "c\0\0", &enlisted, &enlisted, nsect++);
209 if (dchr[type].d_prd < 0)
212 pp = &pchr[dchr[type].d_prd];
214 natp = getnatp(sect.sct_own);
216 * sect p_e (inc improvements)
218 if (pp->p_nrndx != 0) {
220 resource = (unsigned char *)§ + pp->p_nrndx;
221 p_e = (*resource * p_e) / 100.0;
226 prodeff = prod_eff(type, natp->nat_level[pp->p_nlndx]);
231 for (i = 0; i < MAXPRCON; ++i) {
235 if (CANT_HAPPEN(it <= I_NONE || I_MAX < it))
237 used = MIN(used, sect.sct_item[it] / pp->p_camt[i]);
238 unit_work += pp->p_camt[i];
243 * is production limited by resources or
246 max = (int)(work * p_e / (double)unit_work + 0.5);
247 if (pp->p_nrdep != 0 && vtype != I_NONE) {
248 if (*resource * 100 < pp->p_nrdep * max)
249 max = *resource * 100 / pp->p_nrdep;
251 act = MIN(used, max);
253 real = MIN(999.0, (double)act * prodeff);
254 maxr = MIN(999.0, (double)max * prodeff);
256 if (vtype != I_NONE) {
259 /* production backlog? */
260 there = MIN(ITEM_MAX, sect.sct_item[vtype]);
261 real = MIN(real, ITEM_MAX - there);
265 take = real / prodeff;
266 mtake = maxr / prodeff;
270 cost = take * pp->p_cost;
272 if (pp->p_level == NAT_TLEV) {
273 totpop = count_pop(sect.sct_own);
275 cost *= totpop / 50000.0;
279 for (i = 0; i < MAXPRCON; ++i) {
280 cmnem[i] = cuse[i] = cmax[i] = 0;
284 if (CANT_HAPPEN(it <= I_NONE || I_MAX < it))
286 cmnem[i] = ichr[it].i_mnem;
287 cuse[i] = (int)(take * pp->p_camt[i] + 0.5);
288 cmax[i] = (int)(mtake * pp->p_camt[i] + 0.5);
291 if (pp->p_type != I_NONE)
292 mnem = ichr[vtype].i_mnem;
293 else if (pp->p_level == NAT_TLEV || pp->p_level == NAT_RLEV)
297 prprod(sect.sct_x, sect.sct_y, type, p_e, prodeff, work,
298 mnem, real, maxr, cost,
299 cmnem, cuse, cmax, nsect++);
301 player->simulation = 0;
304 pr("%s: No sector(s)\n", player->argp[1]);
306 pr("%s: No sector(s)\n", "");
309 pr("%d sector%s\n", nsect, splur(nsect));
314 prprod(coord x, coord y, int type, double p_e, double prodeff, int work,
315 char mnem, double make, double max, double cost,
316 char cmnem[], int cuse[], int cmax[], int nsect)
321 pr("PRODUCTION SIMULATION\n");
322 pr(" sect des eff avail make p.e. cost use1 use2 use3 max1 max2 max3 max\n");
325 prxy("%4d,%-4d", x, y, player->cnum);
326 pr(" %c %3.0f%% %5d", dchr[type].d_mnem, p_e * 100.0, work);
330 pr(" %4.0f%c", make, mnem ? mnem : ' ');
331 pr(" %.2f $%-5.0f", prodeff, cost);
332 for (i = 0; i < 3; i++) {
333 if (i < MAXPRCON && cmnem[i])
334 pr("%4d%c", cuse[i], cmnem[i]);
339 for (i = 0; i < 3; i++) {
340 if (i < MAXPRCON && cmnem[i])
341 pr("%4d%c", cmax[i], cmnem[i]);