1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #include <funcpoint.h> |
|
|
26 | #include <tod.h> |
26 | #include <tod.h> |
27 | |
27 | |
28 | #include <cstdio> |
28 | #include <cstdio> |
29 | |
29 | |
30 | #include <sys/types.h> |
30 | #include <sys/types.h> |
… | |
… | |
72 | "the Ancient Darkness", |
72 | "the Ancient Darkness", |
73 | "Gorokh" |
73 | "Gorokh" |
74 | }; |
74 | }; |
75 | |
75 | |
76 | void |
76 | void |
77 | get_tod (timeofday_t * tod) |
77 | get_tod (timeofday_t *tod) |
78 | { |
78 | { |
79 | unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR)); |
79 | unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR)); |
80 | |
80 | |
81 | tod->year = todtick / HOURS_PER_YEAR; |
81 | tod->year = todtick / HOURS_PER_YEAR + EPOCH; |
82 | tod->month = todtick / HOURS_PER_MONTH % MONTHS_PER_YEAR; |
82 | tod->month = todtick / HOURS_PER_MONTH % MONTHS_PER_YEAR; |
83 | tod->day = todtick % HOURS_PER_MONTH / DAYS_PER_MONTH; |
83 | tod->day = todtick % HOURS_PER_MONTH / DAYS_PER_MONTH; |
84 | tod->hour = todtick % HOURS_PER_DAY; |
84 | tod->hour = todtick % HOURS_PER_DAY; |
85 | tod->minute = (int)((runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR)); |
85 | tod->minute = (int)((runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR)); |
86 | |
86 | |
87 | tod->dayofweek = tod->day % DAYS_PER_WEEK; |
87 | tod->dayofweek = tod->day % DAYS_PER_WEEK; |
88 | tod->weekofmonth = tod->day / WEEKS_PER_MONTH; |
88 | tod->weekofmonth = tod->day / WEEKS_PER_MONTH; |
89 | tod->season = min (4, tod->month / 3); |
89 | tod->season = min (4, tod->month / 4); |
90 | } |
90 | } |
91 | |
91 | |
92 | void |
92 | char * |
93 | print_tod (object *op) |
93 | format_tod (char *buf, int len, timeofday_t *tod) |
94 | { |
94 | { |
95 | timeofday_t tod; |
95 | int day = tod->day + 1; |
96 | get_tod (&tod); |
|
|
97 | |
96 | |
98 | char todmsg [1024]; |
97 | const char *suf; |
99 | |
98 | |
100 | int day = tod.day + 1; |
|
|
101 | const char *suf; |
|
|
102 | if (day == 1 || ((day % 10) == 1 && day > 20)) |
99 | if (day == 1 || ((day % 10) == 1 && day > 20)) |
103 | suf = "st"; |
100 | suf = "st"; |
104 | else if (day == 2 || ((day % 10) == 2 && day > 20)) |
101 | else if (day == 2 || ((day % 10) == 2 && day > 20)) |
105 | suf = "nd"; |
102 | suf = "nd"; |
106 | else if (day == 3 || ((day % 10) == 3 && day > 20)) |
103 | else if (day == 3 || ((day % 10) == 3 && day > 20)) |
107 | suf = "rd"; |
104 | suf = "rd"; |
108 | else |
105 | else |
109 | suf = "th"; |
106 | suf = "th"; |
110 | |
107 | |
111 | snprintf (todmsg, sizeof (todmsg), |
108 | snprintf (buf, len, |
112 | "It is %d minute%s past %d o'clock %s, on the Day of %s,\n" |
109 | "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" |
110 | "the %d%s Day of the Month of %s, Year %d.\n" |
114 | "It is the Season of %s.", |
111 | "It is the Season of %s.", |
115 | |
112 | |
116 | tod.minute + 1, |
113 | tod->minute ? tod->minute : 60, |
117 | (tod.minute + 1 < 2) ? "" : "s", |
114 | tod->minute ? "s" : "", |
118 | (tod.hour + 13) % 14 + 1, |
115 | (tod->hour + 13) % 14 + 1, |
119 | (tod.hour >= 14 ? "pm" : "am"), |
116 | (tod->hour >= 14 ? "pm" : "am"), |
120 | weekdays[tod.dayofweek], |
117 | weekdays[tod->dayofweek], |
121 | |
118 | |
122 | day, suf, month_name[tod.month], tod.year + 1, |
119 | day, suf, month_name[tod->month], tod->year + 1, |
123 | |
120 | |
124 | season_name[tod.season]); |
121 | season_name[tod->season]); |
125 | |
122 | |
126 | new_draw_info (NDI_UNIQUE, 0, op, todmsg); |
123 | return buf; |
127 | } |
124 | } |
128 | |
125 | |
|
|
126 | static const char * |
|
|
127 | 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 | } |
|
|
143 | |