subs: Simplify MOB_ACCESS mobility update

The do_upd_checking recursion guard is superfluous: do_mob_sect()
doesn't call anything.  Has been that way since MOB_ACCESS was added
in Empire 3.

Inline the remaining code of sct_do_upd_mob(), shp_do_upd_mob(),
pln_do_upd_mob(), lnd_do_upd_mob() in their only callers
sct_postread(), shp_postread(), pln_postread(), lnd_postread().
Rename do_mob_sect(), do_mob_ship(), do_mob_plane(), do_mob_land() to
mob_sect, mob_ship(), mob_plane(), mob_land() and give them external
linkage.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2016-06-20 20:13:32 +02:00
parent 25d48124d0
commit dd9e393b38
6 changed files with 46 additions and 113 deletions

View file

@ -40,91 +40,9 @@
#include "optlist.h"
#include "plane.h"
#include "sect.h"
#include "server.h"
#include "ship.h"
#include "update.h"
static int do_upd_checking;
static void do_mob_land(struct lndstr *, int);
static void do_mob_plane(struct plnstr *, int);
static void do_mob_sect(struct sctstr *sp, int etus);
static void do_mob_ship(struct shpstr *, int);
void
sct_do_upd_mob(struct sctstr *sp)
{
int etus;
if (do_upd_checking || update_running)
return;
if (sp->sct_own == 0)
return;
if (sp->sct_type == SCT_SANCT)
return;
etus = game_tick_to_now(&sp->sct_access);
if (etus == 0)
return;
do_upd_checking = 1; /* avoid recursion */
do_mob_sect(sp, etus);
do_upd_checking = 0;
}
void
shp_do_upd_mob(struct shpstr *sp)
{
int etus;
if (do_upd_checking || update_running)
return;
if (sp->shp_own == 0)
return;
etus = game_tick_to_now(&sp->shp_access);
if (etus == 0)
return;
do_upd_checking = 1; /* avoid recursion */
do_mob_ship(sp, etus);
do_upd_checking = 0;
}
void
lnd_do_upd_mob(struct lndstr *lp)
{
int etus;
if (do_upd_checking || update_running)
return;
if (lp->lnd_own == 0)
return;
etus = game_tick_to_now(&lp->lnd_access);
if (etus == 0)
return;
do_upd_checking = 1; /* avoid recursion */
do_mob_land(lp, etus);
do_upd_checking = 0;
}
void
pln_do_upd_mob(struct plnstr *pp)
{
int etus;
if (do_upd_checking || update_running)
return;
if (pp->pln_own == 0)
return;
etus = game_tick_to_now(&pp->pln_access);
if (etus == 0)
return;
do_upd_checking = 1; /* avoid recursion */
do_mob_plane(pp, etus);
do_upd_checking = 0;
}
/* Increase mobility of everything for @etus ETUs, update timestamps */
void
mob_inc_all(int etus)
@ -141,30 +59,31 @@ mob_inc_all(int etus)
for (i = 0; (sectp = getsectid(i)); i++) {
sectp->sct_timestamp = now;
if (!opt_MOB_ACCESS)
do_mob_sect(sectp, etus);
mob_inc_sect(sectp, etus);
}
for (i = 0; (sp = getshipp(i)); i++) {
sp->shp_timestamp = now;
if (!opt_MOB_ACCESS)
do_mob_ship(sp, etus);
mob_inc_ship(sp, etus);
}
for (i = 0; (pp = getplanep(i)); i++) {
pp->pln_timestamp = now;
if (!opt_MOB_ACCESS)
do_mob_plane(pp, etus);
mob_inc_plane(pp, etus);
}
for (i = 0; (lp = getlandp(i)); i++) {
lp->lnd_timestamp = now;
if (!opt_MOB_ACCESS)
do_mob_land(lp, etus);
mob_inc_land(lp, etus);
}
}
static void
do_mob_sect(struct sctstr *sp, int etus)
/* Increase @sp's mobility for @etus ETUs */
void
mob_inc_sect(struct sctstr *sp, int etus)
{
int value;
@ -182,8 +101,9 @@ do_mob_sect(struct sctstr *sp, int etus)
sp->sct_mobil = value;
}
static void
do_mob_ship(struct shpstr *sp, int etus)
/* Increase @sp's mobility for @etus ETUs */
void
mob_inc_ship(struct shpstr *sp, int etus)
{
int value;
@ -199,8 +119,9 @@ do_mob_ship(struct shpstr *sp, int etus)
sp->shp_mobil = (signed char)value;
}
static void
do_mob_land(struct lndstr *lp, int etus)
/* Increase @lp's mobility for @etus ETUs */
void
mob_inc_land(struct lndstr *lp, int etus)
{
int value;
@ -230,8 +151,9 @@ do_mob_land(struct lndstr *lp, int etus)
lp->lnd_mobil = value;
}
static void
do_mob_plane(struct plnstr *pp, int etus)
/* Increase @pp's mobility for @etus ETUs */
void
mob_inc_plane(struct plnstr *pp, int etus)
{
int value;
@ -264,14 +186,14 @@ mob_access_all(void)
return;
for (i = 0; (sectp = getsectid(i)); i++)
do_mob_sect(sectp, game_reset_tick(&sectp->sct_access));
mob_inc_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));
mob_inc_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));
mob_inc_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));
mob_inc_land(lp, game_reset_tick(&lp->lnd_access));
}