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.

550 lines
18 KiB

  1. // NextBotEventResponderInterface.h
  2. // Interface for propagating and responding to events
  3. // Author: Michael Booth, May 2006
  4. //========= Copyright Valve Corporation, 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 OnActorEmoted( CBaseCombatCharacter *emoter, int emote ); // when "emoter" does an "emote" (ie: manual voice command, etc)
  65. virtual void OnCommandAttack( CBaseEntity *victim ); // attack the given entity
  66. virtual void OnCommandApproach( const Vector &pos, float range = 0.0f ); // move to within range of the given position
  67. virtual void OnCommandApproach( CBaseEntity *goal ); // follow the given leader
  68. virtual void OnCommandRetreat( CBaseEntity *threat, float range = 0.0f ); // retreat from the threat at least range units away (0 == infinite)
  69. virtual void OnCommandPause( float duration = 0.0f ); // pause for the given duration (0 == forever)
  70. virtual void OnCommandResume( void ); // resume after a pause
  71. virtual void OnCommandString( const char *command ); // for debugging: respond to an arbitrary string representing a generalized command
  72. virtual void OnShoved( CBaseEntity *pusher ); // 'pusher' has shoved me
  73. virtual void OnBlinded( CBaseEntity *blinder ); // 'blinder' has blinded me with a flash of light
  74. virtual void OnTerritoryContested( int territoryID ); // territory has been invaded and is changing ownership
  75. virtual void OnTerritoryCaptured( int territoryID ); // we have captured enemy territory
  76. virtual void OnTerritoryLost( int territoryID ); // we have lost territory to the enemy
  77. virtual void OnWin( void );
  78. virtual void OnLose( void );
  79. #ifdef DOTA_SERVER_DLL
  80. virtual void OnCommandMoveTo( const Vector &pos );
  81. virtual void OnCommandMoveToAggressive( const Vector &pos );
  82. virtual void OnCommandAttack( CBaseEntity *victim, bool bDeny );
  83. virtual void OnCastAbilityNoTarget( CDOTABaseAbility *ability );
  84. virtual void OnCastAbilityOnPosition( CDOTABaseAbility *ability, const Vector &pos );
  85. virtual void OnCastAbilityOnTarget( CDOTABaseAbility *ability, CBaseEntity *target );
  86. virtual void OnDropItem( const Vector &pos, CBaseEntity *item );
  87. virtual void OnPickupItem( CBaseEntity *item );
  88. virtual void OnPickupRune( CBaseEntity *item );
  89. virtual void OnStop();
  90. virtual void OnFriendThreatened( CBaseEntity *friendly, CBaseEntity *threat );
  91. virtual void OnCancelAttack( CBaseEntity *pTarget );
  92. virtual void OnDominated();
  93. virtual void OnWarped( Vector vStartPos );
  94. #endif
  95. };
  96. inline void INextBotEventResponder::OnLeaveGround( CBaseEntity *ground )
  97. {
  98. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  99. {
  100. sub->OnLeaveGround( ground );
  101. }
  102. }
  103. inline void INextBotEventResponder::OnLandOnGround( CBaseEntity *ground )
  104. {
  105. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  106. {
  107. sub->OnLandOnGround( ground );
  108. }
  109. }
  110. inline void INextBotEventResponder::OnContact( CBaseEntity *other, CGameTrace *result )
  111. {
  112. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  113. {
  114. sub->OnContact( other, result );
  115. }
  116. }
  117. inline void INextBotEventResponder::OnMoveToSuccess( const Path *path )
  118. {
  119. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  120. {
  121. sub->OnMoveToSuccess( path );
  122. }
  123. }
  124. inline void INextBotEventResponder::OnMoveToFailure( const Path *path, MoveToFailureType reason )
  125. {
  126. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  127. {
  128. sub->OnMoveToFailure( path, reason );
  129. }
  130. }
  131. inline void INextBotEventResponder::OnStuck( void )
  132. {
  133. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  134. {
  135. sub->OnStuck();
  136. }
  137. }
  138. inline void INextBotEventResponder::OnUnStuck( void )
  139. {
  140. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  141. {
  142. sub->OnUnStuck();
  143. }
  144. }
  145. inline void INextBotEventResponder::OnPostureChanged( void )
  146. {
  147. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  148. {
  149. sub->OnPostureChanged();
  150. }
  151. }
  152. inline void INextBotEventResponder::OnAnimationActivityComplete( int activity )
  153. {
  154. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  155. {
  156. sub->OnAnimationActivityComplete( activity );
  157. }
  158. }
  159. inline void INextBotEventResponder::OnAnimationActivityInterrupted( int activity )
  160. {
  161. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  162. {
  163. sub->OnAnimationActivityInterrupted( activity );
  164. }
  165. }
  166. inline void INextBotEventResponder::OnAnimationEvent( animevent_t *event )
  167. {
  168. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  169. {
  170. sub->OnAnimationEvent( event );
  171. }
  172. }
  173. inline void INextBotEventResponder::OnIgnite( void )
  174. {
  175. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  176. {
  177. sub->OnIgnite();
  178. }
  179. }
  180. inline void INextBotEventResponder::OnInjured( const CTakeDamageInfo &info )
  181. {
  182. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  183. {
  184. sub->OnInjured( info );
  185. }
  186. }
  187. inline void INextBotEventResponder::OnKilled( const CTakeDamageInfo &info )
  188. {
  189. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  190. {
  191. sub->OnKilled( info );
  192. }
  193. }
  194. inline void INextBotEventResponder::OnOtherKilled( CBaseCombatCharacter *victim, const CTakeDamageInfo &info )
  195. {
  196. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  197. {
  198. sub->OnOtherKilled( victim, info );
  199. }
  200. }
  201. inline void INextBotEventResponder::OnSight( CBaseEntity *subject )
  202. {
  203. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  204. {
  205. sub->OnSight( subject );
  206. }
  207. }
  208. inline void INextBotEventResponder::OnLostSight( CBaseEntity *subject )
  209. {
  210. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  211. {
  212. sub->OnLostSight( subject );
  213. }
  214. }
  215. inline void INextBotEventResponder::OnSound( CBaseEntity *source, const Vector &pos, KeyValues *keys )
  216. {
  217. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  218. {
  219. sub->OnSound( source, pos, keys );
  220. }
  221. }
  222. inline void INextBotEventResponder::OnSpokeConcept( CBaseCombatCharacter *who, AIConcept_t concept, AI_Response *response )
  223. {
  224. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  225. {
  226. sub->OnSpokeConcept( who, concept, response );
  227. }
  228. }
  229. inline void INextBotEventResponder::OnWeaponFired( CBaseCombatCharacter *whoFired, CBaseCombatWeapon *weapon )
  230. {
  231. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  232. {
  233. sub->OnWeaponFired( whoFired, weapon );
  234. }
  235. }
  236. inline void INextBotEventResponder::OnNavAreaChanged( CNavArea *newArea, CNavArea *oldArea )
  237. {
  238. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  239. {
  240. sub->OnNavAreaChanged( newArea, oldArea );
  241. }
  242. }
  243. inline void INextBotEventResponder::OnModelChanged( void )
  244. {
  245. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  246. {
  247. sub->OnModelChanged();
  248. }
  249. }
  250. inline void INextBotEventResponder::OnPickUp( CBaseEntity *item, CBaseCombatCharacter *giver )
  251. {
  252. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  253. {
  254. sub->OnPickUp( item, giver );
  255. }
  256. }
  257. inline void INextBotEventResponder::OnDrop( CBaseEntity *item )
  258. {
  259. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  260. {
  261. sub->OnDrop( item );
  262. }
  263. }
  264. inline void INextBotEventResponder::OnActorEmoted( CBaseCombatCharacter *emoter, int emote )
  265. {
  266. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  267. {
  268. sub->OnActorEmoted( emoter, emote );
  269. }
  270. }
  271. inline void INextBotEventResponder::OnShoved( CBaseEntity *pusher )
  272. {
  273. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  274. {
  275. sub->OnShoved( pusher );
  276. }
  277. }
  278. inline void INextBotEventResponder::OnBlinded( CBaseEntity *blinder )
  279. {
  280. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  281. {
  282. sub->OnBlinded( blinder );
  283. }
  284. }
  285. inline void INextBotEventResponder::OnCommandAttack( CBaseEntity *victim )
  286. {
  287. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  288. {
  289. sub->OnCommandAttack( victim );
  290. }
  291. }
  292. inline void INextBotEventResponder::OnCommandApproach( const Vector &pos, float range )
  293. {
  294. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  295. {
  296. sub->OnCommandApproach( pos, range );
  297. }
  298. }
  299. inline void INextBotEventResponder::OnCommandApproach( CBaseEntity *goal )
  300. {
  301. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  302. {
  303. sub->OnCommandApproach( goal );
  304. }
  305. }
  306. inline void INextBotEventResponder::OnCommandRetreat( CBaseEntity *threat, float range )
  307. {
  308. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  309. {
  310. sub->OnCommandRetreat( threat, range );
  311. }
  312. }
  313. inline void INextBotEventResponder::OnCommandPause( float duration )
  314. {
  315. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  316. {
  317. sub->OnCommandPause( duration );
  318. }
  319. }
  320. inline void INextBotEventResponder::OnCommandResume( void )
  321. {
  322. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  323. {
  324. sub->OnCommandResume();
  325. }
  326. }
  327. inline void INextBotEventResponder::OnCommandString( const char *command )
  328. {
  329. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  330. {
  331. sub->OnCommandString( command );
  332. }
  333. }
  334. inline void INextBotEventResponder::OnTerritoryContested( int territoryID )
  335. {
  336. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  337. {
  338. sub->OnTerritoryContested( territoryID );
  339. }
  340. }
  341. inline void INextBotEventResponder::OnTerritoryCaptured( int territoryID )
  342. {
  343. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  344. {
  345. sub->OnTerritoryCaptured( territoryID );
  346. }
  347. }
  348. inline void INextBotEventResponder::OnTerritoryLost( int territoryID )
  349. {
  350. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  351. {
  352. sub->OnTerritoryLost( territoryID );
  353. }
  354. }
  355. inline void INextBotEventResponder::OnWin( void )
  356. {
  357. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  358. {
  359. sub->OnWin();
  360. }
  361. }
  362. inline void INextBotEventResponder::OnLose( void )
  363. {
  364. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  365. {
  366. sub->OnLose();
  367. }
  368. }
  369. #ifdef DOTA_SERVER_DLL
  370. inline void INextBotEventResponder::OnCommandMoveTo( const Vector &pos )
  371. {
  372. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  373. {
  374. sub->OnCommandMoveTo( pos );
  375. }
  376. }
  377. inline void INextBotEventResponder::OnCommandMoveToAggressive( const Vector &pos )
  378. {
  379. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  380. {
  381. sub->OnCommandMoveToAggressive( pos );
  382. }
  383. }
  384. inline void INextBotEventResponder::OnCommandAttack( CBaseEntity *victim, bool bDeny )
  385. {
  386. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  387. {
  388. sub->OnCommandAttack( victim, bDeny );
  389. }
  390. }
  391. inline void INextBotEventResponder::OnCastAbilityNoTarget( CDOTABaseAbility *ability )
  392. {
  393. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  394. {
  395. sub->OnCastAbilityNoTarget( ability );
  396. }
  397. }
  398. inline void INextBotEventResponder::OnCastAbilityOnPosition( CDOTABaseAbility *ability, const Vector &pos )
  399. {
  400. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  401. {
  402. sub->OnCastAbilityOnPosition( ability, pos );
  403. }
  404. }
  405. inline void INextBotEventResponder::OnCastAbilityOnTarget( CDOTABaseAbility *ability, CBaseEntity *target )
  406. {
  407. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  408. {
  409. sub->OnCastAbilityOnTarget( ability, target );
  410. }
  411. }
  412. inline void INextBotEventResponder::OnDropItem( const Vector &pos, CBaseEntity *item )
  413. {
  414. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  415. {
  416. sub->OnDropItem( pos, item );
  417. }
  418. }
  419. inline void INextBotEventResponder::OnPickupItem( CBaseEntity *item )
  420. {
  421. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  422. {
  423. sub->OnPickupItem( item );
  424. }
  425. }
  426. inline void INextBotEventResponder::OnPickupRune( CBaseEntity *item )
  427. {
  428. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  429. {
  430. sub->OnPickupRune( item );
  431. }
  432. }
  433. inline void INextBotEventResponder::OnStop()
  434. {
  435. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  436. {
  437. sub->OnStop();
  438. }
  439. }
  440. inline void INextBotEventResponder::OnFriendThreatened( CBaseEntity *friendly, CBaseEntity *threat )
  441. {
  442. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  443. {
  444. sub->OnFriendThreatened( friendly, threat );
  445. }
  446. }
  447. inline void INextBotEventResponder::OnCancelAttack( CBaseEntity *pTarget )
  448. {
  449. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  450. {
  451. sub->OnCancelAttack( pTarget );
  452. }
  453. }
  454. inline void INextBotEventResponder::OnDominated()
  455. {
  456. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  457. {
  458. sub->OnDominated();
  459. }
  460. }
  461. inline void INextBotEventResponder::OnWarped( Vector vStartPos )
  462. {
  463. for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
  464. {
  465. sub->OnWarped( vStartPos );
  466. }
  467. }
  468. #endif
  469. #endif // _NEXT_BOT_EVENT_RESPONDER_INTERFACE_H_