Welcome to the Builder Academy

Question playing_time in do_score

More
02 Feb 2013 17:09 #1447 by Fubar
ACMD(do_score)
Code:
playing_time = *real_time_passed((time(0) - ch->player.time.logon) + ch->player.time.played, 0); send_to_char(ch, "You have been playing for %d day%s, %d hour%s, %d minute%s, and %d second%s.\r\n", playing_time.day, playing_time.day == 1 ? "" : "s", playing_time.hours, playing_time.hours == 1 ? "" : "s", playing_time.minutes, playing_time.minutes == 1 ? "" : "s", playing_time.seconds, playing_time.seconds == 1 ? "" : "s");

Utils.c
Code:
struct time_info_data *real_time_passed(time_t t2, time_t t1) { long secs; static struct time_info_data now; secs = t2 - t1; now.hours = (secs / SECS_PER_REAL_HOUR) % 24; /* 0..23 hours */ secs -= SECS_PER_REAL_HOUR * now.hours; now.day = (secs / SECS_PER_REAL_DAY); /* 0..34 days */ /* secs -= SECS_PER_REAL_DAY * now.day; - Not used. */ now.seconds = -1; now.minutes = -1; now.month = -1; now.year = -1; return (&now); }

Now this shows

You have been playing for 0 days, 17 hours, -1 minutes, and -1 seconds.


But if I change the code to something other than above I get:

You have been playing for 0 days, 17 hours, 0 minutes, and 0 seconds.


Now i tried

now.seconds = secs;

But that gives me a huge number, way to huge.

Is there something I am missing.

Please Log in or Create an account to join the conversation.

More
02 Feb 2013 18:03 #1448 by zusuk
Replied by zusuk on topic Re: playing_time in do_score
Hey Fubar:

Just at a quick glance, it seems like 'secs' is the total seconds, i.e. the total play-time.

So if that is the case, the utils.c function is subracting just the hours from the grand-total of playing time seconds.

If that's the case, you have the leftover of all the days, minutes AND seconds still lefter over in the 'secs' value.

I am most definiately not sure though, I am completely unfamiliar with that code :P

Website
www.luminariMUD.com

Main Game Port
luminariMUD.com:4100

Please Log in or Create an account to join the conversation.

More
03 Feb 2013 06:22 #1449 by Vatiken
Code:
/** Calculate the REAL time passed between two time invervals. * @param t2 The later time. * @param t1 The earlier time. * @retval time_info_data The real hours, days, months and years passed between t2 and t1. */ struct time_info_data *real_time_passed(time_t t2, time_t t1) { long secs; static struct time_info_data now; secs = t2 - t1; now.hours = (secs / SECS_PER_REAL_HOUR) % 24; /* 0..23 hours */ secs -= SECS_PER_REAL_HOUR * now.hours; now.day = (secs / SECS_PER_REAL_DAY) % 35; /* 0..34 days */ secs -= SECS_PER_REAL_DAY * now.day; now.month = (secs / (SECS_PER_REAL_YEAR / 12)) % 12; /* 0..11 months */ secs -= (SECS_PER_REAL_YEAR / 12) * now.month; now.year = (secs / SECS_PER_REAL_YEAR); secs -= SECS_PER_REAL_YEAR * now.year; return (&now); }

Tweaked the original real_time_passed() to include months and years, you should be able to take it further to include minutes and seconds if that's what you desire.

tbaMUD developer/programmer

Please Log in or Create an account to join the conversation.

More
03 Feb 2013 19:05 - 03 Feb 2013 19:19 #1453 by Fubar
Replied by Fubar on topic Re: playing_time in do_score
Code:
now.minutes = (secs / SECS_PER_REAL_HOUR) % 60; /* 0..59 minutes */ secs -= SECS_PER_REAL_HOUR * now.minutes;

It shows 53 so ill now in 7 minutes if it switches to days.

but seconds seem to be the hardest is there a way to edit the pfile to show if the months, days and years?
Last edit: 03 Feb 2013 19:19 by Fubar.

Please Log in or Create an account to join the conversation.

More
04 Feb 2013 08:44 - 04 Feb 2013 09:35 #1454 by zusuk
Replied by zusuk on topic Re: playing_time in do_score
I did not really understand what you wanted, but I will take a guess :P

