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

# User Rev Content
1 elmex 1.1 /*
2 root 1.17 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 pippijn 1.9 *
4 root 1.18 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 root 1.15 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6     * Copyright (©) 1992,2007 Frank Tore Johansen
7 pippijn 1.9 *
8 root 1.17 * Deliantra is free software: you can redistribute it and/or modify
9 root 1.16 * 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 pippijn 1.9 *
13 root 1.16 * 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 pippijn 1.9 *
18 root 1.16 * 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 root 1.15 *
21 root 1.17 * The authors can be reached via e-mail to <support@deliantra.net>
22 pippijn 1.9 */
23 elmex 1.1
24     #include <global.h>
25     #include <tod.h>
26    
27 root 1.10 #include <cstdio>
28    
29 pippijn 1.6 #include <sys/types.h>
30     #include <sys/time.h>
31 elmex 1.1
32     /*
33     * Gloabal variables:
34     */
35 root 1.13 tick_t pticks;
36 elmex 1.1
37 root 1.10 static const char *season_name[5] = {
38     "New Year",
39     "Growth",
40     "Harvest",
41     "Decay",
42     "the Blizzard",
43 elmex 1.1 };
44    
45 root 1.10 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 elmex 1.1 };
54    
55 root 1.10 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 elmex 1.1 };
74    
75     void
76 root 1.4 get_tod (timeofday_t * tod)
77 elmex 1.1 {
78 root 1.12 unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR));
79 root 1.10
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 root 1.12 tod->minute = (int)((runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR));
85 root 1.10
86     tod->dayofweek = tod->day % DAYS_PER_WEEK;
87 root 1.4 tod->weekofmonth = tod->day / WEEKS_PER_MONTH;
88 root 1.10 tod->season = min (4, tod->month / 3);
89 elmex 1.1 }
90    
91     void
92 root 1.4 print_tod (object *op)
93 elmex 1.1 {
94     timeofday_t tod;
95 root 1.4 get_tod (&tod);
96 elmex 1.1
97 root 1.10 char todmsg [1024];
98    
99     int day = tod.day + 1;
100     const char *suf;
101 elmex 1.1 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 root 1.10 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 elmex 1.1 }
127