2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2016, 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-2016
38 #include <sys/resource.h>
39 #include "empthread.h"
44 #include "prototypes.h"
51 * Can be used to suppress messages, or direct them to bulletins.
55 struct budget nat_budget[MAXNOC];
60 int etu = etu_per_update;
61 struct rusage rus1, rus2;
67 logerror("production update (%d etus)", etu);
68 getrusage(RUSAGE_SELF, &rus1);
69 game_record_update(time(NULL));
71 /* Ensure back-to-back production reports are separate: */
72 for (n = 0; n < MAXNOC; n++)
73 clear_telegram_is_new(n);
75 /* Credit the turn's remaining MOB_ACCESS mobility */
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(nat_budget, 0, sizeof(nat_budget));
88 for (n = 0; n < MAXNOC; n++) {
89 if (!(np = getnatp(n)))
91 nat_budget[n].start_money = nat_budget[n].money = np->nat_money;
94 logerror("preparing sectors...");
95 prepare_sects(etu, NULL);
96 logerror("done preparing sectors.");
100 for (i = 0; i < MAXNOC; i++)
101 pay_reserve(getnatp(i), etu);
103 logerror("producing for countries...");
105 prod_ship(etu, NULL, 0);
106 prod_plane(etu, NULL, 0);
107 prod_land(etu, NULL, 0);
109 /* produce all sects */
110 for (i = 0; i < MAXNOC; i++)
111 produce_sect(getnatp(i), etu, NULL);
114 prod_ship(etu, NULL, 1);
115 prod_plane(etu, NULL, 1);
116 prod_land(etu, NULL, 1);
117 logerror("done producing for countries.");
124 if (update_demand == UPD_DEMAND_SCHED
125 || update_demand == UPD_DEMAND_ASYNC)
126 update_removewants();
127 /* flush all mem file objects to disk */
134 delete_old_announcements();
136 delete_old_lostitems();
137 getrusage(RUSAGE_SELF, &rus2);
138 logerror("End update %g user %g system",
139 rus2.ru_utime.tv_sec + rus2.ru_utime.tv_usec / 1e6
140 - (rus1.ru_utime.tv_sec + rus1.ru_utime.tv_usec / 1e6),
141 rus2.ru_stime.tv_sec + rus2.ru_stime.tv_usec / 1e6
142 - (rus1.ru_stime.tv_sec + rus1.ru_stime.tv_usec / 1e6));