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.18 by root, Mon Apr 21 23:35:24 2008 UTC vs.
Revision 1.19 by root, Tue Dec 23 06:58:23 2008 UTC

71 "the Ancient Darkness", 71 "the Ancient Darkness",
72 "Gorokh" 72 "Gorokh"
73}; 73};
74 74
75void 75void
76get_tod (timeofday_t * tod) 76get_tod (timeofday_t *tod)
77{ 77{
78 unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR)); 78 unsigned int todtick = (unsigned int)(runtime * (1. / RUNTIME_PER_HOUR));
79 79
80 tod->year = todtick / HOURS_PER_YEAR; 80 tod->year = todtick / HOURS_PER_YEAR;
81 tod->month = todtick / HOURS_PER_MONTH % MONTHS_PER_YEAR; 81 tod->month = todtick / HOURS_PER_MONTH % MONTHS_PER_YEAR;
83 tod->hour = todtick % HOURS_PER_DAY; 83 tod->hour = todtick % HOURS_PER_DAY;
84 tod->minute = (int)((runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR)); 84 tod->minute = (int)((runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR));
85 85
86 tod->dayofweek = tod->day % DAYS_PER_WEEK; 86 tod->dayofweek = tod->day % DAYS_PER_WEEK;
87 tod->weekofmonth = tod->day / WEEKS_PER_MONTH; 87 tod->weekofmonth = tod->day / WEEKS_PER_MONTH;
88 tod->season = min (4, tod->month / 3); 88 tod->season = min (4, tod->month / 4);
89} 89}
90 90
91void 91char *
92print_tod (object *op) 92format_tod (char *buf, int len, timeofday_t *tod)
93{ 93{
94 timeofday_t tod; 94 int day = tod->day + 1;
95 get_tod (&tod);
96 95
97 char todmsg [1024]; 96 const char *suf;
98 97
99 int day = tod.day + 1;
100 const char *suf;
101 if (day == 1 || ((day % 10) == 1 && day > 20)) 98 if (day == 1 || ((day % 10) == 1 && day > 20))
102 suf = "st"; 99 suf = "st";
103 else if (day == 2 || ((day % 10) == 2 && day > 20)) 100 else if (day == 2 || ((day % 10) == 2 && day > 20))
104 suf = "nd"; 101 suf = "nd";
105 else if (day == 3 || ((day % 10) == 3 && day > 20)) 102 else if (day == 3 || ((day % 10) == 3 && day > 20))
106 suf = "rd"; 103 suf = "rd";
107 else 104 else
108 suf = "th"; 105 suf = "th";
109 106
110 snprintf (todmsg, sizeof (todmsg), 107 snprintf (buf, len,
111 "It is %d minute%s past %d o'clock %s, on the Day of %s,\n" 108 "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" 109 "the %d%s Day of the Month of %s, Year %d.\n"
113 "It is the Season of %s.", 110 "It is the Season of %s.",
114 111
115 tod.minute + 1, 112 tod->minute ? tod->minute : 60,
116 (tod.minute + 1 < 2) ? "" : "s", 113 tod->minute ? "s" : "",
117 (tod.hour + 13) % 14 + 1, 114 (tod->hour + 13) % 14 + 1,
118 (tod.hour >= 14 ? "pm" : "am"), 115 (tod->hour >= 14 ? "pm" : "am"),
119 weekdays[tod.dayofweek], 116 weekdays[tod->dayofweek],
120 117
121 day, suf, month_name[tod.month], tod.year + 1, 118 day, suf, month_name[tod->month], tod->year + 1,
122 119
123 season_name[tod.season]); 120 season_name[tod->season]);
124 121
125 new_draw_info (NDI_UNIQUE, 0, op, todmsg); 122 return buf;
126} 123}
127 124
125const char *
126get_current_tod_str ()
127{
128 timeofday_t tod;
129 get_tod (&tod);
130
131 static char todbuf[512];
132 format_tod (todbuf, sizeof (todbuf), &tod);
133
134 return todbuf;
135}
136
137void
138print_tod (object *op)
139{
140 new_draw_info (NDI_UNIQUE, 0, op, get_current_tod_str ());
141}
142

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines