1 /* 2 =========================================================================== 3 4 Doom 3 GPL Source Code 5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). 8 9 Doom 3 Source Code is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 Doom 3 Source Code is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below. 23 24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. 25 26 =========================================================================== 27 */ 28 29 #ifndef __GAME_AFENTITY_H__ 30 #define __GAME_AFENTITY_H__ 31 32 #include "physics/Physics_AF.h" 33 #include "physics/Force_Constant.h" 34 #include "Entity.h" 35 #include "AF.h" 36 37 /* 38 =============================================================================== 39 40 idMultiModelAF 41 42 Entity using multiple separate visual models animated with a single 43 articulated figure. Only used for debugging! 44 45 =============================================================================== 46 */ 47 const int GIB_DELAY = 200; // only gib this often to keep performace hits when blowing up several mobs 48 49 class idMultiModelAF : public idEntity { 50 public: 51 CLASS_PROTOTYPE( idMultiModelAF ); 52 53 void Spawn( void ); 54 ~idMultiModelAF( void ); 55 56 virtual void Think( void ); 57 virtual void Present( void ); 58 59 protected: 60 idPhysics_AF physicsObj; 61 62 void SetModelForId( int id, const idStr &modelName ); 63 64 private: 65 idList<idRenderModel *> modelHandles; 66 idList<int> modelDefHandles; 67 }; 68 69 70 /* 71 =============================================================================== 72 73 idChain 74 75 Chain hanging down from the ceiling. Only used for debugging! 76 77 =============================================================================== 78 */ 79 80 class idChain : public idMultiModelAF { 81 public: 82 CLASS_PROTOTYPE( idChain ); 83 84 void Spawn( void ); 85 86 protected: 87 void BuildChain( const idStr &name, const idVec3 &origin, float linkLength, float linkWidth, float density, int numLinks, bool bindToWorld = true ); 88 }; 89 90 91 /* 92 =============================================================================== 93 94 idAFAttachment 95 96 =============================================================================== 97 */ 98 99 class idAFAttachment : public idAnimatedEntity { 100 public: 101 CLASS_PROTOTYPE( idAFAttachment ); 102 103 idAFAttachment( void ); 104 virtual ~idAFAttachment( void ); 105 106 void Spawn( void ); 107 108 void Save( idSaveGame *savefile ) const; 109 void Restore( idRestoreGame *savefile ); 110 111 void SetBody( idEntity *bodyEnt, const char *headModel, jointHandle_t attachJoint ); 112 void ClearBody( void ); 113 idEntity * GetBody( void ) const; 114 115 virtual void Think( void ); 116 117 virtual void Hide( void ); 118 virtual void Show( void ); 119 120 void PlayIdleAnim( int blendTime ); 121 122 virtual void GetImpactInfo( idEntity *ent, int id, const idVec3 &point, impactInfo_t *info ); 123 virtual void ApplyImpulse( idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse ); 124 virtual void AddForce( idEntity *ent, int id, const idVec3 &point, const idVec3 &force ); 125 126 virtual void Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &dir, const char *damageDefName, const float damageScale, const int location ); 127 virtual void AddDamageEffect( const trace_t &collision, const idVec3 &velocity, const char *damageDefName ); 128 129 void SetCombatModel( void ); 130 idClipModel * GetCombatModel( void ) const; 131 virtual void LinkCombat( void ); 132 virtual void UnlinkCombat( void ); 133 134 protected: 135 idEntity * body; 136 idClipModel * combatModel; // render model for hit detection of head 137 int idleAnim; 138 jointHandle_t attachJoint; 139 }; 140 141 142 /* 143 =============================================================================== 144 145 idAFEntity_Base 146 147 =============================================================================== 148 */ 149 150 class idAFEntity_Base : public idAnimatedEntity { 151 public: 152 CLASS_PROTOTYPE( idAFEntity_Base ); 153 154 idAFEntity_Base( void ); 155 virtual ~idAFEntity_Base( void ); 156 157 void Spawn( void ); 158 159 void Save( idSaveGame *savefile ) const; 160 void Restore( idRestoreGame *savefile ); 161 162 virtual void Think( void ); 163 virtual void GetImpactInfo( idEntity *ent, int id, const idVec3 &point, impactInfo_t *info ); 164 virtual void ApplyImpulse( idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse ); 165 virtual void AddForce( idEntity *ent, int id, const idVec3 &point, const idVec3 &force ); 166 virtual bool Collide( const trace_t &collision, const idVec3 &velocity ); 167 virtual bool GetPhysicsToVisualTransform( idVec3 &origin, idMat3 &axis ); 168 virtual bool UpdateAnimationControllers( void ); 169 virtual void FreeModelDef( void ); 170 171 virtual bool LoadAF( void ); IsActiveAF(void)172 bool IsActiveAF( void ) const { return af.IsActive(); } GetAFName(void)173 const char * GetAFName( void ) const { return af.GetName(); } GetAFPhysics(void)174 idPhysics_AF * GetAFPhysics( void ) { return af.GetPhysics(); } 175 176 void SetCombatModel( void ); 177 idClipModel * GetCombatModel( void ) const; 178 // contents of combatModel can be set to 0 or re-enabled (mp) 179 void SetCombatContents( bool enable ); 180 virtual void LinkCombat( void ); 181 virtual void UnlinkCombat( void ); 182 183 int BodyForClipModelId( int id ) const; 184 185 void SaveState( idDict &args ) const; 186 void LoadState( const idDict &args ); 187 188 void AddBindConstraints( void ); 189 void RemoveBindConstraints( void ); 190 191 virtual void ShowEditingDialog( void ); 192 193 static void DropAFs( idEntity *ent, const char *type, idList<idEntity *> *list ); 194 195 protected: 196 idAF af; // articulated figure 197 idClipModel * combatModel; // render model for hit detection 198 int combatModelContents; 199 idVec3 spawnOrigin; // spawn origin 200 idMat3 spawnAxis; // rotation axis used when spawned 201 int nextSoundTime; // next time this can make a sound 202 203 void Event_SetConstraintPosition( const char *name, const idVec3 &pos ); 204 }; 205 206 /* 207 =============================================================================== 208 209 idAFEntity_Gibbable 210 211 =============================================================================== 212 */ 213 214 extern const idEventDef EV_Gib; 215 extern const idEventDef EV_Gibbed; 216 217 class idAFEntity_Gibbable : public idAFEntity_Base { 218 public: 219 CLASS_PROTOTYPE( idAFEntity_Gibbable ); 220 221 idAFEntity_Gibbable( void ); 222 ~idAFEntity_Gibbable( void ); 223 224 void Spawn( void ); 225 void Save( idSaveGame *savefile ) const; 226 void Restore( idRestoreGame *savefile ); 227 virtual void Present( void ); 228 virtual void Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &dir, const char *damageDefName, const float damageScale, const int location ); 229 #ifdef _D3XP 230 void SetThrown( bool isThrown ); 231 virtual bool Collide( const trace_t &collision, const idVec3 &velocity ); 232 #endif 233 virtual void SpawnGibs( const idVec3 &dir, const char *damageDefName ); 234 235 #ifdef _D3XP IsGibbed()236 bool IsGibbed() { return gibbed; }; 237 #endif 238 239 protected: 240 idRenderModel * skeletonModel; 241 int skeletonModelDefHandle; 242 bool gibbed; 243 244 #ifdef _D3XP 245 bool wasThrown; 246 #endif 247 248 virtual void Gib( const idVec3 &dir, const char *damageDefName ); 249 void InitSkeletonModel( void ); 250 251 void Event_Gib( const char *damageDefName ); 252 }; 253 254 /* 255 =============================================================================== 256 257 idAFEntity_Generic 258 259 =============================================================================== 260 */ 261 262 class idAFEntity_Generic : public idAFEntity_Gibbable { 263 public: 264 CLASS_PROTOTYPE( idAFEntity_Generic ); 265 266 idAFEntity_Generic( void ); 267 ~idAFEntity_Generic( void ); 268 269 void Spawn( void ); 270 271 void Save( idSaveGame *savefile ) const; 272 void Restore( idRestoreGame *savefile ); 273 274 virtual void Think( void ); KeepRunningPhysics(void)275 void KeepRunningPhysics( void ) { keepRunningPhysics = true; } 276 277 private: 278 void Event_Activate( idEntity *activator ); 279 280 bool keepRunningPhysics; 281 }; 282 283 284 /* 285 =============================================================================== 286 287 idAFEntity_WithAttachedHead 288 289 =============================================================================== 290 */ 291 292 class idAFEntity_WithAttachedHead : public idAFEntity_Gibbable { 293 public: 294 CLASS_PROTOTYPE( idAFEntity_WithAttachedHead ); 295 296 idAFEntity_WithAttachedHead(); 297 ~idAFEntity_WithAttachedHead(); 298 299 void Spawn( void ); 300 301 void Save( idSaveGame *savefile ) const; 302 void Restore( idRestoreGame *savefile ); 303 304 void SetupHead( void ); 305 306 virtual void Think( void ); 307 308 virtual void Hide( void ); 309 virtual void Show( void ); 310 virtual void ProjectOverlay( const idVec3 &origin, const idVec3 &dir, float size, const char *material ); 311 312 virtual void LinkCombat( void ); 313 virtual void UnlinkCombat( void ); 314 315 protected: 316 virtual void Gib( const idVec3 &dir, const char *damageDefName ); 317 318 #ifndef _D3XP 319 private: 320 #else 321 public: 322 #endif 323 idEntityPtr<idAFAttachment> head; 324 325 void Event_Gib( const char *damageDefName ); 326 void Event_Activate( idEntity *activator ); 327 }; 328 329 330 /* 331 =============================================================================== 332 333 idAFEntity_Vehicle 334 335 =============================================================================== 336 */ 337 338 class idAFEntity_Vehicle : public idAFEntity_Base { 339 public: 340 CLASS_PROTOTYPE( idAFEntity_Vehicle ); 341 342 idAFEntity_Vehicle( void ); 343 344 void Spawn( void ); 345 void Use( idPlayer *player ); 346 347 protected: 348 idPlayer * player; 349 jointHandle_t eyesJoint; 350 jointHandle_t steeringWheelJoint; 351 float wheelRadius; 352 float steerAngle; 353 float steerSpeed; 354 const idDeclParticle * dustSmoke; 355 356 float GetSteerAngle( void ); 357 }; 358 359 360 /* 361 =============================================================================== 362 363 idAFEntity_VehicleSimple 364 365 =============================================================================== 366 */ 367 368 class idAFEntity_VehicleSimple : public idAFEntity_Vehicle { 369 public: 370 CLASS_PROTOTYPE( idAFEntity_VehicleSimple ); 371 372 idAFEntity_VehicleSimple( void ); 373 ~idAFEntity_VehicleSimple( void ); 374 375 void Spawn( void ); 376 virtual void Think( void ); 377 378 protected: 379 idClipModel * wheelModel; 380 idAFConstraint_Suspension * suspension[4]; 381 jointHandle_t wheelJoints[4]; 382 float wheelAngles[4]; 383 }; 384 385 386 /* 387 =============================================================================== 388 389 idAFEntity_VehicleFourWheels 390 391 =============================================================================== 392 */ 393 394 class idAFEntity_VehicleFourWheels : public idAFEntity_Vehicle { 395 public: 396 CLASS_PROTOTYPE( idAFEntity_VehicleFourWheels ); 397 398 idAFEntity_VehicleFourWheels( void ); 399 400 void Spawn( void ); 401 virtual void Think( void ); 402 403 protected: 404 idAFBody * wheels[4]; 405 idAFConstraint_Hinge * steering[2]; 406 jointHandle_t wheelJoints[4]; 407 float wheelAngles[4]; 408 }; 409 410 411 /* 412 =============================================================================== 413 414 idAFEntity_VehicleSixWheels 415 416 =============================================================================== 417 */ 418 419 class idAFEntity_VehicleSixWheels : public idAFEntity_Vehicle { 420 public: 421 CLASS_PROTOTYPE( idAFEntity_VehicleSixWheels ); 422 423 idAFEntity_VehicleSixWheels( void ); 424 425 void Spawn( void ); 426 virtual void Think( void ); 427 428 #ifdef _D3XP 429 float force; 430 float velocity; 431 float steerAngle; 432 #endif 433 434 private: 435 idAFBody * wheels[6]; 436 idAFConstraint_Hinge * steering[4]; 437 jointHandle_t wheelJoints[6]; 438 float wheelAngles[6]; 439 }; 440 441 #ifdef _D3XP 442 /* 443 =============================================================================== 444 445 idAFEntity_VehicleAutomated 446 447 =============================================================================== 448 */ 449 450 class idAFEntity_VehicleAutomated : public idAFEntity_VehicleSixWheels { 451 public: 452 CLASS_PROTOTYPE( idAFEntity_VehicleAutomated ); 453 454 void Spawn( void ); 455 void PostSpawn( void ); 456 virtual void Think( void ); 457 458 private: 459 460 idEntity *waypoint; 461 float steeringSpeed; 462 float currentSteering; 463 float idealSteering; 464 float originHeight; 465 466 void Event_SetVelocity( float _velocity ); 467 void Event_SetTorque( float _torque ); 468 void Event_SetSteeringSpeed( float _steeringSpeed ); 469 void Event_SetWayPoint( idEntity *_waypoint ); 470 }; 471 #endif 472 473 /* 474 =============================================================================== 475 476 idAFEntity_SteamPipe 477 478 =============================================================================== 479 */ 480 481 class idAFEntity_SteamPipe : public idAFEntity_Base { 482 public: 483 CLASS_PROTOTYPE( idAFEntity_SteamPipe ); 484 485 idAFEntity_SteamPipe( void ); 486 ~idAFEntity_SteamPipe( void ); 487 488 void Spawn( void ); 489 void Save( idSaveGame *savefile ) const; 490 void Restore( idRestoreGame *savefile ); 491 492 virtual void Think( void ); 493 494 private: 495 int steamBody; 496 float steamForce; 497 float steamUpForce; 498 idForce_Constant force; 499 renderEntity_t steamRenderEntity; 500 qhandle_t steamModelDefHandle; 501 502 void InitSteamRenderEntity( void ); 503 }; 504 505 506 /* 507 =============================================================================== 508 509 idAFEntity_ClawFourFingers 510 511 =============================================================================== 512 */ 513 514 class idAFEntity_ClawFourFingers : public idAFEntity_Base { 515 public: 516 CLASS_PROTOTYPE( idAFEntity_ClawFourFingers ); 517 518 idAFEntity_ClawFourFingers( void ); 519 520 void Spawn( void ); 521 void Save( idSaveGame *savefile ) const; 522 void Restore( idRestoreGame *savefile ); 523 524 private: 525 idAFConstraint_Hinge * fingers[4]; 526 527 void Event_SetFingerAngle( float angle ); 528 void Event_StopFingers( void ); 529 }; 530 531 #ifdef _D3XP 532 533 /** 534 * idHarvestable contains all of the code required to turn an entity into a harvestable 535 * entity. The entity must create an instance of this class and call the appropriate 536 * interface methods at the correct time. 537 */ 538 class idHarvestable : public idEntity { 539 public: 540 CLASS_PROTOTYPE( idHarvestable ); 541 542 idHarvestable(); 543 ~idHarvestable(); 544 545 void Spawn(); 546 void Init(idEntity* parent); 547 void Save( idSaveGame *savefile ) const; 548 void Restore( idRestoreGame *savefile ); 549 550 void SetParent(idEntity* parent); 551 552 void Think(); 553 void Gib(); 554 555 protected: 556 idEntityPtr<idEntity> parentEnt; 557 float triggersize; 558 idClipModel * trigger; 559 float giveDelay; 560 float removeDelay; 561 bool given; 562 563 idEntityPtr<idPlayer> player; 564 int startTime; 565 566 bool fxFollowPlayer; 567 idEntityPtr<idEntityFx> fx; 568 idStr fxOrient; 569 570 protected: 571 void BeginBurn(); 572 void BeginFX(); 573 void CalcTriggerBounds( float size, idBounds &bounds ); 574 575 bool GetFxOrientationAxis(idMat3& mat); 576 577 void Event_SpawnHarvestTrigger( void ); 578 void Event_Touch( idEntity *other, trace_t *trace ); 579 } ; 580 581 582 /* 583 =============================================================================== 584 585 idAFEntity_Harvest 586 587 =============================================================================== 588 */ 589 590 591 592 class idAFEntity_Harvest : public idAFEntity_WithAttachedHead { 593 public: 594 CLASS_PROTOTYPE( idAFEntity_Harvest ); 595 596 idAFEntity_Harvest(); 597 ~idAFEntity_Harvest(); 598 599 void Spawn( void ); 600 601 void Save( idSaveGame *savefile ) const; 602 void Restore( idRestoreGame *savefile ); 603 604 virtual void Think( void ); 605 606 virtual void Gib( const idVec3 &dir, const char *damageDefName ); 607 608 protected: 609 idEntityPtr<idHarvestable> harvestEnt; 610 protected: 611 void Event_SpawnHarvestEntity( void ); 612 613 }; 614 #endif 615 616 #endif /* !__GAME_AFENTITY_H__ */ 617