ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/time.C
Revision: 1.20
Committed: Sun Dec 28 06:59:26 2008 UTC (15 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_80, rel-2_76, rel-2_77, rel-2_74, rel-2_75, rel-2_79, rel-2_78
Changes since 1.19: +1 -1 lines
Log Message:
smell, remove gcfclient support, material fixes, cfpod parse fixes, refactoring

File Contents

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 *
8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */
23
24 #include <global.h>
25 #include <tod.h>
26
27 #include <cstdio>
28
29 #include <sys/types.h>
30 #include <sys/time.h>
31
32 /*
33 * Gloabal variables:
34 */
35 tick_t pticks;
36
37 static const char *season_name[5] = {
38 "New Year",
39 "Growth",
40 "Harvest",
41 "Decay",
42 "the Blizzard",
43 };
44
45 static const char *weekdays[DAYS_PER_WEEK] = {
46 "the Moon",
47 "the Bull",
48 "the Deception",
49 "Thunder",
50 "Freedom",
51 "the Great Gods",
52 "the Sun"
53 };
54
55 static const char *month_name[MONTHS_PER_YEAR] = {
56 "Winter", /* 0 */
57 "the Ice Dragon",
58 "the Frost Giant",
59 "Valriel",
60 "Lythander",
61 "the Harvest",
62 "Gaea",
63 "Futility",
64 "the Dragon",
65 "the Sun",
66 "the Great Infernus",
67 "Ruggilli",
68 "the Dark Shades",
69 "the Devourers",
70 "Sorig",
71 "the Ancient Darkness",
72 "Gorokh"
73 };
74
75 void
76 get_tod (timeofday_t *tod)
77 {
78 unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR));
79
80 tod->year = todtick / HOURS_PER_YEAR + EPOCH;
81 tod->month = todtick / HOURS_PER_MONTH % MONTHS_PER_YEAR;
82 tod->day = todtick % HOURS_PER_MONTH / DAYS_PER_MONTH;
83 tod->hour = todtick % HOURS_PER_DAY;
84 tod->minute = (int)((runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR));
85
86 tod->dayofweek = tod->day % DAYS_PER_WEEK;
87 tod->weekofmonth = tod->day / WEEKS_PER_MONTH;
88 tod->season = min (4, tod->month / 4);
89 }
90
91 char *
92 format_tod (char *buf, int len, timeofday_t *tod)
93 {
94 int day = tod->day + 1;
95
96 const char *suf;
97
98 if (day == 1 || ((day % 10) == 1 && day > 20))
99 suf = "st";
100 else if (day == 2 || ((day % 10) == 2 && day > 20))
101 suf = "nd";
102 else if (day == 3 || ((day % 10) == 3 && day > 20))
103 suf = "rd";
104 else
105 suf = "th";
106
107 snprintf (buf, len,
108 "It is %d minute%s past %d o'clock %s, on the Day of %s,\n"
109 "the %d%s Day of the Month of %s, Year %d.\n"
110 "It is the Season of %s.",
111
112 tod->minute ? tod->minute : 60,
113 tod->minute ? "s" : "",
114 (tod->hour + 13) % 14 + 1,
115 (tod->hour >= 14 ? "pm" : "am"),
116 weekdays[tod->dayofweek],
117
118 day, suf, month_name[tod->month], tod->year + 1,
119
120 season_name[tod->season]);
121
122 return buf;
123 }
124
125 const char *
126 get_current_tod_str ()
127 {
128 timeofday_t tod;
129 get_tod (&tod);
130
131 static char todbuf[512];
132 format_tod (todbuf, sizeof (todbuf), &tod);
133
134 return todbuf;
135 }
136
137 void
138 print_tod (object *op)
139 {
140 new_draw_info (NDI_UNIQUE, 0, op, get_current_tod_str ());
141 }
142