ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/time.C
(Generate patch)

Comparing deliantra/server/common/time.C (file contents):
Revision 1.15 by root, Mon May 28 21:21:40 2007 UTC vs.
Revision 1.19 by root, Tue Dec 23 06:58:23 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines