forked from DIKUNIX/dikumud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.c
217 lines (191 loc) · 3.98 KB
/
weather.c
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
217
/* ************************************************************************
* file: weather.c , Weather and time module Part of DIKUMUD *
* Usage: Performing the clock and the weather *
* Copyright (C) 1990, 1991 - see 'license.doc' for complete information. *
************************************************************************* */
#include <stdio.h>
#include <string.h>
#include "structs.h"
#include "utils.h"
#include "comm.h"
#include "handler.h"
#include "interpreter.h"
#include "db.h"
/* uses */
extern struct time_info_data time_info;
extern struct weather_data weather_info;
/* In this part. */
void weather_and_time(int mode);
void another_hour(int mode);
void weather_change(void);
/* Here comes the code */
void weather_and_time(int mode)
{
another_hour(mode);
if(mode)
weather_change();
}
void another_hour(int mode)
{
time_info.hours++;
if (mode) {
switch (time_info.hours) {
case 5 :
{
weather_info.sunlight = SUN_RISE;
send_to_outdoor("The sun rises in the east.\n\r");
break;
}
case 6 :
{
weather_info.sunlight = SUN_LIGHT;
send_to_outdoor("The day has begun.\n\r");
break;
}
case 21 :
{
weather_info.sunlight = SUN_SET;
send_to_outdoor(
"The sun slowly disappears in the west.\n\r");
break;
}
case 22 :
{
weather_info.sunlight = SUN_DARK;
send_to_outdoor("The night has begun.\n\r");
break;
}
default : break;
}
}
if (time_info.hours > 23) /* Changed by HHS due to bug ???*/
{
time_info.hours -= 24;
time_info.day++;
if (time_info.day>34)
{
time_info.day = 0;
time_info.month++;
if(time_info.month>16)
{
time_info.month = 0;
time_info.year++;
}
}
}
}
void weather_change(void)
{
int diff, change;
if((time_info.month>=9)&&(time_info.month<=16))
diff=(weather_info.pressure>985 ? -2 : 2);
else
diff=(weather_info.pressure>1015? -2 : 2);
weather_info.change += (dice(1,4)*diff+dice(2,6)-dice(2,6));
weather_info.change = MIN(weather_info.change,12);
weather_info.change = MAX(weather_info.change,-12);
weather_info.pressure += weather_info.change;
weather_info.pressure = MIN(weather_info.pressure,1040);
weather_info.pressure = MAX(weather_info.pressure,960);
change = 0;
switch(weather_info.sky){
case SKY_CLOUDLESS :
{
if (weather_info.pressure<990)
change = 1;
else if (weather_info.pressure<1010)
if(dice(1,4)==1)
change = 1;
break;
}
case SKY_CLOUDY :
{
if (weather_info.pressure<970)
change = 2;
else if (weather_info.pressure<990)
if(dice(1,4)==1)
change = 2;
else
change = 0;
else if (weather_info.pressure>1030)
if(dice(1,4)==1)
change = 3;
break;
}
case SKY_RAINING :
{
if (weather_info.pressure<970)
if(dice(1,4)==1)
change = 4;
else
change = 0;
else if (weather_info.pressure>1030)
change = 5;
else if (weather_info.pressure>1010)
if(dice(1,4)==1)
change = 5;
break;
}
case SKY_LIGHTNING :
{
if (weather_info.pressure>1010)
change = 6;
else if (weather_info.pressure>990)
if(dice(1,4)==1)
change = 6;
break;
}
default :
{
change = 0;
weather_info.sky=SKY_CLOUDLESS;
break;
}
}
switch(change){
case 0 : break;
case 1 :
{
send_to_outdoor(
"The sky is getting cloudy.\n\r");
weather_info.sky=SKY_CLOUDY;
break;
}
case 2 :
{
send_to_outdoor(
"It starts to rain.\n\r");
weather_info.sky=SKY_RAINING;
break;
}
case 3 :
{
send_to_outdoor(
"The clouds disappear.\n\r");
weather_info.sky=SKY_CLOUDLESS;
break;
}
case 4 :
{
send_to_outdoor(
"Lightning starts to show in the sky.\n\r");
weather_info.sky=SKY_LIGHTNING;
break;
}
case 5 :
{
send_to_outdoor(
"The rain stopped.\n\r");
weather_info.sky=SKY_CLOUDY;
break;
}
case 6 :
{
send_to_outdoor(
"The lightning has stopped.\n\r");
weather_info.sky=SKY_RAINING;
break;
}
default : break;
}
}