1 |
/* |
2 |
* This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. |
3 |
* |
4 |
* 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 |
* |
8 |
* 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 |
* |
13 |
* 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 |
* |
18 |
* 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 |
*/ |
24 |
|
25 |
#include <global.h> |
26 |
#include <funcpoint.h> |
27 |
#include <tod.h> |
28 |
|
29 |
#include <cstdio> |
30 |
|
31 |
#include <sys/types.h> |
32 |
#include <sys/time.h> |
33 |
|
34 |
/* |
35 |
* Gloabal variables: |
36 |
*/ |
37 |
tick_t pticks; |
38 |
|
39 |
static const char *season_name[5] = { |
40 |
"New Year", |
41 |
"Growth", |
42 |
"Harvest", |
43 |
"Decay", |
44 |
"the Blizzard", |
45 |
}; |
46 |
|
47 |
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 |
}; |
56 |
|
57 |
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 |
}; |
76 |
|
77 |
void |
78 |
get_tod (timeofday_t * tod) |
79 |
{ |
80 |
unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR)); |
81 |
|
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 |
tod->minute = (int)((runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR)); |
87 |
|
88 |
tod->dayofweek = tod->day % DAYS_PER_WEEK; |
89 |
tod->weekofmonth = tod->day / WEEKS_PER_MONTH; |
90 |
tod->season = min (4, tod->month / 3); |
91 |
} |
92 |
|
93 |
void |
94 |
print_tod (object *op) |
95 |
{ |
96 |
timeofday_t tod; |
97 |
get_tod (&tod); |
98 |
|
99 |
char todmsg [1024]; |
100 |
|
101 |
int day = tod.day + 1; |
102 |
const char *suf; |
103 |
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 |
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 |
} |
129 |
|