]> git.pond.sub.org Git - empserver/blob - src/lib/update/prepare.c
Update copyright notice
[empserver] / src / lib / update / prepare.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
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.
10  *
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.
15  *
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/>.
18  *
19  *  ---
20  *
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.
24  *
25  *  ---
26  *
27  *  prepare.c: Perform prelimiary updates of sectors
28  *
29  *  Known contributors to this file:
30  *     Dave Pare, 1986
31  *     Thomas Ruschak, 1992
32  *     Steve McClure, 1997
33  */
34
35 #include <config.h>
36
37 #include "budg.h"
38 #include "item.h"
39 #include "land.h"
40 #include "player.h"
41 #include "ship.h"
42 #include "update.h"
43
44 void
45 prepare_sects(int etu, struct bp *bp)
46 {
47     struct sctstr *sp;
48     struct natstr *np;
49     int n, civ_tax, uw_tax, mil_pay;
50
51     memset(levels, 0, sizeof(levels));
52
53 /* Process all the fallout. */
54     if (opt_FALLOUT) {
55         if (!player->simulation) {
56             /* First, we determine which sectors to process fallout in */
57             for (n = 0; NULL != (sp = getsectid(n)); n++)
58                 sp->sct_updated = sp->sct_fallout != 0;
59             /* Next, we process the fallout there */
60             for (n = 0; NULL != (sp = getsectid(n)); n++)
61                 if (sp->sct_updated)
62                     do_fallout(sp, etu);
63             /* Next, we spread the fallout */
64             for (n = 0; NULL != (sp = getsectid(n)); n++)
65                 if (sp->sct_updated)
66                     spread_fallout(sp, etu);
67             /* Next, we decay the fallout */
68             for (n = 0; NULL != (sp = getsectid(n)); n++)
69                 if (sp->sct_fallout)
70                     decay_fallout(sp, etu);
71         }
72     }
73     for (n = 0; NULL != (sp = getsectid(n)); n++) {
74         sp->sct_updated = 0;
75
76         if (sp->sct_type == SCT_WATER)
77             continue;
78         bp_set_from_sect(bp, sp);
79         np = getnatp(sp->sct_own);
80
81         if (np->nat_stat != STAT_SANCT) {
82             guerrilla(sp);
83             do_plague(sp, np, etu);
84             tax(sp, np, etu, &pops[sp->sct_own], &civ_tax, &uw_tax,
85                 &mil_pay);
86             np->nat_money += civ_tax + uw_tax + mil_pay;
87             if (sp->sct_type == SCT_BANK)
88                 np->nat_money += bank_income(sp, etu);
89         }
90     }
91     for (n = 0; NULL != (np = getnatp(n)); n++) {
92         np->nat_money += upd_slmilcosts(np->nat_cnum, etu);
93     }
94 }
95
96 void
97 tax(struct sctstr *sp, struct natstr *np, int etu, long *pop, int *civ_tax,
98     int *uw_tax, int *mil_pay)
99 {
100     *civ_tax = 0;
101     *uw_tax = 0;
102     *mil_pay = 0;
103
104     if (!player->simulation)
105         populace(np, sp, etu);
106     *civ_tax = (int)(0.5 + sp->sct_item[I_CIVIL] * sp->sct_effic *
107                      etu * money_civ / 100);
108     /*
109      * captured civs only pay 1/4 taxes
110      */
111     if (sp->sct_own != sp->sct_oldown)
112         *civ_tax = *civ_tax / 4;
113     *uw_tax = (int)(0.5 + sp->sct_item[I_UW] * sp->sct_effic *
114                     etu * money_uw / 100);
115     *mil_pay = sp->sct_item[I_MILIT] * etu * money_mil;
116
117     /*
118      * only non-captured civs add to census for nation
119      */
120     if (sp->sct_oldown == sp->sct_own)
121         *pop += sp->sct_item[I_CIVIL];
122 }
123
124 int
125 upd_slmilcosts(natid n, int etu)
126 {
127     struct shpstr *sp;
128     struct lndstr *lp;
129     int mil = 0;
130     int totalmil = 0;
131     int mil_pay = 0;
132     int i;
133
134     for (i = 0; NULL != (sp = getshipp(i)); i++) {
135         if (!sp->shp_own || sp->shp_own != n)
136             continue;
137         if ((mil = sp->shp_item[I_MILIT]) > 0)
138             totalmil += mil;
139     }
140     for (i = 0; NULL != (lp = getlandp(i)); i++) {
141         if (!lp->lnd_own || lp->lnd_own != n)
142             continue;
143         if ((mil = lp->lnd_item[I_MILIT]) > 0)
144             totalmil += mil;
145     }
146     mil_pay = totalmil * etu * money_mil;
147     return mil_pay;
148 }
149
150 int
151 bank_income(struct sctstr *sp, int etu)
152 {
153     return (int)(sp->sct_item[I_BAR] * etu * bankint * sp->sct_effic / 100);
154 }