forked from Warzone2100/warzone2100
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheffects.cpp
2308 lines (2026 loc) · 62.6 KB
/
effects.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
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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This file is part of Warzone 2100.
Copyright (C) 1999-2004 Eidos Interactive
Copyright (C) 2005-2019 Warzone 2100 Project
Warzone 2100 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Warzone 2100 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 License for more details.
You should have received a copy of the GNU General Public License
along with Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
Spot FX code - will handle every miscellaneous imd render and update for temporary
entities except projectiles.
Handles stuff like
- Smoke sprites on the card.
- Explosions
- Building body kit - flashing lights etc etc
- Construction graphics
- Gravitons
- Dust
- Blood
It's now PSX friendly in that there's no floats
************************************************************
* STILL NEED TO REMOVE SOME MAGIC NUMBERS INTO #DEFINES!!! *
************************************************************
*/
#include "lib/framework/wzapp.h"
#include "lib/framework/wzconfig.h"
#include "lib/framework/frameresource.h"
#include "lib/framework/input.h"
#include "lib/framework/math_ext.h"
#include "lib/ivis_opengl/ivisdef.h"
#include "lib/ivis_opengl/pietypes.h"
#include "lib/framework/fixedpoint.h"
#include "lib/ivis_opengl/piepalette.h"
#include "lib/ivis_opengl/piestate.h"
#include "lib/ivis_opengl/piematrix.h"
#include "lib/ivis_opengl/piemode.h"
#include "lib/ivis_opengl/imd.h"
#include "lib/gamelib/gtime.h"
#include "lib/sound/audio.h"
#include "lib/sound/audio_id.h"
#include "display3d.h"
#include "map.h"
#include "bucket3d.h"
#include "effects.h"
#include "miscimd.h"
#include "lighting.h"
#include "console.h"
#include "loop.h"
#include "multiplay.h"
#include "component.h"
#ifndef GLM_ENABLE_EXPERIMENTAL
#define GLM_ENABLE_EXPERIMENTAL
#endif
#include <glm/gtx/transform.hpp>
#define GRAVITON_GRAVITY ((float)-800)
#define EFFECT_X_FLIP 0x1
#define EFFECT_Y_FLIP 0x2
#define EFFECT_CYCLIC 0x4
#define EFFECT_ESSENTIAL 0x8
#define EFFECT_FACING 0x10
#define EFFECT_SCALED 0x20
#define EFFECT_LIT 0x40
#define TEST_FLIPPED_X(x) (x->control & EFFECT_X_FLIP)
#define TEST_FLIPPED_Y(x) (x->control & EFFECT_Y_FLIP)
#define TEST_ESSENTIAL(x) (x->control & EFFECT_ESSENTIAL)
#define TEST_FACING(x) (x->control & EFFECT_FACING)
#define TEST_CYCLIC(x) (x->control & EFFECT_CYCLIC)
#define TEST_SCALED(x) (x->control & EFFECT_SCALED)
#define TEST_LIT(x) (x->control & EFFECT_LIT)
#define SET_FLIPPED_X(x) ((x->control) = (UBYTE)(x->control | EFFECT_X_FLIP))
#define SET_FLIPPED_Y(x) ((x->control) = (UBYTE)(x->control | EFFECT_Y_FLIP))
#define SET_ESSENTIAL(x) ((x->control) = (UBYTE)(x->control | EFFECT_ESSENTIAL))
#define SET_FACING(x) ((x->control) = (UBYTE)(x->control | EFFECT_FACING))
#define SET_CYCLIC(x) ((x->control) = (UBYTE)(x->control | EFFECT_CYCLIC))
#define SET_SCALED(x) ((x->control) = (UBYTE)(x->control | EFFECT_SCALED))
#define SET_LIT(x) ((x->control) = (UBYTE)(x->control | EFFECT_LIT))
#define NORMAL_SMOKE_LIFESPAN (6000 + rand()%3000)
#define SMALL_SMOKE_LIFESPAN (3000 + rand()%3000)
#define TRAIL_SMOKE_LIFESPAN (1200)
#define CONSTRUCTION_LIFESPAN (5000)
#define SMOKE_FRAME_DELAY (40 + rand()%30)
#define EXPLOSION_FRAME_DELAY (25 + rand()%40)
#define EXPLOSION_TESLA_FRAME_DELAY (65)
#define EXPLOSION_PLASMA_FRAME_DELAY (45)
#define BLOOD_FRAME_DELAY (150)
#define DESTRUCTION_FRAME_DELAY (200)
#define TESLA_SPEED (170)// + (30 - rand()%60))
#define TESLA_SIZE (100)// + (20 - rand()%40))
#define GRAVITON_FRAME_DELAY (100 + rand()%50)
#define GRAVITON_BLOOD_DELAY (200 + rand()%100)
#define CONSTRUCTION_FRAME_DELAY (40 + rand()%30)
#define EXPLOSION_SIZE (110+(30-rand()%60))
#define BLOOD_SIZE (100+(30-rand()%60))
#define BLOOD_FALL_SPEED (-(20+rand()%20))
#define GRAVITON_INIT_VEL_X (float)(200 - rand() % 300)
#define GRAVITON_INIT_VEL_Z (float)(200 - rand() % 300)
#define GRAVITON_INIT_VEL_Y (float)(300 + rand() % 100)
#define GIBLET_INIT_VEL_X (float)(50 - rand() % 100)
#define GIBLET_INIT_VEL_Z (float)(50 - rand() % 100)
#define GIBLET_INIT_VEL_Y 12.f
#define DROID_DESTRUCTION_DURATION (3*GAME_TICKS_PER_SEC/2) // 1.5 seconds
#define STRUCTURE_DESTRUCTION_DURATION ((7*GAME_TICKS_PER_SEC)/2) // 3.5 seconds
#define EFFECT_EXPLOSION_ADDITIVE 164
#define EFFECT_PLASMA_ADDITIVE 224
#define EFFECT_SMOKE_TRANSPARENCY 130
#define EFFECT_STEAM_TRANSPARENCY 128
#define EFFECT_BLOOD_TRANSPARENCY 128
#define EFFECT_DROID_DIVISION 101
#define EFFECT_STRUCTURE_DIVISION 103
#define DROID_UPDATE_INTERVAL 500
#define STRUCTURE_UPDATE_INTERVAL 1250
#define BASE_FLAME_SIZE 80
#define BASE_LASER_SIZE 10
#define BASE_PLASMA_SIZE 0
#define DISCOVERY_SIZE 60
#define FLARE_SIZE 100
#define SHOCKWAVE_SPEED (GAME_TICKS_PER_SEC)
#define MAX_SHOCKWAVE_SIZE 500
static std::list<EFFECT *> activeList;
/* Tick counts for updates on a particular interval */
static UDWORD lastUpdateStructures[EFFECT_STRUCTURE_DIVISION];
static UDWORD auxVar; // dirty filthy hack - don't look for what this does.... //FIXME
static UDWORD auxVarSec; // dirty filthy hack - don't look for what this does.... //FIXME
static UDWORD specifiedSize;
static UDWORD ellSpec;
static uint8_t EffectForPlayer = 0;
// ----------------------------------------------------------------------------------------
/* PROTOTYPES */
// ----------------------------------------------------------------------------------------
// ---- Update functions - every group type of effect has one of these */
static bool updateWaypoint(EFFECT *psEffect);
static bool updateExplosion(EFFECT *psEffect);
static bool updatePolySmoke(EFFECT *psEffect);
static bool updateGraviton(EFFECT *psEffect);
static bool updateConstruction(EFFECT *psEffect);
static bool updateBlood(EFFECT *psEffect);
static bool updateDestruction(EFFECT *psEffect);
static bool updateFire(EFFECT *psEffect);
static bool updateSatLaser(EFFECT *psEffect);
static bool updateFirework(EFFECT *psEffect);
static bool updateEffect(EFFECT *psEffect); // MASTER function
// ----------------------------------------------------------------------------------------
// ---- The render functions - every group type of effect has a distinct one
static void renderExplosionEffect(const EFFECT *psEffect, const glm::mat4 &viewMatrix);
static void renderSmokeEffect(const EFFECT *psEffect, const glm::mat4 &viewMatrix);
static void renderGravitonEffect(const EFFECT *psEffect, const glm::mat4 &viewMatrix);
static void renderConstructionEffect(const EFFECT *psEffect, const glm::mat4 &viewMatrix);
static void renderWaypointEffect(const EFFECT *psEffect, const glm::mat4 &viewMatrix);
static void renderBloodEffect(const EFFECT *psEffect, const glm::mat4 &viewMatrix);
static void renderDestructionEffect(const EFFECT *psEffect, const glm::mat4 &viewMatrix);
static void renderFirework(const EFFECT *psEffect, const glm::mat4 &viewMatrix);
static glm::mat4 positionEffect(const EFFECT *psEffect);
/* There is no render destruction effect! */
// ----------------------------------------------------------------------------------------
// ---- The set up functions - every type has one
static void effectSetupSmoke(EFFECT *psEffect);
static void effectSetupGraviton(EFFECT *psEffect);
static void effectSetupExplosion(EFFECT *psEffect);
static void effectSetupConstruction(EFFECT *psEffect);
static void effectSetupWayPoint(EFFECT *psEffect);
static void effectSetupBlood(EFFECT *psEffect);
static void effectSetupDestruction(EFFECT *psEffect);
static void effectSetupFire(EFFECT *psEffect);
static void effectSetupSatLaser(EFFECT *psEffect);
static void effectSetupFirework(EFFECT *psEffect);
static void effectStructureUpdates();
static UDWORD effectGetNumFrames(EFFECT *psEffect);
void shutdownEffectsSystem()
{
for (auto eff : activeList)
{
delete eff;
}
activeList.clear();
}
/*!
* Initialise effects system
*/
void initEffectsSystem()
{
shutdownEffectsSystem();
}
static glm::mat4 positionEffect(const EFFECT *psEffect)
{
/* Establish world position */
glm::vec3 dv(
psEffect->position.x - player.p.x,
psEffect->position.y,
-(psEffect->position.z - player.p.z)
);
return glm::translate(dv);
}
void effectSetLandLightSpec(LAND_LIGHT_SPEC spec)
{
ellSpec = spec;
}
void effectSetSize(UDWORD size)
{
specifiedSize = size;
}
void addMultiEffect(const Vector3i *basePos, Vector3i *scatter, EFFECT_GROUP group,
EFFECT_TYPE type, bool specified, iIMDShape *imd, unsigned int number, bool lit, unsigned int size, unsigned effectTime)
{
if (number == 0)
{
return;
}
/* Set up the scaling for specified ones */
specifiedSize = size;
/* If there's only one, make sure it's in the centre */
if (number == 1)
{
addEffect(basePos, group, type, specified, imd, lit, effectTime);
}
else
{
unsigned int i;
/* Fix for jim */
*scatter = *scatter / 10;
/* There are multiple effects - so scatter them around according to parameter */
for (i = 0; i < number; i++)
{
// This scatters in a cube - is there a good reason for that, or just legacy?
Vector3i scatPos = *basePos + *scatter - Vector3i(rand() % (scatter->x * 2 + 1),
rand() % (scatter->y * 2 + 1),
rand() % (scatter->z * 2 + 1)
);
addEffect(&scatPos, group, type, specified, imd, lit, effectTime);
}
}
}
// When we need to set the effect for the player's color
void SetEffectForPlayer(uint8_t player)
{
ASSERT(player < MAX_PLAYERS, "player is set to a invalid number of %d", (int) player);
EffectForPlayer = getPlayerColour(player);
}
void addEffect(const Vector3i *pos, EFFECT_GROUP group, EFFECT_TYPE type, bool specified, iIMDShape *imd, int lit)
{
return addEffect(pos, group, type, specified, imd, lit, graphicsTime);
}
void addEffect(const Vector3i *pos, EFFECT_GROUP group, EFFECT_TYPE type, bool specified, iIMDShape *imd, int lit, unsigned effectTime)
{
if (gamePaused())
{
return;
}
EFFECT *psEffect = new EFFECT();
/* Reset control bits */
psEffect->control = 0;
/* Store away it's position - into FRACTS */
psEffect->position.x = pos->x;
psEffect->position.y = pos->y;
psEffect->position.z = pos->z;
/* Now, note group and type */
psEffect->group = group;
psEffect->type = type;
// and if the effect needs the player's color for certain things
psEffect->player = EffectForPlayer;
SetEffectForPlayer(0); // reset it
/* Set when it entered the world */
psEffect->birthTime = psEffect->lastFrame = effectTime;
if (group == EFFECT_GRAVITON && (type == GRAVITON_TYPE_GIBLET || type == GRAVITON_TYPE_EMITTING_DR))
{
psEffect->frameNumber = lit;
}
else
{
/* Starts off on frame zero */
psEffect->frameNumber = 0;
}
/*
See what kind of effect it is - the add function is different for each,
although some things are shared
*/
psEffect->imd = nullptr;
if (lit)
{
SET_LIT(psEffect);
}
if (specified)
{
/* We're specifying what the imd is - override */
psEffect->imd = imd;
psEffect->size = specifiedSize;
}
/* Do all the effect type specific stuff */
switch (group)
{
case EFFECT_SMOKE:
effectSetupSmoke(psEffect);
break;
case EFFECT_GRAVITON:
effectSetupGraviton(psEffect);
break;
case EFFECT_EXPLOSION:
effectSetupExplosion(psEffect);
break;
case EFFECT_CONSTRUCTION:
effectSetupConstruction(psEffect);
break;
case EFFECT_WAYPOINT:
effectSetupWayPoint(psEffect);
break;
case EFFECT_BLOOD:
effectSetupBlood(psEffect);
break;
case EFFECT_DESTRUCTION:
effectSetupDestruction(psEffect);
break;
case EFFECT_FIRE:
effectSetupFire(psEffect);
break;
case EFFECT_SAT_LASER:
effectSetupSatLaser(psEffect);
break;
case EFFECT_FIREWORK:
effectSetupFirework(psEffect);
break;
case EFFECT_FREED:
ASSERT(false, "Weirdy group type for an effect");
break;
}
/* As of yet, it hasn't bounced (or whatever)... */
if (type != EXPLOSION_TYPE_LAND_LIGHT)
{
psEffect->specific = 0;
}
ASSERT(psEffect->imd != nullptr || group == EFFECT_DESTRUCTION || group == EFFECT_FIRE || group == EFFECT_SAT_LASER, "null effect imd");
activeList.push_back(psEffect);
}
/* Calls all the update functions for each different currently active effect */
void processEffects(const glm::mat4 &viewMatrix)
{
for (auto it = activeList.begin(); it != activeList.end(); )
{
EFFECT *psEffect = *it;
if (psEffect->birthTime <= graphicsTime) // Don't process, if it doesn't exist yet
{
if (!updateEffect(psEffect))
{
delete psEffect;
it = activeList.erase(it);
continue;
}
if (psEffect->group != EFFECT_FREED && clipXY(psEffect->position.x, psEffect->position.z))
{
bucketAddTypeToList(RENDER_EFFECT, psEffect, viewMatrix);
}
}
++it;
}
/* Add any structure effects */
effectStructureUpdates();
}
/* The general update function for all effects - calls a specific one for each. Returns false if effect should be deleted. */
static bool updateEffect(EFFECT *psEffect)
{
/* What type of effect are we dealing with? */
switch (psEffect->group)
{
case EFFECT_EXPLOSION:
return updateExplosion(psEffect);
case EFFECT_WAYPOINT:
if (!gamePaused())
{
return updateWaypoint(psEffect);
}
return true;
case EFFECT_CONSTRUCTION:
if (!gamePaused())
{
return updateConstruction(psEffect);
}
return true;
case EFFECT_SMOKE:
if (!gamePaused())
{
return updatePolySmoke(psEffect);
}
return true;
case EFFECT_GRAVITON:
if (!gamePaused())
{
return updateGraviton(psEffect);
}
return true;
case EFFECT_BLOOD:
if (!gamePaused())
{
return updateBlood(psEffect);
}
return true;
case EFFECT_DESTRUCTION:
if (!gamePaused())
{
return updateDestruction(psEffect);
}
return true;
case EFFECT_FIRE:
if (!gamePaused())
{
return updateFire(psEffect);
}
return true;
case EFFECT_SAT_LASER:
if (!gamePaused())
{
return updateSatLaser(psEffect);
}
return true;
case EFFECT_FIREWORK:
if (!gamePaused())
{
return updateFirework(psEffect);
}
return true;
case EFFECT_FREED:
break;
}
debug(LOG_ERROR, "Weirdy class of effect passed to updateEffect");
abort();
}
// ----------------------------------------------------------------------------------------
// ALL THE UPDATE FUNCTIONS
// ----------------------------------------------------------------------------------------
/** Update the waypoint effects.*/
static bool updateWaypoint(EFFECT *psEffect)
{
if (!(keyDown(KEY_LCTRL) || keyDown(KEY_RCTRL) || keyDown(KEY_LSHIFT) || keyDown(KEY_RSHIFT)))
{
return false;
}
return true;
}
static bool updateFirework(EFFECT *psEffect)
{
UDWORD height;
UDWORD xDif, yDif, radius, val;
Vector3i dv;
SDWORD dif;
UDWORD drop;
/* Move it */
psEffect->position.x += graphicsTimeAdjustedIncrement(psEffect->velocity.x);
psEffect->position.y += graphicsTimeAdjustedIncrement(psEffect->velocity.y);
psEffect->position.z += graphicsTimeAdjustedIncrement(psEffect->velocity.z);
if (psEffect->type == FIREWORK_TYPE_LAUNCHER)
{
height = psEffect->position.y;
if (height > psEffect->size)
{
dv.x = psEffect->position.x;
dv.z = psEffect->position.z;
dv.y = psEffect->position.y + (psEffect->radius / 2);
addEffect(&dv, EFFECT_EXPLOSION, EXPLOSION_TYPE_MEDIUM, false, nullptr, 0);
audio_PlayStaticTrack(psEffect->position.x, psEffect->position.z, ID_SOUND_EXPLOSION);
for (dif = 0; dif < (psEffect->radius * 2); dif += 20)
{
if (dif < psEffect->radius)
{
drop = psEffect->radius - dif;
}
else
{
drop = dif - psEffect->radius;
}
radius = (UDWORD)sqrtf(psEffect->radius * psEffect->radius - drop * drop);
//val = getStaticTimeValueRange(720,360); // grab an angle - 4 seconds cyclic
for (val = 0; val <= 180; val += 20)
{
xDif = iSinR(DEG(val), radius);
yDif = iCosR(DEG(val), radius);
dv.x = psEffect->position.x + xDif;
dv.z = psEffect->position.z + yDif;
dv.y = psEffect->position.y + dif;
effectGiveAuxVar(100);
addEffect(&dv, EFFECT_FIREWORK, FIREWORK_TYPE_STARBURST, false, nullptr, 0);
dv.x = psEffect->position.x - xDif;
dv.z = psEffect->position.z - yDif;
dv.y = psEffect->position.y + dif;
effectGiveAuxVar(100);
addEffect(&dv, EFFECT_FIREWORK, FIREWORK_TYPE_STARBURST, false, nullptr, 0);
dv.x = psEffect->position.x + xDif;
dv.z = psEffect->position.z - yDif;
dv.y = psEffect->position.y + dif;
effectGiveAuxVar(100);
addEffect(&dv, EFFECT_FIREWORK, FIREWORK_TYPE_STARBURST, false, nullptr, 0);
dv.x = psEffect->position.x - xDif;
dv.z = psEffect->position.z + yDif;
dv.y = psEffect->position.y + dif;
effectGiveAuxVar(100);
addEffect(&dv, EFFECT_FIREWORK, FIREWORK_TYPE_STARBURST, false, nullptr, 0);
}
}
return false;
}
else
{
/* Add an effect at the firework's position */
dv.x = psEffect->position.x;
dv.y = psEffect->position.y;
dv.z = psEffect->position.z;
/* Add a trail graphic */
addEffect(&dv, EFFECT_SMOKE, SMOKE_TYPE_TRAIL, false, nullptr, 0);
}
}
else // must be a startburst
{
/* Time to update the frame number on the smoke sprite */
if (graphicsTime - psEffect->lastFrame > psEffect->frameDelay)
{
/* Store away last frame change time */
psEffect->lastFrame = graphicsTime;
/* Are we on the last frame? */
if (++psEffect->frameNumber >= effectGetNumFrames(psEffect))
{
/* Does the anim wrap around? */
if (TEST_CYCLIC(psEffect))
{
psEffect->frameNumber = 0;
}
else
{
return false; /* Kill it off */
}
}
}
/* If it doesn't get killed by frame number, then by age */
if (TEST_CYCLIC(psEffect))
{
/* Has it overstayed it's welcome? */
if (graphicsTime - psEffect->birthTime > psEffect->lifeSpan)
{
return false; /* Kill it */
}
}
}
return true;
}
static bool updateSatLaser(EFFECT *psEffect)
{
Vector3i dv;
UDWORD val;
UDWORD radius;
UDWORD xDif, yDif;
UDWORD i;
UDWORD startHeight, endHeight;
UDWORD xPos, yPos;
// Do these here because they are used by the lighting code below this if
xPos = psEffect->position.x;
startHeight = psEffect->position.y;
endHeight = startHeight + 1064;
yPos = psEffect->position.z;
if (psEffect->baseScale)
{
psEffect->baseScale = 0;
/* Add some big explosions....! */
for (i = 0; i < 16; i++)
{
dv.x = xPos + (200 - rand() % 400);
dv.z = yPos + (200 - rand() % 400);
dv.y = startHeight + rand() % 100;
addEffect(&dv, EFFECT_EXPLOSION, EXPLOSION_TYPE_MEDIUM, false, nullptr, 0);
}
/* Add a sound effect */
audio_PlayStaticTrack(psEffect->position.x, psEffect->position.z, ID_SOUND_EXPLOSION);
/* Add a shockwave */
dv.x = xPos;
dv.z = yPos;
dv.y = startHeight + SHOCK_WAVE_HEIGHT;
addEffect(&dv, EFFECT_EXPLOSION, EXPLOSION_TYPE_SHOCKWAVE, false, nullptr, 0);
/* Now, add the column of light */
for (i = startHeight; i < endHeight; i += 56)
{
radius = 80;
/* Add 36 around in a circle..! */
for (val = 0; val <= 180; val += 30)
{
xDif = iSinR(DEG(val), radius);
yDif = iCosR(DEG(val), radius);
dv.x = xPos + xDif + i / 64;
dv.z = yPos + yDif;
dv.y = startHeight + i;
effectGiveAuxVar(100);
addEffect(&dv, EFFECT_EXPLOSION, EXPLOSION_TYPE_MEDIUM, false, nullptr, 0);
dv.x = xPos - xDif + i / 64;
dv.z = yPos - yDif;
dv.y = startHeight + i;
effectGiveAuxVar(100);
addEffect(&dv, EFFECT_EXPLOSION, EXPLOSION_TYPE_MEDIUM, false, nullptr, 0);
dv.x = xPos + xDif + i / 64;
dv.z = yPos - yDif;
dv.y = startHeight + i;
effectGiveAuxVar(100);
addEffect(&dv, EFFECT_EXPLOSION, EXPLOSION_TYPE_MEDIUM, false, nullptr, 0);
dv.x = xPos - xDif + i / 64;
dv.z = yPos + yDif;
dv.y = startHeight + i;
effectGiveAuxVar(100);
addEffect(&dv, EFFECT_EXPLOSION, EXPLOSION_TYPE_MEDIUM, false, nullptr, 0);
}
}
}
if (graphicsTime - psEffect->birthTime < 1000)
{
LIGHT light;
light.position = Vector3f(xPos, startHeight, yPos);
light.range = 800;
light.colour = pal_Colour(0, 0, 255);
processLight(&light);
return true;
}
else
{
return false;
}
}
/** The update function for the explosions */
static bool updateExplosion(EFFECT *psEffect)
{
if (TEST_LIT(psEffect))
{
UDWORD percent;
LIGHT light;
if (psEffect->lifeSpan)
{
percent = PERCENT(graphicsTime - psEffect->birthTime, psEffect->lifeSpan);
if (percent > 100)
{
percent = 100;
}
else if (percent > 50)
{
percent = 100 - percent;
}
}
else
{
percent = 100;
}
UDWORD range = percent;
light.position = psEffect->position;
light.range = (3 * range) / 2;
light.colour = pal_Colour(255, 0, 0);
processLight(&light);
}
if (psEffect->type == EXPLOSION_TYPE_SHOCKWAVE)
{
LIGHT light;
const float scaling = (float)psEffect->size / (float)MAX_SHOCKWAVE_SIZE;
psEffect->size += graphicsTimeAdjustedIncrement(SHOCKWAVE_SPEED);
psEffect->frameNumber = scaling * effectGetNumFrames(psEffect);
light.position = psEffect->position;
light.range = psEffect->size + 200;
light.colour = pal_Colour(255, 255, 0);
processLight(&light);
if (psEffect->size > MAX_SHOCKWAVE_SIZE || light.range > 600)
{
return false; /* Kill it off */
}
}
/* Time to update the frame number on the explosion */
else while (graphicsTime - psEffect->lastFrame > psEffect->frameDelay)
{
psEffect->lastFrame += psEffect->frameDelay;
/* Are we on the last frame? */
if (++psEffect->frameNumber >= effectGetNumFrames(psEffect))
{
if (psEffect->type != EXPLOSION_TYPE_LAND_LIGHT)
{
return false; /* Kill it off */
}
else
{
psEffect->frameNumber = 0;
}
}
}
if (!gamePaused())
{
/* Tesla explosions are the only ones that rise, or indeed move */
if (psEffect->type == EXPLOSION_TYPE_TESLA)
{
psEffect->position.y += graphicsTimeAdjustedIncrement(psEffect->velocity.y);
}
}
return true;
}
/** The update function for blood */
static bool updateBlood(EFFECT *psEffect)
{
/* Time to update the frame number on the blood */
if (graphicsTime - psEffect->lastFrame > psEffect->frameDelay)
{
psEffect->lastFrame = graphicsTime;
/* Are we on the last frame? */
if (++psEffect->frameNumber >= effectGetNumFrames(psEffect))
{
return false; /* Kill it off */
}
}
/* Move it about in the world */
psEffect->position.x += graphicsTimeAdjustedIncrement(psEffect->velocity.x);
psEffect->position.y += graphicsTimeAdjustedIncrement(psEffect->velocity.y);
psEffect->position.z += graphicsTimeAdjustedIncrement(psEffect->velocity.z);
return true;
}
/** Processes all the drifting smoke. Handles the smoke puffing out the factory as well. */
static bool updatePolySmoke(EFFECT *psEffect)
{
/* Time to update the frame number on the smoke sprite */
while (graphicsTime - psEffect->lastFrame > psEffect->frameDelay)
{
/* Store away last frame change time */
psEffect->lastFrame += psEffect->frameDelay;
/* Are we on the last frame? */
if (++psEffect->frameNumber >= effectGetNumFrames(psEffect))
{
/* Does the anim wrap around? */
if (TEST_CYCLIC(psEffect))
{
/* Does it change drift direction? */
if (psEffect->type == SMOKE_TYPE_DRIFTING)
{
/* Make it change direction */
psEffect->velocity.x = (float)(rand() % 20);
psEffect->velocity.z = (float)(10 - rand() % 20);
psEffect->velocity.y = (float)(10 + rand() % 20);
}
/* Reset the frame */
psEffect->frameNumber = 0;
}
else
{
/* Kill it off */
return false;
}
}
}
/* Update position */
psEffect->position.x += graphicsTimeAdjustedIncrement(psEffect->velocity.x);
psEffect->position.y += graphicsTimeAdjustedIncrement(psEffect->velocity.y);
psEffect->position.z += graphicsTimeAdjustedIncrement(psEffect->velocity.z);
/* If it doesn't get killed by frame number, then by age */
if (TEST_CYCLIC(psEffect))
{
/* Has it overstayed it's welcome? */
if (graphicsTime - psEffect->birthTime > psEffect->lifeSpan)
{
return false; /* Kill it */
}
}
return true;
}
/**
Gravitons just fly up for a bit and then drop down and are
killed off when they hit the ground
*/
static bool updateGraviton(EFFECT *psEffect)
{
float accel;
Vector3i dv;
MAPTILE *psTile;
LIGHT light;
if (psEffect->type != GRAVITON_TYPE_GIBLET)
{
light.position = psEffect->position;
light.range = 128;
light.colour = pal_Colour(255, 255, 0);
processLight(&light);
}
if (gamePaused())
{
/* Only update the lights if it's paused */
return true;
}
/* Move it about in the world */
psEffect->position.x += graphicsTimeAdjustedIncrement(psEffect->velocity.x);
psEffect->position.y += graphicsTimeAdjustedIncrement(psEffect->velocity.y);
psEffect->position.z += graphicsTimeAdjustedIncrement(psEffect->velocity.z);
/* If it's bounced/drifted off the map then kill it */
if (map_coord(psEffect->position.x) >= mapWidth || map_coord(psEffect->position.z) >= mapHeight)
{
return false;
}
int groundHeight = map_Height(psEffect->position.x, psEffect->position.z);
/* If it's going up and it's still under the landscape, then remove it... */
if (psEffect->position.y < groundHeight && psEffect->velocity.y > 0)
{
return false;
}
/* Does it emit a trail? And is it high enough? */
if ((psEffect->type == GRAVITON_TYPE_EMITTING_DR)
|| ((psEffect->type == GRAVITON_TYPE_EMITTING_ST)
&& (psEffect->position.y > (groundHeight + 10))))
{
/* Time to add another trail 'thing'? */
if (graphicsTime > psEffect->lastFrame + psEffect->frameDelay)
{
/* Store away last update */
psEffect->lastFrame = graphicsTime;
/* Add an effect at the gravitons's position */
dv.x = psEffect->position.x;
dv.y = psEffect->position.y;
dv.z = psEffect->position.z;
/* Add a trail graphic */
addEffect(&dv, EFFECT_SMOKE, SMOKE_TYPE_TRAIL, false, nullptr, 0);
}
}
else if (psEffect->type == GRAVITON_TYPE_GIBLET && (psEffect->position.y > (groundHeight + 5)))
{
/* Time to add another trail 'thing'? */
if (graphicsTime > psEffect->lastFrame + psEffect->frameDelay)
{
/* Store away last update */
psEffect->lastFrame = graphicsTime;
/* Add an effect at the gravitons's position */
dv.x = psEffect->position.x;
dv.y = psEffect->position.y;
dv.z = psEffect->position.z;
addEffect(&dv, EFFECT_BLOOD, BLOOD_TYPE_NORMAL, false, nullptr, 0);
}
}
/* Spin it round a bit */
psEffect->rotation.x += graphicsTimeAdjustedIncrement(psEffect->spin.x);
psEffect->rotation.y += graphicsTimeAdjustedIncrement(psEffect->spin.y);
psEffect->rotation.z += graphicsTimeAdjustedIncrement(psEffect->spin.z);
/* Update velocity (and retarding of descent) according to present frame rate */
accel = graphicsTimeAdjustedIncrement(GRAVITON_GRAVITY);
psEffect->velocity.y += accel;
/* If it's bounced/drifted off the map then kill it */
if ((int)psEffect->position.x <= TILE_UNITS || (int)psEffect->position.z <= TILE_UNITS)
{
return false;
}
/* Are we below it? - Hit the ground? */
if ((int)psEffect->position.y < (int)groundHeight)
{
psTile = mapTile(map_coord(psEffect->position.x), map_coord(psEffect->position.z));
if (terrainType(psTile) == TER_WATER)
{
return false;
}
else if ((int)psEffect->velocity.y < 0) // Are we falling - rather than rising?
{
/* Has it sufficient energy to keep bouncing? */
if (abs(psEffect->velocity.y) > 16 && psEffect->specific <= 2)
{
psEffect->specific++;
/* Half it's velocity */
psEffect->velocity.y /= (float)(-2); // only y gets flipped
/* Set it at ground level - may have gone through */
psEffect->position.y = (float)groundHeight;
}
else
{
/* Giblets don't blow up when they hit the ground! */
if (psEffect->type != GRAVITON_TYPE_GIBLET)
{
/* Remove the graviton and add an explosion */
dv.x = psEffect->position.x;
dv.y = psEffect->position.y + 10;
dv.z = psEffect->position.z;
addEffect(&dv, EFFECT_EXPLOSION, EXPLOSION_TYPE_VERY_SMALL, false, nullptr, 0);
}
return false;
}
}
}
return true;
}
/** This isn't really an on-screen effect itself - it just spawns other ones.... */
static bool updateDestruction(EFFECT *psEffect)
{
Vector3i pos;
UDWORD effectType;