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

@ -104,10 +104,10 @@ extern void prod_land(int, int, struct bp *, int);
extern int get_materials(struct sctstr *, short[], int); extern int get_materials(struct sctstr *, short[], int);
/* mobility.c */ /* mobility.c */
extern void mob_inc_all(int); extern void mob_inc_all(int);
extern void sct_do_upd_mob(struct sctstr *sp); extern void mob_inc_sect(struct sctstr *, int);
extern void shp_do_upd_mob(struct shpstr *sp); extern void mob_inc_ship(struct shpstr *, int);
extern void lnd_do_upd_mob(struct lndstr *lp); extern void mob_inc_plane(struct plnstr *, int);
extern void pln_do_upd_mob(struct plnstr *pp); extern void mob_inc_land(struct lndstr *, int);
extern void mob_access_all(void); extern void mob_access_all(void);
/* move_sat.c */ /* move_sat.c */
extern void move_sat(struct plnstr *); extern void move_sat(struct plnstr *);

View file

@ -28,7 +28,7 @@
* *
* Known contributors to this file: * Known contributors to this file:
* Steve McClure, 1996 * Steve McClure, 1996
* Markus Armbruster, 2004-2011 * Markus Armbruster, 2004-2016
*/ */
#include <config.h> #include <config.h>
@ -40,6 +40,7 @@
#include "optlist.h" #include "optlist.h"
#include "player.h" #include "player.h"
#include "prototypes.h" #include "prototypes.h"
#include "server.h"
#include "unit.h" #include "unit.h"
#include "update.h" #include "update.h"
@ -54,9 +55,10 @@ lnd_postread(int n, void *ptr)
memset(lp, 0, sizeof(struct lndstr)); memset(lp, 0, sizeof(struct lndstr));
} }
if (opt_MOB_ACCESS)
lnd_do_upd_mob(lp);
player->owner = (player->god || lp->lnd_own == player->cnum); player->owner = (player->god || lp->lnd_own == player->cnum);
if (opt_MOB_ACCESS && lp->lnd_own && !update_running)
mob_inc_land(lp, game_tick_to_now(&lp->lnd_access));
} }
void void

View file

@ -29,7 +29,7 @@
* Known contributors to this file: * Known contributors to this file:
* Dave Pare, 1989 * Dave Pare, 1989
* Steve McClure, 1996 * Steve McClure, 1996
* Markus Armbruster, 2006-2011 * Markus Armbruster, 2006-2016
*/ */
#include <config.h> #include <config.h>
@ -41,6 +41,7 @@
#include "plane.h" #include "plane.h"
#include "player.h" #include "player.h"
#include "prototypes.h" #include "prototypes.h"
#include "server.h"
#include "unit.h" #include "unit.h"
#include "update.h" #include "update.h"
@ -54,9 +55,11 @@ pln_postread(int n, void *ptr)
pp->pln_uid, n); pp->pln_uid, n);
memset(pp, 0, sizeof(struct plnstr)); memset(pp, 0, sizeof(struct plnstr));
} }
player->owner = (player->god || pp->pln_own == player->cnum); player->owner = (player->god || pp->pln_own == player->cnum);
if (opt_MOB_ACCESS)
pln_do_upd_mob(pp); if (opt_MOB_ACCESS && pp->pln_own && !update_running)
mob_inc_plane(pp, game_tick_to_now(&pp->pln_access));
} }
void void

View file

@ -36,6 +36,7 @@
#include <ctype.h> #include <ctype.h>
#include "file.h" #include "file.h"
#include "game.h"
#include "lost.h" #include "lost.h"
#include "misc.h" #include "misc.h"
#include "nsc.h" #include "nsc.h"
@ -43,6 +44,7 @@
#include "player.h" #include "player.h"
#include "prototypes.h" #include "prototypes.h"
#include "sect.h" #include "sect.h"
#include "server.h"
#include "update.h" #include "update.h"
#include "xy.h" #include "xy.h"
@ -52,8 +54,10 @@ sct_postread(int id, void *ptr)
struct sctstr *sp = ptr; struct sctstr *sp = ptr;
player->owner = (player->god || sp->sct_own == player->cnum); player->owner = (player->god || sp->sct_own == player->cnum);
if (opt_MOB_ACCESS)
sct_do_upd_mob(sp); if (opt_MOB_ACCESS && sp->sct_own && sp->sct_type != SCT_SANCT
&& !update_running)
mob_inc_sect(sp, game_tick_to_now(&sp->sct_access));
} }
void void

View file

@ -29,7 +29,7 @@
* Known contributors to this file: * Known contributors to this file:
* Dave Pare, 1989 * Dave Pare, 1989
* Steve McClure, 1996 * Steve McClure, 1996
* Markus Armbruster, 2004-2011 * Markus Armbruster, 2004-2016
*/ */
#include <config.h> #include <config.h>
@ -40,6 +40,7 @@
#include "optlist.h" #include "optlist.h"
#include "player.h" #include "player.h"
#include "prototypes.h" #include "prototypes.h"
#include "server.h"
#include "ship.h" #include "ship.h"
#include "unit.h" #include "unit.h"
#include "update.h" #include "update.h"
@ -55,9 +56,10 @@ shp_postread(int n, void *ptr)
memset(sp, 0, sizeof(struct shpstr)); memset(sp, 0, sizeof(struct shpstr));
} }
if (opt_MOB_ACCESS)
shp_do_upd_mob(sp);
player->owner = (player->god || sp->shp_own == player->cnum); player->owner = (player->god || sp->shp_own == player->cnum);
if (opt_MOB_ACCESS & sp->shp_own && !update_running)
mob_inc_ship(sp, game_tick_to_now(&sp->shp_access));
} }
void void

View file

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