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.4 by root, Sun Sep 10 16:00:23 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines