update: Separate MOB_ACCESS from normal mobility update

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>
This commit is contained in:
Markus Armbruster 2016-06-20 19:47:15 +02:00
parent d861902783
commit 25d48124d0
3 changed files with 66 additions and 84 deletions

View 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 */

View 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();

View 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));
}