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.4 by root, Sun Sep 10 16:00:23 2006 UTC vs.
Revision 1.30 by root, Sat Nov 17 23:40:00 2018 UTC

1
2/* 1/*
3 * static char *rcsid_time_c = 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
4 * "$Id: time.C,v 1.4 2006/09/10 16:00:23 root Exp $"; 3 *
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
6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
7 * Copyright (©) 1992 Frank Tore Johansen
8 *
9 * 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 *
14 * 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 *
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 *
23 * The authors can be reached via e-mail to <support@deliantra.net>
5 */ 24 */
6 25
7/*
8 CrossFire, A Multiplayer game for X-windows
9
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27 The authors can be reached via e-mail at crossfire-devel@real-time.com
28*/
29
30#include <global.h> 26#include <global.h>
31#include <funcpoint.h>
32#include <tod.h> 27#include <tod.h>
33 28
34#ifndef WIN32 /* ---win32 exclude header */
35# include <stdio.h> 29#include <cstdio>
30
36# include <sys/types.h> 31#include <sys/types.h>
37# include <sys/time.h> 32#include <sys/time.h>
38#endif /* win32 */
39 33
40/* 34/*
41 * Gloabal variables: 35 * Gloabal variables:
42 */ 36 */
37tick_t server_tick;
43 38
44long psaveind;
45long pticks;
46
47const char *season_name[] = { 39static const char *season_name[5] = {
48 "The Season of New Year", 40 "New Year",
49 "The Season of Growth", 41 "Growth",
50 "The Season of Harvest", 42 "Harvest",
51 "The Season of Decay", 43 "Decay",
52 "The Season of the Blizzard", 44 "the Blizzard",
53 "\n"
54}; 45};
55 46
56const char *weekdays[DAYS_PER_WEEK] = { 47static const char *weekdays[DAYS_PER_WEEK] = {
57 "the Day of the Moon", 48 "the Moon",
58 "the Day of the Bull", 49 "the Bull",
59 "the Day of the Deception", 50 "the Deception",
60 "the Day of Thunder", 51 "Thunder",
61 "the Day of Freedom", 52 "Freedom",
62 "the Day of the Great Gods", 53 "the Great Gods",
63 "the Day of the Sun" 54 "the Sun"
64}; 55};
65 56
66const char *month_name[MONTHS_PER_YEAR] = { 57static const char *month_name[MONTHS_PER_YEAR] = {
67 "Month of Winter", /* 0 */ 58 "Winter", /* 0 */
68 "Month of the Ice Dragon", 59 "the Ice Dragon",
69 "Month of the Frost Giant", 60 "the Frost Giant",
70 "Month of Valriel", 61 "Valriel",
71 "Month of Lythander", 62 "Lythander",
72 "Month of the Harvest", 63 "the Harvest",
73 "Month of Gaea", 64 "Gaea",
74 "Month of Futility", 65 "Futility",
75 "Month of the Dragon", 66 "the Dragon",
76 "Month of the Sun", 67 "the Sun",
77 "Month of the Great Infernus", 68 "the Great Infernus",
78 "Month of Ruggilli", 69 "Ruggilli",
79 "Month of the Dark Shades", 70 "the Dark Shades",
80 "Month of the Devourers", 71 "the Devourers",
81 "Month of Sorig", 72 "Sorig",
82 "Month of the Ancient Darkness", 73 "the Ancient Darkness",
83 "Month of Gorokh" 74 "Gorokh"
84}; 75};
85 76
86extern unsigned long todtick; 77void
78get_tod (timeofday_t *tod)
79{
80 unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR));
87 81
88void
89get_tod (timeofday_t * tod)
90{
91 tod->year = todtick / HOURS_PER_YEAR; 82 tod->year = todtick / HOURS_PER_YEAR + EPOCH;
92 tod->month = (todtick / HOURS_PER_MONTH) % MONTHS_PER_YEAR; 83 tod->month = todtick / HOURS_PER_MONTH % MONTHS_PER_YEAR;
93 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;
86 tod->minute = (int)((runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR));
87
94 tod->dayofweek = tod->day % DAYS_PER_WEEK; 88 tod->dayofweek = tod->day % DAYS_PER_WEEK;
95 tod->hour = todtick % HOURS_PER_DAY;
96 tod->minute = (pticks % PTICKS_PER_CLOCK) / (PTICKS_PER_CLOCK / 58);
97 if (tod->minute > 58)
98 tod->minute = 58; /* it's imprecise at best anyhow */
99 tod->weekofmonth = tod->day / WEEKS_PER_MONTH; 89 tod->weekofmonth = tod->day / WEEKS_PER_MONTH;
100 if (tod->month < 3) 90 tod->season = min (4, tod->month / 4);
101 tod->season = 0;
102 else if (tod->month < 6)
103 tod->season = 1;
104 else if (tod->month < 9)
105 tod->season = 2;
106 else if (tod->month < 12)
107 tod->season = 3;
108 else
109 tod->season = 4;
110} 91}
111 92
112void 93char *
113print_tod (object *op) 94format_tod (char *buf, int len, timeofday_t *tod)
114{ 95{
115 timeofday_t tod; 96 int day = tod->day + 1;
97
116 const char *suf; 98 const char *suf;
117 int day;
118 99
119 get_tod (&tod);
120 sprintf (errmsg, "It is %d minute%s past %d o'clock %s, on %s",
121 tod.minute + 1, ((tod.minute + 1 < 2) ? "" : "s"),
122 ((tod.hour % 14 == 0) ? 14 : ((tod.hour) % 14)), ((tod.hour >= 14) ? "pm" : "am"), weekdays[tod.dayofweek]);
123 new_draw_info (NDI_UNIQUE, 0, op, errmsg);
124
125 day = tod.day + 1;
126 if (day == 1 || ((day % 10) == 1 && day > 20)) 100 if (day == 1 || ((day % 10) == 1 && day > 20))
127 suf = "st"; 101 suf = "st";
128 else if (day == 2 || ((day % 10) == 2 && day > 20)) 102 else if (day == 2 || ((day % 10) == 2 && day > 20))
129 suf = "nd"; 103 suf = "nd";
130 else if (day == 3 || ((day % 10) == 3 && day > 20)) 104 else if (day == 3 || ((day % 10) == 3 && day > 20))
131 suf = "rd"; 105 suf = "rd";
132 else 106 else
133 suf = "th"; 107 suf = "th";
134 sprintf (errmsg, "The %d%s Day of the %s, Year %d", day, suf, month_name[tod.month], tod.year + 1);
135 new_draw_info (NDI_UNIQUE, 0, op, errmsg);
136 108
137 sprintf (errmsg, "Time of Year: %s", season_name[tod.season]); 109 snprintf (buf, len,
138 new_draw_info (NDI_UNIQUE, 0, op, errmsg); 110 "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 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;
139} 125}
140 126
141long 127static const char *
142seconds (void) 128get_current_tod_str ()
143{ 129{
144 struct timeval now; 130 timeofday_t tod;
131 get_tod (&tod);
145 132
146 (void) GETTIMEOFDAY (&now); 133 static char todbuf[512];
147 return now.tv_sec; 134 format_tod (todbuf, sizeof (todbuf), &tod);
135
136 return todbuf;
148} 137}
138
139void
140print_tod (object *op)
141{
142 new_draw_info (NDI_UNIQUE, 0, op, get_current_tod_str ());
143}
144

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines