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