Represent logged in time in seconds rather than minutes
This simplifies things. In particular, it gets rid of random rounding in getcommand(), which created a variation in the nightly build depending on whether the update starts before or after the deity logs out. Replace struct natstr member nat_minused by nat_timeused, and update cou_ca[] accordingly (this affects xdump nat). Replace player member minleft by timeleft, and getminleft() by gettimeleft(). Update getcommand(), daychange(), player_main(), status() accordingly, taking care not to change player output. Change edit country key 'u' to work in seconds.
This commit is contained in:
parent
436328f641
commit
14319b89ec
10 changed files with 40 additions and 42 deletions
|
@ -99,7 +99,7 @@ struct natstr {
|
|||
signed char nat_update; /* Want an update or not. */
|
||||
unsigned short nat_tgms; /* # of telegrams to be announced */
|
||||
unsigned short nat_ann; /* # of annos pending */
|
||||
unsigned short nat_minused; /* number of minutes used today */
|
||||
int nat_timeused; /* number of seconds used today */
|
||||
short nat_btu; /* bureaucratic time units */
|
||||
short nat_access; /* The tick when BTUs were last updated */
|
||||
long nat_reserve; /* military reserves */
|
||||
|
|
|
@ -67,8 +67,8 @@ struct player {
|
|||
char *argp[128]; /* arguments, ASCII, valid if command */
|
||||
char *condarg; /* conditional, ASCII, valid if command */
|
||||
char *comtail[128]; /* start of args in combuf[] */
|
||||
time_t lasttime; /* when minleft was last debited */
|
||||
int minleft;
|
||||
time_t lasttime; /* when timeleft was last debited */
|
||||
int timeleft;
|
||||
int btused;
|
||||
int god;
|
||||
int owner;
|
||||
|
|
|
@ -368,7 +368,7 @@ extern void init_player_commands(void);
|
|||
extern void log_last_commands(void);
|
||||
extern int gamedown(void);
|
||||
extern void daychange(time_t);
|
||||
extern int getminleft(time_t, int);
|
||||
extern int gettimeleft(time_t, int);
|
||||
/* more under Commands */
|
||||
/* empmod.c */
|
||||
/* init_nats.c */
|
||||
|
|
|
@ -300,7 +300,7 @@ prnat(struct natstr *np)
|
|||
pr("Origin <o>: %3s\n",
|
||||
xyas(np->nat_xorg, np->nat_yorg, player->cnum));
|
||||
pr("Status <s>: 0x%x\t\t\t", np->nat_stat);
|
||||
pr("Min Used <u>: %3d\n", np->nat_minused);
|
||||
pr("Seconds Used <u>: %3d\n", np->nat_timeused);
|
||||
pr("Technology <T>: %.2f\t\t", np->nat_level[NAT_TLEV]);
|
||||
pr("Research <R>: %.2f\n", np->nat_level[NAT_RLEV]);
|
||||
pr("Education <E>: %.2f\t\t", np->nat_level[NAT_ELEV]);
|
||||
|
@ -703,10 +703,10 @@ docountry(char op, int arg, char *p, struct natstr *np)
|
|||
np->nat_stat = errcheck(arg, STAT_UNUSED, STAT_GOD);
|
||||
break;
|
||||
case 'u':
|
||||
arg = errcheck(arg, 0, m_m_p_d);
|
||||
pr("Number of minutes used changed from %d to %d.\n",
|
||||
np->nat_minused, arg);
|
||||
np->nat_minused = arg;
|
||||
arg = errcheck(arg, 0, m_m_p_d * 60);
|
||||
pr("Number of seconds used changed from %d to %d.\n",
|
||||
np->nat_timeused, arg);
|
||||
np->nat_timeused = arg;
|
||||
break;
|
||||
case 'M':
|
||||
pr("Money changed from %ld to %d\n", np->nat_money, arg);
|
||||
|
|
|
@ -101,8 +101,8 @@ play_list(struct player *joe)
|
|||
cname(joe->cnum),
|
||||
joe->cnum,
|
||||
player->god || joe->cnum == player->cnum ? praddr(joe) : "",
|
||||
natp->nat_minused / 60,
|
||||
natp->nat_minused % 60,
|
||||
natp->nat_timeused / 3600,
|
||||
(natp->nat_timeused % 3600) / 60,
|
||||
(long)(now - joe->curup));
|
||||
|
||||
if (player->god) {
|
||||
|
|
|
@ -564,7 +564,7 @@ struct castr cou_ca[] = {
|
|||
{"update", fldoff(nat_update), NSC_CHAR, 0, NULL, EF_BAD, 0},
|
||||
{"tgms", fldoff(nat_tgms), NSC_USHORT, 0, NULL, EF_BAD, 0},
|
||||
{"ann", fldoff(nat_ann), NSC_USHORT, 0, NULL, EF_BAD, 0},
|
||||
{"minused", fldoff(nat_minused), NSC_USHORT, 0, NULL, EF_BAD, 0},
|
||||
{"timeused", fldoff(nat_timeused), NSC_INT, 0, NULL, EF_BAD, 0},
|
||||
{"btu", fldoff(nat_btu), NSC_SHORT, 0, NULL, EF_BAD, 0},
|
||||
{"access", fldoff(nat_access), NSC_SHORT, 0, NULL, EF_BAD, 0},
|
||||
{"milreserve", fldoff(nat_reserve), NSC_LONG, 0, NULL, EF_BAD, 0},
|
||||
|
|
|
@ -78,7 +78,7 @@ getcommand(char *combufp)
|
|||
player_commands_index, player->cnum);
|
||||
|
||||
do {
|
||||
prprompt(natp->nat_minused, natp->nat_btu);
|
||||
prprompt(natp->nat_timeused / 60, natp->nat_btu);
|
||||
buf[0] = 0;
|
||||
if (recvclient(buf, 1024) < 0) {
|
||||
return -1;
|
||||
|
@ -223,23 +223,23 @@ daychange(time_t now)
|
|||
tm = localtime(&now);
|
||||
if ((tm->tm_yday % 128) != natp->nat_dayno) {
|
||||
natp->nat_dayno = tm->tm_yday % 128;
|
||||
natp->nat_minused = 0;
|
||||
natp->nat_timeused = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
getminleft(time_t now, int mpd)
|
||||
gettimeleft(time_t now, int mpd)
|
||||
{
|
||||
struct tm *tm;
|
||||
int nminleft;
|
||||
int nsecleft;
|
||||
struct natstr *natp;
|
||||
int n;
|
||||
|
||||
tm = localtime(&now);
|
||||
natp = getnatp(player->cnum);
|
||||
nminleft = mpd - natp->nat_minused;
|
||||
n = 60 * 24 - (tm->tm_min + tm->tm_hour * 60);
|
||||
if (n < nminleft)
|
||||
nminleft = n;
|
||||
return nminleft;
|
||||
nsecleft = mpd * 60 - natp->nat_timeused;
|
||||
n = 60 * 60 * 24 - (tm->tm_sec + tm->tm_min * 60 + tm->tm_hour * 3600);
|
||||
if (n < nsecleft)
|
||||
nsecleft = n;
|
||||
return nsecleft;
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ player_main(struct player *p)
|
|||
return;
|
||||
}
|
||||
daychange(player->curup);
|
||||
if ((player->minleft = getminleft(player->curup, m_m_p_d)) <= 0) {
|
||||
if ((player->timeleft = gettimeleft(player->curup, m_m_p_d)) <= 0) {
|
||||
pr("Time exceeded today\n");
|
||||
return;
|
||||
}
|
||||
|
@ -124,10 +124,7 @@ player_main(struct player *p)
|
|||
*/
|
||||
time(&natp->nat_last_logout);
|
||||
secs = MAX(natp->nat_last_logout - player->lasttime, 15);
|
||||
natp->nat_minused += secs / 60;
|
||||
secs = secs % 60;
|
||||
if (chance(secs / 60.0))
|
||||
natp->nat_minused += 1;
|
||||
natp->nat_timeused += secs;
|
||||
putnat(natp);
|
||||
pr("Bye-bye\n");
|
||||
journal_logout();
|
||||
|
@ -155,7 +152,7 @@ static int
|
|||
status(void)
|
||||
{
|
||||
struct natstr *natp;
|
||||
int old_nstat, minute;
|
||||
int old_nstat, second;
|
||||
char buf[128];
|
||||
|
||||
if (player->eof || player->state == PS_SHUTDOWN)
|
||||
|
@ -185,12 +182,12 @@ status(void)
|
|||
pr("You are no longer broke!\n");
|
||||
|
||||
time(&player->curup);
|
||||
minute = (player->curup - player->lasttime) / 60;
|
||||
if (minute > 0) {
|
||||
player->minleft -= minute;
|
||||
if (player->minleft <= 0) {
|
||||
second = player->curup - player->lasttime;
|
||||
if (second > 0) {
|
||||
player->timeleft -= second;
|
||||
if (player->timeleft <= 0) {
|
||||
/*
|
||||
* countdown timer "player->minleft" has expired.
|
||||
* countdown timer "player->timeleft" has expired.
|
||||
* either day change, or hours restriction
|
||||
*/
|
||||
daychange(player->curup);
|
||||
|
@ -201,12 +198,13 @@ status(void)
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
player->minleft = getminleft(player->curup, m_m_p_d);
|
||||
player->timeleft = gettimeleft(player->curup, m_m_p_d);
|
||||
}
|
||||
player->lasttime += minute * 60;
|
||||
natp->nat_minused += minute;
|
||||
player->lasttime += second;
|
||||
natp->nat_timeused += second;
|
||||
}
|
||||
if (natp->nat_stat == STAT_ACTIVE && natp->nat_minused > m_m_p_d) {
|
||||
if (natp->nat_stat == STAT_ACTIVE &&
|
||||
natp->nat_timeused > m_m_p_d * 60) {
|
||||
pr("Max minutes per day limit exceeded.\n");
|
||||
player->nstat = (player->nstat & ~NORM) | VIS;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ nat_reset(struct natstr *natp, enum nat_status stat, coord x, coord y)
|
|||
}
|
||||
|
||||
natp->nat_dayno = 0;
|
||||
natp->nat_minused = 0;
|
||||
natp->nat_timeused = 0;
|
||||
natp->nat_update = 0;
|
||||
|
||||
natp->nat_tgms = 0;
|
||||
|
|
|
@ -818,17 +818,17 @@ index 513382b..4b97be7 100644
|
|||
- time(&natp->nat_last_logout);
|
||||
+ empire_time(&natp->nat_last_logout);
|
||||
secs = MAX(natp->nat_last_logout - player->lasttime, 15);
|
||||
natp->nat_minused += secs / 60;
|
||||
secs = secs % 60;
|
||||
natp->nat_timeused += secs;
|
||||
putnat(natp);
|
||||
@@ -182,7 +183,7 @@ status(void)
|
||||
if (!(old_nstat & MONEY) && (player->nstat & MONEY))
|
||||
pr("You are no longer broke!\n");
|
||||
|
||||
- time(&player->curup);
|
||||
+ empire_time(&player->curup);
|
||||
minute = (player->curup - player->lasttime) / 60;
|
||||
if (minute > 0) {
|
||||
player->minleft -= minute;
|
||||
second = player->curup - player->lasttime;
|
||||
if (second > 0) {
|
||||
player->timeleft -= second;
|
||||
diff --git a/src/lib/player/recvclient.c b/src/lib/player/recvclient.c
|
||||
index ab4ef69..8934189 100644
|
||||
--- a/src/lib/player/recvclient.c
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue