Use the new Empire clock for implementing MOB_ACCESS:

(lndstr, plnstr, sctstr, shpstr): Change timestamp members lnd_access,
pln_access, sct_access, shp_access from real time (time_t) to ETUs
within a turn (short).
(land_ca, plane_ca, sect_ca, ship_ca): Update accordingly.
(build_ship, build_land, build_bridge, build_plane, build_tower)
(explore, check_trade, bsanct, takeover, takeover_ship)
(takeover_land): Use game_tick_to_now() instead of time() to update
the timestamp.  Change check_trade(), takeover_ship(), takeover_land()
to do that only when MOB_ACCESS is enabled, for consistency.
(lupgr, supgr, pupgr, takeover_ship): Don't touch the timestamp where
mobility isn't touched either.
(sct_do_upd_mob, shp_do_upd_mob, lnd_do_upd_mob, pln_do_upd_mob): Use
game_tick_to_now() instead of increase_mob() to compute ETUs since
the timestamp and update the timestamp.  Closes #1012699.
(increase_mob): Remove.
(mob_sect, mob_ship, mob_land, mob_plane): sct_do_upd_mob() & friends
no longer do the right thing at the update.  Use game_reset_tick() and
pass its result directly to do_mob_sect() & friends.  This is only
correct when argument is etu_per_update, which it always is.  Remove
parameter.  Callers changed.
(do_mob_sect, do_mob_ship, do_mob_land, do_mob_plane): Oops on
negative argument.

(mob_acc_globals, timestampfil, mobupdate, updating_mob)
(update_all_mob, timestamp_fixing, update_timestamps, mobility_check):
The mobupdate command was important to let deities manually
synchronize mobility updating with updates.  That's no longer needed.
The code behind it is somewhat hairy and ugly, and updating it to work
with the Empire clock is just not worth it.  Remove.  Users changed.
(player_coms): Update accordingly.
(upda): Remove display of mobility updating state.

(mobility_init): No need to fix up mobility on startup, as the Empire
clock runs normally even when the server is down.  Remove.  Caller
changed.
This commit is contained in:
Markus Armbruster 2007-07-15 09:43:57 +00:00
parent aa34ef2b7b
commit 4bd19812af
25 changed files with 92 additions and 458 deletions

View file

