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.9 by pippijn, Mon Jan 15 21:06:18 2007 UTC vs.
Revision 1.10 by root, Sat Mar 17 22:11:22 2007 UTC

24 24
25#include <global.h> 25#include <global.h>
26#include <funcpoint.h> 26#include <funcpoint.h>
27#include <tod.h> 27#include <tod.h>
28 28
29#include <stdio.h> 29#include <cstdio>
30
30#include <sys/types.h> 31#include <sys/types.h>
31#include <sys/time.h> 32#include <sys/time.h>
32 33
33/* 34/*
34 * Gloabal variables: 35 * Gloabal variables:
35 */ 36 */
36
37long psaveind;
38long pticks; 37long pticks;
39 38
40const char *season_name[] = { 39static const char *season_name[5] = {
41 "The Season of New Year", 40 "New Year",
42 "The Season of Growth", 41 "Growth",
43 "The Season of Harvest", 42 "Harvest",
44 "The Season of Decay", 43 "Decay",
45 "The Season of the Blizzard", 44 "the Blizzard",
46 "\n"
47}; 45};
48 46
49const char *weekdays[DAYS_PER_WEEK] = { 47static const char *weekdays[DAYS_PER_WEEK] = {
50 "the Day of the Moon", 48 "the Moon",
51 "the Day of the Bull", 49 "the Bull",
52 "the Day of the Deception", 50 "the Deception",
53 "the Day of Thunder", 51 "Thunder",
54 "the Day of Freedom", 52 "Freedom",
55 "the Day of the Great Gods", 53 "the Great Gods",
56 "the Day of the Sun" 54 "the Sun"
57}; 55};
58 56
59const char *month_name[MONTHS_PER_YEAR] = { 57static const char *month_name[MONTHS_PER_YEAR] = {
60 "Month of Winter", /* 0 */ 58 "Winter", /* 0 */
61 "Month of the Ice Dragon", 59 "the Ice Dragon",
62 "Month of the Frost Giant", 60 "the Frost Giant",
63 "Month of Valriel", 61 "Valriel",
64 "Month of Lythander", 62 "Lythander",
65 "Month of the Harvest", 63 "the Harvest",
66 "Month of Gaea", 64 "Gaea",
67 "Month of Futility", 65 "Futility",
68 "Month of the Dragon", 66 "the Dragon",
69 "Month of the Sun", 67 "the Sun",
70 "Month of the Great Infernus", 68 "the Great Infernus",
71 "Month of Ruggilli", 69 "Ruggilli",
72 "Month of the Dark Shades", 70 "the Dark Shades",
73 "Month of the Devourers", 71 "the Devourers",
74 "Month of Sorig", 72 "Sorig",
75 "Month of the Ancient Darkness", 73 "the Ancient Darkness",
76 "Month of Gorokh" 74 "Gorokh"
77}; 75};
78
79extern unsigned long todtick;
80 76
81void 77void
82get_tod (timeofday_t * tod) 78get_tod (timeofday_t * tod)
83{ 79{
80 unsigned int todtick = runtime * (1. / RUNTIME_PER_HOUR);
81
84 tod->year = todtick / HOURS_PER_YEAR; 82 tod->year = todtick / HOURS_PER_YEAR;
85 tod->month = (todtick / HOURS_PER_MONTH) % MONTHS_PER_YEAR; 83 tod->month = todtick / HOURS_PER_MONTH % MONTHS_PER_YEAR;
86 tod->day = (todtick % HOURS_PER_MONTH) / DAYS_PER_MONTH; 84 tod->day = todtick % HOURS_PER_MONTH / DAYS_PER_MONTH;
85 tod->hour = todtick % HOURS_PER_DAY;
86 tod->minute = (runtime - todtick * RUNTIME_PER_HOUR) * (60. / RUNTIME_PER_HOUR);
87
87 tod->dayofweek = tod->day % DAYS_PER_WEEK; 88 tod->dayofweek = tod->day % DAYS_PER_WEEK;
88 tod->hour = todtick % HOURS_PER_DAY;
89 tod->minute = (pticks % PTICKS_PER_CLOCK) / (PTICKS_PER_CLOCK / 58);
90 if (tod->minute > 58)
91 tod->minute = 58; /* it's imprecise at best anyhow */
92 tod->weekofmonth = tod->day / WEEKS_PER_MONTH; 89 tod->weekofmonth = tod->day / WEEKS_PER_MONTH;
93 if (tod->month < 3) 90 tod->season = min (4, tod->month / 3);
94 tod->season = 0;
95 else if (tod->month < 6)
96 tod->season = 1;
97 else if (tod->month < 9)
98 tod->season = 2;
99 else if (tod->month < 12)
100 tod->season = 3;
101 else
102 tod->season = 4;
103} 91}
104 92
105void 93void
106print_tod (object *op) 94print_tod (object *op)
107{ 95{
108 timeofday_t tod; 96 timeofday_t tod;
109 const char *suf;
110 int day;
111 97
112 get_tod (&tod); 98 get_tod (&tod);
113 sprintf (errmsg, "It is %d minute%s past %d o'clock %s, on %s",
114 tod.minute + 1, ((tod.minute + 1 < 2) ? "" : "s"),
115 ((tod.hour % 14 == 0) ? 14 : ((tod.hour) % 14)), ((tod.hour >= 14) ? "pm" : "am"), weekdays[tod.dayofweek]);
116 new_draw_info (NDI_UNIQUE, 0, op, errmsg);
117 99
100 char todmsg [1024];
101
118 day = tod.day + 1; 102 int day = tod.day + 1;
103 const char *suf;
119 if (day == 1 || ((day % 10) == 1 && day > 20)) 104 if (day == 1 || ((day % 10) == 1 && day > 20))
120 suf = "st"; 105 suf = "st";
121 else if (day == 2 || ((day % 10) == 2 && day > 20)) 106 else if (day == 2 || ((day % 10) == 2 && day > 20))
122 suf = "nd"; 107 suf = "nd";
123 else if (day == 3 || ((day % 10) == 3 && day > 20)) 108 else if (day == 3 || ((day % 10) == 3 && day > 20))
124 suf = "rd"; 109 suf = "rd";
125 else 110 else
126 suf = "th"; 111 suf = "th";
127 sprintf (errmsg, "The %d%s Day of the %s, Year %d", day, suf, month_name[tod.month], tod.year + 1);
128 new_draw_info (NDI_UNIQUE, 0, op, errmsg);
129 112
130 sprintf (errmsg, "Time of Year: %s", season_name[tod.season]); 113 snprintf (todmsg, sizeof (todmsg),
114 "It is %d minute%s past %d o'clock %s, on the Day of %s,\n"
115 "the %d%s Day of the Month of %s, Year %d.\n"
116 "It is the Season of %s.",
117
118 tod.minute + 1,
119 (tod.minute + 1 < 2) ? "" : "s",
120 (tod.hour + 13) % 14 + 1,
121 (tod.hour >= 14 ? "pm" : "am"),
122 weekdays[tod.dayofweek],
123
124 day, suf, month_name[tod.month], tod.year + 1,
125
126 season_name[tod.season]);
127
131 new_draw_info (NDI_UNIQUE, 0, op, errmsg); 128 new_draw_info (NDI_UNIQUE, 0, op, todmsg);
132} 129}
133 130

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines