ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/time.C
Revision: 1.17
Committed: Thu Nov 8 19:43:23 2007 UTC (16 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_4, rel-2_5, rel-2_32, rel-2_43, rel-2_42, rel-2_41
Changes since 1.16: +4 -4 lines
Log Message:
update copyrights and other minor stuff to deliantra

File Contents

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2005,2006,2007 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 <funcpoint.h>
26 #include <tod.h>
27
28 #include <cstdio>
29
30 #include <sys/types.h>
31 #include <sys/time.h>
32
33 /*
34 * Gloabal variables:
35 */
36 tick_t pticks;
37
38 static const char *season_name[5] = {
39 "New Year",
40 "Growth",
41 "Harvest",
42 "Decay",
43 "the Blizzard",
44 };
45
46 static const char *weekdays[DAYS_PER_WEEK] = {
47 "the Moon",
48 "the Bull",
49 "the Deception",
50 "Thunder",
51 "Freedom",
52 "the Great Gods",
53 "the Sun"
54 };
55
56 static const char *month_name[MONTHS_PER_YEAR] = {
57 "Winter", /* 0 */
58 "the Ice Dragon",
59 "the Frost Giant",
60 "Valriel",
61 "Lythander",
62 "the Harvest",
63 "Gaea",
64 "Futility",
65 "the Dragon",
66 "the Sun",
67 "the Great Infernus",
68 "Ruggilli",
69 "the Dark Shades",
70 "the Devourers",
71 "Sorig",
72 "the Ancient Darkness",
73 "Gorokh"
74 };
75
76 void
77 get_tod (timeofday_t * tod)
78 {
79 unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR));
80
81 tod->year = todtick / HOURS_PER_YEAR;
82 tod->month = todtick / HOURS_PER_MONTH % MONTHS_PER_YEAR;
83 tod->day = todtick % HOURS_PER_MONTH / DAYS_PER_MONTH;
84 tod->hour = todtick % HOURS_PER_DAY;
85 tod->minute = (int)((runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR));
86
87 tod->dayofweek = tod->day % DAYS_PER_WEEK;
88 tod->weekofmonth = tod->day / WEEKS_PER_MONTH;
89 tod->season = min (4, tod->month / 3);
90 }
91
92 void
93 print_tod (object *op)
94 {
95 timeofday_t tod;
96 get_tod (&tod);
97
98 char todmsg [1024];
99
100 int day = tod.day + 1;
101 const char *suf;
102 if (day == 1 || ((day % 10) == 1 && day > 20))
103 suf = "st";
104 else if (day == 2 || ((day % 10) == 2 && day > 20))
105 suf = "nd";
106 else if (day == 3 || ((day % 10) == 3 && day > 20))
107 suf = "rd";
108 else
109 suf = "th";
110
111 snprintf (todmsg, sizeof (todmsg),
112 "It is %d minute%s past %d o'clock %s, on the Day of %s,\n"
113 "the %d%s Day of the Month of %s, Year %d.\n"
114 "It is the Season of %s.",
115
116 tod.minute + 1,
117 (tod.minute + 1 < 2) ? "" : "s",
118 (tod.hour + 13) % 14 + 1,
119 (tod.hour >= 14 ? "pm" : "am"),
120 weekdays[tod.dayofweek],
121
122 day, suf, month_name[tod.month], tod.year + 1,
123
124 season_name[tod.season]);
125
126 new_draw_info (NDI_UNIQUE, 0, op, todmsg);
127 }
128