#define SEC_PER_MUD_MIN 3
#define SEC_PER_MUD_HOUR (60*SEC_PER_MUD_MIN) /* 180 */
#define SEC_PER_MUD_DAY (24*SEC_PER_MUD_HOUR) /* 4320 */
#define SEC_PER_MUD_MONTH (32*SEC_PER_MUD_DAY) /* 138240 */
#define SEC_PER_MUD_YEAR (20*SEC_PER_MUD_MONTH) /* 2764800 */
// decade name
const char *decade_name[] = {
/* 1 */ "the Rebirth" ,
/* 2 */ "the Twin Towers" ,
/* 3 */ "Asheron's Call" ,
/* 4 */ "the Black Rain" ,
/* 5 */ "the Blinding" ,
/* 6 */ "the First Sight" ,
/* 7 */ "the Moon Rivers" ,
/* 8 */ "the Sky Fall" ,
/* 9 */ "the Shields of Fate" ,
/* 10 */ "the Fates" ,
/* 11 */ "the Great Battles" ,
/* 12 */ "the Revolt" ,
/* 13 */ "the Rebellion" ,
/* 14 */ "Mica's Regret" ,
/* 15 */ "the Fierce Winds" } ;
const char *month_name[] = {
/* 1 */ "Month of Terebrinth" ,
/* 2 */ "Month of Czuven Lith" ,
/* 3 */ "Month of Cian" ,
/* 4 */ "Month of Diere" ,
/* 5 */ "Month of Garai" ,
/* 6 */ "Month of Shevatt" ,
/* 7 */ "Month of Juno" ,
/* 8 */ "Month of Micah" ,
/* 9 */ "Month of Ezra" ,
/* 10 */ "Month of Durai" ,
/* 11 */ "Month of Poshu" ,
/* 12 */ "Month of Quezacotl" ,
/* 13 */ "Month of Armagged" ,
/* 14 */ "Month of Osiris" ,
/* 15 */ "Month of Iris" ,
/* 16 */ "Month of Ar" ,
/* 17 */ "Month of MonThaire" ,
/* 18 */ "Month of Iezapeth" ,
/* 19 */ "Month of Ttannia" ,
/* 20 */ "Month of Zerynth" ,
} ;
// day of the week
const char *day_of_week[] = {
/* Holy */ "the Day of Sunnan" ,
/* Wind */ "the Day of Celes" ,
/* Fire */ "the Day of Helios" ,
/* Earth */ "the Day of Zovogath" ,
/* Water */ "the Day of Leviath" ,
/* Thunder */ "the Day of Innothor" ,
/* Dark */ "the Day of Anak-zuul" ,
/* Strength */ "the Day of Runaeis" } ;
// time information container
typedef struct
{
unsigned int year : 32 ;
unsigned int months : 8 ; // 20 months in a year
unsigned int days : 8 ; // 32 days in a month
unsigned int hours : 8; // 24 hours a day
unsigned int minutes : 8; // 60 minutes an hour
} M_TIME_DATA;
// gets the current MUD time based on the beginning of time
M_TIME_DATA get_current_mud_time(time_t epoch, time_t current_time)
{
M_TIME_DATA now ;
unsigned long seconds_passed ;
seconds_passed = (unsigned long) (current_time - epoch) ;
memset(&now, 0x00, sizeof(M_TIME_DATA)) ;
now.minutes = (seconds_passed/SEC_PER_MUD_MIN) % 60; // 0..59
seconds_passed -= SEC_PER_MUD_MIN * now.minutes;
now.hours = (seconds_passed/SEC_PER_MUD_HOUR) % 24; // 0..23
seconds_passed -= SEC_PER_MUD_HOUR * now.hours;
now.days = (seconds_passed/SEC_PER_MUD_DAY) % 32 ; // 0..31
seconds_passed -= SEC_PER_MUD_DAY * now.days;
now.months = (seconds_passed/SEC_PER_MUD_MONTH) % 20; // 0..19
seconds_passed -= SEC_PER_MUD_MONTH * now.months;
now.year = (seconds_passed/SEC_PER_MUD_YEAR); // 0..1553 years
return now ;
}
// make the time readable to players
void say_time(M_TIME_DATA time_info)
{
char am_pm[14] ;
char *suf ;
char minutes[3] ;
char minute_buff[3] ;
unsigned long hours ;
unsigned int day ;
unsigned int decade = 0;
memset(&am_pm, 0x00, (sizeof(char)*14)) ;
memset(&minutes, 0x00, (sizeof(char)*3)) ;
memset(&minute_buff, 0x00, (sizeof(char)*3)) ;
// determine if AM or PM
((time_info.hours < 12) && (time_info.minutes <= 59)) ? strncpy(am_pm, "Ante Meridian", 14)
: strncpy(am_pm, "Post Meridian", 14) ;
hours = ((time_info.hours % 12) == 0) ? 12 : (time_info.hours % 12) ; // change 0 to 12
// padd additional '0' to minutes if less than 10
itoa(time_info.minutes, minute_buff, 10);
if (time_info.minutes < 10) {
minutes[0] = '0' ;
strncat(minutes, minute_buff, 1) ;
} else {
strncpy(minutes, minute_buff, 2) ;
}
day = time_info.days + 1 ; /* 1..32 */
// add the suffixes
if (day == 1)
suf = "st";
else if (day == 2)
suf = "nd";
else if (day == 3)
suf = "rd";
else if (day < 20)
suf = "th";
else if ((day % 10) == 1)
suf = "st";
else if ((day % 10) == 2)
suf = "nd";
else if ((day % 10) == 3)
suf = "rd";
else
suf = "th";
printf("The current time is %d:%s %s.\n", hours, minutes, am_pm) ;
printf("This is %s, %d%s of the %s, the year %d of %s.\n",
day_of_week[(time_info.days%8)], day, suf, month_name[(time_info.months%20)],
time_info.year, decade_name[decade]) ;
}
int main(void)
{
unsigned long beginning_of_time = 0 ;
unsigned long test_time = 2764800 ;
M_TIME_DATA time_info ;
for(;;) {
test_time += SEC_PER_MUD_YEAR ;
time_info = get_current_mud_time(beginning_of_time, test_time);
printf("test_time value:%l [%X]\n", test_time, test_time) ;
say_time(time_info) ;
}
return 0;
}