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