2 * $Logfile: /Freespace2/code/Ship/ai.h $
8 * Revision 1.1 2002/05/03 03:28:12 root
12 * 12 8/29/99 4:18p Andsager
13 * New "burst" limit for friendly damage. Also credit more damage done
14 * against large friendly ships.
16 * 11 8/26/99 5:14p Andsager
18 * 10 7/26/99 12:14p Andsager
19 * Apply cap to how much slower a transport flies with cargo. Remove
20 * limit on waypoint speed for training. Enemy ai get stealth exact pos
23 * 9 7/02/99 10:56a Andsager
24 * Put in big ship - big ship attack mode. Modify stealth sweep ai.
26 * 8 6/30/99 5:53p Dave
27 * Put in new anti-camper code.
29 * 7 6/23/99 5:51p Andsager
30 * Add waypoint-cap-speed. Checkin stealth ai - inactive.
32 * 6 6/14/99 10:45a Dave
33 * Made beam weapons specify accuracy by skill level in the weapons.tbl
35 * 5 4/20/99 6:39p Dave
36 * Almost done with artillery targeting. Added support for downloading
37 * images on the PXO screen.
39 * 4 4/20/99 3:40p Andsager
40 * Changes to big ship ai. Uses bounding box as limit where to fly to
43 * 3 11/05/98 5:55p Dave
44 * Big pass at reducing #includes
46 * 2 10/07/98 10:53a Dave
49 * 1 10/07/98 10:51a Dave
51 * 186 6/09/98 5:15p Lawrance
52 * French/German localization
54 * 185 5/23/98 2:41p Mike
55 * Make Easy the default skill level and prevent old pilot's skill level
56 * from carrying into new pilot.
58 * 184 5/20/98 12:45a Mike
59 * Fix bug in support ships aborting rearm. Also, remove test code that
60 * made any ship whose name began, "Kami" a kamikaze.
62 * 183 5/18/98 1:58a Mike
63 * Make Phoenix not be fired at fighters (but yes bombers).
64 * Improve positioning of ships in guard mode.
65 * Make turrets on player ship not fire near end of support ship docking.
67 * 182 5/13/98 4:41p Mike
68 * Make big ships try a tiny bit to avoid collision with each other when
69 * attacking another big ship. Make ships a little less likely to collide
70 * into player when in formation, drop off if player flying wacky.
72 * 181 5/12/98 4:53p Mike
73 * Make ships recover from collisions with big ships, eventually flying
76 * 180 5/10/98 11:30p Mike
77 * Better firing of bombs, less likely to go into strafe mode.
79 * 179 4/12/98 2:02p Mike
80 * Make small ships avoid big ships.
81 * Turn on Collide_friendly flag.
83 * 178 4/10/98 11:02p Mike
84 * Make countermeasures less effective against aspect seekers than against
86 * Make AI ships match bank with each other when attacking a faraway
88 * Make ships not do silly loop-de-loop sometimes when attacking a faraway
91 * 177 4/08/98 8:38a Mike
92 * Make ships avoid player when attacking or guarding a faraway object.
94 * 176 4/06/98 12:46a Allender
95 * bump max ai goals down to 5
97 * 175 4/01/98 9:20a Mike
98 * Reduce MAX_SHIPS, MAX_OBJECTS and make MAX_AI_INFO same as MAX_SHIPS
100 * 174 3/21/98 3:36p Mike
101 * Fix/optimize attacking of big ships.
103 * 173 3/17/98 12:50a Mike
104 * Improved kamikaze behavior.
106 * 172 3/16/98 8:27p Allender
107 * Fred support for two new AI flags -- kamikaze and no dynamic goals.
109 * 171 3/16/98 12:03a Mike
110 * Add support for kamikaze mode. Add AIF_NO_DYNAMIC which means
111 * relentlessly pursue current goal.
113 * 170 3/15/98 9:44p Lawrance
114 * Get secondary weapons for turrets working
116 * 169 3/13/98 8:34a Mike
117 * Intermediate checkin to resolve link errors. Working on detecting
118 * whether dock with player ship is obstructed by another ship
120 * 168 3/09/98 5:12p Mike
121 * Make sure Pl_objp uses are valid.
122 * Throw asteroids at ships in asteroid field, not "Gal"
123 * Support ships warp out if no goals after 30 seconds.
125 * 167 2/26/98 10:07p Hoffoss
126 * Rewrote state saving and restoring to fix bugs and simplify the code.
128 * 166 2/22/98 4:17p John
129 * More string externalization classification... 190 left to go!
131 * 165 2/18/98 10:34p Allender
132 * repair/rearm system (for single and multi) about finished.
133 * dock/undock and ai goals packets implemented for multiplayer
135 * 164 2/17/98 5:03p Allender
136 * major cdhanges to rearm repair code. All flag and variable setting
137 * done in one function. A little more work to do. Fix bug in squad
138 * messaging when hotkey was used on invalid target
140 * 163 2/16/98 10:13p Allender
141 * initial work on being able to target weapons (bombs specifically).
142 * Work on getting rearm/repair working under multiplayer
154 #include "systemvars.h"
156 #define AI_DEFAULT_CLASS 3 // default AI class for new ships (Fred)
158 #define AIF_FORMATION_WING (1 << 0) // Fly in formation as part of wing.
159 #define AIF_AWAITING_REPAIR (1 << 1) // Awaiting a repair ship.
160 #define AIF_BEING_REPAIRED (1 << 2) // Currently docked with repair ship.
161 #define AIF_REPAIRING (1 << 3) // Repairing a ship (or going to repair a ship)
162 #define AIF_DOCKED (1 << 4) // this object docked with something else
163 #define AIF_SEEK_LOCK (1 << 5) // set if should focus on gaining aspect lock, not hitting with lasers
164 #define AIF_FORMATION_OBJECT (1 << 6) // Fly in formation off a specific object.
165 #define AIF_TEMPORARY_IGNORE (1 << 7) // Means current ignore_objnum is only temporary, not an order from the player.
166 #define AIF_USE_EXIT_PATH (1 << 8) // Used by path code, to flag path as an exit path
167 #define AIF_USE_STATIC_PATH (1 << 9) // Used by path code, use fixed path, don't try to recreate
168 #define AIF_TARGET_COLLISION (1 << 10) // Collided with aip->target_objnum last frame. Avoid that ship for half a second or so.
169 #define AIF_UNLOAD_SECONDARIES (1 << 11) // Fire secondaries as fast as possible!
170 #define AIF_ON_SUBSYS_PATH (1 << 12) // Current path leads to a subsystem
171 #define AIF_AVOID_SHOCKWAVE_SHIP (1 << 13) // Avoid an existing shockwave from a ship.
172 #define AIF_AVOID_SHOCKWAVE_WEAPON (1 << 14) // Avoid an expected shockwave from a weapon. shockwave_object field contains object index.
173 #define AIF_AVOID_SHOCKWAVE_STARTED (1 << 15) // Already started avoiding shockwave, don't keep deciding whether to avoid.
174 #define AIF_ATTACK_SLOWLY (1 << 16) // Move slowly while attacking.
175 #define AIF_REPAIR_OBSTRUCTED (1 << 17) // Ship wants to be repaired, but path is obstructed.
176 #define AIF_KAMIKAZE (1 << 18) // Crash into target
177 #define AIF_NO_DYNAMIC (1 << 19) // Not allowed to get dynamic goals
178 #define AIF_AVOIDING_SMALL_SHIP (1 << 20) // Avoiding a player ship.
179 #define AIF_AVOIDING_BIG_SHIP (1 << 21) // Avoiding a large ship.
180 #define AIF_BIG_SHIP_COLLIDE_RECOVER_1 (1 << 22) // Collided into a big ship. Recovering by flying away.
181 #define AIF_BIG_SHIP_COLLIDE_RECOVER_2 (1 << 23) // Collided into a big ship. Fly towards big ship sphere perimeter.
182 #define AIF_STEALTH_PURSIUT (1 << 24) // Ai is trying to fight stealth ship
184 #define AIF_AVOID_SHOCKWAVE (AIF_AVOID_SHOCKWAVE_SHIP | AIF_AVOID_SHOCKWAVE_WEAPON)
185 #define AIF_FORMATION (AIF_FORMATION_WING | AIF_FORMATION_OBJECT)
187 // dock_orient_and_approach() modes.
188 #define DOA_APPROACH 1 // Approach the current point on the path (aip->path_cur)
189 #define DOA_DOCK 2 // Dock with goal object.
190 #define DOA_UNDOCK_1 3 // Begin undocking with goal object. Just move away.
191 #define DOA_UNDOCK_2 4 // Secondary undocking. Move away.
192 #define DOA_UNDOCK_3 5 // Tertiary undocking. Move away and orient away.
193 #define DOA_DOCK_STAY 6 // Rigidly maintain position in dock bay.
195 // Type values for ai_dock_with_object() dock_type parameter.
196 #define AIDO_DOCK 1 // Set goal of docking with object.
197 #define AIDO_DOCK_NOW 2 // Immediately move into dock position. For ships that start mission docked.
198 #define AIDO_UNDOCK 3 // Set goal of undocking with object.
200 #define MAX_AI_GOALS 5
202 // Submodes for seeking safety.
203 #define AISS_1 41 // Pick a spot to fly to.
204 #define AISS_2 42 // Flying to spot.
205 #define AISS_3 43 // Gotten near spot, fly about there.
206 #define AISS_1a 44 // Pick a new nearby spot because we are endangered, then go to AISS_2
208 // types of ai goals -- tyese types will help us to determination on which goals should
209 // have priority over others (i.e. when a player issues a goal to a wing, then a seperate
210 // goal to a ship in that wing). We would probably use this type in conjunction with
211 // goal priority to establish which goal to follow
212 #define AIG_TYPE_EVENT_SHIP 1 // from mission event direct to ship
213 #define AIG_TYPE_EVENT_WING 2 // from mission event direct to wing
214 #define AIG_TYPE_PLAYER_SHIP 3 // from player direct to ship
215 #define AIG_TYPE_PLAYER_WING 4 // from player direct to wing
216 #define AIG_TYPE_DYNAMIC 5 // created on the fly
218 // flags for AI_GOALS
219 #define AIGF_DOCKER_NAME_VALID (1<<0) // when set, name field for docker is valid
220 #define AIGF_DOCKEE_NAME_VALID (1<<1) // when set, name field for dockee is valid
221 #define AIGF_GOAL_ON_HOLD (1<<2) // when set, this goal cannot currently be satisfied, although it could be in the future
222 #define AIGF_SUBSYS_NAME_VALID (1<<3) // when set, the subsystem name (for a destroy subsystem goal) is valid, and stored in docker.name field!!
223 #define AIGF_GOAL_OVERRIDE (1<<4) // paired with AIG_TYPE_DYNAMIC to mean this goal overrides any other goal
224 #define AIGF_PURGE (1<<5) // purge this goal next time we process
225 #define AIGF_GOALS_PURGED (1<<6) // this goal has already caused other goals to get purged
227 // Flags to ai_turn_towards_vector().
228 #define AITTV_FAST (1<<0) // Turn fast, not slowed down based on skill level.
230 #define KAMIKAZE_HULL_ON_DEATH -1000.0f // Hull strength ship gets set to if it crash-dies.
232 // structure for AI goals
233 typedef struct ai_goals {
234 int signature; // Unique identifier. All goals ever created (per mission) have a unique signature.
235 int ai_mode; // one of the AIM_* modes for this goal
236 int ai_submode; // maybe need a submode
237 int type; // one of the AIG_TYPE_* values above
238 int flags; // one of the AIGF_* values above
239 fix time; // time at which this goal was issued.
240 int priority; // how important is this goal -- number 0 - 100
241 char *ship_name; // name of the ship that this goal acts upon
242 int ship_name_index; // index of ship_name in Goal_ship_names[][]
243 int wp_index; // index into waypoints list of waypoints that this ship might fly.
244 int weapon_signature; // signature of weapon this ship might be chasing. Paired with above value to get target.
246 // unions for docking stuff.
259 #include "ship.h" // ai_goal must be declared before including this.
261 #define MAX_AI_CLASSES 10
262 #define MAX_GOAL_SHIP_NAMES 100
266 #define AIM_GET_BEHIND 2
267 #define AIM_STAY_NEAR 3 // Stay near another ship.
268 #define AIM_STILL 4 // Sit still. Don't move. Hold your breath. Don't blink.
269 #define AIM_GUARD 5 // Guard an object
270 #define AIM_AVOID 6 // Avoid an object
271 #define AIM_WAYPOINTS 7 // Fly waypoints
272 #define AIM_DOCK 8 // Dock with ship.
273 #define AIM_NONE 9 // Uh, do nothing.
274 #define AIM_BIGSHIP 10 // Like a capital ship, doesn't focus on one ship.
275 #define AIM_PATH 11 // Follow path on ship
276 #define AIM_BE_REARMED 12 // Allow self to be rearmed
277 #define AIM_SAFETY 13 // Seek safety at periphery of battle
278 #define AIM_EVADE_WEAPON 14 // Evade a weapon.
279 #define AIM_STRAFE 15 // attack a big ship by strafing it
280 #define AIM_PLAY_DEAD 16 // Play dead. Get it? Don't move, fire, etc.
281 #define AIM_BAY_EMERGE 17 // Emerging from a fighter bay, following path to do so
282 #define AIM_BAY_DEPART 18 // Departing to a fighter bay, following path to do so
283 #define AIM_SENTRYGUN 19 // AI mode for sentry guns only (floating turrets)
284 #define AIM_WARP_OUT 20 // Commence warp out sequence. Point in legal direction. Then call John's code.
286 #define MAX_AI_BEHAVIORS 21 // Number of AIM_xxxx types
288 #define MAX_WAYPOINTS_PER_LIST 20
289 #define MAX_WAYPOINT_LISTS 32
290 #define MAX_ENEMY_DISTANCE 2500.0f // maximum distance from which a ship will pursue an enemy.
292 // waypoint list flags bitmasks.
293 #define WL_MARKED 0x01
295 typedef struct waypoint_list {
296 char name[NAME_LENGTH];
298 char flags[MAX_WAYPOINTS_PER_LIST];
299 vector waypoints[MAX_WAYPOINTS_PER_LIST];
302 #define AI_GOAL_NONE -1
304 #define AI_ACTIVE_GOAL_DYNAMIC 999
306 typedef struct ai_class {
307 char name[NAME_LENGTH];
308 float ai_accuracy[NUM_SKILL_LEVELS];
309 float ai_evasion[NUM_SKILL_LEVELS];
310 float ai_courage[NUM_SKILL_LEVELS];
311 float ai_patience[NUM_SKILL_LEVELS];
314 // Submode definitions.
315 // Note: These need to be renamed to be of the form: AIS_mode_xxxx
316 #define SM_CONTINUOUS_TURN 1 // takes parm: vector_id {0..3 = right, -right, up, -up}
318 #define SM_EVADE_SQUIGGLE 3
319 #define SM_EVADE_BRAKE 4
321 #define SM_SUPER_ATTACK 6
323 #define SM_GET_BEHIND 8
324 #define SM_GET_AWAY 9
325 #define SM_EVADE_WEAPON 10 // Evade incoming weapon
326 #define SM_FLY_AWAY 11 // Fly away from target_objnum
327 #define SM_ATTACK_FOREVER 12 // Engine subsystem destroyed, so attack, never evading, avoiding, etc.
328 #define SM_STEALTH_FIND 13 // Stealth ship is "targeted", but not visible, so try to find based on predicted pos
329 #define SM_STEALTH_SWEEP 14 // General sweep, looking for stealth after not visible for some time.
330 #define SM_BIG_APPROACH 15 // Big ship approaches another
331 #define SM_BIG_CIRCLE 16 // Big ship flies circle around other big ship to get good angle to go parallel
332 #define SM_BIG_PARALLEL 17 // Big ship flies parallel to another
334 // Submodes for docking behavior
335 #define AIS_DOCK_0 21
336 #define AIS_DOCK_1 22
337 #define AIS_DOCK_2 23
338 #define AIS_DOCK_3 24
339 #define AIS_DOCK_3A 25
340 #define AIS_DOCK_4 26 // Only for rearm/repair.
341 #define AIS_DOCK_4A 27 // Only for not rearm/repair. MK, 7/15/97
342 #define AIS_UNDOCK_0 30
343 #define AIS_UNDOCK_1 31
344 #define AIS_UNDOCK_2 32
345 #define AIS_UNDOCK_3 33
346 #define AIS_UNDOCK_4 34
348 // Submodes for Guard behavior
349 #define AIS_GUARD_PATROL 101
350 #define AIS_GUARD_ATTACK 102
351 #define AIS_GUARD_2 103
352 #define AIS_GUARD_STATIC 104 // maintain current relative position to guard object, if possible
354 // Submodes for strafing big ships behavior (AIM_STRAFE)
355 #define AIS_STRAFE_ATTACK 201 // fly towards target and attack
356 #define AIS_STRAFE_AVOID 202 // fly evasive vector to avoid incoming fire
357 #define AIS_STRAFE_RETREAT1 203 // fly away from attack point
358 #define AIS_STRAFE_RETREAT2 204
359 #define AIS_STRAFE_POSITION 205 // re-position to resume strafing attack
361 #define WPF_REPEAT (1 << 0)
362 #define WPF_BACKTRACK (1 << 1)
365 #define PD_BACKWARD -1
367 #define MIN_TRACKABLE_ASPECT_DOT 0.992f // dot of fvec and vec_to_enemy to progress towards aspect lock
369 // Submodes for warping out.
370 #define AIS_WARP_1 300 // Make sure there is no obstruction to warping out.
371 #define AIS_WARP_2 301
372 #define AIS_WARP_3 302
373 #define AIS_WARP_4 303
374 #define AIS_WARP_5 304
377 // Contains global location of point.
378 // Contains hooks back to original path information.
379 // This hook is used to extract information on the point such as whether it is
380 // protected by turrets.
381 typedef struct pnode {
383 int path_num; // path number from polymodel, ie in polymodel, paths[path_num]
384 int path_index; // index in original model path of point, ie in model_path, use verts[path_index]
387 #define MAX_PATH_POINTS 1000
388 extern pnode Path_points[MAX_PATH_POINTS];
389 extern pnode *Ppfp; // Free pointer in path points.
391 typedef struct ai_info {
392 int ai_flags; // Special flags for AI behavior.
393 int shipnum; // Ship using this slot, -1 means none.
395 int wing; // Member of what wing? -1 means none.
397 int behavior; // AI Class. Doesn't change after initial setting.
400 int mode_time; // timestamp at which current mode elapses.
401 int target_objnum; // object index of current target.
402 int target_signature; // Signature of current target.
403 int previous_target_objnum; // On 5/19/97, only used for player.
405 int stealth_last_cheat_visible_stamp; // when within 100m, always update pos and velocity, with error increasing for increasing time from last legal visible
406 int stealth_last_visible_stamp;
407 float stealth_sweep_box_size;
408 vector stealth_last_pos;
409 vector stealth_velocity;
411 float previous_dot_to_enemy; // dot(fvec, vec_to_enemy) last frame
412 float target_time; // Amount of time continuously targeting this ship.
414 int enemy_wing; // When picking an enemy wing, only allow to be in enemy_wing, unless == -1, in which case don't care.
416 int goal_objnum; // mode specific goal. In DOCK, ship to dock with.
419 int guard_objnum; // Ship to guard.
420 int guard_signature; // Signature of ship to guard.
421 int guard_wingnum; // Wing to guard. guard_objnum set to leader.
423 int ignore_objnum; // ship to be ignored, based on player order. UNUSED_OBJNUM if none. -(wing_num+1) if ignoring wing.
424 int ignore_signature; // signature of ship to be ignored
426 int ai_class; // Class. Might be override of default.
428 // Probably become obsolete, to be replaced by path_start, path_cur, etc.
429 int wp_list; // waypoint list index
430 int wp_index; // waypoint index in list
431 int wp_flags; // waypoint flags, see WPF_xxxx
432 int wp_dir; // 1 or -1, amount to add to get to next waypoint index.
433 char waypoint_speed_cap; // -1 no cap, otherwise cap
435 // Path following information
436 int path_start; // Index into global array, start of path.
437 int path_cur; // Index into global array, current location in path.
438 int path_length; // Number of links in this path.
439 int path_dir; // PD_FORWARD, PD_BACKWARD
440 int path_flags; // loop, backtrack, whatever else.
441 int path_objnum; // Object of interest. It's model contains the path.
442 int path_goal_obj_hash; // Hash value of goal object when global path created.
443 fix path_next_create_time; // Next time at which we'll create a global path.
444 vector path_create_pos; // Object's position at time of global path creation.
445 matrix path_create_orient; // Object's orientation at time of global path creation.
446 int mp_index; // Model path index. Index in polymodel:model_paths
447 fix path_next_check_time; // Last time checked to see if would collide with model.
448 int path_goal_dist; // minimum distance to first path point to consider path reached
449 int path_subsystem_next_check; // timestamp to next check if subsystem is still visible
452 int previous_submode; // previous submode, get it?
453 float best_dot_to_enemy; // best dot product to enemy in last BEST_DOT_TIME seconds
454 float best_dot_from_enemy; // best dot product for enemy to player in last BEST_DOT_TIME seconds
455 fix best_dot_to_time; // time at which best dot occurred
456 fix best_dot_from_time; // time at which best dot occurred
457 fix submode_start_time; // time at which we entered the current submode
458 int submode_parm0; // parameter specific to current submode
459 fix next_predict_pos_time; // Next time to predict position.
461 ai_goal goals[MAX_AI_GOALS];
462 int active_goal; // index of active goal, -1 if none, AI_ACTIVE_GOAL_DYNAMIC if dynamic (runtime-created) goal
463 int goal_check_time; // timer used for processing goals for this ai object
465 vector last_predicted_enemy_pos; // Where he thought enemy was last time.
466 float time_enemy_in_range; // Amount of time enemy continuously in "sight", near crosshair.
467 fix last_attack_time; // Missiontime of last time this ship attacked its enemy.
468 fix last_hit_time; // Missiontime of last time this ship was hit by anyone.
469 int last_hit_quadrant; // Shield section of last hit.
470 fix last_hit_target_time; // Missiontime of last time this ship successfully hit target.
471 int hitter_objnum; // Object index of ship that hit this ship last time.
472 int hitter_signature; // Signature of hitter. Prevents stupidity if hitter gets killed.
473 fix resume_goal_time; // Time at which to resume interrupted goal, if nothing else intervenes.
474 float prev_accel; // Acceleration last frame.
475 float prev_dot_to_goal; // dot of fvec to goal last frame, used to see if making progress towards goal.
476 vector goal_point; // Used in AIM_SAFETY, AIM_STILL and in circling.
477 vector prev_goal_point; // Previous location of goal point, used at least for evading.
478 float ai_accuracy, ai_evasion, ai_courage, ai_patience;
480 float lead_scale; // Amount to lead current opponent by.
481 float stay_near_distance; // Distance to stay within for AIM_STAY_NEAR mode.
484 ship_subsys* targeted_subsys; // Targeted subobject on current target. NULL if none;
485 ship_subsys* last_subsys_target; // last known subsystem target
486 int targeted_subsys_parent; // Parent objnum of subobject, not necessarily targeted
488 float aspect_locked_time; // Time towards acquiring lock for current_target
490 // ship_subsys *targeted_subobject; // subsystem to attack
491 // int attack_subsystem_parent; // objnum of the object containing the attack_subsystem
492 int dock_index; // index of docking point to use when docking.
493 int dockee_index; // index of dock point on other ship.
494 int dock_path_index; // index of docking path to use when docking.
495 int dock_objnum; // objnum of ship we are docked with.
496 int dock_signature; // Signature of repair object.
497 int danger_weapon_objnum; // Closest objnum of weapon fired at this ship.
498 int danger_weapon_signature; // Signature of object danger_weapon_objnum.
500 vector guard_vec; // vector to object being guarded, only used in AIS_GUARD_STATIC submode
501 int nearest_locked_object; // Nearest locked object.
502 float nearest_locked_distance; // Distance to nearest locked object.
504 float current_target_distance; // Distance of current target from player
505 int current_target_is_locked; // Flag to indicate whether the current target is locked for missile fire
506 int current_target_dist_trend; // Tracks whether distance to target is increasing or decreasing
507 int current_target_speed_trend; // Tracks whether speed of target is increasing or decreasing
509 float last_dist; // last frame's distance between player and target
510 float last_speed; // last frame's target speed
511 int last_secondary_index; // needed for secondary weapon change check
514 int rearm_first_missile; // flag to show that reloading of missilies hasn't begun yet
515 int rearm_release_delay; // timestamp used to delay separation of ships after rearm complete
517 fix afterburner_stop_time; // Missiontime to turn off afterburner
518 int last_objsig_hit; // The object number signature of the ship last hit by this ship
519 int ignore_expire_timestamp; // Timestamp at which temporary ignore (AIF_TEMPORARY_IGNORE) expires.
520 int warp_out_timestamp; // Timestamp at which this ship is to warp out.
521 int next_rearm_request_timestamp; // Timestamp at which ship might next request rearm.
522 int primary_select_timestamp; // When to next select a primary weapon.
523 int secondary_select_timestamp; // When to next select a secondary weapon.
525 int scan_for_enemy_timestamp; // When to next look for enemy fighters if sitting still while pounding
526 // on a bigship. SCAN_FIGHTERS_INTERVAL is defined in AiBig.h
527 int choose_enemy_timestamp; // Time at which it is next legal to choose a new enemy (does not apply
528 // to special situations, like getting hit by a weapon)
529 int force_warp_time; // time at which to give up avoiding a ship and just warp out
531 int shockwave_object; // Object index of missile that will generate a shockwave. We will try to avoid.
533 int shield_manage_timestamp; // Time at which to next manage shield.
534 int self_destruct_timestamp; // Time at which to self-destruct, probably due to being disabled.
535 int ok_to_target_timestamp; // Time at which this ship can dynamically target.
537 float kamikaze_damage; // some damage value used to produce a shockwave from a kamikaze ship
538 vector big_attack_point; // Global point this ship is attacking on a big ship.
539 vector big_attack_surface_normal; // Surface normal at ship at big_attack_point;
540 int pick_big_attack_point_timestamp; // timestamp at which to pick a new point to attack on a big ship.
542 // Note: These three avoid_XX terms are shared between the code that avoids small (only player now) and large ships
543 // The bits in ai_flags determine which is occurring. AIF_AVOID_SMALL_SHIP, AIF_AVOID_BIG_SHIP
544 int avoid_ship_num; // object index of small ship to avoid
545 vector avoid_goal_point; // point to aim at when avoiding a ship
546 fix avoid_check_timestamp; // timestamp at which to next check for having to avoid ship
548 vector big_collision_normal; // Global normal of collision with big ship. Helps find direction to fly away from big ship. Set for each collision.
549 vector big_recover_pos_1; // Global point to fly towards when recovering from collision with a big ship, stage 1.
550 vector big_recover_pos_2; // Global point to fly towards when recovering from collision with a big ship, stage 2.
551 int big_recover_timestamp; // timestamp at which it's OK to re-enter stage 1.
553 int abort_rearm_timestamp; // time at which this rearm should be aborted in a multiplayer game.
555 // artillery targeting info
556 int artillery_objnum; // object currently being targeted for artillery lock/attack
557 int artillery_sig; // artillery object signature
558 float artillery_lock_time; // how long we've been locked onto this guy
559 vector artillery_lock_pos; // base position of the lock point on (in model's frame of reference)
560 float lethality; // measure of how dangerous ship is to enemy BIG|HUGE ships (likelyhood of targeting)
563 #define MAX_AI_INFO MAX_SHIPS
565 // SUBSYS_PATH_DIST is used as the distance that a subsystem path should terminate from the actual
566 // subsystem. We don't want to rely on the model path points for this, since we may need to be
568 #define SUBSYS_PATH_DIST 500.0f
570 // Friendly damage defines
571 #define MAX_BURST_DAMAGE 20 // max damage that can be done in BURST_DURATION
572 #define BURST_DURATION 500 // decay time over which Player->damage_this_burst falls from MAX_BURST_DAMAGE to 0
574 extern int Mission_all_attack; // !0 means all teams attack all teams.
575 extern int Total_goal_ship_names;
576 extern char Goal_ship_names[MAX_GOAL_SHIP_NAMES][NAME_LENGTH];
578 extern void update_ai_info_for_hit(int hitter_obj, int hit_obj);
579 extern void ai_frame_all(void);
581 extern int find_guard_obj(void);
583 extern ai_info Ai_info[];
584 extern ai_info *Player_ai;
586 extern int Waypoints_created; // externed since needed for save/restore
588 extern ai_class Ai_classes[];
589 extern char *Ai_class_names[];
591 extern int Num_ai_classes;
592 extern int Ai_firing_enabled;
594 extern char *Skill_level_names(int skill_level, int translate = 1);
595 extern int Skill_level_max_attackers[NUM_SKILL_LEVELS];
596 extern int Ai_goal_signature;
598 // need access to following data in AiBig.cpp
599 extern object *Pl_objp;
600 extern object *En_objp;
601 extern float AI_frametime;
604 // Return index of free AI slot.
605 // Return 0 if no free slot.
606 int ai_get_slot(int shipnum);
608 // Releases an AI slot to be used by someone else.
609 void ai_free_slot(int ai_index);
611 // call to init one ai object.. you can pass all sorts of
612 // stuff by adding new paramters.
613 void ai_object_init(object * obj, int ai_index);
615 // Called once a frame
616 void ai_process( object * obj, int ai_index, float frametime );
618 int get_wingnum(int objnum);
620 void set_wingnum(int objnum, int wingnum);
621 char *ai_get_goal_ship_name(char *name, int *index);
623 extern waypoint_list Waypoint_lists[MAX_WAYPOINT_LISTS];
624 extern int Num_waypoint_lists;
626 extern void init_ai_system(void);
627 extern void ai_attack_object(object *attacker, object *attacked, int priority, ship_subsys *ssp);
628 extern void ai_evade_object(object *evader, object *evaded, int priority);
629 extern void ai_ignore_object(object *ignorer, object *ignored, int priority);
630 extern void ai_ignore_wing(object *ignorer, int wingnum, int priority);
631 extern void ai_dock_with_object(object *docker, object *dockee, int priority, int dock_type, int docker_index, int dockee_index);
632 extern void ai_stay_still(object *still_objp, vector *view_pos);
633 extern void ai_set_default_behavior(object *obj, int classnum);
634 extern void ai_do_default_behavior(object *obj);
635 extern void ai_start_waypoints(object *objp, int waypoint_list_index, int wp_flags);
636 extern void ai_ship_hit(object *objp_ship, object *hit_objp, vector *hitpos, int shield_quadrant, vector *hit_normal);
637 extern void ai_ship_destroy(int shipnum, int method);
638 extern void ai_turn_towards_vector(vector *dest, object *objp, float frametime, float turn_time, vector *slide_vec, vector *rel_pos, float bank_override, int flags, vector *rvec = NULL);
639 extern void init_ai_object(int objnum);
640 extern void ai_init(void); // Call this one to parse ai.tbl.
641 extern void ai_level_init(void); // Call before each level to reset AI
643 extern int ai_set_attack_subsystem(object *objp, int subnum);
644 extern int ai_issue_rearm_request(object *requester_objp); // Object requests rearm/repair.
645 extern int ai_abort_rearm_request(object *requester_objp); // Object aborts rearm/repair.
646 extern void ai_do_repair_frame(object *objp, ai_info *aip, float frametime); // Repair a ship object, player or AI.
647 extern float dock_orient_and_approach(object *objp, object *dobjp, int dock_mode); // Move to a position relative to a dock bay using thrusters.
648 extern void ai_update_danger_weapon(int objnum, int weapon_objnum);
650 // called externally from MissionParse.cpp to position ships in wings upon arrival into the
652 extern void get_absolute_wing_pos( vector *result_pos, object *leader_objp, int wing_index, int formation_object_flag);
655 // Interface from goals code to AI. Set ship to guard. *objp guards *other_objp
656 extern void ai_set_guard_object(object *objp, object *other_objp);
657 extern void ai_set_evade_object(object *objp, object *other_objp);
658 extern void ai_set_guard_wing(object *objp, int wingnum);
659 extern void ai_warp_out(object *objp, vector *vp);
660 extern void ai_attack_wing(object *attacker, int wingnum, int priority);
661 extern void ai_deathroll_start(object *ship_obj);
662 extern void ai_fly_in_formation(int wing_num); // Force wing to fly in formation.
663 extern void ai_disband_formation(int wing_num); // Force wing to disband formation flying.
664 extern object *ai_find_docked_object( object *objp ); // returns object that objp is docked to
665 extern int set_target_objnum(ai_info *aip, int objnum);
666 extern void ai_form_on_wing(object *objp, object *goal_objp);
667 extern void ai_do_stay_near(object *objp, object *other_obj, float dist);
668 extern ship_subsys *set_targeted_subsys(ai_info *aip, ship_subsys *new_subsys, int parent_objnum);
669 extern void ai_rearm_repair( object *objp, object *goal_objp, int priority, int docker_index, int dockee_index );
670 extern void ai_add_rearm_goal( object *requester_objp, object *support_objp );
671 extern void create_model_path(object *pl_objp, object *mobjp, int path_num, int subsys_path=0);
673 // used to get path info for fighter bay emerging and departing
674 int ai_acquire_emerge_path(object *pl_objp, int parent_objnum, vector *pos, vector *fvec);
675 int ai_acquire_depart_path(object *pl_objp, int parent_objnum);
678 extern void ai_set_positions(object *pl_objp, object *en_objp, ai_info *aip, vector *player_pos, vector *enemy_pos);
679 extern void accelerate_ship(ai_info *aip, float accel);
680 extern void turn_away_from_point(object *objp, vector *point, float bank_override);
681 extern float ai_endangered_by_weapon(ai_info *aip);
682 extern void update_aspect_lock_information(ai_info *aip, vector *vec_to_enemy, float dist_to_enemy, float enemy_radius);
683 extern void ai_chase_ct();
684 extern void ai_find_path(object *pl_objp, int objnum, int path_num, int exit_flag, int subsys_path=0);
685 extern float ai_path();
686 extern void evade_weapon();
687 extern int might_collide_with_ship(object *obj1, object *obj2, float dot_to_enemy, float dist_to_enemy, float duration);
688 extern void ai_fire_primary_weapon(object *objp);
689 extern int ai_fire_secondary_weapon(object *objp, int priority1 = -1, int priority2 = -1);
690 extern float ai_get_weapon_dist(ship_weapon *swp);
691 extern void turn_towards_point(object *objp, vector *point, vector *slide_vec, float bank_override);
692 extern int ai_maybe_fire_afterburner(object *objp, ai_info *aip);
693 extern void set_predicted_enemy_pos(vector *predicted_enemy_pos, object *pobjp, object *eobjp, ai_info *aip);
695 extern int is_instructor(object *objp);
696 extern int find_enemy(int objnum, float range, int max_attackers);
698 float ai_get_weapon_speed(ship_weapon *swp);
699 void set_predicted_enemy_pos_turret(vector *predicted_enemy_pos, vector *gun_pos, object *pobjp, vector *enemy_pos, vector *enemy_vel, float weapon_speed, float time_enemy_in_range);
700 void ai_turret_select_default_weapon(ship_subsys *turret);
702 // function to change rearm status for ai ships (called from sexpression code)
703 extern void ai_set_rearm_status( int team, int new_status );
704 extern void ai_good_secondary_time( int team, int weapon_index, int num_weapons, char *shipname );
706 extern void ai_do_objects_docked_stuff( object *docker, object *dockee );
707 extern void ai_do_objects_undocked_stuff( object *docker, object *dockee );
708 extern void ai_do_objects_repairing_stuff( object *repaired_obj, object *repair_obj, int how );
710 extern int find_danger_weapon(object *sobjp, float dtime, float *atime, float dot_threshhold);
712 void ai_set_mode_warp_out(object *objp, ai_info *aip);