ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/time.C
Revision: 1.10
Committed: Sat Mar 17 22:11:22 2007 UTC (17 years, 2 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.9: +64 -67 lines
Log Message:
remove clockdata and base it off of the runtime; improve the tod code.

File Contents

# User Rev Content
1 elmex 1.1 /*
2 pippijn 1.9 * CrossFire, A Multiplayer game for X-windows
3     *
4     * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5     * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
6     * Copyright (C) 1992 Frank Tore Johansen
7     *
8     * This program is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License as published by
10     * the Free Software Foundation; either version 2 of the License, or
11     * (at your option) any later version.
12     *
13     * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17     *
18     * You should have received a copy of the GNU General Public License
19     * along with this program; if not, write to the Free Software
20     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21     *
22     * The authors can be reached via e-mail at <crossfire@schmorp.de>
23     */
24 elmex 1.1
25     #include <global.h>
26     #include <funcpoint.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     long pticks;
38    
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.4 get_tod (timeofday_t * tod)
79 elmex 1.1 {
80 root 1.10 unsigned int todtick = runtime * (1. / RUNTIME_PER_HOUR);
81    
82     tod->year = todtick / HOURS_PER_YEAR;
83     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     tod->minute = (runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR);
87    
88     tod->dayofweek = tod->day % DAYS_PER_WEEK;
89 root 1.4 tod->weekofmonth = tod->day / WEEKS_PER_MONTH;
90 root 1.10 tod->season = min (4, tod->month / 3);
91 elmex 1.1 }
92    
93     void
94 root 1.4 print_tod (object *op)
95 elmex 1.1 {
96     timeofday_t tod;
97    
98 root 1.4 get_tod (&tod);
99 elmex 1.1
100 root 1.10 char todmsg [1024];
101    
102     int day = tod.day + 1;
103     const char *suf;
104 elmex 1.1 if (day == 1 || ((day % 10) == 1 && day > 20))
105     suf = "st";
106     else if (day == 2 || ((day % 10) == 2 && day > 20))
107     suf = "nd";
108     else if (day == 3 || ((day % 10) == 3 && day > 20))
109     suf = "rd";
110     else
111     suf = "th";
112    
113 root 1.10 snprintf (todmsg, sizeof (todmsg),
114     "It is %d minute%s past %d o'clock %s, on the Day of %s,\n"
115     "the %d%s Day of the Month of %s, Year %d.\n"
116     "It is the Season of %s.",
117    
118     tod.minute + 1,
119     (tod.minute + 1 < 2) ? "" : "s",
120     (tod.hour + 13) % 14 + 1,
121     (tod.hour >= 14 ? "pm" : "am"),
122     weekdays[tod.dayofweek],
123    
124     day, suf, month_name[tod.month], tod.year + 1,
125    
126     season_name[tod.season]);
127    
128     new_draw_info (NDI_UNIQUE, 0, op, todmsg);
129 elmex 1.1 }
130