ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/time.C
Revision: 1.22
Committed: Fri Nov 6 13:03:34 2009 UTC (14 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_90, rel-2_92, rel-2_93
Changes since 1.21: +1 -1 lines
Log Message:
make effectively static symbols actually static, part 2

File Contents

# User Rev Content
1 elmex 1.1 /*
2 root 1.17 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 pippijn 1.9 *
4 root 1.18 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 root 1.15 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6     * Copyright (©) 1992,2007 Frank Tore Johansen
7 pippijn 1.9 *
8 root 1.21 * Deliantra is free software: you can redistribute it and/or modify it under
9     * the terms of the Affero GNU General Public License as published by the
10     * Free Software Foundation, either version 3 of the License, or (at your
11     * option) any later version.
12 pippijn 1.9 *
13 root 1.16 * 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 pippijn 1.9 *
18 root 1.21 * You should have received a copy of the Affero GNU General Public License
19     * and the GNU General Public License along with this program. If not, see
20     * <http://www.gnu.org/licenses/>.
21 root 1.15 *
22 root 1.17 * The authors can be reached via e-mail to <support@deliantra.net>
23 pippijn 1.9 */
24 elmex 1.1
25     #include <global.h>
26     #include <tod.h>
27    
28 root 1.10 #include <cstdio>
29    
30 pippijn 1.6 #include <sys/types.h>
31     #include <sys/time.h>
32 elmex 1.1
33     /*
34     * Gloabal variables:
35     */
36 root 1.13 tick_t pticks;
37 elmex 1.1
38 root 1.10 static const char *season_name[5] = {
39     "New Year",
40     "Growth",
41     "Harvest",
42     "Decay",
43     "the Blizzard",
44 elmex 1.1 };
45    
46 root 1.10 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 elmex 1.1 };
55    
56 root 1.10 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 elmex 1.1 };
75    
76     void
77 root 1.19 get_tod (timeofday_t *tod)
78 elmex 1.1 {
79 root 1.12 unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR));
80 root 1.10
81 root 1.20 tod->year = todtick / HOURS_PER_YEAR + EPOCH;
82 root 1.10 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 root 1.12 tod->minute = (int)((runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR));
86 root 1.10
87     tod->dayofweek = tod->day % DAYS_PER_WEEK;
88 root 1.4 tod->weekofmonth = tod->day / WEEKS_PER_MONTH;
89 root 1.19 tod->season = min (4, tod->month / 4);
90 elmex 1.1 }
91    
92 root 1.19 char *
93     format_tod (char *buf, int len, timeofday_t *tod)
94 elmex 1.1 {
95 root 1.19 int day = tod->day + 1;
96 elmex 1.1
97 root 1.19 const char *suf;
98 root 1.10
99 elmex 1.1 if (day == 1 || ((day % 10) == 1 && day > 20))
100     suf = "st";
101     else if (day == 2 || ((day % 10) == 2 && day > 20))
102     suf = "nd";
103     else if (day == 3 || ((day % 10) == 3 && day > 20))
104     suf = "rd";
105     else
106     suf = "th";
107    
108 root 1.19 snprintf (buf, len,
109 root 1.10 "It is %d minute%s past %d o'clock %s, on the Day of %s,\n"
110     "the %d%s Day of the Month of %s, Year %d.\n"
111     "It is the Season of %s.",
112    
113 root 1.19 tod->minute ? tod->minute : 60,
114     tod->minute ? "s" : "",
115     (tod->hour + 13) % 14 + 1,
116     (tod->hour >= 14 ? "pm" : "am"),
117     weekdays[tod->dayofweek],
118    
119     day, suf, month_name[tod->month], tod->year + 1,
120    
121     season_name[tod->season]);
122    
123     return buf;
124     }
125    
126 root 1.22 static const char *
127 root 1.19 get_current_tod_str ()
128     {
129     timeofday_t tod;
130     get_tod (&tod);
131    
132     static char todbuf[512];
133     format_tod (todbuf, sizeof (todbuf), &tod);
134    
135     return todbuf;
136     }
137    
138     void
139     print_tod (object *op)
140     {
141     new_draw_info (NDI_UNIQUE, 0, op, get_current_tod_str ());
142 elmex 1.1 }
143