ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/time.C
Revision: 1.6
Committed: Mon Dec 11 19:46:46 2006 UTC (17 years, 5 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.5: +3 -5 lines
Log Message:
removed #ifn?def WIN32 from all files

File Contents

# User Rev Content
1 elmex 1.1 /*
2     CrossFire, A Multiplayer game for X-windows
3    
4     Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5     Copyright (C) 1992 Frank Tore Johansen
6    
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11    
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20    
21 root 1.5 The authors can be reached via e-mail at <crossfire@schmorp.de>
22 elmex 1.1 */
23    
24     #include <global.h>
25     #include <funcpoint.h>
26     #include <tod.h>
27    
28 pippijn 1.6 #include <stdio.h>
29     #include <sys/types.h>
30     #include <sys/time.h>
31 elmex 1.1
32     /*
33     * Gloabal variables:
34     */
35    
36     long psaveind;
37     long pticks;
38    
39 root 1.4 const char *season_name[] = {
40     "The Season of New Year",
41     "The Season of Growth",
42     "The Season of Harvest",
43     "The Season of Decay",
44     "The Season of the Blizzard",
45     "\n"
46 elmex 1.1 };
47    
48     const char *weekdays[DAYS_PER_WEEK] = {
49 root 1.4 "the Day of the Moon",
50     "the Day of the Bull",
51     "the Day of the Deception",
52     "the Day of Thunder",
53     "the Day of Freedom",
54     "the Day of the Great Gods",
55     "the Day of the Sun"
56 elmex 1.1 };
57    
58     const char *month_name[MONTHS_PER_YEAR] = {
59 root 1.4 "Month of Winter", /* 0 */
60     "Month of the Ice Dragon",
61     "Month of the Frost Giant",
62     "Month of Valriel",
63     "Month of Lythander",
64     "Month of the Harvest",
65     "Month of Gaea",
66     "Month of Futility",
67     "Month of the Dragon",
68     "Month of the Sun",
69     "Month of the Great Infernus",
70     "Month of Ruggilli",
71     "Month of the Dark Shades",
72     "Month of the Devourers",
73     "Month of Sorig",
74     "Month of the Ancient Darkness",
75     "Month of Gorokh"
76 elmex 1.1 };
77    
78     extern unsigned long todtick;
79    
80     void
81 root 1.4 get_tod (timeofday_t * tod)
82 elmex 1.1 {
83 root 1.4 tod->year = todtick / HOURS_PER_YEAR;
84     tod->month = (todtick / HOURS_PER_MONTH) % MONTHS_PER_YEAR;
85     tod->day = (todtick % HOURS_PER_MONTH) / DAYS_PER_MONTH;
86     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 elmex 1.1 if (tod->minute > 58)
90 root 1.4 tod->minute = 58; /* it's imprecise at best anyhow */
91     tod->weekofmonth = tod->day / WEEKS_PER_MONTH;
92 elmex 1.1 if (tod->month < 3)
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     }
103    
104     void
105 root 1.4 print_tod (object *op)
106 elmex 1.1 {
107     timeofday_t tod;
108     const char *suf;
109     int day;
110    
111 root 1.4 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 elmex 1.1
117     day = tod.day + 1;
118     if (day == 1 || ((day % 10) == 1 && day > 20))
119     suf = "st";
120     else if (day == 2 || ((day % 10) == 2 && day > 20))
121     suf = "nd";
122     else if (day == 3 || ((day % 10) == 3 && day > 20))
123     suf = "rd";
124     else
125     suf = "th";
126 root 1.4 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 elmex 1.1
129 root 1.4 sprintf (errmsg, "Time of Year: %s", season_name[tod.season]);
130     new_draw_info (NDI_UNIQUE, 0, op, errmsg);
131 elmex 1.1 }
132    
133     long
134 root 1.4 seconds (void)
135 elmex 1.1 {
136     struct timeval now;
137    
138 root 1.4 (void) GETTIMEOFDAY (&now);
139 elmex 1.1 return now.tv_sec;
140     }