Source ai

From FreeSpace Wiki
Revision as of 13:19, 11 July 2007 by Benoit (talk | contribs) (New page: == Initialization == === init_ai_objects === For each ship objects, call init_ai_object. === init_ai_object(int objnum) === Initialize ai_info structure of object `objnum'. === ai_obj...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Initialization

init_ai_objects

For each ship objects, call init_ai_object.

init_ai_object(int objnum)

Initialize ai_info structure of object `objnum'.

ai_object_init(object *obj, int ai_index)

FIXME

Update

ai_process

This method is called once a frame by ship/ship.cpp in ship_process_post.

1. init_ship_info
2. create_waypoints
3. ai_frame
4. if not in docking or warping modes: do read flying controls (?)

ai_frame

1. possibly: ai_warp_out
2. ai_maybe_self_destruct
3. ai_process_mission_orders
4. possibly: ai_avoid_shockwave, ai_abort_rearm_request
5. ai_do_repair_frame
6. possibly: ai_await_repair_frame
7. maybe_big_ship_collide_recover_frame
8. ai_preprocess_ignore_objnum
9. ai_manage_shield
10. ai_maybe_depart
99. ai_execute_behavior

ai_execute_behavior

Branch on different ai submethods, given the ai_info->mode received as argument:

  • AIM_CHASE: call ai_chase or evade_weapon or [...]
  • AIM_EVADE: call ai_evade or [...]
  • AIM_STILL: call ai_still
  • AIM_STAY_NEAR: call ai_stay_near
  • AIM_GUARD: call ai_guard
  • AIM_WAYPOINTS: call ai_waypoints
  • AIM_FLY_TO_SHIP: call ai_fly_to_ship
  • AIM_DOCK: call ai_dock
  • AIM_NONE: do nothing
  • AIM_BIGSHIP: call ai_big_ship
  • AIM_PATH: call ai_find_path then ai_path
  • AIM_SAFETY: call ai_safety
  • AIM_EVADE_WEAPON: call evade_weapon
  • AIM_STRAFE: call ai_big_strafe or set to AIM_NONE
  • AIM_BAY_EMERGE: call ai_bay_emerge
  • AIM_BAY_DEPART: call ai_bay_depart()
  • AIM_SENTRYGUN: call ai_sentrygun()
  • AIM_WARP_OUT: do nothing: this case is handled directly from ai_frame
  • AIM_GET_BEHIND: see FIXME
  • default: should not be there, just abort

Eventually call mabe_evade_dumbfire_weapon, when FIXME.

ai_process_mission_orders

FIXME


Behaviors

Docking

Mode: AIM_DOCK

Enterring AIM_DOCK:

  • ai_dock_with_object: ask for a `docker' object to dock with a `dockee' one, possibly enter one fo the following submodes:
    • AIS_DOCK_0: start docking
    • AIS_DOCK_4A: dock instantly
    • AIS_UNDOCK_0: start undocking

Handler: ai_dock

Approach a ship, follow path to docking platform, approach platform; after awhile, undock.

Docking is decomposed in several steps:

  • AIS_DOCK_0: find a path to the dockee then enable submode AIS_DOCK_1.
  • AIS_DOCK_1: follow the path previously built until just before the last point. Switch to AIS_DOCK_2 when the point preceding the last one is reached.
  • AIS_DOCK_2: do final approach: orient docker correctly then approach dockee. Once close enough, swith to submode AIS_DOCK_3.
  • AIS_DOCK_3: eventually dock. Call `ai_do_objects_docked_stuff' to decide wether to switch to AIS_DOCK_4 (rearm/repair) or to AIS_DOCK_4A (just wait).
  • AIS_DOCK_4A: just sit where docker is, waiting for further orders. When goal is AI_GOAL_DOCK, this means mission goal completion.
  • AIS_DOCK_4: rearm/repair by calling `ai_do_objects_repairing_stuff'. If the dockee is going too fast, abort by calling `ai_abort_rearm_request'.

Undocking is decomposed in several steps:

  • FIXME

Auxiliary functions

  • ai_cleanup_dock_mode_subjective
 > none
 < ai_dock, ai_cleanup_dock_mode_objective
  • maybe_dock_obstructed
 > pp_collide_any
 < ai_dock
  • dock_orient_and_approach
 > several methods (quite a very important function)
 < ai_dock, ai_dock_with_object, call_doa
  • ai_do_objects_repairing_stuff
 > several methods (quite a very important function)
 < ai_dock, ai_set_goal_maybe_abord_dock, ai_cleanup_rearm_mode,
   ai_do_repair_frame, ai_ship_destroy, ai_abort_rearm_request,
   ai_issue_rearm_request, ai_rearm_repair
  • ai_abort_rearm_request
 >
 < ai_dock, ai_do_repair_frame, ai_set_mode_warp_out, ai_await_repair_frame,
   ai_frame, maybe_process_friendly_hit, ai_ship_hit, ai_abort_rearm_request,
  • ai_do_objects_docked_stuff
 > dock_check_find_direct_docked_object, object_is_docked, dock_dock_objects,
 < ai_dock, ai_dock_with_object
  • ai_do_objects_undocked_stuff
 > dock_check_find_direct_docked_object, dock_undock_objects
 < ai_dock, ai_do_objects_repairing_stuff, ai_deathroll_start
  • ai_cleanup_dock_mode_objective
 > ai_cleanup_dock_mode_subjective
 < ai_deathroll_start
  • dock_find_dockpoint_used_by_object
  • hud_maybe_flash_docking_text
  • ai_return_path_num_from_dockbay
  • ai_do_default_behavior
  • ai_mission_goal_complete
  • ai_find_path

Chasing

Mode: AIM_CHASE

Enterring AIM_CHASE:

  • ai_attack_object: enter SM_ATTACK submode
  • ai_attack_wing: enter SM_ATTACK submode
  • guard_object_was_hit: enter SM_ATTACK submode
  • ai_do_default_behavior: enter SM_ATTACK submode
  • maybe_set_dynamic_chase: enter SM_ATTACK submode
  • ai_ship_hit: enter SM_EVADE_WEAPON or SM_EVADE submode

Handler: ai_chase

Make player object chase ennemy.

Chasing may be interpreted by many different sub-handlers:

  • SM_CONTINUOUS_TURN: ai_chase_ct, after a while, switch to SM_ATTACK submode
  • SM_STEALTH_FIND: ai_stealth_find
  • SM_STEALTH_SWEEP: ai_stealth_sweep
  • SM_ATTACK, SM_SUPER_ATTACK, SM_ATTACK_FOREVER: ai_chase_attack
  • SM_AVOID: avoid_ship
  • SM_GET_BEHIND: get_behind_ship
  • SM_GET_AWAY: ai_chase_ga
  • SM_EVADE_SQUIGGLE: ai_chase_es
  • SM_EVADE_BRAKE: ai_chase_eb
  • SM_EVADE: evade_ship
  • SM_EVADE_WEAPON: evade_weapon

Mode: AIM_GET_BEHIND

A grep on the whole code reveals no way to enter AIM_GET_BEHIND.

Evading

Mode: AIM_EVADE

Enterring AIM_EVADE:

  • ai_evade_object
  • ai_set_evade_object
  • ai_maybe_evade_locked_missile
  • maybe_evade_dumbfire_weapon

Mode: AIM_SAFETY

Search for a safety spot.

Enterring AIM_SAFETY:

  • ai_do_safety
  • ai_do_default_behavior

Mode: AIM_EVADE_WEAPON

Evade a weapon.

Enterring AIM_EVADE_WEAPON:

  • ai_maybe_evade_locked_missile
  • maybe_evade_dumbfire_weapon
  • ai_ship_hit

Guarding

Mode: AIM_GUARD

Enterring AIM_GUARD:

  • ai_set_guard_wing
  • ai_set_guard_object

Wandering

Mode: AIM_STILL

Enterring AIM_STILL:

  • ai_stay_still:

Set mode to AIM_STILL and objective direction view. This direction view is updated by ai_still so that the object turn towrds it.

Mode: AIM_STAY_NEAR

Enterring AIM_STAY_NEAR:

  • ai_do_stay_near

Mode: AIM_NONE

Enterring AIM_NONE:

  • ai_object_init
  • ai_set_guard_wing
  • maybe_hack_cruiser_chase_abort
  • ai_chase
  • ai_guard
  • ai_stay_near
  • ai_dock
  • ai_emerge_bay_path_cleanup
  • ai_bay_emerge
  • ai_bay_depart
  • ai_execute_behavior/AIM_CHASE, AIM_STRAFE
  • ai_do_default_behavior
  • init_ai_object
  • ai_deathroll_start

Following path

Mode: AIM_WAYPOINTS

Enterring AIM_WAYPOINTS:

  • ai_start_waypoints

Mode: AIM_PATH

Enterring AIM_PATH:

  • FIXME

Flying to a ship

Enterring AIM_FLY_TO_SHIP:

  • ai_start_fly_to_ship

Strafing

Enterring AIM_STRAFE:

  • See aibig.

Big ship

Mode: AIM_BIGSHIP

Enterring AIM_BIGSHIP:

  • This state is constant and certainly set at big ship's creation.

Mode: AIM_SENTRYGUN

Enterring AIM_SENTRYGUN:

  • ai_do_default_behavior

Emerging bay

Mode: AIM_BAY_EMERGE

Enterring AIM_BAY_EMERGE:

  • ai_acquire_emerge_path

Mode: AIM_BAY_DEPART

Enterring AIM_BAY_DEPART:

  • ai_acquire_depart_path

Warping

Mode: AIM_WARP_OUT

Enterring AIM_WARP_OUT:

  • ai_set_mode_warp_out


Waypoints

ai_start_waypoints find_nearest_waypoint create_waypoints

ai_waypoints

Make player object fly waypoints.

Code map

Waypoints

ai_start_waypoints find_nearest_waypoint create_waypoints

ai_waypoints

Make player object fly waypoints.

    1. ----------------------------------------------------------------------------

Code map

Geometrical

Pure math functions

  • compute_dots
  • project_point_to_perimeter
  • get_tangent_point
  • ai_matrix_dist
  • update_min_max

Mixed

  • turn_towards_point
  • turn_away_from_point
  • turn_towards_tangent
  • turn_toward_tangent_with_axis
  • get_tangent_point
  • get_nearest_bbox_point
  • bisect_chord (call add_path_point!?)
  • get_enemy_team_range

Physical

  • fds_aux
  • pp_collide_any
  • compute_collision_time
  • might_collide_with_ship
  • might_hit_teammate
  • will_collide_pp
  • will_collide_with_big_ship
  • will_collide_with_big_ship_all
  • force_avoid_player_check
  • maybe_avoid_player
  • avoid_ship
  • avoid_player
  • compute_time_to_enemy
  • adjust_accel_for_docking
  • accelerate_ship
  • change_acceleration
  • set_accel_for_target_speed
  • set_accel_for_docking
  • attack_set_accel
  • static_rand_timed
  • set_predicted_enemy_pos_turret
  • set_predicted_enemy_pos

Accessors

  • is_instructor
  • object_is_targetable
  • num_enemies_attacking
  • num_turrets_attacking
  • num_nearby_fighters
  • compute_num_homing_objects
  • get_wing_lowest_max_speed
  • is_ignore_object_sub
  • find_ignore_new_object_index
  • is_ignore_object
  • compact_ignore_new_objects
  • get_enemy_timestamp
  • FIXME: inline get_ai_info(object *obj) { return & Ai_info[Ships[obj->instance].ai_index] }

Behavioral

Waypoints

  • add_path_point
  • create_path_to_point
  • copy_xlate_model_path_points
  • create_model_path
  • create_model_exit_path
  • ai_find_path
  • get_base_path_info
  • modify_model_path_points
  • maybe_recreate_path
  • ai_path
  • ai_start_waypoints
  • find_nearest_waypoint
  • ai_waypoints

Attacking/Evading

  • evaluate_object_as_nearest_objnum
  • get_nearest_objnum
  • find_nearby_threat
  • find_enemy
  • ai_attack_object
  • ai_attack_wing
  • ai_chase_ct
  • ai_chase_eb
  • ai_endangered_time
  • ai_endangered_by_weapon
  • ai_near_full_strength
  • get_behind_ship
  • ai_evade_object
  • evade_weapon
  • ai_evade
  • slide_face_ship
  • evade_ship
  • ai_do_safety
  • ai_safety_pick_spot
  • ai_safety_goto_spot
  • ai_safety_circle_spot
  • ai_safety

Docking/Repairing/Rearming

  • ai_set_goal_maybe_abort_dock
  • ai_do_objects_docked_stuff
  • ai_do_objects_undocked_stuff
  • ai_dock_with_object

Neutral

  • ai_stay_still
  • ai_do_stay_near
  • ai_form_on_wing
  • ai_formation_object_get_slotnum
  • ai_ignore_object
  • ai_ignore_wing
  • ai_start_fly_to_ship
  • ai_fly_to_ship

Firing

  • maybe_resume_previous_mode
  • ai_maybe_fire_afterburner
  • maybe_afterburner_after_ship_hit
  • ai_select_primary_weapon_OLD
  • ai_select_primary_weapon
  • set_primary_weapon_linkage
  • ai_fire_primary_weapon
  • ai_select_secondary_weapon
  • ai_fire_secondary_weapon
  • ai_maybe_announce_shockwave_weapon
  • compute_incoming_payload
  • check_ok_to_fire
  • ai_get_weapon_dist
  • ai_get_weapon_speed

Misc

  • ai_set_positions

Rendering (debug)

  • render_all_ship_bay_paths
  • render_all_subsys_paths
  • render_path_points

(Still not sorted)

  • ai_good_secondary_time
  • is_preferred_weapon
  • ai_init_secondary_info
  • ai_set_rearm_status
  • ai_good_time_to_rearm
  • garbage_collect_path_points
  • ai_init
  • ai_level_init
  • free_ai_stuff
  • Skill_level_names
  • parse_ai_class
  • reset_ai_class_names
  • parse_aitbl
  • hash
  • create_object_hash
  • is_object_stealth_ship
  • init_ai_stealth_info
  • get_skill_stealth_dist_scaler
  • get_skill_stealth_dot_scaler
  • ai_is_stealth_visible
  • update_ai_stealth_info_with_error
  • ai_update_danger_weapon
  • ai_turn_towards_vector
  • init_ship_info
  • set_target_objnum
  • set_targeted_subsys
  • ai_object_init
  • turn_away_from_point
  • is_ignore_object_sub
  • find_ignore_new_object_index
  • is_ignore_object
  • compact_ignore_new_objects
  • ai_near_full_strength
  • mabs_pick_goal_point
  • maybe_avoid_big_ship
  • compute_desired_rvec
  • ai_stealth_find
  • ai_stealth_sweep
  • ai_chase_attack
  • ai_chase_es
  • ai_chase_ga
  • ai_set_attack_subsystem
  • ai_set_guard_vec
  • ai_set_guard_wing
  • ai_set_evade_object
  • ai_set_guard_object
  • update_aspect_lock_information
  • ai_chase_fly_away
  • has_preferred_secondary
  • ai_choose_secondary_weapon
  • set_secondary_fire_delay
  • ai_chase_big_approach_set_goal
  • ai_chase_big_circle_set_goal
  • ai_chase_big_get_separations
  • ai_chase_big_parallel_set_goal
  • ai_cruiser_chase_set_goal_pos
  • maybe_hack_cruiser_chase_abort
  • ai_cruiser_chase
  • ai_chase
  • dock_move_towards_point
  • set_goal_dock_orient
  • find_parent_rotating_submodel
  • find_adjusted_dockpoint_info
  • dock_orient_and_approach
  • debug_find_guard_object
  • num_ships_attacking
  • remove_farthest_attacker
  • ai_maybe_limit_attackers
  • guard_object_was_hit
  • maybe_update_guard_object
  • ai_guard_find_nearby_bomb
  • ai_guard_find_nearby_ship
  • ai_guard_find_nearby_asteroid
  • ai_guard_find_nearby_object
  • get_cylinder_points
  • ai_big_guard
  • ai_guard
  • ai_do_objects_repairing_stuff
  • ai_cleanup_dock_mode_subjective
  • ai_cleanup_dock_mode_objective
  • ai_cleanup_rearm_mode
  • ai_still
  • ai_stay_near
  • maybe_dock_obstructed
  • ai_dock
  • ai_debug_render_stuff
  • process_subobjects
  • get_wing_index
  • get_wing_leader
  • get_wing_delta
  • gwlr_1
  • gwlr_object_1
  • get_wing_largest_radius
  • DCF
  • DCF
  • get_absolute_wing_pos
  • render_wing_phantoms
  • render_wing_phantoms_all
  • ai_fly_in_formation
  • ai_disband_formation
  • formation_is_leader_chaotic
  • ai_most_massive_object_of_its_wing_of_all_docked_objects_helper
  • ai_formation
  • ai_do_repair_frame
  • call_doa
  • ai_maybe_launch_cmeasure
  • ai_preprocess_ignore_objnum
  • ai_chase_circle
  • ai_transfer_shield
  • ai_balance_shield
  • ai_manage_shield
  • ai_maybe_evade_locked_missile
  • maybe_evade_dumbfire_weapon
  • ai_manage_bay_doors
  • ai_acquire_emerge_path
  • ai_emerge_bay_path_cleanup
  • ai_bay_emerge
  • ai_find_closest_depart_path
  • ai_acquire_depart_path
  • ai_bay_depart
  • ai_sentrygun
  • ai_execute_behavior
  • mrs_subsystem
  • num_allies_rearming
  • maybe_request_support
  • ai_set_mode_warp_out
  • ai_maybe_depart
  • ai_warp_out
  • ai_find_shockwave_weapon
  • ai_announce_ship_dying
  • ai_find_shockwave_ship
  • aas_1
  • ai_avoid_shockwave
  • ai_await_repair_frame
  • ai_maybe_self_destruct
  • ai_need_new_target
  • maybe_big_ship_collide_recover_frame
  • validate_mode_submode
  • ai_frame
  • create_waypoints
  • ai_process
  • init_ai_object
  • init_ai_objects
  • init_ai_system
  • ai_set_default_behavior
  • ai_do_default_behavior
  • process_friendly_hit_message
  • maybe_process_friendly_hit
  • maybe_set_dynamic_chase
  • firing_aspect_seeking_bomb
  • big_ship_collide_recover_start
  • ai_update_lethality
  • ai_ship_hit
  • ai_ship_destroy
  • ai_deathroll_start
  • ai_abort_rearm_request
  • ai_add_rearm_goal
  • ai_issue_rearm_request
  • ai_rearm_repair
  • ai_return_path_num_from_dockbay
  • cheat_fire_synaptic
  • maybe_cheat_fire_synaptic