2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * main.c: World update main function
30 * Known contributors to this file:
41 #include "empthread.h"
56 long sea_money[MAXNOC];
57 long lnd_money[MAXNOC];
58 long air_money[MAXNOC];
61 extern int mil_dbl_pay;
62 int update_pending = 0;
64 static void do_prod(int, int, int, int *, long int (*)[2], int *, int *,
65 int *, int *, int *, int *);
69 update_main(void *argv)
71 extern int etu_per_update;
72 extern double money_res;
73 int etu = etu_per_update;
81 /* First, make sure all mobility is updated correctly. */
89 player->proc = empth_self();
93 * set up all the variables which get used in the
94 * sector production routine (for producing education,
95 * happiness, and printing out the state of the nation)
97 logerror("production update (%d etus)", etu);
98 memset(pops, 0, sizeof(pops));
99 memset(air_money, 0, sizeof(air_money));
100 memset(sea_money, 0, sizeof(sea_money));
101 memset(lnd_money, 0, sizeof(lnd_money));
102 bp = (int *)calloc(WORLD_X * WORLD_Y * 7, sizeof(int));
103 for (n = 0; n < MAXNOC; n++) {
105 if ((np = getnatp(n)) == (struct natstr *)0)
107 money[n] = np->nat_money;
108 tpops[n] = count_pop(n);
111 logerror("preparing sectors...");
112 prepare_sects(etu, bp);
113 logerror("done preparing sectors.");
114 logerror("producing for countries...");
115 for (x = 0; x < MAXNOC; x++) {
116 int y, z, sb = 0, sm = 0, pb = 0, pm = 0, lm = 0, lb = 0;
117 long p_sect[SCT_MAXDEF + 1][2];
119 memset(p_sect, 0, sizeof(p_sect));
121 if ((np = getnatp(x)) == (struct natstr *)0)
123 if (np->nat_stat & STAT_SANCT) {
125 logerror("Country %i is in sanctuary and did not update", x);
129 np->nat_money += (int)(np->nat_reserve * money_res * etu);
131 for (y = 1; y < SCT_MAXDEF + 8; y++) {
132 for (z = 0; z < SCT_MAXDEF + 8; z++) {
133 if (np->nat_priorities[z] == y) {
134 do_prod(z, etu, x, bp, p_sect,
135 &sb, &sm, &pb, &pm, &lb, &lm);
139 /* 0 is maintain, 1 is build */
141 prod_ship(etu, x, bp, 0);
143 prod_ship(etu, x, bp, 1);
145 prod_plane(etu, x, bp, 0);
147 prod_plane(etu, x, bp, 1);
149 prod_land(etu, x, bp, 0);
151 prod_land(etu, x, bp, 1);
153 /* produce all sects that haven't produced yet */
154 produce_sect(x, etu, bp, p_sect, -1);
155 np->nat_money -= p_sect[SCT_CAPIT][1];
157 logerror("done producing for countries.");
165 /* Update war declarations */
166 /* MOBILIZATION->SITZKRIEG->AT_WAR */
167 for (cn = 1; cn < MAXNOC; cn++) {
168 if ((cnp = getnatp(cn)) == 0)
170 for (cn2 = 1; cn2 < MAXNOC; cn2++) {
173 rel = getrel(cnp, cn2);
174 if (rel == MOBILIZATION) {
176 setrel(cn, cn2, rel);
177 } else if (rel == SITZKRIEG) {
179 setrel(cn, cn2, rel);
185 if (opt_LOSE_CONTACT) {
186 for (cn = 1; cn < MAXNOC; cn++) {
187 if ((cnp = getnatp(cn)) != NULL)
191 /* Only update mobility for non-MOB_ACCESS here, since it doesn't
192 get done for MOB_ACCESS anyway during the update */
193 if (!opt_MOB_ACCESS) {
199 if (opt_DEMANDUPDATE)
200 update_removewants();
201 /* flush all mem file objects to disk */
207 delete_old_announcements();
208 /* Clear all the telegram flags */
209 for (cn = 0; cn < MAXNOC; cn++)
210 clear_telegram_is_new(cn);
212 logerror("End update");
213 player_delete(player);
219 do_prod(int sector_type, int etu, int n, int *bp, long int (*p_sect)[2],
220 int *ship_build, int *ship_maint, int *plane_build,
221 int *plane_maint, int *land_build, int *land_maint)
223 extern double money_mil;
228 if (sector_type == PRI_SMAINT) {
229 prod_ship(etu, n, bp, 0);
231 } else if (sector_type == PRI_SBUILD) {
232 prod_ship(etu, n, bp, 1);
234 } else if (sector_type == PRI_PMAINT) {
235 prod_plane(etu, n, bp, 0);
237 } else if (sector_type == PRI_PBUILD) {
238 prod_plane(etu, n, bp, 1);
240 } else if (sector_type == PRI_LMAINT) {
242 np->nat_money -= (int)(money_mil * etu * mil_dbl_pay);
243 prod_land(etu, n, bp, 0);
245 } else if (sector_type == PRI_LBUILD) {
246 prod_land(etu, n, bp, 1);
249 produce_sect(n, etu, bp, p_sect, sector_type);