]> 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-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
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.
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, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  prepare.c: Perform prelimiary updates of sectors
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1986
32  *     Thomas Ruschak, 1992
33  *     Steve McClure, 1997
34  */
35
36 #include "misc.h"
37 #include "sect.h"
38 #include "nat.h"
39 #include "item.h"
40 #include "file.h"
41 #include "xy.h"
42 #include "path.h"
43 #include "optlist.h"
44 #include "budg.h"
45 #include "player.h"
46 #include "ship.h"
47 #include "land.h"
48 #include "update.h"
49 #include "gen.h"
50 #include "common.h"
51
52 void
53 prepare_sects(int etu, int *bp)
54 {
55     struct sctstr *sp;
56     struct natstr *np;
57     int n, civ_tax, uw_tax, mil_pay;
58
59     memset(levels, 0, sizeof(levels));
60
61 /* Process all the fallout. */
62     if (opt_FALLOUT) {
63         if (!player->simulation) {
64             /* First, we determine which sectors to process fallout in */
65             for (n = 0; NULL != (sp = getsectid(n)); n++)
66                 sp->sct_updated = sp->sct_fallout != 0;
67             /* Next, we process the fallout there */
68             for (n = 0; NULL != (sp = getsectid(n)); n++)
69                 if (sp->sct_updated)
70                     do_fallout(sp, etu);
71             /* Next, we spread the fallout */
72             for (n = 0; NULL != (sp = getsectid(n)); n++)
73                 if (sp->sct_updated)
74                     spread_fallout(sp, etu);
75             /* Next, we decay the fallout */
76             for (n = 0; NULL != (sp = getsectid(n)); n++)
77                 if (sp->sct_fallout)
78                     decay_fallout(sp, etu);
79         }
80     }
81     for (n = 0; NULL != (sp = getsectid(n)); n++) {
82         sp->sct_updated = 0;
83
84         if (sp->sct_type == SCT_WATER)
85             continue;
86         fill_update_array(bp, sp);
87         np = getnatp(sp->sct_own);
88
89 #ifdef DEBUG
90         if (np->nat_stat & STAT_SANCT)
91             logerror("Prepare.c: country in sanctuary skipped production");
92 #endif /* DEBUG */
93
94         if (!(np->nat_stat & STAT_SANCT)) {
95             guerrilla(sp);
96             do_plague(sp, np, etu);
97             tax(sp, np, etu, &pops[sp->sct_own], &civ_tax, &uw_tax,
98                 &mil_pay);
99             np->nat_money += civ_tax + uw_tax + mil_pay;
100             if (sp->sct_type == SCT_BANK)
101                 np->nat_money += bank_income(sp, etu);
102         }
103     }
104     for (n = 0; NULL != (np = getnatp(n)); n++) {
105         np->nat_money += upd_slmilcosts(np->nat_cnum, etu);
106     }
107 }
108
109 void
110 tax(struct sctstr *sp, struct natstr *np, int etu, long *pop, int *civ_tax,
111     int *uw_tax, int *mil_pay)
112 {
113     *civ_tax = 0;
114     *uw_tax = 0;
115     *mil_pay = 0;
116
117     if (!player->simulation)
118         populace(np, sp, etu);
119     *civ_tax = (int)(0.5 + sp->sct_item[I_CIVIL] * sp->sct_effic *
120                      etu * money_civ / 100);
121     /*
122      * captured civs only pay 1/4 taxes
123      */
124     if (sp->sct_own != sp->sct_oldown)
125         *civ_tax = *civ_tax / 4;
126     *uw_tax = (int)(0.5 + sp->sct_item[I_UW] * sp->sct_effic *
127                     etu * money_uw / 100);
128     *mil_pay = sp->sct_item[I_MILIT] * etu * money_mil;
129
130     /*
131      * only non-captured civs add to census for nation
132      */
133     if (sp->sct_oldown == sp->sct_own)
134         *pop += sp->sct_item[I_CIVIL];
135 }
136
137 int
138 upd_slmilcosts(natid n, int etu)
139 {
140     struct shpstr *sp;
141     struct lndstr *lp;
142     int mil = 0;
143     int totalmil = 0;
144     int mil_pay = 0;
145     int i;
146
147     for (i = 0; NULL != (sp = getshipp(i)); i++) {
148         if (!sp->shp_own || sp->shp_own != n)
149             continue;
150         if ((mil = sp->shp_item[I_MILIT]) > 0)
151             totalmil += mil;
152     }
153     for (i = 0; NULL != (lp = getlandp(i)); i++) {
154         if (!lp->lnd_own || lp->lnd_own != n)
155             continue;
156         if ((mil = lp->lnd_item[I_MILIT]) > 0)
157             totalmil += mil;
158     }
159     mil_pay = totalmil * etu * money_mil;
160     return (mil_pay);
161 }
162
163 int
164 bank_income(struct sctstr *sp, int etu)
165 {
166     return (int)(sp->sct_item[I_BAR] * etu * bankint * sp->sct_effic / 100);
167 }