1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra 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,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
… | |
… | |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <funcpoint.h> |
|
|
26 | #include <tod.h> |
25 | #include <tod.h> |
27 | |
26 | |
28 | #include <cstdio> |
27 | #include <cstdio> |
29 | |
28 | |
30 | #include <sys/types.h> |
29 | #include <sys/types.h> |
… | |
… | |
72 | "the Ancient Darkness", |
71 | "the Ancient Darkness", |
73 | "Gorokh" |
72 | "Gorokh" |
74 | }; |
73 | }; |
75 | |
74 | |
76 | void |
75 | void |
77 | get_tod (timeofday_t * tod) |
76 | get_tod (timeofday_t *tod) |
78 | { |
77 | { |
79 | unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR)); |
78 | unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR)); |
80 | |
79 | |
81 | tod->year = todtick / HOURS_PER_YEAR; |
80 | tod->year = todtick / HOURS_PER_YEAR; |
82 | tod->month = todtick / HOURS_PER_MONTH % MONTHS_PER_YEAR; |
81 | tod->month = todtick / HOURS_PER_MONTH % MONTHS_PER_YEAR; |
… | |
… | |
84 | tod->hour = todtick % HOURS_PER_DAY; |
83 | tod->hour = todtick % HOURS_PER_DAY; |
85 | tod->minute = (int)((runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR)); |
84 | tod->minute = (int)((runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR)); |
86 | |
85 | |
87 | tod->dayofweek = tod->day % DAYS_PER_WEEK; |
86 | tod->dayofweek = tod->day % DAYS_PER_WEEK; |
88 | tod->weekofmonth = tod->day / WEEKS_PER_MONTH; |
87 | tod->weekofmonth = tod->day / WEEKS_PER_MONTH; |
89 | tod->season = min (4, tod->month / 3); |
88 | tod->season = min (4, tod->month / 4); |
90 | } |
89 | } |
91 | |
90 | |
92 | void |
91 | char * |
93 | print_tod (object *op) |
92 | format_tod (char *buf, int len, timeofday_t *tod) |
94 | { |
93 | { |
95 | timeofday_t tod; |
94 | int day = tod->day + 1; |
96 | get_tod (&tod); |
|
|
97 | |
95 | |
98 | char todmsg [1024]; |
96 | const char *suf; |
99 | |
97 | |
100 | int day = tod.day + 1; |
|
|
101 | const char *suf; |
|
|
102 | if (day == 1 || ((day % 10) == 1 && day > 20)) |
98 | if (day == 1 || ((day % 10) == 1 && day > 20)) |
103 | suf = "st"; |
99 | suf = "st"; |
104 | else if (day == 2 || ((day % 10) == 2 && day > 20)) |
100 | else if (day == 2 || ((day % 10) == 2 && day > 20)) |
105 | suf = "nd"; |
101 | suf = "nd"; |
106 | else if (day == 3 || ((day % 10) == 3 && day > 20)) |
102 | else if (day == 3 || ((day % 10) == 3 && day > 20)) |
107 | suf = "rd"; |
103 | suf = "rd"; |
108 | else |
104 | else |
109 | suf = "th"; |
105 | suf = "th"; |
110 | |
106 | |
111 | snprintf (todmsg, sizeof (todmsg), |
107 | snprintf (buf, len, |
112 | "It is %d minute%s past %d o'clock %s, on the Day of %s,\n" |
108 | "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" |
109 | "the %d%s Day of the Month of %s, Year %d.\n" |
114 | "It is the Season of %s.", |
110 | "It is the Season of %s.", |
115 | |
111 | |
116 | tod.minute + 1, |
112 | tod->minute ? tod->minute : 60, |
117 | (tod.minute + 1 < 2) ? "" : "s", |
113 | tod->minute ? "s" : "", |
118 | (tod.hour + 13) % 14 + 1, |
114 | (tod->hour + 13) % 14 + 1, |
119 | (tod.hour >= 14 ? "pm" : "am"), |
115 | (tod->hour >= 14 ? "pm" : "am"), |
120 | weekdays[tod.dayofweek], |
116 | weekdays[tod->dayofweek], |
121 | |
117 | |
122 | day, suf, month_name[tod.month], tod.year + 1, |
118 | day, suf, month_name[tod->month], tod->year + 1, |
123 | |
119 | |
124 | season_name[tod.season]); |
120 | season_name[tod->season]); |
125 | |
121 | |
126 | new_draw_info (NDI_UNIQUE, 0, op, todmsg); |
122 | return buf; |
127 | } |
123 | } |
128 | |
124 | |
|
|
125 | const char * |
|
|
126 | get_current_tod_str () |
|
|
127 | { |
|
|
128 | timeofday_t tod; |
|
|
129 | get_tod (&tod); |
|
|
130 | |
|
|
131 | static char todbuf[512]; |
|
|
132 | format_tod (todbuf, sizeof (todbuf), &tod); |
|
|
133 | |
|
|
134 | return todbuf; |
|
|
135 | } |
|
|
136 | |
|
|
137 | void |
|
|
138 | print_tod (object *op) |
|
|
139 | { |
|
|
140 | new_draw_info (NDI_UNIQUE, 0, op, get_current_tod_str ()); |
|
|
141 | } |
|
|
142 | |