ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/time.C
Revision: 1.18
Committed: Mon Apr 21 23:35:24 2008 UTC (16 years, 1 month ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_6, rel-2_7, rel-2_72, rel-2_73, rel-2_71, rel-2_54, rel-2_55, rel-2_56, rel-2_52, rel-2_53, rel-2_61
Changes since 1.17: +1 -2 lines
Log Message:
- fix weight/pickup bugs, visible_to
- do more automatic nrof/weight updates
- kill funcpoint.h

File Contents

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 *
8 * Deliantra 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 3 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, see <http://www.gnu.org/licenses/>.
20 *
21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */
23
24 #include <global.h>
25 #include <tod.h>
26
27 #include <cstdio>
28
29 #include <sys/types.h>
30 #include <sys/time.h>
31
32 /*
33 * Gloabal variables:
34 */
35 tick_t pticks;
36
37 static const char *season_name[5] = {
38 "New Year",
39 "Growth",
40 "Harvest",
41 "Decay",
42 "the Blizzard",
43 };
44
45 static const char *weekdays[DAYS_PER_WEEK] = {
46 "the Moon",
47 "the Bull",
48 "the Deception",
49 "Thunder",
50 "Freedom",
51 "the Great Gods",
52 "the Sun"
53 };
54
55 static const char *month_name[MONTHS_PER_YEAR] = {
56 "Winter", /* 0 */
57 "the Ice Dragon",
58 "the Frost Giant",
59 "Valriel",
60 "Lythander",
61 "the Harvest",
62 "Gaea",
63 "Futility",
64 "the Dragon",
65 "the Sun",
66 "the Great Infernus",
67 "Ruggilli",
68 "the Dark Shades",
69 "the Devourers",
70 "Sorig",
71 "the Ancient Darkness",
72 "Gorokh"
73 };
74
75 void
76 get_tod (timeofday_t * tod)
77 {
78 unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR));
79
80 tod->year = todtick / HOURS_PER_YEAR;
81 tod->month = todtick / HOURS_PER_MONTH % MONTHS_PER_YEAR;
82 tod->day = todtick % HOURS_PER_MONTH / DAYS_PER_MONTH;
83 tod->hour = todtick % HOURS_PER_DAY;
84 tod->minute = (int)((runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR));
85
86 tod->dayofweek = tod->day % DAYS_PER_WEEK;
87 tod->weekofmonth = tod->day / WEEKS_PER_MONTH;
88 tod->season = min (4, tod->month / 3);
89 }
90
91 void
92 print_tod (object *op)
93 {
94 timeofday_t tod;
95 get_tod (&tod);
96
97 char todmsg [1024];
98
99 int day = tod.day + 1;
100 const char *suf;
101 if (day == 1 || ((day % 10) == 1 && day > 20))
102 suf = "st";
103 else if (day == 2 || ((day % 10) == 2 && day > 20))
104 suf = "nd";
105 else if (day == 3 || ((day % 10) == 3 && day > 20))
106 suf = "rd";
107 else
108 suf = "th";
109
110 snprintf (todmsg, sizeof (todmsg),
111 "It is %d minute%s past %d o'clock %s, on the Day of %s,\n"
112 "the %d%s Day of the Month of %s, Year %d.\n"
113 "It is the Season of %s.",
114
115 tod.minute + 1,
116 (tod.minute + 1 < 2) ? "" : "s",
117 (tod.hour + 13) % 14 + 1,
118 (tod.hour >= 14 ? "pm" : "am"),
119 weekdays[tod.dayofweek],
120
121 day, suf, month_name[tod.month], tod.year + 1,
122
123 season_name[tod.season]);
124
125 new_draw_info (NDI_UNIQUE, 0, op, todmsg);
126 }
127