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.

508 lines
13 KiB

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