2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * main.c: World update main function
29 * Known contributors to this file:
33 * Markus Armbruster, 2006-2011
38 #include <sys/resource.h>
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;
59 struct rusage rus1, rus2;
66 logerror("production update (%d etus)", etu);
67 getrusage(RUSAGE_SELF, &rus1);
68 game_record_update(time(NULL));
71 /* First, make sure all mobility is updated correctly. */
83 * set up all the variables which get used in the
84 * sector production routine (for producing education,
85 * happiness, and printing out the state of the nation)
87 memset(pops, 0, sizeof(pops));
88 memset(air_money, 0, sizeof(air_money));
89 memset(sea_money, 0, sizeof(sea_money));
90 memset(lnd_money, 0, sizeof(lnd_money));
92 for (n = 0; n < MAXNOC; n++) {
94 if (!(np = getnatp(n)))
96 money[n] = np->nat_money;
97 tpops[n] = count_pop(n);
100 logerror("preparing sectors...");
101 prepare_sects(etu, bp);
102 logerror("done preparing sectors.");
103 logerror("producing for countries...");
104 for (i = 0; i < MAXNOC; i++) {
105 long p_sect[SCT_BUDG_MAX+1][2];
107 memset(p_sect, 0, sizeof(p_sect));
108 if (!(np = getnatp(i)))
110 if (np->nat_stat == STAT_SANCT) {
113 np->nat_money += (int)(np->nat_reserve * money_res * etu);
116 prod_ship(etu, i, bp, 0);
117 prod_plane(etu, i, bp, 0);
118 prod_land(etu, i, bp, 0);
120 /* produce all sects */
121 produce_sect(i, etu, bp, p_sect);
124 prod_ship(etu, i, bp, 1);
125 prod_plane(etu, i, bp, 1);
126 prod_land(etu, i, bp, 1);
128 logerror("done producing for countries.");
135 /* Only update mobility for non-MOB_ACCESS here, since it doesn't
136 get done for MOB_ACCESS anyway during the update */
137 if (!opt_MOB_ACCESS) {
143 if (update_demand == UPD_DEMAND_SCHED
144 || update_demand == UPD_DEMAND_ASYNC)
145 update_removewants();
146 /* flush all mem file objects to disk */
153 delete_old_announcements();
155 delete_old_lostitems();
156 /* Clear all the telegram flags */
157 for (cn = 0; cn < MAXNOC; cn++)
158 clear_telegram_is_new(cn);
159 getrusage(RUSAGE_SELF, &rus2);
160 logerror("End update %g user %g system",
161 rus2.ru_utime.tv_sec + rus2.ru_utime.tv_usec / 1e6
162 - (rus1.ru_utime.tv_sec + rus1.ru_utime.tv_usec / 1e6),
163 rus2.ru_stime.tv_sec + rus2.ru_stime.tv_usec / 1e6
164 - (rus1.ru_stime.tv_sec + rus1.ru_stime.tv_usec / 1e6));