Team Fortress 2 Source Code as on 22/4/2020
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.

142 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Used to create a path that can be followed by NPCs and trains.
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "trains.h"
  8. #include "entitylist.h"
  9. #include "ndebugoverlay.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. class CPathCorner : public CPointEntity
  13. {
  14. DECLARE_CLASS( CPathCorner, CPointEntity );
  15. public:
  16. void Spawn( );
  17. float GetDelay( void ) { return m_flWait; }
  18. int DrawDebugTextOverlays(void);
  19. void DrawDebugGeometryOverlays(void);
  20. // Input handlers
  21. void InputSetNextPathCorner( inputdata_t &inputdata );
  22. void InputInPass( inputdata_t &inputdata );
  23. DECLARE_DATADESC();
  24. private:
  25. float m_flWait;
  26. COutputEvent m_OnPass;
  27. };
  28. LINK_ENTITY_TO_CLASS( path_corner, CPathCorner );
  29. class CPathCornerCrash : public CPathCorner
  30. {
  31. DECLARE_CLASS( CPathCornerCrash, CPathCorner );
  32. };
  33. LINK_ENTITY_TO_CLASS( path_corner_crash, CPathCornerCrash );
  34. BEGIN_DATADESC( CPathCorner )
  35. DEFINE_KEYFIELD( m_flWait, FIELD_FLOAT, "wait" ),
  36. // Inputs
  37. DEFINE_INPUTFUNC( FIELD_STRING, "SetNextPathCorner", InputSetNextPathCorner),
  38. // Internal inputs - not exposed in the FGD
  39. DEFINE_INPUTFUNC( FIELD_VOID, "InPass", InputInPass ),
  40. // Outputs
  41. DEFINE_OUTPUT( m_OnPass, "OnPass"),
  42. END_DATADESC()
  43. //-----------------------------------------------------------------------------
  44. // Purpose:
  45. //-----------------------------------------------------------------------------
  46. void CPathCorner::Spawn( void )
  47. {
  48. ASSERTSZ(GetEntityName() != NULL_STRING, "path_corner without a targetname");
  49. }
  50. //------------------------------------------------------------------------------
  51. // Purpose: Sets the next path corner by name.
  52. // Input : String ID name of next path corner.
  53. //-----------------------------------------------------------------------------
  54. void CPathCorner::InputSetNextPathCorner( inputdata_t &inputdata )
  55. {
  56. m_target = inputdata.value.StringID();
  57. }
  58. //-----------------------------------------------------------------------------
  59. // Purpose: Fired by path followers as they pass the path corner.
  60. //-----------------------------------------------------------------------------
  61. void CPathCorner::InputInPass( inputdata_t &inputdata )
  62. {
  63. m_OnPass.FireOutput( inputdata.pActivator, inputdata.pCaller, 0);
  64. }
  65. //-----------------------------------------------------------------------------
  66. // Purpose: Draw any debug text overlays
  67. // Output : Current text offset from the top
  68. //-----------------------------------------------------------------------------
  69. int CPathCorner::DrawDebugTextOverlays(void)
  70. {
  71. int text_offset = BaseClass::DrawDebugTextOverlays();
  72. if (m_debugOverlays & OVERLAY_TEXT_BIT)
  73. {
  74. // --------------
  75. // Print Target
  76. // --------------
  77. char tempstr[255];
  78. if (m_target!=NULL_STRING)
  79. {
  80. Q_snprintf(tempstr,sizeof(tempstr),"Target: %s",STRING(m_target));
  81. }
  82. else
  83. {
  84. Q_strncpy(tempstr,"Target: - ",sizeof(tempstr));
  85. }
  86. EntityText(text_offset,tempstr,0);
  87. text_offset++;
  88. }
  89. return text_offset;
  90. }
  91. //-----------------------------------------------------------------------------
  92. // Purpose: Override base class to add display of paths
  93. //-----------------------------------------------------------------------------
  94. void CPathCorner::DrawDebugGeometryOverlays(void)
  95. {
  96. // ----------------------------------------------
  97. // Draw line to next target is bbox is selected
  98. // ----------------------------------------------
  99. if (m_debugOverlays & (OVERLAY_BBOX_BIT|OVERLAY_ABSBOX_BIT))
  100. {
  101. NDebugOverlay::Box(GetAbsOrigin(), Vector(-10,-10,-10), Vector(10,10,10), 255, 100, 100, 0 ,0);
  102. if (m_target != NULL_STRING)
  103. {
  104. CBaseEntity *pTarget = gEntList.FindEntityByName( NULL, m_target );
  105. if (pTarget)
  106. {
  107. NDebugOverlay::Line(GetAbsOrigin(),pTarget->GetAbsOrigin(),255,100,100,true,0.0);
  108. }
  109. }
  110. }
  111. BaseClass::DrawDebugGeometryOverlays();
  112. }