]> git.pond.sub.org Git - empserver/blob - src/lib/update/main.c
(opt_DEMANDUPDATE): Remove. Deities can use update_demandpolicy to
[empserver] / src / lib / update / main.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2007, 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  *  main.c: World update main function
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1994
32  *     Steve McClure, 1996
33  *     Doug Hay, 1998
34  */
35
36 #include <config.h>
37
38 #include "budg.h"
39 #include "empthread.h"
40 #include "journal.h"
41 #include "player.h"
42 #include "server.h"
43 #include "update.h"
44 #include "wantupd.h"
45
46 long money[MAXNOC];
47 long pops[MAXNOC];
48 long sea_money[MAXNOC];
49 long lnd_money[MAXNOC];
50 long air_money[MAXNOC];
51 long tpops[MAXNOC];
52
53 void
54 update_main(void)
55 {
56     int etu = etu_per_update;
57     int n;
58     int x;
59     struct bp *bp;
60     int cn, cn2, rel;
61     struct natstr *cnp;
62     struct natstr *np;
63
64     logerror("production update (%d etus)", etu);
65     journal_update(etu);
66
67     /* First, make sure all mobility is updated correctly. */
68     if (opt_MOB_ACCESS) {
69         mob_ship(etu);
70         mob_sect(etu);
71         mob_plane(etu);
72         mob_land(etu);
73     }
74
75     if (opt_AUTO_POWER)
76         update_power();
77
78     /*
79      * set up all the variables which get used in the
80      * sector production routine (for producing education,
81      * happiness, and printing out the state of the nation)
82      */
83     memset(pops, 0, sizeof(pops));
84     memset(air_money, 0, sizeof(air_money));
85     memset(sea_money, 0, sizeof(sea_money));
86     memset(lnd_money, 0, sizeof(lnd_money));
87     bp = bp_alloc();
88     for (n = 0; n < MAXNOC; n++) {
89         money[n] = 0;
90         if (!(np = getnatp(n)))
91             continue;
92         money[n] = np->nat_money;
93         tpops[n] = count_pop(n);
94     }
95
96     logerror("preparing sectors...");
97     prepare_sects(etu, bp);
98     logerror("done preparing sectors.");
99     logerror("producing for countries...");
100     for (x = 0; x < MAXNOC; x++) {
101         long p_sect[SCT_TYPE_MAX+2][2];
102
103         memset(p_sect, 0, sizeof(p_sect));
104         if (!(np = getnatp(x)))
105             continue;
106         if (np->nat_stat == STAT_SANCT) {
107 #ifdef DEBUG
108             logerror("Country %i is in sanctuary and did not update", x);
109 #endif
110             continue;
111         }
112         np->nat_money += (int)(np->nat_reserve * money_res * etu);
113
114         /* maintain units */
115         prod_ship(etu, x, bp, 0);
116         prod_plane(etu, x, bp, 0);
117         prod_land(etu, x, bp, 0);
118
119         /* produce all sects */
120         produce_sect(x, etu, bp, p_sect);
121
122         /* build units */
123         prod_ship(etu, x, bp, 1);
124         prod_plane(etu, x, bp, 1);
125         prod_land(etu, x, bp, 1);
126     }
127     logerror("done producing for countries.");
128
129     finish_sects(etu);
130     prod_nat(etu);
131     age_levels(etu);
132     free(bp);
133     /*flushwu(); */
134     if (opt_SLOW_WAR) {
135         /* Update war declarations */
136         /* MOBILIZATION->SITZKRIEG->AT_WAR */
137         for (cn = 1; cn < MAXNOC; cn++) {
138             if ((cnp = getnatp(cn)) == 0)
139                 break;
140             for (cn2 = 1; cn2 < MAXNOC; cn2++) {
141                 if (cn2 == cn)
142                     continue;
143                 rel = getrel(cnp, cn2);
144                 if (rel == MOBILIZATION) {
145                     rel = SITZKRIEG;
146                     setrel(cn, cn2, rel);
147                 } else if (rel == SITZKRIEG) {
148                     rel = AT_WAR;
149                     setrel(cn, cn2, rel);
150                 }
151             }
152         }
153     }
154     /* Only update mobility for non-MOB_ACCESS here, since it doesn't
155        get done for MOB_ACCESS anyway during the update */
156     if (!opt_MOB_ACCESS) {
157         mob_ship(etu);
158         mob_sect(etu);
159         mob_plane(etu);
160         mob_land(etu);
161     }
162     if (update_demandpolicy != UDDEM_DISABLE)
163         update_removewants();
164     /* flush all mem file objects to disk */
165     ef_flush(EF_NATION);
166     ef_flush(EF_SECTOR);
167     ef_flush(EF_SHIP);
168     ef_flush(EF_PLANE);
169     ef_flush(EF_LAND);
170     delete_old_announcements();
171     delete_old_news();
172     /* Clear all the telegram flags */
173     for (cn = 0; cn < MAXNOC; cn++)
174         clear_telegram_is_new(cn);
175     logerror("End update");
176 }