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.

541 lines
18 KiB

  1. // NextBotEventResponderInterface.h
  2. // Interface for propagating and responding to events
  3. // Author: Michael Booth, May 2006
  4. // Copyright (c) 2006 Turtle Rock Studios, Inc. - All Rights Reserved
  5. #ifndef _NEXT_BOT_EVENT_RESPONDER_INTERFACE_H_
  6. #define _NEXT_BOT_EVENT_RESPONDER_INTERFACE_H_
  7. class Path;
  8. class CTakeDamageInfo;
  9. class CBaseEntity;
  10. class CDOTABaseAbility;
  11. struct CSoundParameters;
  12. struct animevent_t;
  13. #include "ai_speech.h"
  14. //--------------------------------------------------------------------------------------------------------------------------
  15. enum MoveToFailureType
  16. {
  17. FAIL_NO_PATH_EXISTS,
  18. FAIL_STUCK,
  19. FAIL_FELL_OFF,
  20. };
  21. //--------------------------------------------------------------------------------------------------------------------------
  22. /**
  23. * Events propagated to/between components.
  24. * To add an event, add its signature here and implement its propagation
  25. * to derived classes via FirstContainedResponder() and NextContainedResponder().
  26. * NOTE: Also add a translator to the Action class in NextBotBehavior.h.
  27. */
  28. class INextBotEventResponder
  29. {
  30. public:
  31. DECLARE_CLASS_NOBASE( INextBotEventResponder );
  32. virtual ~INextBotEventResponder() { }
  33. // these methods are used by derived classes to define how events propagate
  34. virtual INextBotEventResponder *FirstContainedResponder( void ) const { return NULL; }
  35. virtual INextBotEventResponder *NextContainedResponder( INextBotEventResponder *current ) const { return NULL; }
  36. //
  37. // Events. All events must be 'extended' by calling the derived class explicitly to ensure propagation.
  38. // Each event must implement its propagation in this interface class.
  39. //
  40. virtual void OnLeaveGround( CBaseEntity *ground ); // invoked when bot leaves ground for any reason
  41. virtual void OnLandOnGround( CBaseEntity *ground ); // invoked when bot lands on the ground after being in the air
  42. virtual void OnContact( CBaseEntity *other, CGameTrace *result = NULL ); // invoked when bot touches 'other'
  43. virtual void OnMoveToSuccess( const Path *path ); // invoked when a bot reaches the end of the given Path
  44. virtual void OnMoveToFailure( const Path *path, MoveToFailureType reason ); // invoked when a bot fails to reach the end of the given Path
  45. virtual void OnStuck( void ); // invoked when bot becomes stuck while trying to move
  46. virtual void OnUnStuck( void ); // invoked when a previously stuck bot becomes un-stuck and can again move
  47. virtual void OnPostureChanged( void ); // when bot has assumed new posture (query IBody for posture)
  48. virtual void OnAnimationActivityComplete( int activity ); // when animation activity has finished playing
  49. virtual void OnAnimationActivityInterrupted( int activity );// when animation activity was replaced by another animation
  50. virtual void OnAnimationEvent( animevent_t *event ); // when a QC-file animation event is triggered by the current animation sequence
  51. virtual void OnIgnite( void ); // when bot starts to burn
  52. virtual void OnInjured( const CTakeDamageInfo &info ); // when bot is damaged by something
  53. virtual void OnKilled( const CTakeDamageInfo &info ); // when the bot's health reaches zero
  54. virtual void OnOtherKilled( CBaseCombatCharacter *victim, const CTakeDamageInfo &info ); // when someone else dies
  55. virtual void OnSight( CBaseEntity *subject ); // when subject initially enters bot's visual awareness
  56. virtual void OnLostSight( CBaseEntity *subject ); // when subject leaves enters bot's visual awareness
  57. virtual void OnSound( CBaseEntity *source, const Vector &pos, KeyValues *keys ); // when an entity emits a sound. "pos" is world coordinates of sound. "keys" are from sound's GameData
  58. virtual void OnSpokeConcept( CBaseCombatCharacter *who, AIConcept_t concept, AI_Response *response ); // when an Actor speaks a concept
  59. virtual void OnWeaponFired( CBaseCombatCharacter *whoFired, CBaseCombatWeapon *weapon ); // when someone fires a weapon
  60. virtual void OnNavAreaChanged( CNavArea *newArea, CNavArea *oldArea ); // when bot enters a new navigation area
  61. virtual void OnModelChanged( void ); // when the entity's model has been changed
  62. virtual void OnPickUp( CBaseEntity *item, CBaseCombatCharacter *giver ); // when something is added to our inventory
  63. virtual void OnDrop( CBaseEntity *item ); // when something is removed from our inventory
  64. virtual void OnCommandAttack( CBaseEntity *victim ); // attack the given entity
  65. virtual void OnCommandApproach( const Vector &pos, float range = 0.0f ); // move to within range of the given position
  66. virtual void OnCommandApproach( CBaseEntity *goal ); // follow the given leader
  67. virtual void OnCommandRetreat( CBaseEntity *threat, float range = 0.0f ); // retreat from the threat at least range units away (0 == infinite)
  68. virtual void OnCommandPause( float duration = 0.0f ); // pause for the given duration (0 == forever)
  69. virtual void OnCommandResume( void ); // resume after a pause
  70. virtual void OnCommandString( const char *command ); // for debugging: respond to an arbitrary string representing a generalized command
  71. virtual void OnShoved( CBaseEntity *pusher ); // 'pusher' has shoved me
  72. virtual void OnBlinded( CBaseEntity *blinder ); // 'blinder' has blinded me with a flash of light
  73. virtual void OnTerritoryContested( int territoryID ); // territory has been invaded and is changing ownership
  74. virtual void OnTerritoryCaptured( int territoryID ); // we have captured enemy territory
  75. virtual void OnTerritoryLost( int territoryID ); // we have lost territory to the enemy
  76. virtual void OnWin( void );
  77. virtual void OnLose( void );
  78. #ifdef DOTA_SERVER_DLL
  79. virtual void OnCommandMoveTo( const Vector &pos );
  80. virtual void OnCommandMoveToAggressive( const Vector &pos );
  81. virtual void OnCommandAttack( CBaseEntity *victim, bool bDeny );
  82. virtual void OnCastAbilityNoTarget( CDOTABaseAbility *ability );
  83. virtual void OnCastAbilityOnPosition( CDOTABaseAbility *ability, const Vector &pos );
  84. virtual void OnCastAbilityOnTarget( CDOTABaseAbility *ability, CBaseEntity *target );
  85. virtual void OnDropItem( const Vector &pos, CBaseEntity *item );
  86. virtual void OnPickupItem( CBaseEntity *item );
  87. virtual void OnPickupRune( CBaseEntity *item );
  88. virtual void OnStop();
  89. virtual void OnFriendThreatened( CBaseEntity *friendly, CBaseEntity *threat );
  90. virtual void OnCancelAttack( CBaseEntity *pTarget );
  91. virtual void OnDominated();
  92. virtual void OnWarped( Vector vStartPos );
  93. #endif
  94. };
  95. inline void INextBotEventResponder::OnLeaveGround( CBaseEntity *ground )
  96. {
  97. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  98. {
  99. sub->OnLeaveGround( ground );
  100. }
  101. }
  102. inline void INextBotEventResponder::OnLandOnGround( CBaseEntity *ground )
  103. {
  104. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  105. {
  106. sub->OnLandOnGround( ground );
  107. }
  108. }
  109. inline void INextBotEventResponder::OnContact( CBaseEntity *other, CGameTrace *result )
  110. {
  111. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  112. {
  113. sub->OnContact( other, result );
  114. }
  115. }
  116. inline void INextBotEventResponder::OnMoveToSuccess( const Path *path )
  117. {
  118. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  119. {
  120. sub->OnMoveToSuccess( path );
  121. }
  122. }
  123. inline void INextBotEventResponder::OnMoveToFailure( const Path *path, MoveToFailureType reason )
  124. {
  125. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  126. {
  127. sub->OnMoveToFailure( path, reason );
  128. }
  129. }
  130. inline void INextBotEventResponder::OnStuck( void )
  131. {
  132. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  133. {
  134. sub->OnStuck();
  135. }
  136. }
  137. inline void INextBotEventResponder::OnUnStuck( void )
  138. {
  139. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  140. {
  141. sub->OnUnStuck();
  142. }
  143. }
  144. inline void INextBotEventResponder::OnPostureChanged( void )
  145. {
  146. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  147. {
  148. sub->OnPostureChanged();
  149. }
  150. }
  151. inline void INextBotEventResponder::OnAnimationActivityComplete( int activity )
  152. {
  153. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  154. {
  155. sub->OnAnimationActivityComplete( activity );
  156. }
  157. }
  158. inline void INextBotEventResponder::OnAnimationActivityInterrupted( int activity )
  159. {
  160. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  161. {
  162. sub->OnAnimationActivityInterrupted( activity );
  163. }
  164. }
  165. inline void INextBotEventResponder::OnAnimationEvent( animevent_t *event )
  166. {
  167. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  168. {
  169. sub->OnAnimationEvent( event );
  170. }
  171. }
  172. inline void INextBotEventResponder::OnIgnite( void )
  173. {
  174. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  175. {
  176. sub->OnIgnite();
  177. }
  178. }
  179. inline void INextBotEventResponder::OnInjured( const CTakeDamageInfo &info )
  180. {
  181. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  182. {
  183. sub->OnInjured( info );
  184. }
  185. }
  186. inline void INextBotEventResponder::OnKilled( const CTakeDamageInfo &info )
  187. {
  188. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  189. {
  190. sub->OnKilled( info );
  191. }
  192. }
  193. inline void INextBotEventResponder::OnOtherKilled( CBaseCombatCharacter *victim, const CTakeDamageInfo &info )
  194. {
  195. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  196. {
  197. sub->OnOtherKilled( victim, info );
  198. }
  199. }
  200. inline void INextBotEventResponder::OnSight( CBaseEntity *subject )
  201. {
  202. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  203. {
  204. sub->OnSight( subject );
  205. }
  206. }
  207. inline void INextBotEventResponder::OnLostSight( CBaseEntity *subject )
  208. {
  209. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  210. {
  211. sub->OnLostSight( subject );
  212. }
  213. }
  214. inline void INextBotEventResponder::OnSound( CBaseEntity *source, const Vector &pos, KeyValues *keys )
  215. {
  216. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  217. {
  218. sub->OnSound( source, pos, keys );
  219. }
  220. }
  221. inline void INextBotEventResponder::OnSpokeConcept( CBaseCombatCharacter *who, AIConcept_t concept, AI_Response *response )
  222. {
  223. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  224. {
  225. sub->OnSpokeConcept( who, concept, response );
  226. }
  227. }
  228. inline void INextBotEventResponder::OnWeaponFired( CBaseCombatCharacter *whoFired, CBaseCombatWeapon *weapon )
  229. {
  230. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  231. {
  232. sub->OnWeaponFired( whoFired, weapon );
  233. }
  234. }
  235. inline void INextBotEventResponder::OnNavAreaChanged( CNavArea *newArea, CNavArea *oldArea )
  236. {
  237. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  238. {
  239. sub->OnNavAreaChanged( newArea, oldArea );
  240. }
  241. }
  242. inline void INextBotEventResponder::OnModelChanged( void )
  243. {
  244. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  245. {
  246. sub->OnModelChanged();
  247. }
  248. }
  249. inline void INextBotEventResponder::OnPickUp( CBaseEntity *item, CBaseCombatCharacter *giver )
  250. {
  251. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  252. {
  253. sub->OnPickUp( item, giver );
  254. }
  255. }
  256. inline void INextBotEventResponder::OnDrop( CBaseEntity *item )
  257. {
  258. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  259. {
  260. sub->OnDrop( item );
  261. }
  262. }
  263. inline void INextBotEventResponder::OnShoved( CBaseEntity *pusher )
  264. {
  265. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  266. {
  267. sub->OnShoved( pusher );
  268. }
  269. }
  270. inline void INextBotEventResponder::OnBlinded( CBaseEntity *blinder )
  271. {
  272. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  273. {
  274. sub->OnBlinded( blinder );
  275. }
  276. }
  277. inline void INextBotEventResponder::OnCommandAttack( CBaseEntity *victim )
  278. {
  279. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  280. {
  281. sub->OnCommandAttack( victim );
  282. }
  283. }
  284. inline void INextBotEventResponder::OnCommandApproach( const Vector &pos, float range )
  285. {
  286. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  287. {
  288. sub->OnCommandApproach( pos, range );
  289. }
  290. }
  291. inline void INextBotEventResponder::OnCommandApproach( CBaseEntity *goal )
  292. {
  293. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  294. {
  295. sub->OnCommandApproach( goal );
  296. }
  297. }
  298. inline void INextBotEventResponder::OnCommandRetreat( CBaseEntity *threat, float range )
  299. {
  300. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  301. {
  302. sub->OnCommandRetreat( threat, range );
  303. }
  304. }
  305. inline void INextBotEventResponder::OnCommandPause( float duration )
  306. {
  307. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  308. {
  309. sub->OnCommandPause( duration );
  310. }
  311. }
  312. inline void INextBotEventResponder::OnCommandResume( void )
  313. {
  314. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  315. {
  316. sub->OnCommandResume();
  317. }
  318. }
  319. inline void INextBotEventResponder::OnCommandString( const char *command )
  320. {
  321. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  322. {
  323. sub->OnCommandString( command );
  324. }
  325. }
  326. inline void INextBotEventResponder::OnTerritoryContested( int territoryID )
  327. {
  328. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  329. {
  330. sub->OnTerritoryContested( territoryID );
  331. }
  332. }
  333. inline void INextBotEventResponder::OnTerritoryCaptured( int territoryID )
  334. {
  335. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  336. {
  337. sub->OnTerritoryCaptured( territoryID );
  338. }
  339. }
  340. inline void INextBotEventResponder::OnTerritoryLost( int territoryID )
  341. {
  342. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  343. {
  344. sub->OnTerritoryLost( territoryID );
  345. }
  346. }
  347. inline void INextBotEventResponder::OnWin( void )
  348. {
  349. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  350. {
  351. sub->OnWin();
  352. }
  353. }
  354. inline void INextBotEventResponder::OnLose( void )
  355. {
  356. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  357. {
  358. sub->OnLose();
  359. }
  360. }
  361. #ifdef DOTA_SERVER_DLL
  362. inline void INextBotEventResponder::OnCommandMoveTo( const Vector &pos )
  363. {
  364. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  365. {
  366. sub->OnCommandMoveTo( pos );
  367. }
  368. }
  369. inline void INextBotEventResponder::OnCommandMoveToAggressive( const Vector &pos )
  370. {
  371. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  372. {
  373. sub->OnCommandMoveToAggressive( pos );
  374. }
  375. }
  376. inline void INextBotEventResponder::OnCommandAttack( CBaseEntity *victim, bool bDeny )
  377. {
  378. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  379. {
  380. sub->OnCommandAttack( victim, bDeny );
  381. }
  382. }
  383. inline void INextBotEventResponder::OnCastAbilityNoTarget( CDOTABaseAbility *ability )
  384. {
  385. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  386. {
  387. sub->OnCastAbilityNoTarget( ability );
  388. }
  389. }
  390. inline void INextBotEventResponder::OnCastAbilityOnPosition( CDOTABaseAbility *ability, const Vector &pos )
  391. {
  392. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  393. {
  394. sub->OnCastAbilityOnPosition( ability, pos );
  395. }
  396. }
  397. inline void INextBotEventResponder::OnCastAbilityOnTarget( CDOTABaseAbility *ability, CBaseEntity *target )
  398. {
  399. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  400. {
  401. sub->OnCastAbilityOnTarget( ability, target );
  402. }
  403. }
  404. inline void INextBotEventResponder::OnDropItem( const Vector &pos, CBaseEntity *item )
  405. {
  406. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  407. {
  408. sub->OnDropItem( pos, item );
  409. }
  410. }
  411. inline void INextBotEventResponder::OnPickupItem( CBaseEntity *item )
  412. {
  413. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  414. {
  415. sub->OnPickupItem( item );
  416. }
  417. }
  418. inline void INextBotEventResponder::OnPickupRune( CBaseEntity *item )
  419. {
  420. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  421. {
  422. sub->OnPickupRune( item );
  423. }
  424. }
  425. inline void INextBotEventResponder::OnStop()
  426. {
  427. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  428. {
  429. sub->OnStop();
  430. }
  431. }
  432. inline void INextBotEventResponder::OnFriendThreatened( CBaseEntity *friendly, CBaseEntity *threat )
  433. {
  434. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  435. {
  436. sub->OnFriendThreatened( friendly, threat );
  437. }
  438. }
  439. inline void INextBotEventResponder::OnCancelAttack( CBaseEntity *pTarget )
  440. {
  441. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  442. {
  443. sub->OnCancelAttack( pTarget );
  444. }
  445. }
  446. inline void INextBotEventResponder::OnDominated()
  447. {
  448. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  449. {
  450. sub->OnDominated();
  451. }
  452. }
  453. inline void INextBotEventResponder::OnWarped( Vector vStartPos )
  454. {
  455. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  456. {
  457. sub->OnWarped( vStartPos );
  458. }
  459. }
  460. #endif
  461. #endif // _NEXT_BOT_EVENT_RESPONDER_INTERFACE_H_