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:
parent
aa34ef2b7b
commit
4bd19812af
25 changed files with 92 additions and 458 deletions
|
@ -77,7 +77,7 @@ struct lndstr {
|
||||||
short lnd_ptime; /* how many etus remain in this stage */
|
short lnd_ptime; /* how many etus remain in this stage */
|
||||||
short lnd_land; /* pointer to transporting unit */
|
short lnd_land; /* pointer to transporting unit */
|
||||||
unsigned char lnd_nland;
|
unsigned char lnd_nland;
|
||||||
time_t lnd_access; /* Last time mob was updated (MOB_ACCESS) */
|
short lnd_access; /* Last tick mob was updated (MOB_ACCESS) */
|
||||||
float lnd_att; /* attack multiplier */
|
float lnd_att; /* attack multiplier */
|
||||||
float lnd_def; /* defense multiplier */
|
float lnd_def; /* defense multiplier */
|
||||||
int lnd_vul; /* vulnerability (0-100) */
|
int lnd_vul; /* vulnerability (0-100) */
|
||||||
|
|
|
@ -83,15 +83,6 @@ typedef int pid_t;
|
||||||
#define S_IRWUG S_IRGRP | S_IWGRP | S_IRUSR | S_IWUSR
|
#define S_IRWUG S_IRGRP | S_IWGRP | S_IRUSR | S_IWUSR
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This is the structure we use to keep track of the global mobility
|
|
||||||
things, such as when the server is supposed to start/stop updating
|
|
||||||
mobility and the timestamp of when the game was last up. These
|
|
||||||
times are in seconds. */
|
|
||||||
struct mob_acc_globals {
|
|
||||||
time_t timestamp; /* Last timestamp of when the game was up */
|
|
||||||
time_t starttime; /* When we should start updating mobility again. */
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define ATTRIBUTE(attrs) __attribute__ (attrs)
|
#define ATTRIBUTE(attrs) __attribute__ (attrs)
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -51,7 +51,6 @@ extern char motdfil[];
|
||||||
extern char downfil[];
|
extern char downfil[];
|
||||||
extern char disablefil[];
|
extern char disablefil[];
|
||||||
extern char annfil[];
|
extern char annfil[];
|
||||||
extern char timestampfil[];
|
|
||||||
extern char teldir[];
|
extern char teldir[];
|
||||||
extern char telfil[];
|
extern char telfil[];
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ struct plnstr {
|
||||||
signed char pln_harden; /* for missiles */
|
signed char pln_harden; /* for missiles */
|
||||||
signed char pln_nuketype; /* type of nuclear armament (if any) */
|
signed char pln_nuketype; /* type of nuclear armament (if any) */
|
||||||
signed char pln_flags; /* State of the plane */
|
signed char pln_flags; /* State of the plane */
|
||||||
time_t pln_access; /* Last time mob was updated (MOB_ACCESS) */
|
short pln_access; /* Last tick mob was updated (MOB_ACCESS) */
|
||||||
time_t pln_timestamp; /* Last time this plane was touched */
|
time_t pln_timestamp; /* Last time this plane was touched */
|
||||||
float pln_theta; /* position in orbital sine wave */
|
float pln_theta; /* position in orbital sine wave */
|
||||||
};
|
};
|
||||||
|
|
|
@ -161,7 +161,6 @@ int mark(void);
|
||||||
int mine(void);
|
int mine(void);
|
||||||
int mission(void);
|
int mission(void);
|
||||||
int mobq(void);
|
int mobq(void);
|
||||||
int mobupdate(void);
|
|
||||||
int morale(void);
|
int morale(void);
|
||||||
int move(void);
|
int move(void);
|
||||||
int multifire(void);
|
int multifire(void);
|
||||||
|
@ -736,12 +735,10 @@ extern int prod_land(int, int, struct bp *, int);
|
||||||
/* material.c */
|
/* material.c */
|
||||||
/* in budg.h */
|
/* in budg.h */
|
||||||
/* mobility.c */
|
/* mobility.c */
|
||||||
extern void mob_sect(int);
|
extern void mob_sect(void);
|
||||||
extern void mob_ship(int);
|
extern void mob_ship(void);
|
||||||
extern void mob_land(int);
|
extern void mob_land(void);
|
||||||
extern void mob_plane(int);
|
extern void mob_plane(void);
|
||||||
extern void update_all_mob(void);
|
|
||||||
extern void update_timestamps(time_t offset);
|
|
||||||
extern void sct_do_upd_mob(struct sctstr *sp);
|
extern void sct_do_upd_mob(struct sctstr *sp);
|
||||||
extern void shp_do_upd_mob(struct shpstr *sp);
|
extern void shp_do_upd_mob(struct shpstr *sp);
|
||||||
extern void lnd_do_upd_mob(struct lndstr *lp);
|
extern void lnd_do_upd_mob(struct lndstr *lp);
|
||||||
|
|
|
@ -82,7 +82,7 @@ struct sctstr {
|
||||||
unsigned char sct_che; /* number of guerrillas */
|
unsigned char sct_che; /* number of guerrillas */
|
||||||
natid sct_che_target; /* nation targeted by che */
|
natid sct_che_target; /* nation targeted by che */
|
||||||
unsigned short sct_fallout;
|
unsigned short sct_fallout;
|
||||||
time_t sct_access; /* Last time mob was updated (MOB_ACCESS) */
|
short sct_access; /* Last tick mob was updated (MOB_ACCESS) */
|
||||||
unsigned char sct_road; /* Road value of a sector */
|
unsigned char sct_road; /* Road value of a sector */
|
||||||
unsigned char sct_rail; /* Rail value of a sector */
|
unsigned char sct_rail; /* Rail value of a sector */
|
||||||
unsigned char sct_defense; /* Defensive value of a sector */
|
unsigned char sct_defense; /* Defensive value of a sector */
|
||||||
|
|
|
@ -40,9 +40,7 @@ extern int shutdown_pending;
|
||||||
extern int update_pending;
|
extern int update_pending;
|
||||||
extern empth_rwlock_t *update_lock;
|
extern empth_rwlock_t *update_lock;
|
||||||
extern time_t update_time[];
|
extern time_t update_time[];
|
||||||
extern int updating_mob;
|
|
||||||
|
|
||||||
void mobility_init(void);
|
|
||||||
void market_init(void);
|
void market_init(void);
|
||||||
void update_main(void);
|
void update_main(void);
|
||||||
void update_init(void);
|
void update_init(void);
|
||||||
|
@ -52,7 +50,6 @@ int shutdown_initiate(int);
|
||||||
|
|
||||||
/* thread entry points */
|
/* thread entry points */
|
||||||
void delete_lostitems(void *);
|
void delete_lostitems(void *);
|
||||||
void mobility_check(void *);
|
|
||||||
void player_kill_idle(void *);
|
void player_kill_idle(void *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -93,7 +93,7 @@ struct shpstr {
|
||||||
short shp_item[I_MAX+1]; /* amount of items on board */
|
short shp_item[I_MAX+1]; /* amount of items on board */
|
||||||
short shp_pstage; /* plague stage */
|
short shp_pstage; /* plague stage */
|
||||||
short shp_ptime; /* how many etus remain in this stage */
|
short shp_ptime; /* how many etus remain in this stage */
|
||||||
time_t shp_access; /* Last time mob was updated (MOB_ACCESS) */
|
short shp_access; /* Last tick mob was updated (MOB_ACCESS) */
|
||||||
time_t shp_timestamp; /* Last time this ship was touched. */
|
time_t shp_timestamp; /* Last time this ship was touched. */
|
||||||
unsigned char shp_mobquota; /* mobility quota */
|
unsigned char shp_mobquota; /* mobility quota */
|
||||||
char shp_path[MAXSHPPATH];
|
char shp_path[MAXSHPPATH];
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
.TH Command MOBUPDATE
|
|
||||||
.NA mobupdate "turn on/off mobility updating"
|
|
||||||
.LV Expert
|
|
||||||
.SY "mobupdate <MINUTES|check>"
|
|
||||||
The mobupdate command will disable mobility updating for 'X' minutes.
|
|
||||||
Note that this only works if the MOB_ACCESS option has been enabled.
|
|
||||||
.s1
|
|
||||||
Using this command with 0 minutes will turn mobility updating back on.
|
|
||||||
.s1
|
|
||||||
Using this command with 'check' or a negative amount of minutes will
|
|
||||||
tell you when the mobility updating will be turned back on if it is
|
|
||||||
off, or that it is on if it is on.
|
|
||||||
.s1
|
|
||||||
.SA "update, Deity"
|
|
|
@ -36,6 +36,7 @@
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
|
#include "game.h"
|
||||||
#include "land.h"
|
#include "land.h"
|
||||||
#include "lost.h"
|
#include "lost.h"
|
||||||
#include "map.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_type = mp - mchr;
|
||||||
ship.shp_effic = SHIP_MINEFF;
|
ship.shp_effic = SHIP_MINEFF;
|
||||||
if (opt_MOB_ACCESS) {
|
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);
|
ship.shp_mobil = -(etu_per_update / sect_mob_neg_factor);
|
||||||
} else {
|
} else {
|
||||||
ship.shp_mobil = 0;
|
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_type = lp - lchr;
|
||||||
land.lnd_effic = LAND_MINEFF;
|
land.lnd_effic = LAND_MINEFF;
|
||||||
if (opt_MOB_ACCESS) {
|
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);
|
land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
|
||||||
} else {
|
} else {
|
||||||
land.lnd_mobil = 0;
|
land.lnd_mobil = 0;
|
||||||
|
@ -610,7 +611,7 @@ build_bridge(struct sctstr *sp, short *vec)
|
||||||
sect.sct_rail = 0;
|
sect.sct_rail = 0;
|
||||||
sect.sct_defense = 0;
|
sect.sct_defense = 0;
|
||||||
if (opt_MOB_ACCESS) {
|
if (opt_MOB_ACCESS) {
|
||||||
time(§.sct_access);
|
game_tick_to_now(§.sct_access);
|
||||||
sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
|
sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
|
||||||
} else {
|
} else {
|
||||||
sect.sct_mobil = 0;
|
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_type = pp - plchr;
|
||||||
plane.pln_effic = PLANE_MINEFF;
|
plane.pln_effic = PLANE_MINEFF;
|
||||||
if (opt_MOB_ACCESS) {
|
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);
|
plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
|
||||||
} else {
|
} else {
|
||||||
plane.pln_mobil = 0;
|
plane.pln_mobil = 0;
|
||||||
|
@ -902,7 +903,7 @@ build_tower(struct sctstr *sp, short *vec)
|
||||||
sect.sct_rail = 0;
|
sect.sct_rail = 0;
|
||||||
sect.sct_defense = 0;
|
sect.sct_defense = 0;
|
||||||
if (opt_MOB_ACCESS) {
|
if (opt_MOB_ACCESS) {
|
||||||
time(§.sct_access);
|
game_tick_to_now(§.sct_access);
|
||||||
sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
|
sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
|
||||||
} else {
|
} else {
|
||||||
sect.sct_mobil = 0;
|
sect.sct_mobil = 0;
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
|
#include "game.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "optlist.h"
|
#include "optlist.h"
|
||||||
|
@ -251,7 +252,7 @@ explore(void)
|
||||||
pr("Sector %s is now yours.\n",
|
pr("Sector %s is now yours.\n",
|
||||||
xyas(sect.sct_x, sect.sct_y, player->cnum));
|
xyas(sect.sct_x, sect.sct_y, player->cnum));
|
||||||
if (opt_MOB_ACCESS) {
|
if (opt_MOB_ACCESS) {
|
||||||
time(§.sct_access);
|
game_tick_to_now(§.sct_access);
|
||||||
sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
|
sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
|
||||||
} else {
|
} else {
|
||||||
sect.sct_mobil = 0;
|
sect.sct_mobil = 0;
|
||||||
|
|
|
@ -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(×tamps, 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(×tamps.starttime));
|
|
||||||
pr("within 3 minutes, depending on when the server checks.");
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
timestamps.timestamp = now;
|
|
||||||
timestamps.starttime = now + minites;
|
|
||||||
rewind(fp);
|
|
||||||
fwrite(×tamps, 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(×tamps.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(×tamps.starttime));
|
|
||||||
pr("within 3 minutes, depending on when the server checks.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -396,12 +396,12 @@ check_trade(void)
|
||||||
/* no cheap version of fly */
|
/* no cheap version of fly */
|
||||||
if (opt_MOB_ACCESS) {
|
if (opt_MOB_ACCESS) {
|
||||||
tg.plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
|
tg.plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
|
||||||
|
game_tick_to_now(&tg.plane.pln_access);
|
||||||
} else {
|
} else {
|
||||||
tg.plane.pln_mobil = 0;
|
tg.plane.pln_mobil = 0;
|
||||||
}
|
}
|
||||||
tg.plane.pln_mission = 0;
|
tg.plane.pln_mission = 0;
|
||||||
tg.plane.pln_harden = 0;
|
tg.plane.pln_harden = 0;
|
||||||
time(&tg.plane.pln_access);
|
|
||||||
tg.plane.pln_ship = -1;
|
tg.plane.pln_ship = -1;
|
||||||
tg.plane.pln_land = -1;
|
tg.plane.pln_land = -1;
|
||||||
break;
|
break;
|
||||||
|
@ -426,11 +426,11 @@ check_trade(void)
|
||||||
/* no cheap version of fly */
|
/* no cheap version of fly */
|
||||||
if (opt_MOB_ACCESS) {
|
if (opt_MOB_ACCESS) {
|
||||||
tg.land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
|
tg.land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
|
||||||
|
game_tick_to_now(&tg.land.lnd_access);
|
||||||
} else {
|
} else {
|
||||||
tg.land.lnd_mobil = 0;
|
tg.land.lnd_mobil = 0;
|
||||||
}
|
}
|
||||||
tg.land.lnd_harden = 0;
|
tg.land.lnd_harden = 0;
|
||||||
time(&tg.land.lnd_access);
|
|
||||||
tg.land.lnd_mission = 0;
|
tg.land.lnd_mission = 0;
|
||||||
/* Drop any land units this unit was carrying */
|
/* Drop any land units this unit was carrying */
|
||||||
snxtitem_xy(&ni, EF_LAND, tg.land.lnd_x, tg.land.lnd_y);
|
snxtitem_xy(&ni, EF_LAND, tg.land.lnd_x, tg.land.lnd_y);
|
||||||
|
|
|
@ -45,26 +45,8 @@ int
|
||||||
upda(void)
|
upda(void)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
struct mob_acc_globals timestamps;
|
|
||||||
time_t now, next, stop;
|
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(×tamps, 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(×tamps.starttime));
|
|
||||||
pr("game time, within 3 minutes, depending on when the server checks.\n\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updates_disabled())
|
if (updates_disabled())
|
||||||
pr("UPDATES ARE DISABLED!\n");
|
pr("UPDATES ARE DISABLED!\n");
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,6 @@ lupgr(void)
|
||||||
lnd_set_tech(&land, tlev);
|
lnd_set_tech(&land, tlev);
|
||||||
land.lnd_harden = 0;
|
land.lnd_harden = 0;
|
||||||
land.lnd_mission = 0;
|
land.lnd_mission = 0;
|
||||||
time(&land.lnd_access);
|
|
||||||
|
|
||||||
putland(land.lnd_uid, &land);
|
putland(land.lnd_uid, &land);
|
||||||
putsect(§);
|
putsect(§);
|
||||||
|
@ -220,7 +219,6 @@ supgr(void)
|
||||||
ship.shp_effic -= UPGR_EFF;
|
ship.shp_effic -= UPGR_EFF;
|
||||||
shp_set_tech(&ship, tlev);
|
shp_set_tech(&ship, tlev);
|
||||||
ship.shp_mission = 0;
|
ship.shp_mission = 0;
|
||||||
time(&ship.shp_access);
|
|
||||||
|
|
||||||
putship(ship.shp_uid, &ship);
|
putship(ship.shp_uid, &ship);
|
||||||
putsect(§);
|
putsect(§);
|
||||||
|
@ -308,7 +306,6 @@ pupgr(void)
|
||||||
pln_set_tech(&plane, tlev);
|
pln_set_tech(&plane, tlev);
|
||||||
plane.pln_harden = 0;
|
plane.pln_harden = 0;
|
||||||
plane.pln_mission = 0;
|
plane.pln_mission = 0;
|
||||||
time(&plane.pln_access);
|
|
||||||
|
|
||||||
putplane(plane.pln_uid, &plane);
|
putplane(plane.pln_uid, &plane);
|
||||||
putsect(§);
|
putsect(§);
|
||||||
|
|
|
@ -142,7 +142,7 @@ struct castr sect_ca[] = {
|
||||||
{NSC_NATID, NSC_DEITY, 0, fldoff(sctstr, sct_che_target), "che_target",
|
{NSC_NATID, NSC_DEITY, 0, fldoff(sctstr, sct_che_target), "che_target",
|
||||||
EF_NATION},
|
EF_NATION},
|
||||||
{NSC_USHORT, 0, 0, fldoff(sctstr, sct_fallout), "fallout", EF_BAD},
|
{NSC_USHORT, 0, 0, fldoff(sctstr, sct_fallout), "fallout", EF_BAD},
|
||||||
{NSC_TIME, 0, 0, fldoff(sctstr, sct_access), "access", EF_BAD},
|
{NSC_SHORT, 0, 0, fldoff(sctstr, sct_access), "access", EF_BAD},
|
||||||
{NSC_UCHAR, 0, 0, fldoff(sctstr, sct_road), "road", EF_BAD},
|
{NSC_UCHAR, 0, 0, fldoff(sctstr, sct_road), "road", EF_BAD},
|
||||||
{NSC_UCHAR, 0, 0, fldoff(sctstr, sct_rail), "rail", EF_BAD},
|
{NSC_UCHAR, 0, 0, fldoff(sctstr, sct_rail), "rail", EF_BAD},
|
||||||
{NSC_UCHAR, 0, 0, fldoff(sctstr, sct_defense), "dfense", EF_BAD},
|
{NSC_UCHAR, 0, 0, fldoff(sctstr, sct_defense), "dfense", EF_BAD},
|
||||||
|
@ -211,7 +211,7 @@ struct castr ship_ca[] = {
|
||||||
{NSC_SHORT, NSC_DEITY, 0, fldoff(shpstr, shp_pstage), "pstage",
|
{NSC_SHORT, NSC_DEITY, 0, fldoff(shpstr, shp_pstage), "pstage",
|
||||||
EF_PLAGUE_STAGES},
|
EF_PLAGUE_STAGES},
|
||||||
{NSC_SHORT, NSC_DEITY, 0, fldoff(shpstr, shp_ptime), "ptime", EF_BAD},
|
{NSC_SHORT, NSC_DEITY, 0, fldoff(shpstr, shp_ptime), "ptime", EF_BAD},
|
||||||
{NSC_TIME, 0, 0, fldoff(shpstr, shp_access), "access", EF_BAD},
|
{NSC_SHORT, 0, 0, fldoff(shpstr, shp_access), "access", EF_BAD},
|
||||||
{NSC_TIME, NSC_EXTRA, 0, fldoff(shpstr, shp_timestamp), "timestamp",
|
{NSC_TIME, NSC_EXTRA, 0, fldoff(shpstr, shp_timestamp), "timestamp",
|
||||||
EF_BAD},
|
EF_BAD},
|
||||||
{NSC_UCHAR, 0, 0, fldoff(shpstr, shp_mobquota), "mquota", EF_BAD},
|
{NSC_UCHAR, 0, 0, fldoff(shpstr, shp_mobquota), "mquota", EF_BAD},
|
||||||
|
@ -271,7 +271,7 @@ struct castr plane_ca[] = {
|
||||||
{NSC_CHAR, 0, 0, fldoff(plnstr, pln_nuketype), "nuketype", EF_BAD},
|
{NSC_CHAR, 0, 0, fldoff(plnstr, pln_nuketype), "nuketype", EF_BAD},
|
||||||
{NSC_CHAR, NSC_BITS, 0, fldoff(plnstr, pln_flags), "flags",
|
{NSC_CHAR, NSC_BITS, 0, fldoff(plnstr, pln_flags), "flags",
|
||||||
EF_PLANE_FLAGS},
|
EF_PLANE_FLAGS},
|
||||||
{NSC_TIME, 0, 0, fldoff(plnstr, pln_access), "access", EF_BAD},
|
{NSC_SHORT, 0, 0, fldoff(plnstr, pln_access), "access", EF_BAD},
|
||||||
{NSC_TIME, NSC_EXTRA, 0, fldoff(plnstr, pln_timestamp), "timestamp",
|
{NSC_TIME, NSC_EXTRA, 0, fldoff(plnstr, pln_timestamp), "timestamp",
|
||||||
EF_BAD},
|
EF_BAD},
|
||||||
{NSC_FLOAT, 0, 0, fldoff(plnstr, pln_theta), "theta", EF_BAD},
|
{NSC_FLOAT, 0, 0, fldoff(plnstr, pln_theta), "theta", EF_BAD},
|
||||||
|
@ -316,7 +316,7 @@ struct castr land_ca[] = {
|
||||||
{NSC_SHORT, NSC_DEITY, 0, fldoff(lndstr, lnd_ptime), "ptime", EF_BAD},
|
{NSC_SHORT, NSC_DEITY, 0, fldoff(lndstr, lnd_ptime), "ptime", EF_BAD},
|
||||||
{NSC_SHORT, 0, 0, fldoff(lndstr, lnd_land), "land", EF_BAD},
|
{NSC_SHORT, 0, 0, fldoff(lndstr, lnd_land), "land", EF_BAD},
|
||||||
{NSC_UCHAR, NSC_EXTRA, 0, fldoff(lndstr, lnd_nland), "nland", EF_BAD},
|
{NSC_UCHAR, NSC_EXTRA, 0, fldoff(lndstr, lnd_nland), "nland", EF_BAD},
|
||||||
{NSC_TIME, 0, 0, fldoff(lndstr, lnd_access), "access", EF_BAD},
|
{NSC_SHORT, 0, 0, fldoff(lndstr, lnd_access), "access", EF_BAD},
|
||||||
{NSC_FLOAT, NSC_EXTRA, 0, fldoff(lndstr, lnd_att), "att", EF_BAD},
|
{NSC_FLOAT, NSC_EXTRA, 0, fldoff(lndstr, lnd_att), "att", EF_BAD},
|
||||||
{NSC_FLOAT, NSC_EXTRA, 0, fldoff(lndstr, lnd_def), "def", EF_BAD},
|
{NSC_FLOAT, NSC_EXTRA, 0, fldoff(lndstr, lnd_def), "def", EF_BAD},
|
||||||
{NSC_INT, NSC_EXTRA, 0, fldoff(lndstr, lnd_vul), "vul", EF_BAD},
|
{NSC_INT, NSC_EXTRA, 0, fldoff(lndstr, lnd_vul), "vul", EF_BAD},
|
||||||
|
|
|
@ -69,7 +69,6 @@ char downfil[] = "down";
|
||||||
char disablefil[] = "disable";
|
char disablefil[] = "disable";
|
||||||
char telfil[] = "tel/tel";
|
char telfil[] = "tel/tel";
|
||||||
char annfil[] = "ann";
|
char annfil[] = "ann";
|
||||||
char timestampfil[] = "timestamp";
|
|
||||||
|
|
||||||
char *listen_addr = "";
|
char *listen_addr = "";
|
||||||
char *loginport = "@EMPIREPORT@";
|
char *loginport = "@EMPIREPORT@";
|
||||||
|
|
|
@ -157,7 +157,6 @@ struct cmndstr player_coms[] = {
|
||||||
{"mine <SHIPS>", 2, mine, C_MOD, NORM + MONEY + CAP},
|
{"mine <SHIPS>", 2, mine, C_MOD, NORM + MONEY + CAP},
|
||||||
{"mission <TYPE> <PLANES|SHIPS|UNITS> <mission type> <op sect> [<radius>]",
|
{"mission <TYPE> <PLANES|SHIPS|UNITS> <mission type> <op sect> [<radius>]",
|
||||||
2, mission, C_MOD, NORM + CAP},
|
2, mission, C_MOD, NORM + CAP},
|
||||||
{"mobupdate <MINUTES|check>", 0, mobupdate, C_MOD, GOD},
|
|
||||||
{"morale <UNITS> <retreat%>", 1, morale, C_MOD, NORM + CAP},
|
{"morale <UNITS> <retreat%>", 1, morale, C_MOD, NORM + CAP},
|
||||||
{"motd", 0, show_motd, C_MOD, VIS},
|
{"motd", 0, show_motd, C_MOD, VIS},
|
||||||
{"move <COMM> <SECT> <NUM> <PATH|DESTINATION>",
|
{"move <COMM> <SECT> <NUM> <PATH|DESTINATION>",
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
|
#include "game.h"
|
||||||
#include "news.h"
|
#include "news.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
|
@ -64,7 +65,7 @@ bsanct(void)
|
||||||
s.sct_type = SCT_HIWAY;
|
s.sct_type = SCT_HIWAY;
|
||||||
s.sct_newtype = SCT_HIWAY;
|
s.sct_newtype = SCT_HIWAY;
|
||||||
}
|
}
|
||||||
time(&s.sct_access);
|
game_tick_to_now(&s.sct_access);
|
||||||
(void)putsect(&s);
|
(void)putsect(&s);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
|
#include "game.h"
|
||||||
#include "land.h"
|
#include "land.h"
|
||||||
#include "lost.h"
|
#include "lost.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
@ -162,7 +163,7 @@ takeover(struct sctstr *sp, natid newown)
|
||||||
makenotlost(EF_SECTOR, newown, 0, sp->sct_x, sp->sct_y);
|
makenotlost(EF_SECTOR, newown, 0, sp->sct_x, sp->sct_y);
|
||||||
sp->sct_own = newown;
|
sp->sct_own = newown;
|
||||||
if (opt_MOB_ACCESS) {
|
if (opt_MOB_ACCESS) {
|
||||||
time(&sp->sct_access);
|
game_tick_to_now(&sp->sct_access);
|
||||||
sp->sct_mobil = -(etu_per_update / sect_mob_neg_factor);
|
sp->sct_mobil = -(etu_per_update / sect_mob_neg_factor);
|
||||||
} else {
|
} else {
|
||||||
sp->sct_mobil = 0;
|
sp->sct_mobil = 0;
|
||||||
|
@ -231,8 +232,6 @@ takeover_ship(struct shpstr *sp, natid newown, int hostile)
|
||||||
sp->shp_mission = 0;
|
sp->shp_mission = 0;
|
||||||
sp->shp_fleet = 0;
|
sp->shp_fleet = 0;
|
||||||
sp->shp_rflags = 0;
|
sp->shp_rflags = 0;
|
||||||
/* Keep track of when this was taken over */
|
|
||||||
time(&sp->shp_access);
|
|
||||||
memset(sp->shp_rpath, 0, sizeof(sp->shp_rpath));
|
memset(sp->shp_rpath, 0, sizeof(sp->shp_rpath));
|
||||||
pp = &p;
|
pp = &p;
|
||||||
lp = &llp;
|
lp = &llp;
|
||||||
|
@ -248,8 +247,8 @@ takeover_ship(struct shpstr *sp, natid newown, int hostile)
|
||||||
pp->pln_effic = PLANE_MINEFF;
|
pp->pln_effic = PLANE_MINEFF;
|
||||||
}
|
}
|
||||||
pp->pln_mobil = 0;
|
pp->pln_mobil = 0;
|
||||||
/* Keep track of when this was taken over */
|
if (opt_MOB_ACCESS)
|
||||||
time(&pp->pln_access);
|
game_tick_to_now(&pp->pln_access);
|
||||||
if (opt_MARKET)
|
if (opt_MARKET)
|
||||||
trdswitchown(EF_PLANE, pp, newown);
|
trdswitchown(EF_PLANE, pp, newown);
|
||||||
pp->pln_mission = 0;
|
pp->pln_mission = 0;
|
||||||
|
@ -286,9 +285,9 @@ takeover_land(struct lndstr *landp, natid newown, int hostile)
|
||||||
}
|
}
|
||||||
landp->lnd_army = 0;
|
landp->lnd_army = 0;
|
||||||
landp->lnd_mobil = 0;
|
landp->lnd_mobil = 0;
|
||||||
|
if (opt_MOB_ACCESS)
|
||||||
|
game_tick_to_now(&landp->lnd_access);
|
||||||
landp->lnd_harden = 0;
|
landp->lnd_harden = 0;
|
||||||
/* Keep track of when this was taken over */
|
|
||||||
time(&landp->lnd_access);
|
|
||||||
if (opt_MARKET)
|
if (opt_MARKET)
|
||||||
trdswitchown(EF_LAND, landp, newown);
|
trdswitchown(EF_LAND, landp, newown);
|
||||||
landp->lnd_mission = 0;
|
landp->lnd_mission = 0;
|
||||||
|
@ -311,8 +310,8 @@ takeover_land(struct lndstr *landp, natid newown, int hostile)
|
||||||
pp->pln_effic = PLANE_MINEFF;
|
pp->pln_effic = PLANE_MINEFF;
|
||||||
}
|
}
|
||||||
pp->pln_mobil = 0;
|
pp->pln_mobil = 0;
|
||||||
/* Keep track of when this was taken over */
|
if (opt_MOB_ACCESS)
|
||||||
time(&pp->pln_access);
|
game_tick_to_now(&pp->pln_access);
|
||||||
if (opt_MARKET)
|
if (opt_MARKET)
|
||||||
trdswitchown(EF_PLANE, pp, newown);
|
trdswitchown(EF_PLANE, pp, newown);
|
||||||
pp->pln_mission = 0;
|
pp->pln_mission = 0;
|
||||||
|
|
|
@ -67,10 +67,10 @@ update_main(void)
|
||||||
|
|
||||||
/* First, make sure all mobility is updated correctly. */
|
/* First, make sure all mobility is updated correctly. */
|
||||||
if (opt_MOB_ACCESS) {
|
if (opt_MOB_ACCESS) {
|
||||||
mob_ship(etu);
|
mob_ship();
|
||||||
mob_sect(etu);
|
mob_sect();
|
||||||
mob_plane(etu);
|
mob_plane();
|
||||||
mob_land(etu);
|
mob_land();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opt_AUTO_POWER)
|
if (opt_AUTO_POWER)
|
||||||
|
@ -155,10 +155,10 @@ update_main(void)
|
||||||
/* Only update mobility for non-MOB_ACCESS here, since it doesn't
|
/* Only update mobility for non-MOB_ACCESS here, since it doesn't
|
||||||
get done for MOB_ACCESS anyway during the update */
|
get done for MOB_ACCESS anyway during the update */
|
||||||
if (!opt_MOB_ACCESS) {
|
if (!opt_MOB_ACCESS) {
|
||||||
mob_ship(etu);
|
mob_ship();
|
||||||
mob_sect(etu);
|
mob_sect();
|
||||||
mob_plane(etu);
|
mob_plane();
|
||||||
mob_land(etu);
|
mob_land();
|
||||||
}
|
}
|
||||||
if (update_demand == UPD_DEMAND_SCHED
|
if (update_demand == UPD_DEMAND_SCHED
|
||||||
|| update_demand == UPD_DEMAND_ASYNC)
|
|| update_demand == UPD_DEMAND_ASYNC)
|
||||||
|
|
|
@ -34,133 +34,37 @@
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
#include "game.h"
|
||||||
#include "land.h"
|
#include "land.h"
|
||||||
#include "plane.h"
|
#include "plane.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "ship.h"
|
#include "ship.h"
|
||||||
#include "update.h"
|
#include "update.h"
|
||||||
|
|
||||||
|
static int do_upd_checking;
|
||||||
int updating_mob = 1;
|
|
||||||
|
|
||||||
static int timestamp_fixing;
|
|
||||||
static int do_upd_checking = 0;
|
|
||||||
|
|
||||||
static void do_mob_land(struct lndstr *, int);
|
static void do_mob_land(struct lndstr *, int);
|
||||||
static void do_mob_plane(struct plnstr *, int);
|
static void do_mob_plane(struct plnstr *, int);
|
||||||
static void do_mob_sect(struct sctstr *sp, int etus);
|
static void do_mob_sect(struct sctstr *sp, int etus);
|
||||||
static void do_mob_ship(struct shpstr *, int);
|
static void do_mob_ship(struct shpstr *, int);
|
||||||
|
|
||||||
static int
|
|
||||||
increase_mob(time_t *counter, float mult)
|
|
||||||
{
|
|
||||||
time_t secs;
|
|
||||||
time_t now;
|
|
||||||
time_t left;
|
|
||||||
int newetus;
|
|
||||||
float newmob;
|
|
||||||
int inewmob;
|
|
||||||
|
|
||||||
time(&now);
|
|
||||||
|
|
||||||
secs = now - *counter;
|
|
||||||
if (secs < 1 || secs < s_p_etu)
|
|
||||||
return 0;
|
|
||||||
newetus = (int)(secs / s_p_etu);
|
|
||||||
if (newetus < 1)
|
|
||||||
return 0;
|
|
||||||
left = (secs % s_p_etu);
|
|
||||||
do {
|
|
||||||
newmob = newetus * mult;
|
|
||||||
inewmob = (int)newmob;
|
|
||||||
if (newmob == inewmob || newetus > 7)
|
|
||||||
break;
|
|
||||||
newetus--;
|
|
||||||
left += s_p_etu;
|
|
||||||
} while (newetus > 0);
|
|
||||||
if (newetus <= 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
*counter = now - left;
|
|
||||||
|
|
||||||
if (updating_mob)
|
|
||||||
return newetus;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
update_timestamps(time_t lastsavedtime)
|
|
||||||
{
|
|
||||||
struct shpstr *shipp;
|
|
||||||
struct sctstr *sectp;
|
|
||||||
struct lndstr *landp;
|
|
||||||
struct plnstr *planep;
|
|
||||||
int n;
|
|
||||||
time_t now;
|
|
||||||
time_t delta;
|
|
||||||
|
|
||||||
timestamp_fixing = 1;
|
|
||||||
time(&now);
|
|
||||||
delta = now - lastsavedtime;
|
|
||||||
for (n = 0; (shipp = getshipp(n)); n++)
|
|
||||||
shipp->shp_access += delta;
|
|
||||||
for (n = 0; (sectp = getsectid(n)); n++)
|
|
||||||
sectp->sct_access += delta;
|
|
||||||
for (n = 0; (landp = getlandp(n)); n++)
|
|
||||||
landp->lnd_access += delta;
|
|
||||||
for (n = 0; (planep = getplanep(n)); n++)
|
|
||||||
planep->pln_access += delta;
|
|
||||||
timestamp_fixing = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
update_all_mob(void)
|
|
||||||
{
|
|
||||||
struct shpstr *shipp;
|
|
||||||
struct sctstr *sectp;
|
|
||||||
struct lndstr *landp;
|
|
||||||
struct plnstr *planep;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
n = 0;
|
|
||||||
while (1) {
|
|
||||||
do_upd_checking = 1;
|
|
||||||
shipp = getshipp(n);
|
|
||||||
sectp = getsectid(n);
|
|
||||||
landp = getlandp(n);
|
|
||||||
planep = getplanep(n);
|
|
||||||
do_upd_checking = 0;
|
|
||||||
if (shipp)
|
|
||||||
shp_do_upd_mob(shipp);
|
|
||||||
if (sectp)
|
|
||||||
sct_do_upd_mob(sectp);
|
|
||||||
if (landp)
|
|
||||||
lnd_do_upd_mob(landp);
|
|
||||||
if (planep)
|
|
||||||
pln_do_upd_mob(planep);
|
|
||||||
if (!shipp && !sectp && !landp && !planep)
|
|
||||||
break;
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
do_upd_checking = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
sct_do_upd_mob(struct sctstr *sp)
|
sct_do_upd_mob(struct sctstr *sp)
|
||||||
{
|
{
|
||||||
int etus;
|
int etus;
|
||||||
|
|
||||||
if (do_upd_checking || timestamp_fixing || update_pending)
|
if (do_upd_checking || update_pending)
|
||||||
return;
|
return;
|
||||||
if (sp->sct_own == 0)
|
if (sp->sct_own == 0)
|
||||||
return;
|
return;
|
||||||
if (sp->sct_type == SCT_SANCT)
|
if (sp->sct_type == SCT_SANCT)
|
||||||
return;
|
return;
|
||||||
if ((etus = increase_mob(&sp->sct_access, sect_mob_scale)) == 0)
|
etus = game_tick_to_now(&sp->sct_access);
|
||||||
|
if (etus == 0)
|
||||||
return;
|
return;
|
||||||
do_upd_checking = 1;
|
|
||||||
|
do_upd_checking = 1; /* avoid recursion */
|
||||||
do_mob_sect(sp, etus);
|
do_mob_sect(sp, etus);
|
||||||
/* putsect(sp);*/
|
|
||||||
do_upd_checking = 0;
|
do_upd_checking = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,13 +73,15 @@ shp_do_upd_mob(struct shpstr *sp)
|
||||||
{
|
{
|
||||||
int etus;
|
int etus;
|
||||||
|
|
||||||
if (do_upd_checking || timestamp_fixing || update_pending)
|
if (do_upd_checking || update_pending)
|
||||||
return;
|
return;
|
||||||
if (sp->shp_own == 0)
|
if (sp->shp_own == 0)
|
||||||
return;
|
return;
|
||||||
if ((etus = increase_mob(&sp->shp_access, ship_mob_scale)) == 0)
|
etus = game_tick_to_now(&sp->shp_access);
|
||||||
|
if (etus == 0)
|
||||||
return;
|
return;
|
||||||
do_upd_checking = 1;
|
|
||||||
|
do_upd_checking = 1; /* avoid recursion */
|
||||||
do_mob_ship(sp, etus);
|
do_mob_ship(sp, etus);
|
||||||
do_upd_checking = 0;
|
do_upd_checking = 0;
|
||||||
}
|
}
|
||||||
|
@ -185,14 +91,15 @@ lnd_do_upd_mob(struct lndstr *lp)
|
||||||
{
|
{
|
||||||
int etus;
|
int etus;
|
||||||
|
|
||||||
if (do_upd_checking || timestamp_fixing || update_pending)
|
if (do_upd_checking || update_pending)
|
||||||
return;
|
return;
|
||||||
if (lp->lnd_own == 0)
|
if (lp->lnd_own == 0)
|
||||||
return;
|
return;
|
||||||
if ((etus = increase_mob(&lp->lnd_access, land_mob_scale)) == 0)
|
etus = game_tick_to_now(&lp->lnd_access);
|
||||||
|
if (etus == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
do_upd_checking = 1;
|
do_upd_checking = 1; /* avoid recursion */
|
||||||
do_mob_land(lp, etus);
|
do_mob_land(lp, etus);
|
||||||
do_upd_checking = 0;
|
do_upd_checking = 0;
|
||||||
}
|
}
|
||||||
|
@ -202,32 +109,34 @@ pln_do_upd_mob(struct plnstr *pp)
|
||||||
{
|
{
|
||||||
int etus;
|
int etus;
|
||||||
|
|
||||||
if (do_upd_checking || timestamp_fixing || update_pending)
|
if (do_upd_checking || update_pending)
|
||||||
return;
|
return;
|
||||||
if (pp->pln_own == 0)
|
if (pp->pln_own == 0)
|
||||||
return;
|
return;
|
||||||
if ((etus = increase_mob(&pp->pln_access, plane_mob_scale)) == 0)
|
etus = game_tick_to_now(&pp->pln_access);
|
||||||
|
if (etus == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
do_upd_checking = 1;
|
do_upd_checking = 1; /* avoid recursion */
|
||||||
do_mob_plane(pp, etus);
|
do_mob_plane(pp, etus);
|
||||||
do_upd_checking = 0;
|
do_upd_checking = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mob_sect(int etus)
|
mob_sect(void)
|
||||||
{
|
{
|
||||||
struct sctstr *sp;
|
struct sctstr *sp;
|
||||||
int n;
|
int n, etus;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
time(&now);
|
time(&now);
|
||||||
for (n = 0; NULL != (sp = getsectid(n)); n++) {
|
for (n = 0; NULL != (sp = getsectid(n)); n++) {
|
||||||
sp->sct_timestamp = now;
|
sp->sct_timestamp = now;
|
||||||
if (opt_MOB_ACCESS)
|
if (opt_MOB_ACCESS)
|
||||||
sct_do_upd_mob(sp);
|
etus = game_reset_tick(&sp->sct_access);
|
||||||
else
|
else
|
||||||
do_mob_sect(sp, etus);
|
etus = etu_per_update;
|
||||||
|
do_mob_sect(sp, etus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,6 +145,9 @@ do_mob_sect(struct sctstr *sp, int etus)
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
|
if (CANT_HAPPEN(etus < 0))
|
||||||
|
etus = 0;
|
||||||
|
|
||||||
if (sp->sct_own == 0)
|
if (sp->sct_own == 0)
|
||||||
return;
|
return;
|
||||||
if (sp->sct_type == SCT_SANCT)
|
if (sp->sct_type == SCT_SANCT)
|
||||||
|
@ -248,19 +160,20 @@ do_mob_sect(struct sctstr *sp, int etus)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mob_ship(int etus)
|
mob_ship(void)
|
||||||
{
|
{
|
||||||
struct shpstr *sp;
|
struct shpstr *sp;
|
||||||
int n;
|
int n, etus;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
time(&now);
|
time(&now);
|
||||||
for (n = 0; NULL != (sp = getshipp(n)); n++) {
|
for (n = 0; NULL != (sp = getshipp(n)); n++) {
|
||||||
sp->shp_timestamp = now;
|
sp->shp_timestamp = now;
|
||||||
if (opt_MOB_ACCESS)
|
if (opt_MOB_ACCESS)
|
||||||
shp_do_upd_mob(sp);
|
etus = game_reset_tick(&sp->shp_access);
|
||||||
else
|
else
|
||||||
do_mob_ship(sp, etus);
|
etus = etu_per_update;
|
||||||
|
do_mob_ship(sp, etus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,6 +185,9 @@ do_mob_ship(struct shpstr *sp, int etus)
|
||||||
int can_add, have_fuel_for, total_add;
|
int can_add, have_fuel_for, total_add;
|
||||||
double d;
|
double d;
|
||||||
|
|
||||||
|
if (CANT_HAPPEN(etus < 0))
|
||||||
|
etus = 0;
|
||||||
|
|
||||||
if (sp->shp_own == 0)
|
if (sp->shp_own == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -344,19 +260,20 @@ do_mob_ship(struct shpstr *sp, int etus)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mob_land(int etus)
|
mob_land(void)
|
||||||
{
|
{
|
||||||
struct lndstr *lp;
|
struct lndstr *lp;
|
||||||
int n;
|
int n, etus;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
time(&now);
|
time(&now);
|
||||||
for (n = 0; NULL != (lp = getlandp(n)); n++) {
|
for (n = 0; NULL != (lp = getlandp(n)); n++) {
|
||||||
lp->lnd_timestamp = now;
|
lp->lnd_timestamp = now;
|
||||||
if (opt_MOB_ACCESS)
|
if (opt_MOB_ACCESS)
|
||||||
lnd_do_upd_mob(lp);
|
etus = game_reset_tick(&lp->lnd_access);
|
||||||
else
|
else
|
||||||
do_mob_land(lp, etus);
|
etus = etu_per_update;
|
||||||
|
do_mob_land(lp, etus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,6 +285,9 @@ do_mob_land(struct lndstr *lp, int etus)
|
||||||
int can_add, have_fuel_for, total_add;
|
int can_add, have_fuel_for, total_add;
|
||||||
double d;
|
double d;
|
||||||
|
|
||||||
|
if (CANT_HAPPEN(etus < 0))
|
||||||
|
etus = 0;
|
||||||
|
|
||||||
if (lp->lnd_own == 0)
|
if (lp->lnd_own == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -453,19 +373,20 @@ do_mob_land(struct lndstr *lp, int etus)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mob_plane(int etus)
|
mob_plane(void)
|
||||||
{
|
{
|
||||||
struct plnstr *pp;
|
struct plnstr *pp;
|
||||||
int n;
|
int n, etus;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
time(&now);
|
time(&now);
|
||||||
for (n = 0; NULL != (pp = getplanep(n)); n++) {
|
for (n = 0; NULL != (pp = getplanep(n)); n++) {
|
||||||
pp->pln_timestamp = now;
|
pp->pln_timestamp = now;
|
||||||
if (opt_MOB_ACCESS)
|
if (opt_MOB_ACCESS)
|
||||||
pln_do_upd_mob(pp);
|
etus = game_reset_tick(&pp->pln_access);
|
||||||
else
|
else
|
||||||
do_mob_plane(pp, etus);
|
etus = etu_per_update;
|
||||||
|
do_mob_plane(pp, etus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,6 +395,9 @@ do_mob_plane(struct plnstr *pp, int etus)
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
|
if (CANT_HAPPEN(etus < 0))
|
||||||
|
etus = 0;
|
||||||
|
|
||||||
if (pp->pln_own == 0)
|
if (pp->pln_own == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -298,11 +298,6 @@ init_server(void)
|
||||||
init_nreport();
|
init_nreport();
|
||||||
|
|
||||||
loginit("server");
|
loginit("server");
|
||||||
|
|
||||||
if (opt_MOB_ACCESS) {
|
|
||||||
/* This fixes up mobility upon restart */
|
|
||||||
mobility_init();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -329,10 +324,6 @@ start_server(int flags)
|
||||||
"KillIdle", 0);
|
"KillIdle", 0);
|
||||||
empth_create(PP_TIMESTAMP, delete_lostitems, (50 * 1024), flags,
|
empth_create(PP_TIMESTAMP, delete_lostitems, (50 * 1024), flags,
|
||||||
"DeleteItems", 0);
|
"DeleteItems", 0);
|
||||||
if (opt_MOB_ACCESS) {
|
|
||||||
empth_create(PP_TIMESTAMP, mobility_check, (50 * 1024), flags,
|
|
||||||
"MobilityCheck", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
market_init();
|
market_init();
|
||||||
update_init();
|
update_init();
|
||||||
|
|
|
@ -1,128 +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.
|
|
||||||
*
|
|
||||||
* ---
|
|
||||||
*
|
|
||||||
* timestamp.c: Timestamp writer/maintainer thread
|
|
||||||
*
|
|
||||||
* Known contributors to this file:
|
|
||||||
* Steve McClure, 1996
|
|
||||||
* Doug Hay, 1998
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include "empthread.h"
|
|
||||||
#include "misc.h"
|
|
||||||
#include "optlist.h"
|
|
||||||
#include "prototypes.h"
|
|
||||||
#include "server.h"
|
|
||||||
|
|
||||||
/*ARGSUSED*/
|
|
||||||
void
|
|
||||||
mobility_check(void *unused)
|
|
||||||
{
|
|
||||||
struct mob_acc_globals timestamps;
|
|
||||||
time_t now;
|
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
time(&now);
|
|
||||||
/* logerror("Updating timestamp file at %s", ctime(&now));*/
|
|
||||||
if ((fp = fopen(timestampfil, "rb+")) == NULL) {
|
|
||||||
logerror("Unable to edit timestamp file.");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
rewind(fp);
|
|
||||||
fread(×tamps, sizeof(timestamps), 1, fp);
|
|
||||||
timestamps.timestamp = now;
|
|
||||||
rewind(fp);
|
|
||||||
fwrite(×tamps, sizeof(timestamps), 1, fp);
|
|
||||||
fclose(fp);
|
|
||||||
if (!gamehours(now)) {
|
|
||||||
if (updating_mob == 1) {
|
|
||||||
update_all_mob();
|
|
||||||
logerror("Turning off mobility updating (gamehours).");
|
|
||||||
updating_mob = 0;
|
|
||||||
}
|
|
||||||
} else if (updating_mob == 1 && now < timestamps.starttime) {
|
|
||||||
logerror("Turning off mobility updating at %s", ctime(&now));
|
|
||||||
update_all_mob();
|
|
||||||
updating_mob = 0;
|
|
||||||
} else if (updating_mob == 0 && now >= timestamps.starttime) {
|
|
||||||
logerror("Turning on mobility updating at %s", ctime(&now));
|
|
||||||
update_all_mob();
|
|
||||||
updating_mob = 1;
|
|
||||||
}
|
|
||||||
now = now + 180; /* Every 3 minutes */
|
|
||||||
empth_sleep(now);
|
|
||||||
|
|
||||||
}
|
|
||||||
/*NOTREACHED*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
mobility_init(void)
|
|
||||||
{
|
|
||||||
struct mob_acc_globals timestamps;
|
|
||||||
time_t now;
|
|
||||||
time_t lastsavedtime;
|
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
/* During downtime, we don't want mobility to accrue. So, we look
|
|
||||||
at the timestamp file, and determine how far forward to push
|
|
||||||
mobility */
|
|
||||||
|
|
||||||
time(&now);
|
|
||||||
if ((fp = fopen(timestampfil, "rb+")) == NULL) {
|
|
||||||
logerror("Unable to edit timestamp file.");
|
|
||||||
/* FIXME safe to continue? */
|
|
||||||
} else {
|
|
||||||
rewind(fp);
|
|
||||||
fread(×tamps, sizeof(timestamps), 1, fp);
|
|
||||||
lastsavedtime = timestamps.timestamp;
|
|
||||||
timestamps.timestamp = now;
|
|
||||||
rewind(fp);
|
|
||||||
fwrite(×tamps, sizeof(timestamps), 1, fp);
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
time(&now);
|
|
||||||
logerror("Adjusting timestamps at %s", ctime(&now));
|
|
||||||
logerror("(was %s)", ctime(&lastsavedtime));
|
|
||||||
/* Update the timestamps to this point in time */
|
|
||||||
update_timestamps(lastsavedtime);
|
|
||||||
time(&now);
|
|
||||||
logerror("Done at %s", ctime(&now));
|
|
||||||
|
|
||||||
if (now >= timestamps.starttime && gamehours(now)) {
|
|
||||||
logerror("Turning on mobility updating.");
|
|
||||||
updating_mob = 1;
|
|
||||||
} else {
|
|
||||||
logerror("Turning off mobility updating.");
|
|
||||||
updating_mob = 0;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -186,7 +186,6 @@ main(int argc, char *argv[])
|
||||||
filename = mailbox(buf, x);
|
filename = mailbox(buf, x);
|
||||||
close(creat(filename, S_IRWUG));
|
close(creat(filename, S_IRWUG));
|
||||||
}
|
}
|
||||||
close(creat(timestampfil, S_IRWUG));
|
|
||||||
close(creat(annfil, S_IRWUG));
|
close(creat(annfil, S_IRWUG));
|
||||||
|
|
||||||
/* create a zero-filled sector file */
|
/* create a zero-filled sector file */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue