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