]> 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-2009, 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 files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future 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 <config.h>
37
38 #include "budg.h"
39 #include "item.h"
40 #include "land.h"
41 #include "path.h"
42 #include "player.h"
43 #include "ship.h"
44 #include "update.h"
45
46 void
47 prepare_sects(int etu, struct bp *bp)
48 {
49     struct sctstr *sp;
50     struct natstr *np;
51     int n, civ_tax, uw_tax, mil_pay;
52
53     memset(levels, 0, sizeof(levels));
54
55 /* Process all the fallout. */
56     if (opt_FALLOUT) {
57         if (!player->simulation) {
58             /* First, we determine which sectors to process fallout in */
59             for (n = 0; NULL != (sp = getsectid(n)); n++)
60                 sp->sct_updated = sp->sct_fallout != 0;
61             /* Next, we process the fallout there */
62             for (n = 0; NULL != (sp = getsectid(n)); n++)
63                 if (sp->sct_updated)
64                     do_fallout(sp, etu);
65             /* Next, we spread the fallout */
66             for (n = 0; NULL != (sp = getsectid(n)); n++)
67                 if (sp->sct_updated)
68                     spread_fallout(sp, etu);
69             /* Next, we decay the fallout */
70             for (n = 0; NULL != (sp = getsectid(n)); n++)
71                 if (sp->sct_fallout)
72                     decay_fallout(sp, etu);
73         }
74     }
75     for (n = 0; NULL != (sp = getsectid(n)); n++) {
76         sp->sct_updated = 0;
77
78         if (sp->sct_type == SCT_WATER)
79             continue;
80         bp_set_from_sect(bp, sp);
81         np = getnatp(sp->sct_own);
82
83 #ifdef DEBUG
84         if (np->nat_stat == STAT_SANCT)
85             logerror("Prepare.c: country in sanctuary skipped production");
86 #endif /* DEBUG */
87
88         if (np->nat_stat != STAT_SANCT) {
89             guerrilla(sp);
90             do_plague(sp, np, etu);
91             tax(sp, np, etu, &pops[sp->sct_own], &civ_tax, &uw_tax,
92                 &mil_pay);
93             np->nat_money += civ_tax + uw_tax + mil_pay;
94             if (sp->sct_type == SCT_BANK)
95                 np->nat_money += bank_income(sp, etu);
96         }
97     }
98     for (n = 0; NULL != (np = getnatp(n)); n++) {
99         np->nat_money += upd_slmilcosts(np->nat_cnum, etu);
100     }
101 }
102
103 void
104 tax(struct sctstr *sp, struct natstr *np, int etu, long *pop, int *civ_tax,
105     int *uw_tax, int *mil_pay)
106 {
107     *civ_tax = 0;
108     *uw_tax = 0;
109     *mil_pay = 0;
110
111     if (!player->simulation)
112         populace(np, sp, etu);
113     *civ_tax = (int)(0.5 + sp->sct_item[I_CIVIL] * sp->sct_effic *
114                      etu * money_civ / 100);
115     /*
116      * captured civs only pay 1/4 taxes
117      */
118     if (sp->sct_own != sp->sct_oldown)
119         *civ_tax = *civ_tax / 4;
120     *uw_tax = (int)(0.5 + sp->sct_item[I_UW] * sp->sct_effic *
121                     etu * money_uw / 100);
122     *mil_pay = sp->sct_item[I_MILIT] * etu * money_mil;
123
124     /*
125      * only non-captured civs add to census for nation
126      */
127     if (sp->sct_oldown == sp->sct_own)
128         *pop += sp->sct_item[I_CIVIL];
129 }
130
131 int
132 upd_slmilcosts(natid n, int etu)
133 {
134     struct shpstr *sp;
135     struct lndstr *lp;
136     int mil = 0;
137     int totalmil = 0;
138     int mil_pay = 0;
139     int i;
140
141     for (i = 0; NULL != (sp = getshipp(i)); i++) {
142         if (!sp->shp_own || sp->shp_own != n)
143             continue;
144         if ((mil = sp->shp_item[I_MILIT]) > 0)
145             totalmil += mil;
146     }
147     for (i = 0; NULL != (lp = getlandp(i)); i++) {
148         if (!lp->lnd_own || lp->lnd_own != n)
149             continue;
150         if ((mil = lp->lnd_item[I_MILIT]) > 0)
151             totalmil += mil;
152     }
153     mil_pay = totalmil * etu * money_mil;
154     return mil_pay;
155 }
156
157 int
158 bank_income(struct sctstr *sp, int etu)
159 {
160     return (int)(sp->sct_item[I_BAR] * etu * bankint * sp->sct_effic / 100);
161 }