forked from Warzone2100/warzone2100
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheffects.cpp
2640 lines (2268 loc) · 68.9 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-2012 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" //ivis matrix code
#include "lib/ivis_opengl/piedef.h" //ivis matrix code
#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/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 "mission.h"
#include "miscimd.h"
#include "hci.h"
#include "lighting.h"
#include "console.h"
#include "loop.h"
#include "multiplay.h"
#include "game.h"
#include "component.h"
#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 MINIMUM_IMPACT_VELOCITY (16)
#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 LIMITED_EXPLOSION_SIZE (100+(5-rand()%10))
#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 FIREWORK_EXPLODE_HEIGHT 400
#define STARBURST_RADIUS 150
#define STARBURST_DIAMETER 300
#define EFFECT_SMOKE_ADDITIVE 1
#define EFFECT_STEAM_ADDITIVE 8
#define EFFECT_WAYPOINT_ADDITIVE 32
#define EFFECT_EXPLOSION_ADDITIVE 164
#define EFFECT_PLASMA_ADDITIVE 224
#define EFFECT_SMOKE_TRANSPARENCY 130
#define EFFECT_STEAM_TRANSPARENCY 128
#define EFFECT_WAYPOINT_TRANSPARENCY 128
#define EFFECT_BLOOD_TRANSPARENCY 128
#define EFFECT_EXPLOSION_TRANSPARENCY 164
#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
/*! Number of effects in one chunk */
#define EFFECT_CHUNK_SIZE 10000
/*! A memory chunk of effects */
struct EffectChunk
{
EFFECT effects[EFFECT_CHUNK_SIZE]; //!< Chunk of effects
EffectChunk *next; //!< Next element in list
};
/*! List containing all allocated effect chunks */
struct chunkList_t {
EffectChunk *first; //!< First element of list, used for iteration
EffectChunk *last; //!< Last element of list, used for appending
} chunkList = {
NULL, NULL
};
/*! Our lists of all game world effects */
struct activeList_t {
size_t num; //!< Number of effects in this list, used when saving
EFFECT *first; //!< First element of list, used for iteration / finding free effects
EFFECT *last; //!< Last element of list, used for appending
} activeList = { //!< List of all active effects
0, NULL, NULL
}, inactiveList = { //!< List of unused effects
0, NULL, NULL
};
/* Tick counts for updates on a particular interval */
static UDWORD lastUpdateDroids[EFFECT_DROID_DIVISION];
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 void updateWaypoint(EFFECT *psEffect);
static void updateExplosion(EFFECT *psEffect);
static void updatePolySmoke(EFFECT *psEffect);
static void updateGraviton(EFFECT *psEffect);
static void updateConstruction(EFFECT *psEffect);
static void updateBlood (EFFECT *psEffect);
static void updateDestruction(EFFECT *psEffect);
static void updateFire(EFFECT *psEffect);
static void updateSatLaser(EFFECT *psEffect);
static void updateFirework(EFFECT *psEffect);
static void updateEffect(EFFECT *psEffect); // MASTER function
// ----------------------------------------------------------------------------------------
// ---- The render functions - every group type of effect has a distinct one
static void renderExplosionEffect ( const EFFECT *psEffect );
static void renderSmokeEffect ( const EFFECT *psEffect );
static void renderGravitonEffect ( const EFFECT *psEffect );
static void renderConstructionEffect( const EFFECT *psEffect );
static void renderWaypointEffect ( const EFFECT *psEffect );
static void renderBloodEffect ( const EFFECT *psEffect );
static void renderDestructionEffect ( const EFFECT *psEffect );
static void renderFirework ( const EFFECT *psEffect );
static void 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(void);
static void effectDroidUpdates(void);
static UDWORD effectGetNumFrames(EFFECT *psEffect);
static void killEffect(EFFECT *e);
/*!
* Initialise memory between first and last as singly linked list
* \param first First element in memory chunk
* \param last Last element in memory chunk
*/
static void initEffectPool(EFFECT *first, EFFECT *last)
{
EFFECT *it;
for (it = first; it < last; it++)
{
// We do not need a double-linked-list for inactiveeffects, since we always pick from the front:
it->prev = NULL;
it->next = it+1;
}
last->prev = NULL;
last->next = NULL;
}
/*!
* Allocate a new effect from memory pool
* FIXME: Does not deal with out-of-memory conditions (yet)
* \return New, uninitialised effect
*/
static EFFECT *Effect_malloc(void)
{
/* Take the first item in inactiveList */
EFFECT *instance = inactiveList.first;
/* Remove from inactiveList */
inactiveList.first = instance->next; // Singly linked, so do not update prev
instance->next = NULL; // We are the last in activeList now
/* Append to activeList */
instance->prev = activeList.last;
if (instance->prev == NULL) {
activeList.first = instance; // activeList was empty, so fill it
}
else {
activeList.last->next = instance;
}
activeList.last = instance;
/* Adjust counts */
activeList.num++;
inactiveList.num--;
/* Ensure the next search will have something to feed its hunger with */
if (inactiveList.first == NULL)
{
/* Allocate new effect chunk */
EffectChunk *chunk = (EffectChunk *)calloc(1, sizeof(EffectChunk));
debug(LOG_MEMORY, "%lu effects in use, allocating %d extra", (unsigned long)activeList.num, EFFECT_CHUNK_SIZE);
/* Deal with out-of-memory conditions */
if (chunk == NULL) {
debug(LOG_ERROR, "Out of memory");
return NULL; // The next call relies on inactiveList being non-empty, and would thus segfault, so bail out early instead
}
/* Append to list */
chunk->next = NULL; // Last element
chunkList.last->next = chunk; // chunkList is never empty, thus we can rely on last!=NULL
/* Update inactiveList */
inactiveList.num = EFFECT_CHUNK_SIZE;
inactiveList.first = &chunk->effects[0];
inactiveList.last = &chunk->effects[EFFECT_CHUNK_SIZE-1];
/* Initialise list links between inactive effects */
initEffectPool(inactiveList.first, inactiveList.last);
}
return instance;
}
/*!
* Return an effect into memory pool
* \param self Effect to be freed
*/
static void Effect_free(EFFECT *instance)
{
instance->group = EFFECT_FREED;
/* Remove from activeList and fixup endings necessary */
if (instance->prev != NULL) {
instance->prev->next = instance->next;
}
else {
activeList.first = instance->next; // We were the first in activeList
}
if (instance->next != NULL) {
instance->next->prev = instance->prev;
}
else {
activeList.last = instance->prev; // We were the last in activeList
}
/* Append to inactiveList */
instance->prev = NULL; // Singly linked
instance->next = NULL; // Last element
// inactiveList is never empty (guaranteed in Effect_malloc), thus we can rely on last!=NULL
inactiveList.last->next = instance;
inactiveList.last = instance;
/* Adjust counts */
inactiveList.num++;
ASSERT_OR_RETURN(, activeList.num > 0, "Underflow");
activeList.num--;
}
void shutdownEffectsSystem(void)
{
EFFECT *eff;
/* Traverse the list */
for (eff = activeList.first; eff;)
{
EFFECT *effNext = eff->next;
killEffect(eff);
eff = effNext;
}
chunkList.first = NULL;
chunkList.last = NULL;
}
/*!
* Initialise effects system
* Cleans up old effects, allocates a first chunk of effects, initialises (in)active lists
*/
void initEffectsSystem(void)
{
EffectChunk *chunk;
/* Clean up old chunks */
shutdownEffectsSystem();
/* Allocate new chunk */
chunk = (EffectChunk *)calloc(1, sizeof(EffectChunk));
/* Deal with out-of-memory conditions */
if (chunk == NULL)
return; // FIXME We have no way to report an error here...
/* Create chunkList */
chunkList.first = chunk;
chunkList.last = chunk;
chunk->next = NULL; // Last element
/* activeList is empty at start */
activeList.num = 0;
activeList.first = NULL;
activeList.last = NULL;
/* inactiveList contains all elements */
inactiveList.num = EFFECT_CHUNK_SIZE;
inactiveList.first = &chunk->effects[0];
inactiveList.last = &chunk->effects[EFFECT_CHUNK_SIZE-1];
/* Initialise free-effects pool */
initEffectPool(inactiveList.first, inactiveList.last);
}
static void positionEffect(const EFFECT *psEffect)
{
/* Establish world position */
Vector3i dv(
psEffect->position.x - player.p.x,
psEffect->position.y,
-(psEffect->position.z - player.p.z)
);
/* Push the indentity matrix */
pie_MatBegin();
/* Move to position */
pie_TRANSLATE(dv.x, dv.y, dv.z);
}
static void killEffect(EFFECT *e)
{
/* Put effect back into pool */
Effect_free(e);
}
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)
{
EFFECT *psEffect = NULL;
if(gamePaused())
{
return;
}
/* Retrieve a new effect from pool */
psEffect = Effect_malloc();
/* Deal with out-of-memory conditions */
if (psEffect == NULL) {
debug(LOG_ERROR, "Out of memory");
return; // FIXME We have no way to report an error here...
}
/* 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 fucnction is different for each,
although some things are shared
*/
psEffect->imd = NULL;
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 != NULL || group == EFFECT_DESTRUCTION || group == EFFECT_FIRE || group == EFFECT_SAT_LASER, "null effect imd");
}
/* Calls all the update functions for each different currently active effect */
void processEffects(void)
{
EFFECT *it;
/* Traverse the list */
for (it = activeList.first; it != NULL;)
{
EFFECT *itNext = it->next; // If updateEffect deletes something, we would be screwed...
if (it->birthTime <= graphicsTime) // Don't process, if it doesn't exist yet.
{
/* Run updates, effect may be deleted here */
updateEffect(it);
/* Is it on the grid */
if (it->group != EFFECT_FREED && clipXY(it->position.x, it->position.z))
{
/* Add it to the bucket */
bucketAddTypeToList(RENDER_EFFECT, it);
}
}
it = itNext;
}
/* Add any droid effects */
effectDroidUpdates();
/* Add any structure effects */
effectStructureUpdates();
}
/* The general update function for all effects - calls a specific one for each */
static void updateEffect(EFFECT *psEffect)
{
/* What type of effect are we dealing with? */
switch(psEffect->group)
{
case EFFECT_EXPLOSION:
updateExplosion(psEffect);
return;
case EFFECT_WAYPOINT:
if(!gamePaused()) updateWaypoint(psEffect);
return;
case EFFECT_CONSTRUCTION:
if(!gamePaused()) updateConstruction(psEffect);
return;
case EFFECT_SMOKE:
if(!gamePaused()) updatePolySmoke(psEffect);
return;
case EFFECT_GRAVITON:
if(!gamePaused()) updateGraviton(psEffect);
return;
case EFFECT_BLOOD:
if(!gamePaused()) updateBlood(psEffect);
return;
case EFFECT_DESTRUCTION:
if(!gamePaused()) updateDestruction(psEffect);
return;
case EFFECT_FIRE:
if(!gamePaused()) updateFire(psEffect);
return;
case EFFECT_SAT_LASER:
if(!gamePaused()) updateSatLaser(psEffect);
return;
case EFFECT_FIREWORK:
if(!gamePaused()) updateFirework(psEffect);
return;
case EFFECT_FREED:
break;
}
debug( LOG_ERROR, "Weirdy class of effect passed to updateEffect" );
abort();
}
// ----------------------------------------------------------------------------------------
// ALL THE UPDATE FUNCTIONS
// ----------------------------------------------------------------------------------------
/** Update the waypoint effects.*/
static void updateWaypoint(EFFECT *psEffect)
{
if(!(keyDown(KEY_LCTRL) || keyDown(KEY_RCTRL) ||
keyDown(KEY_LSHIFT) || keyDown(KEY_RSHIFT)))
{
killEffect(psEffect);
}
}
static void 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,NULL,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,NULL,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,NULL,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,NULL,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,NULL,0);
}
}
killEffect(psEffect);
}
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,NULL,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
{
/* Kill it off */
killEffect(psEffect);
return;
}
}
}
/* 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)
{
/* Kill it */
killEffect(psEffect);
}
}
}
}
static void updateSatLaser(EFFECT *psEffect)
{
Vector3i dv;
UDWORD val;
UDWORD radius;
UDWORD xDif,yDif;
UDWORD i;
UDWORD startHeight,endHeight;
UDWORD xPos,yPos;
LIGHT light;
// Do these here cause there 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,NULL,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,NULL,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,NULL,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,NULL,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,NULL,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,NULL,0);
}
}
}
if(graphicsTime - psEffect->birthTime < 1000)
{
light.position.x = xPos;
light.position.y = startHeight;
light.position.z = yPos;
light.range = 800;
light.colour = LIGHT_BLUE;
processLight(&light);
}
else
{
killEffect(psEffect);
}
}
/** The update function for the explosions */
static void updateExplosion(EFFECT *psEffect)
{
LIGHT light;
UDWORD percent;
UDWORD range;
float scaling;
if (TEST_LIT(psEffect))
{
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;
}
range = percent;
light.position.x = psEffect->position.x;
light.position.y = psEffect->position.y;
light.position.z = psEffect->position.z;
light.range = (3*range)/2;
light.colour = LIGHT_RED;
processLight(&light);
}
if (psEffect->type == EXPLOSION_TYPE_SHOCKWAVE)
{
psEffect->size += graphicsTimeAdjustedIncrement(SHOCKWAVE_SPEED);
scaling = (float)psEffect->size / (float)MAX_SHOCKWAVE_SIZE;
psEffect->frameNumber = scaling * effectGetNumFrames(psEffect);
light.position.x = psEffect->position.x;
light.position.y = psEffect->position.y;
light.position.z = psEffect->position.z;
light.range = psEffect->size+200;
light.colour = LIGHT_YELLOW;
processLight(&light);
if (psEffect->size > MAX_SHOCKWAVE_SIZE || light.range > 600)
{
/* Kill it off */
killEffect(psEffect);
return;
}
}
/* 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)
{
/* Kill it off */
killEffect(psEffect);
return;
}
else
{
psEffect->frameNumber = 0;
}
}
}