ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/time.C
(Generate patch)

Comparing deliantra/server/common/time.C (file contents):
Revision 1.3 by root, Thu Aug 24 13:13:48 2006 UTC vs.
Revision 1.6 by pippijn, Mon Dec 11 19:46:46 2006 UTC

1/*
2 * static char *rcsid_time_c =
3 * "$Id: time.C,v 1.3 2006/08/24 13:13:48 root Exp $";
4 */
5
6/* 1/*
7 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
8 3
9 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
10 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
21 16
22 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 20
26 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
27*/ 22*/
28 23
29#include <global.h> 24#include <global.h>
30#include <funcpoint.h> 25#include <funcpoint.h>
31#include <tod.h> 26#include <tod.h>
32 27
33#ifndef WIN32 /* ---win32 exclude header */
34#include <stdio.h> 28#include <stdio.h>
35#include <sys/types.h> 29#include <sys/types.h>
36#include <sys/time.h> 30#include <sys/time.h>
37#endif /* win32 */
38 31
39/* 32/*
40 * Gloabal variables: 33 * Gloabal variables:
41 */ 34 */
42 35
43long psaveind; 36long psaveind;
44long pticks; 37long pticks;
45 38
46const char *season_name[] = 39const char *season_name[] = {
47{
48 "The Season of New Year", 40 "The Season of New Year",
49 "The Season of Growth", 41 "The Season of Growth",
50 "The Season of Harvest", 42 "The Season of Harvest",
51 "The Season of Decay", 43 "The Season of Decay",
52 "The Season of the Blizzard", 44 "The Season of the Blizzard",
53 "\n" 45 "\n"
54}; 46};
55 47
56const char *weekdays[DAYS_PER_WEEK] = { 48const char *weekdays[DAYS_PER_WEEK] = {
57 "the Day of the Moon", 49 "the Day of the Moon",
58 "the Day of the Bull", 50 "the Day of the Bull",
59 "the Day of the Deception", 51 "the Day of the Deception",
60 "the Day of Thunder", 52 "the Day of Thunder",
61 "the Day of Freedom", 53 "the Day of Freedom",
62 "the Day of the Great Gods", 54 "the Day of the Great Gods",
63 "the Day of the Sun" 55 "the Day of the Sun"
64}; 56};
65 57
66const char *month_name[MONTHS_PER_YEAR] = { 58const char *month_name[MONTHS_PER_YEAR] = {
67 "Month of Winter", /* 0 */ 59 "Month of Winter", /* 0 */
68 "Month of the Ice Dragon", 60 "Month of the Ice Dragon",
69 "Month of the Frost Giant", 61 "Month of the Frost Giant",
70 "Month of Valriel", 62 "Month of Valriel",
71 "Month of Lythander", 63 "Month of Lythander",
72 "Month of the Harvest", 64 "Month of the Harvest",
73 "Month of Gaea", 65 "Month of Gaea",
74 "Month of Futility", 66 "Month of Futility",
75 "Month of the Dragon", 67 "Month of the Dragon",
76 "Month of the Sun", 68 "Month of the Sun",
77 "Month of the Great Infernus", 69 "Month of the Great Infernus",
78 "Month of Ruggilli", 70 "Month of Ruggilli",
79 "Month of the Dark Shades", 71 "Month of the Dark Shades",
80 "Month of the Devourers", 72 "Month of the Devourers",
81 "Month of Sorig", 73 "Month of Sorig",
82 "Month of the Ancient Darkness", 74 "Month of the Ancient Darkness",
83 "Month of Gorokh" 75 "Month of Gorokh"
84}; 76};
85 77
86extern unsigned long todtick; 78extern unsigned long todtick;
87 79
88void 80void
89get_tod(timeofday_t *tod) 81get_tod (timeofday_t * tod)
90{ 82{
91 tod->year = todtick/HOURS_PER_YEAR; 83 tod->year = todtick / HOURS_PER_YEAR;
92 tod->month = (todtick/HOURS_PER_MONTH)%MONTHS_PER_YEAR; 84 tod->month = (todtick / HOURS_PER_MONTH) % MONTHS_PER_YEAR;
93 tod->day = (todtick%HOURS_PER_MONTH)/DAYS_PER_MONTH; 85 tod->day = (todtick % HOURS_PER_MONTH) / DAYS_PER_MONTH;
94 tod->dayofweek = tod->day%DAYS_PER_WEEK; 86 tod->dayofweek = tod->day % DAYS_PER_WEEK;
95 tod->hour = todtick%HOURS_PER_DAY; 87 tod->hour = todtick % HOURS_PER_DAY;
96 tod->minute = (pticks%PTICKS_PER_CLOCK)/(PTICKS_PER_CLOCK/58); 88 tod->minute = (pticks % PTICKS_PER_CLOCK) / (PTICKS_PER_CLOCK / 58);
97 if (tod->minute > 58) 89 if (tod->minute > 58)
98 tod->minute = 58; /* it's imprecise at best anyhow */ 90 tod->minute = 58; /* it's imprecise at best anyhow */
99 tod->weekofmonth = tod->day/WEEKS_PER_MONTH; 91 tod->weekofmonth = tod->day / WEEKS_PER_MONTH;
100 if (tod->month < 3) 92 if (tod->month < 3)
101 tod->season = 0; 93 tod->season = 0;
102 else if (tod->month < 6) 94 else if (tod->month < 6)
103 tod->season = 1; 95 tod->season = 1;
104 else if (tod->month < 9) 96 else if (tod->month < 9)
108 else 100 else
109 tod->season = 4; 101 tod->season = 4;
110} 102}
111 103
112void 104void
113print_tod(object *op) 105print_tod (object *op)
114{ 106{
115 timeofday_t tod; 107 timeofday_t tod;
116 const char *suf; 108 const char *suf;
117 int day; 109 int day;
118 110
119 get_tod(&tod); 111 get_tod (&tod);
120 sprintf(errmsg, "It is %d minute%s past %d o'clock %s, on %s", 112 sprintf (errmsg, "It is %d minute%s past %d o'clock %s, on %s",
121 tod.minute+1, ((tod.minute+1 < 2) ? "" : "s"), 113 tod.minute + 1, ((tod.minute + 1 < 2) ? "" : "s"),
122 ((tod.hour % 14 == 0) ? 14 : ((tod.hour)%14)), 114 ((tod.hour % 14 == 0) ? 14 : ((tod.hour) % 14)), ((tod.hour >= 14) ? "pm" : "am"), weekdays[tod.dayofweek]);
123 ((tod.hour >= 14) ? "pm" : "am"),
124 weekdays[tod.dayofweek]);
125 new_draw_info(NDI_UNIQUE, 0,op,errmsg); 115 new_draw_info (NDI_UNIQUE, 0, op, errmsg);
126 116
127 day = tod.day + 1; 117 day = tod.day + 1;
128 if (day == 1 || ((day % 10) == 1 && day > 20)) 118 if (day == 1 || ((day % 10) == 1 && day > 20))
129 suf = "st"; 119 suf = "st";
130 else if (day == 2 || ((day % 10) == 2 && day > 20)) 120 else if (day == 2 || ((day % 10) == 2 && day > 20))
131 suf = "nd"; 121 suf = "nd";
132 else if (day == 3 || ((day % 10) == 3 && day > 20)) 122 else if (day == 3 || ((day % 10) == 3 && day > 20))
133 suf = "rd"; 123 suf = "rd";
134 else 124 else
135 suf = "th"; 125 suf = "th";
136 sprintf(errmsg, "The %d%s Day of the %s, Year %d", day, suf, 126 sprintf (errmsg, "The %d%s Day of the %s, Year %d", day, suf, month_name[tod.month], tod.year + 1);
137 month_name[tod.month], tod.year+1);
138 new_draw_info(NDI_UNIQUE, 0,op,errmsg); 127 new_draw_info (NDI_UNIQUE, 0, op, errmsg);
139 128
140 sprintf(errmsg, "Time of Year: %s", season_name[tod.season]); 129 sprintf (errmsg, "Time of Year: %s", season_name[tod.season]);
141 new_draw_info(NDI_UNIQUE, 0,op,errmsg); 130 new_draw_info (NDI_UNIQUE, 0, op, errmsg);
142} 131}
143 132
144long 133long
145seconds(void) 134seconds (void)
146{ 135{
147 struct timeval now; 136 struct timeval now;
148 137
149 (void) GETTIMEOFDAY(&now); 138 (void) GETTIMEOFDAY (&now);
150 return now.tv_sec; 139 return now.tv_sec;
151} 140}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines