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.

247 lines
6.3 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "animation.h"
  8. #include "flex_expresser.h"
  9. #include "entitylist.h"
  10. /*
  11. #include "filesystem.h"
  12. #include "studio.h"
  13. #include "choreoevent.h"
  14. #include "choreoscene.h"
  15. #include "choreoactor.h"
  16. #include "vstdlib/random.h"
  17. #include "engine/IEngineSound.h"
  18. #include "tier1/strtools.h"
  19. #include "keyvalues.h"
  20. #include "ai_basenpc.h"
  21. #include "ai_navigator.h"
  22. #include "ai_moveprobe.h"
  23. #include "sceneentity.h"
  24. #include "ai_baseactor.h"
  25. #include "datacache/imdlcache.h"
  26. #include "tier1/byteswap.h"
  27. */
  28. // memdbgon must be the last include file in a .cpp file!!!
  29. #include "tier0/memdbgon.h"
  30. CFlexExpresser::CFlexExpresser()
  31. {
  32. m_pExpresser = NULL;
  33. m_flThenAnyMaxDist = 0;
  34. }
  35. CFlexExpresser::~CFlexExpresser()
  36. {
  37. if (m_pExpresser)
  38. delete m_pExpresser;
  39. m_pExpresser = NULL;
  40. }
  41. //-----------------------------------------------------------------------------
  42. // Purpose:
  43. //-----------------------------------------------------------------------------
  44. CAI_Expresser *CFlexExpresser::CreateExpresser( void )
  45. {
  46. AssertMsg1( !m_pExpresser, "LEAK: Double-created expresser for FlexExpresser %s", GetDebugName() );
  47. m_pExpresser = new CAI_ExpresserWithFollowup(this);
  48. if ( !m_pExpresser )
  49. return NULL;
  50. m_pExpresser->Connect(this);
  51. return m_pExpresser;
  52. }
  53. // does not call to base class spawn.
  54. void CFlexExpresser::Spawn( void )
  55. {
  56. const char *szModel = (char *)STRING( GetModelName() );
  57. if (!szModel || !*szModel)
  58. {
  59. Warning( "WARNING: %s at %.0f %.0f %0.f missing modelname\n", GetDebugName(), GetAbsOrigin().x, GetAbsOrigin().y, GetAbsOrigin().z );
  60. }
  61. else
  62. {
  63. PrecacheModel( szModel );
  64. SetModel( szModel );
  65. }
  66. Precache();
  67. if ( m_spawnflags & FCYCLER_NOTSOLID )
  68. {
  69. SetSolid( SOLID_NONE );
  70. }
  71. else
  72. {
  73. SetSolid( SOLID_BBOX );
  74. AddSolidFlags( FSOLID_NOT_STANDABLE );
  75. }
  76. SetMoveType( MOVETYPE_NONE );
  77. // funcorators are immortal
  78. m_takedamage = DAMAGE_NO;
  79. m_iHealth = 80000;// no cycler should die
  80. m_flPlaybackRate = 1.0f;
  81. m_flGroundSpeed = 0;
  82. SetNextThink( gpGlobals->curtime + 1.0f );
  83. ResetSequenceInfo( );
  84. InitBoneControllers();
  85. /*
  86. if (GetNumFlexControllers() < 5)
  87. Warning( "cycler_flex used on model %s without enough flexes.\n", szModel );
  88. */
  89. CreateExpresser();
  90. }
  91. void CFlexExpresser::Think( void )
  92. {
  93. SetNextThink( gpGlobals->curtime + 0.1f );
  94. StudioFrameAdvance ( );
  95. }
  96. void CFlexExpresser::InputSpeakResponseConcept( inputdata_t &inputdata )
  97. {
  98. const char *pInputString = STRING(inputdata.value.StringID());
  99. // if no params, early out
  100. if (!pInputString || *pInputString == 0)
  101. {
  102. Warning( "empty SpeakResponse input from %s to %s\n", inputdata.pCaller->GetDebugName(), GetDebugName() );
  103. return;
  104. }
  105. char buf[512]; // temporary for tokenizing
  106. char outputmodifiers[512]; // eventual output to speak
  107. int outWritten = 0;
  108. V_strncpy(buf, pInputString, 510);
  109. buf[511] = 0; // just in case the last character is a comma -- enforce that the
  110. // last character in the buffer is always a terminator.
  111. // special syntax allowing designers to submit inputs with contexts like
  112. // "concept,context1:value1,context2:value2,context3:value3"
  113. // except that entity i/o seems to eat commas these days (didn't used to be the case)
  114. // so instead of commas we have to use spaces in the entity IO,
  115. // and turn them into commas here. AWESOME.
  116. char *pModifiers = const_cast<char *>(V_strnchr(buf, ' ', 510));
  117. if ( pModifiers )
  118. {
  119. *pModifiers = 0;
  120. ++pModifiers;
  121. // tokenize on spaces
  122. char *token = strtok(pModifiers, " ");
  123. while (token)
  124. {
  125. // find the start characters for the key and value
  126. // (seperated by a : which we replace with null)
  127. char * RESTRICT key = token;
  128. char * RESTRICT colon = const_cast<char *>(V_strnchr(key, ':', 510));
  129. char * RESTRICT value;
  130. if (!colon)
  131. {
  132. Warning( "faulty context k:v pair in entity io %s\n", pInputString );
  133. break;
  134. }
  135. // write the key and colon to the output string
  136. int toWrite = colon - key + 1;
  137. if ( outWritten + toWrite >= 512 )
  138. {
  139. Warning( "Speak input to %s had overlong parameter %s", GetDebugName(), pInputString );
  140. return;
  141. }
  142. memcpy(outputmodifiers + outWritten, key, toWrite);
  143. outWritten += toWrite;
  144. *colon = 0;
  145. value = colon + 1;
  146. // determine if the value is actually a procedural name
  147. CBaseEntity *pProcedural = gEntList.FindEntityProcedural( value, this, inputdata.pActivator, inputdata.pCaller );
  148. // write the value to the output -- if it's a procedural name, replace appropriately;
  149. // if not, just copy over.
  150. const char *valString;
  151. if (pProcedural)
  152. {
  153. valString = STRING(pProcedural->GetEntityName());
  154. }
  155. else
  156. {
  157. valString = value;
  158. }
  159. toWrite = strlen(valString);
  160. toWrite = MIN( 511-outWritten, toWrite );
  161. V_strncpy( outputmodifiers + outWritten, valString, toWrite+1 );
  162. outWritten += toWrite;
  163. // get the next token
  164. token = strtok(NULL, " ");
  165. if (token)
  166. {
  167. // if there is a next token, write in a comma
  168. if (outWritten < 511)
  169. {
  170. outputmodifiers[outWritten++]=',';
  171. }
  172. }
  173. }
  174. }
  175. // null terminate just in case
  176. outputmodifiers[outWritten] = 0;
  177. Speak( buf, outWritten > 0 ? outputmodifiers : NULL );
  178. }
  179. // does nothing. It's important that it does nothing because if it
  180. // calls through to base class and tries to flinch, it will crash.
  181. int CFlexExpresser::OnTakeDamage( const CTakeDamageInfo &info )
  182. {
  183. return 0;
  184. }
  185. IResponseSystem *CFlexExpresser::GetResponseSystem( void )
  186. {
  187. return BaseClass::GetResponseSystem();
  188. }
  189. // because nothing inherits from CFlexExpresser, we can just check classname.
  190. CFlexExpresser * CFlexExpresser::AsFlexExpresser( CBaseEntity *pEntity )
  191. {
  192. if ( pEntity )
  193. {
  194. if ( pEntity->ClassMatches( MAKE_STRING("prop_talker") ) )
  195. {
  196. return static_cast< CFlexExpresser * >(pEntity);
  197. }
  198. }
  199. AssertMsg1( pEntity == NULL || dynamic_cast<CFlexExpresser *>(pEntity) == NULL, "%s subclasses prop_talker; update CFlexExpresser::AsFlexExpresser\n",
  200. pEntity->GetClassname() );
  201. return NULL;
  202. }
  203. BEGIN_DATADESC( CFlexExpresser )
  204. DEFINE_INPUTFUNC( FIELD_STRING, "SpeakResponseConcept", InputSpeakResponseConcept ),
  205. DEFINE_KEYFIELD( m_flThenAnyMaxDist, FIELD_FLOAT, "maxThenAnyDispatchDist" ),
  206. END_DATADESC()
  207. LINK_ENTITY_TO_CLASS( prop_talker , CFlexExpresser );