4b825dc642cb6eb9a060e54bf8d69288fbee4904ebd360ec63ec976c05699f3180e866b3f69e5472
 
 
1
#include "system.h"
 
 
2
#include "stratdef.h"
 
 
3
#include "bh_selfdest.h"
 
 
4
#include "weapons.h"
 
 
5
#include "particle.h"
 
 
6
#include <assert.h>
 
 
7
#include "bh_types.h"
 
 
8
#include <stdlib.h>
 
 
9
 
 
 
10
void SelfDestructBehaveInit(void* bhdata,STRATEGYBLOCK* sbptr)
 
 
11
{
 
 
12
    assert(sbptr);
 
 
13
    assert(bhdata);
 
 
14
 
 
 
15
    SELF_DESTRUCT_BEHAV_BLOCK* sd_bhv = malloc(sizeof(SELF_DESTRUCT_BEHAV_BLOCK));
 
 
16
 
 
 
17
    if(sd_bhv)
 
 
18
    {
 
 
19
        sbptr->dataptr = sd_bhv;
 
 
20
        sd_bhv->bhvr_type = I_BehaviourSelfDestruct;
 
 
21
        SELF_DESTRUCT_TOOLS_TEMPLATE* sd_tt = (SELF_DESTRUCT_TOOLS_TEMPLATE*)bhdata;
 
 
22
        //copy stuff from tools template
 
 
23
        COPY_NAME(sbptr->SBname, sd_tt->nameID);
 
 
24
        sd_bhv->timer = sd_tt->timer;
 
 
25
        sd_bhv->active = 0;
 
 
26
    }
 
 
27
    else
 
 
28
    {
 
 
29
        RemoveBehaviourStrategy(sbptr);
 
 
30
    }
 
 
31
}
 
 
32
 
 
 
33
void SelfDestructBehaveFun(STRATEGYBLOCK* sbptr)
 
 
34
{
 
 
35
     assert(sbptr);
 
 
36
    SELF_DESTRUCT_BEHAV_BLOCK* sd_bhv = (SELF_DESTRUCT_BEHAV_BLOCK*)sbptr->dataptr;
 
 
37
    assert((sd_bhv->bhvr_type == I_BehaviourSelfDestruct));
 
 
38
 
 
 
39
    if(sd_bhv->active)
 
 
40
    {    
 
 
41
        sd_bhv->timer -= NormalFrameTime;
 
 
42
 
 
 
43
        if(sd_bhv->timer <= 0)
 
 
44
        {
 
 
45
            int i;
 
 
46
 
 
 
47
            /* KJL 16:20:57 27/08/98 - let's do some pyrotechnics */
 
 
48
            Sound_Play(SID_NICE_EXPLOSION,"d",&PlayerStatus.DisplayBlock->ObWorld);
 
 
49
            MakeVolumetricExplosionAt(&PlayerStatus.DisplayBlock->ObWorld, EXPLOSION_SADAR_BLAST);
 
 
50
            PlayerStatus.sbptr->DamageBlock.IsOnFire = 1;
 
 
51
 
 
 
52
            //blow up everone
 
 
53
            for (i=0; i < NumActiveStBlocks; i++)
 
 
54
            {
 
 
55
                STRATEGYBLOCK *sbPtr = ActiveStBlockList[i];
 
 
56
 
 
 
57
                switch(sbPtr->type)
 
 
58
                {
 
 
59
                    case I_BehaviourAlien:
 
 
60
                    case I_BehaviourQueenAlien:
 
 
61
                    case I_BehaviourFaceHugger:
 
 
62
                    case I_BehaviourPredator:
 
 
63
                    case I_BehaviourXenoborg:
 
 
64
                    case I_BehaviourMarine:
 
 
65
                    case I_BehaviourMarinePlayer:
 
 
66
                    case I_BehaviourPredatorPlayer:
 
 
67
                    case I_BehaviourAlienPlayer: 
 
 
68
                    {
 
 
69
                        //kill the creature/player
 
 
70
                        VECTORCH direction = {0, -ONE_FIXED, 0};
 
 
71
                        CauseDamageToObject(sbPtr, &damage_profiles[CERTAINDEATH], ONE_FIXED, &direction);
 
 
72
                    }
 
 
73
                    default:
 
 
74
                    break;
 
 
75
                }
 
 
76
            }
 
 
77
            sd_bhv->active = 0;
 
 
78
        }
 
 
79
    }
 
 
80
}
 
 
81
 
 
 
82
/*--------------------**
 
 
83
** Loading and Saving **
 
 
84
**--------------------*/
 
 
85
#include "savegame.h"
 
 
86
 
 
 
87
typedef struct self_destruct_save_block
 
 
88
{
 
 
89
    SAVE_BLOCK_STRATEGY_HEADER header;
 
 
90
 
 
 
91
    int timer; //in fixed point seconds
 
 
92
    int active;
 
 
93
 
 
 
94
} SELF_DESTRUCT_SAVE_BLOCK;
 
 
95
 
 
 
96
#define SAVELOAD_BLOCK block
 
 
97
#define SAVELOAD_BEHAV sd_bhv
 
 
98
 
 
 
99
void LoadStrategy_SelfDestruct(SAVE_BLOCK_STRATEGY_HEADER* header)
 
 
100
{
 
 
101
    SELF_DESTRUCT_SAVE_BLOCK* block = (SELF_DESTRUCT_SAVE_BLOCK*) header; 
 
 
102
 
 
 
103
    //check the size of the save block
 
 
104
    if(header->size != sizeof(*block))
 
 
105
        return;
 
 
106
 
 
 
107
    //find the existing strategy block
 
 
108
    STRATEGYBLOCK* sbPtr = FindSBWithName(header->SBname);
 
 
109
 
 
 
110
    if(!sbPtr)
 
 
111
        return;
 
 
112
 
 
 
113
    //make sure the strategy found is of the right type
 
 
114
    if(sbPtr->type != I_BehaviourSelfDestruct)
 
 
115
        return;
 
 
116
 
 
 
117
    SELF_DESTRUCT_BEHAV_BLOCK* sd_bhv = (SELF_DESTRUCT_BEHAV_BLOCK*)sbPtr->dataptr;
 
 
118
 
 
 
119
    //start copying stuff
 
 
120
    COPYELEMENT_LOAD(timer);
 
 
121
    COPYELEMENT_LOAD(active);
 
 
122
}
 
 
123
 
 
 
124
void SaveStrategy_SelfDestruct(STRATEGYBLOCK* sbPtr)
 
 
125
{
 
 
126
    SELF_DESTRUCT_SAVE_BLOCK *block;
 
 
127
    SELF_DESTRUCT_BEHAV_BLOCK* sd_bhv = (SELF_DESTRUCT_BEHAV_BLOCK*)sbPtr->dataptr;
 
 
128
 
 
 
129
    GET_STRATEGY_SAVE_BLOCK(block,sbPtr);
 
 
130
 
 
 
131
    //start copying stuff
 
 
132
    COPYELEMENT_SAVE(timer);
 
 
133
    COPYELEMENT_SAVE(active);
 
 
134
}