Just an important note though, I took a gander at the structure and it does not already have the 'minutes' element in it, so you would have to add it. Same with seconds. (in structs.h)
Code:
now.minutes = (secs / SECS_PER_REAL_MIN) % 60; /* <------------- this what you want? */ secs -= SECS_PER_REAL_MIN * now.minutes; ... now.hours = (secs / SECS_PER_REAL_HOUR) % 24; /* 0..23 hours */ secs -= SECS_PER_REAL_HOUR * now.hours; now.day = (secs / SECS_PER_REAL_DAY) % 35; /* 0..34 days */ secs -= SECS_PER_REAL_DAY * now.day; now.month = (secs / (SECS_PER_REAL_YEAR / 12)) % 12; /* 0..11 months */ secs -= (SECS_PER_REAL_YEAR / 12) * now.month; now.year = (secs / SECS_PER_REAL_YEAR); secs -= SECS_PER_REAL_YEAR * now.year;

Website
www.luminariMUD.com

Main Game Port
luminariMUD.com:4100
Last edit: 04 Feb 2013 09:35 by zusuk. Reason: didn't format code

Please Log in or Create an account to join the conversation.

More
08 Apr 2024 04:11 #10378 by Fubar
Replied by Fubar on topic playing_time in do_score
Ok I figured it out. I lost all my files a long time ago, so I have been trying to restore what was.

UTILSC:

/** Calculate the REAL time passed between two time invervals.
* @param t2 The later time.
* @param t1 The earlier time.
* @retval time_info_data The real hours, days, months and years passed between t2 and t1. */
struct time_info_data* real_time_passed(time_t t2, time_t t1)
{
long secs;
static struct time_info_data now;

secs = t2 - t1;

now.seconds = (secs / (SECS_PER_REAL_MIN / 60)) % 60;/* 0..59 seconds */
secs -= (SECS_PER_REAL_MIN / 60) * now.seconds;

now.minutes = (secs / SECS_PER_REAL_MIN) % 60; /* 0..59 minutes */
secs -= SECS_PER_REAL_MIN * now.minutes;

now.hours = (secs / SECS_PER_REAL_HOUR) % 24; /* 0..23 hours */
secs -= SECS_PER_REAL_HOUR * now.hours;

now.day = (secs / SECS_PER_REAL_DAY) % 35; /* 0..34 days */
secs -= SECS_PER_REAL_DAY * now.day;

now.month = (secs / (SECS_PER_REAL_YEAR / 12)) % 12; /* 0..11 months */
secs -= (SECS_PER_REAL_YEAR / 12) * now.month;

now.year = (secs / SECS_PER_REAL_YEAR);
secs -= SECS_PER_REAL_YEAR * now.year;

return (&now);
}

UtILS.H:

/** The number of seconds in a real seconds. */
#define SECS_PER_REAL_SEC 60
/** The number of seconds in a real minute. */
#define SECS_PER_REAL_MIN 60
/** The number of seconds in a real hour. */
#define SECS_PER_REAL_HOUR (60*SECS_PER_REAL_MIN)
/** The number of seconds in a real day. */
#define SECS_PER_REAL_DAY (24*SECS_PER_REAL_HOUR)
/** The number of seconds in a real year. */
#define SECS_PER_REAL_YEAR (365*SECS_PER_REAL_DAY)

ACT.INFORMATIVE.C:
playing_time = *real_time_passed((time(0) - ch->player.time.logon) +
ch->player.time.played, 0);

send_to_char(ch, "PLAYTIME: %d year%s, %d day%s, %d hour%s, %d minute%s, and %d second%s\r\n\r\n",
playing_time.year, playing_time.year == 1 ? "" : "s",
playing_time.day, playing_time.day == 1 ? "" : "s",
playing_time.hours, playing_time.hours == 1 ? "" : "s",
playing_time.minutes, playing_time.minutes == 1 ? "" : "s",
playing_time.seconds, playing_time.seconds == 1 ? "" : "s");


This will show:

PLAYTIME: 0 years, 0 days, 0 hours, 32 minutes, and 37 seconds

Second will now be actual seconds or very close to it. You can check by typing score every second and it should up date. Mushclient has a great timer function that I checked with. I have a imp and a non immortal character that show good information.

Please Log in or Create an account to join the conversation.

Time to create page: 0.230 seconds