diff --git a/include/update.h b/include/update.h index b1d74340..7a159f4e 100644 --- a/include/update.h +++ b/include/update.h @@ -104,10 +104,10 @@ extern void prod_land(int, int, struct bp *, int); extern int get_materials(struct sctstr *, short[], int); /* mobility.c */ 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_inc_sect(struct sctstr *, int); +extern void mob_inc_ship(struct shpstr *, int); +extern void mob_inc_plane(struct plnstr *, int); +extern void mob_inc_land(struct lndstr *, int); extern void mob_access_all(void); /* move_sat.c */ extern void move_sat(struct plnstr *); diff --git a/src/lib/subs/land.c b/src/lib/subs/land.c index 10278627..4d187006 100644 --- a/src/lib/subs/land.c +++ b/src/lib/subs/land.c @@ -28,7 +28,7 @@ * * Known contributors to this file: * Steve McClure, 1996 - * Markus Armbruster, 2004-2011 + * Markus Armbruster, 2004-2016 */ #include @@ -40,6 +40,7 @@ #include "optlist.h" #include "player.h" #include "prototypes.h" +#include "server.h" #include "unit.h" #include "update.h" @@ -54,9 +55,10 @@ lnd_postread(int n, void *ptr) memset(lp, 0, sizeof(struct lndstr)); } - if (opt_MOB_ACCESS) - lnd_do_upd_mob(lp); 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 diff --git a/src/lib/subs/plane.c b/src/lib/subs/plane.c index a39560a2..1c28368f 100644 --- a/src/lib/subs/plane.c +++ b/src/lib/subs/plane.c @@ -29,7 +29,7 @@ * Known contributors to this file: * Dave Pare, 1989 * Steve McClure, 1996 - * Markus Armbruster, 2006-2011 + * Markus Armbruster, 2006-2016 */ #include @@ -41,6 +41,7 @@ #include "plane.h" #include "player.h" #include "prototypes.h" +#include "server.h" #include "unit.h" #include "update.h" @@ -54,9 +55,11 @@ pln_postread(int n, void *ptr) pp->pln_uid, n); memset(pp, 0, sizeof(struct plnstr)); } + 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 diff --git a/src/lib/subs/sect.c b/src/lib/subs/sect.c index 55e6c9e3..a53ee52b 100644 --- a/src/lib/subs/sect.c +++ b/src/lib/subs/sect.c @@ -36,6 +36,7 @@ #include #include "file.h" +#include "game.h" #include "lost.h" #include "misc.h" #include "nsc.h" @@ -43,6 +44,7 @@ #include "player.h" #include "prototypes.h" #include "sect.h" +#include "server.h" #include "update.h" #include "xy.h" @@ -52,8 +54,10 @@ sct_postread(int id, void *ptr) struct sctstr *sp = ptr; 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 diff --git a/src/lib/subs/ship.c b/src/lib/subs/ship.c index f3f6a04d..3c75e84c 100644 --- a/src/lib/subs/ship.c +++ b/src/lib/subs/ship.c @@ -29,7 +29,7 @@ * Known contributors to this file: * Dave Pare, 1989 * Steve McClure, 1996 - * Markus Armbruster, 2004-2011 + * Markus Armbruster, 2004-2016 */ #include @@ -40,6 +40,7 @@ #include "optlist.h" #include "player.h" #include "prototypes.h" +#include "server.h" #include "ship.h" #include "unit.h" #include "update.h" @@ -55,9 +56,10 @@ shp_postread(int n, void *ptr) memset(sp, 0, sizeof(struct shpstr)); } - if (opt_MOB_ACCESS) - shp_do_upd_mob(sp); 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 diff --git a/src/lib/update/mobility.c b/src/lib/update/mobility.c index f4626f40..e77fe4b4 100644 --- a/src/lib/update/mobility.c +++ b/src/lib/update/mobility.c @@ -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(§p->sct_access)); + mob_inc_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)); + 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)); }