/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* ---
*
* main.c: World update main function
- *
+ *
* Known contributors to this file:
* Dave Pare, 1994
* Steve McClure, 1996
* Doug Hay, 1998
+ * Markus Armbruster, 2006-2009
*/
#include <config.h>
-#include "misc.h"
-#include "nat.h"
-#include "file.h"
-#include "sect.h"
-#include "player.h"
-#include "empthread.h"
#include "budg.h"
-#include "player.h"
-#include "update.h"
-#include "common.h"
-#include "optlist.h"
+#include "empthread.h"
+#include "game.h"
#include "journal.h"
+#include "player.h"
#include "server.h"
-#include <stdlib.h>
-#if !defined(_WIN32)
-#include <sys/time.h>
-#endif
+#include "unit.h"
+#include "update.h"
long money[MAXNOC];
long pops[MAXNOC];
long air_money[MAXNOC];
long tpops[MAXNOC];
-int update_pending = 0;
-
-/*ARGSUSED*/
void
-update_main(void *unused)
+update_main(void)
{
int etu = etu_per_update;
int n;
- int x;
- int *bp;
+ int i;
+ struct bp *bp;
int cn, cn2, rel;
struct natstr *cnp;
struct natstr *np;
- if (CANT_HAPPEN(!update_pending))
- update_pending = 1;
+ logerror("production update (%d etus)", etu);
+ game_record_update(time(NULL));
+ journal_update(etu);
/* First, make sure all mobility is updated correctly. */
if (opt_MOB_ACCESS) {
- mob_ship(etu);
- mob_sect(etu);
- mob_plane(etu);
- mob_land(etu);
+ mob_ship();
+ mob_sect();
+ mob_plane();
+ mob_land();
}
- player->proc = empth_self();
- player->cnum = 0;
- player->god = 1;
+
+ if (opt_AUTO_POWER)
+ update_power();
+
/*
* set up all the variables which get used in the
* sector production routine (for producing education,
* happiness, and printing out the state of the nation)
*/
- logerror("production update (%d etus)", etu);
- journal_update(etu);
memset(pops, 0, sizeof(pops));
memset(air_money, 0, sizeof(air_money));
memset(sea_money, 0, sizeof(sea_money));
memset(lnd_money, 0, sizeof(lnd_money));
- bp = calloc(WORLD_X * WORLD_Y * 7, sizeof(int));
+ bp = bp_alloc();
for (n = 0; n < MAXNOC; n++) {
money[n] = 0;
if (!(np = getnatp(n)))
prepare_sects(etu, bp);
logerror("done preparing sectors.");
logerror("producing for countries...");
- for (x = 0; x < MAXNOC; x++) {
- long p_sect[SCT_TYPE_MAX+2][2];
+ for (i = 0; i < MAXNOC; i++) {
+ long p_sect[SCT_BUDG_MAX+1][2];
memset(p_sect, 0, sizeof(p_sect));
- mil_dbl_pay = 0;
- if (!(np = getnatp(x)))
+ if (!(np = getnatp(i)))
continue;
if (np->nat_stat == STAT_SANCT) {
#ifdef DEBUG
- logerror("Country %i is in sanctuary and did not update", x);
+ logerror("Country %i is in sanctuary and did not update", i);
#endif
continue;
}
np->nat_money += (int)(np->nat_reserve * money_res * etu);
/* maintain units */
- prod_ship(etu, x, bp, 0);
- prod_plane(etu, x, bp, 0);
- prod_land(etu, x, bp, 0);
+ prod_ship(etu, i, bp, 0);
+ prod_plane(etu, i, bp, 0);
+ prod_land(etu, i, bp, 0);
/* produce all sects */
- produce_sect(x, etu, bp, p_sect);
+ produce_sect(i, etu, bp, p_sect);
/* build units */
- prod_ship(etu, x, bp, 1);
- prod_plane(etu, x, bp, 1);
- prod_land(etu, x, bp, 1);
+ prod_ship(etu, i, bp, 1);
+ prod_plane(etu, i, bp, 1);
+ prod_land(etu, i, bp, 1);
}
logerror("done producing for countries.");
prod_nat(etu);
age_levels(etu);
free(bp);
- /*flushwu(); */
if (opt_SLOW_WAR) {
/* Update war declarations */
/* MOBILIZATION->SITZKRIEG->AT_WAR */
for (cn = 1; cn < MAXNOC; cn++) {
- if ((cnp = getnatp(cn)) == 0)
+ if (!(cnp = getnatp(cn)))
break;
for (cn2 = 1; cn2 < MAXNOC; cn2++) {
if (cn2 == cn)
/* Only update mobility for non-MOB_ACCESS here, since it doesn't
get done for MOB_ACCESS anyway during the update */
if (!opt_MOB_ACCESS) {
- mob_ship(etu);
- mob_sect(etu);
- mob_plane(etu);
- mob_land(etu);
+ mob_ship();
+ mob_sect();
+ mob_plane();
+ mob_land();
}
- if (opt_DEMANDUPDATE)
+ if (update_demand == UPD_DEMAND_SCHED
+ || update_demand == UPD_DEMAND_ASYNC)
update_removewants();
/* flush all mem file objects to disk */
ef_flush(EF_NATION);
ef_flush(EF_SHIP);
ef_flush(EF_PLANE);
ef_flush(EF_LAND);
+ unit_cargo_init();
delete_old_announcements();
delete_old_news();
+ delete_old_lostitems();
/* Clear all the telegram flags */
for (cn = 0; cn < MAXNOC; cn++)
clear_telegram_is_new(cn);
- update_pending = 0;
logerror("End update");
- player_delete(player);
- empth_exit();
- /*NOTREACHED*/
}