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.6 by pippijn, Mon Dec 11 19:46:46 2006 UTC vs.
Revision 1.23 by root, Fri Mar 26 00:59:20 2010 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 (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
6 7 *
7 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
8 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
9 the Free Software Foundation; either version 2 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
10 (at your option) any later version. 11 * option) any later version.
11 12 *
12 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,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 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
18 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
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * <http://www.gnu.org/licenses/>.
20 21 *
21 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>
22*/ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <funcpoint.h>
26#include <tod.h> 26#include <tod.h>
27 27
28#include <stdio.h> 28#include <cstdio>
29
29#include <sys/types.h> 30#include <sys/types.h>
30#include <sys/time.h> 31#include <sys/time.h>
31 32
32/* 33/*
33 * Gloabal variables: 34 * Gloabal variables:
34 */ 35 */
36tick_t pticks;
35 37
36long psaveind;
37long pticks;
38
39const char *season_name[] = { 38static const char *season_name[5] = {
40 "The Season of New Year", 39 "New Year",
41 "The Season of Growth", 40 "Growth",
42 "The Season of Harvest", 41 "Harvest",
43 "The Season of Decay", 42 "Decay",
44 "The Season of the Blizzard", 43 "the Blizzard",
45 "\n"
46}; 44};
47 45
48const char *weekdays[DAYS_PER_WEEK] = { 46static const char *weekdays[DAYS_PER_WEEK] = {
49 "the Day of the Moon", 47 "the Moon",
50 "the Day of the Bull", 48 "the Bull",
51 "the Day of the Deception", 49 "the Deception",
52 "the Day of Thunder", 50 "Thunder",
53 "the Day of Freedom", 51 "Freedom",
54 "the Day of the Great Gods", 52 "the Great Gods",
55 "the Day of the Sun" 53 "the Sun"
56}; 54};
57 55
58const char *month_name[MONTHS_PER_YEAR] = { 56static const char *month_name[MONTHS_PER_YEAR] = {
59 "Month of Winter", /* 0 */ 57 "Winter", /* 0 */
60 "Month of the Ice Dragon", 58 "the Ice Dragon",
61 "Month of the Frost Giant", 59 "the Frost Giant",
62 "Month of Valriel", 60 "Valriel",
63 "Month of Lythander", 61 "Lythander",
64 "Month of the Harvest", 62 "the Harvest",
65 "Month of Gaea", 63 "Gaea",
66 "Month of Futility", 64 "Futility",
67 "Month of the Dragon", 65 "the Dragon",
68 "Month of the Sun", 66 "the Sun",
69 "Month of the Great Infernus", 67 "the Great Infernus",
70 "Month of Ruggilli", 68 "Ruggilli",
71 "Month of the Dark Shades", 69 "the Dark Shades",
72 "Month of the Devourers", 70 "the Devourers",
73 "Month of Sorig", 71 "Sorig",
74 "Month of the Ancient Darkness", 72 "the Ancient Darkness",
75 "Month of Gorokh" 73 "Gorokh"
76}; 74};
77 75
78extern unsigned long todtick; 76void
77get_tod (timeofday_t *tod)
78{
79 unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR));
79 80
80void
81get_tod (timeofday_t * tod)
82{
83 tod->year = todtick / HOURS_PER_YEAR; 81 tod->year = todtick / HOURS_PER_YEAR + EPOCH;
84 tod->month = (todtick / HOURS_PER_MONTH) % MONTHS_PER_YEAR; 82 tod->month = todtick / HOURS_PER_MONTH % MONTHS_PER_YEAR;
85 tod->day = (todtick % HOURS_PER_MONTH) / DAYS_PER_MONTH; 83 tod->day = todtick % HOURS_PER_MONTH / DAYS_PER_MONTH;
84 tod->hour = todtick % HOURS_PER_DAY;
85 tod->minute = (int)((runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR));
86
86 tod->dayofweek = tod->day % DAYS_PER_WEEK; 87 tod->dayofweek = tod->day % DAYS_PER_WEEK;
87 tod->hour = todtick % HOURS_PER_DAY;
88 tod->minute = (pticks % PTICKS_PER_CLOCK) / (PTICKS_PER_CLOCK / 58);
89 if (tod->minute > 58)
90 tod->minute = 58; /* it's imprecise at best anyhow */
91 tod->weekofmonth = tod->day / WEEKS_PER_MONTH; 88 tod->weekofmonth = tod->day / WEEKS_PER_MONTH;
92 if (tod->month < 3) 89 tod->season = min (4, tod->month / 4);
93 tod->season = 0;
94 else if (tod->month < 6)
95 tod->season = 1;
96 else if (tod->month < 9)
97 tod->season = 2;
98 else if (tod->month < 12)
99 tod->season = 3;
100 else
101 tod->season = 4;
102} 90}
103 91
104void 92char *
105print_tod (object *op) 93format_tod (char *buf, int len, timeofday_t *tod)
106{ 94{
107 timeofday_t tod; 95 int day = tod->day + 1;
96
108 const char *suf; 97 const char *suf;
109 int day;
110 98
111 get_tod (&tod);
112 sprintf (errmsg, "It is %d minute%s past %d o'clock %s, on %s",
113 tod.minute + 1, ((tod.minute + 1 < 2) ? "" : "s"),
114 ((tod.hour % 14 == 0) ? 14 : ((tod.hour) % 14)), ((tod.hour >= 14) ? "pm" : "am"), weekdays[tod.dayofweek]);
115 new_draw_info (NDI_UNIQUE, 0, op, errmsg);
116
117 day = tod.day + 1;
118 if (day == 1 || ((day % 10) == 1 && day > 20)) 99 if (day == 1 || ((day % 10) == 1 && day > 20))
119 suf = "st"; 100 suf = "st";
120 else if (day == 2 || ((day % 10) == 2 && day > 20)) 101 else if (day == 2 || ((day % 10) == 2 && day > 20))
121 suf = "nd"; 102 suf = "nd";
122 else if (day == 3 || ((day % 10) == 3 && day > 20)) 103 else if (day == 3 || ((day % 10) == 3 && day > 20))
123 suf = "rd"; 104 suf = "rd";
124 else 105 else
125 suf = "th"; 106 suf = "th";
126 sprintf (errmsg, "The %d%s Day of the %s, Year %d", day, suf, month_name[tod.month], tod.year + 1);
127 new_draw_info (NDI_UNIQUE, 0, op, errmsg);
128 107
129 sprintf (errmsg, "Time of Year: %s", season_name[tod.season]); 108 snprintf (buf, len,
130 new_draw_info (NDI_UNIQUE, 0, op, errmsg); 109 "It is %d minute%s past %d o'clock %s, on the Day of %s,\n"
110 "the %d%s Day of the Month of %s, Year %d.\n"
111 "It is the Season of %s.",
112
113 tod->minute ? tod->minute : 60,
114 tod->minute ? "s" : "",
115 (tod->hour + 13) % 14 + 1,
116 (tod->hour >= 14 ? "pm" : "am"),
117 weekdays[tod->dayofweek],
118
119 day, suf, month_name[tod->month], tod->year + 1,
120
121 season_name[tod->season]);
122
123 return buf;
131} 124}
132 125
133long 126static const char *
134seconds (void) 127get_current_tod_str ()
135{ 128{
136 struct timeval now; 129 timeofday_t tod;
130 get_tod (&tod);
137 131
138 (void) GETTIMEOFDAY (&now); 132 static char todbuf[512];
139 return now.tv_sec; 133 format_tod (todbuf, sizeof (todbuf), &tod);
134
135 return todbuf;
140} 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