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