| | 1 | #include "system.h" |
| | 2 | #include "prototyp.h" |
| | 3 | #include "stratdef.h" |
| | 4 | #include "bh_types.h" |
| | 5 | #include "npc_marine.h" |
| | 6 | #include "npc_alien.h" |
| | 7 | #include "npc_xenoborg.h" |
| | 8 | #include "weapons.h" |
| | 9 | #include "particle.h" |
| | 10 | #include "net.h" |
| | 11 | #include "psndplat.h" |
| | 12 | #include "corpse.h" |
| | 13 | #include <assert.h> |
| | 14 | #include <stdlib.h> |
| | 15 | #include <string.h> |
| | 16 | #include "extents.h" |
| | 17 | |
| | 18 | extern void SetSeededFastRandom(int seed); |
| | 19 | extern SECTION * GetNamedHierarchyFromLibrary(const char * rif_name, const char * hier_name); |
| | 20 | |
| | 21 | CORPSEDATABLOCK* make_new_corpse(AVP_BEHAVIOUR_TYPE type) |
| | 22 | { |
| | 23 | CORPSEDATABLOCK *new_corpse = malloc(sizeof(CORPSEDATABLOCK)); |
| | 24 | |
| | 25 | if (NULL != new_corpse) |
| | 26 | { |
| | 27 | new_corpse->timer = 0; |
| | 28 | new_corpse->validityTimer = 0; |
| | 29 | new_corpse->SoundHandle = SOUND_NOACTIVEINDEX; |
| | 30 | new_corpse->SoundHandle2 = SOUND_NOACTIVEINDEX; |
| | 31 | new_corpse->SoundHandle3 = SOUND_NOACTIVEINDEX; |
| | 32 | new_corpse->SoundHandle4 = SOUND_NOACTIVEINDEX; |
| | 33 | new_corpse->HModelController.Deltas = NULL; |
| | 34 | new_corpse->HModelController.Root_Section = NULL; |
| | 35 | new_corpse->HModelController.section_data = NULL; |
| | 36 | new_corpse->Type = type; |
| | 37 | new_corpse->hltable = NULL; |
| | 38 | new_corpse->GibbFactor = 0; |
| | 39 | new_corpse->This_Death = NULL; |
| | 40 | new_corpse->CloakStatus = PCLOAK_Off; |
| | 41 | new_corpse->CloakTimer = 0; |
| | 42 | new_corpse->WeaponMisfireFunction = NULL; |
| | 43 | new_corpse->My_Gunflash_Section = NULL; |
| | 44 | new_corpse->TemplateRoot = NULL; |
| | 45 | new_corpse->My_Weapon = NULL; |
| | 46 | new_corpse->weapon_variable = 0; |
| | 47 | new_corpse->Android = 0; |
| | 48 | new_corpse->ARealMarine = 0; |
| | 49 | new_corpse->subtype = 0; |
| | 50 | new_corpse->Wounds = 0; |
| | 51 | new_corpse->DeathFiring = 0; |
| | 52 | new_corpse->SelfDestructTimer = 0; |
| | 53 | } |
| | 54 | |
| | 55 | return new_corpse; |
| | 56 | } |
| | 57 | |
| | 58 | /* these functions are called directly by the visibility management system */ |
| | 59 | void MakeCorpseNear(STRATEGYBLOCK *sbPtr) |
| | 60 | { |
| | 61 | CORPSEDATABLOCK *corpseData = (CORPSEDATABLOCK *)sbPtr->dataptr; |
| | 62 | assert(corpseData); |
| | 63 | |
| | 64 | DISPLAYBLOCK *dPtr = CreateActiveObject(); |
| | 65 | |
| | 66 | if(dPtr) |
| | 67 | { |
| | 68 | dPtr->ObShape = sbPtr->shapeIndex; |
| | 69 | dPtr->ShapeData = mainshapelist[sbPtr->shapeIndex]; |
| | 70 | sbPtr->DisplayBlock = dPtr; |
| | 71 | dPtr->ObStrategyBlock = sbPtr; |
| | 72 | |
| | 73 | /* need to initialise positional information in the new display block */ |
| | 74 | /*Must be done before ProveHModel*/ |
| | 75 | dPtr->ObWorld = sbPtr->DynPtr->Position; |
| | 76 | dPtr->ObEuler = sbPtr->DynPtr->OrientEuler; |
| | 77 | dPtr->ObMat = sbPtr->DynPtr->OrientMat; |
| | 78 | |
| | 79 | /* set the animation sequence, if we're a player corpse */ |
| | 80 | /* Okay, no messing, you MUST be a player corpse. */ |
| | 81 | dPtr->HModelControlBlock = &corpseData->HModelController; |
| | 82 | ProveHModel(dPtr->HModelControlBlock,dPtr); |
| | 83 | } |
| | 84 | } |
| | 85 | |
| | 86 | void SetCorpseAnimSequence_Core(STRATEGYBLOCK *sbPtr,HMODEL_SEQUENCE_TYPES type, int subtype, int length, int tweeningtime) |
| | 87 | { |
| | 88 | CORPSEDATABLOCK *corpseStatus = (CORPSEDATABLOCK *)(sbPtr->dataptr); |
| | 89 | |
| | 90 | assert(length != 0); |
| | 91 | |
| | 92 | if (tweeningtime <= 0) |
| | 93 | InitHModelSequence(&corpseStatus->HModelController,(int)type,subtype,length); |
| | 94 | else |
| | 95 | InitHModelTweening(&corpseStatus->HModelController, tweeningtime, (int)type,subtype,length,0); |
| | 96 | |
| | 97 | corpseStatus->HModelController.Playing = 1; |
| | 98 | /* Might be unset... */ |
| | 99 | } |
| | 100 | |
| | 101 | void Convert_Alien_To_Corpse(STRATEGYBLOCK *sbPtr, DEATH_DATA *this_death, const DAMAGE_PROFILE* damage) |
| | 102 | { |
| | 103 | ALIEN_STATUS_BLOCK *alienStatusPointer = (ALIEN_STATUS_BLOCK *)(sbPtr->dataptr); |
| | 104 | assert(this_death); |
| | 105 | |
| | 106 | if(SinglePlayer != AvP.PlayMode) |
| | 107 | AddNetMsg_AlienAIKilled(sbPtr, this_death->Multiplayer_Code, ALIEN_DYINGTIME, alienStatusPointer->GibbFactor, damage); |
| | 108 | |
| | 109 | CORPSEDATABLOCK *corpseDataPtr = make_new_corpse(I_BehaviourAlien); |
| | 110 | |
| | 111 | if(NULL == corpseDataPtr) |
| | 112 | { |
| | 113 | RemoveBehaviourStrategy(sbPtr); |
| | 114 | return; |
| | 115 | } |
| | 116 | |
| | 117 | corpseDataPtr->GibbFactor = alienStatusPointer->GibbFactor; |
| | 118 | corpseDataPtr->This_Death = this_death; |
| | 119 | |
| | 120 | switch (alienStatusPointer->Type) |
| | 121 | { |
| | 122 | case Standard: |
| | 123 | default: |
| | 124 | corpseDataPtr->hltable = GetThisHitLocationTable("alien"); |
| | 125 | break; |
| | 126 | case Predalien: |
| | 127 | corpseDataPtr->subtype = 1; |
| | 128 | corpseDataPtr->hltable = GetThisHitLocationTable("predalien"); |
| | 129 | break; |
| | 130 | case Praetorian: |
| | 131 | corpseDataPtr->subtype = 2; |
| | 132 | corpseDataPtr->hltable = GetThisHitLocationTable("praetorian"); |
| | 133 | } |
| | 134 | |
| | 135 | /* Remember wounds, or not? */ |
| | 136 | Splice_HModels(&corpseDataPtr->HModelController, alienStatusPointer->HModelController.section_data); |
| | 137 | |
| | 138 | /* Heh... now bin the old data block! */ |
| | 139 | if(alienStatusPointer->soundOnFire != SOUND_NOACTIVEINDEX) |
| | 140 | Sound_Stop(alienStatusPointer->soundOnFire); |
| | 141 | |
| | 142 | if(alienStatusPointer->sound_mouth != SOUND_NOACTIVEINDEX) |
| | 143 | Sound_Stop(alienStatusPointer->sound_mouth); |
| | 144 | |
| | 145 | Dispel_HModel(&alienStatusPointer->HModelController); |
| | 146 | free(sbPtr->dataptr); |
| | 147 | /* Turn into the corpse. */ |
| | 148 | sbPtr->dataptr = corpseDataPtr; |
| | 149 | sbPtr->type = I_BehaviourCorpse; |
| | 150 | |
| | 151 | SetCorpseAnimSequence_Core(sbPtr, this_death->Sequence_Type, this_death->Sub_Sequence, this_death->Sequence_Length, this_death->TweeningTime); |
| | 152 | |
| | 153 | if (sbPtr->DisplayBlock) |
| | 154 | { |
| | 155 | /* Swap controllers round. */ |
| | 156 | sbPtr->DisplayBlock->HModelControlBlock = &corpseDataPtr->HModelController; |
| | 157 | ProveHModel(&corpseDataPtr->HModelController, sbPtr->DisplayBlock); |
| | 158 | } |
| | 159 | else |
| | 160 | { |
| | 161 | ProveHModel_Far(&corpseDataPtr->HModelController, sbPtr); |
| | 162 | } |
| | 163 | |
| | 164 | corpseDataPtr->timer = ALIEN_DYINGTIME; |
| | 165 | corpseDataPtr->validityTimer = CORPSE_VALIDITY_TIME; |
| | 166 | corpseDataPtr->HModelController.Looped = 0; |
| | 167 | corpseDataPtr->HModelController.LoopAfterTweening = 0; |
| | 168 | |
| | 169 | /* stop motion */ |
| | 170 | sbPtr->DynPtr->Friction = 400000; |
| | 171 | sbPtr->DynPtr->LinImpulse.vx += sbPtr->DynPtr->LinVelocity.vx; |
| | 172 | sbPtr->DynPtr->LinImpulse.vy += sbPtr->DynPtr->LinVelocity.vy; |
| | 173 | sbPtr->DynPtr->LinImpulse.vz += sbPtr->DynPtr->LinVelocity.vz; |
| | 174 | sbPtr->DynPtr->LinVelocity.vx = sbPtr->DynPtr->LinVelocity.vy = sbPtr->DynPtr->LinVelocity.vz = 0; |
| | 175 | sbPtr->DynPtr->CanClimbStairs = 0; |
| | 176 | sbPtr->DynPtr->UseStandardGravity = 1; |
| | 177 | |
| | 178 | /* KJL 17:19:35 27/08/98 - ignore the player, other body parts, etc */ |
| | 179 | sbPtr->DynPtr->OnlyCollideWithEnvironment = 1; |
| | 180 | |
| | 181 | /* Electric death sound? */ |
| | 182 | if (corpseDataPtr->This_Death->Electrical) |
| | 183 | Sound_Play(SID_ELEC_DEATH, "de", &sbPtr->DynPtr->Position, &corpseDataPtr->SoundHandle4); |
| | 184 | } |
| | 185 | |
| | 186 | void Convert_Predator_To_Corpse(STRATEGYBLOCK *sbPtr, DEATH_DATA *this_death) |
| | 187 | { |
| | 188 | PREDATOR_STATUS_BLOCK *predatorStatusPointer = (PREDATOR_STATUS_BLOCK *)(sbPtr->dataptr); |
| | 189 | CORPSEDATABLOCK *corpseDataPtr = make_new_corpse(I_BehaviourPredator); |
| | 190 | |
| | 191 | if(NULL == corpseDataPtr) |
| | 192 | { |
| | 193 | RemoveBehaviourStrategy(sbPtr); |
| | 194 | return; |
| | 195 | } |
| | 196 | |
| | 197 | if (PBS_SelfDestruct == predatorStatusPointer->behaviourState) |
| | 198 | { |
| | 199 | if (1 == predatorStatusPointer->internalState) |
| | 200 | corpseDataPtr->SelfDestructTimer = predatorStatusPointer->stateTimer; |
| | 201 | } |
| | 202 | |
| | 203 | corpseDataPtr->GibbFactor = predatorStatusPointer->GibbFactor; |
| | 204 | corpseDataPtr->This_Death = this_death; |
| | 205 | corpseDataPtr->CloakStatus = predatorStatusPointer->CloakStatus; |
| | 206 | corpseDataPtr->CloakTimer = predatorStatusPointer->CloakTimer; |
| | 207 | |
| | 208 | corpseDataPtr->hltable = GetThisHitLocationTable(predatorStatusPointer->Selected_Weapon->HitLocationTableName); |
| | 209 | |
| | 210 | /* Remember wounds, or not? */ |
| | 211 | Splice_HModels(&corpseDataPtr->HModelController, predatorStatusPointer->HModelController.section_data); |
| | 212 | |
| | 213 | if (this_death->Template) |
| | 214 | { |
| | 215 | /* Convert to template. */ |
| | 216 | SECTION *root = GetNamedHierarchyFromLibrary("hnpcpredator", "Template"); |
| | 217 | Transmogrify_HModels(sbPtr, &corpseDataPtr->HModelController, root, 1, 0, 0); |
| | 218 | } |
| | 219 | |
| | 220 | /* Heh... now bin the old data block! */ |
| | 221 | if(predatorStatusPointer->soundHandle != SOUND_NOACTIVEINDEX) |
| | 222 | Sound_Stop(predatorStatusPointer->soundHandle); |
| | 223 | |
| | 224 | Dispel_HModel(&predatorStatusPointer->HModelController); |
| | 225 | free(sbPtr->dataptr); |
| | 226 | /* Turn into the corpse. */ |
| | 227 | sbPtr->dataptr = corpseDataPtr; |
| | 228 | sbPtr->type = I_BehaviourCorpse; |
| | 229 | |
| | 230 | SetCorpseAnimSequence_Core(sbPtr, this_death->Sequence_Type, this_death->Sub_Sequence, this_death->Sequence_Length, this_death->TweeningTime); |
| | 231 | |
| | 232 | if (sbPtr->DisplayBlock) |
| | 233 | { |
| | 234 | /* Swap controllers round. */ |
| | 235 | sbPtr->DisplayBlock->HModelControlBlock = &corpseDataPtr->HModelController; |
| | 236 | ProveHModel(&corpseDataPtr->HModelController, sbPtr->DisplayBlock); |
| | 237 | } |
| | 238 | else |
| | 239 | { |
| | 240 | ProveHModel_Far(&corpseDataPtr->HModelController, sbPtr); |
| | 241 | } |
| | 242 | |
| | 243 | corpseDataPtr->timer = PRED_DIETIME; |
| | 244 | corpseDataPtr->validityTimer = CORPSE_VALIDITY_TIME; |
| | 245 | corpseDataPtr->HModelController.Looped = 0; |
| | 246 | corpseDataPtr->HModelController.LoopAfterTweening = 0; |
| | 247 | |
| | 248 | /* stop motion */ |
| | 249 | sbPtr->DynPtr->Friction = 400000; |
| | 250 | sbPtr->DynPtr->LinImpulse.vx += sbPtr->DynPtr->LinVelocity.vx; |
| | 251 | sbPtr->DynPtr->LinImpulse.vy += sbPtr->DynPtr->LinVelocity.vy; |
| | 252 | sbPtr->DynPtr->LinImpulse.vz += sbPtr->DynPtr->LinVelocity.vz; |
| | 253 | sbPtr->DynPtr->LinVelocity.vx = sbPtr->DynPtr->LinVelocity.vy = sbPtr->DynPtr->LinVelocity.vz = 0; |
| | 254 | sbPtr->DynPtr->CanClimbStairs = 0; |
| | 255 | |
| | 256 | /* KJL 17:19:35 27/08/98 - ignore the player, other body parts, etc */ |
| | 257 | sbPtr->DynPtr->OnlyCollideWithEnvironment = 1; |
| | 258 | /* Electric death sound? */ |
| | 259 | |
| | 260 | if (corpseDataPtr->This_Death->Electrical) |
| | 261 | Sound_Play(SID_ELEC_DEATH, "de", &sbPtr->DynPtr->Position, &corpseDataPtr->SoundHandle4); |
| | 262 | } |
| | 263 | |
| | 264 | void Convert_Marine_To_Corpse(STRATEGYBLOCK *sbPtr, DEATH_DATA *this_death) |
| | 265 | { |
| | 266 | MARINE_STATUS_BLOCK *marineStatusPointer = (MARINE_STATUS_BLOCK *)(sbPtr->dataptr); |
| | 267 | CORPSEDATABLOCK *corpseDataPtr = make_new_corpse(I_BehaviourMarine); |
| | 268 | |
| | 269 | if(NULL == corpseDataPtr) |
| | 270 | { |
| | 271 | RemoveBehaviourStrategy(sbPtr); |
| | 272 | return; |
| | 273 | } |
| | 274 | |
| | 275 | corpseDataPtr->GibbFactor = marineStatusPointer->GibbFactor; |
| | 276 | corpseDataPtr->This_Death = this_death; |
| | 277 | |
| | 278 | corpseDataPtr->My_Weapon = marineStatusPointer->My_Weapon; |
| | 279 | corpseDataPtr->WeaponMisfireFunction = marineStatusPointer->My_Weapon->WeaponMisfireFunction; |
| | 280 | corpseDataPtr->My_Gunflash_Section = marineStatusPointer->My_Gunflash_Section; |
| | 281 | corpseDataPtr->TemplateRoot = GetNamedHierarchyFromLibrary(marineStatusPointer->My_Weapon->Riffname,
marineStatusPointer->My_Weapon->TemplateName); |
| | 282 | corpseDataPtr->Android = marineStatusPointer->Android; |
| | 283 | corpseDataPtr->ARealMarine = marineStatusPointer->My_Weapon->ARealMarine; |
| | 284 | corpseDataPtr->hltable = GetThisHitLocationTable(marineStatusPointer->My_Weapon->HitLocationTableName); |
| | 285 | |
| | 286 | if (corpseDataPtr->WeaponMisfireFunction) |
| | 287 | { |
| | 288 | if (marineStatusPointer->behaviourState == MBS_Firing) |
| | 289 | corpseDataPtr->DeathFiring = 1; |
| | 290 | } |
| | 291 | |
| | 292 | /* Remember wounds, or not? */ |
| | 293 | Splice_HModels(&corpseDataPtr->HModelController, marineStatusPointer->HModelController.section_data); |
| | 294 | |
| | 295 | /* Convert to template. */ |
| | 296 | if (this_death->Template) |
| | 297 | Transmogrify_HModels(sbPtr, &corpseDataPtr->HModelController, corpseDataPtr->TemplateRoot, 1, 0, 0); |
| | 298 | |
| | 299 | /* Pass over some sounds? */ |
| | 300 | |
| | 301 | /* Heh... now bin the old data block! */ |
| | 302 | if(marineStatusPointer->soundHandle != SOUND_NOACTIVEINDEX) |
| | 303 | Sound_Stop(marineStatusPointer->soundHandle); |
| | 304 | |
| | 305 | if(marineStatusPointer->soundHandle2 != SOUND_NOACTIVEINDEX) |
| | 306 | { |
| | 307 | /* soundHandle2 is the voice! */ |
| | 308 | corpseDataPtr->SoundHandle2 = marineStatusPointer->soundHandle2; |
| | 309 | ActiveSounds[marineStatusPointer->soundHandle2].externalRef = &corpseDataPtr->SoundHandle2; |
| | 310 | } |
| | 311 | |
| | 312 | Dispel_HModel(&marineStatusPointer->HModelController); |
| | 313 | free(sbPtr->dataptr); |
| | 314 | /* Turn into the corpse. */ |
| | 315 | sbPtr->dataptr = corpseDataPtr; |
| | 316 | sbPtr->type = I_BehaviourCorpse; |
| | 317 | |
| | 318 | SetCorpseAnimSequence_Core(sbPtr, this_death->Sequence_Type, this_death->Sub_Sequence, this_death->Sequence_Length, this_death->TweeningTime); |
| | 319 | |
| | 320 | if (sbPtr->DisplayBlock) |
| | 321 | { |
| | 322 | /* Swap controllers round. */ |
| | 323 | sbPtr->DisplayBlock->HModelControlBlock = &corpseDataPtr->HModelController; |
| | 324 | ProveHModel(&corpseDataPtr->HModelController, sbPtr->DisplayBlock); |
| | 325 | } |
| | 326 | else |
| | 327 | { |
| | 328 | ProveHModel_Far(&corpseDataPtr->HModelController, sbPtr); |
| | 329 | } |
| | 330 | |
| | 331 | corpseDataPtr->timer = MARINE_DYINGTIME; |
| | 332 | corpseDataPtr->validityTimer = CORPSE_VALIDITY_TIME; |
| | 333 | corpseDataPtr->HModelController.Looped = 0; |
| | 334 | corpseDataPtr->HModelController.LoopAfterTweening = 0; |
| | 335 | |
| | 336 | /* stop motion */ |
| | 337 | sbPtr->DynPtr->Friction = 400000; |
| | 338 | sbPtr->DynPtr->LinImpulse.vx += sbPtr->DynPtr->LinVelocity.vx; |
| | 339 | sbPtr->DynPtr->LinImpulse.vy += sbPtr->DynPtr->LinVelocity.vy; |
| | 340 | sbPtr->DynPtr->LinImpulse.vz += sbPtr->DynPtr->LinVelocity.vz; |
| | 341 | sbPtr->DynPtr->LinVelocity.vx = sbPtr->DynPtr->LinVelocity.vy = sbPtr->DynPtr->LinVelocity.vz = 0; |
| | 342 | sbPtr->DynPtr->CanClimbStairs = 0; |
| | 343 | |
| | 344 | /* KJL 17:19:35 27/08/98 - ignore the player, other body parts, etc */ |
| | 345 | //sbPtr->DynPtr->OnlyCollideWithEnvironment = 1; |
| | 346 | |
| | 347 | /* Electric death sound? */ |
| | 348 | if (corpseDataPtr->This_Death->Electrical) |
| | 349 | Sound_Play(SID_ELEC_DEATH, "de", &sbPtr->DynPtr->Position, &corpseDataPtr->SoundHandle4); |
| | 350 | } |
| | 351 | |
| | 352 | void Convert_Xenoborg_To_Corpse(STRATEGYBLOCK *sbPtr,DEATH_DATA *this_death) |
| | 353 | { |
| | 354 | XENO_STATUS_BLOCK *xenoStatusPointer = (XENO_STATUS_BLOCK *)(sbPtr->dataptr); |
| | 355 | CORPSEDATABLOCK *corpseDataPtr = make_new_corpse(I_BehaviourXenoborg); |
| | 356 | |
| | 357 | if(NULL == corpseDataPtr) |
| | 358 | { |
| | 359 | RemoveBehaviourStrategy(sbPtr); |
| | 360 | return; |
| | 361 | } |
| | 362 | |
| | 363 | corpseDataPtr->GibbFactor = xenoStatusPointer->GibbFactor; |
| | 364 | corpseDataPtr->This_Death = this_death; |
| | 365 | corpseDataPtr->hltable = GetThisHitLocationTable("xenoborg"); |
| | 366 | |
| | 367 | /* Remember wounds, or not? */ |
| | 368 | Splice_HModels(&corpseDataPtr->HModelController, xenoStatusPointer->HModelController.section_data); |
| | 369 | |
| | 370 | /* Heh... now bin the old data block! */ |
| | 371 | Dispel_HModel(&xenoStatusPointer->HModelController); |
| | 372 | free(sbPtr->dataptr); |
| | 373 | /* Turn into the corpse. */ |
| | 374 | sbPtr->dataptr = corpseDataPtr; |
| | 375 | sbPtr->type = I_BehaviourCorpse; |
| | 376 | |
| | 377 | SetCorpseAnimSequence_Core(sbPtr, this_death->Sequence_Type, this_death->Sub_Sequence, this_death->Sequence_Length, this_death->TweeningTime); |
| | 378 | |
| | 379 | if (sbPtr->DisplayBlock) |
| | 380 | { |
| | 381 | /* Swap controllers round. */ |
| | 382 | sbPtr->DisplayBlock->HModelControlBlock = &corpseDataPtr->HModelController; |
| | 383 | ProveHModel(&corpseDataPtr->HModelController, sbPtr->DisplayBlock); |
| | 384 | } |
| | 385 | else |
| | 386 | { |
| | 387 | ProveHModel_Far(&corpseDataPtr->HModelController, sbPtr); |
| | 388 | } |
| | 389 | |
| | 390 | corpseDataPtr->timer = XENO_DYINGTIME; |
| | 391 | corpseDataPtr->validityTimer = CORPSE_VALIDITY_TIME; |
| | 392 | corpseDataPtr->HModelController.Looped = 0; |
| | 393 | corpseDataPtr->HModelController.LoopAfterTweening = 0; |
| | 394 | |
| | 395 | /* stop motion */ |
| | 396 | sbPtr->DynPtr->Friction = 400000; |
| | 397 | sbPtr->DynPtr->LinImpulse.vx += sbPtr->DynPtr->LinVelocity.vx; |
| | 398 | sbPtr->DynPtr->LinImpulse.vy += sbPtr->DynPtr->LinVelocity.vy; |
| | 399 | sbPtr->DynPtr->LinImpulse.vz += sbPtr->DynPtr->LinVelocity.vz; |
| | 400 | sbPtr->DynPtr->LinVelocity.vx = sbPtr->DynPtr->LinVelocity.vy = sbPtr->DynPtr->LinVelocity.vz = 0; |
| | 401 | sbPtr->DynPtr->CanClimbStairs = 0; |
| | 402 | sbPtr->DynPtr->UseStandardGravity = 1; |
| | 403 | |
| | 404 | /* KJL 17:19:35 27/08/98 - ignore the player, other body parts, etc */ |
| | 405 | sbPtr->DynPtr->OnlyCollideWithEnvironment = 1; |
| | 406 | } |
| | 407 | |
| | 408 | void CorpseBehaveFun(STRATEGYBLOCK *sbPtr) |
| | 409 | { |
| | 410 | /* Just count down. */ |
| | 411 | assert(sbPtr); |
| | 412 | |
| | 413 | CORPSEDATABLOCK *corpseDataPtr = (CORPSEDATABLOCK *)sbPtr->dataptr; |
| | 414 | |
| | 415 | if(corpseDataPtr->SelfDestructTimer) |
| | 416 | { |
| | 417 | corpseDataPtr->SelfDestructTimer -= NormalFrameTime; |
| | 418 | |
| | 419 | if (corpseDataPtr->SelfDestructTimer < 0) |
| | 420 | { |
| | 421 | corpseDataPtr->SelfDestructTimer = 0; |
| | 422 | corpseDataPtr->GibbFactor = ONE_FIXED; |
| | 423 | MakeVolumetricExplosionAt(&sbPtr->DynPtr->Position, EXPLOSION_SADAR_BLAST); |
| | 424 | Sound_Play(SID_NICE_EXPLOSION, "d", &sbPtr->DynPtr->Position); |
| | 425 | } |
| | 426 | } |
| | 427 | else if (corpseDataPtr->timer > 0) |
| | 428 | { |
| | 429 | if (sbPtr->DisplayBlock) |
| | 430 | { |
| | 431 | sbPtr->DisplayBlock->SpecialFXFlags |= SFXFLAG_MELTINGINTOGROUND; |
| | 432 | sbPtr->DisplayBlock->ObFlags2 = corpseDataPtr->timer / 2; |
| | 433 | } |
| | 434 | |
| | 435 | /* Does the corpse that falls when not visible make no sound? */ |
| | 436 | ProveHModel_Far(&corpseDataPtr->HModelController, sbPtr); |
| | 437 | |
| | 438 | corpseDataPtr->timer -= NormalFrameTime; |
| | 439 | corpseDataPtr->validityTimer -= NormalFrameTime; |
| | 440 | |
| | 441 | switch(corpseDataPtr->Type) |
| | 442 | { |
| | 443 | case I_BehaviourPredator: |
| | 444 | case I_BehaviourPredatorPlayer: |
| | 445 | { |
| | 446 | /* If we're a partially cloaked predator, continue to decloak. */ |
| | 447 | switch(corpseDataPtr->CloakStatus) |
| | 448 | { |
| | 449 | case PCLOAK_Deactivating: |
| | 450 | case PCLOAK_Off: |
| | 451 | /* Do nothing. */ |
| | 452 | break; |
| | 453 | case PCLOAK_Activating: |
| | 454 | /* Don't reset timer. */ |
| | 455 | corpseDataPtr->CloakStatus = PCLOAK_Deactivating; |
| | 456 | break; |
| | 457 | default: |
| | 458 | { |
| | 459 | /* Cloak must be On. */ |
| | 460 | corpseDataPtr->CloakStatus = PCLOAK_Deactivating; |
| | 461 | corpseDataPtr->CloakTimer = 0; /* Was predStatus->PredShimmer. */ |
| | 462 | } |
| | 463 | } |
| | 464 | |
| | 465 | if (corpseDataPtr->CloakStatus == PCLOAK_Deactivating) |
| | 466 | { |
| | 467 | corpseDataPtr->CloakTimer += NormalFrameTime; |
| | 468 | |
| | 469 | if(corpseDataPtr->CloakTimer >= (ONE_FIXED)) |
| | 470 | { |
| | 471 | corpseDataPtr->CloakTimer = 0; |
| | 472 | corpseDataPtr->CloakStatus = PCLOAK_Off; |
| | 473 | } |
| | 474 | } |
| | 475 | } |
| | 476 | break; |
| | 477 | case I_BehaviourMarine: |
| | 478 | { |
| | 479 | /* Did marine die with the trigger held down? */ |
| | 480 | if (corpseDataPtr->DeathFiring && corpseDataPtr->My_Gunflash_Section) |
| | 481 | { |
| | 482 | /* But is it still attached? */ |
| | 483 | if (corpseDataPtr->My_Gunflash_Section->my_controller == &corpseDataPtr->HModelController) |
| | 484 | { |
| | 485 | /* Keep firing! */ |
| | 486 | assert(corpseDataPtr->WeaponMisfireFunction); |
| | 487 | /* Shouldn't be doing this without knowing why. */ |
| | 488 | (*corpseDataPtr->WeaponMisfireFunction)(corpseDataPtr->My_Gunflash_Section, &corpseDataPtr->weapon_variable); |
| | 489 | } |
| | 490 | } |
| | 491 | |
| | 492 | /* Do we want to trim off the weapons? */ |
| | 493 | |
| | 494 | if (corpseDataPtr->HModelController.keyframe_flags) |
| | 495 | { |
| | 496 | assert(corpseDataPtr->TemplateRoot); |
| | 497 | TrimToTemplate(sbPtr,&corpseDataPtr->HModelController,corpseDataPtr->TemplateRoot, 1); |
| | 498 | } |
| | 499 | } // no break |
| | 500 | case I_BehaviourMarinePlayer: |
| | 501 | { |
| | 502 | /* May get decapitated whilst screaming... */ |
| | 503 | SECTION_DATA *head = GetThisSectionData(corpseDataPtr->HModelController.section_data, "head"); |
| | 504 | |
| | 505 | /* Is it still attached? */ |
| | 506 | if (head && !(head->flags & section_data_notreal)) |
| | 507 | { |
| | 508 | if(corpseDataPtr->SoundHandle2 != SOUND_NOACTIVEINDEX) |
| | 509 | Sound_Stop(corpseDataPtr->SoundHandle2); |
| | 510 | } |
| | 511 | } |
| | 512 | break; |
| | 513 | case I_BehaviourXenoborg: |
| | 514 | { |
| | 515 | if (sbPtr->DisplayBlock) |
| | 516 | { |
| | 517 | /* Particularly important for xenoborgs... optional for others? */ |
| | 518 | if (sbPtr->DisplayBlock->ObFlags2 < ONE_FIXED) |
| | 519 | corpseDataPtr->HModelController.DisableBleeding = 1; |
| | 520 | } |
| | 521 | } |
| | 522 | default: |
| | 523 | break; |
| | 524 | } |
| | 525 | |
| | 526 | if(corpseDataPtr->SoundHandle4 != SOUND_NOACTIVEINDEX) |
| | 527 | Sound_Update3d(corpseDataPtr->SoundHandle4, &sbPtr->DynPtr->Position); |
| | 528 | |
| | 529 | |
| | 530 | if (sbPtr->DamageBlock.IsOnFire) |
| | 531 | { |
| | 532 | if(corpseDataPtr->SoundHandle3 != SOUND_NOACTIVEINDEX) |
| | 533 | Sound_Update3d(corpseDataPtr->SoundHandle3, &sbPtr->DynPtr->Position); |
| | 534 | else |
| | 535 | Sound_Play(SID_FIRE, "dle", &sbPtr->DynPtr->Position, &corpseDataPtr->SoundHandle3); |
| | 536 | } |
| | 537 | else |
| | 538 | { |
| | 539 | if (corpseDataPtr->SoundHandle3 != SOUND_NOACTIVEINDEX) |
| | 540 | Sound_Stop(corpseDataPtr->SoundHandle3); |
| | 541 | } |
| | 542 | } |
| | 543 | else |
| | 544 | { |
| | 545 | if(corpseDataPtr->SoundHandle != SOUND_NOACTIVEINDEX) Sound_Stop(corpseDataPtr->SoundHandle); |
| | 546 | if(corpseDataPtr->SoundHandle2 != SOUND_NOACTIVEINDEX) Sound_Stop(corpseDataPtr->SoundHandle2); |
| | 547 | if(corpseDataPtr->SoundHandle3 != SOUND_NOACTIVEINDEX) Sound_Stop(corpseDataPtr->SoundHandle3); |
| | 548 | if(corpseDataPtr->SoundHandle4 != SOUND_NOACTIVEINDEX) Sound_Stop(corpseDataPtr->SoundHandle4); |
| | 549 | |
| | 550 | sbPtr->please_destroy_me = 1; |
| | 551 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 552 | } |
| | 553 | } |
| | 554 | |
| | 555 | void CorpseIsDamaged(STRATEGYBLOCK *sbPtr, const DAMAGE_PROFILE *damage, int wounds, VECTORCH *incoming) |
| | 556 | { |
| | 557 | CORPSEDATABLOCK *corpseDataPtr = (CORPSEDATABLOCK *)sbPtr->dataptr; |
| | 558 | corpseDataPtr->Wounds |= wounds; |
| | 559 | |
| | 560 | if(damage->ExplosivePower) |
| | 561 | { |
| | 562 | Extreme_Gibbing(sbPtr, corpseDataPtr->HModelController.section_data, ONE_FIXED, incoming); |
| | 563 | sbPtr->please_destroy_me = 1; |
| | 564 | } |
| | 565 | } |
| | 566 | |
| | 567 | /*--------------------** |
| | 568 | ** Loading and Saving ** |
| | 569 | **--------------------*/ |
| | 570 | #include "savegame.h" |
| | 571 | typedef struct corpse_save_block |
| | 572 | { |
| | 573 | SAVE_BLOCK_STRATEGY_HEADER header; |
| | 574 | |
| | 575 | int timer; |
| | 576 | int validityTimer; |
| | 577 | |
| | 578 | AVP_BEHAVIOUR_TYPE Type; |
| | 579 | int hltable_index; |
| | 580 | int GibbFactor; |
| | 581 | |
| | 582 | /* If you're a predator... */ |
| | 583 | PRED_CLOAKSTATE CloakStatus; |
| | 584 | int CloakTimer; |
| | 585 | /* If you're a marine... */ |
| | 586 | int weapon_id; |
| | 587 | int weapon_variable; |
| | 588 | int Android; |
| | 589 | int ARealMarine; |
| | 590 | /* If you're an alien... */ |
| | 591 | int subtype; |
| | 592 | int Wounds; |
| | 593 | int DeathFiring :1; |
| | 594 | int SelfDestructTimer; |
| | 595 | int deathCode; |
| | 596 | |
| | 597 | //strategyblock stuff |
| | 598 | DAMAGEBLOCK DamageBlock; |
| | 599 | DYNAMICSBLOCK dynamics; |
| | 600 | |
| | 601 | } CORPSE_SAVE_BLOCK; |
| | 602 | |
| | 603 | //defines for load/save macros |
| | 604 | #define SAVELOAD_BLOCK block |
| | 605 | #define SAVELOAD_BEHAV corpseDataPtr |
| | 606 | |
| | 607 | void LoadStrategy_Corpse(SAVE_BLOCK_STRATEGY_HEADER* header) |
| | 608 | { |
| | 609 | extern HITLOCATIONTABLE Global_Hitlocation_Tables[]; |
| | 610 | |
| | 611 | CORPSE_SAVE_BLOCK* block = (CORPSE_SAVE_BLOCK*) header; |
| | 612 | |
| | 613 | //check the size of the save block |
| | 614 | if(header->size != sizeof(*block)) |
| | 615 | return; |
| | 616 | |
| | 617 | //see if there is a living version of this corpse |
| | 618 | STRATEGYBLOCK* sbPtr = FindSBWithName(header->SBname); |
| | 619 | |
| | 620 | if(sbPtr) |
| | 621 | { |
| | 622 | //make sure the strategy found is some type of creature |
| | 623 | switch(sbPtr->type) |
| | 624 | { |
| | 625 | case I_BehaviourAlien: |
| | 626 | case I_BehaviourMarine: |
| | 627 | case I_BehaviourPredator: |
| | 628 | case I_BehaviourDormantPredator: |
| | 629 | case I_BehaviourXenoborg: |
| | 630 | case I_BehaviourFaceHugger: |
| | 631 | //get rid of it then |
| | 632 | sbPtr->please_destroy_me = 1; |
| | 633 | RemoveBehaviourStrategy(sbPtr); |
| | 634 | break; |
| | 635 | default: |
| | 636 | return; |
| | 637 | } |
| | 638 | } |
| | 639 | |
| | 640 | //now we need to create a corpse from scratch |
| | 641 | sbPtr = CreateActiveStrategyBlock(I_BehaviourCorpse); |
| | 642 | |
| | 643 | if(!sbPtr) |
| | 644 | { |
| | 645 | assert(0=="Run out of strategy blocks"); |
| | 646 | return; |
| | 647 | } |
| | 648 | |
| | 649 | CORPSEDATABLOCK *corpseDataPtr = make_new_corpse(I_BehaviourCorpse); |
| | 650 | |
| | 651 | if(NULL == corpseDataPtr) |
| | 652 | { |
| | 653 | RemoveBehaviourStrategy(sbPtr); |
| | 654 | return; |
| | 655 | } |
| | 656 | |
| | 657 | sbPtr->dataptr = corpseDataPtr; |
| | 658 | COPY_NAME(sbPtr->SBname,block->header.SBname); |
| | 659 | sbPtr->maintainVisibility = 1; |
| | 660 | |
| | 661 | //get a dynamics block |
| | 662 | sbPtr->DynPtr = AllocateDynamicsBlock(DYNAMICS_TEMPLATE_DEFAULT); |
| | 663 | |
| | 664 | //start copying stuff |
| | 665 | |
| | 666 | COPYELEMENT_LOAD(timer) |
| | 667 | COPYELEMENT_LOAD(validityTimer) |
| | 668 | COPYELEMENT_LOAD(Type) |
| | 669 | COPYELEMENT_LOAD(GibbFactor) |
| | 670 | COPYELEMENT_LOAD(CloakStatus) |
| | 671 | COPYELEMENT_LOAD(CloakTimer) |
| | 672 | COPYELEMENT_LOAD(weapon_variable) |
| | 673 | COPYELEMENT_LOAD(Android) |
| | 674 | COPYELEMENT_LOAD(ARealMarine) |
| | 675 | COPYELEMENT_LOAD(subtype) |
| | 676 | COPYELEMENT_LOAD(Wounds) |
| | 677 | COPYELEMENT_LOAD(DeathFiring) |
| | 678 | COPYELEMENT_LOAD(SelfDestructTimer) |
| | 679 | |
| | 680 | //copy strategy block stuff |
| | 681 | *sbPtr->DynPtr = block->dynamics; |
| | 682 | sbPtr->DamageBlock = block->DamageBlock; |
| | 683 | |
| | 684 | if(-1 != block->hltable_index) |
| | 685 | corpseDataPtr->hltable = &Global_Hitlocation_Tables[block->hltable_index]; |
| | 686 | |
| | 687 | if(1 != block->deathCode) |
| | 688 | corpseDataPtr->This_Death = GetThisDeath_FromUniqueCode(block->deathCode); |
| | 689 | |
| | 690 | //get marine's weapon (if a marine) |
| | 691 | if(-1 != block->weapon_id) |
| | 692 | { |
| | 693 | corpseDataPtr->My_Weapon = GetThisNPCMarineWeapon(block->weapon_id); |
| | 694 | |
| | 695 | if(corpseDataPtr->My_Weapon) |
| | 696 | { |
| | 697 | corpseDataPtr->WeaponMisfireFunction = corpseDataPtr->My_Weapon->WeaponMisfireFunction; |
| | 698 | corpseDataPtr->My_Gunflash_Section = corpseDataPtr->My_Gunflash_Section; |
| | 699 | corpseDataPtr->TemplateRoot =
GetNamedHierarchyFromLibrary(corpseDataPtr->My_Weapon->Riffname,corpseDataPtr->My_Weapon->TemplateName); |
| | 700 | } |
| | 701 | } |
| | 702 | |
| | 703 | //load the corpse's hierarchy |
| | 704 | { |
| | 705 | SAVE_BLOCK_HEADER* hier_header = GetNextBlockIfOfType(SaveBlock_Hierarchy); |
| | 706 | |
| | 707 | if(hier_header) |
| | 708 | LoadHierarchy(hier_header, &corpseDataPtr->HModelController); |
| | 709 | } |
| | 710 | |
| | 711 | Load_SoundState(&corpseDataPtr->SoundHandle); |
| | 712 | Load_SoundState(&corpseDataPtr->SoundHandle2); |
| | 713 | Load_SoundState(&corpseDataPtr->SoundHandle3); |
| | 714 | Load_SoundState(&corpseDataPtr->SoundHandle4); |
| | 715 | } |
| | 716 | |
| | 717 | void SaveStrategy_Corpse(STRATEGYBLOCK* sbPtr) |
| | 718 | { |
| | 719 | CORPSE_SAVE_BLOCK *block; |
| | 720 | CORPSEDATABLOCK* corpseDataPtr = (CORPSEDATABLOCK*)sbPtr->dataptr; |
| | 721 | |
| | 722 | GET_STRATEGY_SAVE_BLOCK(block,sbPtr); |
| | 723 | |
| | 724 | //start copying stuff |
| | 725 | |
| | 726 | COPYELEMENT_SAVE(timer) |
| | 727 | COPYELEMENT_SAVE(validityTimer) |
| | 728 | COPYELEMENT_SAVE(Type) |
| | 729 | COPYELEMENT_SAVE(GibbFactor) |
| | 730 | COPYELEMENT_SAVE(CloakStatus) |
| | 731 | COPYELEMENT_SAVE(CloakTimer) |
| | 732 | COPYELEMENT_SAVE(weapon_variable) |
| | 733 | COPYELEMENT_SAVE(Android) |
| | 734 | COPYELEMENT_SAVE(ARealMarine) |
| | 735 | COPYELEMENT_SAVE(subtype) |
| | 736 | COPYELEMENT_SAVE(Wounds) |
| | 737 | COPYELEMENT_SAVE(DeathFiring) |
| | 738 | COPYELEMENT_SAVE(SelfDestructTimer) |
| | 739 | |
| | 740 | block->hltable_index = corpseDataPtr->hltable ? corpseDataPtr->hltable->index : -1; |
| | 741 | block->deathCode = corpseDataPtr->This_Death ? corpseDataPtr->This_Death->Unique_Code : -1; |
| | 742 | block->weapon_id = corpseDataPtr->My_Weapon ? corpseDataPtr->My_Weapon->id : -1; |
| | 743 | |
| | 744 | //save strategy block stuff |
| | 745 | |
| | 746 | block->dynamics = *sbPtr->DynPtr; |
| | 747 | block->dynamics.CollisionReportPtr =0 ; |
| | 748 | block->DamageBlock = sbPtr->DamageBlock; |
| | 749 | |
| | 750 | //save the hierarchy |
| | 751 | SaveHierarchy(&corpseDataPtr->HModelController); |
| | 752 | |
| | 753 | Save_SoundState(&corpseDataPtr->SoundHandle); |
| | 754 | Save_SoundState(&corpseDataPtr->SoundHandle2); |
| | 755 | Save_SoundState(&corpseDataPtr->SoundHandle3); |
| | 756 | Save_SoundState(&corpseDataPtr->SoundHandle4); |
| | 757 | } |