39
39
#include "lib/framework/frameresource.h"
40
40
#include "lib/framework/input.h"
41
41
#include "lib/framework/tagfile.h"
42
#include "lib/framework/math-help.h"
42
#include "lib/framework/math_ext.h"
44
44
#include "lib/ivis_common/ivisdef.h" //ivis matrix code
45
45
#include "lib/ivis_common/piedef.h" //ivis matrix code
46
#include "lib/framework/fixedpoint.h"
46
47
#include "lib/ivis_common/piepalette.h"
47
48
#include "lib/ivis_common/piestate.h"
48
49
#include "lib/ivis_opengl/piematrix.h"
228
228
static void effectSetupFire ( EFFECT *psEffect );
229
229
static void effectSetUpSatLaser ( EFFECT *psEffect );
230
230
static void effectSetUpFirework ( EFFECT *psEffect );
232
static BOOL validatePie( EFFECT_GROUP group, iIMDShape *pie );
234
231
static void effectStructureUpdates(void);
235
232
static void effectDroidUpdates(void);
233
static UDWORD effectGetNumFrames(EFFECT *psEffect);
237
236
static void positionEffect(EFFECT *psEffect)
261
260
static void killEffect(EFFECT *e)
262
if (e->group == EFFECT_FIRE)
264
const int posX = map_coord(e->position.x);
265
const int posY = map_coord(e->position.z);
266
MAPTILE *psTile = mapTile(posX, posY);
268
ASSERT(psTile, "Fire effect on non-existing tile (%d, %d)", posX, posY);
271
psTile->tileInfoBits &= ~BITS_ON_FIRE; // clear fire bit
263
274
effectStatus[e-asEffectsList] = ES_INACTIVE;
264
275
e->control = (UBYTE) 0;
267
// ----------------------------------------------------------------------------------------
268
278
static BOOL essentialEffect(EFFECT_GROUP group, EFFECT_TYPE type)
335
337
/* Get a pointer - just cos our macro requires it, speeds not an issue here */
336
338
psEffect = &asEffectsList[i];
337
/* Clear all the control bits */
338
psEffect->control = (UBYTE)0;
339
// clear the fire bit
340
killEffect(psEffect);
341
// Clear out the whole array
342
memset(psEffect, 0x0, sizeof(EFFECT));
339
343
/* All effects are initially inactive */
340
344
effectStatus[i] = ES_INACTIVE;
344
// ----------------------------------------------------------------------------------------
345
348
void effectSetLandLightSpec(LAND_LIGHT_SPEC spec)
349
// ----------------------------------------------------------------------------------------
350
353
void effectSetSize(UDWORD size)
352
355
specifiedSize = size;
354
// ----------------------------------------------------------------------------------------
355
358
void addMultiEffect(Vector3i *basePos, Vector3i *scatter, EFFECT_GROUP group,
356
359
EFFECT_TYPE type,BOOL specified, iIMDShape *imd, UDWORD number, BOOL lit, UDWORD size)
413
414
return(letThrough);
415
// ----------------------------------------------------------------------------------------
419
void addEffect(Vector3i *pos, EFFECT_GROUP group, EFFECT_TYPE type,BOOL specified, iIMDShape *imd, BOOL lit)
418
void addEffect(Vector3i *pos, EFFECT_GROUP group, EFFECT_TYPE type,BOOL specified, iIMDShape *imd, int lit)
420
static unsigned int aeCalls = 0;
421
421
UDWORD essentialCount;
423
EFFECT *psEffect = NULL;
478
477
/* Check the list isn't just full of essential effects */
479
if(essentialCount>=MAX_EFFECTS)
478
if (essentialCount >= MAX_EFFECTS)
481
480
/* All of the effects are essential!?!? */
486
psEffect = &asEffectsList[freeEffect];
489
488
/* Store away it's position - into FRACTS */
490
asEffectsList[freeEffect].position.x = pos->x;
491
asEffectsList[freeEffect].position.y = pos->y;
492
asEffectsList[freeEffect].position.z = pos->z;
489
psEffect->position.x = pos->x;
490
psEffect->position.y = pos->y;
491
psEffect->position.z = pos->z;
495
493
/* Now, note group and type */
496
asEffectsList[freeEffect].group = group;
497
asEffectsList[freeEffect].type = type;
494
psEffect->group = group;
495
psEffect->type = type;
499
497
/* Set when it entered the world */
500
asEffectsList[freeEffect].birthTime = asEffectsList[freeEffect].lastFrame = gameTime;
498
psEffect->birthTime = psEffect->lastFrame = gameTime;
502
500
if(group == EFFECT_GRAVITON && (type == GRAVITON_TYPE_GIBLET || type == GRAVITON_TYPE_EMITTING_DR))
504
asEffectsList[freeEffect].frameNumber = lit;
502
psEffect->frameNumber = lit;
509
507
/* Starts off on frame zero */
510
asEffectsList[freeEffect].frameNumber = 0;
508
psEffect->frameNumber = 0;
514
512
See what kind of effect it is - the add fucnction is different for each,
515
513
although some things are shared
517
asEffectsList[freeEffect].imd = NULL;
515
psEffect->imd = NULL;
520
SET_LITABS(asEffectsList[freeEffect]);
525
523
/* We're specifying what the imd is - override */
526
asEffectsList[freeEffect].imd = imd;
527
// if(type == EXPLOSION_TYPE_SPECIFIED_FIXME)
529
// asEffectsList[freeEffect].size = EXPLOSION_SIZE;
533
asEffectsList[freeEffect].size =(UWORD) specifiedSize;
525
psEffect->size = specifiedSize;
537
528
/* Do all the effect type specific stuff */
540
531
case EFFECT_SMOKE:
541
effectSetupSmoke(&asEffectsList[freeEffect]);
532
effectSetupSmoke(psEffect);
543
534
case EFFECT_GRAVITON:
544
effectSetupGraviton(&asEffectsList[freeEffect]);
535
effectSetupGraviton(psEffect);
546
537
case EFFECT_EXPLOSION:
547
effectSetupExplosion(&asEffectsList[freeEffect]);
538
effectSetupExplosion(psEffect);
549
540
case EFFECT_CONSTRUCTION:
550
effectSetupConstruction(&asEffectsList[freeEffect]);
541
effectSetupConstruction(psEffect);
552
543
case EFFECT_WAYPOINT:
553
effectSetupWayPoint(&asEffectsList[freeEffect]);
544
effectSetupWayPoint(psEffect);
555
546
case EFFECT_BLOOD:
556
effectSetupBlood(&asEffectsList[freeEffect]);
547
effectSetupBlood(psEffect);
558
549
case EFFECT_DESTRUCTION:
559
effectSetupDestruction(&asEffectsList[freeEffect]);
550
effectSetupDestruction(psEffect);
561
552
case EFFECT_FIRE:
562
effectSetupFire(&asEffectsList[freeEffect]);
553
effectSetupFire(psEffect);
564
555
case EFFECT_SAT_LASER:
565
effectSetUpSatLaser(&asEffectsList[freeEffect]);
556
effectSetUpSatLaser(psEffect);
567
558
case EFFECT_FIREWORK:
568
effectSetUpFirework(&asEffectsList[freeEffect]);
559
effectSetUpFirework(psEffect);
561
case EFFECT_STRUCTURE:
562
case EFFECT_DUST_BALL:
571
563
ASSERT( false,"Weirdy group type for an effect" );
578
570
/* As of yet, it hasn't bounced (or whatever)... */
579
571
if(type!=EXPLOSION_TYPE_LAND_LIGHT)
581
asEffectsList[freeEffect].specific = 0;
584
/* Looks like we didn't establish an imd for the effect */
586
ASSERT( asEffectsList[freeEffect].imd != NULL || group == EFFECT_DESTRUCTION || group == EFFECT_FIRE || group == EFFECT_SAT_LASER,
591
if ( validatePie( group, asEffectsList[freeEffect].imd ) == false )
593
ASSERT( false,"No PIE found or specified for an effect" );
573
psEffect->specific = 0;
576
ASSERT(psEffect->imd != NULL || group == EFFECT_DESTRUCTION || group == EFFECT_FIRE || group == EFFECT_SAT_LASER, "null effect imd");
597
578
/* No more slots available? */
598
579
if(freeEffect++ >= (MAX_EFFECTS-1))
676
631
case EFFECT_EXPLOSION:
677
632
updateExplosion(psEffect);
680
635
case EFFECT_WAYPOINT:
681
636
if(!gamePaused()) updateWaypoint(psEffect);
684
639
case EFFECT_CONSTRUCTION:
685
640
if(!gamePaused()) updateConstruction(psEffect);
688
643
case EFFECT_SMOKE:
689
644
if(!gamePaused()) updatePolySmoke(psEffect);
692
647
case EFFECT_STRUCTURE:
695
650
case EFFECT_GRAVITON:
696
651
if(!gamePaused()) updateGraviton(psEffect);
699
654
case EFFECT_BLOOD:
700
655
if(!gamePaused()) updateBlood(psEffect);
703
658
case EFFECT_DESTRUCTION:
704
659
if(!gamePaused()) updateDestruction(psEffect);
707
662
case EFFECT_FIRE:
708
663
if(!gamePaused()) updateFire(psEffect);
711
666
case EFFECT_SAT_LASER:
712
667
if(!gamePaused()) updateSatLaser(psEffect);
714
670
case EFFECT_FIREWORK:
715
671
if(!gamePaused()) updateFirework(psEffect);
718
debug( LOG_ERROR, "Weirdy class of effect passed to updateEffect" );
675
debug( LOG_ERROR, "Weirdy class of effect passed to updateEffect" );
724
678
// ----------------------------------------------------------------------------------------
725
679
// ALL THE UPDATE FUNCTIONS
726
680
// ----------------------------------------------------------------------------------------
727
/* Update the waypoint effects.*/
681
/** Update the waypoint effects.*/
728
682
static void updateWaypoint(EFFECT *psEffect)
730
684
if(!(keyDown(KEY_LCTRL) || keyDown(KEY_RCTRL) ||
1542
1483
psEffect->lastFrame = gameTime;
1543
1484
pos.x = (psEffect->position.x + ((rand() % psEffect->radius) - (rand() % (2 * psEffect->radius))));
1544
1485
pos.z = (psEffect->position.z + ((rand() % psEffect->radius) - (rand() % (2 * psEffect->radius))));
1546
1487
// Effect is off map, no need to update it anymore
1547
1488
if(!worldOnMap(pos.x, pos.z))
1549
1490
killEffect(psEffect);
1553
1494
pos.y = map_Height(pos.x,pos.z);
1555
1496
if(psEffect->type == FIRE_TYPE_SMOKY_BLUE)
1617
1555
case EFFECT_WAYPOINT:
1618
1556
renderWaypointEffect(psEffect);
1621
1559
case EFFECT_EXPLOSION:
1622
1560
renderExplosionEffect(psEffect);
1625
1563
case EFFECT_CONSTRUCTION:
1626
1564
renderConstructionEffect(psEffect);
1629
1567
case EFFECT_SMOKE:
1630
1568
renderSmokeEffect(psEffect);
1633
1571
case EFFECT_GRAVITON:
1634
1572
renderGravitonEffect(psEffect);
1637
1575
case EFFECT_BLOOD:
1638
1576
renderBloodEffect(psEffect);
1641
1579
case EFFECT_STRUCTURE:
1644
1582
case EFFECT_DESTRUCTION:
1645
1583
/* There is no display func for a destruction effect -
1646
1584
it merely spawn other effects over time */
1647
1585
renderDestructionEffect(psEffect);
1649
1588
case EFFECT_FIRE:
1652
1592
case EFFECT_SAT_LASER:
1655
1596
case EFFECT_FIREWORK:
1656
1597
renderFirework(psEffect);
1659
debug( LOG_ERROR, "Weirdy class of effect passed to renderEffect" );
1601
debug( LOG_ERROR, "Weirdy class of effect passed to renderEffect" );
1665
// ----------------------------------------------------------------------------------------
1666
/* drawing func for wapypoints . AJL. */
1667
void renderWaypointEffect(EFFECT *psEffect)
1604
/** drawing func for wapypoints */
1605
static void renderWaypointEffect(EFFECT *psEffect)
1669
1607
positionEffect(psEffect);
1736
1671
iV_MatrixEnd();
1739
// ----------------------------------------------------------------------------------------
1740
static BOOL rejectLandLight(LAND_LIGHT_SPEC type)
1674
static bool rejectLandLight(LAND_LIGHT_SPEC type)
1676
unsigned int timeSlice = gameTime%2000;
1744
timeSlice = gameTime%2000;
1747
if(type == LL_MIDDLE) return(false); else return(true); // reject all expect middle
1749
else if(timeSlice<800)
1751
if(type == LL_OUTER) return(true); else return(false); // reject only outer
1753
else if(timeSlice<1200)
1755
return(false); //reject none
1757
else if(timeSlice<1600)
1759
if(type == LL_OUTER) return(true); else return(false); // reject only outer
1678
if (timeSlice < 400)
1680
return (type != LL_MIDDLE); // reject all expect middle
1682
else if (timeSlice < 800)
1684
return (type == LL_OUTER); // reject only outer
1686
else if (timeSlice < 1200)
1688
return(false); //reject none
1690
else if (timeSlice < 1600)
1692
return (type == LL_OUTER); // reject only outer
1763
if(type == LL_MIDDLE) return(false); else return(true); // reject all expect middle
1696
return (type != LL_MIDDLE); // reject all expect middle
1767
// ----------------------------------------------------------------------------------------
1768
/* Renders the standard explosion effect */
1769
void renderExplosionEffect(EFFECT *psEffect)
1700
/** Renders the standard explosion effect */
1701
static void renderExplosionEffect(EFFECT *psEffect)
1771
1703
SDWORD percent;
1772
1704
const PIELIGHT brightness = WZCOL_WHITE;
2325
// ----------------------------------------------------------------------------------------
2326
2244
void effectSetupFire(EFFECT *psEffect)
2246
const int posX = map_coord(psEffect->position.x);
2247
const int posY = map_coord(psEffect->position.z);
2248
MAPTILE *psTile = mapTile(posX, posY);
2250
ASSERT(psTile, "Cannot place a fire effect %d, %d - outside map!", posX, posY);
2253
psTile->tileInfoBits |= BITS_ON_FIRE;
2328
2255
psEffect->frameDelay = 300; // needs to be investigated...
2329
2256
psEffect->radius = auxVar; // needs to be investigated
2330
2257
psEffect->lifeSpan = (UWORD)auxVarSec;
2478
// ----------------------------------------------------------------------------------------
2479
UDWORD getNumEffects( void )
2485
// ----------------------------------------------------------------------------------------
2486
UDWORD EffectGetNumFrames(EFFECT *psEffect)
2403
static UDWORD effectGetNumFrames(EFFECT *psEffect)
2489
2405
return psEffect->imd->numFrames;
2493
UDWORD IMDGetNumFrames(iIMDShape *Shape)
2496
return Shape->numFrames;
2500
UDWORD IMDGetAnimInterval(iIMDShape *Shape)
2503
return Shape->animInterval;
2507
2409
void effectGiveAuxVar( UDWORD var)
2512
2415
void effectGiveAuxVarSec( UDWORD var)
2514
2417
auxVarSec = var;
2517
// ----------------------------------------------------------------------------------------
2518
/* Runs all the spot effect stuff for the droids - adding of dust and the like... */
2420
/** Runs all the spot effect stuff for the droids - adding of dust and the like... */
2519
2421
static void effectDroidUpdates(void)
2521
2423
unsigned int i;
2710
// -----------------------------------------------------------------------------------
2711
bool fireOnLocation(unsigned int x, unsigned int y)
2715
for(i = 0; i < MAX_EFFECTS; ++i)
2717
if (effectStatus[i] == ES_ACTIVE
2718
&& asEffectsList[i].group == EFFECT_FIRE)
2720
const unsigned int posX = asEffectsList[i].position.x;
2721
const unsigned int posY = asEffectsList[i].position.z;
2734
2605
static const char FXData_tag_definition[] = "tagdefinitions/savegame/effects.def";
2735
2606
static const char FXData_file_identifier[] = "FXData";
2737
// -----------------------------------------------------------------------------------
2738
/* This will save out the effects data */
2608
/** This will save out the effects data */
2739
2609
bool writeFXData(const char* fileName)
2741
2611
unsigned int count, i;