ROM Code: Real Time vs. Role Playing Time

Posted by Skane on Thu 29 Apr 2004 01:19 AM — 2 posts, 12,139 views.

#0
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?



USA #1
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.