| | 1 | #include "system.h" |
| | 2 | #include "stratdef.h" |
| | 3 | #include "bh_types.h" |
| | 4 | #include "videoscreen.h" |
| | 5 | #include "dynamics.h" |
| | 6 | #include "debris.h" |
| | 7 | #include "npc_facehugger.h" |
| | 8 | #include "pvisible.h" |
| | 9 | #include <assert.h> |
| | 10 | #include <stdlib.h> |
| | 11 | #include <stdio.h> |
| | 12 | |
| | 13 | int FmvColourRed; |
| | 14 | int FmvColourGreen; |
| | 15 | int FmvColourBlue; |
| | 16 | |
| | 17 | void InitVideoScreen(void* bhdata, STRATEGYBLOCK *sbPtr) |
| | 18 | { |
| | 19 | TOOLS_DATA_VIDEO_SCREEN *toolsData = (TOOLS_DATA_VIDEO_SCREEN *)bhdata; |
| | 20 | VIDEO_SCREEN_BEHAV_BLOCK* videoScreen = sbPtr->dataptr = malloc(sizeof(VIDEO_SCREEN_BEHAV_BLOCK)); |
| | 21 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr = AllocateDynamicsBlock(DYNAMICS_TEMPLATE_STATIC); |
| | 22 | int i; |
| | 23 | |
| | 24 | if((NULL == videoScreen) || (NULL == dynPtr)) |
| | 25 | { |
| | 26 | RemoveBehaviourStrategy(sbPtr); |
| | 27 | return; |
| | 28 | } |
| | 29 | |
| | 30 | videoScreen->bhvr_type = I_BehaviourVideoScreen; |
| | 31 | |
| | 32 | sbPtr->maintainVisibility = 1; |
| | 33 | |
| | 34 | videoScreen->hidingfacehugger = !(random () % 15); |
| | 35 | videoScreen->inan_tac = NULL; |
| | 36 | |
| | 37 | { |
| | 38 | const NPC_DATA *NpcData = &NpcDataList[I_NPC_DefaultInanimate]; |
| | 39 | |
| | 40 | sbPtr->DamageBlock = NpcData->StartingStats; |
| | 41 | sbPtr->DamageBlock.Health = NpcData->StartingStats.Health << ONE_FIXED_SHIFT; |
| | 42 | sbPtr->DamageBlock.Armour = NpcData->StartingStats.Armour << ONE_FIXED_SHIFT; |
| | 43 | } |
| | 44 | |
| | 45 | sbPtr->DamageBlock.Health *= toolsData->integrity; |
| | 46 | sbPtr->DamageBlock.Indestructable = (toolsData->integrity > 20); |
| | 47 | |
| | 48 | dynPtr->IsStatic = 0; |
| | 49 | dynPtr->IsNetGhost = 1; |
| | 50 | dynPtr->GravityOn = 0; |
| | 51 | |
| | 52 | dynPtr->PrevPosition = dynPtr->Position = toolsData->position; |
| | 53 | dynPtr->OrientEuler = toolsData->orientation; |
| | 54 | CreateEulerMatrix(&dynPtr->OrientEuler, &dynPtr->OrientMat); |
| | 55 | TransposeMatrixCH(&dynPtr->OrientMat); |
| | 56 | sbPtr->containingModule = ModuleFromPosition(&dynPtr->Position, NULL); |
| | 57 | |
| | 58 | if(NULL == sbPtr->containingModule) |
| | 59 | { |
| | 60 | printf("no containing module for videoscreen\n"); |
| | 61 | RemoveBehaviourStrategy(sbPtr); |
| | 62 | return; |
| | 63 | } |
| | 64 | |
| | 65 | for(i=0; i < SB_NAME_LENGTH; i++) |
| | 66 | sbPtr->SBname[i] = toolsData->nameID[i]; |
| | 67 | |
| | 68 | /*check to see if object is animated.*/ |
| | 69 | { |
| | 70 | int item_num = 0; |
| | 71 | struct shapeheader* shptr = mainshapelist[sbPtr->shapeIndex]; |
| | 72 | TXACTRLBLK **pptxactrlblk = &videoScreen->inan_tac; |
| | 73 | |
| | 74 | for(; item_num < shptr->numitems; item_num++) |
| | 75 | { |
| | 76 | POLYHEADER *poly = (POLYHEADER*)(shptr->items[item_num]); |
| | 77 | |
| | 78 | if(poly->PolyFlags & iflag_txanim) |
| | 79 | { |
| | 80 | TXACTRLBLK *pnew_txactrlblk = malloc(sizeof(TXACTRLBLK)); |
| | 81 | |
| | 82 | if(pnew_txactrlblk) |
| | 83 | { |
| | 84 | pnew_txactrlblk->tac_flags = 0; |
| | 85 | pnew_txactrlblk->tac_item = item_num; |
| | 86 | pnew_txactrlblk->tac_sequence = 0; |
| | 87 | pnew_txactrlblk->tac_node = 0; |
| | 88 | pnew_txactrlblk->tac_txarray = GetTxAnimArrayZ(sbPtr->shapeIndex, item_num); |
| | 89 | pnew_txactrlblk->tac_txah_s = GetTxAnimHeaderFromShape(pnew_txactrlblk, sbPtr->shapeIndex); |
| | 90 | |
| | 91 | *pptxactrlblk = pnew_txactrlblk; |
| | 92 | pptxactrlblk = &pnew_txactrlblk->tac_next; |
| | 93 | } |
| | 94 | else |
| | 95 | *pptxactrlblk = NULL; |
| | 96 | } |
| | 97 | } |
| | 98 | |
| | 99 | *pptxactrlblk = NULL; |
| | 100 | } |
| | 101 | |
| | 102 | //copy destruction target stuff |
| | 103 | videoScreen->destruct_target_request = toolsData->destruct_target_request; |
| | 104 | |
| | 105 | for(i=0;i < SB_NAME_LENGTH; i++) |
| | 106 | videoScreen->destruct_target_ID[i] = toolsData->destruct_target_ID[i]; |
| | 107 | |
| | 108 | videoScreen->destruct_target_sbptr = 0; |
| | 109 | } |
| | 110 | |
| | 111 | extern void update_static(); |
| | 112 | |
| | 113 | void VideoScreenBehaviour(STRATEGYBLOCK *sbPtr) |
| | 114 | { |
| | 115 | if(sbPtr->DisplayBlock) |
| | 116 | { |
| | 117 | DISPLAYBLOCK* dptr = sbPtr->DisplayBlock; |
| | 118 | VIDEO_SCREEN_BEHAV_BLOCK* videoScreen = sbPtr->dataptr; |
| | 119 | LIGHTBLOCK *lightPtr = dptr->ObLights[0]; |
| | 120 | |
| | 121 | update_static(); |
| | 122 | |
| | 123 | if ((NULL != lightPtr) && (dptr->ObNumLights == 1)) |
| | 124 | { |
| | 125 | |
| | 126 | lightPtr->LightBright = ONE_FIXED/2; |
| | 127 | //lightPtr->LightFlags; |
| | 128 | lightPtr->LightRange = 3500; |
| | 129 | //lightPtr->RedScale= FmvColourRed; |
| | 130 | //lightPtr->GreenScale= FmvColourGreen; |
| | 131 | //lightPtr->BlueScale= FmvColourBlue; |
| | 132 | lightPtr->RedScale = 256 * 256; |
| | 133 | lightPtr->GreenScale = 256 * 256; |
| | 134 | lightPtr->BlueScale = 256 * 256; |
| | 135 | } |
| | 136 | |
| | 137 | //deal with texture animation if near |
| | 138 | if(videoScreen->inan_tac && !dptr->ObTxAnimCtrlBlks) |
| | 139 | dptr->ObTxAnimCtrlBlks = videoScreen->inan_tac; |
| | 140 | |
| | 141 | if(sbPtr->containingModule == PlayerStatus.sbptr->containingModule) |
| | 142 | { |
| | 143 | if (videoScreen->hidingfacehugger && (AvP.PlayerType != I_Alien) && !(random() % 300)) |
| | 144 | { |
| | 145 | CreateFacehuggerBot(&sbPtr->DisplayBlock->ObWorld); |
| | 146 | MakeFragments(sbPtr); |
| | 147 | sbPtr->please_destroy_me = 1; |
| | 148 | } |
| | 149 | } |
| | 150 | } |
| | 151 | |
| | 152 | if(sbPtr->DamageBlock.IsOnFire) |
| | 153 | CauseDamageToObject(sbPtr, &TemplateAmmo[AMMO_FLAMETHROWER].MaxDamage, ONE_FIXED/400, NULL); |
| | 154 | } |
| | 155 | |
| | 156 | void VideoScreenIsDamaged(STRATEGYBLOCK *sbPtr, const DAMAGE_PROFILE *damage, int multiple) |
| | 157 | { |
| | 158 | sbPtr->DynPtr->GravityOn = 1; |
| | 159 | |
| | 160 | if(sbPtr->DamageBlock.Health <= 0) |
| | 161 | { |
| | 162 | VIDEO_SCREEN_BEHAV_BLOCK* videoScreen = sbPtr->dataptr; |
| | 163 | //notify target of destruction |
| | 164 | if(videoScreen->destruct_target_sbptr) |
| | 165 | RequestState(videoScreen->destruct_target_sbptr,videoScreen->destruct_target_request,0); |
| | 166 | |
| | 167 | MakeFragments(sbPtr); |
| | 168 | sbPtr->please_destroy_me = 1; |
| | 169 | } |
| | 170 | } |
| | 171 | |
| | 172 | /*--------------------** |
| | 173 | ** Loading and Saving ** |
| | 174 | **--------------------*/ |
| | 175 | #include "savegame.h" |
| | 176 | |
| | 177 | typedef struct video_screen_save_block |
| | 178 | { |
| | 179 | SAVE_BLOCK_STRATEGY_HEADER header; |
| | 180 | |
| | 181 | //strategyblock stuff |
| | 182 | DAMAGEBLOCK DamageBlock; |
| | 183 | |
| | 184 | } VIDEO_SCREEN_SAVE_BLOCK; |
| | 185 | |
| | 186 | void LoadStrategy_VideoScreen(SAVE_BLOCK_STRATEGY_HEADER* header) |
| | 187 | { |
| | 188 | VIDEO_SCREEN_SAVE_BLOCK* block = (VIDEO_SCREEN_SAVE_BLOCK*) header; |
| | 189 | |
| | 190 | //check the size of the save block |
| | 191 | if(header->size != sizeof(*block)) |
| | 192 | return; |
| | 193 | |
| | 194 | //find the existing strategy block |
| | 195 | STRATEGYBLOCK* sbPtr = FindSBWithName(header->SBname); |
| | 196 | |
| | 197 | if(!sbPtr) |
| | 198 | return; |
| | 199 | |
| | 200 | //make sure the strategy found is of the right type |
| | 201 | if(sbPtr->type != I_BehaviourVideoScreen) |
| | 202 | return; |
| | 203 | |
| | 204 | VIDEO_SCREEN_BEHAV_BLOCK* videoScreen = (VIDEO_SCREEN_BEHAV_BLOCK*)sbPtr->dataptr; |
| | 205 | |
| | 206 | sbPtr->DamageBlock = block->DamageBlock; |
| | 207 | } |
| | 208 | |
| | 209 | void SaveStrategy_VideoScreen(STRATEGYBLOCK* sbPtr) |
| | 210 | { |
| | 211 | VIDEO_SCREEN_SAVE_BLOCK *block; |
| | 212 | VIDEO_SCREEN_BEHAV_BLOCK* videoScreen = (VIDEO_SCREEN_BEHAV_BLOCK*)sbPtr->dataptr; |
| | 213 | |
| | 214 | GET_STRATEGY_SAVE_BLOCK(block, sbPtr); |
| | 215 | |
| | 216 | block->DamageBlock = sbPtr->DamageBlock; |
| | 217 | } |