1 |
elmex |
1.1 |
/* |
2 |
pippijn |
1.9 |
* CrossFire, A Multiplayer game for X-windows |
3 |
|
|
* |
4 |
|
|
* Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
5 |
|
|
* Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
6 |
|
|
* Copyright (C) 1992 Frank Tore Johansen |
7 |
|
|
* |
8 |
|
|
* This program 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 2 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, write to the Free Software |
20 |
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 |
|
|
* |
22 |
|
|
* The authors can be reached via e-mail at <crossfire@schmorp.de> |
23 |
|
|
*/ |
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 |
|
|
long pticks; |
38 |
|
|
|
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 |
|
|
|