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