ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/time.C
Revision: 1.11
Committed: Sat Mar 17 22:32:15 2007 UTC (17 years, 2 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.10: +0 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 /*
2 * 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
25 #include <global.h>
26 #include <funcpoint.h>
27 #include <tod.h>
28
29 #include <cstdio>
30
31 #include <sys/types.h>
32 #include <sys/time.h>
33
34 /*
35 * Gloabal variables:
36 */
37 long pticks;
38
39 static const char *season_name[5] = {
40 "New Year",
41 "Growth",
42 "Harvest",
43 "Decay",
44 "the Blizzard",
45 };
46
47 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 };
56
57 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 };
76
77 void
78 get_tod (timeofday_t * tod)
79 {
80 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 tod->weekofmonth = tod->day / WEEKS_PER_MONTH;
90 tod->season = min (4, tod->month / 3);
91 }
92
93 void
94 print_tod (object *op)
95 {
96 timeofday_t tod;
97 get_tod (&tod);
98
99 char todmsg [1024];
100
101 int day = tod.day + 1;
102 const char *suf;
103 if (day == 1 || ((day % 10) == 1 && day > 20))
104 suf = "st";
105 else if (day == 2 || ((day % 10) == 2 && day > 20))
106 suf = "nd";
107 else if (day == 3 || ((day % 10) == 3 && day > 20))
108 suf = "rd";
109 else
110 suf = "th";
111
112 snprintf (todmsg, sizeof (todmsg),
113 "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"
115 "It is the Season of %s.",
116
117 tod.minute + 1,
118 (tod.minute + 1 < 2) ? "" : "s",
119 (tod.hour + 13) % 14 + 1,
120 (tod.hour >= 14 ? "pm" : "am"),
121 weekdays[tod.dayofweek],
122
123 day, suf, month_name[tod.month], tod.year + 1,
124
125 season_name[tod.season]);
126
127 new_draw_info (NDI_UNIQUE, 0, op, todmsg);
128 }
129