-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloud.c
457 lines (331 loc) · 9.33 KB
/
cloud.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
/*
Lacewing
Copyright (C) 2003 Linley Henzell & Captain Pork
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public Licence as published by
the Free Software Foundation; either version 2 of the Licence, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public Licence for more details.
You should have received a copy of the GNU General Public Licence
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The GPL version 2 is included in this distribution in a file called
LICENCE.TXT. Use any text editor or the TYPE command to read it.
You should be able to reach us by sending an email to
captainpork@fastmail.fm.
File: cloud.c
History:
6/10/2003 - Version 1.0 finalised
This file contains:
- functions relating to clouds and transient special effects
*/
#define ALLEGRO_NO_CLEAR_BITMAP_ALIAS
#define ALLEGRO_NO_VHLINE_ALIAS
#include "allegro.h"
#include <math.h>
#include "config.h"
#include "globvars.h"
#include "stuff.h"
#include "palette.h"
#include "sound.h"
void manage_cloud(int cl);
int move_cloud(int mc, char limited);
void destroy_cloud(int c);
void drag_cloud(int i);
void simple_cloud(int colour, int x, int y, int xs, int ys, int size);
void simple_cloud_trans(int colour, int x, int y, int xs, int ys, int size);
void place_explosion_with_smoke(int x, int y, int xs, int ys, int size, int colours [5]);
void init_clouds(void)
{
int c;
for (c = 0; c < NO_CLOUDS; c++)
{
cloud[c].type = CLOUD_NONE;
}
}
// should delta_tickrate be unsigned?
int create_cloud(int type, int x, int y, int x2, int y2,
int x_speed, int y_speed, int timer, int tickrate,
int delta_tickrate, int angle,
int status, unsigned char seed, int colours [5])
{
int c = 0;
for (c = 1; c < NO_CLOUDS; c++)
{
if (c == NO_CLOUDS - 1) return -1;
if (cloud[c].type == CLOUD_NONE) break;
}
cloud[c].type = type;
cloud[c].x = x;// + (x_speed - actor[owner].x_speed);
cloud[c].y = y;// + (y_speed - actor[owner].y_speed);
cloud[c].x2 = x2;
cloud[c].y2 = y2;
cloud[c].x_speed = x_speed;
cloud[c].y_speed = y_speed;
cloud[c].seed = seed;
cloud[c].timeout = timer;
cloud[c].tickrate= tickrate;
cloud[c].delta_tickrate= delta_tickrate;
cloud[c].status = status;
cloud[c].angle = angle;
cloud[c].colour [0] = colours [0];
cloud[c].colour [1] = colours [1];
cloud[c].colour [2] = colours [2];
cloud[c].colour [3] = colours [3];
cloud[c].colour [4] = colours [4];
return c;
}
void run_clouds(void)
{
int c;
for (c = 1; c < NO_CLOUDS; c++)
{
if (cloud[c].type != CLOUD_NONE) manage_cloud(c);
}
}
void manage_cloud(int c)
{
int passing_colours [5];
// int x_gain = 0;
// int y_gain = 0;
// char angle_change;
// if (cloud[c].timeout > 0)
// {
cloud[c].timeout -= cloud[c].tickrate;
cloud[c].tickrate += cloud[c].delta_tickrate;
// }
if (cloud[c].timeout <= 0)
{
destroy_cloud(c);
return;
}
switch(cloud[c].type)
{
case CLOUD_BURSTLET:
// place_explosion(cloud[c].x, cloud[c].y, 0, 0, , cloud[c].colours);
passing_colours [0] = cloud[c].colour [1]; // was [0]
create_cloud(CLOUD_MED_TRANS_CIRCLE,
cloud[c].x, cloud[c].y, 0, 0, 0, 0,
50 + grand(300),0,3, 0, 0, 0, passing_colours);
// passing_colours [0] = cloud[c].colour [1];
// create_cloud(CLOUD_MED_TRANS_CIRCLE,
// cloud[c].x, cloud[c].y, 0, 0, 0, 0, size,-40,15, 0, 0, 0, passing_colours);
passing_colours [0] = cloud[c].colour [2];
create_cloud(CLOUD_MED_TRANS_CIRCLE,
cloud[c].x, cloud[c].y, 0, 0, 0, 0,
50 + grand(300),0,6, 0, 0, 0, passing_colours);
break;
case CLOUD_SPAWNER:
if (cloud[c].timeout % 2 == 0)
{
int cangle = grand(ANGLE_FULL);
int cx = cloud[c].x + cos(angle_to_radians(cangle)) * grand(cloud[c].status * 100);
int cy = cloud[c].y + sin(angle_to_radians(cangle)) * grand(cloud[c].status * 100);
// create_cloud(CLOUD_MED_TRANS_CIRCLE,
// cloud[c].x, cloud[c].y, 0, 0, 0, 0,
// 50 + grand(300),0,3, 0, 0, 0, passing_colours);
place_explosion_with_smoke(
// cloud[c].x - cloud[c].status * 100 + grand(cloud[c].status * 200),
// cloud[c].y - cloud[c].status * 100 + grand(cloud[c].status * 200),
cx, cy,
0, 0, grand(cloud[c].status) + 250, cloud[c].colour);
if (cloud[c].timeout % 8 == 0)
play_sound_pos(WAV_MINEBANG, 200 + grand(200), 200, cx, cy);
}
break;
}
if (move_cloud(c, 1) == 0)
return;
drag_cloud(c);
}
void destroy_cloud(int c)
{
cloud[c].type = CLOUD_NONE;
}
int move_cloud(int c, char limited)
{
if (cloud[c].x_speed == 0 && cloud[c].y_speed == 0) return 1;
cloud[c].x2 += cloud[c].x_speed;
cloud[c].y2 += cloud[c].y_speed;
cloud[c].x += cloud[c].x_speed;
cloud[c].y += cloud[c].y_speed;
return 1;
}
void drag_cloud(int i)
{
cloud[i].x_speed *= 1 - game.drag;
cloud[i].y_speed *= 1 - game.drag;
}
void simple_cloud(int colour, int x, int y, int xs, int ys, int size)
{
int passing_colours [5];
passing_colours [0] = colour;
create_cloud(CLOUD_MED_CIRCLE,
x,
y,
0, 0,
xs,
ys,
size,-30,10, 0, 0, 0, passing_colours);
}
void simple_cloud_trans(int colour, int x, int y, int xs, int ys, int size)
{
int passing_colours [5];
passing_colours [0] = colour;
create_cloud(CLOUD_MED_TRANS_CIRCLE,
x,
y,
0, 0,
xs,
ys,
size,-30,10, 0, 0, 0, passing_colours);
}
void place_explosion(int x, int y, int xs, int ys, int size, int colours [5])
{
int passing_colours [5];
passing_colours [0] = colours [0];
create_cloud(CLOUD_MED_TRANS_CIRCLE,
x,
y,
0, 0,
xs,
ys,
size,-100,10, 0, 0, 0, passing_colours);
passing_colours [0] = colours [1];
create_cloud(CLOUD_MED_TRANS_CIRCLE,
x,
y,
0, 0,
xs,
ys,
size,-120,15, 0, 0, 0, passing_colours);
passing_colours [0] = colours [2];
create_cloud(CLOUD_MED_TRANS_CIRCLE,
x,
y,
0, 0,
xs,
ys,
size,-140,20, 0, 0, 0, passing_colours);
}
void place_explosion_with_smoke(int x, int y, int xs, int ys, int size, int colours [5])
{
int passing_colours [5];
passing_colours [0] = TRANS_GREY;
create_cloud(CLOUD_MED_TRANS_CIRCLE,
x,
y,
0, 0,
xs,
ys,
size,-30,1, 0, 0, 0, passing_colours);
passing_colours [0] = colours [0];
create_cloud(CLOUD_MED_TRANS_CIRCLE,
x,
y,
0, 0,
xs,
ys,
size,-100,10, 0, 0, 0, passing_colours);
passing_colours [0] = colours [1];
create_cloud(CLOUD_MED_TRANS_CIRCLE,
x,
y,
0, 0,
xs,
ys,
size,-105,15, 0, 0, 0, passing_colours);
passing_colours [0] = colours [2];
create_cloud(CLOUD_MED_TRANS_CIRCLE,
x,
y,
0, 0,
xs,
ys,
size,-110,20, 0, 0, 0, passing_colours);
}
void place_rocket_trail(int x, int y, int xs, int ys, int size, int colours [5])
{
int passing_colours [5];
passing_colours [0] = colours [0];
create_cloud(CLOUD_MED_TRANS_CIRCLE,
x,
y,
0, 0,
xs,
ys,
size,-6,1, 0, 0, 0, passing_colours);
passing_colours [0] = colours [1];
create_cloud(CLOUD_MED_TRANS_CIRCLE,
x,
y,
0, 0,
xs,
ys,
size,-15,6, 0, 0, 0, passing_colours);
passing_colours [0] = colours [2];
create_cloud(CLOUD_MED_TRANS_CIRCLE,
x,
y,
0, 0,
xs,
ys,
size,-20,15, 0, 0, 0, passing_colours);
}
void place_speck_burst(int x, int y, int xs, int ys, int specks, int min_timeout, int random_timeout, int scatter, int colours [5])
{
int i;
for (i = 0; i < specks; i ++)
{
create_cloud(CLOUD_SPECK,
x,
y,
0, 0,
xs + grand(scatter * 2 + 1) - scatter,
ys + grand(scatter * 2 + 1) - scatter,
min_timeout + grand(random_timeout), 1,0,0, 0, 0, colours);
}
}
void place_line_burst(int x, int y, int xs, int ys, int specks, int min_timeout, int random_timeout, int burst, int random_burst, int colours [5])
{
int i, angle, xsp, ysp, burst_speed;
for (i = 0; i < specks; i ++)
{
angle = grand(ANGLE_FULL);
burst_speed = burst + grand(burst);
xsp = xs + cos(angle_to_radians(angle)) * burst_speed;
ysp = ys + sin(angle_to_radians(angle)) * burst_speed;
x += xsp;
y += ysp;
create_cloud(CLOUD_SHRINKING_LINE,
x,
y,
0, 0,
xsp,
ysp,
(min_timeout + grand(random_timeout)) * 10, 10 + grand(6),0,angle, 0, 0, colours);
}
}
void place_burstlet_burst(int x, int y, int xs, int ys, int burstlets, int min_timeout, int random_timeout, int burst, int random_burst, int pretravel, int colours [5])
{
int i, xs2, ys2, x2, y2;
for (i = 0; i < burstlets; i ++)
{
xs2 = burst + grand(random_burst);
ys2 = burst + grand(random_burst);
if (grand(2) == 0)
xs2 *= -1;
if (grand(2) == 0)
ys2 *= -1;
xs2 += xs;
ys2 += ys;
x2 = x + xs2 * pretravel; // or it will just be masked by the main
y2 = y + ys2 * pretravel; // explosion
create_cloud(CLOUD_BURSTLET,
x2, y2, 0,0, xs2, ys2,
min_timeout + random_timeout,1,0, 0, 0, 0, colours);
}
}