--- deliantra/server/common/time.C 2007/03/17 22:32:15 1.11 +++ deliantra/server/common/time.C 2011/05/04 19:04:44 1.26 @@ -1,29 +1,28 @@ /* - * CrossFire, A Multiplayer game for X-windows + * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team - * Copyright (C) 2002 Mark Wedel & Crossfire Development Team - * Copyright (C) 1992 Frank Tore Johansen + * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2002 Mark Wedel & Crossfire Development Team + * Copyright (©) 1992 Frank Tore Johansen * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Deliantra is free software: you can redistribute it and/or modify it under + * the terms of the Affero GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * The authors can be reached via e-mail at + * You should have received a copy of the Affero GNU General Public License + * and the GNU General Public License along with this program. If not, see + * . + * + * The authors can be reached via e-mail to */ #include -#include #include #include @@ -34,7 +33,7 @@ /* * Gloabal variables: */ -long pticks; +tick_t server_tick; static const char *season_name[5] = { "New Year", @@ -75,31 +74,28 @@ }; void -get_tod (timeofday_t * tod) +get_tod (timeofday_t *tod) { - unsigned int todtick = runtime * (1. / RUNTIME_PER_HOUR); + unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR)); - tod->year = todtick / HOURS_PER_YEAR; + tod->year = todtick / HOURS_PER_YEAR + EPOCH; tod->month = todtick / HOURS_PER_MONTH % MONTHS_PER_YEAR; tod->day = todtick % HOURS_PER_MONTH / DAYS_PER_MONTH; tod->hour = todtick % HOURS_PER_DAY; - tod->minute = (runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR); + tod->minute = (int)((runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR)); 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)) @@ -109,21 +105,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; +} + +static 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 ()); }