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.

504 lines
13 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Defines the tasks for default AI.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef AI_TASK_H
  8. #define AI_TASK_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. class CStringRegistry;
  13. // ----------------------------------------------------------------------
  14. // Failure messages
  15. //
  16. // UNDONE: do this diffently so when not in developer mode we can
  17. // not use any memory for these text strings
  18. // ----------------------------------------------------------------------
  19. // Codes are either one of the enumerated types below, or a string (similar to Windows resource IDs)
  20. typedef int AI_TaskFailureCode_t;
  21. enum AI_BaseTaskFailureCodes_t
  22. {
  23. NO_TASK_FAILURE,
  24. FAIL_NO_TARGET,
  25. FAIL_WEAPON_OWNED,
  26. FAIL_ITEM_NO_FIND,
  27. FAIL_NO_HINT_NODE,
  28. FAIL_SCHEDULE_NOT_FOUND,
  29. FAIL_NO_ENEMY,
  30. FAIL_NO_BACKAWAY_NODE,
  31. FAIL_NO_COVER,
  32. FAIL_NO_FLANK,
  33. FAIL_NO_SHOOT,
  34. FAIL_NO_ROUTE,
  35. FAIL_NO_ROUTE_GOAL,
  36. FAIL_NO_ROUTE_BLOCKED,
  37. FAIL_NO_ROUTE_ILLEGAL,
  38. FAIL_NO_WALK,
  39. FAIL_ALREADY_LOCKED,
  40. FAIL_NO_SOUND,
  41. FAIL_NO_SCENT,
  42. FAIL_BAD_ACTIVITY,
  43. FAIL_NO_GOAL,
  44. FAIL_NO_PLAYER,
  45. FAIL_NO_REACHABLE_NODE,
  46. FAIL_NO_AI_NETWORK,
  47. FAIL_BAD_POSITION,
  48. FAIL_BAD_PATH_GOAL,
  49. FAIL_STUCK_ONTOP,
  50. FAIL_ITEM_TAKEN,
  51. NUM_FAIL_CODES,
  52. };
  53. inline bool IsPathTaskFailure( AI_TaskFailureCode_t code )
  54. {
  55. return ( code >= FAIL_NO_ROUTE && code <= FAIL_NO_ROUTE_ILLEGAL );
  56. }
  57. const char *TaskFailureToString( AI_TaskFailureCode_t code );
  58. inline int MakeFailCode( const char *pszGeneralError ) { return (int)pszGeneralError; }
  59. enum TaskStatus_e
  60. {
  61. TASKSTATUS_NEW = 0, // Just started
  62. TASKSTATUS_RUN_MOVE_AND_TASK = 1, // Running task & movement
  63. TASKSTATUS_RUN_MOVE = 2, // Just running movement
  64. TASKSTATUS_RUN_TASK = 3, // Just running task
  65. TASKSTATUS_COMPLETE = 4, // Completed, get next task
  66. };
  67. // an array of tasks is a task list
  68. // an array of schedules is a schedule list
  69. struct Task_t
  70. {
  71. int iTask;
  72. float flTaskData;
  73. };
  74. //=========================================================
  75. // These are the shared tasks
  76. //=========================================================
  77. enum sharedtasks_e
  78. {
  79. TASK_INVALID = 0,
  80. // Forces the activity to reset.
  81. TASK_RESET_ACTIVITY,
  82. // Waits for the specified number of seconds.
  83. TASK_WAIT,
  84. // Make announce attack sound
  85. TASK_ANNOUNCE_ATTACK,
  86. // Waits for the specified number of seconds. Will constantly turn to
  87. // face the enemy while waiting.
  88. TASK_WAIT_FACE_ENEMY,
  89. // Waits up to the specified number of seconds. Will constantly turn to
  90. // face the enemy while waiting.
  91. TASK_WAIT_FACE_ENEMY_RANDOM,
  92. // Wait until the player enters the same PVS as this character.
  93. TASK_WAIT_PVS,
  94. // DON'T use this, it needs to go away.
  95. TASK_SUGGEST_STATE,
  96. // Set m_hTargetEnt to nearest player
  97. TASK_TARGET_PLAYER,
  98. // Walk to m_hTargetEnt's location
  99. TASK_SCRIPT_WALK_TO_TARGET,
  100. // Run to m_hTargetEnt's location
  101. TASK_SCRIPT_RUN_TO_TARGET,
  102. // Move to m_hTargetEnt's location using the activity specified by m_hCine->m_iszCustomMove.
  103. TASK_SCRIPT_CUSTOM_MOVE_TO_TARGET,
  104. // Move to within specified range of m_hTargetEnt
  105. TASK_MOVE_TO_TARGET_RANGE,
  106. // Move to within specified range of our nav goal
  107. TASK_MOVE_TO_GOAL_RANGE,
  108. // Path that moves the character a few steps forward of where it is.
  109. TASK_MOVE_AWAY_PATH,
  110. TASK_GET_PATH_AWAY_FROM_BEST_SOUND,
  111. // Set the implied goal for TASK_GET_PATH_TO_GOAL
  112. TASK_SET_GOAL,
  113. // Get the path to the goal specified by TASK_SET_GOAL
  114. TASK_GET_PATH_TO_GOAL,
  115. // Path to the enemy's location. Even if the enemy is unseen!
  116. TASK_GET_PATH_TO_ENEMY,
  117. // Path to the last place this character saw the enemy
  118. TASK_GET_PATH_TO_ENEMY_LKP,
  119. // Path to the enemy's location or path to a LOS with the enemy's last known position, depending on range
  120. TASK_GET_CHASE_PATH_TO_ENEMY,
  121. // Path to a LOS with the enemy's last known position
  122. TASK_GET_PATH_TO_ENEMY_LKP_LOS,
  123. // Path to the dead enemy's carcass.
  124. TASK_GET_PATH_TO_ENEMY_CORPSE,
  125. // Path to the player's origin
  126. TASK_GET_PATH_TO_PLAYER,
  127. // Path to node with line of sight to enemy
  128. TASK_GET_PATH_TO_ENEMY_LOS,
  129. // Path to node with line of sight to enemy, at least flTaskData units away from m_vSavePosition
  130. TASK_GET_FLANK_RADIUS_PATH_TO_ENEMY_LOS,
  131. // Path to node with line of sight to enemy, at least flTaskData degrees away from m_vSavePosition from the enemy's POV
  132. TASK_GET_FLANK_ARC_PATH_TO_ENEMY_LOS,
  133. // Path to the within shot range of last place this character saw the enemy
  134. TASK_GET_PATH_TO_RANGE_ENEMY_LKP_LOS,
  135. // Build a path to m_hTargetEnt
  136. TASK_GET_PATH_TO_TARGET,
  137. // Allow a little slop, and allow for some Z offset (like the target is a gun on a table).
  138. TASK_GET_PATH_TO_TARGET_WEAPON,
  139. TASK_CREATE_PENDING_WEAPON,
  140. // Path to nodes[ m_pHintNode ]
  141. TASK_GET_PATH_TO_HINTNODE,
  142. // Store current position for later reference
  143. TASK_STORE_LASTPOSITION,
  144. // Clear stored position
  145. TASK_CLEAR_LASTPOSITION,
  146. // Store current position for later reference
  147. TASK_STORE_POSITION_IN_SAVEPOSITION,
  148. // Store best sound position for later reference
  149. TASK_STORE_BESTSOUND_IN_SAVEPOSITION,
  150. TASK_STORE_BESTSOUND_REACTORIGIN_IN_SAVEPOSITION,
  151. TASK_REACT_TO_COMBAT_SOUND,
  152. // Store current enemy position in saveposition
  153. TASK_STORE_ENEMY_POSITION_IN_SAVEPOSITION,
  154. // Move to the goal specified by the player in command mode.
  155. TASK_GET_PATH_TO_COMMAND_GOAL,
  156. TASK_MARK_COMMAND_GOAL_POS,
  157. TASK_CLEAR_COMMAND_GOAL,
  158. // Path to last position (Last position must be stored with TASK_STORE_LAST_POSITION)
  159. TASK_GET_PATH_TO_LASTPOSITION,
  160. // Path to saved position (Save position must by set in code or by a task)
  161. TASK_GET_PATH_TO_SAVEPOSITION,
  162. // Path to location that has line of sight to saved position (Save position must by set in code or by a task)
  163. TASK_GET_PATH_TO_SAVEPOSITION_LOS,
  164. // Path to random node
  165. TASK_GET_PATH_TO_RANDOM_NODE,
  166. // Path to source of loudest heard sound that I care about
  167. TASK_GET_PATH_TO_BESTSOUND,
  168. // Path to source of the strongest scend that I care about
  169. TASK_GET_PATH_TO_BESTSCENT,
  170. // Run the current path
  171. TASK_RUN_PATH,
  172. // Walk the current path
  173. TASK_WALK_PATH,
  174. // Walk the current path for a specified number of seconds
  175. TASK_WALK_PATH_TIMED,
  176. // Walk the current path until you are x units from the goal.
  177. TASK_WALK_PATH_WITHIN_DIST,
  178. // Walk the current path until for x units
  179. TASK_WALK_PATH_FOR_UNITS,
  180. // Rung the current path until you are x units from the goal.
  181. TASK_RUN_PATH_FLEE,
  182. // Run the current path for a specified number of seconds
  183. TASK_RUN_PATH_TIMED,
  184. // Run the current path until for x units
  185. TASK_RUN_PATH_FOR_UNITS,
  186. // Run the current path until you are x units from the goal.
  187. TASK_RUN_PATH_WITHIN_DIST,
  188. // Walk the current path sideways (must be supported by animation)
  189. TASK_STRAFE_PATH,
  190. // Clear m_flMoveWaitFinished (timer that inhibits movement)
  191. TASK_CLEAR_MOVE_WAIT,
  192. // Decide on the appropriate small flinch animation, and play it.
  193. TASK_SMALL_FLINCH,
  194. // Decide on the appropriate big flinch animation, and play it.
  195. TASK_BIG_FLINCH,
  196. // Prevent dodging for a certain amount of time.
  197. TASK_DEFER_DODGE,
  198. // Turn to face ideal yaw
  199. TASK_FACE_IDEAL,
  200. // Find an interesting direction to face. Don't face into walls, corners if you can help it.
  201. TASK_FACE_REASONABLE,
  202. // Turn to face the way I should walk or run
  203. TASK_FACE_PATH,
  204. // Turn to face a player
  205. TASK_FACE_PLAYER,
  206. // Turn to face the enemy
  207. TASK_FACE_ENEMY,
  208. // Turn to face nodes[ m_pHintNode ]
  209. TASK_FACE_HINTNODE,
  210. // Play activity associate with the current hint
  211. TASK_PLAY_HINT_ACTIVITY,
  212. // Turn to face m_hTargetEnt
  213. TASK_FACE_TARGET,
  214. // Turn to face stored last position (last position must be stored first!)
  215. TASK_FACE_LASTPOSITION,
  216. // Turn to face stored save position (save position must be stored first!)
  217. TASK_FACE_SAVEPOSITION,
  218. // Turn to face directly away from stored save position (save position must be stored first!)
  219. TASK_FACE_AWAY_FROM_SAVEPOSITION,
  220. // Set the current facing to be the ideal
  221. TASK_SET_IDEAL_YAW_TO_CURRENT,
  222. // Attack the enemy (should be facing the enemy)
  223. TASK_RANGE_ATTACK1,
  224. TASK_RANGE_ATTACK2,
  225. TASK_MELEE_ATTACK1,
  226. TASK_MELEE_ATTACK2,
  227. // Reload weapon
  228. TASK_RELOAD,
  229. // Execute special attack (user-defined)
  230. TASK_SPECIAL_ATTACK1,
  231. TASK_SPECIAL_ATTACK2,
  232. TASK_FIND_HINTNODE,
  233. TASK_FIND_LOCK_HINTNODE,
  234. TASK_CLEAR_HINTNODE,
  235. // Claim m_pHintNode exclusively for this NPC.
  236. TASK_LOCK_HINTNODE,
  237. // Emit an angry sound
  238. TASK_SOUND_ANGRY,
  239. // Emit a dying sound
  240. TASK_SOUND_DEATH,
  241. // Emit an idle sound
  242. TASK_SOUND_IDLE,
  243. // Emit a sound because you are pissed off because you just saw someone you don't like
  244. TASK_SOUND_WAKE,
  245. // Emit a pain sound
  246. TASK_SOUND_PAIN,
  247. // Emit a death sound
  248. TASK_SOUND_DIE,
  249. // Speak a sentence
  250. TASK_SPEAK_SENTENCE,
  251. // Wait for the current sentence I'm speaking to finish
  252. TASK_WAIT_FOR_SPEAK_FINISH,
  253. // Set current animation activity to the specified activity
  254. TASK_SET_ACTIVITY,
  255. // Adjust the framerate to plus/minus N%
  256. TASK_RANDOMIZE_FRAMERATE,
  257. // Immediately change to a schedule of the specified type
  258. TASK_SET_SCHEDULE,
  259. // Set the specified schedule to execute if the current schedule fails.
  260. TASK_SET_FAIL_SCHEDULE,
  261. // How close to route goal do I need to get
  262. TASK_SET_TOLERANCE_DISTANCE,
  263. // How many seconds should I spend search for a route
  264. TASK_SET_ROUTE_SEARCH_TIME,
  265. // Return to use of default fail schedule
  266. TASK_CLEAR_FAIL_SCHEDULE,
  267. // Play the specified animation sequence before continuing
  268. TASK_PLAY_SEQUENCE,
  269. // Play the specified private animation sequence before continuing
  270. TASK_PLAY_PRIVATE_SEQUENCE,
  271. // Turn to face the enemy while playing specified animation sequence
  272. TASK_PLAY_PRIVATE_SEQUENCE_FACE_ENEMY,
  273. TASK_PLAY_SEQUENCE_FACE_ENEMY,
  274. TASK_PLAY_SEQUENCE_FACE_TARGET,
  275. // tries lateral cover first, then node cover
  276. TASK_FIND_COVER_FROM_BEST_SOUND,
  277. // tries lateral cover first, then node cover
  278. TASK_FIND_COVER_FROM_ENEMY,
  279. // Find a place to hide from the enemy, somewhere on either side of me
  280. TASK_FIND_LATERAL_COVER_FROM_ENEMY,
  281. // Find a place further from the saved position
  282. TASK_FIND_BACKAWAY_FROM_SAVEPOSITION,
  283. // Fine a place to hide from the enemy, anywhere. Use the node system.
  284. TASK_FIND_NODE_COVER_FROM_ENEMY,
  285. // Find a place to hide from the enemy that's within the specified distance
  286. TASK_FIND_NEAR_NODE_COVER_FROM_ENEMY,
  287. // data for this one is there MINIMUM aceptable distance to the cover.
  288. TASK_FIND_FAR_NODE_COVER_FROM_ENEMY,
  289. // Find a place to go that can't see to where I am now.
  290. TASK_FIND_COVER_FROM_ORIGIN,
  291. // Unhook from the AI system.
  292. TASK_DIE,
  293. // Wait until scripted sequence plays
  294. TASK_WAIT_FOR_SCRIPT,
  295. // Play scripted sequence animation
  296. TASK_PUSH_SCRIPT_ARRIVAL_ACTIVITY,
  297. TASK_PLAY_SCRIPT,
  298. TASK_PLAY_SCRIPT_POST_IDLE,
  299. TASK_ENABLE_SCRIPT,
  300. TASK_PLANT_ON_SCRIPT,
  301. TASK_FACE_SCRIPT,
  302. // Wait for scene to complete
  303. TASK_PLAY_SCENE,
  304. // Wait for 0 to specified number of seconds
  305. TASK_WAIT_RANDOM,
  306. // Wait forever (until this schedule is interrupted)
  307. TASK_WAIT_INDEFINITE,
  308. TASK_STOP_MOVING,
  309. // Turn left the specified number of degrees
  310. TASK_TURN_LEFT,
  311. // Turn right the specified number of degrees
  312. TASK_TURN_RIGHT,
  313. // Remember the specified piece of data
  314. TASK_REMEMBER,
  315. // Forget the specified piece of data
  316. TASK_FORGET,
  317. // Wait until current movement is complete.
  318. TASK_WAIT_FOR_MOVEMENT,
  319. // Wait until a single-step movement is complete.
  320. TASK_WAIT_FOR_MOVEMENT_STEP,
  321. // Wait until I can't hear any danger sound.
  322. TASK_WAIT_UNTIL_NO_DANGER_SOUND,
  323. // Pick up new weapons:
  324. TASK_WEAPON_FIND,
  325. TASK_WEAPON_PICKUP,
  326. TASK_WEAPON_RUN_PATH, // run to weapon but break if someone else picks it up
  327. TASK_WEAPON_CREATE,
  328. TASK_ITEM_PICKUP,
  329. TASK_ITEM_RUN_PATH,
  330. // Use small hull for tight navigation
  331. TASK_USE_SMALL_HULL,
  332. // wait until you are on ground
  333. TASK_FALL_TO_GROUND,
  334. // Wander for a specfied amound of time
  335. TASK_WANDER,
  336. TASK_FREEZE,
  337. // regather conditions at the start of a schedule (all conditions are cleared between schedules)
  338. TASK_GATHER_CONDITIONS,
  339. // Require an enemy be seen after the task is run to be considered a candidate enemy
  340. TASK_IGNORE_OLD_ENEMIES,
  341. TASK_DEBUG_BREAK,
  342. // Add a specified amount of health to this NPC
  343. TASK_ADD_HEALTH,
  344. // Add a gesture layer and wait until it's finished
  345. TASK_ADD_GESTURE_WAIT,
  346. // Add a gesture layer
  347. TASK_ADD_GESTURE,
  348. // Get a path to my forced interaction partner
  349. TASK_GET_PATH_TO_INTERACTION_PARTNER,
  350. // First task of all schedules for playing back scripted sequences
  351. TASK_PRE_SCRIPT,
  352. // ======================================
  353. // IMPORTANT: This must be the last enum
  354. // ======================================
  355. LAST_SHARED_TASK
  356. };
  357. #endif // AI_TASK_H