doorfolding.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #include "../idlib/precompiled.h"
  2. #pragma hdrstop
  3. #include "Game_local.h"
  4. const idEventDef EV_doorfoldingactivate( "doorfoldingactivate", "d" );
  5. CLASS_DECLARATION( idEntity, idDoorFolding )
  6. EVENT( EV_doorfoldingactivate, idDoorFolding::Event_activate)
  7. END_CLASS
  8. void idDoorFolding::Think( void )
  9. {
  10. idEntity::Present();
  11. }
  12. void idDoorFolding::Event_activate( int value )
  13. {
  14. if (value <= 0)
  15. {
  16. int i;
  17. //close.
  18. for (i = 0; i < BARCOUNT; i++)
  19. {
  20. idVec3 origin = GetPhysics()->GetOrigin();
  21. movers[i]->Event_MoveToPos( origin );
  22. }
  23. }
  24. else
  25. {
  26. int i;
  27. //open.
  28. for (i = 0; i < BARCOUNT; i++)
  29. {
  30. movers[i]->Event_MoveToPos( movers[i]->originalPosition );
  31. }
  32. }
  33. }
  34. void idDoorFolding::Spawn( void )
  35. {
  36. int i;
  37. idVec3 forward;
  38. int doorHeight = 112;
  39. int doorWidth = spawnArgs.GetInt("width", "128");
  40. float movetime = spawnArgs.GetFloat("movetime", "1" );
  41. int segmentWidth = doorWidth / BARCOUNT;
  42. this->GetPhysics()->GetAxis().ToAngles().ToVectors(&forward);
  43. int barheight0 = doorHeight * 0.3f;
  44. int barheight1 = doorHeight * 0.7f;
  45. for (i = 0; i < BARCOUNT; i++)
  46. {
  47. idDict args;
  48. args.Clear();
  49. args.SetVector( "origin", this->GetPhysics()->GetOrigin() + (forward * (segmentWidth * (i+1))));
  50. args.Set( "model", "models/doorfolding/tris.ase" );
  51. movers[i] = ( idMover * )gameLocal.SpawnEntityType( idMover::Type, &args );
  52. movers[i]->Event_SetMoveTime( movetime );
  53. }
  54. //diagonal bars.
  55. for (i = 1; i < BARCOUNT; i++)
  56. {
  57. idDict args;
  58. args.Clear();
  59. args.SetVector( "origin", movers[i]->GetPhysics()->GetOrigin() + idVec3(0,0,barheight0+16) );
  60. this->beam[(i * 8) + 0] = ( idBeam * )gameLocal.SpawnEntityType( idBeam::Type, &args );
  61. this->beam[(i * 8) + 0]->Bind(movers[i], false);
  62. args.Clear();
  63. args.SetVector( "origin", movers[i - 1]->GetPhysics()->GetOrigin() + idVec3(0,0,barheight0-16) );
  64. args.Set( "width", "2" );
  65. args.Set( "skin", "skins/beam_black" );
  66. args.Set( "target", beam[(i * 8) + 0]->name.c_str() );
  67. this->beam[(i * 8) + 1] = ( idBeam * )gameLocal.SpawnEntityType( idBeam::Type, &args );
  68. this->beam[(i * 8) + 1]->Bind(movers[i - 1], false);
  69. args.Clear();
  70. args.SetVector( "origin", movers[i]->GetPhysics()->GetOrigin() + idVec3(0,0,barheight0-16) );
  71. this->beam[(i * 8) + 2] = ( idBeam * )gameLocal.SpawnEntityType( idBeam::Type, &args );
  72. this->beam[(i * 8) + 2]->Bind(movers[i], false);
  73. args.Clear();
  74. args.SetVector( "origin", movers[i - 1]->GetPhysics()->GetOrigin() + idVec3(0,0,barheight0+16) );
  75. args.Set( "width", "2" );
  76. args.Set( "skin", "skins/beam_black" );
  77. args.Set( "target", beam[(i * 8) + 2]->name.c_str() );
  78. this->beam[(i * 8) + 3] = ( idBeam * )gameLocal.SpawnEntityType( idBeam::Type, &args );
  79. this->beam[(i * 8) + 3]->Bind(movers[i - 1], false);
  80. //second set.
  81. args.Clear();
  82. args.SetVector( "origin", movers[i]->GetPhysics()->GetOrigin() + idVec3(0,0,barheight1+16) );
  83. this->beam[(i * 8) + 4] = ( idBeam * )gameLocal.SpawnEntityType( idBeam::Type, &args );
  84. this->beam[(i * 8) + 4]->Bind(movers[i], false);
  85. args.Clear();
  86. args.SetVector( "origin", movers[i - 1]->GetPhysics()->GetOrigin() + idVec3(0,0,barheight1-16) );
  87. args.Set( "width", "2" );
  88. args.Set( "skin", "skins/beam_black" );
  89. args.Set( "target", beam[(i * 8) + 4]->name.c_str() );
  90. this->beam[(i * 8) + 5] = ( idBeam * )gameLocal.SpawnEntityType( idBeam::Type, &args );
  91. this->beam[(i * 8) + 5]->Bind(movers[i - 1], false);
  92. args.Clear();
  93. args.SetVector( "origin", movers[i]->GetPhysics()->GetOrigin() + idVec3(0,0,barheight1-16) );
  94. this->beam[(i * 8) + 6] = ( idBeam * )gameLocal.SpawnEntityType( idBeam::Type, &args );
  95. this->beam[(i * 8) + 6]->Bind(movers[i], false);
  96. args.Clear();
  97. args.SetVector( "origin", movers[i - 1]->GetPhysics()->GetOrigin() + idVec3(0,0,barheight1+16) );
  98. args.Set( "width", "2" );
  99. args.Set( "skin", "skins/beam_black" );
  100. args.Set( "target", beam[(i * 8) + 6]->name.c_str() );
  101. this->beam[(i * 8) + 7] = ( idBeam * )gameLocal.SpawnEntityType( idBeam::Type, &args );
  102. this->beam[(i * 8) + 7]->Bind(movers[i - 1], false);
  103. }
  104. }