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:
parent
d861902783
commit
25d48124d0
3 changed files with 66 additions and 84 deletions
|
@ -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(§p->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));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue