/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2017, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure, Markus Armbruster
*
* Empire is free software: you can redistribute it and/or modify
#include <config.h>
#include <sys/resource.h>
-#include "budg.h"
#include "empthread.h"
#include "game.h"
#include "journal.h"
+#include "optlist.h"
+#include "prototypes.h"
#include "server.h"
#include "unit.h"
#include "update.h"
-int money[MAXNOC];
-int pops[MAXNOC];
-int sea_money[MAXNOC];
-int lnd_money[MAXNOC];
-int air_money[MAXNOC];
-int tpops[MAXNOC];
+/*
+ * Update is running.
+ * Can be used to suppress messages, or direct them to bulletins.
+ */
+int update_running;
+
+struct budget nat_budget[MAXNOC];
void
update_main(void)
struct rusage rus1, rus2;
int n;
int i;
- struct bp *bp;
struct natstr *np;
+ update_running = 1;
logerror("production update (%d etus)", etu);
getrusage(RUSAGE_SELF, &rus1);
game_record_update(time(NULL));
for (n = 0; n < MAXNOC; n++)
clear_telegram_is_new(n);
- /* First, make sure all mobility is updated correctly. */
- if (opt_MOB_ACCESS) {
- mob_ship();
- mob_sect();
- mob_plane();
- mob_land();
- }
+ /* Credit the turn's remaining MOB_ACCESS mobility */
+ if (opt_MOB_ACCESS)
+ mob_access_all();
if (opt_AUTO_POWER)
update_power();
* sector production routine (for producing education,
* happiness, and printing out the state of the nation)
*/
- 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 = bp_alloc();
+ memset(nat_budget, 0, sizeof(nat_budget));
for (n = 0; n < MAXNOC; n++) {
- money[n] = 0;
if (!(np = getnatp(n)))
continue;
- money[n] = np->nat_money;
- tpops[n] = count_pop(n);
+ nat_budget[n].start_money = nat_budget[n].money = np->nat_money;
}
+ prep_ships(etu, NULL);
+ prep_planes(etu, NULL);
+ prep_lands(etu, NULL);
logerror("preparing sectors...");
- prepare_sects(etu, bp);
+ prepare_sects(etu, NULL);
logerror("done preparing sectors.");
- logerror("producing for countries...");
- for (i = 0; i < MAXNOC; i++) {
- int p_sect[SCT_BUDG_MAX+1][2];
+ for (i = 0; i < MAXNOC; i++)
+ pay_reserve(getnatp(i), etu);
- memset(p_sect, 0, sizeof(p_sect));
- if (!(np = getnatp(i)))
- continue;
- if (np->nat_stat == STAT_SANCT) {
- continue;
- }
- np->nat_money += (int)(np->nat_reserve * money_res * etu);
-
- /* maintain units */
- prod_ship(etu, i, bp, 0);
- prod_plane(etu, i, bp, 0);
- prod_land(etu, i, bp, 0);
+ logerror("producing for countries...");
+ /* maintain units */
+ prod_ship(etu, NULL, 0);
+ prod_plane(etu, NULL, 0);
+ prod_land(etu, NULL, 0);
- /* produce all sects */
- produce_sect(np, etu, bp, p_sect);
+ /* produce all sects */
+ produce_sect(etu, NULL);
- /* build units */
- prod_ship(etu, i, bp, 1);
- prod_plane(etu, i, bp, 1);
- prod_land(etu, i, bp, 1);
- }
+ /* build units */
+ prod_ship(etu, NULL, 1);
+ prod_plane(etu, NULL, 1);
+ prod_land(etu, NULL, 1);
logerror("done producing for countries.");
finish_sects(etu);
prod_nat(etu);
age_levels(etu);
- free(bp);
+ mob_inc_all(etu);
- /* 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();
- mob_sect();
- mob_plane();
- mob_land();
- }
if (update_demand == UPD_DEMAND_SCHED
|| update_demand == UPD_DEMAND_ASYNC)
update_removewants();
- (rus1.ru_utime.tv_sec + rus1.ru_utime.tv_usec / 1e6),
rus2.ru_stime.tv_sec + rus2.ru_stime.tv_usec / 1e6
- (rus1.ru_stime.tv_sec + rus1.ru_stime.tv_usec / 1e6));
+ update_running = 0;
}