tablefold.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "../idlib/precompiled.h"
  2. #pragma hdrstop
  3. #include "Game_local.h"
  4. const idEventDef EV_tablefoldreset( "tablefoldreset" );
  5. CLASS_DECLARATION( idAnimatedEntity, idTableFold )
  6. EVENT( EV_tablefoldreset, idTableFold::Event_reset)
  7. END_CLASS
  8. void idTableFold::Spawn( void )
  9. {
  10. idDict args;
  11. args.Clear();
  12. args.SetVector( "origin", this->GetPhysics()->GetOrigin() );
  13. args.Set( "model", "models/tablefold/tris_cm.ase" );
  14. args.SetInt( "frobbable", 1 );
  15. args.SetInt( "corpse", 1 );
  16. args.SetInt( "noGrab", 1 );
  17. args.Set( "owner", this->GetName() );
  18. args.Set( "recordable", this->spawnArgs.GetString("recordable", "0") );
  19. this->frobcube = gameLocal.SpawnEntityType( idStaticEntity::Type, &args );
  20. this->frobcube->SetAngles( this->GetPhysics()->GetAxis().ToAngles() );
  21. args.Clear();
  22. args.SetVector( "origin", this->GetPhysics()->GetOrigin() );
  23. args.Set( "model", "models/tablefold/tris_handle_cm.ase" );
  24. args.SetInt( "frobbable", 1 );
  25. args.SetInt( "corpse", 1 );
  26. args.SetInt( "noGrab", 1 );
  27. args.Set( "owner", this->GetName() );
  28. args.Set( "recordable", this->spawnArgs.GetString("recordable", "0") );
  29. this->frobcube_handle = gameLocal.SpawnEntityType( idStaticEntity::Type, &args );
  30. this->frobcube_handle->SetAngles( this->GetPhysics()->GetAxis().ToAngles() );
  31. args.Clear();
  32. args.SetVector( "origin", this->GetPhysics()->GetOrigin() );
  33. args.Set( "model", "models/tablefold/tris_table_cm.ase" );
  34. mover = ( idMover * )gameLocal.SpawnEntityType( idMover::Type, &args );
  35. mover->SetAngles( this->GetPhysics()->GetAxis().ToAngles() );
  36. mover->Event_SetMoveTime( 0.5 );
  37. Event_open(0);
  38. state = CLOSED;
  39. }
  40. void idTableFold::Event_open( bool value )
  41. {
  42. if (value)
  43. {
  44. //open.
  45. Event_PlayAnim("open", 4);
  46. this->frobcube->GetPhysics()->SetContents(0);
  47. this->frobcube_handle->GetPhysics()->SetContents( CONTENTS_RENDERMODEL );
  48. this->frobcube_handle->GetPhysics()->SetClipMask( MASK_SOLID | CONTENTS_MOVEABLECLIP );
  49. state = OPENED;
  50. idVec3 origPos = this->GetPhysics()->GetOrigin();
  51. mover->Event_MoveToPos( origPos );
  52. }
  53. else
  54. {
  55. //close.
  56. Event_PlayAnim("close", 4);
  57. this->frobcube_handle->GetPhysics()->SetContents(0);
  58. this->frobcube->GetPhysics()->SetContents( CONTENTS_RENDERMODEL );
  59. this->frobcube->GetPhysics()->SetClipMask( MASK_SOLID | CONTENTS_MOVEABLECLIP );
  60. state = CLOSED;
  61. idVec3 forward;
  62. idVec3 movePos;
  63. GetPhysics()->GetAxis().ToAngles().ToVectors( &forward );
  64. movePos = this->GetPhysics()->GetOrigin() + (forward * -20);
  65. mover->Event_MoveToPos( movePos );
  66. }
  67. }
  68. void idTableFold::Event_reset( void )
  69. {
  70. Event_open(0);
  71. }
  72. void idTableFold::OnFrob( idEntity* activator )
  73. {
  74. if (state == CLOSED)
  75. {
  76. Event_open(true);
  77. }
  78. else
  79. {
  80. Event_open(false);
  81. }
  82. }