Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ Programming ➜ General ➜ ROM Code: Real Time vs. Role Playing Time

ROM Code: Real Time vs. Role Playing Time

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Skane   (1 post)  Bio
Date Thu 29 Apr 2004 01:19 AM (UTC)
Message
I'm going through the ROM source code (db.c file, ROM 2.4) and I'm trying to figure out how ROM does its timing and I just don't understand how this code works...

/*
* Set time and weather.
*/
{
long lhour, lday, lmonth;

lhour = (current_time - 650336715)
/ (PULSE_TICK / PULSE_PER_SECOND);
time_info.hour = lhour % 24;
lday = lhour / 24;
time_info.day = lday % 35;
lmonth = lday / 35;
time_info.month = lmonth % 17;
time_info.year = lmonth / 17;

Okay -- what is the significance of 650336715? What exactly is the code that divides to get lhour doing? I'm not as concerned with the code below it, but an explanation of why 35 and 17 are used would be helpful too.

One last question -- what kind value is current_time? Is it the current time in seconds? In comm.c, it is defined as:

time_t current_time; /* time of this pulse */

and later it is defined as:
gettimeofday( &now_time, NULL );
current_time = (time_t) now_time.tv_sec;

Gettimeofday's function:
int gettimeofday( struct timeval *tp, void *tzp )
{
tp->tv_sec = time( NULL );
tp->tv_usec = 0;
}


Hope this helps. I'm just trying to get some clarification on what this code is doing and maybe some background help on how the time system works in ROM or any other text-based role playing game. I've heard the time in ROM is 2 hours = 1 year -- is this correct? How can this be changed or verified?



Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #1 on Thu 29 Apr 2004 01:29 AM (UTC)
Message
current_time is the number of seconds since the Epoch, which is typically Jan-01-1970 00:00.

The monster subtraction is effectively shifting the Epoch, I believe. It doesn't matter as far as the code is concerned.

Are you wondering about the % operator? That means modulo; basically, it does the division and gives you the remainder.

5 % 2 = 1. 2 goes into 5 twice, remainder of 1.

49 % 24 = 1.

128 % 100 = 28.

I believe that 35 and 17 are simply arbitrary constants.

So to verify your two hours = 1 year, you would just see how much game-time progresses in one second of real life and then just multiply by 60 * 60 * 2.

Here's a starting point:

lhour = (current_time - 650336715)
    / (PULSE_TICK / PULSE_PER_SECOND);


To get technical about things you derive the lhour function; to be less mathematical about it you look at how much lhour changes if you increase current_time by 1. The answer is 1/(PT/PPS) = PPS/PT.

So go figure out what those values are (PPS and PT) and you have an answer. Don't forget that this is integer and not floating-point division.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


10,365 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.