2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * sect.c: Do production for sectors
29 * Known contributors to this file:
32 * Markus Armbruster, 2004-2016
42 #include "prototypes.h"
46 buildeff(struct sctstr *sp)
48 int avail = sp->sct_avail / 2 * 100;
55 if (sp->sct_type != sp->sct_newtype) {
57 * Tear down existing sector.
58 * Easier to destroy than to build.
60 dcp = &dchr[sp->sct_type];
61 build = 4 * avail / dcp->d_bwork;
62 if (build <= sp->sct_effic)
63 sp->sct_effic -= build;
65 build = sp->sct_effic;
67 sp->sct_type = sp->sct_newtype;
69 avail -= roundavg(build / 4.0 * dcp->d_bwork);
73 if (sp->sct_type == sp->sct_newtype) {
74 dcp = &dchr[sp->sct_type];
75 delta = avail / dcp->d_bwork;
76 if (delta > 100 - sp->sct_effic)
77 delta = 100 - sp->sct_effic;
78 build = get_materials(sp, dcp->d_mat, delta);
79 sp->sct_effic += build;
80 avail -= build * dcp->d_bwork;
81 cost += build * dcp->d_cost / 100.0;
84 sp->sct_avail = (sp->sct_avail + 1) / 2 + avail / 100;
89 * enlistment sectors are special; they require military
90 * to convert civ into mil in large numbers.
91 * Conversion will happen much more slowly without
95 enlist(struct natstr *np, short *vec, int etu)
101 maxmil = vec[I_CIVIL] / 2 - vec[I_MILIT];
103 enlisted = etu * (10 + vec[I_MILIT]) * 0.05;
104 if (enlisted > maxmil)
106 vec[I_CIVIL] -= enlisted;
107 vec[I_MILIT] += enlisted;
110 nat_budget[np->nat_cnum].prod[SCT_ENLIST].count += enlisted;
111 nat_budget[np->nat_cnum].prod[SCT_ENLIST].money -= enlisted * 3;
112 nat_budget[np->nat_cnum].money -= enlisted * 3;
116 * Produce for a specific nation
119 produce_sect(int etu, struct bp *bp)
121 struct budget *budget;
123 struct sctstr *sp, scratch_sect;
127 for (n = 0; NULL != (sp = getsectid(n)); n++) {
128 if (bp_skip_sect(bp, sp))
130 if (sp->sct_type == SCT_WATER || sp->sct_type == SCT_SANCT)
134 * When running the test suite, reseed PRNG for each sector
135 * with its UID, to keep results stable even when the number
136 * of PRNs consumed changes.
138 if (running_test_suite)
139 seed_prng(sp->sct_uid);
141 if (player->simulation) {
142 /* work on a copy, which will be discarded */
144 bp_to_sect(bp, &scratch_sect);
148 budget = &nat_budget[sp->sct_own];
149 np = getnatp(sp->sct_own);
151 if (dchr[sp->sct_type].d_maint) {
152 cost = etu * dchr[sp->sct_type].d_maint;
153 budget->bm[BUDG_SCT_MAINT].count++;
154 budget->bm[BUDG_SCT_MAINT].money -= cost;
155 budget->money -= cost;
158 if (sp->sct_off || budget->money < 0) {
160 bp_set_from_sect(bp, sp);
164 if ((sp->sct_effic < 100 || sp->sct_type != sp->sct_newtype) &&
165 budget->money >= 0) {
167 budget->bm[BUDG_SCT_BUILD].count++;
168 budget->bm[BUDG_SCT_BUILD].money -= cost;
169 budget->money -= cost;
172 if (sp->sct_type == SCT_ENLIST && sp->sct_effic >= 60 &&
173 sp->sct_own == sp->sct_oldown) {
174 enlist(np, sp->sct_item, etu);
178 * now do the production (if sector effic >= 60%)
181 if (sp->sct_effic >= 60) {
182 if (budget->money >= 0 && dchr[sp->sct_type].d_prd >= 0)
186 bp_set_from_sect(bp, sp);