--- deliantra/server/common/time.C 2006/08/24 13:13:48 1.3
+++ deliantra/server/common/time.C 2007/07/01 05:00:18 1.16
@@ -1,130 +1,104 @@
/*
- * static char *rcsid_time_c =
- * "$Id: time.C,v 1.3 2006/08/24 13:13:48 root Exp $";
+ * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
+ *
+ * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
+ * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
+ * Copyright (©) 1992,2007 Frank Tore Johansen
+ *
+ * Crossfire TRT 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 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
+ * 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, see .
+ *
+ * The authors can be reached via e-mail to
*/
-/*
- CrossFire, A Multiplayer game for X-windows
-
- Copyright (C) 2002 Mark Wedel & Crossfire Development Team
- Copyright (C) 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.
-
- 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
- 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 crossfire-devel@real-time.com
-*/
-
#include
#include
#include
-#ifndef WIN32 /* ---win32 exclude header */
-#include
+#include
+
#include
#include
-#endif /* win32 */
/*
* Gloabal variables:
*/
+tick_t pticks;
-long psaveind;
-long pticks;
-
-const char *season_name[] =
-{
- "The Season of New Year",
- "The Season of Growth",
- "The Season of Harvest",
- "The Season of Decay",
- "The Season of the Blizzard",
- "\n"
+static const char *season_name[5] = {
+ "New Year",
+ "Growth",
+ "Harvest",
+ "Decay",
+ "the Blizzard",
};
-const char *weekdays[DAYS_PER_WEEK] = {
- "the Day of the Moon",
- "the Day of the Bull",
- "the Day of the Deception",
- "the Day of Thunder",
- "the Day of Freedom",
- "the Day of the Great Gods",
- "the Day of the Sun"
+static const char *weekdays[DAYS_PER_WEEK] = {
+ "the Moon",
+ "the Bull",
+ "the Deception",
+ "Thunder",
+ "Freedom",
+ "the Great Gods",
+ "the Sun"
};
-const char *month_name[MONTHS_PER_YEAR] = {
- "Month of Winter", /* 0 */
- "Month of the Ice Dragon",
- "Month of the Frost Giant",
- "Month of Valriel",
- "Month of Lythander",
- "Month of the Harvest",
- "Month of Gaea",
- "Month of Futility",
- "Month of the Dragon",
- "Month of the Sun",
- "Month of the Great Infernus",
- "Month of Ruggilli",
- "Month of the Dark Shades",
- "Month of the Devourers",
- "Month of Sorig",
- "Month of the Ancient Darkness",
- "Month of Gorokh"
+static const char *month_name[MONTHS_PER_YEAR] = {
+ "Winter", /* 0 */
+ "the Ice Dragon",
+ "the Frost Giant",
+ "Valriel",
+ "Lythander",
+ "the Harvest",
+ "Gaea",
+ "Futility",
+ "the Dragon",
+ "the Sun",
+ "the Great Infernus",
+ "Ruggilli",
+ "the Dark Shades",
+ "the Devourers",
+ "Sorig",
+ "the Ancient Darkness",
+ "Gorokh"
};
-extern unsigned long todtick;
-
void
-get_tod(timeofday_t *tod)
+get_tod (timeofday_t * tod)
{
- tod->year = todtick/HOURS_PER_YEAR;
- tod->month = (todtick/HOURS_PER_MONTH)%MONTHS_PER_YEAR;
- tod->day = (todtick%HOURS_PER_MONTH)/DAYS_PER_MONTH;
- tod->dayofweek = tod->day%DAYS_PER_WEEK;
- tod->hour = todtick%HOURS_PER_DAY;
- tod->minute = (pticks%PTICKS_PER_CLOCK)/(PTICKS_PER_CLOCK/58);
- if (tod->minute > 58)
- tod->minute = 58; /* it's imprecise at best anyhow */
- tod->weekofmonth = tod->day/WEEKS_PER_MONTH;
- if (tod->month < 3)
- tod->season = 0;
- else if (tod->month < 6)
- tod->season = 1;
- else if (tod->month < 9)
- tod->season = 2;
- else if (tod->month < 12)
- tod->season = 3;
- else
- tod->season = 4;
+ unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR));
+
+ tod->year = todtick / HOURS_PER_YEAR;
+ 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 = (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);
}
void
-print_tod(object *op)
+print_tod (object *op)
{
timeofday_t tod;
- const char *suf;
- int day;
+ get_tod (&tod);
- get_tod(&tod);
- sprintf(errmsg, "It is %d minute%s past %d o'clock %s, on %s",
- tod.minute+1, ((tod.minute+1 < 2) ? "" : "s"),
- ((tod.hour % 14 == 0) ? 14 : ((tod.hour)%14)),
- ((tod.hour >= 14) ? "pm" : "am"),
- weekdays[tod.dayofweek]);
- new_draw_info(NDI_UNIQUE, 0,op,errmsg);
+ char todmsg [1024];
- 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))
@@ -133,19 +107,22 @@
suf = "rd";
else
suf = "th";
- sprintf(errmsg, "The %d%s Day of the %s, Year %d", day, suf,
- month_name[tod.month], tod.year+1);
- new_draw_info(NDI_UNIQUE, 0,op,errmsg);
- sprintf(errmsg, "Time of Year: %s", season_name[tod.season]);
- new_draw_info(NDI_UNIQUE, 0,op,errmsg);
+ snprintf (todmsg, sizeof (todmsg),
+ "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);
}
-long
-seconds(void)
-{
- struct timeval now;
-
- (void) GETTIMEOFDAY(&now);
- return now.tv_sec;
-}