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
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:
34 * Markus Armbruster, 2006-2009
40 #include "empthread.h"
50 long sea_money[MAXNOC];
51 long lnd_money[MAXNOC];
52 long air_money[MAXNOC];
58 int etu = etu_per_update;
66 logerror("production update (%d etus)", etu);
67 game_record_update(time(NULL));
70 /* First, make sure all mobility is updated correctly. */
82 * set up all the variables which get used in the
83 * sector production routine (for producing education,
84 * happiness, and printing out the state of the nation)
86 memset(pops, 0, sizeof(pops));
87 memset(air_money, 0, sizeof(air_money));
88 memset(sea_money, 0, sizeof(sea_money));
89 memset(lnd_money, 0, sizeof(lnd_money));
91 for (n = 0; n < MAXNOC; n++) {
93 if (!(np = getnatp(n)))
95 money[n] = np->nat_money;
96 tpops[n] = count_pop(n);
99 logerror("preparing sectors...");
100 prepare_sects(etu, bp);
101 logerror("done preparing sectors.");
102 logerror("producing for countries...");
103 for (i = 0; i < MAXNOC; i++) {
104 long p_sect[SCT_BUDG_MAX+1][2];
106 memset(p_sect, 0, sizeof(p_sect));
107 if (!(np = getnatp(i)))
109 if (np->nat_stat == STAT_SANCT) {
111 logerror("Country %i is in sanctuary and did not update", i);
115 np->nat_money += (int)(np->nat_reserve * money_res * etu);
118 prod_ship(etu, i, bp, 0);
119 prod_plane(etu, i, bp, 0);
120 prod_land(etu, i, bp, 0);
122 /* produce all sects */
123 produce_sect(i, etu, bp, p_sect);
126 prod_ship(etu, i, bp, 1);
127 prod_plane(etu, i, bp, 1);
128 prod_land(etu, i, bp, 1);
130 logerror("done producing for countries.");
137 /* Update war declarations */
138 /* MOBILIZATION->SITZKRIEG->AT_WAR */
139 for (cn = 1; cn < MAXNOC; cn++) {
140 if (!(cnp = getnatp(cn)))
142 for (cn2 = 1; cn2 < MAXNOC; cn2++) {
145 rel = getrel(cnp, cn2);
146 if (rel == MOBILIZATION) {
148 setrel(cn, cn2, rel);
149 } else if (rel == SITZKRIEG) {
151 setrel(cn, cn2, rel);
156 /* Only update mobility for non-MOB_ACCESS here, since it doesn't
157 get done for MOB_ACCESS anyway during the update */
158 if (!opt_MOB_ACCESS) {
164 if (update_demand == UPD_DEMAND_SCHED
165 || update_demand == UPD_DEMAND_ASYNC)
166 update_removewants();
167 /* flush all mem file objects to disk */
174 delete_old_announcements();
176 delete_old_lostitems();
177 /* Clear all the telegram flags */
178 for (cn = 0; cn < MAXNOC; cn++)
179 clear_telegram_is_new(cn);
180 logerror("End update");