ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/time.C
Revision: 1.15
Committed: Mon May 28 21:21:40 2007 UTC (17 years ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.14: +17 -17 lines
Log Message:
update copyrights in common/*.C and util/*.C

File Contents

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