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.13 by root, Wed Apr 25 18:47:49 2007 UTC vs.
Revision 1.26 by root, Wed May 4 19:04:44 2011 UTC

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 (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * This program 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 2 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, write to the Free Software 19 * and the GNU General Public License along with this program. If not, see
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 23 */
24 24
25#include <global.h> 25#include <global.h>
26#include <funcpoint.h>
27#include <tod.h> 26#include <tod.h>
28 27
29#include <cstdio> 28#include <cstdio>
30 29
31#include <sys/types.h> 30#include <sys/types.h>
32#include <sys/time.h> 31#include <sys/time.h>
33 32
34/* 33/*
35 * Gloabal variables: 34 * Gloabal variables:
36 */ 35 */
37tick_t pticks; 36tick_t server_tick;
38 37
39static const char *season_name[5] = { 38static const char *season_name[5] = {
40 "New Year", 39 "New Year",
41 "Growth", 40 "Growth",
42 "Harvest", 41 "Harvest",
73 "the Ancient Darkness", 72 "the Ancient Darkness",
74 "Gorokh" 73 "Gorokh"
75}; 74};
76 75
77void 76void
78get_tod (timeofday_t * tod) 77get_tod (timeofday_t *tod)
79{ 78{
80 unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR)); 79 unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR));
81 80
82 tod->year = todtick / HOURS_PER_YEAR; 81 tod->year = todtick / HOURS_PER_YEAR + EPOCH;
83 tod->month = todtick / HOURS_PER_MONTH % MONTHS_PER_YEAR; 82 tod->month = todtick / HOURS_PER_MONTH % MONTHS_PER_YEAR;
84 tod->day = todtick % HOURS_PER_MONTH / DAYS_PER_MONTH; 83 tod->day = todtick % HOURS_PER_MONTH / DAYS_PER_MONTH;
85 tod->hour = todtick % HOURS_PER_DAY; 84 tod->hour = todtick % HOURS_PER_DAY;
86 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));
87 86
88 tod->dayofweek = tod->day % DAYS_PER_WEEK; 87 tod->dayofweek = tod->day % DAYS_PER_WEEK;
89 tod->weekofmonth = tod->day / WEEKS_PER_MONTH; 88 tod->weekofmonth = tod->day / WEEKS_PER_MONTH;
90 tod->season = min (4, tod->month / 3); 89 tod->season = min (4, tod->month / 4);
91} 90}
92 91
93void 92char *
94print_tod (object *op) 93format_tod (char *buf, int len, timeofday_t *tod)
95{ 94{
96 timeofday_t tod; 95 int day = tod->day + 1;
97 get_tod (&tod);
98 96
99 char todmsg [1024]; 97 const char *suf;
100 98
101 int day = tod.day + 1;
102 const char *suf;
103 if (day == 1 || ((day % 10) == 1 && day > 20)) 99 if (day == 1 || ((day % 10) == 1 && day > 20))
104 suf = "st"; 100 suf = "st";
105 else if (day == 2 || ((day % 10) == 2 && day > 20)) 101 else if (day == 2 || ((day % 10) == 2 && day > 20))
106 suf = "nd"; 102 suf = "nd";
107 else if (day == 3 || ((day % 10) == 3 && day > 20)) 103 else if (day == 3 || ((day % 10) == 3 && day > 20))
108 suf = "rd"; 104 suf = "rd";
109 else 105 else
110 suf = "th"; 106 suf = "th";
111 107
112 snprintf (todmsg, sizeof (todmsg), 108 snprintf (buf, len,
113 "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"
114 "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"
115 "It is the Season of %s.", 111 "It is the Season of %s.",
116 112
117 tod.minute + 1, 113 tod->minute ? tod->minute : 60,
118 (tod.minute + 1 < 2) ? "" : "s", 114 tod->minute ? "s" : "",
119 (tod.hour + 13) % 14 + 1, 115 (tod->hour + 13) % 14 + 1,
120 (tod.hour >= 14 ? "pm" : "am"), 116 (tod->hour >= 14 ? "pm" : "am"),
121 weekdays[tod.dayofweek], 117 weekdays[tod->dayofweek],
122 118
123 day, suf, month_name[tod.month], tod.year + 1, 119 day, suf, month_name[tod->month], tod->year + 1,
124 120
125 season_name[tod.season]); 121 season_name[tod->season]);
126 122
127 new_draw_info (NDI_UNIQUE, 0, op, todmsg); 123 return buf;
128} 124}
129 125
126static const char *
127get_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
138void
139print_tod (object *op)
140{
141 new_draw_info (NDI_UNIQUE, 0, op, get_current_tod_str ());
142}
143

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines