]> git.pond.sub.org Git - empserver/commitdiff
update: Separate MOB_ACCESS from normal mobility update
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 20 Jun 2016 17:47:15 +0000 (19:47 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 18:08:30 +0000 (20:08 +0200)
The update uses mob_sect(), mob_ship(), mob_plane() and mob_land() for
two related, but different jobs: to give the previous turn's remaining
MOB_ACCESS mobility, and to give this update's new mobility.  The two
were probably conflated in an attempt to share code, but it actually
just complicates things.

Collect the MOB_ACCESS code in new function mob_access_all(), and the
normal mobility update code in new function mob_inc_all().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/update.h
src/lib/update/main.c
src/lib/update/mobility.c

index f0129191f3c74d5e0c1255df3e20bb062167c123..b1d743403f3d60c979d917b9d136da693302f178 100644 (file)
@@ -103,14 +103,12 @@ extern void prod_land(int, int, struct bp *, int);
 /* material.c */
 extern int get_materials(struct sctstr *, short[], int);
 /* mobility.c */
-extern void mob_sect(void);
-extern void mob_ship(void);
-extern void mob_land(void);
-extern void mob_plane(void);
+extern void mob_inc_all(int);
 extern void sct_do_upd_mob(struct sctstr *sp);
 extern void shp_do_upd_mob(struct shpstr *sp);
 extern void lnd_do_upd_mob(struct lndstr *lp);
 extern void pln_do_upd_mob(struct plnstr *pp);
+extern void mob_access_all(void);
 /* move_sat.c */
 extern void move_sat(struct plnstr *);
 /* nat.c */
index cb1cf2957f5a5ec4226cfbcb082c096ff219d511..e71da43602700ad4b4405ca4c2d0207018c6df86 100644 (file)
@@ -65,13 +65,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();
@@ -117,15 +113,8 @@ update_main(void)
     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();
index 3d7829b08635f67ac1b1b1c3eb006b5a58686dd9..f4626f404730823fedeb0fdfd152fef5e24ae7ae 100644 (file)
@@ -29,7 +29,7 @@
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Steve McClure, 1998-1999
- *     Markus Armbruster, 2004-2008
+ *     Markus Armbruster, 2004-2016
  */
 
 #include <config.h>
@@ -125,21 +125,41 @@ pln_do_upd_mob(struct plnstr *pp)
     do_upd_checking = 0;
 }
 
+/* Increase mobility of everything for @etus ETUs, update timestamps */
 void
-mob_sect(void)
+mob_inc_all(int etus)
 {
-    struct sctstr *sp;
-    int n, etus;
+    struct sctstr *sectp;
+    struct shpstr *sp;
+    struct plnstr *pp;
+    struct lndstr *lp;
+    int i;
     time_t now;
 
     time(&now);
-    for (n = 0; NULL != (sp = getsectid(n)); n++) {
-       sp->sct_timestamp = now;
-       if (opt_MOB_ACCESS)
-           etus = game_reset_tick(&sp->sct_access);
-       else
-           etus = etu_per_update;
-       do_mob_sect(sp, etus);
+
+    for (i = 0; (sectp = getsectid(i)); i++) {
+       sectp->sct_timestamp = now;
+       if (!opt_MOB_ACCESS)
+           do_mob_sect(sectp, etus);
+    }
+
+    for (i = 0; (sp = getshipp(i)); i++) {
+       sp->shp_timestamp = now;
+       if (!opt_MOB_ACCESS)
+           do_mob_ship(sp, etus);
+    }
+
+    for (i = 0; (pp = getplanep(i)); i++) {
+       pp->pln_timestamp = now;
+       if (!opt_MOB_ACCESS)
+           do_mob_plane(pp, etus);
+    }
+
+    for (i = 0; (lp = getlandp(i)); i++) {
+       lp->lnd_timestamp = now;
+       if (!opt_MOB_ACCESS)
+           do_mob_land(lp, etus);
     }
 }
 
@@ -162,24 +182,6 @@ do_mob_sect(struct sctstr *sp, int etus)
     sp->sct_mobil = value;
 }
 
-void
-mob_ship(void)
-{
-    struct shpstr *sp;
-    int n, etus;
-    time_t now;
-
-    time(&now);
-    for (n = 0; NULL != (sp = getshipp(n)); n++) {
-       sp->shp_timestamp = now;
-       if (opt_MOB_ACCESS)
-           etus = game_reset_tick(&sp->shp_access);
-       else
-           etus = etu_per_update;
-       do_mob_ship(sp, etus);
-    }
-}
-
 static void
 do_mob_ship(struct shpstr *sp, int etus)
 {
@@ -197,24 +199,6 @@ do_mob_ship(struct shpstr *sp, int etus)
     sp->shp_mobil = (signed char)value;
 }
 
-void
-mob_land(void)
-{
-    struct lndstr *lp;
-    int n, etus;
-    time_t now;
-
-    time(&now);
-    for (n = 0; NULL != (lp = getlandp(n)); n++) {
-       lp->lnd_timestamp = now;
-       if (opt_MOB_ACCESS)
-           etus = game_reset_tick(&lp->lnd_access);
-       else
-           etus = etu_per_update;
-       do_mob_land(lp, etus);
-    }
-}
-
 static void
 do_mob_land(struct lndstr *lp, int etus)
 {
@@ -246,24 +230,6 @@ do_mob_land(struct lndstr *lp, int etus)
     lp->lnd_mobil = value;
 }
 
-void
-mob_plane(void)
-{
-    struct plnstr *pp;
-    int n, etus;
-    time_t now;
-
-    time(&now);
-    for (n = 0; NULL != (pp = getplanep(n)); n++) {
-       pp->pln_timestamp = now;
-       if (opt_MOB_ACCESS)
-           etus = game_reset_tick(&pp->pln_access);
-       else
-           etus = etu_per_update;
-       do_mob_plane(pp, etus);
-    }
-}
-
 static void
 do_mob_plane(struct plnstr *pp, int etus)
 {
@@ -280,3 +246,32 @@ do_mob_plane(struct plnstr *pp, int etus)
        value = plane_mob_max;
     pp->pln_mobil = value;
 }
+
+/*
+ * Credit the turn's remaining MOB_ACCESS mobility.
+ * Exactly as if everything was accessed right now.
+ */
+void
+mob_access_all(void)
+{
+    struct sctstr *sectp;
+    struct shpstr *sp;
+    struct plnstr *pp;
+    struct lndstr *lp;
+    int i;
+
+    if (CANT_HAPPEN(!opt_MOB_ACCESS))
+       return;
+
+    for (i = 0; (sectp = getsectid(i)); i++)
+       do_mob_sect(sectp, game_reset_tick(&sectp->sct_access));
+
+    for (i = 0; (sp = getshipp(i)); i++)
+       do_mob_ship(sp, game_reset_tick(&sp->shp_access));
+
+    for (i = 0; (pp = getplanep(i)); i++)
+       do_mob_plane(pp, game_reset_tick(&pp->pln_access));
+
+    for (i = 0; (lp = getlandp(i)); i++)
+       do_mob_land(lp, game_reset_tick(&lp->lnd_access));
+}