]> git.pond.sub.org Git - empserver/blob - src/lib/update/prepare.c
Add some missing declarations to headers. Remove some redundant
[empserver] / src / lib / update / prepare.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, 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 <math.h>
37 #include "misc.h"
38 #include "var.h"
39 #include "sect.h"
40 #include "nat.h"
41 #include "item.h"
42 #include "news.h"
43 #include "file.h"
44 #include "xy.h"
45 #include "path.h"
46 #include "optlist.h"
47 #include "budg.h"
48 #include "player.h"
49 #include "ship.h"
50 #include "land.h"
51 #include "update.h"
52 #include "gen.h"
53 #include "common.h"
54
55 void
56 prepare_sects(int etu, int *bp)
57 {
58     register struct sctstr *sp;
59     struct natstr *np;
60     int n, civ_tax, uw_tax, mil_pay;
61
62     memset(levels, 0, sizeof(levels));
63
64 /* Process all the fallout. */
65     if (opt_FALLOUT) {
66         if (!player->simulation) {
67             /* First, we determine which sectors to process fallout in */
68             for (n = 0; NULL != (sp = getsectid(n)); n++) {
69                 if (getvar(V_FALLOUT, (s_char *)sp, EF_SECTOR))
70                     sp->sct_updated = 1;
71                 else
72                     sp->sct_updated = 0;
73             }
74             /* Next, we process the fallout there */
75             for (n = 0; NULL != (sp = getsectid(n)); n++)
76                 if (sp->sct_updated)
77                     do_fallout(sp, etu);
78             /* Next, we spread the fallout */
79             for (n = 0; NULL != (sp = getsectid(n)); n++)
80                 if (sp->sct_updated)
81                     spread_fallout(sp, etu);
82             /* Next, we decay the fallout */
83             for (n = 0; NULL != (sp = getsectid(n)); n++)
84                 if (getvar(V_FALLOUT, (s_char *)sp, EF_SECTOR))
85                     decay_fallout(sp, etu);
86         }
87     }
88     for (n = 0; NULL != (sp = getsectid(n)); n++) {
89         sp->sct_updated = 0;
90
91         if (sp->sct_type == SCT_WATER)
92             continue;
93         fill_update_array(bp, sp);
94         np = getnatp(sp->sct_own);
95
96 #ifdef DEBUG
97         if (np->nat_stat & STAT_SANCT)
98             logerror("Prepare.c: country in sanctuary skipped production");
99 #endif /* DEBUG */
100
101         if (!(np->nat_stat & STAT_SANCT)) {
102             guerrilla(sp);
103             do_plague(sp, np, etu);
104             tax(sp, np, etu, &pops[sp->sct_own], &civ_tax, &uw_tax,
105                 &mil_pay);
106             np->nat_money += civ_tax + uw_tax + mil_pay;
107             if (sp->sct_type == SCT_BANK)
108                 np->nat_money += bank_income(sp, etu);
109         }
110     }
111     for (n = 0; NULL != (np = getnatp(n)); n++) {
112         np->nat_money += upd_slmilcosts(np->nat_cnum, etu);
113     }
114 }
115
116 void
117 tax(struct sctstr *sp, struct natstr *np, int etu, long *pop, int *civ_tax,
118     int *uw_tax, int *mil_pay)
119 {
120     int vec[I_MAX + 1];
121
122     *civ_tax = 0;
123     *uw_tax = 0;
124     *mil_pay = 0;
125     if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0)
126         return;
127
128     if (!player->simulation)
129         populace(np, sp, vec, etu);
130     *civ_tax = (int)(0.5 + vec[I_CIVIL] * sp->sct_effic *
131                      etu * money_civ / 100);
132     /*
133      * captured civs only pay 1/4 taxes
134      */
135     if (sp->sct_own != sp->sct_oldown)
136         *civ_tax = *civ_tax / 4;
137     *uw_tax = (int)(0.5 + vec[I_UW] * sp->sct_effic *
138                     etu * money_uw / 100);
139     *mil_pay = vec[I_MILIT] * etu * money_mil;
140
141     /*
142      * only non-captured civs add to census for nation
143      */
144     if (sp->sct_oldown == sp->sct_own)
145         *pop += vec[I_CIVIL];
146 }
147
148 int
149 upd_slmilcosts(natid n, int etu)
150 {
151     struct shpstr *sp;
152     struct lndstr *lp;
153     int mil = 0;
154     int totalmil = 0;
155     int mil_pay = 0;
156     int i;
157
158     for (i = 0; NULL != (sp = getshipp(i)); i++) {
159         if (!sp->shp_own || sp->shp_own != n)
160             continue;
161         if ((mil = getvar(V_MILIT, (s_char *)sp, EF_SHIP)) > 0)
162             totalmil += mil;
163     }
164     for (i = 0; NULL != (lp = getlandp(i)); i++) {
165         if (!lp->lnd_own || lp->lnd_own != n)
166             continue;
167         if ((mil = getvar(V_MILIT, (s_char *)lp, EF_LAND)) > 0)
168             totalmil += mil;
169     }
170     mil_pay = totalmil * etu * money_mil;
171     return (mil_pay);
172 }
173
174 int
175 bank_income(struct sctstr *sp, int etu)
176 {
177     int vec[I_MAX + 1];
178
179     if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0)
180         return 0;
181     else
182         return (int)(vec[I_BAR] * etu * bankint * sp->sct_effic / 100);
183 }