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.

305 lines
10 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "eventlist.h"
  10. #include "stringregistry.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. // NOTE: If CStringRegistry allowed storing arbitrary data, we could just use that.
  14. // in this case we have the "isPrivate" member and the replacement rules
  15. // (eventIndex can be reused by private activities), so a custom table is necessary
  16. struct eventlist_t
  17. {
  18. int eventIndex;
  19. int iType;
  20. unsigned short stringKey;
  21. short isPrivate;
  22. };
  23. CUtlVector<eventlist_t> g_EventList;
  24. // This stores the actual event names. Also, the string ID in the registry is simply an index
  25. // into the g_EventList array.
  26. CStringRegistry g_EventStrings;
  27. // this is just here to accelerate adds
  28. static int g_HighestEvent = 0;
  29. int g_nEventListVersion = 1;
  30. void EventList_Init( void )
  31. {
  32. g_HighestEvent = 0;
  33. }
  34. void EventList_Free( void )
  35. {
  36. g_EventStrings.ClearStrings();
  37. g_EventList.Purge();
  38. // So studiohdrs can reindex event indices
  39. ++g_nEventListVersion;
  40. }
  41. // add a new event to the database
  42. eventlist_t *EventList_AddEventEntry( const char *pName, int iEventIndex, bool isPrivate, int iType )
  43. {
  44. MEM_ALLOC_CREDIT();
  45. int index = g_EventList.AddToTail();
  46. eventlist_t *pList = &g_EventList[index];
  47. pList->eventIndex = iEventIndex;
  48. pList->stringKey = g_EventStrings.AddString( pName, index );
  49. pList->isPrivate = isPrivate;
  50. pList->iType = iType;
  51. // UNDONE: This implies that ALL shared activities are added before ANY custom activities
  52. // UNDONE: Segment these instead? It's a 32-bit int, how many activities do we need?
  53. if ( iEventIndex > g_HighestEvent )
  54. {
  55. g_HighestEvent = iEventIndex;
  56. }
  57. return pList;
  58. }
  59. // get the database entry from a string
  60. static eventlist_t *ListFromString( const char *pString )
  61. {
  62. // just use the string registry to do this search/map
  63. int stringID = g_EventStrings.GetStringID( pString );
  64. if ( stringID < 0 )
  65. return NULL;
  66. return &g_EventList[stringID];
  67. }
  68. // Get the database entry for an index
  69. static eventlist_t *ListFromEvent( int eventIndex )
  70. {
  71. // ugly linear search
  72. for ( int i = 0; i < g_EventList.Count(); i++ )
  73. {
  74. if ( g_EventList[i].eventIndex == eventIndex )
  75. {
  76. return &g_EventList[i];
  77. }
  78. }
  79. return NULL;
  80. }
  81. int EventList_GetEventType( int eventIndex )
  82. {
  83. eventlist_t *pEvent = ListFromEvent( eventIndex );
  84. if ( pEvent )
  85. {
  86. return pEvent->iType;
  87. }
  88. return -1;
  89. }
  90. bool EventList_RegisterSharedEvent( const char *pszEventName, int iEventIndex, int iType )
  91. {
  92. // UNDONE: Do we want to do these checks when not in developer mode? or maybe DEBUG only?
  93. // They really only matter when you change the list of code controlled activities. IDs
  94. // for content controlled activities never collide because they are generated.
  95. // first, check to make sure the slot we're asking for is free. It must be for
  96. // a shared event.
  97. eventlist_t *pList = ListFromString( pszEventName );
  98. if ( !pList )
  99. {
  100. pList = ListFromEvent( iEventIndex );
  101. }
  102. //Already in list.
  103. if ( pList )
  104. {
  105. return false;
  106. }
  107. // ----------------------------------------------------------------
  108. EventList_AddEventEntry( pszEventName, iEventIndex, false, iType );
  109. return true;
  110. }
  111. Animevent EventList_RegisterPrivateEvent( const char *pszEventName )
  112. {
  113. eventlist_t *pList = ListFromString( pszEventName );
  114. if ( pList )
  115. {
  116. // this activity is already in the list. If the activity we collided with is also private,
  117. // then the collision is OK. Otherwise, it's a bug.
  118. if ( pList->isPrivate )
  119. {
  120. return (Animevent)pList->eventIndex;
  121. }
  122. else
  123. {
  124. // this private activity collides with a shared activity. That is not allowed.
  125. Warning( "***\nShared<->Private Event collision!\n***\n" );
  126. Assert(0);
  127. return AE_INVALID;
  128. }
  129. }
  130. int iType = AE_TYPE_SERVER;
  131. #ifdef CLIENT_DLL
  132. iType = AE_TYPE_CLIENT;
  133. #endif
  134. pList = EventList_AddEventEntry( pszEventName, g_HighestEvent+1, true, iType );
  135. return (Animevent)pList->eventIndex;
  136. }
  137. // Get the index for a given Event name
  138. // Done at load time for all models
  139. int EventList_IndexForName( const char *pszEventName )
  140. {
  141. // this is a fast O(lgn) search (actually does 2 O(lgn) searches)
  142. eventlist_t *pList = ListFromString( pszEventName );
  143. if ( pList )
  144. {
  145. return pList->eventIndex;
  146. }
  147. return -1;
  148. }
  149. // Get the name for a given index
  150. // This should only be used in debug code, it does a linear search
  151. // But at least it only compares integers
  152. const char *EventList_NameForIndex( int eventIndex )
  153. {
  154. eventlist_t *pList = ListFromEvent( eventIndex );
  155. if ( pList )
  156. {
  157. return g_EventStrings.GetStringForKey( pList->stringKey );
  158. }
  159. return NULL;
  160. }
  161. void EventList_RegisterSharedEvents( void )
  162. {
  163. REGISTER_SHARED_ANIMEVENT( AE_EMPTY, AE_TYPE_SERVER );
  164. REGISTER_SHARED_ANIMEVENT( AE_NPC_LEFTFOOT, AE_TYPE_SERVER );
  165. REGISTER_SHARED_ANIMEVENT( AE_NPC_RIGHTFOOT, AE_TYPE_SERVER );
  166. REGISTER_SHARED_ANIMEVENT( AE_NPC_BODYDROP_LIGHT, AE_TYPE_SERVER );
  167. REGISTER_SHARED_ANIMEVENT( AE_NPC_BODYDROP_HEAVY, AE_TYPE_SERVER );
  168. REGISTER_SHARED_ANIMEVENT( AE_NPC_SWISHSOUND, AE_TYPE_SERVER );
  169. REGISTER_SHARED_ANIMEVENT( AE_NPC_180TURN, AE_TYPE_SERVER );
  170. REGISTER_SHARED_ANIMEVENT( AE_NPC_ITEM_PICKUP, AE_TYPE_SERVER );
  171. REGISTER_SHARED_ANIMEVENT( AE_NPC_WEAPON_DROP, AE_TYPE_SERVER );
  172. REGISTER_SHARED_ANIMEVENT( AE_NPC_WEAPON_SET_SEQUENCE_NAME, AE_TYPE_SERVER );
  173. REGISTER_SHARED_ANIMEVENT( AE_NPC_WEAPON_SET_SEQUENCE_NUMBER, AE_TYPE_SERVER );
  174. REGISTER_SHARED_ANIMEVENT( AE_NPC_WEAPON_SET_ACTIVITY, AE_TYPE_SERVER );
  175. REGISTER_SHARED_ANIMEVENT( AE_NPC_HOLSTER, AE_TYPE_SERVER );
  176. REGISTER_SHARED_ANIMEVENT( AE_NPC_DRAW, AE_TYPE_SERVER );
  177. REGISTER_SHARED_ANIMEVENT( AE_NPC_WEAPON_FIRE, AE_TYPE_SERVER | AE_TYPE_WEAPON );
  178. REGISTER_SHARED_ANIMEVENT( AE_CL_PLAYSOUND, AE_TYPE_CLIENT );
  179. REGISTER_SHARED_ANIMEVENT( AE_SV_PLAYSOUND, AE_TYPE_SERVER );
  180. REGISTER_SHARED_ANIMEVENT( AE_CL_STOPSOUND, AE_TYPE_CLIENT );
  181. REGISTER_SHARED_ANIMEVENT( AE_START_SCRIPTED_EFFECT, AE_TYPE_SERVER );
  182. REGISTER_SHARED_ANIMEVENT( AE_STOP_SCRIPTED_EFFECT, AE_TYPE_SERVER );
  183. REGISTER_SHARED_ANIMEVENT( AE_CLIENT_EFFECT_ATTACH, AE_TYPE_CLIENT );
  184. REGISTER_SHARED_ANIMEVENT( AE_MUZZLEFLASH, AE_TYPE_CLIENT );
  185. REGISTER_SHARED_ANIMEVENT( AE_NPC_MUZZLEFLASH, AE_TYPE_CLIENT );
  186. REGISTER_SHARED_ANIMEVENT( AE_THUMPER_THUMP, AE_TYPE_SERVER );
  187. REGISTER_SHARED_ANIMEVENT( AE_AMMOCRATE_PICKUP_AMMO, AE_TYPE_SERVER );
  188. REGISTER_SHARED_ANIMEVENT( AE_NPC_RAGDOLL, AE_TYPE_SERVER );
  189. REGISTER_SHARED_ANIMEVENT( AE_NPC_ADDGESTURE, AE_TYPE_SERVER );
  190. REGISTER_SHARED_ANIMEVENT( AE_NPC_RESTARTGESTURE, AE_TYPE_SERVER );
  191. REGISTER_SHARED_ANIMEVENT( AE_NPC_ATTACK_BROADCAST, AE_TYPE_SERVER );
  192. REGISTER_SHARED_ANIMEVENT( AE_NPC_HURT_INTERACTION_PARTNER, AE_TYPE_SERVER );
  193. REGISTER_SHARED_ANIMEVENT( AE_NPC_SET_INTERACTION_CANTDIE, AE_TYPE_SERVER );
  194. REGISTER_SHARED_ANIMEVENT( AE_SV_DUSTTRAIL, AE_TYPE_SERVER );
  195. REGISTER_SHARED_ANIMEVENT( AE_CL_CREATE_PARTICLE_EFFECT, AE_TYPE_CLIENT );
  196. REGISTER_SHARED_ANIMEVENT( AE_CL_STOP_PARTICLE_EFFECT, AE_TYPE_CLIENT );
  197. REGISTER_SHARED_ANIMEVENT( AE_CL_ADD_PARTICLE_EFFECT_CP, AE_TYPE_CLIENT );
  198. REGISTER_SHARED_ANIMEVENT( AE_CL_CREATE_PARTICLE_BRASS, AE_TYPE_CLIENT );
  199. REGISTER_SHARED_ANIMEVENT( AE_RAGDOLL, AE_TYPE_SERVER );
  200. REGISTER_SHARED_ANIMEVENT( AE_CL_ENABLE_BODYGROUP, AE_TYPE_CLIENT );
  201. REGISTER_SHARED_ANIMEVENT( AE_CL_DISABLE_BODYGROUP, AE_TYPE_CLIENT );
  202. REGISTER_SHARED_ANIMEVENT( AE_CL_BODYGROUP_SET_VALUE, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  203. REGISTER_SHARED_ANIMEVENT( AE_CL_BODYGROUP_SET_VALUE_CMODEL_WPN, AE_TYPE_CLIENT );
  204. REGISTER_SHARED_ANIMEVENT( AE_CL_BODYGROUP_SET_TO_CLIP, AE_TYPE_SERVER );
  205. REGISTER_SHARED_ANIMEVENT( AE_CL_BODYGROUP_SET_TO_NEXTCLIP, AE_TYPE_SERVER );
  206. REGISTER_SHARED_ANIMEVENT( AE_CL_EJECT_MAG, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  207. REGISTER_SHARED_ANIMEVENT( AE_CL_EJECT_MAG_UNHIDE, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  208. REGISTER_SHARED_ANIMEVENT( AE_CL_SHOW_SILENCER, AE_TYPE_SERVER );
  209. REGISTER_SHARED_ANIMEVENT( AE_CL_ATTACH_SILENCER_COMPLETE, AE_TYPE_SERVER );
  210. REGISTER_SHARED_ANIMEVENT( AE_CL_HIDE_SILENCER, AE_TYPE_SERVER );
  211. REGISTER_SHARED_ANIMEVENT( AE_CL_DETACH_SILENCER_COMPLETE, AE_TYPE_SERVER );
  212. REGISTER_SHARED_ANIMEVENT( AE_WPN_PRIMARYATTACK, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  213. REGISTER_SHARED_ANIMEVENT( AE_WPN_INCREMENTAMMO, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  214. REGISTER_SHARED_ANIMEVENT( AE_WPN_HIDE, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  215. REGISTER_SHARED_ANIMEVENT( AE_WPN_UNHIDE, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  216. REGISTER_SHARED_ANIMEVENT( AE_ASW_FOOTSTEP, AE_TYPE_CLIENT );
  217. REGISTER_SHARED_ANIMEVENT( AE_MARINE_FOOTSTEP, AE_TYPE_CLIENT );
  218. REGISTER_SHARED_ANIMEVENT( AE_MARINE_RELOAD_SOUND_A, AE_TYPE_CLIENT );
  219. REGISTER_SHARED_ANIMEVENT( AE_MARINE_RELOAD_SOUND_B, AE_TYPE_CLIENT );
  220. REGISTER_SHARED_ANIMEVENT( AE_MARINE_RELOAD_SOUND_C, AE_TYPE_CLIENT );
  221. REGISTER_SHARED_ANIMEVENT( AE_REMOVE_CLIENT_AIM, AE_TYPE_CLIENT );
  222. REGISTER_SHARED_ANIMEVENT( AE_WPN_PLAYWPNSOUND, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  223. REGISTER_SHARED_ANIMEVENT( AE_WPN_COMPLETE_RELOAD, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  224. REGISTER_SHARED_ANIMEVENT( AE_MELEE_DAMAGE, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  225. REGISTER_SHARED_ANIMEVENT( AE_MELEE_START_COLLISION_DAMAGE, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  226. REGISTER_SHARED_ANIMEVENT( AE_MELEE_STOP_COLLISION_DAMAGE, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  227. REGISTER_SHARED_ANIMEVENT( AE_SCREEN_SHAKE, AE_TYPE_CLIENT );
  228. REGISTER_SHARED_ANIMEVENT( AE_START_DETECTING_COMBO, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  229. REGISTER_SHARED_ANIMEVENT( AE_STOP_DETECTING_COMBO, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  230. REGISTER_SHARED_ANIMEVENT( AE_COMBO_TRANSITION, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  231. REGISTER_SHARED_ANIMEVENT( AE_ALLOW_MOVEMENT, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  232. REGISTER_SHARED_ANIMEVENT( AE_SKILL_EVENT, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  233. REGISTER_SHARED_ANIMEVENT( AE_TUG_INCAP, AE_TYPE_SERVER );
  234. REGISTER_SHARED_ANIMEVENT( AE_BEGIN_TAUNT_LOOP, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  235. REGISTER_SHARED_ANIMEVENT( AE_CLIENT_EJECT_BRASS, AE_TYPE_CLIENT );
  236. REGISTER_SHARED_ANIMEVENT( AE_CL_SET_STATTRAK_GLOW, AE_TYPE_CLIENT );
  237. REGISTER_SHARED_ANIMEVENT( AE_WPN_CZ_DUMP_CURRENT_MAG, AE_TYPE_SERVER );
  238. REGISTER_SHARED_ANIMEVENT( AE_WPN_CZ_UPDATE_BODYGROUP, AE_TYPE_SERVER );
  239. REGISTER_SHARED_ANIMEVENT( AE_WPN_CLIP_TO_POSEPARAM, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  240. REGISTER_SHARED_ANIMEVENT( AE_WPN_NEXTCLIP_TO_POSEPARAM, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  241. REGISTER_SHARED_ANIMEVENT( AE_WPN_EMPTYSHOTS_TO_POSEPARAM, AE_TYPE_CLIENT | AE_TYPE_SERVER );
  242. }