--- deliantra/server/common/time.C 2007/11/08 19:43:23 1.17 +++ deliantra/server/common/time.C 2008/12/23 06:58:23 1.19 @@ -1,7 +1,7 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team * Copyright (©) 1992,2007 Frank Tore Johansen * @@ -22,7 +22,6 @@ */ #include -#include #include #include @@ -74,7 +73,7 @@ }; void -get_tod (timeofday_t * tod) +get_tod (timeofday_t *tod) { unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR)); @@ -86,19 +85,16 @@ tod->dayofweek = tod->day % DAYS_PER_WEEK; tod->weekofmonth = tod->day / WEEKS_PER_MONTH; - tod->season = min (4, tod->month / 3); + tod->season = min (4, tod->month / 4); } -void -print_tod (object *op) +char * +format_tod (char *buf, int len, timeofday_t *tod) { - timeofday_t tod; - get_tod (&tod); - - char todmsg [1024]; + int day = tod->day + 1; - int day = tod.day + 1; const char *suf; + if (day == 1 || ((day % 10) == 1 && day > 20)) suf = "st"; else if (day == 2 || ((day % 10) == 2 && day > 20)) @@ -108,21 +104,39 @@ else suf = "th"; - snprintf (todmsg, sizeof (todmsg), + snprintf (buf, len, "It is %d minute%s past %d o'clock %s, on the Day of %s,\n" "the %d%s Day of the Month of %s, Year %d.\n" "It is the Season of %s.", - tod.minute + 1, - (tod.minute + 1 < 2) ? "" : "s", - (tod.hour + 13) % 14 + 1, - (tod.hour >= 14 ? "pm" : "am"), - weekdays[tod.dayofweek], - - day, suf, month_name[tod.month], tod.year + 1, - - season_name[tod.season]); - - new_draw_info (NDI_UNIQUE, 0, op, todmsg); + tod->minute ? tod->minute : 60, + tod->minute ? "s" : "", + (tod->hour + 13) % 14 + 1, + (tod->hour >= 14 ? "pm" : "am"), + weekdays[tod->dayofweek], + + day, suf, month_name[tod->month], tod->year + 1, + + season_name[tod->season]); + + return buf; +} + +const char * +get_current_tod_str () +{ + timeofday_t tod; + get_tod (&tod); + + static char todbuf[512]; + format_tod (todbuf, sizeof (todbuf), &tod); + + return todbuf; +} + +void +print_tod (object *op) +{ + new_draw_info (NDI_UNIQUE, 0, op, get_current_tod_str ()); }