@ -36,6 +36,7 @@
#include <limits.h>
#include "commands.h"
#include "game.h"
#include "land.h"
#include "lost.h"
#include "map.h"
@ -353,7 +354,7 @@ build_ship(struct sctstr *sp, struct mchrstr *mp, short *vec, int tlev)
ship.shp_type = mp - mchr;
ship.shp_effic = SHIP_MINEFF;
if (opt_MOB_ACCESS) {
time(&ship.shp_access);
game_tick_to_now(&ship.shp_access);
ship.shp_mobil = -(etu_per_update / sect_mob_neg_factor);
} else {
ship.shp_mobil = 0;
@ -478,7 +479,7 @@ build_land(struct sctstr *sp, struct lchrstr *lp, short *vec, int tlev)
land.lnd_type = lp - lchr;
land.lnd_effic = LAND_MINEFF;
if (opt_MOB_ACCESS) {
time(&land.lnd_access);
game_tick_to_now(&land.lnd_access);
land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
} else {
land.lnd_mobil = 0;
@ -610,7 +611,7 @@ build_bridge(struct sctstr *sp, short *vec)
sect.sct_rail = 0;
sect.sct_defense = 0;
if (opt_MOB_ACCESS) {
time(&sect.sct_access);
game_tick_to_now(&sect.sct_access);
sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
} else {
sect.sct_mobil = 0;
@ -775,7 +776,7 @@ build_plane(struct sctstr *sp, struct plchrstr *pp, short *vec, int tlev)
plane.pln_type = pp - plchr;
plane.pln_effic = PLANE_MINEFF;
if (opt_MOB_ACCESS) {
time(&plane.pln_access);
game_tick_to_now(&plane.pln_access);
plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
} else {
plane.pln_mobil = 0;
@ -902,7 +903,7 @@ build_tower(struct sctstr *sp, short *vec)
sect.sct_rail = 0;
sect.sct_defense = 0;
if (opt_MOB_ACCESS) {
time(&sect.sct_access);
game_tick_to_now(&sect.sct_access);
sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
} else {
sect.sct_mobil = 0;

View file

@ -34,6 +34,7 @@
#include <config.h>
#include "commands.h"
#include "game.h"
#include "item.h"
#include "map.h"
#include "optlist.h"
@ -251,7 +252,7 @@ explore(void)
pr("Sector %s is now yours.\n",
xyas(sect.sct_x, sect.sct_y, player->cnum));
if (opt_MOB_ACCESS) {
time(&sect.sct_access);
game_tick_to_now(&sect.sct_access);
sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
} else {
sect.sct_mobil = 0;

View file

@ -1,101 +0,0 @@
/*
* Empire - A multi-player, client/server Internet based war game.
* Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ---
*
* See files README, COPYING and CREDITS in the root of the source
* tree for related information and legal notices. It is expected
* that future projects/authors will amend these files as needed.
*
* ---
*
* mobu.c: Adjust mobility updating
*
* Known contributors to this file:
* Steve McClure, 1996
*/
#include <config.h>
#include "commands.h"
#include "optlist.h"
#include "path.h"
#include "server.h"
int
mobupdate(void)
{
FILE *fp;
long minites;
struct mob_acc_globals timestamps;
time_t now;
if (!opt_MOB_ACCESS) {
pr("Command invalid - MOB_ACCESS is not enabled.\n");
return RET_FAIL;
}
if (!player->argp[1])
return RET_SYN;
if (*player->argp[1] == 'c')
minites = -1;
else
minites = atol(player->argp[1]) * 60;
time(&now);
if ((fp = fopen(timestampfil, "rb+")) == NULL) {
logerror("Unable to edit timestamp file.");
} else {
rewind(fp);
fread(&timestamps, sizeof(timestamps), 1, fp);
if (minites < 0) {
fclose(fp);
if (updating_mob)
pr("Mobility updating is enabled.");
else {
pr("Mobility updating will come back on around %s",
ctime(&timestamps.starttime));
pr("within 3 minutes, depending on when the server checks.");
}
return 0;
}
timestamps.timestamp = now;
timestamps.starttime = now + minites;
rewind(fp);
fwrite(&timestamps, sizeof(timestamps), 1, fp);
fclose(fp);
if (now >= timestamps.starttime) {
pr("Turning on mobility updating.");
update_all_mob();
updating_mob = 1;
} else if (updating_mob == 1) {
pr("Turning off mobility updating.\n");
pr("Mobility updating will come back on around %s",
ctime(&timestamps.starttime));
pr("within 3 minutes, depending on when the server checks.");
update_all_mob();
updating_mob = 0;
} else if (updating_mob == 0) {
pr("Mobility updating is already off.\n");
pr("Mobility updating will come back on around %s",
ctime(&timestamps.starttime));
pr("within 3 minutes, depending on when the server checks.");
}
}
return 0;
}

View file

@ -396,12 +396,12 @@ check_trade(void)
/* no cheap version of fly */
if (opt_MOB_ACCESS) {
tg.plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
game_tick_to_now(&tg.plane.pln_access);
} else {
tg.plane.pln_mobil = 0;
}
tg.plane.pln_mission = 0;
tg.plane.pln_harden = 0;
time(&tg.plane.pln_access);
tg.plane.pln_ship = -1;
tg.plane.pln_land = -1;
break;
@ -426,11 +426,11 @@ check_trade(void)
/* no cheap version of fly */
if (opt_MOB_ACCESS) {
tg.land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
game_tick_to_now(&tg.land.lnd_access);
} else {
tg.land.lnd_mobil = 0;
}
tg.land.lnd_harden = 0;
time(&tg.land.lnd_access);
tg.land.lnd_mission = 0;
/* Drop any land units this unit was carrying */
snxtitem_xy(&ni, EF_LAND, tg.land.lnd_x, tg.land.lnd_y);

View file

@ -45,26 +45,8 @@ int
upda(void)
{
FILE *fp;
struct mob_acc_globals timestamps;
time_t now, next, stop;
if (opt_MOB_ACCESS) {
if ((fp = fopen(timestampfil, "rb")) == NULL)
logerror("Unable to open timestamp file.");
else {
rewind(fp);
fread(&timestamps, sizeof(timestamps), 1, fp);
fclose(fp);
if (updating_mob)
pr("Mobility updating is enabled.\n\n");
else {
pr("Mobility updating will come back on around %s",
ctime(&timestamps.starttime));
pr("game time, within 3 minutes, depending on when the server checks.\n\n");
}
}
}
if (updates_disabled())
pr("UPDATES ARE DISABLED!\n");

View file

@ -137,7 +137,6 @@ lupgr(void)
lnd_set_tech(&land, tlev);
land.lnd_harden = 0;
land.lnd_mission = 0;
time(&land.lnd_access);
putland(land.lnd_uid, &land);
putsect(&sect);
@ -220,7 +219,6 @@ supgr(void)
ship.shp_effic -= UPGR_EFF;
shp_set_tech(&ship, tlev);
ship.shp_mission = 0;
time(&ship.shp_access);
putship(ship.shp_uid, &ship);
putsect(&sect);
@ -308,7 +306,6 @@ pupgr(void)
pln_set_tech(&plane, tlev);
plane.pln_harden = 0;
plane.pln_mission = 0;
time(&plane.pln_access);
putplane(plane.pln_uid, &plane);
putsect(&sect);