2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2016, 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 * prepare.c: Perform prelimiary updates of sectors
29 * Known contributors to this file:
31 * Thomas Ruschak, 1992
33 * Markus Armbruster, 2016
45 #include "prototypes.h"
50 prepare_sects(int etu)
56 memset(levels, 0, sizeof(levels));
58 /* Process all the fallout. */
60 if (!player->simulation) {
61 /* First, we determine which sectors to process fallout in */
62 for (n = 0; NULL != (sp = getsectid(n)); n++)
63 sp->sct_updated = sp->sct_fallout != 0;
64 /* Next, we process the fallout there */
65 for (n = 0; NULL != (sp = getsectid(n)); n++)
68 /* Next, we spread the fallout */
69 for (n = 0; NULL != (sp = getsectid(n)); n++)
71 spread_fallout(sp, etu);
72 /* Next, we decay the fallout */
73 for (n = 0; NULL != (sp = getsectid(n)); n++)
75 decay_fallout(sp, etu);
78 for (n = 0; NULL != (sp = getsectid(n)); n++) {
81 if (sp->sct_type == SCT_WATER)
83 if (getnatp(sp->sct_own)->nat_stat == STAT_SANCT)
87 * When running the test suite, reseed PRNG for each sector
88 * with its UID, to keep results stable even when the number
89 * of PRNs consumed changes.
91 if (running_test_suite)
92 seed_prng(sp->sct_uid);
97 np = getnatp(sp->sct_own);
98 tax(sp, etu, &pops[sp->sct_own]);
99 if (sp->sct_type == SCT_BANK)
100 np->nat_money += bank_income(sp, etu);
102 for (n = 0; NULL != (np = getnatp(n)); n++) {
103 upd_slmilcosts(etu, np->nat_cnum);
104 pay_reserve(np, etu);
105 np->nat_money += nat_budget[n].mil.money;
106 np->nat_money += nat_budget[n].civ.money;
107 np->nat_money += nat_budget[n].uw.money;
112 tax(struct sctstr *sp, int etu, int *pop)
114 struct budget *budget = &nat_budget[sp->sct_own];
115 int civ_tax, uw_tax, mil_pay;
117 civ_tax = (int)(0.5 + sp->sct_item[I_CIVIL] * sp->sct_effic *
118 etu * money_civ / 100);
120 * captured civs only pay 1/4 taxes
122 if (sp->sct_own != sp->sct_oldown)
124 budget->civ.count += sp->sct_item[I_CIVIL];
125 budget->civ.money += civ_tax;
127 uw_tax = (int)(0.5 + sp->sct_item[I_UW] * sp->sct_effic *
128 etu * money_uw / 100);
129 budget->uw.count += sp->sct_item[I_UW];
130 budget->uw.money += uw_tax;
132 mil_pay = sp->sct_item[I_MILIT] * etu * money_mil;
133 budget->mil.count += sp->sct_item[I_MILIT];
134 budget->mil.money += mil_pay;
137 * only non-captured civs add to census for nation
139 if (sp->sct_oldown == sp->sct_own)
140 *pop += sp->sct_item[I_CIVIL];
144 upd_slmilcosts(int etu, natid n)
152 for (i = 0; (sp = getshipp(i)); i++) {
153 if (!sp->shp_own || sp->shp_own != n)
155 mil += sp->shp_item[I_MILIT];
158 for (i = 0; (lp = getlandp(i)); i++) {
159 if (!lp->lnd_own || lp->lnd_own != n)
161 mil += lp->lnd_item[I_MILIT];
164 nat_budget[n].mil.count += mil;
165 nat_budget[n].mil.money += mil * etu * money_mil;
169 bank_income(struct sctstr *sp, int etu)
171 return (int)(sp->sct_item[I_BAR] * etu * bankint * sp->sct_effic / 100);
175 pay_reserve(struct natstr *np, int etu)
177 nat_budget[np->nat_cnum].mil.money
178 += (int)(np->nat_reserve * money_res * etu);