-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathictime.cpp
216 lines (189 loc) · 7.18 KB
/
ictime.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/**************************************************************************/
// ictime.cpp - IC Time system - Kalahn & Kerenos
/***************************************************************************
* The Dawn of Time v1.69r (c)1997-2004 Michael Garratt *
* >> A number of people have contributed to the Dawn codebase, with the *
* majority of code written by Michael Garratt - www.dawnoftime.org *
* >> To use this source code, you must fully comply with the dawn license *
* in licenses.txt... In particular, you may not remove this copyright *
* notice. *
**************************************************************************/
#include "include.h"
#include "ictime.h"
/**************************************************************************/
void init_weather();
/***************************************************************************/
const struct season_type season_table [WEATHER_SEASON_MAX] =
{
{ WEATHER_SEASON_WINTER, "winter" },
{ WEATHER_SEASON_SPRING, "spring" },
{ WEATHER_SEASON_SUMMER, "summer" },
{ WEATHER_SEASON_AUTUMN, "autumn" }
};
/**************************************************************************/
void set_ictime()
{
time_info.minute = (int)current_time/ICTIME_IRLSECS_PER_MINUTE;
time_info.minute%= ICTIME_MINUTES_PER_HOUR;
time_info.hour = (int)current_time/ICTIME_IRLSECS_PER_HOUR;
time_info.hour%= ICTIME_HOURS_PER_DAY;
time_info.day = (int)current_time/ICTIME_IRLSECS_PER_DAY;
time_info.day%= ICTIME_DAYS_PER_MONTH;
time_info.month = (int)current_time/ICTIME_IRLSECS_PER_MONTH;
time_info.month%= ICTIME_MONTHS_PER_YEAR;
time_info.year = (int)current_time/ICTIME_IRLSECS_PER_YEAR;
time_info.year+=ICTIME_YEAR_OFFSET; // calibrate year for dawns ic time
char buf[MIL];
sprintf(buf,"%s",(char*)ctime((time_t*)¤t_time));
buf[str_len(buf)-1]='\0';
logf("set_ictime(): current_time=%s (%d)", buf, (int)current_time);
logf("- IC results: min=%d, hour=%d, day=%d, month=%d, year=%d",
time_info.minute,
time_info.hour,
time_info.day,
time_info.month,
time_info.year);
/* { // log it to confirm it is working correctly
char tbuf[MSL];
sprintf(tbuf, "%s (%d) -> %2d:%02d %2d/%02d/%4d",
buf,
(int)current_time,
time_info.hour,
time_info.minute,
time_info.day,
time_info.month,
time_info.year);
append_string_to_file( "ictime.log", tbuf);
}
*/
}
/**************************************************************************/
void do_setage(char_data *ch, char *argument)
{
if (IS_NPC(ch)){
ch->println("Players only.");
return;
}
// Check if they're being ordered to do this
if ( IS_SET( ch->dyn, DYN_IS_BEING_ORDERED ))
{
if ( ch->master )
ch->master->println("Not going to happen.");
return;
}
if(ch->pcdata->birthdate && !GAMESETTING(GAMESET_ALWAYS_ALLOW_SETAGE)){
ch->println("Your age as already been set.");
return;
}
char arg[MIL], arg1[MIL];
argument = one_argument( argument, arg );
argument = one_argument( argument, arg1 );
if ( IS_NULLSTR(arg1) || str_cmp("confirm", arg1)) {
if(!codehelp(ch, "do_setage_noargument", false)){
ch->println("You can set your age once and once only using the setage command.");
ch->println(" `=Csetage <age> confirm`x." );
ch->println("`RBE WARNED: `xYou age can only be set once and it can not be changed once set.");
};
return;
}
int value=atoi(arg);
if ( value < 4 )
{
ch->println("Age must be 4 or greater.");
return;
}
if ( value > 1000 )
{
ch->println("Age must be less than 1000.");
return;
}
ch->pcdata->birthdate= current_time+ number_range(-ICTIME_IRLSECS_PER_YEAR,ICTIME_IRLSECS_PER_YEAR);
ch->pcdata->birthyear_modifier=-value;
ch->pcdata->birthyear_modifier++;
ch->pcdata->birthdate-=ICTIME_IRLSECS_PER_YEAR;
ch->println("Age set - see score to see your new age.");
}
/**************************************************************************/
char *get_ictimediff(time_t t1, time_t t2, int icyears_added_to_result)
{
static char timebuf[MSL][3];
static int index;
int dsec, icyear, icmonth, icweek, icday;
++index%=3;
// initialise working string
timebuf[index][0]=0;
dsec = abs((int)(t1-t2)); // number of IRL seconds between the 2 times
icyear = dsec/ICTIME_IRLSECS_PER_YEAR;
icyear+= icyears_added_to_result;
dsec %= ICTIME_IRLSECS_PER_YEAR;
icmonth= dsec/ICTIME_IRLSECS_PER_MONTH;
dsec %= ICTIME_IRLSECS_PER_MONTH;
icweek = dsec/ICTIME_IRLSECS_PER_WEEK;
dsec %= ICTIME_IRLSECS_PER_WEEK;
icday = dsec/ICTIME_IRLSECS_PER_DAY;
sprintf(timebuf[index],"%d year%s, %d month%s, %d week%s, %d day%s",
icyear,
(icyear!=1?"s":""),
icmonth,
(icmonth!=1?"s":""),
icweek,
(icweek!=1?"s":""),
icday,
(icday!=1?"s":""));
return(timebuf[index]);
}
/**************************************************************************/
char *get_shorticdate_from_time(time_t tt, char * format, int icyears_added_to_result)
{
static char buf[MIL];
time_info_data tm;
tm.day = (int)tt/ICTIME_IRLSECS_PER_DAY;
tm.day%= ICTIME_DAYS_PER_MONTH;
tm.month = (int)tt/ICTIME_IRLSECS_PER_MONTH;
tm.month%= ICTIME_MONTHS_PER_YEAR;
tm.year = (int)tt/ICTIME_IRLSECS_PER_YEAR;
tm.year+=ICTIME_YEAR_OFFSET+icyears_added_to_result; // calibrate year for dawns ic time
// budget system to allow for customizing the format
if(count_char(format, '%')!=3 || count_char(format, 'd')!=3){
sprintf(buf, "%d/%d/%d", tm.day+1, tm.month+1, tm.year);
}else{
sprintf(buf, format, tm.day+1, tm.month+1, tm.year);
}
return buf;
}
/**************************************************************************/
int get_birthmonth( char_data *ch )
{
int month = -1;
if ( ch->pcdata->birthdate )
{
month = (int)ch->pcdata->birthdate/ICTIME_IRLSECS_PER_MONTH;
month%= ICTIME_MONTHS_PER_YEAR;
}
return month;
}
/**************************************************************************/
void set_weather()
{
init_weather();
int sect;
for ( sect = 0; sect < SECT_MAX; sect++ )
{
if ( time_info.hour < 5 ) weather_info[sect].sunlight = SUN_DARK;
else if ( time_info.hour < 6 ) weather_info[sect].sunlight = SUN_RISE;
else if ( time_info.hour < 19 ) weather_info[sect].sunlight = SUN_LIGHT;
else if ( time_info.hour < 20 ) weather_info[sect].sunlight = SUN_SET;
else weather_info[sect].sunlight = SUN_DARK;
weather_info[sect].change = 0;
weather_info[sect].mmhg = 960;
if ( time_info.month >= 7 && time_info.month <=12 )
weather_info[sect].mmhg += number_range( 1, 50 );
else
weather_info[sect].mmhg += number_range( 20, 80 );
if ( weather_info[sect].mmhg <= 980 ) weather_info[sect].sky = SKY_LIGHTNING;
else if ( weather_info[sect].mmhg <= 1000 ) weather_info[sect].sky = SKY_RAINING;
else if ( weather_info[sect].mmhg <= 1020 ) weather_info[sect].sky = SKY_CLOUDY;
else weather_info[sect].sky = SKY_CLOUDLESS;
}
}
/**************************************************************************/