| | 1 | #include "system.h" |
| | 2 | #include "prototyp.h" |
| | 3 | #include "stratdef.h" |
| | 4 | #include "bh_types.h" |
| | 5 | #include "weaponbehaviour.h" |
| | 6 | #include "debris.h" |
| | 7 | #include "weapons.h" |
| | 8 | #include "dynamics.h" |
| | 9 | #include "lighting.h" |
| | 10 | #include "npc_alien.h" |
| | 11 | #include "pheromon.h" |
| | 12 | #include "psndplat.h" |
| | 13 | #include "targeting.h" |
| | 14 | #include "game_statistics.h" |
| | 15 | #include "sfx.h" |
| | 16 | #include "savegame.h" |
| | 17 | #include "los.h" |
| | 18 | #include "userprofile.h" |
| | 19 | #include "pldghost.h" |
| | 20 | #include <stdio.h> |
| | 21 | #include <stdlib.h> |
| | 22 | #include <string.h> |
| | 23 | #include <assert.h> |
| | 24 | #include "scream.h" |
| | 25 | |
| | 26 | #define FLAMETHROWER_PARTICLES_PER_FRAME (MUL_FIXED(120,NormalFrameTime)) |
| | 27 | |
| | 28 | #define FRISBEE_SPEED 20000 |
| | 29 | #define ENERGY_BOLT_SPEED (ONE_FIXED * 4) |
| | 30 | |
| | 31 | extern SECTION * GetNamedHierarchyFromLibrary(const char * rif_name, const char * hier_name); |
| | 32 | extern int SlotForThisWeapon(enum WEAPON_ID weaponID); |
| | 33 | extern void AutoSwapToDisc(); |
| | 34 | extern int GetLoadedShapeMSL(char const * shapename); |
| | 35 | |
| | 36 | extern MATRIXCH IdentityMatrix; |
| | 37 | |
| | 38 | int PredPistolBoltGravity = 80000; |
| | 39 | int PredPistolBoltSpeed = 32767; |
| | 40 | int Caster_BlastRadius = 5000; |
| | 41 | |
| | 42 | SOUND3DDATA Explosion_SoundData = |
| | 43 | { |
| | 44 | {0,0,0,}, |
| | 45 | {0,0,0,}, |
| | 46 | 15000, |
| | 47 | 150000, |
| | 48 | }; |
| | 49 | |
| | 50 | static void RubberDuckBehaviour(STRATEGYBLOCK *sbPtr) |
| | 51 | { |
| | 52 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr; |
| | 53 | |
| | 54 | if (!sbPtr->DisplayBlock) |
| | 55 | return; |
| | 56 | |
| | 57 | int newLevel = EffectOfRipples(&dynPtr->Position); |
| | 58 | |
| | 59 | { |
| | 60 | int minusDeltaX,plusDeltaX,minusDeltaZ,plusDeltaZ; |
| | 61 | VECTORCH delta; |
| | 62 | delta.vx = dynPtr->Position.vx; |
| | 63 | delta.vz = dynPtr->Position.vz; |
| | 64 | |
| | 65 | delta.vx -= 50; |
| | 66 | minusDeltaX = EffectOfRipples(&delta)-newLevel; |
| | 67 | delta.vx += 100; |
| | 68 | plusDeltaX = EffectOfRipples(&delta)-newLevel; |
| | 69 | delta.vx -= 50; |
| | 70 | |
| | 71 | delta.vz -= 50; |
| | 72 | minusDeltaZ = EffectOfRipples(&delta)-newLevel; |
| | 73 | delta.vz += 100; |
| | 74 | plusDeltaZ = EffectOfRipples(&delta)-newLevel; |
| | 75 | |
| | 76 | { |
| | 77 | int scale = NormalFrameTime<<1; |
| | 78 | |
| | 79 | if(scale > ONE_FIXED) |
| | 80 | scale = ONE_FIXED; |
| | 81 | |
| | 82 | scale = ONE_FIXED; |
| | 83 | dynPtr->LinImpulse.vx -= MUL_FIXED(scale,dynPtr->LinImpulse.vx); |
| | 84 | dynPtr->LinImpulse.vz -= MUL_FIXED(scale,dynPtr->LinImpulse.vz); |
| | 85 | } |
| | 86 | |
| | 87 | if (minusDeltaX > plusDeltaX) |
| | 88 | { |
| | 89 | if (minusDeltaX > 0) |
| | 90 | dynPtr->LinImpulse.vx = -minusDeltaX*256; |
| | 91 | } |
| | 92 | else |
| | 93 | { |
| | 94 | if (plusDeltaX > 0) |
| | 95 | dynPtr->LinImpulse.vx = plusDeltaX*256; |
| | 96 | } |
| | 97 | |
| | 98 | if (minusDeltaZ > plusDeltaZ) |
| | 99 | { |
| | 100 | if (minusDeltaZ > 0) |
| | 101 | dynPtr->LinImpulse.vz = -minusDeltaZ*256; |
| | 102 | } |
| | 103 | else |
| | 104 | { |
| | 105 | if (plusDeltaZ > 0) |
| | 106 | dynPtr->LinImpulse.vz = plusDeltaZ*256; |
| | 107 | } |
| | 108 | } |
| | 109 | |
| | 110 | dynPtr->LinImpulse.vy = 0; |
| | 111 | |
| | 112 | { |
| | 113 | int level; |
| | 114 | |
| | 115 | switch(AvP.level) |
| | 116 | { |
| | 117 | case AVP_ENVIRONMENT_INVASION_A: |
| | 118 | level = -35800; |
| | 119 | break; |
| | 120 | case AVP_ENVIRONMENT_COLONY: |
| | 121 | level = 2656; |
| | 122 | break; |
| | 123 | case AVP_ENVIRONMENT_WATERFALL_M: |
| | 124 | case AVP_ENVIRONMENT_WATERFALL: |
| | 125 | level = 12925; |
| | 126 | break; |
| | 127 | case AVP_ENVIRONMENT_DERELICT: |
| | 128 | level = 32000; |
| | 129 | break; |
| | 130 | case AVP_ENVIRONMENT_E3DEMOSP: |
| | 131 | case AVP_ENVIRONMENT_MASSACRE: |
| | 132 | level = 3300; |
| | 133 | break; |
| | 134 | default: |
| | 135 | level = 0; |
| | 136 | } |
| | 137 | |
| | 138 | dynPtr->Position.vy = newLevel + level; |
| | 139 | } |
| | 140 | |
| | 141 | dynPtr->AngVelocity.EulerY -= MUL_FIXED(dynPtr->AngVelocity.EulerY,NormalFrameTime); |
| | 142 | dynPtr->AngVelocity.EulerY += (dynPtr->LinImpulse.vz + dynPtr->LinImpulse.vx+(FastRandom()&255)-128)/16; |
| | 143 | dynPtr->AngVelocity.EulerZ = (dynPtr->LinImpulse.vz/256); |
| | 144 | dynPtr->AngVelocity.EulerX = (dynPtr->LinImpulse.vx/256); |
| | 145 | |
| | 146 | if (dynPtr->AngVelocity.EulerY > 8192) |
| | 147 | dynPtr->AngVelocity.EulerY = 8192; |
| | 148 | else if (dynPtr->AngVelocity.EulerY < -8192) |
| | 149 | dynPtr->AngVelocity.EulerY = -8192; |
| | 150 | |
| | 151 | DynamicallyRotateObject(dynPtr); |
| | 152 | } |
| | 153 | |
| | 154 | DISPLAYBLOCK *MakeObject(AVP_BEHAVIOUR_TYPE bhvr, const VECTORCH *positionPtr) |
| | 155 | { |
| | 156 | int shapeIndex; |
| | 157 | |
| | 158 | switch (bhvr) |
| | 159 | { |
| | 160 | case I_BehaviourRocket: |
| | 161 | shapeIndex = GetLoadedShapeMSL("missile"); |
| | 162 | break; |
| | 163 | case I_BehaviourPulseGrenade: |
| | 164 | case I_BehaviourGrenade: |
| | 165 | shapeIndex = GetLoadedShapeMSL("Shell"); |
| | 166 | break; |
| | 167 | case I_BehaviourFragmentationGrenade: |
| | 168 | shapeIndex = GetLoadedShapeMSL("Cluster"); |
| | 169 | break; |
| | 170 | case I_BehaviourProximityGrenade: |
| | 171 | shapeIndex = GetLoadedShapeMSL("Proxmine"); |
| | 172 | break; |
| | 173 | case I_BehaviourFlare: |
| | 174 | shapeIndex = GetLoadedShapeMSL("Flare"); |
| | 175 | break; |
| | 176 | default: |
| | 177 | shapeIndex = 0; |
| | 178 | } |
| | 179 | |
| | 180 | STRATEGYBLOCK* sbPtr = CreateActiveStrategyBlock(bhvr); |
| | 181 | |
| | 182 | if(NULL == sbPtr) |
| | 183 | return NULL; |
| | 184 | |
| | 185 | sbPtr->DisplayBlock = AllocateNewObject(shapeIndex); |
| | 186 | |
| | 187 | if (sbPtr->DisplayBlock) |
| | 188 | { |
| | 189 | sbPtr->DisplayBlock->ObStrategyBlock = sbPtr; |
| | 190 | sbPtr->DisplayBlock->ObWorld = *positionPtr; |
| | 191 | sbPtr->shapeIndex = shapeIndex; |
| | 192 | return sbPtr->DisplayBlock; |
| | 193 | } |
| | 194 | |
| | 195 | RemoveBehaviourStrategy(sbPtr); |
| | 196 | |
| | 197 | return NULL; |
| | 198 | } |
| | 199 | |
| | 200 | STRATEGYBLOCK* CreateRocketKernel(VECTORCH *position, MATRIXCH *orient, int fromplayer) |
| | 201 | { |
| | 202 | DISPLAYBLOCK *dispPtr = MakeObject(I_BehaviourRocket, position); |
| | 203 | |
| | 204 | if (NULL != dispPtr) |
| | 205 | { |
| | 206 | /* make displayblock a dynamic module object */ |
| | 207 | dispPtr->ObFlags3 |= ObFlag3_DynamicModuleObject; |
| | 208 | |
| | 209 | AddLightingEffectToObject(dispPtr, LFX_ROCKETJET); |
| | 210 | |
| | 211 | DYNAMICSBLOCK *dynPtr = dispPtr->ObStrategyBlock->DynPtr = AllocateDynamicsBlock(DYNAMICS_TEMPLATE_ROCKET); |
| | 212 | dispPtr->ObStrategyBlock->dataptr = malloc(sizeof(PREDPISTOL_BEHAV_BLOCK)); |
| | 213 | |
| | 214 | if ((NULL != dynPtr) && (NULL != dispPtr->ObStrategyBlock->dataptr)) |
| | 215 | { |
| | 216 | dynPtr->IgnoreThePlayer = fromplayer; |
| | 217 | |
| | 218 | ((PREDPISTOL_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->counter = 5 * ONE_FIXED * 100; |
| | 219 | ((PREDPISTOL_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->player = fromplayer; |
| | 220 | |
| | 221 | /* align rocket to launcher */ |
| | 222 | dynPtr->Position = dynPtr->PrevPosition = *position; |
| | 223 | |
| | 224 | dynPtr->PrevOrientMat = dynPtr->OrientMat = *orient; |
| | 225 | /* I added this next line for networking: Patrick */ |
| | 226 | MatrixToEuler(&dynPtr->OrientMat, &dynPtr->OrientEuler); |
| | 227 | |
| | 228 | /* align velocity too */ |
| | 229 | #define MISSILE_SPEED 80000 |
| | 230 | dynPtr->LinVelocity.vx = MUL_FIXED(dynPtr->OrientMat.mat31, MISSILE_SPEED); |
| | 231 | dynPtr->LinVelocity.vy = MUL_FIXED(dynPtr->OrientMat.mat32, MISSILE_SPEED); |
| | 232 | dynPtr->LinVelocity.vz = MUL_FIXED(dynPtr->OrientMat.mat33, MISSILE_SPEED); |
| | 233 | |
| | 234 | if(SinglePlayer != AvP.PlayMode) |
| | 235 | AddNetGameObjectID(dispPtr->ObStrategyBlock); |
| | 236 | |
| | 237 | return dispPtr->ObStrategyBlock; |
| | 238 | } |
| | 239 | |
| | 240 | RemoveBehaviourStrategy(dispPtr->ObStrategyBlock); |
| | 241 | } |
| | 242 | |
| | 243 | return NULL; |
| | 244 | } |
| | 245 | |
| | 246 | STRATEGYBLOCK* CreateGrenadeKernel(AVP_BEHAVIOUR_TYPE behaviourID, VECTORCH *position, MATRIXCH *orient, int fromplayer) |
| | 247 | { |
| | 248 | DISPLAYBLOCK *dispPtr = MakeObject(behaviourID, position); |
| | 249 | |
| | 250 | if (NULL != dispPtr) |
| | 251 | { |
| | 252 | DYNAMICSBLOCK *dynPtr = AllocateDynamicsBlock(DYNAMICS_TEMPLATE_GRENADE); |
| | 253 | |
| | 254 | if (NULL != dynPtr) |
| | 255 | { |
| | 256 | switch(behaviourID) |
| | 257 | { |
| | 258 | case I_BehaviourProximityGrenade: |
| | 259 | { |
| | 260 | dispPtr->ObStrategyBlock->dataptr = malloc(sizeof(PROX_GRENADE_BEHAV_BLOCK)); |
| | 261 | dispPtr->extent.min_x = -20; |
| | 262 | dispPtr->extent.min_y = -20; |
| | 263 | dispPtr->extent.min_z = -20; |
| | 264 | dispPtr->extent.max_x = 20; |
| | 265 | dispPtr->extent.max_y = 20; |
| | 266 | dispPtr->extent.max_z = 20; |
| | 267 | |
| | 268 | if (NULL != dispPtr->ObStrategyBlock->dataptr) |
| | 269 | { |
| | 270 | dynPtr->StopOnCollision = 1; |
| | 271 | ((PROX_GRENADE_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->counter = 2 * ONE_FIXED; |
| | 272 | ((PROX_GRENADE_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->SoundHandle = SOUND_NOACTIVEINDEX; |
| | 273 | ((PROX_GRENADE_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->SoundGenerationTimer = 0; |
| | 274 | } |
| | 275 | } |
| | 276 | break; |
| | 277 | default: |
| | 278 | { |
| | 279 | dispPtr->ObStrategyBlock->dataptr = malloc(sizeof(GRENADE_BEHAV_BLOCK)); |
| | 280 | |
| | 281 | if (NULL != dispPtr->ObStrategyBlock->dataptr) |
| | 282 | { |
| | 283 | ((GRENADE_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->counter = 2 * ONE_FIXED; |
| | 284 | ((GRENADE_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->bouncelastframe = 0; |
| | 285 | } |
| | 286 | } |
| | 287 | } |
| | 288 | |
| | 289 | if (NULL != dispPtr->ObStrategyBlock->dataptr) |
| | 290 | { |
| | 291 | dispPtr->ObFlags3 |= ObFlag3_DynamicModuleObject; |
| | 292 | dispPtr->ObStrategyBlock->DynPtr = dynPtr; |
| | 293 | dynPtr->IgnoreThePlayer = fromplayer; |
| | 294 | |
| | 295 | /* align grenade to launcher */ |
| | 296 | dynPtr->Position = dynPtr->PrevPosition = *position; |
| | 297 | dynPtr->OrientMat = dynPtr->PrevOrientMat = *orient; |
| | 298 | MatrixToEuler(&dynPtr->OrientMat, &dynPtr->OrientEuler); |
| | 299 | |
| | 300 | #define GRENADE_SPEED 70000 |
| | 301 | /* align velocity too */ |
| | 302 | dynPtr->LinImpulse.vx = MUL_FIXED(dynPtr->OrientMat.mat31, GRENADE_SPEED); |
| | 303 | dynPtr->LinImpulse.vy = MUL_FIXED(dynPtr->OrientMat.mat32, GRENADE_SPEED); |
| | 304 | dynPtr->LinImpulse.vz = MUL_FIXED(dynPtr->OrientMat.mat33, GRENADE_SPEED); |
| | 305 | dynPtr->IgnoresNotVisPolys = 1; |
| | 306 | |
| | 307 | if(SinglePlayer != AvP.PlayMode) |
| | 308 | AddNetGameObjectID(dispPtr->ObStrategyBlock); |
| | 309 | |
| | 310 | return dispPtr->ObStrategyBlock; |
| | 311 | } |
| | 312 | } |
| | 313 | |
| | 314 | RemoveBehaviourStrategy(dispPtr->ObStrategyBlock); |
| | 315 | } |
| | 316 | |
| | 317 | return NULL; |
| | 318 | } |
| | 319 | |
| | 320 | static STRATEGYBLOCK* CreateFlare(const VECTORCH *position, const MATRIXCH *orient) |
| | 321 | { |
| | 322 | DISPLAYBLOCK *dispPtr = MakeObject(I_BehaviourFlare, position); |
| | 323 | |
| | 324 | if (NULL != dispPtr) |
| | 325 | { |
| | 326 | dispPtr->ObFlags3 |= ObFlag3_DynamicModuleObject; |
| | 327 | |
| | 328 | DYNAMICSBLOCK *dynPtr = dispPtr->ObStrategyBlock->DynPtr = AllocateDynamicsBlock(DYNAMICS_TEMPLATE_GRENADE); |
| | 329 | dispPtr->ObStrategyBlock->dataptr = malloc(sizeof(FLARE_BEHAV_BLOCK)); |
| | 330 | |
| | 331 | if ((NULL != dynPtr) && (NULL != dispPtr->ObStrategyBlock->dataptr)) |
| | 332 | { |
| | 333 | FLARE_BEHAV_BLOCK *bbPtr = (FLARE_BEHAV_BLOCK * )dispPtr->ObStrategyBlock->dataptr; |
| | 334 | AddLightingEffectToObject(dispPtr, LFX_FLARE); |
| | 335 | |
| | 336 | dynPtr->Position = dynPtr->PrevPosition = *position; |
| | 337 | dynPtr->OrientMat = dynPtr->PrevOrientMat = *orient; |
| | 338 | MatrixToEuler(&dynPtr->OrientMat, &dynPtr->OrientEuler); |
| | 339 | |
| | 340 | dynPtr->LinImpulse.vx = MUL_FIXED(dynPtr->OrientMat.mat31, 30000); |
| | 341 | dynPtr->LinImpulse.vy = MUL_FIXED(dynPtr->OrientMat.mat32, 30000); |
| | 342 | dynPtr->LinImpulse.vz = MUL_FIXED(dynPtr->OrientMat.mat33, 30000); |
| | 343 | dynPtr->IgnoresNotVisPolys = dynPtr->StopOnCollision = 1; |
| | 344 | |
| | 345 | bbPtr->LifeTimeRemaining = FLARE_LIFETIME * ONE_FIXED; |
| | 346 | bbPtr->ParticleGenerationTimer = 0; |
| | 347 | bbPtr->SoundHandle = SOUND_NOACTIVEINDEX; |
| | 348 | bbPtr->becomeStuck = 0; |
| | 349 | |
| | 350 | if(SinglePlayer != AvP.PlayMode) |
| | 351 | AddNetGameObjectID(dispPtr->ObStrategyBlock); |
| | 352 | |
| | 353 | return dispPtr->ObStrategyBlock; |
| | 354 | } |
| | 355 | |
| | 356 | RemoveBehaviourStrategy(dispPtr->ObStrategyBlock); |
| | 357 | } |
| | 358 | |
| | 359 | return NULL; |
| | 360 | } |
| | 361 | |
| | 362 | int FlareDebounced = 0; |
| | 363 | |
| | 364 | void ThrowAFlare() |
| | 365 | { |
| | 366 | if (FlareDebounced) |
| | 367 | { |
| | 368 | FlareDebounced = 0; |
| | 369 | |
| | 370 | MATRIXCH mat = Global_VDB.VDB_Mat; |
| | 371 | VECTORCH position = Global_VDB.VDB_World; |
| | 372 | |
| | 373 | TransposeMatrixCH(&mat); |
| | 374 | |
| | 375 | CreateFlare(&position, &mat); |
| | 376 | Sound_Play(SID_THROW_FLARE, "h"); |
| | 377 | PlayerStatus.FlaresLeft--; |
| | 378 | } |
| | 379 | } |
| | 380 | |
| | 381 | STRATEGYBLOCK* InitialisePulseGrenadeBehaviour(const VECTORCH *position, const MATRIXCH *orient) |
| | 382 | { |
| | 383 | DISPLAYBLOCK *dispPtr = MakeObject(I_BehaviourPulseGrenade, position); |
| | 384 | |
| | 385 | if (NULL != dispPtr) |
| | 386 | { |
| | 387 | DYNAMICSBLOCK *dynPtr = dispPtr->ObStrategyBlock->DynPtr = AllocateDynamicsBlock(DYNAMICS_TEMPLATE_GRENADE); |
| | 388 | dispPtr->ObStrategyBlock->dataptr = malloc(sizeof(PREDPISTOL_BEHAV_BLOCK)); |
| | 389 | |
| | 390 | if ((NULL != dynPtr) && (NULL != dispPtr->ObStrategyBlock->dataptr)) |
| | 391 | { |
| | 392 | //AddLightingEffectToObject(dispPtr, LFX_ROCKETJET); |
| | 393 | |
| | 394 | ((PREDPISTOL_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->counter = 5 * ONE_FIXED; |
| | 395 | ((PREDPISTOL_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->player = 1; |
| | 396 | |
| | 397 | dynPtr->Position = dynPtr->PrevPosition = *position; |
| | 398 | dynPtr->PrevOrientMat = dynPtr->OrientMat = *orient; |
| | 399 | |
| | 400 | dynPtr->StopOnCollision = 1; |
| | 401 | #define PULSEGRENADE_SPEED 100000 |
| | 402 | |
| | 403 | dynPtr->LinVelocity.vx = MUL_FIXED(dynPtr->OrientMat.mat31, PULSEGRENADE_SPEED); |
| | 404 | dynPtr->LinVelocity.vy = MUL_FIXED(dynPtr->OrientMat.mat32, PULSEGRENADE_SPEED); |
| | 405 | dynPtr->LinVelocity.vz = MUL_FIXED(dynPtr->OrientMat.mat33, PULSEGRENADE_SPEED); |
| | 406 | |
| | 407 | if(SinglePlayer != AvP.PlayMode) |
| | 408 | AddNetGameObjectID(dispPtr->ObStrategyBlock); |
| | 409 | |
| | 410 | return dispPtr->ObStrategyBlock; |
| | 411 | } |
| | 412 | |
| | 413 | RemoveBehaviourStrategy(dispPtr->ObStrategyBlock); |
| | 414 | } |
| | 415 | |
| | 416 | return NULL; |
| | 417 | } |
| | 418 | |
| | 419 | STRATEGYBLOCK* Pred_Pistol_Bolt(VECTORCH *position, MATRIXCH *orient, int player) |
| | 420 | { |
| | 421 | STRATEGYBLOCK* sbPtr = CreateActiveStrategyBlock(I_BehaviourPPPlasmaBolt); |
| | 422 | |
| | 423 | if(NULL == sbPtr) |
| | 424 | return NULL; |
| | 425 | |
| | 426 | DISPLAYBLOCK *dispPtr = sbPtr->DisplayBlock = CreateActiveObject(); |
| | 427 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr = AllocateDynamicsBlock(DYNAMICS_TEMPLATE_GRENADE); |
| | 428 | sbPtr->dataptr = malloc(sizeof(PREDPISTOL_BEHAV_BLOCK)); |
| | 429 | SFXBLOCK* sfx_ptr = AllocateSfxBlock(); |
| | 430 | |
| | 431 | if ((NULL == dispPtr) || (NULL == dynPtr) || (NULL == sbPtr->dataptr) || (NULL == sfx_ptr)) |
| | 432 | { |
| | 433 | RemoveBehaviourStrategy(sbPtr); |
| | 434 | return NULL; |
| | 435 | } |
| | 436 | |
| | 437 | dispPtr->ObStrategyBlock = sbPtr; |
| | 438 | dispPtr->SfxPtr = sfx_ptr; |
| | 439 | |
| | 440 | dispPtr->SfxPtr->SfxID = SFX_SMALL_PREDATOR_PLASMA_BOLT; |
| | 441 | /* make displayblock a dynamic module object */ |
| | 442 | dispPtr->ObFlags3 |= ObFlag3_DynamicModuleObject; |
| | 443 | dispPtr->ObMat = IdentityMatrix; |
| | 444 | dispPtr->ObWorld = *position; |
| | 445 | |
| | 446 | AddLightingEffectToObject(dispPtr, LFX_PLASMA_BOLT); |
| | 447 | |
| | 448 | dispPtr->extent.min_x = -50; |
| | 449 | dispPtr->extent.min_y = -50; |
| | 450 | dispPtr->extent.min_y = -50; |
| | 451 | dispPtr->extent.max_x = 50; |
| | 452 | dispPtr->extent.max_y = 50; |
| | 453 | dispPtr->extent.max_z = 50; |
| | 454 | |
| | 455 | ((PREDPISTOL_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->counter = 5 * ONE_FIXED; |
| | 456 | ((PREDPISTOL_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->player = player; |
| | 457 | |
| | 458 | /* align rocket to launcher */ |
| | 459 | dynPtr->Position = dynPtr->PrevPosition = *position; |
| | 460 | |
| | 461 | /* align velocity too */ |
| | 462 | dynPtr->PrevOrientMat = dynPtr->OrientMat = *orient; |
| | 463 | /* I added this next line for networking: Patrick */ |
| | 464 | MatrixToEuler(&dynPtr->OrientMat, &dynPtr->OrientEuler); |
| | 465 | |
| | 466 | /* align velocity too */ |
| | 467 | |
| | 468 | dynPtr->LinImpulse.vx = MUL_FIXED(dynPtr->OrientMat.mat31, PredPistolBoltSpeed); |
| | 469 | dynPtr->LinImpulse.vy = MUL_FIXED(dynPtr->OrientMat.mat32, PredPistolBoltSpeed); |
| | 470 | dynPtr->LinImpulse.vz = MUL_FIXED(dynPtr->OrientMat.mat33, PredPistolBoltSpeed); |
| | 471 | |
| | 472 | dynPtr->UseStandardGravity = 0; |
| | 473 | dynPtr->GravityDirection.vy = PredPistolBoltGravity; /* Half gravity! */ |
| | 474 | dynPtr->StopOnCollision = 1; |
| | 475 | dynPtr->IgnoreThePlayer = player; |
| | 476 | |
| | 477 | if(SinglePlayer != AvP.PlayMode) |
| | 478 | AddNetGameObjectID(dispPtr->ObStrategyBlock); |
| | 479 | |
| | 480 | return sbPtr; |
| | 481 | } |
| | 482 | |
| | 483 | void Crunch_Position_For_Players_Weapon(VECTORCH *position) |
| | 484 | { |
| | 485 | position->vx += PlayerStatus.weapon.ObWorld.vx - Global_VDB.VDB_World.vx; |
| | 486 | position->vx = position->vx/4 + Global_VDB.VDB_World.vx; |
| | 487 | |
| | 488 | position->vy += PlayerStatus.weapon.ObWorld.vy - Global_VDB.VDB_World.vy; |
| | 489 | position->vy = position->vy/4 + Global_VDB.VDB_World.vy; |
| | 490 | |
| | 491 | position->vz += PlayerStatus.weapon.ObWorld.vz - Global_VDB.VDB_World.vz; |
| | 492 | position->vz = position->vz/4 + Global_VDB.VDB_World.vz; |
| | 493 | } |
| | 494 | |
| | 495 | STRATEGYBLOCK* InitialiseEnergyBoltBehaviourKernel(VECTORCH *position, MATRIXCH *orient, int player, const DAMAGE_PROFILE *damage, int factor) |
| | 496 | { |
| | 497 | STRATEGYBLOCK* sbPtr = CreateActiveStrategyBlock(I_BehaviourPredatorEnergyBolt); |
| | 498 | |
| | 499 | if(NULL == sbPtr) |
| | 500 | return NULL; |
| | 501 | |
| | 502 | DISPLAYBLOCK *dispPtr = sbPtr->DisplayBlock = CreateActiveObject(); |
| | 503 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr = AllocateDynamicsBlock(DYNAMICS_TEMPLATE_ROCKET); |
| | 504 | sbPtr->dataptr = malloc(sizeof(CASTER_BOLT_BEHAV_BLOCK)); |
| | 505 | SFXBLOCK* sfx_ptr = AllocateSfxBlock(); |
| | 506 | |
| | 507 | if((NULL == dispPtr) || (NULL == dynPtr) || (NULL == sbPtr->dataptr) || (NULL == sfx_ptr)) |
| | 508 | { |
| | 509 | RemoveBehaviourStrategy(dispPtr->ObStrategyBlock); |
| | 510 | return NULL; |
| | 511 | } |
| | 512 | |
| | 513 | dispPtr->ObStrategyBlock = sbPtr; |
| | 514 | dispPtr->SfxPtr = sfx_ptr; |
| | 515 | |
| | 516 | dispPtr->SfxPtr->SfxID = SFX_PREDATOR_PLASMA_BOLT; |
| | 517 | dispPtr->ObFlags3 |= ObFlag3_DynamicModuleObject; |
| | 518 | dispPtr->ObMat = IdentityMatrix; |
| | 519 | dispPtr->ObWorld = *position; |
| | 520 | |
| | 521 | dispPtr->extent.min_x = -50; |
| | 522 | dispPtr->extent.min_y = -50; |
| | 523 | dispPtr->extent.min_y = -50; |
| | 524 | dispPtr->extent.max_x = 50; |
| | 525 | dispPtr->extent.max_y = 50; |
| | 526 | dispPtr->extent.max_z = 50; |
| | 527 | |
| | 528 | dynPtr->Mass = 1; |
| | 529 | |
| | 530 | AddLightingEffectToObject(dispPtr, LFX_PLASMA_BOLT); |
| | 531 | |
| | 532 | ((CASTER_BOLT_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->counter = 5 * ONE_FIXED * 50; |
| | 533 | ((CASTER_BOLT_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->damage = *damage; |
| | 534 | ((CASTER_BOLT_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->blast_radius = MUL_FIXED(factor, Caster_BlastRadius); |
| | 535 | ((CASTER_BOLT_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->player = player; |
| | 536 | ((CASTER_BOLT_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->soundHandle = SOUND_NOACTIVEINDEX; |
| | 537 | |
| | 538 | /* align rocket to launcher */ |
| | 539 | dynPtr->Position = dynPtr->PrevPosition = *position; |
| | 540 | |
| | 541 | /* align velocity too */ |
| | 542 | dynPtr->PrevOrientMat = dynPtr->OrientMat = *orient; |
| | 543 | /* I added this next line for networking: Patrick */ |
| | 544 | MatrixToEuler(&dynPtr->OrientMat, &dynPtr->OrientEuler); |
| | 545 | |
| | 546 | /* align velocity too */ |
| | 547 | |
| | 548 | dynPtr->LinVelocity.vx = MUL_FIXED(dynPtr->OrientMat.mat31, ENERGY_BOLT_SPEED); |
| | 549 | dynPtr->LinVelocity.vy = MUL_FIXED(dynPtr->OrientMat.mat32, ENERGY_BOLT_SPEED); |
| | 550 | dynPtr->LinVelocity.vz = MUL_FIXED(dynPtr->OrientMat.mat33, ENERGY_BOLT_SPEED); |
| | 551 | |
| | 552 | if(SinglePlayer != AvP.PlayMode) |
| | 553 | AddNetGameObjectID(dispPtr->ObStrategyBlock); |
| | 554 | |
| | 555 | Sound_Play(SID_PRED_LAUNCHER, "hpd",(FastRandom() & 255)-128, &dynPtr->Position); |
| | 556 | |
| | 557 | dynPtr->IgnoreThePlayer = player; |
| | 558 | |
| | 559 | return sbPtr; |
| | 560 | } |
| | 561 | |
| | 562 | STRATEGYBLOCK* CreateFrisbeeKernel(VECTORCH *position, MATRIXCH *orient, int fromplayer) |
| | 563 | { |
| | 564 | STRATEGYBLOCK* sbPtr = CreateActiveStrategyBlock(I_BehaviourFrisbee); |
| | 565 | |
| | 566 | if(NULL == sbPtr) |
| | 567 | return NULL; |
| | 568 | |
| | 569 | DISPLAYBLOCK *dispPtr = sbPtr->DisplayBlock = CreateActiveObject(); |
| | 570 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr = AllocateDynamicsBlock(DYNAMICS_TEMPLATE_ROCKET); |
| | 571 | sbPtr->dataptr = malloc(sizeof(FRISBEE_BEHAV_BLOCK)); |
| | 572 | |
| | 573 | if ((NULL == dynPtr) || (NULL == sbPtr->dataptr) || (NULL == dispPtr)) |
| | 574 | { |
| | 575 | RemoveBehaviourStrategy(dispPtr->ObStrategyBlock); |
| | 576 | return NULL; |
| | 577 | } |
| | 578 | |
| | 579 | dispPtr->ObStrategyBlock = sbPtr; |
| | 580 | dispPtr->ObFlags3 |= ObFlag3_DynamicModuleObject; |
| | 581 | dispPtr->ObMat = IdentityMatrix; |
| | 582 | dispPtr->ObWorld = *position; |
| | 583 | |
| | 584 | dispPtr->extent.min_x = -50; |
| | 585 | dispPtr->extent.min_y = -50; |
| | 586 | dispPtr->extent.min_y = -50; |
| | 587 | dispPtr->extent.max_x = 50; |
| | 588 | dispPtr->extent.max_y = 50; |
| | 589 | dispPtr->extent.max_z = 50; |
| | 590 | |
| | 591 | dynPtr->Mass = 3; |
| | 592 | |
| | 593 | AddLightingEffectToObject(dispPtr, LFX_ROCKETJET); |
| | 594 | |
| | 595 | dynPtr->IgnoreThePlayer = fromplayer; |
| | 596 | |
| | 597 | FRISBEE_BEHAV_BLOCK *fblk = ((FRISBEE_BEHAV_BLOCK *)sbPtr->dataptr); |
| | 598 | |
| | 599 | fblk->counter = 5 * ONE_FIXED; |
| | 600 | fblk->soundHandle = SOUND_NOACTIVEINDEX; |
| | 601 | fblk->Bounced = 0; |
| | 602 | fblk->bounces = 0; |
| | 603 | |
| | 604 | fblk->Laser.SourcePosition = *position; |
| | 605 | fblk->Laser.SourcePosition = *position; |
| | 606 | fblk->Laser.BeamHasHitPlayer = 0; |
| | 607 | fblk->Laser.BeamIsOn = 0; |
| | 608 | |
| | 609 | /* Create HModel. */ |
| | 610 | { |
| | 611 | SECTION *root_section = GetNamedHierarchyFromLibrary("mdisk", "Mdisk"); |
| | 612 | |
| | 613 | assert(root_section); |
| | 614 | |
| | 615 | Create_HModel(&fblk->HModelController, root_section); |
| | 616 | InitHModelSequence(&fblk->HModelController, HMSQT_MarineStand, MSSS_Minigun_Delta, (ONE_FIXED>>1)); |
| | 617 | |
| | 618 | ProveHModel(&fblk->HModelController,dispPtr); |
| | 619 | fblk->HModelController.Looped = 1; |
| | 620 | |
| | 621 | dispPtr->HModelControlBlock = &fblk->HModelController; |
| | 622 | } |
| | 623 | |
| | 624 | /* align rocket to launcher */ |
| | 625 | dynPtr->Position = dynPtr->PrevPosition = *position; |
| | 626 | dynPtr->PrevOrientMat = dynPtr->OrientMat = *orient; |
| | 627 | |
| | 628 | /* I added this next line for networking: Patrick */ |
| | 629 | MatrixToEuler(&dynPtr->OrientMat, &dynPtr->OrientEuler); |
| | 630 | |
| | 631 | /* align velocity too */ |
| | 632 | |
| | 633 | dynPtr->LinVelocity.vx = MUL_FIXED(dynPtr->OrientMat.mat31, FRISBEE_SPEED); |
| | 634 | dynPtr->LinVelocity.vy = MUL_FIXED(dynPtr->OrientMat.mat32, FRISBEE_SPEED); |
| | 635 | dynPtr->LinVelocity.vz = MUL_FIXED(dynPtr->OrientMat.mat33, FRISBEE_SPEED); |
| | 636 | |
| | 637 | if(SinglePlayer != AvP.PlayMode) |
| | 638 | AddNetGameObjectID(dispPtr->ObStrategyBlock); |
| | 639 | |
| | 640 | return sbPtr; |
| | 641 | } |
| | 642 | |
| | 643 | static int Frisbee_TargetFilter(STRATEGYBLOCK *candidate) |
| | 644 | { |
| | 645 | switch (candidate->type) |
| | 646 | { |
| | 647 | case I_BehaviourAlien: |
| | 648 | case I_BehaviourPredator: |
| | 649 | case I_BehaviourPredatorPlayer: |
| | 650 | case I_BehaviourAlienPlayer: |
| | 651 | case I_BehaviourFaceHugger: |
| | 652 | case I_BehaviourXenoborg: |
| | 653 | case I_BehaviourQueenAlien: |
| | 654 | return 1; |
| | 655 | case I_BehaviourMarine: |
| | 656 | case I_BehaviourMarinePlayer: |
| | 657 | return 0; |
| | 658 | case I_BehaviourNetGhost: |
| | 659 | { |
| | 660 | NETGHOSTDATABLOCK *dataptr = candidate->dataptr; |
| | 661 | switch (dataptr->type) |
| | 662 | { |
| | 663 | case I_BehaviourAlienPlayer: |
| | 664 | case I_BehaviourPredatorPlayer: |
| | 665 | case I_BehaviourMarinePlayer: |
| | 666 | { |
| | 667 | switch (netGameData.gameType) |
| | 668 | { |
| | 669 | default: |
| | 670 | case NGT_Coop: |
| | 671 | case NGT_CoopDeathmatch: |
| | 672 | case NGT_LastManStanding: |
| | 673 | return 0; |
| | 674 | case NGT_Individual: |
| | 675 | case NGT_PredatorTag: |
| | 676 | case NGT_AlienTag: |
| | 677 | return 1; //However, there shouldn't be more than one alien in alien tag anyway. |
| | 678 | } |
| | 679 | } |
| | 680 | case I_BehaviourAlien: |
| | 681 | return 1; |
| | 682 | default: |
| | 683 | return 0; |
| | 684 | } |
| | 685 | } |
| | 686 | case I_BehaviourDummy: |
| | 687 | { |
| | 688 | switch (AvP.PlayerType) |
| | 689 | { |
| | 690 | default: |
| | 691 | case I_Marine: |
| | 692 | return 0; |
| | 693 | case I_Predator: |
| | 694 | case I_Alien: |
| | 695 | return 1; |
| | 696 | } |
| | 697 | } |
| | 698 | default: |
| | 699 | return 0; |
| | 700 | } |
| | 701 | } |
| | 702 | |
| | 703 | void FrisbeeEnergyBoltBehaviour(STRATEGYBLOCK *sbPtr) |
| | 704 | { |
| | 705 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr; |
| | 706 | COLLISIONREPORT *reportPtr = dynPtr->CollisionReportPtr; |
| | 707 | CASTER_BOLT_BEHAV_BLOCK *bbPtr = (CASTER_BOLT_BEHAV_BLOCK * )sbPtr->dataptr; |
| | 708 | |
| | 709 | MakeDewlineTrailParticles(dynPtr, 32); |
| | 710 | |
| | 711 | /* check for a collision with something */ |
| | 712 | if (bbPtr->counter <= 0) |
| | 713 | { |
| | 714 | /* for net game support: send a message saying we've blown up... */ |
| | 715 | if(SinglePlayer != AvP.PlayMode) |
| | 716 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 717 | |
| | 718 | sbPtr->please_destroy_me = 1; |
| | 719 | } |
| | 720 | else if (reportPtr) |
| | 721 | { |
| | 722 | if(reportPtr->ObstacleSBPtr) |
| | 723 | { |
| | 724 | VECTORCH attack_dir; |
| | 725 | /* Accuracy snipped again! */ |
| | 726 | GetDirectionOfAttack(reportPtr->ObstacleSBPtr, &dynPtr->LinVelocity, &attack_dir); |
| | 727 | CauseDamageToObject(reportPtr->ObstacleSBPtr, &bbPtr->damage, ONE_FIXED, &attack_dir); |
| | 728 | } |
| | 729 | |
| | 730 | if(SinglePlayer != AvP.PlayMode) |
| | 731 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 732 | |
| | 733 | /* Splash damage? */ |
| | 734 | DestroyActiveObject(&sbPtr->DisplayBlock); |
| | 735 | MakeVolumetricExplosionAt(&dynPtr->Position, EXPLOSION_PULSEGRENADE); |
| | 736 | sbPtr->please_destroy_me = 1; |
| | 737 | } |
| | 738 | else |
| | 739 | { |
| | 740 | VECTORCH direction; |
| | 741 | direction.vx = dynPtr->LinVelocity.vx + dynPtr->LinImpulse.vx; |
| | 742 | direction.vy = dynPtr->LinVelocity.vy + dynPtr->LinImpulse.vy; |
| | 743 | direction.vz = dynPtr->LinVelocity.vz + dynPtr->LinImpulse.vz; |
| | 744 | Normalise(&direction); |
| | 745 | MakeMatrixFromDirection(&direction, &dynPtr->OrientMat); |
| | 746 | bbPtr->counter -= NormalFrameTime; |
| | 747 | } |
| | 748 | } |
| | 749 | |
| | 750 | //Function only does minimal frisbee setup , the rest will be done by the load function |
| | 751 | static const VECTORCH zeroVect = {0,0,0}; |
| | 752 | |
| | 753 | static STRATEGYBLOCK* InitialiseFrisbeeBehaviour_ForLoad() |
| | 754 | { |
| | 755 | DISPLAYBLOCK *dispPtr = MakeObject(I_BehaviourFrisbee, &zeroVect); |
| | 756 | |
| | 757 | if (NULL != dispPtr) |
| | 758 | { |
| | 759 | DYNAMICSBLOCK *dynPtr = AllocateDynamicsBlock(DYNAMICS_TEMPLATE_ROCKET); |
| | 760 | dispPtr->ObStrategyBlock->dataptr = malloc(sizeof(FRISBEE_BEHAV_BLOCK)); |
| | 761 | |
| | 762 | if ((NULL != dynPtr) && (NULL != dispPtr->ObStrategyBlock->dataptr)) |
| | 763 | { |
| | 764 | /* make displayblock a dynamic module object */ |
| | 765 | dispPtr->ObFlags3 |= ObFlag3_DynamicModuleObject; |
| | 766 | |
| | 767 | dispPtr->ObStrategyBlock->DynPtr = dynPtr; |
| | 768 | |
| | 769 | FRISBEE_BEHAV_BLOCK *bblk = dispPtr->ObStrategyBlock->dataptr; |
| | 770 | |
| | 771 | bblk->soundHandle = SOUND_NOACTIVEINDEX; |
| | 772 | bblk->Laser.SourcePosition = zeroVect; |
| | 773 | bblk->Laser.SourcePosition = zeroVect; |
| | 774 | bblk->Laser.BeamHasHitPlayer = 0; |
| | 775 | bblk->Laser.BeamIsOn = 0; |
| | 776 | |
| | 777 | dispPtr->HModelControlBlock = &bblk->HModelController; |
| | 778 | |
| | 779 | return dispPtr->ObStrategyBlock; |
| | 780 | } |
| | 781 | |
| | 782 | RemoveBehaviourStrategy(dispPtr->ObStrategyBlock); |
| | 783 | } |
| | 784 | |
| | 785 | return NULL; |
| | 786 | } |
| | 787 | |
| | 788 | static STRATEGYBLOCK* InitialiseFrisbeeBoltBehaviourKernel(VECTORCH *position,MATRIXCH *orient, int player, const DAMAGE_PROFILE *damage, int factor) |
| | 789 | { |
| | 790 | STRATEGYBLOCK* sbPtr = CreateActiveStrategyBlock(I_BehaviourFrisbeeEnergyBolt); |
| | 791 | |
| | 792 | if(NULL == sbPtr) |
| | 793 | return NULL; |
| | 794 | |
| | 795 | DISPLAYBLOCK *dispPtr = sbPtr->DisplayBlock = CreateActiveObject(); |
| | 796 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr = AllocateDynamicsBlock(DYNAMICS_TEMPLATE_ROCKET); |
| | 797 | sbPtr->dataptr = malloc(sizeof(CASTER_BOLT_BEHAV_BLOCK)); |
| | 798 | SFXBLOCK* sfx_ptr = AllocateSfxBlock(); |
| | 799 | |
| | 800 | if((NULL == dynPtr) || (NULL == sbPtr->dataptr) || (NULL == dispPtr) || (NULL == sfx_ptr)) |
| | 801 | { |
| | 802 | RemoveBehaviourStrategy(sbPtr); |
| | 803 | return NULL; |
| | 804 | } |
| | 805 | |
| | 806 | dispPtr->ObStrategyBlock = sbPtr; |
| | 807 | dispPtr->SfxPtr = sfx_ptr; |
| | 808 | |
| | 809 | dispPtr->SfxPtr->SfxID = SFX_FRISBEE_PLASMA_BOLT; |
| | 810 | dispPtr->ObFlags3 |= ObFlag3_DynamicModuleObject; |
| | 811 | dispPtr->ObMat = IdentityMatrix; |
| | 812 | dispPtr->ObWorld = *position; |
| | 813 | |
| | 814 | dispPtr->extent.min_x = -50; |
| | 815 | dispPtr->extent.min_y = -50; |
| | 816 | dispPtr->extent.min_y = -50; |
| | 817 | dispPtr->extent.max_x = 50; |
| | 818 | dispPtr->extent.max_y = 50; |
| | 819 | dispPtr->extent.max_z = 50; |
| | 820 | |
| | 821 | dynPtr->Mass = 1; |
| | 822 | |
| | 823 | AddLightingEffectToObject(dispPtr, LFX_PLASMA_BOLT); |
| | 824 | |
| | 825 | ((CASTER_BOLT_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->counter = 5 * ONE_FIXED; |
| | 826 | ((CASTER_BOLT_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->damage = *damage; |
| | 827 | ((CASTER_BOLT_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->blast_radius = MUL_FIXED(factor,Caster_BlastRadius); |
| | 828 | ((CASTER_BOLT_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->player = player; |
| | 829 | ((CASTER_BOLT_BEHAV_BLOCK *)dispPtr->ObStrategyBlock->dataptr)->soundHandle = SOUND_NOACTIVEINDEX; |
| | 830 | |
| | 831 | /* align rocket to launcher */ |
| | 832 | dynPtr->Position = dynPtr->PrevPosition = *position; |
| | 833 | dynPtr->IgnoreSameObjectsAsYou = 1; |
| | 834 | |
| | 835 | /* align velocity too */ |
| | 836 | dynPtr->PrevOrientMat = dynPtr->OrientMat = *orient; |
| | 837 | /* I added this next line for networking: Patrick */ |
| | 838 | MatrixToEuler(&dynPtr->OrientMat, &dynPtr->OrientEuler); |
| | 839 | |
| | 840 | dynPtr->LinVelocity.vx = MUL_FIXED(dynPtr->OrientMat.mat31, ENERGY_BOLT_SPEED); |
| | 841 | dynPtr->LinVelocity.vy = MUL_FIXED(dynPtr->OrientMat.mat32, ENERGY_BOLT_SPEED); |
| | 842 | dynPtr->LinVelocity.vz = MUL_FIXED(dynPtr->OrientMat.mat33, ENERGY_BOLT_SPEED); |
| | 843 | |
| | 844 | if(SinglePlayer != AvP.PlayMode) |
| | 845 | AddNetGameObjectID(dispPtr->ObStrategyBlock); |
| | 846 | |
| | 847 | Sound_Play(SID_PRED_LAUNCHER, "hpd", (FastRandom() & 255)-128, &dynPtr->Position); |
| | 848 | |
| | 849 | dynPtr->IgnoreThePlayer = player; |
| | 850 | |
| | 851 | return sbPtr; |
| | 852 | } |
| | 853 | |
| | 854 | static int Reflect(VECTORCH *Incident, VECTORCH *Normal, EULER *Output) |
| | 855 | { |
| | 856 | MATRIXCH tempMat; |
| | 857 | VECTORCH outVec; |
| | 858 | /* Ah, the wonders of better math support. */ |
| | 859 | |
| | 860 | assert(Incident); |
| | 861 | assert(Normal); |
| | 862 | assert(Output); |
| | 863 | |
| | 864 | VECTORCH normInc = *Incident; |
| | 865 | Normalise(&normInc); |
| | 866 | int retval = DotProduct(&normInc,Normal); |
| | 867 | |
| | 868 | /* Hold that thought. */ |
| | 869 | int dot = retval*(-2); |
| | 870 | |
| | 871 | /* Yeah, okay, and a better algorithm. */ |
| | 872 | outVec.vx = normInc.vx + MUL_FIXED(dot, Normal->vx); |
| | 873 | outVec.vy = normInc.vy + MUL_FIXED(dot, Normal->vy); |
| | 874 | outVec.vz = normInc.vz + MUL_FIXED(dot, Normal->vz); |
| | 875 | |
| | 876 | MakeMatrixFromDirection(&outVec,&tempMat); |
| | 877 | MatrixToEuler(&tempMat,Output); |
| | 878 | /* But bear in mind, most of the early one was coping with * |
| | 879 | * bad functions and junk inputs... that's my excuse. */ |
| | 880 | |
| | 881 | return retval; |
| | 882 | } |
| | 883 | |
| | 884 | #define DISC_MAX_BOUNCES (10) |
| | 885 | |
| | 886 | void Frisbee_Hit_Environment(STRATEGYBLOCK *sbPtr,COLLISIONREPORT *reportPtr) |
| | 887 | { |
| | 888 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr; |
| | 889 | FRISBEE_BEHAV_BLOCK *fbPtr = (FRISBEE_BEHAV_BLOCK * ) sbPtr->dataptr; |
| | 890 | MATRIXCH mat; |
| | 891 | |
| | 892 | /* Hit the environment. Bounce? */ |
| | 893 | int dp = Reflect(&dynPtr->LinVelocity, &reportPtr->ObstacleNormal, &dynPtr->OrientEuler); |
| | 894 | |
| | 895 | dynPtr->OrientEuler.EulerZ = 0; |
| | 896 | dynPtr->IgnoreThePlayer = 0; |
| | 897 | |
| | 898 | /* Always bounce. Reference Disc_Hit_Environment for sticking conditions. */ |
| | 899 | MakeImpactSparks(&dynPtr->LinVelocity, &reportPtr->ObstacleNormal,&dynPtr->Position); |
| | 900 | //Sound_Play(SID_ED_SKEETERDISC_HITWALL,"dp",&(dynPtr->Position),((FastRandom()&511)-255)); |
| | 901 | |
| | 902 | CreateEulerMatrix(&dynPtr->OrientEuler, &mat); |
| | 903 | TransposeMatrixCH(&mat); |
| | 904 | |
| | 905 | dynPtr->OrientMat = mat; |
| | 906 | |
| | 907 | dynPtr->LinVelocity.vx = MUL_FIXED(mat.mat31, FRISBEE_SPEED); |
| | 908 | dynPtr->LinVelocity.vy = MUL_FIXED(mat.mat32, FRISBEE_SPEED); |
| | 909 | dynPtr->LinVelocity.vz = MUL_FIXED(mat.mat33, FRISBEE_SPEED); |
| | 910 | |
| | 911 | dynPtr->LinImpulse.vx = dynPtr->LinImpulse.vy = dynPtr->LinImpulse.vz = 0; |
| | 912 | |
| | 913 | // Record that the disc has bounced - for use in network game |
| | 914 | fbPtr->Bounced = 1; |
| | 915 | fbPtr->bounces++; |
| | 916 | } |
| | 917 | |
| | 918 | static int SBForcesBounce(STRATEGYBLOCK *sbPtr) |
| | 919 | { |
| | 920 | switch (sbPtr->type) |
| | 921 | { |
| | 922 | case I_BehaviourInanimateObject: |
| | 923 | return sbPtr->DamageBlock.Indestructable; |
| | 924 | case I_BehaviourProximityDoor: |
| | 925 | case I_BehaviourTrackObject: |
| | 926 | case I_BehaviourLiftDoor: |
| | 927 | case I_BehaviourSwitchDoor: |
| | 928 | case I_BehaviourLinkSwitch: |
| | 929 | case I_BehaviourBinarySwitch: |
| | 930 | case I_BehaviourLift: |
| | 931 | case I_BehaviourPlatform: |
| | 932 | case I_BehaviourPredatorDisc_SeekTrack: |
| | 933 | return 1; |
| | 934 | case I_BehaviourNetGhost: |
| | 935 | { |
| | 936 | NETGHOSTDATABLOCK *dataptr = sbPtr->dataptr; |
| | 937 | |
| | 938 | switch (dataptr->type) |
| | 939 | { |
| | 940 | case I_BehaviourPredatorDisc_SeekTrack: |
| | 941 | return 1; |
| | 942 | default: |
| | 943 | return 0; |
| | 944 | } |
| | 945 | } |
| | 946 | default: |
| | 947 | return 0; |
| | 948 | } |
| | 949 | } |
| | 950 | |
| | 951 | static void MatrixFromZVector(VECTORCH *v, MATRIXCH *m) |
| | 952 | { |
| | 953 | VECTORCH XVector; |
| | 954 | VECTORCH YVector; |
| | 955 | VECTORCH zero = {0, 0, 0}; |
| | 956 | |
| | 957 | XVector.vx = v->vz; |
| | 958 | XVector.vy = 0; |
| | 959 | XVector.vz = -v->vx; |
| | 960 | |
| | 961 | Normalise(&XVector); |
| | 962 | |
| | 963 | MakeNormal(&zero, &XVector, v, &YVector); |
| | 964 | |
| | 965 | m->mat11 = XVector.vx; |
| | 966 | m->mat12 = XVector.vy; |
| | 967 | m->mat13 = XVector.vz; |
| | 968 | |
| | 969 | m->mat21 = -YVector.vx; |
| | 970 | m->mat22 = -YVector.vy; |
| | 971 | m->mat23 = -YVector.vz; |
| | 972 | |
| | 973 | m->mat31 = v->vx; |
| | 974 | m->mat32 = v->vy; |
| | 975 | m->mat33 = v->vz; |
| | 976 | } |
| | 977 | |
| | 978 | void FrisbeeBehaviour(STRATEGYBLOCK *sbPtr) |
| | 979 | { |
| | 980 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr; |
| | 981 | COLLISIONREPORT *reportPtr = dynPtr->CollisionReportPtr; |
| | 982 | FRISBEE_BEHAV_BLOCK *fbPtr = (FRISBEE_BEHAV_BLOCK * ) sbPtr->dataptr; |
| | 983 | int explodeNow = 0; |
| | 984 | |
| | 985 | if (fbPtr->counter <= 0) |
| | 986 | { |
| | 987 | explodeNow = 1; |
| | 988 | } |
| | 989 | else |
| | 990 | { |
| | 991 | if (reportPtr) |
| | 992 | { |
| | 993 | if (NULL == reportPtr->ObstacleSBPtr) |
| | 994 | { |
| | 995 | Frisbee_Hit_Environment(sbPtr, reportPtr); |
| | 996 | } |
| | 997 | else if (SBForcesBounce(reportPtr->ObstacleSBPtr)) |
| | 998 | { |
| | 999 | MATRIXCH mat; |
| | 1000 | /* Bounce. */ |
| | 1001 | Reflect(&dynPtr->LinVelocity, &reportPtr->ObstacleNormal, &dynPtr->OrientEuler); |
| | 1002 | dynPtr->OrientEuler.EulerZ = 0; |
| | 1003 | dynPtr->IgnoreThePlayer = 0; |
| | 1004 | |
| | 1005 | MakeImpactSparks(&dynPtr->LinVelocity, &reportPtr->ObstacleNormal,&dynPtr->Position); |
| | 1006 | //Sound_Play(SID_ED_SKEETERDISC_HITWALL, "dp", &dynPtr->Position, ((FastRandom()&511)-255)); |
| | 1007 | |
| | 1008 | fbPtr->bounces++; |
| | 1009 | /* |
| | 1010 | Record that the disc has bounced - for use in network game |
| | 1011 | */ |
| | 1012 | |
| | 1013 | fbPtr->Bounced = 1; |
| | 1014 | |
| | 1015 | CreateEulerMatrix(&dynPtr->OrientEuler, &mat); |
| | 1016 | TransposeMatrixCH(&mat); |
| | 1017 | |
| | 1018 | dynPtr->OrientMat = mat; |
| | 1019 | |
| | 1020 | dynPtr->LinVelocity.vx = MUL_FIXED(mat.mat31, FRISBEE_SPEED); |
| | 1021 | dynPtr->LinVelocity.vy = MUL_FIXED(mat.mat32, FRISBEE_SPEED); |
| | 1022 | dynPtr->LinVelocity.vz = MUL_FIXED(mat.mat33, FRISBEE_SPEED); |
| | 1023 | |
| | 1024 | dynPtr->LinImpulse.vx = dynPtr->LinImpulse.vy = dynPtr->LinImpulse.vz = 0; |
| | 1025 | } |
| | 1026 | else |
| | 1027 | { |
| | 1028 | /* Hit a creature? */ |
| | 1029 | VECTORCH attack_dir; |
| | 1030 | |
| | 1031 | /* Accuracy snipped. */ |
| | 1032 | GetDirectionOfAttack(reportPtr->ObstacleSBPtr, &dynPtr->LinVelocity, &attack_dir); |
| | 1033 | CauseDamageToObject(reportPtr->ObstacleSBPtr, &TemplateAmmo[AMMO_FRISBEE].MaxDamage, ONE_FIXED,&attack_dir); |
| | 1034 | explodeNow = 1; |
| | 1035 | } |
| | 1036 | } |
| | 1037 | } |
| | 1038 | |
| | 1039 | if (explodeNow) |
| | 1040 | { |
| | 1041 | DestroyActiveObject(&sbPtr->DisplayBlock); |
| | 1042 | |
| | 1043 | if (sbPtr->containingModule) |
| | 1044 | { |
| | 1045 | MakeVolumetricExplosionAt(&dynPtr->Position, EXPLOSION_PULSEGRENADE); |
| | 1046 | Explosion_SoundData.position = dynPtr->Position; |
| | 1047 | Sound_Play(SID_NICE_EXPLOSION, "nh", &Explosion_SoundData); |
| | 1048 | } |
| | 1049 | |
| | 1050 | /* for net game support: send a message saying we've blown up... */ |
| | 1051 | if(SinglePlayer != AvP.PlayMode) |
| | 1052 | { |
| | 1053 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 1054 | AddNetMsg_SpotOtherSound(SID_NICE_EXPLOSION, &dynPtr->Position, 1); |
| | 1055 | } |
| | 1056 | |
| | 1057 | sbPtr->please_destroy_me = 1; |
| | 1058 | } |
| | 1059 | else |
| | 1060 | { |
| | 1061 | /* We must be flying. Maintain sound. */ |
| | 1062 | |
| | 1063 | if(fbPtr->soundHandle != SOUND_NOACTIVEINDEX) |
| | 1064 | { |
| | 1065 | Sound_Update3d(fbPtr->soundHandle, &sbPtr->DynPtr->Position); |
| | 1066 | |
| | 1067 | if (ActiveSounds[fbPtr->soundHandle].soundIndex != SID_PREDATOR_DISK_FLYING) |
| | 1068 | { |
| | 1069 | Sound_Stop(fbPtr->soundHandle); |
| | 1070 | //Sound_Play(SID_ED_SKEETERDISC_SPIN, "del", &sbPtr->DynPtr->Position, &fbPtr->soundHandle); |
| | 1071 | } |
| | 1072 | } |
| | 1073 | //else Sound_Play(SID_ED_SKEETERDISC_SPIN,"del",&(sbPtr->DynPtr->Position),&fbPtr->soundHandle); |
| | 1074 | |
| | 1075 | SECTION_DATA *disc_section = GetThisSectionData(fbPtr->HModelController.section_data, "Mdisk"); |
| | 1076 | |
| | 1077 | if (disc_section) |
| | 1078 | { |
| | 1079 | VECTORCH line; |
| | 1080 | line.vx = disc_section->SecMat.mat11; |
| | 1081 | line.vy = disc_section->SecMat.mat12; |
| | 1082 | line.vz = disc_section->SecMat.mat13; |
| | 1083 | |
| | 1084 | /* Make a laser? */ |
| | 1085 | // KJL 12:32:40 08/02/00 - Fox want the laser beam removed |
| | 1086 | fbPtr->Laser.BeamIsOn = 0; |
| | 1087 | |
| | 1088 | { |
| | 1089 | int l = 0; |
| | 1090 | for (;l < 4; l++) |
| | 1091 | MakeFlareParticle(dynPtr); |
| | 1092 | } |
| | 1093 | |
| | 1094 | /* Now do the target sweep. */ |
| | 1095 | if (fbPtr->counter < (4* (ONE_FIXED))) |
| | 1096 | { |
| | 1097 | int a = 0; |
| | 1098 | STRATEGYBLOCK *nearest = NULL; |
| | 1099 | VECTORCH offset; |
| | 1100 | |
| | 1101 | MODULE *dmod = ModuleFromPosition(&sbPtr->DynPtr->Position, PlayerStatus.sbptr->containingModule); |
| | 1102 | |
| | 1103 | for (; a < NumActiveStBlocks; a++) |
| | 1104 | { |
| | 1105 | STRATEGYBLOCK *candidate = ActiveStBlockList[a]; |
| | 1106 | |
| | 1107 | if (candidate != sbPtr) |
| | 1108 | { |
| | 1109 | if (candidate->DynPtr) |
| | 1110 | { |
| | 1111 | if (Frisbee_TargetFilter(candidate)) |
| | 1112 | { |
| | 1113 | /* Check visibility? */ |
| | 1114 | |
| | 1115 | if (!NPC_IsDead(candidate)) |
| | 1116 | { |
| | 1117 | if (candidate->DisplayBlock && sbPtr->DisplayBlock) |
| | 1118 | { |
| | 1119 | /* Near case. */ |
| | 1120 | if (NPCCanSeeTarget(sbPtr, candidate)) |
| | 1121 | { |
| | 1122 | VECTORCH targetPos; |
| | 1123 | nearest = candidate; |
| | 1124 | |
| | 1125 | /* Shoot it, */ |
| | 1126 | GetTargetingPointOfObject_Far(nearest, &targetPos); |
| | 1127 | |
| | 1128 | if (CalculateFiringSolution(&sbPtr->DynPtr->Position,&nearest->DynPtr->Position, |
| | 1129 | &nearest->DynPtr->LinVelocity,ENERGY_BOLT_SPEED,&offset)) |
| | 1130 | { |
| | 1131 | /* Use this. */ |
| | 1132 | } |
| | 1133 | else |
| | 1134 | { |
| | 1135 | offset.vx = targetPos.vx-sbPtr->DynPtr->Position.vx; |
| | 1136 | offset.vy = targetPos.vy-sbPtr->DynPtr->Position.vy; |
| | 1137 | offset.vz = targetPos.vz-sbPtr->DynPtr->Position.vz; |
| | 1138 | Normalise(&offset); |
| | 1139 | } |
| | 1140 | |
| | 1141 | { |
| | 1142 | MATRIXCH mat; |
| | 1143 | MatrixFromZVector(&offset,&mat); |
| | 1144 | InitialiseFrisbeeBoltBehaviourKernel(&sbPtr->DynPtr->Position,&mat, 0, |
| | 1145 | &TemplateAmmo[AMMO_FRISBEE].MaxDamage, 65536); |
| | 1146 | } |
| | 1147 | } |
| | 1148 | } |
| | 1149 | else |
| | 1150 | { |
| | 1151 | if (dmod) |
| | 1152 | { |
| | 1153 | if (IsModuleVisibleFromModule(dmod,candidate->containingModule)) |
| | 1154 | { |
| | 1155 | VECTORCH targetPos; |
| | 1156 | nearest = candidate; |
| | 1157 | |
| | 1158 | /* Shoot it, */ |
| | 1159 | GetTargetingPointOfObject_Far(nearest,&targetPos); |
| | 1160 | |
| | 1161 | if (CalculateFiringSolution(&sbPtr->DynPtr->Position,&nearest->DynPtr->Position, |
| | 1162 | &nearest->DynPtr->LinVelocity,ENERGY_BOLT_SPEED,&offset)) |
| | 1163 | { |
| | 1164 | /* Use this. */ |
| | 1165 | } |
| | 1166 | else |
| | 1167 | { |
| | 1168 | offset.vx = targetPos.vx-sbPtr->DynPtr->Position.vx; |
| | 1169 | offset.vy = targetPos.vy-sbPtr->DynPtr->Position.vy; |
| | 1170 | offset.vz = targetPos.vz-sbPtr->DynPtr->Position.vz; |
| | 1171 | Normalise(&offset); |
| | 1172 | } |
| | 1173 | |
| | 1174 | { |
| | 1175 | MATRIXCH mat; |
| | 1176 | MatrixFromZVector(&offset,&mat); |
| | 1177 | InitialiseFrisbeeBoltBehaviourKernel(&sbPtr->DynPtr->Position,&mat, 0, |
| | 1178 | &TemplateAmmo[AMMO_FRISBEE].MaxDamage, 65536); |
| | 1179 | } |
| | 1180 | } |
| | 1181 | } |
| | 1182 | } |
| | 1183 | } |
| | 1184 | } |
| | 1185 | } |
| | 1186 | } |
| | 1187 | } |
| | 1188 | |
| | 1189 | if (nearest) |
| | 1190 | { |
| | 1191 | /* And explode. */ |
| | 1192 | |
| | 1193 | DestroyActiveObject(&sbPtr->DisplayBlock); |
| | 1194 | |
| | 1195 | if (sbPtr->containingModule) |
| | 1196 | { |
| | 1197 | MakeVolumetricExplosionAt(&dynPtr->Position, EXPLOSION_PULSEGRENADE); |
| | 1198 | Explosion_SoundData.position = dynPtr->Position; |
| | 1199 | //Sound_Play(SID_ED_SKEETERPLASMAFIRE, "n", &Explosion_SoundData); |
| | 1200 | } |
| | 1201 | |
| | 1202 | /* for net game support: send a message saying we've blown up... */ |
| | 1203 | if(SinglePlayer != AvP.PlayMode) |
| | 1204 | { |
| | 1205 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 1206 | //AddNetMsg_SpotOtherSound(SID_ED_SKEETERPLASMAFIRE, &dynPtr->Position,1); |
| | 1207 | } |
| | 1208 | |
| | 1209 | /* destroy rocket */ |
| | 1210 | sbPtr->please_destroy_me = 1; |
| | 1211 | } |
| | 1212 | } |
| | 1213 | } |
| | 1214 | |
| | 1215 | fbPtr->counter -= NormalFrameTime; |
| | 1216 | } |
| | 1217 | } |
| | 1218 | |
| | 1219 | void RocketBehaviour(STRATEGYBLOCK *sbPtr) |
| | 1220 | { |
| | 1221 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr; |
| | 1222 | COLLISIONREPORT *reportPtr = dynPtr->CollisionReportPtr; |
| | 1223 | PREDPISTOL_BEHAV_BLOCK *bbPtr = (PREDPISTOL_BEHAV_BLOCK * ) sbPtr->dataptr; |
| | 1224 | |
| | 1225 | if (reportPtr || (bbPtr->counter <= 0) ) |
| | 1226 | { |
| | 1227 | if (reportPtr && reportPtr->ObstacleSBPtr) |
| | 1228 | { |
| | 1229 | if (bbPtr->player && AccuracyStats_TargetFilter(reportPtr->ObstacleSBPtr)) |
| | 1230 | { |
| | 1231 | /* Log accuracy! */ |
| | 1232 | int slot = SlotForThisWeapon(WEAPON_SADAR); |
| | 1233 | |
| | 1234 | if (slot != -1) |
| | 1235 | CurrentGameStats_WeaponHit(slot, 1); |
| | 1236 | } |
| | 1237 | } |
| | 1238 | |
| | 1239 | DestroyActiveObject(&sbPtr->DisplayBlock); |
| | 1240 | |
| | 1241 | if (sbPtr->containingModule) |
| | 1242 | { |
| | 1243 | MakeVolumetricExplosionAt(&dynPtr->Position, EXPLOSION_SADAR_BLAST); |
| | 1244 | Explosion_SoundData.position = dynPtr->Position; |
| | 1245 | Sound_Play(SID_NICE_EXPLOSION, "nh", &Explosion_SoundData); |
| | 1246 | } |
| | 1247 | |
| | 1248 | /* for net game support: send a message saying we've blown up... */ |
| | 1249 | if(SinglePlayer != AvP.PlayMode) |
| | 1250 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 1251 | |
| | 1252 | /* destroy rocket */ |
| | 1253 | sbPtr->please_destroy_me = 1; |
| | 1254 | } |
| | 1255 | else |
| | 1256 | { |
| | 1257 | bbPtr->counter -= NormalFrameTime; |
| | 1258 | MakeRocketTrailParticles(&dynPtr->PrevPosition, &dynPtr->Position); |
| | 1259 | } |
| | 1260 | } |
| | 1261 | |
| | 1262 | void GrenadeBehaviour(STRATEGYBLOCK *sbPtr) |
| | 1263 | { |
| | 1264 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr; |
| | 1265 | COLLISIONREPORT *reportPtr = dynPtr->CollisionReportPtr; |
| | 1266 | GRENADE_BEHAV_BLOCK *bbPtr = (GRENADE_BEHAV_BLOCK * )sbPtr->dataptr; |
| | 1267 | |
| | 1268 | if (reportPtr == NULL) |
| | 1269 | { |
| | 1270 | bbPtr->bouncelastframe = !DynamicObjectIsMoving(dynPtr); |
| | 1271 | } |
| | 1272 | else |
| | 1273 | { |
| | 1274 | if(reportPtr->ObstacleSBPtr) |
| | 1275 | { |
| | 1276 | switch(reportPtr->ObstacleSBPtr->type) |
| | 1277 | { |
| | 1278 | case I_BehaviourAlien: |
| | 1279 | case I_BehaviourMarinePlayer: |
| | 1280 | case I_BehaviourAlienPlayer: |
| | 1281 | case I_BehaviourPredatorPlayer: |
| | 1282 | case I_BehaviourPredator: |
| | 1283 | case I_BehaviourXenoborg: |
| | 1284 | case I_BehaviourMarine: |
| | 1285 | case I_BehaviourQueenAlien: |
| | 1286 | bbPtr->counter = 0; |
| | 1287 | break; |
| | 1288 | case I_BehaviourInanimateObject: |
| | 1289 | CauseDamageToObject(reportPtr->ObstacleSBPtr, &damage_profiles[FALLINGDAMAGE], 100 * NormalFrameTime, NULL); |
| | 1290 | //CauseDamageToObject(reportPtr->ObstacleSBPtr, &damage_profiles[CERTAINDEATH], 100 * NormalFrameTime, NULL); |
| | 1291 | break; |
| | 1292 | case I_BehaviourNetGhost: |
| | 1293 | { |
| | 1294 | NETGHOSTDATABLOCK *ghostData = reportPtr->ObstacleSBPtr->dataptr; |
| | 1295 | |
| | 1296 | switch(ghostData->type) |
| | 1297 | { |
| | 1298 | case I_BehaviourMarinePlayer: |
| | 1299 | case I_BehaviourPredatorPlayer: |
| | 1300 | case I_BehaviourAlienPlayer: |
| | 1301 | case I_BehaviourAlien: |
| | 1302 | bbPtr->counter = 0; |
| | 1303 | default: |
| | 1304 | break; |
| | 1305 | } |
| | 1306 | } |
| | 1307 | default: |
| | 1308 | break; |
| | 1309 | } |
| | 1310 | } |
| | 1311 | |
| | 1312 | if (bbPtr->counter && !bbPtr->bouncelastframe) |
| | 1313 | { |
| | 1314 | Sound_Play(SID_GRENADE_BOUNCE, "dph", &dynPtr->Position, ((FastRandom()&511)-255)); |
| | 1315 | bbPtr->bouncelastframe = 1; |
| | 1316 | } |
| | 1317 | } |
| | 1318 | |
| | 1319 | if (bbPtr->counter <= 0) |
| | 1320 | { |
| | 1321 | DestroyActiveObject(&sbPtr->DisplayBlock); |
| | 1322 | |
| | 1323 | if (sbPtr->containingModule) |
| | 1324 | { |
| | 1325 | MakeVolumetricExplosionAt(&dynPtr->Position, EXPLOSION_GRENADE_BLAST); |
| | 1326 | Explosion_SoundData.position = dynPtr->Position; |
| | 1327 | Sound_Play(SID_GRENADE_EXPLOSION, "nh", &Explosion_SoundData); |
| | 1328 | } |
| | 1329 | |
| | 1330 | if(SinglePlayer != AvP.PlayMode) |
| | 1331 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 1332 | |
| | 1333 | sbPtr->please_destroy_me = 1; |
| | 1334 | } |
| | 1335 | else |
| | 1336 | { |
| | 1337 | bbPtr->counter -= NormalFrameTime; |
| | 1338 | MakeGrenadeTrailParticles(&dynPtr->PrevPosition, &dynPtr->Position); |
| | 1339 | DynamicallyRotateObject(dynPtr); |
| | 1340 | } |
| | 1341 | } |
| | 1342 | |
| | 1343 | void FragGrenadeBehaviour(STRATEGYBLOCK *sbPtr) |
| | 1344 | { |
| | 1345 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr; |
| | 1346 | COLLISIONREPORT *reportPtr = dynPtr->CollisionReportPtr; |
| | 1347 | GRENADE_BEHAV_BLOCK *bbPtr = (GRENADE_BEHAV_BLOCK * )sbPtr->dataptr; |
| | 1348 | |
| | 1349 | if (reportPtr == NULL) |
| | 1350 | { |
| | 1351 | bbPtr->bouncelastframe = !DynamicObjectIsMoving(dynPtr); |
| | 1352 | } |
| | 1353 | else |
| | 1354 | { |
| | 1355 | do |
| | 1356 | { |
| | 1357 | if (reportPtr->ObstacleSBPtr) |
| | 1358 | { |
| | 1359 | switch(reportPtr->ObstacleSBPtr->type) |
| | 1360 | { |
| | 1361 | case I_BehaviourAlien: |
| | 1362 | case I_BehaviourMarinePlayer: |
| | 1363 | case I_BehaviourAlienPlayer: |
| | 1364 | case I_BehaviourPredatorPlayer: |
| | 1365 | case I_BehaviourPredator: |
| | 1366 | case I_BehaviourXenoborg: |
| | 1367 | case I_BehaviourMarine: |
| | 1368 | case I_BehaviourQueenAlien: |
| | 1369 | bbPtr->counter = 0; |
| | 1370 | break; |
| | 1371 | case I_BehaviourNetGhost: |
| | 1372 | { |
| | 1373 | NETGHOSTDATABLOCK *ghostData = reportPtr->ObstacleSBPtr->dataptr; |
| | 1374 | |
| | 1375 | switch(ghostData->type) |
| | 1376 | { |
| | 1377 | case I_BehaviourMarinePlayer: |
| | 1378 | case I_BehaviourPredatorPlayer: |
| | 1379 | case I_BehaviourAlienPlayer: |
| | 1380 | case I_BehaviourAlien: |
| | 1381 | bbPtr->counter = 0; |
| | 1382 | default: |
| | 1383 | break; |
| | 1384 | } |
| | 1385 | } |
| | 1386 | default: |
| | 1387 | break; |
| | 1388 | } |
| | 1389 | } |
| | 1390 | else |
| | 1391 | { |
| | 1392 | dynPtr->IgnoreThePlayer = 0; |
| | 1393 | } |
| | 1394 | |
| | 1395 | reportPtr = reportPtr->NextCollisionReportPtr; |
| | 1396 | |
| | 1397 | } while (reportPtr); |
| | 1398 | |
| | 1399 | if (bbPtr->counter && !bbPtr->bouncelastframe) |
| | 1400 | { |
| | 1401 | Sound_Play(SID_GRENADE_BOUNCE, "dph", &dynPtr->Position, ((FastRandom()&511)-255)); |
| | 1402 | bbPtr->bouncelastframe = 1; |
| | 1403 | } |
| | 1404 | } |
| | 1405 | |
| | 1406 | if (bbPtr->counter <= 0) |
| | 1407 | { |
| | 1408 | if (sbPtr->containingModule) |
| | 1409 | { |
| | 1410 | Explosion_SoundData.position = dynPtr->Position; |
| | 1411 | Sound_Play(SID_NADEEXPLODE, "nh", &Explosion_SoundData); |
| | 1412 | MakeFlechetteExplosionAt(&dynPtr->Position, 0); |
| | 1413 | } |
| | 1414 | |
| | 1415 | /* for net game support: send a message saying we've blown up... */ |
| | 1416 | if(SinglePlayer != AvP.PlayMode) |
| | 1417 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 1418 | |
| | 1419 | sbPtr->please_destroy_me = 1; |
| | 1420 | } |
| | 1421 | else |
| | 1422 | { |
| | 1423 | VECTORCH velocity; |
| | 1424 | velocity.vx = (FastRandom()&255) - 128; |
| | 1425 | velocity.vy = -1000-(FastRandom()&255); |
| | 1426 | velocity.vz = (FastRandom()&255) - 128; |
| | 1427 | MakeParticle(&dynPtr->Position, &velocity, PARTICLE_BLACKSMOKE); |
| | 1428 | |
| | 1429 | bbPtr->counter -= NormalFrameTime; |
| | 1430 | DynamicallyRotateObject(dynPtr); |
| | 1431 | } |
| | 1432 | } |
| | 1433 | |
| | 1434 | int ValidTargetForProxMine(const STRATEGYBLOCK *sbPtr) |
| | 1435 | { |
| | 1436 | int i = NumActiveStBlocks; |
| | 1437 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr; |
| | 1438 | |
| | 1439 | while(i) |
| | 1440 | { |
| | 1441 | STRATEGYBLOCK *obstaclePtr = ActiveStBlockList[--i]; |
| | 1442 | DYNAMICSBLOCK *obstacleDynPtr = obstaclePtr->DynPtr; |
| | 1443 | |
| | 1444 | if(NULL != obstaclePtr->DynPtr) |
| | 1445 | switch(obstaclePtr->type) |
| | 1446 | { |
| | 1447 | case I_BehaviourAlien: |
| | 1448 | case I_BehaviourMarinePlayer: |
| | 1449 | case I_BehaviourAlienPlayer: |
| | 1450 | case I_BehaviourPredatorPlayer: |
| | 1451 | case I_BehaviourPredator: |
| | 1452 | case I_BehaviourXenoborg: |
| | 1453 | case I_BehaviourMarine: |
| | 1454 | case I_BehaviourQueenAlien: |
| | 1455 | case I_BehaviourFaceHugger: |
| | 1456 | { |
| | 1457 | VECTORCH disp = obstacleDynPtr->Position; |
| | 1458 | disp.vx -= dynPtr->Position.vx; |
| | 1459 | disp.vy -= dynPtr->Position.vy; |
| | 1460 | disp.vz -= dynPtr->Position.vz; |
| | 1461 | |
| | 1462 | if (Approximate3dMagnitude(&disp) <= PROX_GRENADE_RANGE) |
| | 1463 | return 1; |
| | 1464 | } |
| | 1465 | break; |
| | 1466 | case I_BehaviourNetGhost: |
| | 1467 | { |
| | 1468 | NETGHOSTDATABLOCK *ghostDataPtr = (NETGHOSTDATABLOCK *)obstaclePtr->dataptr; |
| | 1469 | |
| | 1470 | switch(ghostDataPtr->type) |
| | 1471 | { |
| | 1472 | case I_BehaviourAlienPlayer: |
| | 1473 | case I_BehaviourMarinePlayer: |
| | 1474 | case I_BehaviourPredatorPlayer: |
| | 1475 | case I_BehaviourAlien: |
| | 1476 | { |
| | 1477 | VECTORCH disp = obstacleDynPtr->Position; |
| | 1478 | disp.vx -= dynPtr->Position.vx; |
| | 1479 | disp.vy -= dynPtr->Position.vy; |
| | 1480 | disp.vz -= dynPtr->Position.vz; |
| | 1481 | |
| | 1482 | if (Approximate3dMagnitude(&disp) <= PROX_GRENADE_RANGE) |
| | 1483 | return 1; |
| | 1484 | } |
| | 1485 | default: |
| | 1486 | continue; |
| | 1487 | } |
| | 1488 | } |
| | 1489 | default: |
| | 1490 | continue; |
| | 1491 | } |
| | 1492 | } |
| | 1493 | |
| | 1494 | return 0; |
| | 1495 | } |
| | 1496 | |
| | 1497 | void ProximityGrenadeBehaviour(STRATEGYBLOCK *sbPtr) |
| | 1498 | { |
| | 1499 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr; |
| | 1500 | PROX_GRENADE_BEHAV_BLOCK *bbPtr = (PROX_GRENADE_BEHAV_BLOCK *)sbPtr->dataptr; |
| | 1501 | |
| | 1502 | if (bbPtr->counter <= 0) |
| | 1503 | { |
| | 1504 | if (bbPtr->SoundHandle != SOUND_NOACTIVEINDEX) |
| | 1505 | { |
| | 1506 | Sound_Stop(bbPtr->SoundHandle); |
| | 1507 | bbPtr->SoundHandle = SOUND_NOACTIVEINDEX; |
| | 1508 | } |
| | 1509 | |
| | 1510 | DestroyActiveObject(&sbPtr->DisplayBlock); |
| | 1511 | MakeVolumetricExplosionAt(&dynPtr->Position, EXPLOSION_GRENADE_BLAST); |
| | 1512 | |
| | 1513 | if (sbPtr->containingModule) |
| | 1514 | { |
| | 1515 | Explosion_SoundData.position = dynPtr->Position; |
| | 1516 | Sound_Play(SID_GRENADE_PROXEXPLOSION, "np", &Explosion_SoundData); |
| | 1517 | } |
| | 1518 | |
| | 1519 | /* for net game support: send a message saying we've blown up... */ |
| | 1520 | if(SinglePlayer != AvP.PlayMode) |
| | 1521 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 1522 | |
| | 1523 | sbPtr->please_destroy_me = 1; |
| | 1524 | } |
| | 1525 | else |
| | 1526 | { |
| | 1527 | if (dynPtr->IsStatic) |
| | 1528 | { |
| | 1529 | if(bbPtr->counter > PROX_GRENADE_TRIGGER_TIME) |
| | 1530 | { |
| | 1531 | // scan for objects in proximity |
| | 1532 | |
| | 1533 | if (ValidTargetForProxMine(sbPtr)) |
| | 1534 | { |
| | 1535 | bbPtr->counter = PROX_GRENADE_TRIGGER_TIME; |
| | 1536 | Sound_Play(SID_PROX_GRENADE_READYTOBLOW, "deh", &dynPtr->Position, &bbPtr->SoundHandle); |
| | 1537 | } |
| | 1538 | else |
| | 1539 | { |
| | 1540 | int scale = ONE_FIXED - bbPtr->counter / PROX_GRENADE_LIFETIME; |
| | 1541 | scale = MUL_FIXED(scale, scale); |
| | 1542 | scale = MUL_FIXED(scale, scale) * 8; |
| | 1543 | bbPtr->SoundGenerationTimer += NormalFrameTime + MUL_FIXED(NormalFrameTime, scale); |
| | 1544 | |
| | 1545 | while (bbPtr->SoundGenerationTimer >= PROX_GRENADE_SOUND_GENERATION_TIME) |
| | 1546 | { |
| | 1547 | bbPtr->SoundGenerationTimer -= PROX_GRENADE_SOUND_GENERATION_TIME; |
| | 1548 | Sound_Play(SID_PROX_GRENADE_ACTIVE, "dh", &dynPtr->Position); |
| | 1549 | } |
| | 1550 | } |
| | 1551 | } |
| | 1552 | } |
| | 1553 | else |
| | 1554 | { |
| | 1555 | COLLISIONREPORT *reportPtr = dynPtr->CollisionReportPtr; |
| | 1556 | |
| | 1557 | if (reportPtr) |
| | 1558 | { |
| | 1559 | char stickWhereYouAre = 0; |
| | 1560 | |
| | 1561 | STRATEGYBLOCK *obstaclePtr = reportPtr->ObstacleSBPtr; |
| | 1562 | |
| | 1563 | if (obstaclePtr) |
| | 1564 | { |
| | 1565 | DISPLAYBLOCK *dispPtr = obstaclePtr->DisplayBlock; |
| | 1566 | |
| | 1567 | if (dispPtr && dispPtr->Module) |
| | 1568 | { |
| | 1569 | if(NULL != dispPtr->ObMorphCtrl) |
| | 1570 | stickWhereYouAre = 1; |
| | 1571 | } |
| | 1572 | else |
| | 1573 | { |
| | 1574 | switch(obstaclePtr->type) |
| | 1575 | { |
| | 1576 | case I_BehaviourAlien: |
| | 1577 | case I_BehaviourMarinePlayer: |
| | 1578 | case I_BehaviourAlienPlayer: |
| | 1579 | case I_BehaviourPredatorPlayer: |
| | 1580 | case I_BehaviourPredator: |
| | 1581 | case I_BehaviourXenoborg: |
| | 1582 | case I_BehaviourMarine: |
| | 1583 | case I_BehaviourQueenAlien: |
| | 1584 | case I_BehaviourFaceHugger: |
| | 1585 | // best blow up then |
| | 1586 | bbPtr->counter = 0; |
| | 1587 | return; |
| | 1588 | case I_BehaviourNetGhost: |
| | 1589 | { |
| | 1590 | NETGHOSTDATABLOCK *ghostDataPtr = (NETGHOSTDATABLOCK *)obstaclePtr->dataptr; |
| | 1591 | |
| | 1592 | switch(ghostDataPtr->type) |
| | 1593 | { |
| | 1594 | case I_BehaviourAlienPlayer: |
| | 1595 | case I_BehaviourMarinePlayer: |
| | 1596 | case I_BehaviourPredatorPlayer: |
| | 1597 | case I_BehaviourAlien: |
| | 1598 | // best blow up then |
| | 1599 | bbPtr->counter = 0; |
| | 1600 | return; |
| | 1601 | default: |
| | 1602 | break; |
| | 1603 | } |
| | 1604 | } |
| | 1605 | default: |
| | 1606 | break; |
| | 1607 | } |
| | 1608 | } |
| | 1609 | } |
| | 1610 | else |
| | 1611 | { |
| | 1612 | stickWhereYouAre = 1; |
| | 1613 | } |
| | 1614 | |
| | 1615 | if(stickWhereYouAre) |
| | 1616 | { |
| | 1617 | dynPtr->IsStatic = 1; |
| | 1618 | dynPtr->PrevPosition = dynPtr->Position; |
| | 1619 | MakeMatrixFromDirection(&reportPtr->ObstacleNormal, &dynPtr->OrientMat); |
| | 1620 | /* KJL 15:27:42 23/01/99 - Euler has to be filled out for network play! */ |
| | 1621 | MatrixToEuler(&dynPtr->OrientMat, &dynPtr->OrientEuler); |
| | 1622 | bbPtr->counter = PROX_GRENADE_LIFETIME * ONE_FIXED; |
| | 1623 | } |
| | 1624 | } |
| | 1625 | |
| | 1626 | MakeGrenadeTrailParticles(&dynPtr->PrevPosition, &dynPtr->Position); |
| | 1627 | } |
| | 1628 | |
| | 1629 | bbPtr->counter -= NormalFrameTime; |
| | 1630 | } |
| | 1631 | } |
| | 1632 | |
| | 1633 | void FlareBehaviour(STRATEGYBLOCK *sbPtr) |
| | 1634 | { |
| | 1635 | FLARE_BEHAV_BLOCK *bbPtr = (FLARE_BEHAV_BLOCK * ) sbPtr->dataptr; |
| | 1636 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr; |
| | 1637 | |
| | 1638 | if (bbPtr->SoundHandle != SOUND_NOACTIVEINDEX) |
| | 1639 | ActiveSounds[bbPtr->SoundHandle].threedeedata.position = dynPtr->Position; |
| | 1640 | |
| | 1641 | if (bbPtr->LifeTimeRemaining <= 0) |
| | 1642 | { |
| | 1643 | if (bbPtr->SoundHandle != SOUND_NOACTIVEINDEX) |
| | 1644 | { |
| | 1645 | Sound_Stop(bbPtr->SoundHandle); |
| | 1646 | bbPtr->SoundHandle = SOUND_NOACTIVEINDEX; |
| | 1647 | } |
| | 1648 | |
| | 1649 | /* for net game support: send a message saying we've blown up... */ |
| | 1650 | if(SinglePlayer != AvP.PlayMode) |
| | 1651 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 1652 | |
| | 1653 | sbPtr->please_destroy_me = 1; |
| | 1654 | |
| | 1655 | return; |
| | 1656 | } |
| | 1657 | else if (bbPtr->LifeTimeRemaining > ONE_FIXED * 4) |
| | 1658 | bbPtr->ParticleGenerationTimer += NormalFrameTime; |
| | 1659 | else |
| | 1660 | bbPtr->ParticleGenerationTimer += MUL_FIXED(NormalFrameTime, bbPtr->LifeTimeRemaining)/4; |
| | 1661 | |
| | 1662 | while (bbPtr->ParticleGenerationTimer >= FLARE_PARTICLE_GENERATION_TIME) |
| | 1663 | { |
| | 1664 | bbPtr->ParticleGenerationTimer -= FLARE_PARTICLE_GENERATION_TIME; |
| | 1665 | MakeFlareParticle(dynPtr); |
| | 1666 | } |
| | 1667 | |
| | 1668 | /* add lighting effect */ |
| | 1669 | { |
| | 1670 | LIGHTBLOCK *lightPtr = sbPtr->DisplayBlock->ObLights[0]; |
| | 1671 | assert(sbPtr->DisplayBlock->ObNumLights == 1); |
| | 1672 | lightPtr->LightBright = 1 + MUL_FIXED( (ONE_FIXED*4-(FastRandom()&32767)), bbPtr->LifeTimeRemaining / FLARE_LIFETIME); |
| | 1673 | } |
| | 1674 | |
| | 1675 | bbPtr->LifeTimeRemaining -= NormalFrameTime; |
| | 1676 | |
| | 1677 | if (dynPtr->IsFloating) |
| | 1678 | { |
| | 1679 | RubberDuckBehaviour(sbPtr); |
| | 1680 | } |
| | 1681 | else if(!dynPtr->IsStatic) |
| | 1682 | { |
| | 1683 | COLLISIONREPORT *reportPtr = dynPtr->CollisionReportPtr; |
| | 1684 | |
| | 1685 | if (reportPtr) |
| | 1686 | { |
| | 1687 | char stickWhereYouAre = 0; |
| | 1688 | |
| | 1689 | if (reportPtr->ObstacleSBPtr) |
| | 1690 | { |
| | 1691 | DISPLAYBLOCK *dispPtr = reportPtr->ObstacleSBPtr->DisplayBlock; |
| | 1692 | |
| | 1693 | if (dispPtr) |
| | 1694 | { |
| | 1695 | STRATEGYBLOCK* hit_sbptr = reportPtr->ObstacleSBPtr; |
| | 1696 | |
| | 1697 | if (dispPtr->Module) |
| | 1698 | { |
| | 1699 | if(NULL != dispPtr->ObMorphCtrl) stickWhereYouAre = 1; |
| | 1700 | } |
| | 1701 | else |
| | 1702 | { |
| | 1703 | switch(hit_sbptr->type) |
| | 1704 | { |
| | 1705 | case I_BehaviourAlien: |
| | 1706 | { |
| | 1707 | ALIEN_STATUS_BLOCK *alienStatusPointer = (ALIEN_STATUS_BLOCK *)(hit_sbptr->dataptr); |
| | 1708 | CauseDamageToObject(hit_sbptr, &damage_profiles[FIREDAMAGE], NormalFrameTime, NULL); |
| | 1709 | NPC_OBSTRUCTIONREPORT obstruction = {1,0,0,0}; |
| | 1710 | NPC_InitMovementData(&alienStatusPointer->moveData); |
| | 1711 | NPCGetAvoidanceDirection(sbPtr, &alienStatusPointer->moveData.avoidanceDirn, &obstruction); |
| | 1712 | alienStatusPointer->BehaviourState = ABS_Avoidance; |
| | 1713 | alienStatusPointer->StateTimer = ONE_FIXED / 8; |
| | 1714 | } |
| | 1715 | break; |
| | 1716 | default: |
| | 1717 | CauseDamageToObject(hit_sbptr, &damage_profiles[FIREDAMAGE], NormalFrameTime, NULL); |
| | 1718 | } |
| | 1719 | } |
| | 1720 | } |
| | 1721 | } |
| | 1722 | else |
| | 1723 | { |
| | 1724 | stickWhereYouAre = 1; |
| | 1725 | } |
| | 1726 | |
| | 1727 | if(stickWhereYouAre) |
| | 1728 | { |
| | 1729 | dynPtr->IsStatic = 1; |
| | 1730 | dynPtr->OnlyCollideWithEnvironment = 1; |
| | 1731 | dynPtr->PrevPosition = dynPtr->Position; |
| | 1732 | MakeMatrixFromDirection(&reportPtr->ObstacleNormal, &dynPtr->OrientMat); |
| | 1733 | /* KJL 15:27:42 23/01/99 - Euler has to be filled out for network play! */ |
| | 1734 | MatrixToEuler(&dynPtr->OrientMat, &dynPtr->OrientEuler); |
| | 1735 | //set flag, so appropriate net message gets sent |
| | 1736 | bbPtr->becomeStuck = 1; |
| | 1737 | Sound_Play(SID_BURNING_FLARE, "dlev", &dynPtr->Position, &bbPtr->SoundHandle, 50); |
| | 1738 | } |
| | 1739 | } |
| | 1740 | } |
| | 1741 | } |
| | 1742 | |
| | 1743 | void PulseGrenadeBehaviour(STRATEGYBLOCK *sbPtr) |
| | 1744 | { |
| | 1745 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr; |
| | 1746 | COLLISIONREPORT *reportPtr = dynPtr->CollisionReportPtr; |
| | 1747 | PREDPISTOL_BEHAV_BLOCK *bbPtr = (PREDPISTOL_BEHAV_BLOCK * )sbPtr->dataptr; |
| | 1748 | |
| | 1749 | if (reportPtr) |
| | 1750 | { |
| | 1751 | if(reportPtr->ObstacleSBPtr && bbPtr->player && AccuracyStats_TargetFilter(reportPtr->ObstacleSBPtr)) |
| | 1752 | { |
| | 1753 | int slot = SlotForThisWeapon(WEAPON_PULSERIFLE); |
| | 1754 | |
| | 1755 | if (slot != -1) |
| | 1756 | CurrentGameStats_WeaponHit(slot, 1); |
| | 1757 | } |
| | 1758 | } |
| | 1759 | else |
| | 1760 | { |
| | 1761 | bbPtr->counter -= NormalFrameTime; |
| | 1762 | |
| | 1763 | if (bbPtr->counter > 0) |
| | 1764 | { |
| | 1765 | MakeRocketTrailParticles(&dynPtr->PrevPosition, &dynPtr->Position); |
| | 1766 | return; |
| | 1767 | } |
| | 1768 | } |
| | 1769 | |
| | 1770 | DestroyActiveObject(&sbPtr->DisplayBlock); |
| | 1771 | MakeVolumetricExplosionAt(&dynPtr->Position, EXPLOSION_PULSEGRENADE); |
| | 1772 | |
| | 1773 | //if (sbPtr->containingModule) |
| | 1774 | { |
| | 1775 | Explosion_SoundData.position = dynPtr->Position; |
| | 1776 | Sound_Play(SID_NADEEXPLODE, "nh", &Explosion_SoundData); |
| | 1777 | } |
| | 1778 | |
| | 1779 | /* for net game support: send a message saying we've blown up... */ |
| | 1780 | if(SinglePlayer != AvP.PlayMode) |
| | 1781 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 1782 | |
| | 1783 | sbPtr->please_destroy_me = 1; |
| | 1784 | } |
| | 1785 | |
| | 1786 | void PPPlasmaBoltBehaviour(STRATEGYBLOCK *sbPtr) |
| | 1787 | { |
| | 1788 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr; |
| | 1789 | COLLISIONREPORT *reportPtr = dynPtr->CollisionReportPtr; |
| | 1790 | PREDPISTOL_BEHAV_BLOCK *bbPtr = (PREDPISTOL_BEHAV_BLOCK * ) sbPtr->dataptr; |
| | 1791 | |
| | 1792 | if (reportPtr) |
| | 1793 | { |
| | 1794 | if(reportPtr->ObstacleSBPtr && bbPtr->player && AccuracyStats_TargetFilter(reportPtr->ObstacleSBPtr)) |
| | 1795 | { |
| | 1796 | int slot = SlotForThisWeapon(WEAPON_PRED_PISTOL); |
| | 1797 | |
| | 1798 | if (slot != -1) |
| | 1799 | CurrentGameStats_WeaponHit(slot,1); |
| | 1800 | } |
| | 1801 | } |
| | 1802 | else if (bbPtr->counter > 0) |
| | 1803 | { |
| | 1804 | bbPtr->counter -= NormalFrameTime; |
| | 1805 | return; |
| | 1806 | } |
| | 1807 | |
| | 1808 | DestroyActiveObject(&sbPtr->DisplayBlock); |
| | 1809 | MakeElectricalExplosion(&dynPtr->Position); |
| | 1810 | |
| | 1811 | if(SinglePlayer != AvP.PlayMode) |
| | 1812 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 1813 | |
| | 1814 | sbPtr->please_destroy_me = 1; |
| | 1815 | } |
| | 1816 | |
| | 1817 | static DISPLAYBLOCK* InitialiseSpeargunBoltBehaviour_ForLoad() |
| | 1818 | { |
| | 1819 | STRATEGYBLOCK* sbPtr = CreateActiveStrategyBlock(I_BehaviourSpeargunBolt); |
| | 1820 | |
| | 1821 | if(NULL == sbPtr) |
| | 1822 | return NULL; |
| | 1823 | |
| | 1824 | int shapeIndex = GetLoadedShapeMSL("spear"); |
| | 1825 | |
| | 1826 | DISPLAYBLOCK *dispPtr = sbPtr->DisplayBlock = AllocateNewObject(shapeIndex); |
| | 1827 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr = AllocateDynamicsBlock(DYNAMICS_TEMPLATE_GRENADE); |
| | 1828 | sbPtr->dataptr = malloc(sizeof(SPEAR_BEHAV_BLOCK)); |
| | 1829 | |
| | 1830 | if (!dynPtr || !sbPtr->dataptr || !dispPtr) |
| | 1831 | { |
| | 1832 | RemoveBehaviourStrategy(sbPtr); |
| | 1833 | return NULL; |
| | 1834 | } |
| | 1835 | |
| | 1836 | dispPtr->ObWorld.vx = dispPtr->ObWorld.vy = dispPtr->ObWorld.vz = 0; |
| | 1837 | |
| | 1838 | dispPtr->ObStrategyBlock = sbPtr; |
| | 1839 | sbPtr->shapeIndex = shapeIndex; |
| | 1840 | |
| | 1841 | dispPtr->extent.min_x = -10; |
| | 1842 | dispPtr->extent.min_y = -10; |
| | 1843 | dispPtr->extent.min_y = -10; |
| | 1844 | dispPtr->extent.max_x = 10; |
| | 1845 | dispPtr->extent.max_y = 10; |
| | 1846 | dispPtr->extent.max_z = 10; |
| | 1847 | |
| | 1848 | return dispPtr; |
| | 1849 | } |
| | 1850 | |
| | 1851 | void SpeargunBoltBehaviour(STRATEGYBLOCK *sbPtr) |
| | 1852 | { |
| | 1853 | SPEAR_BEHAV_BLOCK *bbPtr = (SPEAR_BEHAV_BLOCK * ) sbPtr->dataptr; |
| | 1854 | |
| | 1855 | if (bbPtr->counter > 0) |
| | 1856 | { |
| | 1857 | bbPtr->counter -= NormalFrameTime; |
| | 1858 | |
| | 1859 | if (!bbPtr->Stuck) |
| | 1860 | { |
| | 1861 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr; |
| | 1862 | COLLISIONREPORT *reportPtr = dynPtr->CollisionReportPtr; |
| | 1863 | |
| | 1864 | if (reportPtr) |
| | 1865 | { |
| | 1866 | int normDotBeta = DotProduct(&dynPtr->LinVelocity, &reportPtr->ObstacleNormal); |
| | 1867 | |
| | 1868 | char stickWhereYouAre = 0; |
| | 1869 | |
| | 1870 | if (reportPtr->ObstacleSBPtr) |
| | 1871 | { |
| | 1872 | DISPLAYBLOCK *dispPtr = reportPtr->ObstacleSBPtr->DisplayBlock; |
| | 1873 | |
| | 1874 | if (dispPtr && dispPtr->Module && !dispPtr->ObMorphCtrl) |
| | 1875 | { |
| | 1876 | stickWhereYouAre = 1; |
| | 1877 | } |
| | 1878 | else |
| | 1879 | { |
| | 1880 | STRATEGYBLOCK * victim = reportPtr->ObstacleSBPtr; |
| | 1881 | //reportPtr->ObstacleNormal; |
| | 1882 | //reportPtr->ObstaclePoint; |
| | 1883 | |
| | 1884 | if(bbPtr->FromPlayer && AccuracyStats_TargetFilter(reportPtr->ObstacleSBPtr)) |
| | 1885 | CurrentGameStats_WeaponHit(PlayerStatus.SelectedWeaponSlot, 1); |
| | 1886 | |
| | 1887 | if(0) |
| | 1888 | if (victim->DisplayBlock) |
| | 1889 | { |
| | 1890 | if (victim->DisplayBlock->HModelControlBlock) |
| | 1891 | { |
| | 1892 | //bbPtr->SpearThroughFragment = 1; |
| | 1893 | DISPLAYBLOCK *fragged_section = CauseDamageToHModel(victim->DisplayBlock->HModelControlBlock, victim, &TemplateAmmo[AMMO_PRED_RIFLE].MaxDamage,
ONE_FIXED, |
| | 1894 | //this_section_data, |
| | 1895 | victim->DisplayBlock->HModelControlBlock->section_data, |
| | 1896 | &reportPtr->ObstacleNormal, &reportPtr->ObstaclePoint, 0); |
| | 1897 | |
| | 1898 | if (fragged_section) |
| | 1899 | { |
| | 1900 | #define SPEAR_NPC_IMPULSE (2000) |
| | 1901 | fragged_section->ObStrategyBlock->DynPtr->LinImpulse.vx += MUL_FIXED(reportPtr->ObstacleNormal.vx, SPEAR_NPC_IMPULSE); |
| | 1902 | fragged_section->ObStrategyBlock->DynPtr->LinImpulse.vy += MUL_FIXED(reportPtr->ObstacleNormal.vy, SPEAR_NPC_IMPULSE); |
| | 1903 | fragged_section->ObStrategyBlock->DynPtr->LinImpulse.vz += MUL_FIXED(reportPtr->ObstacleNormal.vz, SPEAR_NPC_IMPULSE); |
| | 1904 | CreateSpearPossiblyWithFragment(fragged_section, &reportPtr->ObstaclePoint, &reportPtr->ObstacleNormal); |
| | 1905 | } |
| | 1906 | |
| | 1907 | /* |
| | 1908 | switch(victim->type) |
| | 1909 | { |
| | 1910 | case I_BehaviourMarinePlayer: |
| | 1911 | case I_BehaviourPredatorPlayer: |
| | 1912 | case I_BehaviourAlienPlayer: |
| | 1913 | case I_BehaviourAlien: |
| | 1914 | case I_BehaviourQueenAlien: |
| | 1915 | case I_BehaviourFaceHugger: |
| | 1916 | case I_BehaviourPredator: |
| | 1917 | case I_BehaviourXenoborg: |
| | 1918 | case I_BehaviourMarine: |
| | 1919 | case I_BehaviourAutoGun: |
| | 1920 | case I_BehaviourHierarchicalFragment: |
| | 1921 | case I_BehaviourCorpse: |
| | 1922 | case I_BehaviourDummy: |
| | 1923 | |
| | 1924 | } |
| | 1925 | */ |
| | 1926 | |
| | 1927 | } |
| | 1928 | } |
| | 1929 | |
| | 1930 | VECTORCH attack_dir; |
| | 1931 | GetDirectionOfAttack(reportPtr->ObstacleSBPtr, &dynPtr->LinVelocity, &attack_dir); |
| | 1932 | //CauseDamageToObject(reportPtr->ObstacleSBPtr, &TemplateAmmo[AMMO_PRED_RIFLE].MaxDamage, ONE_FIXED, NULL); |
| | 1933 | } |
| | 1934 | } |
| | 1935 | else |
| | 1936 | { |
| | 1937 | stickWhereYouAre = 1; |
| | 1938 | } |
| | 1939 | |
| | 1940 | if(stickWhereYouAre && normDotBeta) |
| | 1941 | { |
| | 1942 | /* Sink in... */ |
| | 1943 | Sound_Play(SID_SPEARGUN_HITTING_WALL, "d", &dynPtr->Position); |
| | 1944 | bbPtr->Stuck = 1; |
| | 1945 | /* Counter at 20s. */ |
| | 1946 | bbPtr->counter = (20 * ONE_FIXED); |
| | 1947 | dynPtr->GravityOn = 0; |
| | 1948 | dynPtr->DynamicsType = DYN_TYPE_NO_COLLISIONS; |
| | 1949 | |
| | 1950 | { |
| | 1951 | /* get a pt in the poly */ |
| | 1952 | VECTORCH pop = reportPtr->ObstaclePoint; |
| | 1953 | pop.vx -= dynPtr->Position.vx; |
| | 1954 | pop.vy -= dynPtr->Position.vy; |
| | 1955 | pop.vz -= dynPtr->Position.vz; |
| | 1956 | |
| | 1957 | /* hmm, what about double sided polys? */ |
| | 1958 | int d = DotProduct(&reportPtr->ObstacleNormal, &pop); |
| | 1959 | |
| | 1960 | int lambda = DIV_FIXED(d, normDotBeta); |
| | 1961 | |
| | 1962 | dynPtr->Position.vx += MUL_FIXED(lambda, dynPtr->LinVelocity.vx); |
| | 1963 | dynPtr->Position.vy += MUL_FIXED(lambda, dynPtr->LinVelocity.vy); |
| | 1964 | dynPtr->Position.vz += MUL_FIXED(lambda, dynPtr->LinVelocity.vz); |
| | 1965 | } |
| | 1966 | |
| | 1967 | dynPtr->LinVelocity.vx = dynPtr->LinVelocity.vy = dynPtr->LinVelocity.vz = 0; |
| | 1968 | dynPtr->LinImpulse.vx = dynPtr->LinImpulse.vy = dynPtr->LinImpulse.vz = 0; |
| | 1969 | //dynPtr->IsStatic = 1; |
| | 1970 | |
| | 1971 | MakeFocusedExplosion(&dynPtr->PrevPosition, &dynPtr->Position, 20, PARTICLE_SPARK); |
| | 1972 | MakeLightElement(&dynPtr->Position, LIGHTELEMENT_ELECTRICAL_SPARKS); |
| | 1973 | } |
| | 1974 | |
| | 1975 | bbPtr->Stuck = 1; |
| | 1976 | } |
| | 1977 | } |
| | 1978 | } |
| | 1979 | else |
| | 1980 | { |
| | 1981 | /* for net game support: send a message saying we've blown up... */ |
| | 1982 | if(SinglePlayer != AvP.PlayMode) |
| | 1983 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 1984 | |
| | 1985 | sbPtr->please_destroy_me = 1; |
| | 1986 | } |
| | 1987 | } |
| | 1988 | |
| | 1989 | #define TIME_FOR_FLAMETHROWER_PARTICLE (ONE_FIXED/120) |
| | 1990 | |
| | 1991 | void FireFlameThrower(VECTORCH *base_position, const VECTORCH *base_offset, MATRIXCH *orientmat, int player, int *timer) |
| | 1992 | { |
| | 1993 | /* Simple function containing flamethrower function. */ |
| | 1994 | |
| | 1995 | VECTORCH position; |
| | 1996 | |
| | 1997 | //*timer += NormalFrameTime; |
| | 1998 | |
| | 1999 | //while (*timer >= TIME_FOR_FLAMETHROWER_PARTICLE) |
| | 2000 | { |
| | 2001 | VECTORCH velocity; |
| | 2002 | //(*timer) -= TIME_FOR_FLAMETHROWER_PARTICLE; |
| | 2003 | |
| | 2004 | /* calculate the position */ |
| | 2005 | |
| | 2006 | { |
| | 2007 | int offset = MUL_FIXED(FastRandom()&16383, NormalFrameTime); |
| | 2008 | |
| | 2009 | position = *base_offset; |
| | 2010 | |
| | 2011 | position.vz += offset; |
| | 2012 | position.vy += (FastRandom() % (offset/8+1)) - offset/16; |
| | 2013 | position.vx += (FastRandom() % (offset/8+1)) - offset/16; |
| | 2014 | } |
| | 2015 | |
| | 2016 | RotateVector(&position, orientmat); |
| | 2017 | |
| | 2018 | if (player) |
| | 2019 | { |
| | 2020 | Crunch_Position_For_Players_Weapon(&position); |
| | 2021 | } |
| | 2022 | else |
| | 2023 | { |
| | 2024 | position.vx += base_position->vx; |
| | 2025 | position.vy += base_position->vy; |
| | 2026 | position.vz += base_position->vz; |
| | 2027 | } |
| | 2028 | |
| | 2029 | velocity.vx = ((FastRandom()&1023) - 512);//*2; |
| | 2030 | velocity.vy = ((FastRandom()&1023) - 512);//*2; |
| | 2031 | velocity.vz = ((FastRandom()&511) + 200+512)*16; |
| | 2032 | RotateVector(&velocity, orientmat); |
| | 2033 | MakeParticle(&position, &velocity, PARTICLE_FLAME); |
| | 2034 | } |
| | 2035 | } |
| | 2036 | |
| | 2037 | void FireNetGhostFlameThrower(VECTORCH *positionPtr, MATRIXCH *orientMatPtr) |
| | 2038 | { |
| | 2039 | /* KJL 16:31:42 27/01/98 - these particles aren't colliding, so I'll |
| | 2040 | see what happens if I use more... */ |
| | 2041 | int i = FLAMETHROWER_PARTICLES_PER_FRAME * 2; |
| | 2042 | |
| | 2043 | VECTORCH position; |
| | 2044 | |
| | 2045 | while(i--) |
| | 2046 | /* calculate the position */ |
| | 2047 | { |
| | 2048 | VECTORCH velocity; |
| | 2049 | |
| | 2050 | { |
| | 2051 | int offset = MUL_FIXED(FastRandom()&16383, NormalFrameTime); |
| | 2052 | |
| | 2053 | position.vz = offset; |
| | 2054 | position.vy = (FastRandom()%(offset/8+1)) - offset/16; |
| | 2055 | position.vx = (FastRandom()%(offset/8+1)) - offset/16; |
| | 2056 | } |
| | 2057 | |
| | 2058 | velocity.vx = ((FastRandom()&1023) - 512);//*2; |
| | 2059 | velocity.vy = ((FastRandom()&1023) - 512);//*2; |
| | 2060 | velocity.vz = ((FastRandom()&511) + 200+512)*16; |
| | 2061 | |
| | 2062 | RotateVector(&position, orientMatPtr); |
| | 2063 | RotateVector(&velocity, orientMatPtr); |
| | 2064 | |
| | 2065 | position.vx += positionPtr->vx; |
| | 2066 | position.vy += positionPtr->vy; |
| | 2067 | position.vz += positionPtr->vz; |
| | 2068 | |
| | 2069 | if (!LocalDetailLevels.GhostFlameThrowerCollisions) |
| | 2070 | MakeParticle(&position, &velocity, PARTICLE_NONCOLLIDINGFLAME); |
| | 2071 | else |
| | 2072 | MakeParticle(&position, &velocity, PARTICLE_NONDAMAGINGFLAME); |
| | 2073 | } |
| | 2074 | } |
| | 2075 | |
| | 2076 | /*----------------------Patrick 4/3/97-------------------------- |
| | 2077 | Stuff for predator (and xenoborg) projectiles... |
| | 2078 | NB will need a creation function for player (AIs have their own) |
| | 2079 | --------------------------------------------------------------*/ |
| | 2080 | void PredatorEnergyBoltBehaviour(STRATEGYBLOCK *sbPtr) |
| | 2081 | { |
| | 2082 | CASTER_BOLT_BEHAV_BLOCK *bbPtr = (CASTER_BOLT_BEHAV_BLOCK * ) sbPtr->dataptr; |
| | 2083 | |
| | 2084 | if (bbPtr->counter > 0) |
| | 2085 | { |
| | 2086 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr; |
| | 2087 | COLLISIONREPORT *reportPtr = dynPtr->CollisionReportPtr; |
| | 2088 | |
| | 2089 | bbPtr->counter -= NormalFrameTime; |
| | 2090 | |
| | 2091 | if (reportPtr) |
| | 2092 | { |
| | 2093 | if(reportPtr->ObstacleSBPtr) |
| | 2094 | { |
| | 2095 | DISPLAYBLOCK *dispPtr = reportPtr->ObstacleSBPtr->DisplayBlock; |
| | 2096 | |
| | 2097 | if (bbPtr->player && AccuracyStats_TargetFilter(reportPtr->ObstacleSBPtr)) |
| | 2098 | { |
| | 2099 | int slot = SlotForThisWeapon(WEAPON_PRED_SHOULDERCANNON); |
| | 2100 | |
| | 2101 | if (slot != -1) |
| | 2102 | CurrentGameStats_WeaponHit(slot, 1); |
| | 2103 | } |
| | 2104 | |
| | 2105 | switch (reportPtr->ObstacleSBPtr->type) |
| | 2106 | { |
| | 2107 | case I_BehaviourMarine: |
| | 2108 | case I_BehaviourAlien: |
| | 2109 | { |
| | 2110 | if(dispPtr) |
| | 2111 | { |
| | 2112 | /* look for the object's torso in preference */ |
| | 2113 | SECTION_DATA *chest_section = GetThisSectionData(dispPtr->HModelControlBlock->section_data, "chest"); |
| | 2114 | |
| | 2115 | if (chest_section) |
| | 2116 | { |
| | 2117 | VECTORCH rel_pos = dynPtr->Position; |
| | 2118 | |
| | 2119 | rel_pos.vx -= chest_section->World_Offset.vx; |
| | 2120 | rel_pos.vy -= chest_section->World_Offset.vy; |
| | 2121 | rel_pos.vz -= chest_section->World_Offset.vz; |
| | 2122 | |
| | 2123 | Normalise(&rel_pos); |
| | 2124 | |
| | 2125 | CauseDamageToHModel(dispPtr->HModelControlBlock, reportPtr->ObstacleSBPtr, &bbPtr->damage, ONE_FIXED, chest_section, &rel_pos,
&chest_section->World_Offset, 0); |
| | 2126 | } |
| | 2127 | else |
| | 2128 | { |
| | 2129 | VECTORCH attack_dir; |
| | 2130 | GetDirectionOfAttack(reportPtr->ObstacleSBPtr,&dynPtr->LinVelocity,&attack_dir); |
| | 2131 | CauseDamageToObject(reportPtr->ObstacleSBPtr, &bbPtr->damage, ONE_FIXED, &attack_dir); |
| | 2132 | } |
| | 2133 | } |
| | 2134 | } |
| | 2135 | break; |
| | 2136 | default: |
| | 2137 | { |
| | 2138 | VECTORCH attack_dir; |
| | 2139 | GetDirectionOfAttack(reportPtr->ObstacleSBPtr,&dynPtr->LinVelocity,&attack_dir); |
| | 2140 | CauseDamageToObject(reportPtr->ObstacleSBPtr, &bbPtr->damage, ONE_FIXED, &attack_dir); |
| | 2141 | } |
| | 2142 | } |
| | 2143 | |
| | 2144 | MakePlasmaExplosion(&dynPtr->Position, &dynPtr->PrevPosition, EXPLOSION_FOCUSEDPLASMA); |
| | 2145 | |
| | 2146 | if(SinglePlayer != AvP.PlayMode) |
| | 2147 | { |
| | 2148 | AddNetMsg_MakePlasmaExplosion(&dynPtr->Position, &dynPtr->PrevPosition, EXPLOSION_FOCUSEDPLASMA); |
| | 2149 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 2150 | } |
| | 2151 | } |
| | 2152 | else |
| | 2153 | { |
| | 2154 | DestroyActiveObject(&sbPtr->DisplayBlock); |
| | 2155 | MakePlasmaExplosion(&dynPtr->Position, &dynPtr->PrevPosition, EXPLOSION_DISSIPATINGPLASMA); |
| | 2156 | |
| | 2157 | if(SinglePlayer != AvP.PlayMode) |
| | 2158 | { |
| | 2159 | AddNetMsg_MakePlasmaExplosion(&dynPtr->Position, &dynPtr->PrevPosition, EXPLOSION_DISSIPATINGPLASMA); |
| | 2160 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 2161 | } |
| | 2162 | } |
| | 2163 | |
| | 2164 | sbPtr->please_destroy_me = 1; |
| | 2165 | } |
| | 2166 | else |
| | 2167 | { |
| | 2168 | //MakePlasmaTrailParticles(dynPtr, (bbPtr->damage.Impact ? (bbPtr->damage.Impact * 5) : 20)); |
| | 2169 | MakePlasmaTrailParticles(dynPtr, (bbPtr->damage.Impact ? (bbPtr->damage.Impact * 5) : 1)); |
| | 2170 | |
| | 2171 | VECTORCH direction; |
| | 2172 | direction.vx = dynPtr->LinVelocity.vx + dynPtr->LinImpulse.vx; |
| | 2173 | direction.vy = dynPtr->LinVelocity.vy + dynPtr->LinImpulse.vy; |
| | 2174 | direction.vz = dynPtr->LinVelocity.vz + dynPtr->LinImpulse.vz; |
| | 2175 | Normalise(&direction); |
| | 2176 | MakeMatrixFromDirection(&direction, &dynPtr->OrientMat); |
| | 2177 | } |
| | 2178 | } |
| | 2179 | else |
| | 2180 | { |
| | 2181 | /* for net game support: send a message saying we've blown up... */ |
| | 2182 | |
| | 2183 | if(SinglePlayer != AvP.PlayMode) |
| | 2184 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 2185 | |
| | 2186 | sbPtr->please_destroy_me = 1; |
| | 2187 | } |
| | 2188 | } |
| | 2189 | |
| | 2190 | /* Function only does minimal disc setup , the rest will be done by the load function */ |
| | 2191 | |
| | 2192 | static STRATEGYBLOCK* InitialiseDiscBehaviour_ForLoad() |
| | 2193 | { |
| | 2194 | DISPLAYBLOCK *dispPtr = MakeObject(I_BehaviourPredatorDisc_SeekTrack, &zeroVect); |
| | 2195 | |
| | 2196 | if (NULL != dispPtr) |
| | 2197 | { |
| | 2198 | dispPtr->ObFlags3 |= ObFlag3_DynamicModuleObject; |
| | 2199 | |
| | 2200 | DYNAMICSBLOCK *dynPtr = AllocateDynamicsBlock(DYNAMICS_TEMPLATE_ROCKET); |
| | 2201 | dispPtr->ObStrategyBlock->dataptr = malloc(sizeof(PC_PRED_DISC_BEHAV_BLOCK)); |
| | 2202 | dispPtr->ObStrategyBlock->DynPtr = dynPtr; |
| | 2203 | |
| | 2204 | if ((NULL != dynPtr) && (NULL != dispPtr->ObStrategyBlock->dataptr)) |
| | 2205 | { |
| | 2206 | PC_PRED_DISC_BEHAV_BLOCK *bblk = dispPtr->ObStrategyBlock->dataptr; |
| | 2207 | |
| | 2208 | bblk->soundHandle = SOUND_NOACTIVEINDEX; |
| | 2209 | |
| | 2210 | dispPtr->HModelControlBlock = &bblk->HModelController; |
| | 2211 | |
| | 2212 | return dispPtr->ObStrategyBlock; |
| | 2213 | } |
| | 2214 | |
| | 2215 | RemoveBehaviourStrategy(dispPtr->ObStrategyBlock); |
| | 2216 | } |
| | 2217 | |
| | 2218 | return NULL; |
| | 2219 | } |
| | 2220 | |
| | 2221 | static void EulerAnglesHoming(VECTORCH *source, VECTORCH *Target, EULER *eulr, int rate) |
| | 2222 | { |
| | 2223 | int offsetx = Target->vx - source->vx; |
| | 2224 | int offsety = Target->vz - source->vz; |
| | 2225 | int angle1 = ArcTan(offsetx, offsety); |
| | 2226 | int angle2 = eulr->EulerY; |
| | 2227 | int offsetz; |
| | 2228 | |
| | 2229 | if (angle1 != angle2) |
| | 2230 | { |
| | 2231 | int testangle = angle2 - angle1; |
| | 2232 | |
| | 2233 | if (abs(testangle) < (NormalFrameTime >> rate)) |
| | 2234 | { |
| | 2235 | eulr->EulerY = angle1; |
| | 2236 | eulr->EulerY &= wrap360; |
| | 2237 | } |
| | 2238 | else if ( ((testangle > 0) && (testangle < deg180)) || (testangle < -deg180) ) |
| | 2239 | { |
| | 2240 | eulr->EulerY -= NormalFrameTime >> rate; |
| | 2241 | eulr->EulerY &= wrap360; |
| | 2242 | } |
| | 2243 | else |
| | 2244 | { |
| | 2245 | eulr->EulerY += NormalFrameTime >> rate; |
| | 2246 | eulr->EulerY &= wrap360; |
| | 2247 | } |
| | 2248 | } |
| | 2249 | |
| | 2250 | /* That was for the first plane. Now the second. */ |
| | 2251 | |
| | 2252 | offsetz = SqRoot32((offsetx*offsetx)+(offsety*offsety)); |
| | 2253 | offsety = -(Target->vy - source->vy); |
| | 2254 | |
| | 2255 | angle1 = ArcTan(offsety, offsetz); |
| | 2256 | angle2 = eulr->EulerX; |
| | 2257 | |
| | 2258 | if (angle1 != angle2) |
| | 2259 | { |
| | 2260 | int testangle = angle2 - angle1; |
| | 2261 | |
| | 2262 | if (abs(testangle) < (NormalFrameTime>>rate)) |
| | 2263 | { |
| | 2264 | eulr->EulerX = angle1; |
| | 2265 | eulr->EulerX &= wrap360; |
| | 2266 | } |
| | 2267 | else if ( ((testangle > 0) && (testangle < deg180)) || (testangle < -deg180) ) |
| | 2268 | { |
| | 2269 | eulr->EulerX -= NormalFrameTime >> rate; |
| | 2270 | eulr->EulerX &= wrap360; |
| | 2271 | } |
| | 2272 | else |
| | 2273 | { |
| | 2274 | eulr->EulerX += NormalFrameTime >> rate; |
| | 2275 | eulr->EulerX &= wrap360; |
| | 2276 | } |
| | 2277 | } |
| | 2278 | } |
| | 2279 | |
| | 2280 | static void Convert_Disc_To_Pickup(STRATEGYBLOCK *sbPtr) |
| | 2281 | { |
| | 2282 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr; |
| | 2283 | PC_PRED_DISC_BEHAV_BLOCK *bbPtr = (PC_PRED_DISC_BEHAV_BLOCK * ) sbPtr->dataptr; |
| | 2284 | SECTION_DATA *disc_section = GetThisSectionData(bbPtr->HModelController.section_data, "disk"); |
| | 2285 | /* Transmogrify a disc behaviour to a disc ammo pickup! */ |
| | 2286 | |
| | 2287 | assert(disc_section); |
| | 2288 | |
| | 2289 | dynPtr->LinVelocity.vx = dynPtr->LinVelocity.vy = dynPtr->LinVelocity.vz = 0; |
| | 2290 | dynPtr->LinImpulse.vx = dynPtr->LinImpulse.vy = dynPtr->LinImpulse.vz = 0; |
| | 2291 | |
| | 2292 | dynPtr->IsPickupObject = 1; |
| | 2293 | dynPtr->OrientMat = disc_section->SecMat; |
| | 2294 | dynPtr->Position = disc_section->World_Offset; |
| | 2295 | MatrixToEuler(&dynPtr->OrientMat, &dynPtr->OrientEuler); |
| | 2296 | |
| | 2297 | sbPtr->shapeIndex = disc_section->sempai->ShapeNum; |
| | 2298 | sbPtr->DamageBlock.Indestructable = 1; |
| | 2299 | |
| | 2300 | if (sbPtr->DisplayBlock) |
| | 2301 | { |
| | 2302 | sbPtr->DisplayBlock->ObShape = disc_section->sempai->ShapeNum; |
| | 2303 | sbPtr->DisplayBlock->ShapeData = disc_section->sempai->Shape; |
| | 2304 | sbPtr->DisplayBlock->HModelControlBlock = NULL; |
| | 2305 | } |
| | 2306 | |
| | 2307 | INANIMATEOBJECT_STATUSBLOCK* objectStatusPtr = malloc(sizeof(INANIMATEOBJECT_STATUSBLOCK)); |
| | 2308 | |
| | 2309 | objectStatusPtr->respawnTimer = 0; |
| | 2310 | |
| | 2311 | objectStatusPtr->typeId = IOT_Weapon; |
| | 2312 | objectStatusPtr->subType = (int)WEAPON_PRED_DISC; |
| | 2313 | objectStatusPtr->event_target = NULL; |
| | 2314 | objectStatusPtr->fragments = NULL; |
| | 2315 | objectStatusPtr->num_frags = 0; |
| | 2316 | objectStatusPtr->inan_tac = NULL; |
| | 2317 | objectStatusPtr->ghosted_object = 1; |
| | 2318 | objectStatusPtr->explosionTimer = 0; |
| | 2319 | objectStatusPtr->lifespanTimer = 0; |
| | 2320 | |
| | 2321 | Sound_Stop(bbPtr->soundHandle); |
| | 2322 | Dispel_HModel(&bbPtr->HModelController); |
| | 2323 | free(bbPtr); |
| | 2324 | sbPtr->dataptr = (void *)objectStatusPtr; |
| | 2325 | sbPtr->type = I_BehaviourInanimateObject; |
| | 2326 | } |
| | 2327 | |
| | 2328 | static void Disc_Hit_Environment(STRATEGYBLOCK *sbPtr, COLLISIONREPORT *reportPtr) |
| | 2329 | { |
| | 2330 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr; |
| | 2331 | PC_PRED_DISC_BEHAV_BLOCK *bbPtr = (PC_PRED_DISC_BEHAV_BLOCK * ) sbPtr->dataptr; |
| | 2332 | MATRIXCH mat; |
| | 2333 | |
| | 2334 | /* Hit the environment. Bounce? */ |
| | 2335 | int dp = Reflect(&dynPtr->LinVelocity, &reportPtr->ObstacleNormal, &dynPtr->OrientEuler); |
| | 2336 | |
| | 2337 | dynPtr->OrientEuler.EulerZ = 0; |
| | 2338 | dynPtr->IgnoreThePlayer = 0; |
| | 2339 | |
| | 2340 | if ((-1 == reportPtr->ModuleIndex) || ((dp > -46341) && (bbPtr->counter > 0) && (bbPtr->bounces <= DISC_MAX_BOUNCES))) |
| | 2341 | { /* 65536/Rt2 */ |
| | 2342 | /* Bounce. */ |
| | 2343 | MakeImpactSparks(&dynPtr->LinVelocity, &reportPtr->ObstacleNormal, &dynPtr->Position); |
| | 2344 | Sound_Play(SID_PREDATOR_DISK_HITTING_WALL, "dp", &dynPtr->Position, ((FastRandom()&511)-255)); |
| | 2345 | /* Record that the disc has bounced - for use in network game */ |
| | 2346 | bbPtr->Bounced = 1; |
| | 2347 | bbPtr->bounces++; |
| | 2348 | } |
| | 2349 | else |
| | 2350 | { |
| | 2351 | CreateEulerMatrix(&dynPtr->OrientEuler, &mat); |
| | 2352 | TransposeMatrixCH(&mat); |
| | 2353 | /* very steep angle (or very long flight!) - stick. */ |
| | 2354 | bbPtr->Stuck = 1; |
| | 2355 | bbPtr->HModelController.Playing = 0; |
| | 2356 | MakeSprayOfSparks(&mat, &dynPtr->Position); |
| | 2357 | Sound_Stop(bbPtr->soundHandle); |
| | 2358 | Sound_Play(SID_DISC_STICKSINWALL, "dp", &dynPtr->Position, ((FastRandom()&511)-255)); |
| | 2359 | } |
| | 2360 | |
| | 2361 | if (bbPtr->Target == NULL) |
| | 2362 | { |
| | 2363 | /* No target, so come home. */ |
| | 2364 | bbPtr->Target = PlayerStatus.sbptr; |
| | 2365 | COPY_NAME(bbPtr->Target_SBname, bbPtr->Target->SBname); |
| | 2366 | } |
| | 2367 | } |
| | 2368 | |
| | 2369 | void DiscBehaviour_SeekTrack(STRATEGYBLOCK *sbPtr) |
| | 2370 | { |
| | 2371 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr; |
| | 2372 | COLLISIONREPORT *reportPtr = dynPtr->CollisionReportPtr; |
| | 2373 | PC_PRED_DISC_BEHAV_BLOCK *bbPtr = (PC_PRED_DISC_BEHAV_BLOCK * ) sbPtr->dataptr; |
| | 2374 | |
| | 2375 | ProveHModel_Far(&bbPtr->HModelController, sbPtr); |
| | 2376 | |
| | 2377 | if (bbPtr->Target) |
| | 2378 | { |
| | 2379 | if (bbPtr->Target == PlayerStatus.sbptr) |
| | 2380 | { |
| | 2381 | VECTORCH targetPos; |
| | 2382 | GetTargetingPointOfObject_Far(bbPtr->Target, &targetPos); |
| | 2383 | EulerAnglesHoming(&dynPtr->Position, &targetPos, &dynPtr->OrientEuler, ((bbPtr->counter > 0) ? 4 : 2)); |
| | 2384 | } |
| | 2385 | else |
| | 2386 | { |
| | 2387 | if(NPC_IsDead(bbPtr->Target))// || !NAME_ISEQUAL(bbPtr->Target_SBname, bbPtr->Target->SBname)) |
| | 2388 | { |
| | 2389 | bbPtr->Target = PlayerStatus.sbptr; |
| | 2390 | bbPtr->counter = DISC_LIFETIME; |
| | 2391 | COPY_NAME(bbPtr->Target_SBname, bbPtr->Target->SBname); |
| | 2392 | } |
| | 2393 | else |
| | 2394 | { |
| | 2395 | /* Our target lives! */ |
| | 2396 | VECTORCH targetPos; |
| | 2397 | GetTargetingPointOfObject_Far(bbPtr->Target, &targetPos); |
| | 2398 | EulerAnglesHoming(&dynPtr->Position, &targetPos, &dynPtr->OrientEuler, 4); |
| | 2399 | } |
| | 2400 | } |
| | 2401 | } |
| | 2402 | |
| | 2403 | if(reportPtr) |
| | 2404 | { |
| | 2405 | dynPtr->IgnoreThePlayer = 0; |
| | 2406 | |
| | 2407 | if(reportPtr->ObstacleSBPtr) |
| | 2408 | { |
| | 2409 | switch (reportPtr->ObstacleSBPtr->type) |
| | 2410 | { |
| | 2411 | case I_BehaviourPredatorPlayer: |
| | 2412 | { |
| | 2413 | if(reportPtr->ObstacleSBPtr == PlayerStatus.sbptr) |
| | 2414 | { |
| | 2415 | /* Hit the owner. Catch it! */ |
| | 2416 | int a; |
| | 2417 | |
| | 2418 | for (a=0; a < MAX_NO_OF_WEAPON_SLOTS; a++) |
| | 2419 | { |
| | 2420 | if (PlayerStatus.WeaponSlot[a].WeaponIDNumber == WEAPON_PRED_DISC) |
| | 2421 | { |
| | 2422 | if (!PlayerStatus.WeaponSlot[a].PrimaryRoundsRemaining) |
| | 2423 | { |
| | 2424 | PlayerStatus.WeaponSlot[a].PrimaryRoundsRemaining = 1; |
| | 2425 | bbPtr->Target = NULL; |
| | 2426 | sbPtr->please_destroy_me = 1; |
| | 2427 | Sound_Stop(bbPtr->soundHandle); |
| | 2428 | Sound_Play(SID_PREDATOR_DISK_BEING_CAUGHT, "h"); |
| | 2429 | |
| | 2430 | if(SinglePlayer != AvP.PlayMode) |
| | 2431 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 2432 | |
| | 2433 | AutoSwapToDisc(); |
| | 2434 | return; |
| | 2435 | } |
| | 2436 | } |
| | 2437 | } |
| | 2438 | } |
| | 2439 | } |
| | 2440 | break; |
| | 2441 | case I_BehaviourInanimateObject: |
| | 2442 | CauseDamageToObject(reportPtr->ObstacleSBPtr, &TemplateAmmo[AMMO_PRED_DISC].MaxDamage, ONE_FIXED, NULL); |
| | 2443 | break; |
| | 2444 | case I_BehaviourNetGhost: |
| | 2445 | { |
| | 2446 | NETGHOSTDATABLOCK *dataptr = sbPtr->dataptr; |
| | 2447 | |
| | 2448 | if(I_BehaviourPredatorDisc_SeekTrack != dataptr->type) |
| | 2449 | { |
| | 2450 | CauseDamageToObject(reportPtr->ObstacleSBPtr, &TemplateAmmo[AMMO_PRED_DISC].MaxDamage, ONE_FIXED, NULL); |
| | 2451 | break; |
| | 2452 | } |
| | 2453 | } |
| | 2454 | case I_BehaviourProximityDoor: |
| | 2455 | case I_BehaviourTrackObject: |
| | 2456 | case I_BehaviourLiftDoor: |
| | 2457 | case I_BehaviourSwitchDoor: |
| | 2458 | case I_BehaviourLinkSwitch: |
| | 2459 | case I_BehaviourBinarySwitch: |
| | 2460 | case I_BehaviourLift: |
| | 2461 | case I_BehaviourPlatform: |
| | 2462 | case I_BehaviourPredatorDisc_SeekTrack: |
| | 2463 | { |
| | 2464 | Reflect(&dynPtr->LinVelocity, &reportPtr->ObstacleNormal, &dynPtr->OrientEuler); |
| | 2465 | dynPtr->OrientEuler.EulerZ = 0; |
| | 2466 | MakeImpactSparks(&dynPtr->LinVelocity, &reportPtr->ObstacleNormal, &dynPtr->Position); |
| | 2467 | Sound_Play(SID_PREDATOR_DISK_HITTING_WALL, "dp", &dynPtr->Position, ((FastRandom()&511)-255)); |
| | 2468 | bbPtr->bounces++; |
| | 2469 | bbPtr->Bounced = 1; // Record that the disc has bounced - for use in network game |
| | 2470 | } |
| | 2471 | break; |
| | 2472 | case I_BehaviourMarine: |
| | 2473 | case I_BehaviourAlien: |
| | 2474 | { |
| | 2475 | DISPLAYBLOCK *objectPtr = reportPtr->ObstacleSBPtr->DisplayBlock; |
| | 2476 | |
| | 2477 | if(objectPtr) |
| | 2478 | { |
| | 2479 | /* look for the object's torso in preference */ |
| | 2480 | SECTION_DATA *chest_section = GetThisSectionData(objectPtr->HModelControlBlock->section_data, "chest"); |
| | 2481 | |
| | 2482 | if (chest_section) |
| | 2483 | { |
| | 2484 | VECTORCH rel_pos = dynPtr->Position; |
| | 2485 | |
| | 2486 | rel_pos.vx -= chest_section->World_Offset.vx; |
| | 2487 | rel_pos.vy -= chest_section->World_Offset.vy; |
| | 2488 | rel_pos.vz -= chest_section->World_Offset.vz; |
| | 2489 | |
| | 2490 | Normalise(&rel_pos); |
| | 2491 | |
| | 2492 | CauseDamageToHModel(objectPtr->HModelControlBlock, reportPtr->ObstacleSBPtr, &TemplateAmmo[AMMO_PRED_DISC].MaxDamage, ONE_FIXED, chest_section,
&rel_pos, &chest_section->World_Offset, 0); |
| | 2493 | break; |
| | 2494 | } |
| | 2495 | } |
| | 2496 | } // no break for you |
| | 2497 | default: |
| | 2498 | CauseDamageToObject(reportPtr->ObstacleSBPtr, &TemplateAmmo[AMMO_PRED_DISC].MaxDamage, ONE_FIXED, NULL); |
| | 2499 | } |
| | 2500 | |
| | 2501 | Sound_Play(SID_PREDATOR_DISK_HITTING_TARGET, "dp", &dynPtr->Position, ((FastRandom()&511)-255)); |
| | 2502 | |
| | 2503 | if (NAME_ISEQUAL(reportPtr->ObstacleSBPtr->SBname, bbPtr->Target_SBname)) |
| | 2504 | { |
| | 2505 | /* Got him! Seek the player. */ |
| | 2506 | bbPtr->Target = PlayerStatus.sbptr; |
| | 2507 | bbPtr->counter = DISC_LIFETIME; |
| | 2508 | COPY_NAME(bbPtr->Target_SBname, bbPtr->Target->SBname); |
| | 2509 | } |
| | 2510 | } |
| | 2511 | else |
| | 2512 | { |
| | 2513 | Disc_Hit_Environment(sbPtr, reportPtr); |
| | 2514 | } |
| | 2515 | reportPtr = reportPtr->NextCollisionReportPtr; |
| | 2516 | } |
| | 2517 | |
| | 2518 | if (bbPtr->Stuck) |
| | 2519 | { |
| | 2520 | Convert_Disc_To_Pickup(sbPtr); |
| | 2521 | } |
| | 2522 | else |
| | 2523 | { |
| | 2524 | MATRIXCH mat; |
| | 2525 | |
| | 2526 | if(SOUND_NOACTIVEINDEX == bbPtr->soundHandle) |
| | 2527 | Sound_Play(SID_PREDATOR_DISK_FLYING, "del", &sbPtr->DynPtr->Position, &bbPtr->soundHandle); |
| | 2528 | else |
| | 2529 | Sound_Update3d(bbPtr->soundHandle, &sbPtr->DynPtr->Position); |
| | 2530 | |
| | 2531 | sbPtr->DamageBlock.IsOnFire = 0; |
| | 2532 | bbPtr->counter -= NormalFrameTime; |
| | 2533 | |
| | 2534 | if ((bbPtr->Target == NULL) && (bbPtr->counter <= 0)) |
| | 2535 | { |
| | 2536 | bbPtr->Target = PlayerStatus.sbptr; |
| | 2537 | bbPtr->counter = DISC_LIFETIME; |
| | 2538 | COPY_NAME(bbPtr->Target_SBname, bbPtr->Target->SBname); |
| | 2539 | } |
| | 2540 | |
| | 2541 | CreateEulerMatrix(&dynPtr->OrientEuler, &mat); |
| | 2542 | TransposeMatrixCH(&mat); |
| | 2543 | |
| | 2544 | dynPtr->OrientMat = mat; |
| | 2545 | |
| | 2546 | dynPtr->LinVelocity.vx = MUL_FIXED(mat.mat31, DISC_SPEED); |
| | 2547 | dynPtr->LinVelocity.vy = MUL_FIXED(mat.mat32, DISC_SPEED); |
| | 2548 | dynPtr->LinVelocity.vz = MUL_FIXED(mat.mat33, DISC_SPEED); |
| | 2549 | |
| | 2550 | dynPtr->LinImpulse.vx = dynPtr->LinImpulse.vy = dynPtr->LinImpulse.vz = 0; |
| | 2551 | NewTrailPoint(sbPtr->DynPtr); |
| | 2552 | } |
| | 2553 | } |
| | 2554 | |
| | 2555 | static int PredDisc_TargetFilter(STRATEGYBLOCK *candidate) |
| | 2556 | { |
| | 2557 | switch (candidate->type) |
| | 2558 | { |
| | 2559 | case I_BehaviourAlien: |
| | 2560 | case I_BehaviourMarine: |
| | 2561 | case I_BehaviourMarinePlayer: |
| | 2562 | case I_BehaviourAlienPlayer: |
| | 2563 | case I_BehaviourPredator: |
| | 2564 | case I_BehaviourPredatorPlayer: |
| | 2565 | case I_BehaviourXenoborg: |
| | 2566 | case I_BehaviourQueenAlien: |
| | 2567 | case I_BehaviourFaceHugger: |
| | 2568 | return 1; |
| | 2569 | case I_BehaviourNetGhost: |
| | 2570 | { |
| | 2571 | NETGHOSTDATABLOCK *dataptr = candidate->dataptr; |
| | 2572 | |
| | 2573 | switch (dataptr->type) |
| | 2574 | { |
| | 2575 | case I_BehaviourMarinePlayer: |
| | 2576 | case I_BehaviourAlienPlayer: |
| | 2577 | case I_BehaviourPredatorPlayer: |
| | 2578 | return 1; |
| | 2579 | default: |
| | 2580 | return 0; |
| | 2581 | } |
| | 2582 | } |
| | 2583 | default: |
| | 2584 | return 0; |
| | 2585 | } |
| | 2586 | } |
| | 2587 | |
| | 2588 | static int ObjectIsOnScreen(DISPLAYBLOCK *object) |
| | 2589 | { |
| | 2590 | extern struct KObject VisibleObjects[maxobjects]; |
| | 2591 | extern int numVisObjs; |
| | 2592 | int a = 0; |
| | 2593 | |
| | 2594 | for (; a < numVisObjs; a++) |
| | 2595 | { |
| | 2596 | if (VisibleObjects[a].DispPtr == object) |
| | 2597 | return 1; |
| | 2598 | } |
| | 2599 | |
| | 2600 | return 0; |
| | 2601 | } |
| | 2602 | |
| | 2603 | #define DISC_PROX_RANGE 90000 |
| | 2604 | |
| | 2605 | STRATEGYBLOCK *PredDisc_GetNewTarget(PC_PRED_DISC_BEHAV_BLOCK *bptr,VECTORCH *discpos, STRATEGYBLOCK *prevtarg, int mine) |
| | 2606 | { |
| | 2607 | int a = 0; |
| | 2608 | STRATEGYBLOCK *nearest = NULL; |
| | 2609 | |
| | 2610 | for (; a < NumActiveStBlocks; a++) |
| | 2611 | { |
| | 2612 | STRATEGYBLOCK *candidate = ActiveStBlockList[a]; |
| | 2613 | |
| | 2614 | if ((candidate != prevtarg) && (candidate != PlayerStatus.sbptr)) |
| | 2615 | { |
| | 2616 | if (candidate->DynPtr && PredDisc_TargetFilter(candidate)) |
| | 2617 | { |
| | 2618 | VECTORCH offset; |
| | 2619 | |
| | 2620 | offset.vx = discpos->vx-candidate->DynPtr->Position.vx; |
| | 2621 | offset.vy = discpos->vy-candidate->DynPtr->Position.vy; |
| | 2622 | offset.vz = discpos->vz-candidate->DynPtr->Position.vz; |
| | 2623 | |
| | 2624 | int dist = Approximate3dMagnitude(&offset); |
| | 2625 | |
| | 2626 | if (! ((mine == 1) && dist > DISC_PROX_RANGE)) |
| | 2627 | { |
| | 2628 | if (dist < ONE_FIXED) |
| | 2629 | { |
| | 2630 | /* Check visibility? */ |
| | 2631 | if (candidate->DisplayBlock && !NPC_IsDead(candidate)) |
| | 2632 | { |
| | 2633 | /* Not the last one again! */ |
| | 2634 | if (!NAME_ISEQUAL(bptr->Prev_Target_SBname, candidate->SBname)) |
| | 2635 | { |
| | 2636 | if (mine == 1) |
| | 2637 | { |
| | 2638 | if (IsThisObjectVisibleFromThisPosition(candidate->DisplayBlock, discpos)) |
| | 2639 | nearest = candidate; |
| | 2640 | } |
| | 2641 | else if (mine == 2) |
| | 2642 | { |
| | 2643 | if (ObjectIsOnScreen(candidate->DisplayBlock)) |
| | 2644 | nearest = candidate; |
| | 2645 | } |
| | 2646 | else if (candidate->containingModule) |
| | 2647 | { |
| | 2648 | MODULE *dmod = ModuleFromPosition(discpos, PlayerStatus.sbptr->containingModule); |
| | 2649 | |
| | 2650 | if (IsModuleVisibleFromModule(dmod, candidate->containingModule)) |
| | 2651 | nearest = candidate; |
| | 2652 | } |
| | 2653 | } |
| | 2654 | } |
| | 2655 | } |
| | 2656 | } |
| | 2657 | } |
| | 2658 | } |
| | 2659 | } |
| | 2660 | |
| | 2661 | return nearest; |
| | 2662 | } |
| | 2663 | |
| | 2664 | DISPLAYBLOCK *SpawnMolotovCocktail(SECTION_DATA *root, MATRIXCH *master_orient) |
| | 2665 | { |
| | 2666 | /* Doesn't really matter what shape gets generated... */ |
| | 2667 | STRATEGYBLOCK* sbPtr = CreateActiveStrategyBlock(I_BehaviourMolotov); |
| | 2668 | |
| | 2669 | if(NULL == sbPtr) |
| | 2670 | return NULL; |
| | 2671 | |
| | 2672 | DISPLAYBLOCK *dispPtr = sbPtr->DisplayBlock = CreateActiveObject(); |
| | 2673 | sbPtr->dataptr = malloc(sizeof(MOLOTOV_BEHAV_BLOCK)); |
| | 2674 | DYNAMICSBLOCK *dynPtr = sbPtr->DynPtr = AllocateDynamicsBlock(DYNAMICS_TEMPLATE_GRENADE); |
| | 2675 | |
| | 2676 | if ((NULL == sbPtr->dataptr) || (NULL == dynPtr) || (NULL == dispPtr)) |
| | 2677 | { |
| | 2678 | RemoveBehaviourStrategy(sbPtr); |
| | 2679 | return NULL; |
| | 2680 | } |
| | 2681 | |
| | 2682 | if(root) //allow case root==NULL for loading |
| | 2683 | dispPtr->ObWorld = root->World_Offset; |
| | 2684 | |
| | 2685 | // 2. NOW set up the strategyblock-specific fields for |
| | 2686 | // the new displayblock. We won't go through the "AttachNew |
| | 2687 | // StrategyBlock" and "AssignRunTimeBehaviours" pair, since |
| | 2688 | // the first switches on ObShape and the second on bhvr; |
| | 2689 | // but, in this case, there isn't a particular connection |
| | 2690 | // between them. |
| | 2691 | |
| | 2692 | dispPtr->ObStrategyBlock = sbPtr; |
| | 2693 | |
| | 2694 | ((MOLOTOV_BEHAV_BLOCK * ) sbPtr->dataptr)->counter = 65536;//32767;//FastRandom()&32767; |
| | 2695 | |
| | 2696 | if(root) //allow case root == NULL for loading |
| | 2697 | { |
| | 2698 | int woundflags = Splice_HModels(&(((MOLOTOV_BEHAV_BLOCK * ) sbPtr->dataptr)->HModelController), root); |
| | 2699 | InitHModelSequence( &(((MOLOTOV_BEHAV_BLOCK * ) sbPtr->dataptr)->HModelController), 0, 1, ONE_FIXED); |
| | 2700 | } |
| | 2701 | |
| | 2702 | dispPtr->HModelControlBlock = &(((MOLOTOV_BEHAV_BLOCK * ) sbPtr->dataptr)->HModelController); |
| | 2703 | |
| | 2704 | if(root) //allow case root == NULL for loading |
| | 2705 | { |
| | 2706 | dispPtr->ObWorld = root->World_Offset; |
| | 2707 | dispPtr->ObMat = root->SecMat; |
| | 2708 | } |
| | 2709 | |
| | 2710 | assert(dispPtr->ObWorld.vx < 1000000 && dispPtr->ObWorld.vx > -1000000); |
| | 2711 | assert(dispPtr->ObWorld.vy < 1000000 && dispPtr->ObWorld.vy > -1000000); |
| | 2712 | assert(dispPtr->ObWorld.vz < 1000000 && dispPtr->ObWorld.vz > -1000000); |
| | 2713 | |
| | 2714 | ProveHModel(dispPtr->HModelControlBlock, dispPtr); |
| | 2715 | |
| | 2716 | if(root) //allow case root == NULL for loading |
| | 2717 | { |
| | 2718 | dynPtr->Position = root->World_Offset; |
| | 2719 | dynPtr->OrientMat = root->SecMat; |
| | 2720 | } |
| | 2721 | |
| | 2722 | // Give explosion fragments an angular velocity |
| | 2723 | dynPtr->AngVelocity.EulerX = (FastRandom()&2047)-1024; |
| | 2724 | dynPtr->AngVelocity.EulerY = (FastRandom()&2047)-1024; |
| | 2725 | dynPtr->AngVelocity.EulerZ = (FastRandom()&2047)-1024; |
| | 2726 | |
| | 2727 | dynPtr->IgnoreThePlayer = 0; |
| | 2728 | |
| | 2729 | /* Handle velocity... */ |
| | 2730 | VECTORCH start = {0, -2000, 12000}; |
| | 2731 | MATRIXCH tm = *master_orient; |
| | 2732 | |
| | 2733 | RotateAndCopyVector(&start, &dynPtr->LinImpulse, &tm); |
| | 2734 | |
| | 2735 | return dispPtr; |
| | 2736 | } |
| | 2737 | |
| | 2738 | void MolotovBehaviour(STRATEGYBLOCK *sbPtr) |
| | 2739 | { |
| | 2740 | COLLISIONREPORT *reportPtr = sbPtr->DynPtr->CollisionReportPtr; |
| | 2741 | MOLOTOV_BEHAV_BLOCK *bbPtr = (MOLOTOV_BEHAV_BLOCK * )sbPtr->dataptr; |
| | 2742 | |
| | 2743 | if(reportPtr && reportPtr->ObstacleSBPtr) |
| | 2744 | { |
| | 2745 | reportPtr->ObstacleSBPtr->DamageBlock.IsOnFire = ONE_FIXED * 60; |
| | 2746 | reportPtr->ObstacleSBPtr->DamageBlock.Combustability = 2; |
| | 2747 | } |
| | 2748 | |
| | 2749 | if ((bbPtr->counter <= 0) || reportPtr) |
| | 2750 | { |
| | 2751 | DestroyActiveObject(&sbPtr->DisplayBlock); |
| | 2752 | MakeMolotovExplosionAt(&sbPtr->DynPtr->Position); |
| | 2753 | |
| | 2754 | if (sbPtr->containingModule) |
| | 2755 | { |
| | 2756 | Explosion_SoundData.position = sbPtr->DynPtr->Position; |
| | 2757 | Sound_Play(SID_MOLOTOV_EXPLOSION, "n", &Explosion_SoundData); |
| | 2758 | } |
| | 2759 | |
| | 2760 | if(SinglePlayer != AvP.PlayMode) |
| | 2761 | AddNetMsg_LocalObjectDestroyed(sbPtr); |
| | 2762 | |
| | 2763 | sbPtr->please_destroy_me = 1; |
| | 2764 | } |
| | 2765 | else |
| | 2766 | { |
| | 2767 | bbPtr->counter -= NormalFrameTime; |
| | 2768 | DynamicallyRotateObject(sbPtr->DynPtr); |
| | 2769 | } |
| | 2770 | } |
| | 2771 | |
| | 2772 | /*-------------------** |
| | 2773 | ** Load/Save Grenade ** |
| | 2774 | **-------------------*/ |
| | 2775 | typedef struct grenade_save_block |
| | 2776 | { |
| | 2777 | SAVE_BLOCK_STRATEGY_HEADER header; |
| | 2778 | |
| | 2779 | int counter; |
| | 2780 | int bouncelastframe; |
| | 2781 | |
| | 2782 | DYNAMICSBLOCK dynamics; |
| | 2783 | |
| | 2784 | } GRENADE_SAVE_BLOCK; |
| | 2785 | |
| | 2786 | //defines for load/save macros |
| | 2787 | #define SAVELOAD_BLOCK block |
| | 2788 | #define SAVELOAD_BEHAV behav |
| | 2789 | |
| | 2790 | void LoadStrategy_Grenade(SAVE_BLOCK_STRATEGY_HEADER* header) |
| | 2791 | { |
| | 2792 | GRENADE_SAVE_BLOCK* block = (GRENADE_SAVE_BLOCK*) header; |
| | 2793 | |
| | 2794 | //check the size of the save block |
| | 2795 | if(header->size != sizeof(*block)) |
| | 2796 | return; |
| | 2797 | |
| | 2798 | STRATEGYBLOCK* sbPtr = CreateGrenadeKernel(I_BehaviourGrenade, &block->dynamics.Position, &block->dynamics.OrientMat, 0); |
| | 2799 | |
| | 2800 | if(NULL != sbPtr) |
| | 2801 | { |
| | 2802 | GRENADE_BEHAV_BLOCK* behav = (GRENADE_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 2803 | |
| | 2804 | COPYELEMENT_LOAD(counter); |
| | 2805 | COPYELEMENT_LOAD(bouncelastframe); |
| | 2806 | |
| | 2807 | *sbPtr->DynPtr = block->dynamics; |
| | 2808 | } |
| | 2809 | } |
| | 2810 | |
| | 2811 | void SaveStrategy_Grenade(STRATEGYBLOCK* sbPtr) |
| | 2812 | { |
| | 2813 | GRENADE_SAVE_BLOCK* block; |
| | 2814 | |
| | 2815 | GRENADE_BEHAV_BLOCK* behav = (GRENADE_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 2816 | GET_STRATEGY_SAVE_BLOCK(block,sbPtr); |
| | 2817 | |
| | 2818 | COPYELEMENT_SAVE(counter); |
| | 2819 | COPYELEMENT_SAVE(bouncelastframe); |
| | 2820 | |
| | 2821 | block->dynamics = *sbPtr->DynPtr; |
| | 2822 | block->dynamics.CollisionReportPtr = NULL; |
| | 2823 | } |
| | 2824 | |
| | 2825 | /*-------------------** |
| | 2826 | ** Load/Save Flare Grenade ** |
| | 2827 | **-------------------*/ |
| | 2828 | typedef struct flare_grenade_save_block |
| | 2829 | { |
| | 2830 | SAVE_BLOCK_STRATEGY_HEADER header; |
| | 2831 | |
| | 2832 | int LifeTimeRemaining; |
| | 2833 | int ParticleGenerationTimer; |
| | 2834 | |
| | 2835 | DYNAMICSBLOCK dynamics; |
| | 2836 | |
| | 2837 | } FLARE_GRENADE_SAVE_BLOCK; |
| | 2838 | |
| | 2839 | void LoadStrategy_Flare(SAVE_BLOCK_STRATEGY_HEADER* header) |
| | 2840 | { |
| | 2841 | FLARE_GRENADE_SAVE_BLOCK* block = (FLARE_GRENADE_SAVE_BLOCK*) header; |
| | 2842 | |
| | 2843 | //check the size of the save block |
| | 2844 | if(header->size != sizeof(*block)) |
| | 2845 | return; |
| | 2846 | |
| | 2847 | STRATEGYBLOCK* sbPtr = CreateFlare(&block->dynamics.Position, &block->dynamics.OrientMat); |
| | 2848 | |
| | 2849 | if(NULL != sbPtr) |
| | 2850 | { |
| | 2851 | FLARE_BEHAV_BLOCK* behav = (FLARE_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 2852 | |
| | 2853 | COPYELEMENT_LOAD(LifeTimeRemaining) |
| | 2854 | COPYELEMENT_LOAD(ParticleGenerationTimer) |
| | 2855 | |
| | 2856 | *sbPtr->DynPtr = block->dynamics; |
| | 2857 | |
| | 2858 | Load_SoundState(&behav->SoundHandle); |
| | 2859 | } |
| | 2860 | } |
| | 2861 | |
| | 2862 | void SaveStrategy_Flare(STRATEGYBLOCK* sbPtr) |
| | 2863 | { |
| | 2864 | FLARE_GRENADE_SAVE_BLOCK* block; |
| | 2865 | FLARE_BEHAV_BLOCK* behav = (FLARE_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 2866 | |
| | 2867 | GET_STRATEGY_SAVE_BLOCK(block,sbPtr); |
| | 2868 | |
| | 2869 | COPYELEMENT_SAVE(LifeTimeRemaining) |
| | 2870 | COPYELEMENT_SAVE(ParticleGenerationTimer) |
| | 2871 | |
| | 2872 | block->dynamics = *sbPtr->DynPtr; |
| | 2873 | block->dynamics.CollisionReportPtr=0; |
| | 2874 | |
| | 2875 | Save_SoundState(&behav->SoundHandle); |
| | 2876 | } |
| | 2877 | |
| | 2878 | /*-------------------** |
| | 2879 | ** Load/Save Prox Grenade ** |
| | 2880 | **-------------------*/ |
| | 2881 | typedef struct prox_grenade_save_block |
| | 2882 | { |
| | 2883 | SAVE_BLOCK_STRATEGY_HEADER header; |
| | 2884 | |
| | 2885 | int counter; |
| | 2886 | int SoundGenerationTimer; |
| | 2887 | |
| | 2888 | DYNAMICSBLOCK dynamics; |
| | 2889 | |
| | 2890 | } PROX_GRENADE_SAVE_BLOCK; |
| | 2891 | |
| | 2892 | void LoadStrategy_ProxGrenade(SAVE_BLOCK_STRATEGY_HEADER* header) |
| | 2893 | { |
| | 2894 | PROX_GRENADE_SAVE_BLOCK* block = (PROX_GRENADE_SAVE_BLOCK*) header; |
| | 2895 | |
| | 2896 | //check the size of the save block |
| | 2897 | if(header->size != sizeof(*block)) |
| | 2898 | return; |
| | 2899 | |
| | 2900 | STRATEGYBLOCK* sbPtr = CreateGrenadeKernel(I_BehaviourProximityGrenade, &block->dynamics.Position, &block->dynamics.OrientMat, 0); |
| | 2901 | |
| | 2902 | if(NULL != sbPtr) |
| | 2903 | { |
| | 2904 | PROX_GRENADE_BEHAV_BLOCK* behav = (PROX_GRENADE_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 2905 | |
| | 2906 | //copy stuff over |
| | 2907 | COPYELEMENT_LOAD(counter) |
| | 2908 | COPYELEMENT_LOAD(SoundGenerationTimer) |
| | 2909 | |
| | 2910 | *sbPtr->DynPtr = block->dynamics; |
| | 2911 | |
| | 2912 | Load_SoundState(&behav->SoundHandle); |
| | 2913 | } |
| | 2914 | } |
| | 2915 | |
| | 2916 | void SaveStrategy_ProxGrenade(STRATEGYBLOCK* sbPtr) |
| | 2917 | { |
| | 2918 | PROX_GRENADE_SAVE_BLOCK* block; |
| | 2919 | PROX_GRENADE_BEHAV_BLOCK* behav = (PROX_GRENADE_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 2920 | |
| | 2921 | GET_STRATEGY_SAVE_BLOCK(block, sbPtr); |
| | 2922 | |
| | 2923 | COPYELEMENT_SAVE(counter) |
| | 2924 | COPYELEMENT_SAVE(SoundGenerationTimer) |
| | 2925 | |
| | 2926 | block->dynamics = *sbPtr->DynPtr; |
| | 2927 | block->dynamics.CollisionReportPtr = NULL; |
| | 2928 | |
| | 2929 | Save_SoundState(&behav->SoundHandle); |
| | 2930 | } |
| | 2931 | |
| | 2932 | /*-------------------** |
| | 2933 | ** Load/Save rocket ** |
| | 2934 | **-------------------*/ |
| | 2935 | typedef struct rocket_save_block |
| | 2936 | { |
| | 2937 | SAVE_BLOCK_STRATEGY_HEADER header; |
| | 2938 | |
| | 2939 | int counter; |
| | 2940 | int player; |
| | 2941 | |
| | 2942 | DYNAMICSBLOCK dynamics; |
| | 2943 | |
| | 2944 | } ROCKET_SAVE_BLOCK; |
| | 2945 | |
| | 2946 | void LoadStrategy_Rocket(SAVE_BLOCK_STRATEGY_HEADER* header) |
| | 2947 | { |
| | 2948 | ROCKET_SAVE_BLOCK* block = (ROCKET_SAVE_BLOCK*) header; |
| | 2949 | |
| | 2950 | //check the size of the save block |
| | 2951 | if(header->size != sizeof(*block)) |
| | 2952 | return; |
| | 2953 | |
| | 2954 | //create default grende |
| | 2955 | STRATEGYBLOCK* sbPtr = CreateRocketKernel(&block->dynamics.Position,&block->dynamics.OrientMat,0); |
| | 2956 | |
| | 2957 | if(NULL != sbPtr) |
| | 2958 | { |
| | 2959 | PREDPISTOL_BEHAV_BLOCK* behav = (PREDPISTOL_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 2960 | |
| | 2961 | //copy stuff over |
| | 2962 | COPYELEMENT_LOAD(counter) |
| | 2963 | COPYELEMENT_LOAD(player) |
| | 2964 | |
| | 2965 | *sbPtr->DynPtr = block->dynamics; |
| | 2966 | } |
| | 2967 | } |
| | 2968 | |
| | 2969 | void SaveStrategy_Rocket(STRATEGYBLOCK* sbPtr) |
| | 2970 | { |
| | 2971 | ROCKET_SAVE_BLOCK* block; |
| | 2972 | PREDPISTOL_BEHAV_BLOCK* behav = (PREDPISTOL_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 2973 | |
| | 2974 | GET_STRATEGY_SAVE_BLOCK(block,sbPtr); |
| | 2975 | |
| | 2976 | COPYELEMENT_SAVE(counter) |
| | 2977 | COPYELEMENT_SAVE(player) |
| | 2978 | |
| | 2979 | block->dynamics = *sbPtr->DynPtr; |
| | 2980 | block->dynamics.CollisionReportPtr = NULL; |
| | 2981 | } |
| | 2982 | |
| | 2983 | /*-------------------** |
| | 2984 | ** Load/Save PP plasma bolt ** |
| | 2985 | **-------------------*/ |
| | 2986 | typedef struct ppplasma_save_block |
| | 2987 | { |
| | 2988 | SAVE_BLOCK_STRATEGY_HEADER header; |
| | 2989 | |
| | 2990 | int counter; |
| | 2991 | int player; |
| | 2992 | |
| | 2993 | DYNAMICSBLOCK dynamics; |
| | 2994 | |
| | 2995 | } PPPLASMA_SAVE_BLOCK; |
| | 2996 | |
| | 2997 | void LoadStrategy_PPPlasmaBolt(SAVE_BLOCK_STRATEGY_HEADER* header) |
| | 2998 | { |
| | 2999 | PPPLASMA_SAVE_BLOCK* block = (PPPLASMA_SAVE_BLOCK*) header; |
| | 3000 | |
| | 3001 | //check the size of the save block |
| | 3002 | if(header->size != sizeof(*block)) |
| | 3003 | return; |
| | 3004 | |
| | 3005 | //create default bolt |
| | 3006 | STRATEGYBLOCK* sbPtr = Pred_Pistol_Bolt(&block->dynamics.Position,&block->dynamics.OrientMat,0); |
| | 3007 | |
| | 3008 | if(NULL != sbPtr) |
| | 3009 | { |
| | 3010 | PREDPISTOL_BEHAV_BLOCK* behav = (PREDPISTOL_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 3011 | |
| | 3012 | //copy stuff over |
| | 3013 | COPYELEMENT_LOAD(counter) |
| | 3014 | COPYELEMENT_LOAD(player) |
| | 3015 | |
| | 3016 | *sbPtr->DynPtr = block->dynamics; |
| | 3017 | } |
| | 3018 | } |
| | 3019 | |
| | 3020 | void SaveStrategy_PPPlasmaBolt(STRATEGYBLOCK* sbPtr) |
| | 3021 | { |
| | 3022 | PPPLASMA_SAVE_BLOCK* block; |
| | 3023 | PREDPISTOL_BEHAV_BLOCK* behav = (PREDPISTOL_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 3024 | |
| | 3025 | GET_STRATEGY_SAVE_BLOCK(block,sbPtr); |
| | 3026 | |
| | 3027 | COPYELEMENT_SAVE(counter) |
| | 3028 | COPYELEMENT_SAVE(player) |
| | 3029 | |
| | 3030 | block->dynamics = *sbPtr->DynPtr; |
| | 3031 | block->dynamics.CollisionReportPtr = NULL; |
| | 3032 | } |
| | 3033 | |
| | 3034 | /*-------------------** |
| | 3035 | ** Load/Save energy bolt ** |
| | 3036 | **-------------------*/ |
| | 3037 | typedef struct pred_energy_bolt_save_block |
| | 3038 | { |
| | 3039 | SAVE_BLOCK_STRATEGY_HEADER header; |
| | 3040 | |
| | 3041 | int counter; |
| | 3042 | int player; |
| | 3043 | DAMAGE_PROFILE damage; |
| | 3044 | int blast_radius; |
| | 3045 | |
| | 3046 | DYNAMICSBLOCK dynamics; |
| | 3047 | |
| | 3048 | } PREDATOR_ENERGY_BOLT_SAVE_BLOCK; |
| | 3049 | |
| | 3050 | void LoadStrategy_PredatorEnergyBolt(SAVE_BLOCK_STRATEGY_HEADER* header) |
| | 3051 | { |
| | 3052 | PREDATOR_ENERGY_BOLT_SAVE_BLOCK* block = (PREDATOR_ENERGY_BOLT_SAVE_BLOCK*) header; |
| | 3053 | |
| | 3054 | //check the size of the save block |
| | 3055 | if(header->size != sizeof(*block)) |
| | 3056 | return; |
| | 3057 | |
| | 3058 | //create default bolt |
| | 3059 | STRATEGYBLOCK* sbPtr =
InitialiseEnergyBoltBehaviourKernel(&block->dynamics.Position,&block->dynamics.OrientMat,0,&block->damage,ONE_FIXED); |
| | 3060 | |
| | 3061 | if(NULL != sbPtr) |
| | 3062 | { |
| | 3063 | CASTER_BOLT_BEHAV_BLOCK* behav = (CASTER_BOLT_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 3064 | |
| | 3065 | //copy stuff over |
| | 3066 | COPYELEMENT_LOAD(counter) |
| | 3067 | COPYELEMENT_LOAD(player) |
| | 3068 | COPYELEMENT_LOAD(damage) |
| | 3069 | COPYELEMENT_LOAD(blast_radius) |
| | 3070 | |
| | 3071 | *sbPtr->DynPtr = block->dynamics; |
| | 3072 | } |
| | 3073 | } |
| | 3074 | |
| | 3075 | void SaveStrategy_PredatorEnergyBolt(STRATEGYBLOCK* sbPtr) |
| | 3076 | { |
| | 3077 | PREDATOR_ENERGY_BOLT_SAVE_BLOCK* block; |
| | 3078 | |
| | 3079 | CASTER_BOLT_BEHAV_BLOCK* behav = (CASTER_BOLT_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 3080 | GET_STRATEGY_SAVE_BLOCK(block,sbPtr); |
| | 3081 | |
| | 3082 | COPYELEMENT_SAVE(counter) |
| | 3083 | COPYELEMENT_SAVE(player) |
| | 3084 | COPYELEMENT_SAVE(damage) |
| | 3085 | COPYELEMENT_SAVE(blast_radius) |
| | 3086 | |
| | 3087 | block->dynamics = *sbPtr->DynPtr; |
| | 3088 | block->dynamics.CollisionReportPtr = NULL; |
| | 3089 | } |
| | 3090 | |
| | 3091 | /*-------------------** |
| | 3092 | ** Load/Save pulse grenade ** |
| | 3093 | **-------------------*/ |
| | 3094 | typedef struct pulse_grenade_save_block |
| | 3095 | { |
| | 3096 | SAVE_BLOCK_STRATEGY_HEADER header; |
| | 3097 | |
| | 3098 | int counter; |
| | 3099 | int player; |
| | 3100 | |
| | 3101 | DYNAMICSBLOCK dynamics; |
| | 3102 | |
| | 3103 | } PULSE_GRENADE_SAVE_BLOCK; |
| | 3104 | |
| | 3105 | void LoadStrategy_PulseGrenade(SAVE_BLOCK_STRATEGY_HEADER* header) |
| | 3106 | { |
| | 3107 | PULSE_GRENADE_SAVE_BLOCK* block = (PULSE_GRENADE_SAVE_BLOCK*) header; |
| | 3108 | |
| | 3109 | //check the size of the save block |
| | 3110 | if(header->size != sizeof(*block)) |
| | 3111 | return; |
| | 3112 | |
| | 3113 | VECTORCH position; // gets copied over |
| | 3114 | MATRIXCH orient; |
| | 3115 | |
| | 3116 | STRATEGYBLOCK* sbPtr = InitialisePulseGrenadeBehaviour(&position, &orient); |
| | 3117 | |
| | 3118 | if(NULL != sbPtr) |
| | 3119 | { |
| | 3120 | PREDPISTOL_BEHAV_BLOCK* behav = (PREDPISTOL_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 3121 | |
| | 3122 | //copy stuff over |
| | 3123 | COPYELEMENT_LOAD(counter) |
| | 3124 | COPYELEMENT_LOAD(player) |
| | 3125 | |
| | 3126 | *sbPtr->DynPtr = block->dynamics; |
| | 3127 | } |
| | 3128 | } |
| | 3129 | |
| | 3130 | void SaveStrategy_PulseGrenade(STRATEGYBLOCK* sbPtr) |
| | 3131 | { |
| | 3132 | PULSE_GRENADE_SAVE_BLOCK* block; |
| | 3133 | PREDPISTOL_BEHAV_BLOCK* behav = (PREDPISTOL_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 3134 | |
| | 3135 | GET_STRATEGY_SAVE_BLOCK(block, sbPtr); |
| | 3136 | |
| | 3137 | COPYELEMENT_SAVE(counter) |
| | 3138 | COPYELEMENT_SAVE(player) |
| | 3139 | |
| | 3140 | block->dynamics = *sbPtr->DynPtr; |
| | 3141 | block->dynamics.CollisionReportPtr = NULL; |
| | 3142 | } |
| | 3143 | |
| | 3144 | /*-------------------** |
| | 3145 | ** Load/Save molotov ** |
| | 3146 | **-------------------*/ |
| | 3147 | typedef struct molotov_save_block |
| | 3148 | { |
| | 3149 | SAVE_BLOCK_STRATEGY_HEADER header; |
| | 3150 | |
| | 3151 | int counter; |
| | 3152 | |
| | 3153 | DYNAMICSBLOCK dynamics; |
| | 3154 | |
| | 3155 | } MOLOTOV_SAVE_BLOCK; |
| | 3156 | |
| | 3157 | void LoadStrategy_Molotov(SAVE_BLOCK_STRATEGY_HEADER* header) |
| | 3158 | { |
| | 3159 | PULSE_GRENADE_SAVE_BLOCK* block = (PULSE_GRENADE_SAVE_BLOCK*) header; |
| | 3160 | |
| | 3161 | //check the size of the save block |
| | 3162 | if(header->size != sizeof(*block)) |
| | 3163 | return; |
| | 3164 | |
| | 3165 | //create default molotov |
| | 3166 | DISPLAYBLOCK* dPtr = SpawnMolotovCocktail(0, &block->dynamics.OrientMat); |
| | 3167 | |
| | 3168 | if(NULL != dPtr) |
| | 3169 | { |
| | 3170 | STRATEGYBLOCK* sbPtr = dPtr->ObStrategyBlock; |
| | 3171 | |
| | 3172 | MOLOTOV_BEHAV_BLOCK* behav = (MOLOTOV_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 3173 | |
| | 3174 | //copy stuff over |
| | 3175 | COPYELEMENT_LOAD(counter) |
| | 3176 | |
| | 3177 | *sbPtr->DynPtr = block->dynamics; |
| | 3178 | |
| | 3179 | //load the molotov hierarchy |
| | 3180 | { |
| | 3181 | SAVE_BLOCK_HEADER* hier_header = GetNextBlockIfOfType(SaveBlock_Hierarchy); |
| | 3182 | |
| | 3183 | if(hier_header) |
| | 3184 | LoadHierarchy(hier_header,&behav->HModelController); |
| | 3185 | } |
| | 3186 | } |
| | 3187 | } |
| | 3188 | |
| | 3189 | void SaveStrategy_Molotov(STRATEGYBLOCK* sbPtr) |
| | 3190 | { |
| | 3191 | PULSE_GRENADE_SAVE_BLOCK* block; |
| | 3192 | MOLOTOV_BEHAV_BLOCK* behav = (MOLOTOV_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 3193 | |
| | 3194 | GET_STRATEGY_SAVE_BLOCK(block,sbPtr); |
| | 3195 | |
| | 3196 | COPYELEMENT_SAVE(counter) |
| | 3197 | |
| | 3198 | block->dynamics = *sbPtr->DynPtr; |
| | 3199 | block->dynamics.CollisionReportPtr = NULL; |
| | 3200 | |
| | 3201 | //save the molotov hierarchy |
| | 3202 | SaveHierarchy(&behav->HModelController); |
| | 3203 | } |
| | 3204 | |
| | 3205 | /*-------------------------** |
| | 3206 | ** Load/Save Predator Disc ** |
| | 3207 | **-------------------------*/ |
| | 3208 | |
| | 3209 | typedef struct predator_disc_save_block |
| | 3210 | { |
| | 3211 | SAVE_BLOCK_STRATEGY_HEADER header; |
| | 3212 | |
| | 3213 | //behaviour block stuff |
| | 3214 | int counter; |
| | 3215 | int Destruct:1; |
| | 3216 | int Stuck :1; |
| | 3217 | int Bounced :1; |
| | 3218 | int bounces; |
| | 3219 | |
| | 3220 | char Prev_Target_SBname[SB_NAME_LENGTH]; |
| | 3221 | //pointer things |
| | 3222 | char Target_SBname[SB_NAME_LENGTH]; |
| | 3223 | |
| | 3224 | //strategy block stuff |
| | 3225 | DAMAGEBLOCK DamageBlock; |
| | 3226 | DYNAMICSBLOCK dynamics; |
| | 3227 | |
| | 3228 | } PREDATOR_DISC_SAVE_BLOCK; |
| | 3229 | |
| | 3230 | void LoadStrategy_PredatorDisc(SAVE_BLOCK_STRATEGY_HEADER* header) |
| | 3231 | { |
| | 3232 | PREDATOR_DISC_SAVE_BLOCK* block = (PREDATOR_DISC_SAVE_BLOCK*) header; |
| | 3233 | |
| | 3234 | //check the size of the save block |
| | 3235 | if(header->size != sizeof(*block)) |
| | 3236 | return; |
| | 3237 | |
| | 3238 | //create default disc |
| | 3239 | STRATEGYBLOCK* sbPtr = InitialiseDiscBehaviour_ForLoad(); |
| | 3240 | |
| | 3241 | if(NULL != sbPtr) |
| | 3242 | { |
| | 3243 | PC_PRED_DISC_BEHAV_BLOCK* behav = (PC_PRED_DISC_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 3244 | |
| | 3245 | COPYELEMENT_LOAD(counter) |
| | 3246 | COPYELEMENT_LOAD(Destruct) |
| | 3247 | COPYELEMENT_LOAD(Stuck) |
| | 3248 | COPYELEMENT_LOAD(Bounced) |
| | 3249 | COPYELEMENT_LOAD(bounces) |
| | 3250 | |
| | 3251 | COPY_NAME(behav->Target_SBname,block->Target_SBname); |
| | 3252 | COPY_NAME(behav->Prev_Target_SBname,block->Prev_Target_SBname); |
| | 3253 | behav->Target = FindSBWithName(behav->Target_SBname); |
| | 3254 | |
| | 3255 | //strategy block stuff |
| | 3256 | *sbPtr->DynPtr = block->dynamics; |
| | 3257 | sbPtr->DamageBlock = block->DamageBlock; |
| | 3258 | |
| | 3259 | //load the hierarchy |
| | 3260 | { |
| | 3261 | SAVE_BLOCK_HEADER* hier_header = GetNextBlockIfOfType(SaveBlock_Hierarchy); |
| | 3262 | |
| | 3263 | if(hier_header) |
| | 3264 | LoadHierarchy(hier_header,&behav->HModelController); |
| | 3265 | } |
| | 3266 | |
| | 3267 | Load_SoundState(&behav->soundHandle); |
| | 3268 | } |
| | 3269 | } |
| | 3270 | |
| | 3271 | void SaveStrategy_PredatorDisc(STRATEGYBLOCK* sbPtr) |
| | 3272 | { |
| | 3273 | PREDATOR_DISC_SAVE_BLOCK *block; |
| | 3274 | PC_PRED_DISC_BEHAV_BLOCK *behav = (PC_PRED_DISC_BEHAV_BLOCK*)sbPtr->dataptr; |
| | 3275 | |
| | 3276 | GET_STRATEGY_SAVE_BLOCK(block,sbPtr); |
| | 3277 | |
| | 3278 | //start copying stuff |
| | 3279 | COPYELEMENT_SAVE(counter) |
| | 3280 | COPYELEMENT_SAVE(Destruct) |
| | 3281 | COPYELEMENT_SAVE(Stuck) |
| | 3282 | COPYELEMENT_SAVE(Bounced) |
| | 3283 | COPYELEMENT_SAVE(bounces) |
| | 3284 | |
| | 3285 | COPY_NAME(block->Target_SBname,behav->Target_SBname); |
| | 3286 | COPY_NAME(block->Prev_Target_SBname,behav->Prev_Target_SBname); |
| | 3287 | |
| | 3288 | //strategy block stuff |
| | 3289 | block->dynamics = *sbPtr->DynPtr; |
| | 3290 | block->dynamics.CollisionReportPtr = NULL; |
| | 3291 | block->DamageBlock = sbPtr->DamageBlock; |
| | 3292 | //save hierarchy |
| | 3293 | SaveHierarchy(&behav->HModelController); |
| | 3294 | |
| | 3295 | Save_SoundState(&behav->soundHandle); |
| | 3296 | } |
| | 3297 | |
| | 3298 | /*-------------------------** |
| | 3299 | ** Load/Save speargun bolt ** |
| | 3300 | **-------------------------*/ |
| | 3301 | |
| | 3302 | typedef struct spear_bolt_save_block |
| | 3303 | { |
| | 3304 | SAVE_BLOCK_STRATEGY_HEADER header; |
| | 3305 | |
| | 3306 | //behaviour block stuff |
| | 3307 | int counter; |
| | 3308 | MATRIXCH Orient; |
| | 3309 | VECTORCH Position; |
| | 3310 | // HMODELCONTROLLER HierarchicalFragment; |
| | 3311 | int Android; |
| | 3312 | AVP_BEHAVIOUR_TYPE Type; |
| | 3313 | int SubType; |
| | 3314 | unsigned int SpearThroughFragment; |
| | 3315 | unsigned int Stuck :1; |
| | 3316 | |
| | 3317 | //strategy block stuff |
| | 3318 | DYNAMICSBLOCK dynamics; |
| | 3319 | |
| | 3320 | } SPEAR_BOLT_SAVE_BLOCK; |
| | 3321 | |
| | 3322 | void LoadStrategy_SpearBolt(SAVE_BLOCK_HEADER* header) |
| | 3323 | { |
| | 3324 | SPEAR_BOLT_SAVE_BLOCK* block = (SPEAR_BOLT_SAVE_BLOCK*) header; |
| | 3325 | |
| | 3326 | //check the size of the save block |
| | 3327 | if(header->size != sizeof(*block)) |
| | 3328 | return; |
| | 3329 | |
| | 3330 | //create default spear bolt |
| | 3331 | DISPLAYBLOCK* dPtr = InitialiseSpeargunBoltBehaviour_ForLoad(); |
| | 3332 | |
| | 3333 | if(NULL != dPtr) |
| | 3334 | { |
| | 3335 | STRATEGYBLOCK* sbPtr = dPtr->ObStrategyBlock; |
| | 3336 | |
| | 3337 | SPEAR_BEHAV_BLOCK* behav = (SPEAR_BEHAV_BLOCK*)sbPtr->dataptr; |
| | 3338 | |
| | 3339 | COPYELEMENT_LOAD(counter) |
| | 3340 | COPYELEMENT_LOAD(Orient) |
| | 3341 | COPYELEMENT_LOAD(Position) |
| | 3342 | COPYELEMENT_LOAD(Android) |
| | 3343 | COPYELEMENT_LOAD(Type) |
| | 3344 | COPYELEMENT_LOAD(SubType) |
| | 3345 | COPYELEMENT_LOAD(SpearThroughFragment) |
| | 3346 | COPYELEMENT_LOAD(Stuck) |
| | 3347 | |
| | 3348 | *sbPtr->DynPtr = block->dynamics; |
| | 3349 | |
| | 3350 | { |
| | 3351 | SAVE_BLOCK_HEADER* hier_header = GetNextBlockIfOfType(SaveBlock_Hierarchy); |
| | 3352 | |
| | 3353 | if(hier_header) |
| | 3354 | LoadHierarchy(hier_header,&behav->HierarchicalFragment); |
| | 3355 | } |
| | 3356 | |
| | 3357 | //if there is a hierarchy fill it in the displayblock |
| | 3358 | if(behav->HierarchicalFragment.Root_Section) |
| | 3359 | dPtr->HModelControlBlock = &behav->HierarchicalFragment; |
| | 3360 | } |
| | 3361 | } |
| | 3362 | |
| | 3363 | void SaveStrategy_SpearBolt(STRATEGYBLOCK* sbPtr) |
| | 3364 | { |
| | 3365 | SPEAR_BOLT_SAVE_BLOCK *block; |
| | 3366 | SPEAR_BEHAV_BLOCK *behav = (SPEAR_BEHAV_BLOCK*)sbPtr->dataptr; |
| | 3367 | GET_STRATEGY_SAVE_BLOCK(block,sbPtr); |
| | 3368 | |
| | 3369 | COPYELEMENT_SAVE(counter) |
| | 3370 | COPYELEMENT_SAVE(Orient) |
| | 3371 | COPYELEMENT_SAVE(Position) |
| | 3372 | COPYELEMENT_SAVE(Android) |
| | 3373 | COPYELEMENT_SAVE(Type) |
| | 3374 | COPYELEMENT_SAVE(SubType) |
| | 3375 | COPYELEMENT_SAVE(SpearThroughFragment) |
| | 3376 | COPYELEMENT_SAVE(Stuck) |
| | 3377 | |
| | 3378 | block->dynamics = *sbPtr->DynPtr; |
| | 3379 | block->dynamics.CollisionReportPtr = NULL; |
| | 3380 | |
| | 3381 | //save the hierarchy |
| | 3382 | SaveHierarchy(&behav->HierarchicalFragment); |
| | 3383 | } |
| | 3384 | |
| | 3385 | typedef struct frisbee_save_block |
| | 3386 | { |
| | 3387 | SAVE_BLOCK_STRATEGY_HEADER header; |
| | 3388 | |
| | 3389 | //behaviour block stuff |
| | 3390 | int counter; |
| | 3391 | int Bounced :1; |
| | 3392 | int bounces; |
| | 3393 | |
| | 3394 | //strategy block stuff |
| | 3395 | DAMAGEBLOCK DamageBlock; |
| | 3396 | DYNAMICSBLOCK dynamics; |
| | 3397 | |
| | 3398 | } FRISBEE_SAVE_BLOCK; |
| | 3399 | |
| | 3400 | void LoadStrategy_Frisbee(SAVE_BLOCK_STRATEGY_HEADER* header) |
| | 3401 | { |
| | 3402 | FRISBEE_SAVE_BLOCK* block = (FRISBEE_SAVE_BLOCK*) header; |
| | 3403 | |
| | 3404 | //check the size of the save block |
| | 3405 | if(header->size != sizeof(*block)) |
| | 3406 | return; |
| | 3407 | |
| | 3408 | //create default disc |
| | 3409 | STRATEGYBLOCK* sbPtr = InitialiseFrisbeeBehaviour_ForLoad(); |
| | 3410 | |
| | 3411 | if(NULL != sbPtr) |
| | 3412 | { |
| | 3413 | FRISBEE_BEHAV_BLOCK* behav = (FRISBEE_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 3414 | |
| | 3415 | COPYELEMENT_LOAD(counter) |
| | 3416 | COPYELEMENT_LOAD(Bounced) |
| | 3417 | COPYELEMENT_LOAD(bounces) |
| | 3418 | |
| | 3419 | *sbPtr->DynPtr = block->dynamics; |
| | 3420 | sbPtr->DamageBlock = block->DamageBlock; |
| | 3421 | |
| | 3422 | //load the hierarchy |
| | 3423 | { |
| | 3424 | SAVE_BLOCK_HEADER* hier_header = GetNextBlockIfOfType(SaveBlock_Hierarchy); |
| | 3425 | |
| | 3426 | if(hier_header) |
| | 3427 | LoadHierarchy(hier_header,&behav->HModelController); |
| | 3428 | } |
| | 3429 | |
| | 3430 | Load_SoundState(&behav->soundHandle); |
| | 3431 | } |
| | 3432 | } |
| | 3433 | |
| | 3434 | void SaveStrategy_Frisbee(STRATEGYBLOCK* sbPtr) |
| | 3435 | { |
| | 3436 | FRISBEE_SAVE_BLOCK *block; |
| | 3437 | FRISBEE_BEHAV_BLOCK *behav = (FRISBEE_BEHAV_BLOCK*)sbPtr->dataptr; |
| | 3438 | |
| | 3439 | GET_STRATEGY_SAVE_BLOCK(block,sbPtr); |
| | 3440 | |
| | 3441 | //start copying stuff |
| | 3442 | COPYELEMENT_SAVE(counter) |
| | 3443 | COPYELEMENT_SAVE(Bounced) |
| | 3444 | COPYELEMENT_SAVE(bounces) |
| | 3445 | |
| | 3446 | //strategy block stuff |
| | 3447 | block->dynamics = *sbPtr->DynPtr; |
| | 3448 | block->dynamics.CollisionReportPtr = NULL; |
| | 3449 | block->DamageBlock = sbPtr->DamageBlock; |
| | 3450 | //save hierarchy |
| | 3451 | SaveHierarchy(&behav->HModelController); |
| | 3452 | |
| | 3453 | Save_SoundState(&behav->soundHandle); |
| | 3454 | } |
| | 3455 | |
| | 3456 | void LoadStrategy_FrisbeeEnergyBolt(SAVE_BLOCK_STRATEGY_HEADER* header) |
| | 3457 | { |
| | 3458 | PREDATOR_ENERGY_BOLT_SAVE_BLOCK* block = (PREDATOR_ENERGY_BOLT_SAVE_BLOCK*) header; |
| | 3459 | |
| | 3460 | //check the size of the save block |
| | 3461 | if(header->size != sizeof(*block)) |
| | 3462 | return; |
| | 3463 | |
| | 3464 | //create default bolt |
| | 3465 | STRATEGYBLOCK* sbPtr =
InitialiseFrisbeeBoltBehaviourKernel(&block->dynamics.Position,&block->dynamics.OrientMat,0,&block->damage,ONE_FIXED); |
| | 3466 | |
| | 3467 | if(NULL != sbPtr) |
| | 3468 | { |
| | 3469 | CASTER_BOLT_BEHAV_BLOCK* behav = (CASTER_BOLT_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 3470 | |
| | 3471 | //copy stuff over |
| | 3472 | COPYELEMENT_LOAD(counter) |
| | 3473 | COPYELEMENT_LOAD(player) |
| | 3474 | COPYELEMENT_LOAD(damage) |
| | 3475 | COPYELEMENT_LOAD(blast_radius) |
| | 3476 | |
| | 3477 | *sbPtr->DynPtr = block->dynamics; |
| | 3478 | } |
| | 3479 | } |
| | 3480 | |
| | 3481 | void SaveStrategy_FrisbeeEnergyBolt(STRATEGYBLOCK* sbPtr) |
| | 3482 | { |
| | 3483 | PREDATOR_ENERGY_BOLT_SAVE_BLOCK* block; |
| | 3484 | CASTER_BOLT_BEHAV_BLOCK* behav = (CASTER_BOLT_BEHAV_BLOCK*) sbPtr->dataptr; |
| | 3485 | |
| | 3486 | GET_STRATEGY_SAVE_BLOCK(block, sbPtr); |
| | 3487 | |
| | 3488 | COPYELEMENT_SAVE(counter) |
| | 3489 | COPYELEMENT_SAVE(player) |
| | 3490 | COPYELEMENT_SAVE(damage) |
| | 3491 | COPYELEMENT_SAVE(blast_radius) |
| | 3492 | |
| | 3493 | block->dynamics = *sbPtr->DynPtr; |
| | 3494 | block->dynamics.CollisionReportPtr = NULL; |
| | 3495 | } |