Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.8 KiB

  1. //===== Copyright �c 1996-2008, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: static_prop - don't move, don't animate, don't do anything.
  4. // physics_prop - move, take damage, but don't animate
  5. //
  6. //===========================================================================//
  7. #include "cbase.h"
  8. #include "prop_physics2.h"
  9. #include "tier1/tier1.h"
  10. #include "vphysics2_interface.h"
  11. #include "datacache/imdlcache.h"
  12. #include <vphysics2_interface_flags.h>
  13. #include "phzfile.h"
  14. extern IPhysics2World *g_pPhys2World;
  15. ConVar g_cv_phys2_shoot_speed("phys2_shoot_speed", "250");
  16. //bool g_bTestPhysics2PropSphere = false;
  17. void CPhysics2Prop::Spawn( void )
  18. {
  19. SetNetworkQuantizeOriginAngAngles( true );
  20. if ( FClassnameIs( this, "physics2_prop" ) )
  21. {
  22. SetClassname( "prop_physics2" );
  23. }
  24. CBaseEntity::Spawn();
  25. if ( IsMarkedForDeletion() )
  26. return;
  27. m_pCookedInertia = NULL;
  28. m_pInertia = NULL;
  29. m_pShape = NULL;
  30. const Physics2PropCollision_t *propCollision = modelinfo->GetPhysics2PropCollision(GetModelIndex());
  31. m_pShape = propCollision->m_pShape;
  32. m_pInertia = propCollision->m_pInertia;
  33. if(!m_pShape)
  34. m_pShape = g_pPhysics2ResourceManager->GetStockShape(PHYSICS2_STOCK_SPHERE_1M);
  35. if(!m_pInertia)
  36. {
  37. m_pCookedInertia = g_pPhysics2->GetCook()->CookInertia(m_pShape);
  38. m_pInertia = m_pCookedInertia->GetInertia();
  39. }
  40. m_pActor = g_pPhys2World->AddActor(m_pShape, m_pInertia);
  41. fltx4 pos = LoadUnaligned3SIMD(&GetAbsOrigin().x);
  42. m_pActor->SetPosition(pos);
  43. m_pActor->SetUserData((uintp)static_cast<CBaseEntity*>(this));
  44. }
  45. CPhysics2Prop::~CPhysics2Prop()
  46. {
  47. if(m_pCookedInertia)
  48. g_pPhysics2->GetCook()->Destroy(m_pCookedInertia);
  49. m_pActor->SetUserData(0);
  50. g_pPhys2World->Destroy(m_pActor);
  51. //g_pPhys2World->Destroy(m_pBoxActor);
  52. //g_pPhysics2ResourceManager->Release(m_pBoxShape);
  53. }
  54. void CPhysics2Prop::Precache( void )
  55. {
  56. if ( GetModelName() == NULL_STRING )
  57. {
  58. Msg( "%s at (%.3f, %.3f, %.3f) has no model name!\n", GetClassname(), GetAbsOrigin().x, GetAbsOrigin().y, GetAbsOrigin().z );
  59. }
  60. else
  61. {
  62. PrecacheModel( STRING( GetModelName() ) );
  63. CBaseEntity::Precache();
  64. }
  65. }
  66. void CPhysics2Prop::VPhysicsUpdate( IPhysicsObject *pPhysicsNull )
  67. {
  68. Assert(!pPhysicsNull);
  69. union
  70. {
  71. struct{float x,y,z,w;}f;
  72. fltx4 v4;
  73. }temp;
  74. Assert(m_pActor->GetUserData() == (uintp)this);
  75. temp.v4 = m_pActor->GetPosition();
  76. SetAbsOrigin(Vector(temp.f.x,temp.f.y,temp.f.z));
  77. QAngle angles;
  78. QuaternionAngles(m_pActor->GetOrientation(), angles);
  79. SetAbsAngles(angles);
  80. }
  81. BEGIN_DATADESC( CPhysics2Prop )
  82. END_DATADESC()
  83. // IMPLEMENT_SERVERCLASS_ST( CPhysics2Prop, DT_Physics2Prop )
  84. // END_SEND_TABLE()
  85. LINK_ENTITY_TO_CLASS( prop_physics2, CPhysics2Prop );
  86. CON_COMMAND_F( phys2_shoot, "<tank|boomer|smoker|witch|hunter|mob|common> <auto> <ragdoll> <area>. Shoots a phys2 object.", FCVAR_CHEAT )
  87. {
  88. CBasePlayer *commandIssuer = UTIL_GetCommandClient();
  89. if( commandIssuer == NULL )
  90. return ;
  91. Vector spawnOffset(0,0,24);
  92. Vector forward;
  93. commandIssuer->EyeVectors( &forward );
  94. trace_t tr;
  95. UTIL_TraceLine( commandIssuer->EyePosition(), commandIssuer->EyePosition() + forward * 100, MASK_ZOMBIESOLID, commandIssuer, COLLISION_GROUP_NONE, &tr );
  96. //CBaseEntity *pTemp = CreateEntityByName("prop_physics2");
  97. Vector velocity = forward * g_cv_phys2_shoot_speed.GetFloat();
  98. Vector spawnPos = tr.endpos;
  99. if ( tr.fraction != 1.0 )
  100. spawnPos += spawnOffset;
  101. CBaseEntity *pEntity = CBaseEntity::CreateNoSpawn("prop_physics2", spawnPos, QAngle(0,0,0));
  102. pEntity->SetModelName(/*castable_string_t*/MAKE_STRING("models/props_crates/supply_crate01.mdl"));
  103. pEntity->Precache();
  104. pEntity->SetModel("models/props_crates/supply_crate01.mdl");
  105. pEntity->Spawn();
  106. static_cast<CPhysics2Prop*>(pEntity)->m_pActor->SetVelocity(LoadUnaligned3SIMD(&velocity.x));
  107. //static_cast<CPhysics2Prop*>(pEntity)->m_pBoxActor->;
  108. }