| | 1 | #include "system.h" |
| | 2 | #include "prototyp.h" |
| | 3 | #include "stratdef.h" |
| | 4 | #include "bh_types.h" |
| | 5 | #include "npc_alien.h" |
| | 6 | #include "npc_marine.h" |
| | 7 | #include "npc_xenoborg.h" |
| | 8 | #include "corpse.h" |
| | 9 | #include "debris.h" |
| | 10 | #include <stdlib.h> |
| | 11 | #include <assert.h> |
| | 12 | |
| | 13 | extern int PlayerIdInPlayerList(int Id); |
| | 14 | int NumActiveStBlocks = 0; |
| | 15 | static int NumFreeStBlocks = 0; |
| | 16 | unsigned int IncrementalSBname = 0; |
| | 17 | |
| | 18 | STRATEGYBLOCK *ActiveStBlockList[maxstblocks]; |
| | 19 | STRATEGYBLOCK FreeStBlockData[maxstblocks]; |
| | 20 | |
| | 21 | static STRATEGYBLOCK *FreeStBlockList[maxstblocks]; |
| | 22 | static STRATEGYBLOCK **FreeStBlockListPtr = &FreeStBlockList[maxstblocks-1]; |
| | 23 | static STRATEGYBLOCK **ActiveStBlockListPtr = &ActiveStBlockList[0]; |
| | 24 | |
| | 25 | void InitialiseStrategyBlocks() |
| | 26 | { |
| | 27 | for(; NumFreeStBlocks < maxstblocks; NumFreeStBlocks++) |
| | 28 | { |
| | 29 | FreeStBlockList[NumFreeStBlocks] = &FreeStBlockData[NumFreeStBlocks]; |
| | 30 | FreeStBlockList[NumFreeStBlocks]->destroyed_but_preserved = 0; |
| | 31 | } |
| | 32 | } |
| | 33 | |
| | 34 | static const STRATEGYBLOCK Zero_Strategyblock = |
| | 35 | { |
| | 36 | I_BehaviourNull, |
| | 37 | NULL, |
| | 38 | NULL, |
| | 39 | NULL, |
| | 40 | NULL, |
| | 41 | NULL, |
| | 42 | NULL, |
| | 43 | NULL, |
| | 44 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| | 45 | 0, |
| | 46 | 0, |
| | 47 | 0, |
| | 48 | 0, |
| | 49 | 0, |
| | 50 | { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}, |
| | 51 | -1 |
| | 52 | }; |
| | 53 | |
| | 54 | STRATEGYBLOCK* CreateActiveStrategyBlock(AVP_BEHAVIOUR_TYPE type) |
| | 55 | { |
| | 56 | if(NumFreeStBlocks) |
| | 57 | { |
| | 58 | NumFreeStBlocks--; |
| | 59 | |
| | 60 | *ActiveStBlockListPtr = *FreeStBlockListPtr--; |
| | 61 | **ActiveStBlockListPtr = Zero_Strategyblock; |
| | 62 | ActiveStBlockList[NumActiveStBlocks]->index = NumActiveStBlocks; |
| | 63 | NumActiveStBlocks++; |
| | 64 | (*ActiveStBlockListPtr)->type = type; |
| | 65 | return *ActiveStBlockListPtr++; |
| | 66 | } |
| | 67 | |
| | 68 | return NULL; |
| | 69 | } |
| | 70 | |
| | 71 | void DestroyActiveStrategyBlock(STRATEGYBLOCK* sb) |
| | 72 | { |
| | 73 | if ( -1 != sb->index) |
| | 74 | { |
| | 75 | ActiveStBlockList[sb->index] = ActiveStBlockList[--NumActiveStBlocks]; |
| | 76 | ActiveStBlockList[NumActiveStBlocks]->index = sb->index; |
| | 77 | ActiveStBlockListPtr--; |
| | 78 | |
| | 79 | if(!sb->preserve_until_end_of_level) |
| | 80 | { |
| | 81 | *(++FreeStBlockListPtr) = sb; |
| | 82 | NumFreeStBlocks++; |
| | 83 | } |
| | 84 | else |
| | 85 | { |
| | 86 | sb->destroyed_but_preserved = 1; |
| | 87 | } |
| | 88 | |
| | 89 | sb->index = -1; |
| | 90 | } |
| | 91 | } |
| | 92 | |
| | 93 | /* |
| | 94 | RWH - function to search thgough the list of active |
| | 95 | strat blocks and return the pointer |
| | 96 | */ |
| | 97 | |
| | 98 | STRATEGYBLOCK* FindSBWithName(char* id_name) |
| | 99 | { |
| | 100 | if(id_name) |
| | 101 | { |
| | 102 | int i = 0; |
| | 103 | |
| | 104 | //If the name is all 0`s I want to return a null pointer - Richard. |
| | 105 | for(; i < SB_NAME_LENGTH; i++) |
| | 106 | { |
| | 107 | if(id_name[i]) |
| | 108 | { |
| | 109 | for(i=0; i < NumActiveStBlocks; i++) |
| | 110 | { |
| | 111 | STRATEGYBLOCK* sbptr = ActiveStBlockList[i]; |
| | 112 | |
| | 113 | if(NAME_ISEQUAL(sbptr->SBname, id_name)) |
| | 114 | return sbptr; |
| | 115 | } |
| | 116 | } |
| | 117 | } |
| | 118 | } |
| | 119 | |
| | 120 | // we have to return null for lifts - so that |
| | 121 | // we know that the lift is outside the env |
| | 122 | return NULL; |
| | 123 | } |
| | 124 | |
| | 125 | void DestroyAllStrategyBlocks() |
| | 126 | { |
| | 127 | int i; |
| | 128 | while(NumActiveStBlocks > 0) |
| | 129 | RemoveBehaviourStrategy(ActiveStBlockList[0]); |
| | 130 | |
| | 131 | //get rid of all the strategyblocks that have been preserved until the end of the level |
| | 132 | |
| | 133 | for(i=0; i < maxstblocks; i++) |
| | 134 | { |
| | 135 | if(FreeStBlockData[i].destroyed_but_preserved) |
| | 136 | { |
| | 137 | FreeStBlockData[i].destroyed_but_preserved = 0; |
| | 138 | FreeStBlockData[i].preserve_until_end_of_level = 0; |
| | 139 | *(++FreeStBlockListPtr) = &FreeStBlockData[i]; |
| | 140 | NumFreeStBlocks++; |
| | 141 | } |
| | 142 | |
| | 143 | ActiveStBlockList[i] = NULL; |
| | 144 | } |
| | 145 | } |
| | 146 | |
| | 147 | void AssignNewSBName(STRATEGYBLOCK *sbPtr) |
| | 148 | { |
| | 149 | IncrementalSBname++; |
| | 150 | |
| | 151 | if(IncrementalSBname > 0xffffff) |
| | 152 | IncrementalSBname = 1; |
| | 153 | |
| | 154 | *((int *)&sbPtr->SBname[4]) = IncrementalSBname; |
| | 155 | |
| | 156 | if(SinglePlayer != AvP.PlayMode) |
| | 157 | { |
| | 158 | //modify name to ensure uniqueness between players |
| | 159 | extern int AVPDPNetID; |
| | 160 | sbPtr->SBname[SB_NAME_LENGTH-1] = + 10 + PlayerIdInPlayerList(AVPDPNetID); /* Just to make sure... */ |
| | 161 | } |
| | 162 | else |
| | 163 | { |
| | 164 | sbPtr->SBname[SB_NAME_LENGTH-1] = 1; /* Just to make sure... */ |
| | 165 | } |
| | 166 | } |