]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/main.c
Update copyright notice
[empserver] / src / lib / update / main.c
index 643b9d5117c697e0660420556ce491b45e57af47..80c9be1ffb726447d85896c3d1c88245e9a7fded 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  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
@@ -37,7 +37,6 @@
 
 #include <sys/resource.h>
 #include "empthread.h"
-#include "file.h"
 #include "game.h"
 #include "journal.h"
 #include "optlist.h"
 #include "unit.h"
 #include "update.h"
 
+/*
+ * Update is running.
+ * Can be used to suppress messages, or direct them to bulletins.
+ */
+int update_running;
+
 struct budget nat_budget[MAXNOC];
-int tpops[MAXNOC];
 
 void
 update_main(void)
@@ -58,6 +62,7 @@ update_main(void)
     int i;
     struct natstr *np;
 
+    update_running = 1;
     logerror("production update (%d etus)", etu);
     getrusage(RUSAGE_SELF, &rus1);
     game_record_update(time(NULL));
@@ -66,13 +71,9 @@ update_main(void)
     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();
@@ -87,47 +88,37 @@ update_main(void)
        if (!(np = getnatp(n)))
            continue;
        nat_budget[n].start_money = nat_budget[n].money = np->nat_money;
-       tpops[n] = count_pop(n);
     }
 
+    prep_ships(etu, NULL);
+    prep_planes(etu, NULL);
+    prep_lands(etu, NULL);
     logerror("preparing sectors...");
-    prepare_sects(etu);
+    prepare_sects(etu, NULL);
     logerror("done preparing sectors.");
-    logerror("producing for countries...");
-    for (i = 0; i < MAXNOC; i++) {
-       if (!(np = getnatp(i)))
-           continue;
-       if (np->nat_stat == STAT_SANCT) {
-           continue;
-       }
+    for (i = 0; i < MAXNOC; i++)
+       pay_reserve(getnatp(i), etu);
 
-       /* maintain units */
-       prod_ship(etu, i, NULL, 0);
-       prod_plane(etu, i, NULL, 0);
-       prod_land(etu, i, NULL, 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, NULL);
+    /* produce all sects */
+    produce_sect(etu, NULL);
 
-       /* build units */
-       prod_ship(etu, i, NULL, 1);
-       prod_plane(etu, i, NULL, 1);
-       prod_land(etu, i, NULL, 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);
+    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();
@@ -147,4 +138,5 @@ update_main(void)
             - (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;
 }