| 1 |
elmex |
1.1 |
/* |
| 2 |
root |
1.17 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
| 3 |
root |
1.28 |
* |
| 4 |
root |
1.30 |
* Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
| 5 |
root |
1.29 |
* Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
| 6 |
root |
1.23 |
* Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
| 7 |
|
|
* Copyright (©) 1992 Frank Tore Johansen |
| 8 |
root |
1.28 |
* |
| 9 |
root |
1.21 |
* Deliantra is free software: you can redistribute it and/or modify it under |
| 10 |
|
|
* the terms of the Affero GNU General Public License as published by the |
| 11 |
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
| 12 |
|
|
* option) any later version. |
| 13 |
root |
1.28 |
* |
| 14 |
root |
1.16 |
* This program is distributed in the hope that it will be useful, |
| 15 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
|
|
* GNU General Public License for more details. |
| 18 |
root |
1.28 |
* |
| 19 |
root |
1.21 |
* 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 |
root |
1.28 |
* |
| 23 |
root |
1.17 |
* The authors can be reached via e-mail to <support@deliantra.net> |
| 24 |
pippijn |
1.9 |
*/ |
| 25 |
elmex |
1.1 |
|
| 26 |
|
|
#include <global.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 |
root |
1.26 |
tick_t server_tick; |
| 38 |
elmex |
1.1 |
|
| 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.19 |
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 |
root |
1.20 |
tod->year = todtick / HOURS_PER_YEAR + EPOCH; |
| 83 |
root |
1.10 |
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.19 |
tod->season = min (4, tod->month / 4); |
| 91 |
elmex |
1.1 |
} |
| 92 |
|
|
|
| 93 |
root |
1.19 |
char * |
| 94 |
|
|
format_tod (char *buf, int len, timeofday_t *tod) |
| 95 |
elmex |
1.1 |
{ |
| 96 |
root |
1.19 |
int day = tod->day + 1; |
| 97 |
elmex |
1.1 |
|
| 98 |
root |
1.19 |
const char *suf; |
| 99 |
root |
1.10 |
|
| 100 |
elmex |
1.1 |
if (day == 1 || ((day % 10) == 1 && day > 20)) |
| 101 |
|
|
suf = "st"; |
| 102 |
|
|
else if (day == 2 || ((day % 10) == 2 && day > 20)) |
| 103 |
|
|
suf = "nd"; |
| 104 |
|
|
else if (day == 3 || ((day % 10) == 3 && day > 20)) |
| 105 |
|
|
suf = "rd"; |
| 106 |
|
|
else |
| 107 |
|
|
suf = "th"; |
| 108 |
|
|
|
| 109 |
root |
1.19 |
snprintf (buf, len, |
| 110 |
root |
1.10 |
"It is %d minute%s past %d o'clock %s, on the Day of %s,\n" |
| 111 |
|
|
"the %d%s Day of the Month of %s, Year %d.\n" |
| 112 |
|
|
"It is the Season of %s.", |
| 113 |
|
|
|
| 114 |
root |
1.19 |
tod->minute ? tod->minute : 60, |
| 115 |
|
|
tod->minute ? "s" : "", |
| 116 |
|
|
(tod->hour + 13) % 14 + 1, |
| 117 |
|
|
(tod->hour >= 14 ? "pm" : "am"), |
| 118 |
|
|
weekdays[tod->dayofweek], |
| 119 |
|
|
|
| 120 |
|
|
day, suf, month_name[tod->month], tod->year + 1, |
| 121 |
|
|
|
| 122 |
|
|
season_name[tod->season]); |
| 123 |
|
|
|
| 124 |
|
|
return buf; |
| 125 |
|
|
} |
| 126 |
|
|
|
| 127 |
root |
1.22 |
static const char * |
| 128 |
root |
1.19 |
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 |
elmex |
1.1 |
} |
| 144 |
|
|
|