2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
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.
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.
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
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.
28 * main.c: World update main function
30 * Known contributors to this file:
43 #include "empthread.h"
57 long sea_money[MAXNOC];
58 long lnd_money[MAXNOC];
59 long air_money[MAXNOC];
62 int update_pending = 0;
66 update_main(void *unused)
68 int etu = etu_per_update;
76 if (CANT_HAPPEN(!update_pending))
79 /* First, make sure all mobility is updated correctly. */
86 player->proc = empth_self();
90 * set up all the variables which get used in the
91 * sector production routine (for producing education,
92 * happiness, and printing out the state of the nation)
94 logerror("production update (%d etus)", etu);
95 memset(pops, 0, sizeof(pops));
96 memset(air_money, 0, sizeof(air_money));
97 memset(sea_money, 0, sizeof(sea_money));
98 memset(lnd_money, 0, sizeof(lnd_money));
99 bp = calloc(WORLD_X * WORLD_Y * 7, sizeof(int));
100 for (n = 0; n < MAXNOC; n++) {
102 if (!(np = getnatp(n)))
104 money[n] = np->nat_money;
105 tpops[n] = count_pop(n);
108 logerror("preparing sectors...");
109 prepare_sects(etu, bp);
110 logerror("done preparing sectors.");
111 logerror("producing for countries...");
112 for (x = 0; x < MAXNOC; x++) {
114 long p_sect[SCT_MAXDEF+1][2];
116 memset(p_sect, 0, sizeof(p_sect));
118 if (!(np = getnatp(x)))
120 if (np->nat_stat == STAT_SANCT) {
122 logerror("Country %i is in sanctuary and did not update", x);
126 np->nat_money += (int)(np->nat_reserve * money_res * etu);
128 /* 0 is maintain, 1 is build */
129 prod_ship(etu, x, bp, 0);
130 prod_ship(etu, x, bp, 1);
131 prod_plane(etu, x, bp, 0);
132 prod_plane(etu, x, bp, 1);
133 prod_land(etu, x, bp, 0);
134 prod_land(etu, x, bp, 1);
136 /* produce all sects that haven't produced yet */
137 produce_sect(x, etu, bp, p_sect);
138 np->nat_money -= p_sect[SCT_CAPIT][1];
140 logerror("done producing for countries.");
148 /* Update war declarations */
149 /* MOBILIZATION->SITZKRIEG->AT_WAR */
150 for (cn = 1; cn < MAXNOC; cn++) {
151 if ((cnp = getnatp(cn)) == 0)
153 for (cn2 = 1; cn2 < MAXNOC; cn2++) {
156 rel = getrel(cnp, cn2);
157 if (rel == MOBILIZATION) {
159 setrel(cn, cn2, rel);
160 } else if (rel == SITZKRIEG) {
162 setrel(cn, cn2, rel);
167 /* Only update mobility for non-MOB_ACCESS here, since it doesn't
168 get done for MOB_ACCESS anyway during the update */
169 if (!opt_MOB_ACCESS) {
175 if (opt_DEMANDUPDATE)
176 update_removewants();
177 /* flush all mem file objects to disk */
183 delete_old_announcements();
185 /* Clear all the telegram flags */
186 for (cn = 0; cn < MAXNOC; cn++)
187 clear_telegram_is_new(cn);
189 logerror("End update");
190 player_delete(player);