-- The types of OpenReliant's scripting API, for Luau's language server (luau-lsp). Add this
-- file to its luau-lsp.types.definitionFiles setting under a name, such as "@openreliant", and
-- give each package's local its type, such as `local hooks: Hooks = require("openreliant.hooks")`,
-- for completion, descriptions and type checks. Generated by `openreliant hooks --definitions`
-- from OpenReliant's bindings; don't change it by hand.

-- Names of values. A value without a name is a number.

export type ShipType = "predator" | "naginata" | "grendel" | "crusader" | "coyote" | "mirage" | "tempest" | "patriot" | "wolverine" | "reaper" | "shroud" | "phoenix" | "reliant" | "yamato" | "alsace" | "kestrel" | "falco" | "victorious" | "endeavour" | "mitchell" | "bremen" | "arc_ship" | "ulysses" | "sai" | "nanny" | "galahad" | "hades" | "mule" | "lonestar" | "limpet_car" | "prowler" | "ripper" | "lueneburg" | "mammoth" | "intruder" | "sentry" | "goodwill" | "stork" | "sky_hawk" | "haidar" | "karak" | "salin" | "azan" | "sabre" | "lagg" | "kamov" | "saracen" | "salamander" | "scimitar" | "basilisk" | "kossac" | "yao" | "ramases" | "kozlov" | "morzov" | "badanov" | "pukov" | "xia" | "riza" | "cyclops" | "kurgan" | "sharov" | "gurevich" | "berijev" | "kirov" | "loki" | "kalan_shuttle" | "saladin" | "darkreign" | "stalag" | "antanov" | "kronstadt" | "boridin" | "troop_car" | "torpedo" | "ulysses_back" | "ulysses_fin" | "escape_pod" | "debris" | "debris_1" | "debris_2" | "debris_3" | "debris_4" | "debris_5" | "debris_6" | "debris_7" | "debris_8" | "debris_9" | "crewman" | "crewman_1" | "crewman_2" | "crewman_3" | "russian_torpedo" | "mammoth_back" | "baxter" | "neptune_hi" | "triton_hi" | "uranus_hi" | "saturn_hi" | "titan_hi" | "jupiter_hi" | "europa_hi" | "ganymede_hi" | "io_hi" | "calisto_hi" | "venus_hi" | "earth" | "kronstadt_wreck" | "planet_placeholder_4" | "proto_gate" | "advanced_gate" | "proximity_mine" | "black_box" | "satellite" | "mammoth_wreck_front" | "mammoth_wreck_back" | "proto_gate_panel" | "badanov_wreck_back" | "badanov_wreck_front" | "kurgan_wreck" | "krasnaya" | "asteroid_1" | "asteroid_2" | "asteroid_3" | "asteroid_4" | "asteroid_5" | "asteroid_6" | "asteroid_7" | "research_station" | "latov" | "gurevich_wreck_back" | "training_hoop" | "czar_docked" | "turret_asteroid_1" | "turret_asteroid_2" | "turret_asteroid_3" | "turret_asteroid_4" | "turret_asteroid_5" | "turret_asteroid_6" | "turret_asteroid_7" | "powerup_random" | "dm_beacon_gate" | "dm_beacon" | "pukov_wreck_back" | "other_escape_pod" | "cargo_pod" | "other_cargo_pod" | "grazer_gun_sat" | "archer_missile_sat" | "kafelnikof" | "reliant_wreck_back" | "stalag_doors" | "stalag_duct_cover" | "yakob_shuttle" | "krasny" | "varyag" | "other_ramases" | "fort_carter" | "koenig" | "washington" | "other_mitchell" | "ufelsky" | "kresta" | "krasnaya_left_arm" | "krasnaya_right_arm" | "rogue_base" | "kronstadt_arm" | "boridin_gun_dome" | "boridin_breakaway" | "darkreign_wreck_hat" | "yamato_wreck_back" | "maintenance_droid" | "maintenance_astronaut" | "rogue_base_wreck_top" | "tank" | "training_target" | "zakov" | "shell" | "rock_chunk" | "rock_chunk_tiny_1" | "rock_chunk_tiny_2" | "rock_chunk_tiny_3" | "rock_chunk_tiny_4" | "latov_wreck_1" | "latov_wreck_2" | "czar" | "zakov_wreck_back" | "sharov_wreck_back" | "limpet_pod" | "stalag_wreck_1" | "stalag_wreck_2" | "saladin_wreck" | "gegarin" | "krelov" | "kiev" | "kiev_wreck_back" | "baxter_wreck_top" | "victorious_wreck_front" | "mitchell_wreck_back" | "fort_bear" | "fort_sherman" | "neptune_lo" | "triton_lo" | "uranus_lo" | "saturn_lo" | "titan_lo" | "jupiter_lo" | "europa_lo" | "ganymede_lo" | "io_lo" | "calisto_lo" | "venus_lo" | "yamato_hangar" | "yamato_landing_bay" | "reliant_hangar" | "comms_relay" | "saladin_link" | "varyag_wreck_front" | "churchill" | "bokov" | "bulatov" | "shinnik" | "kovtun" | "late_escape_pod" | "other_late_escape_pod" | "fuel_pod" | "yevstafiy" | "mammoth_gulliver" | "mammoth_santa_maria" | "mammoth_rosario" | "mammoth_larsons_pride" | "mammoth_brittania" | "mammoth_sierra_madre" | "mammoth_mayan_gold" | "mammoth_dawn_chorus" | "mammoth_calysto" | "mammoth_sundown" | "mammoth_krenna" | "mammoth_seabound" | "mammoth_crimson_sky" | "asteroid_with_hole_1" | "asteroid_with_hole_2" | "asteroid_with_hole_3" | "asteroid_with_hole_4" | "t_predator" | "t_naginata" | "t_grendel" | "t_crusader" | "t_coyote" | "t_mirage" | "t_tempest" | "t_patriot" | "t_wolverine" | "t_reaper" | "t_shroud" | "t_phoenix" | "sun_marker" | "nebula_marker" | "dm_sphere_centre" | "beacon_marker" | "spawn_player" | "spawn_powerup" | "marker" | "stand_in" | number | string
export type ShipClass = "fighter" | "capital" | "support" | "other" | "torpedo" | "debris" | "mine" | "planet" | number
export type PilotNumber = "bandit_tigers_leader" | "diceman_tigers_leader" | "moose_tigers" | "tigers" | "moose_volunteers" | "volunteers" | "bandit_volunteers_leader" | "viper" | "fifty_first" | "black_guard" | "black_sun_leader" | "black_sun" | "blades" | "black_eagle_leader" | "black_eagle" | "ivan_petrov" | "nicolai_petrov" | "black_aces" | "bremen_bridge_officer" | "buccaneer" | "cat_foster" | "cobra" | "couger" | "coalition_comms_officer" | "coalition_fighter" | "coalition_scientist" | "endeavour_bridge_officer" | "enriquez_reliant_bridge" | "enriquez_yamato_bridge" | "enriquez_cockpit" | "foster_dead" | "fort_bear_comms" | "fort_baxter_comms" | "fort_carter_comms" | "fort_sherman_comms" | "gamma_dead" | "gamma_leader" | "golden_warrior" | "hellcat_leader" | "hellcat" | "hornet" | "jackel_leader" | "jackel" | "jaguar" | "kestrel_command" | "koenig_bridge_officer" | "kestrel_bridge_officer" | "kurgen" | "lonestar" | "mauler" | "mcgann" | "mitchell_bridge_officer" | "nanny_leader" | "pirate_leader" | "pirate" | "prowler" | "pukov_captain" | "puma_leader" | "puma" | "raven" | "reliant_bridge_officer" | "ripper" | "ronin_leader" | "ronin" | "russian_bomber" | "sabre_leader" | "sabre" | "saracen" | "scorpion_leader" | "scorpion" | "saladin_captain" | "stahl_bridge" | "stahl_marines" | "steiner_ejected" | "stinger" | "stork" | "ulysses_captain" | "ulysses_captain_panicking" | "steiner_vampires_leader" | "vampire" | "varyag_captain" | "victorious_bridge_officer" | "virtual_flight_instructor" | "washington_bridge_officer" | "yamato_bridge_officer" | "frenchy" | "silky" | "mayday" | "trigger" | "vixen" | "cutter" | "claymore" | "skippy" | "juice" | "face" | "hawkeye" | "arrow" | "nero" | "rhino" | "stalker" | "flash" | "stretch" | "talon" | "butcher" | "snapper" | "banshee" | "wolf" | "reaper" | "worm" | "wildcat" | "siron" | "ferret" | "poker" | "blade" | "scarlet" | "rico" | "slick" | "irish" | "spider" | "ego" | "diceman" | "captain_mukai" | "cat_foster_prowler" | "coalition_torpedo_leader" | "general_reese_pod" | "kulov_borodin" | "kulov_pod" | "mammoth_1" | "mammoth_2" | "mammoth_3" | "mammoth_4" | "saracen_leader" | "stahl_ripper" | "golden_warrior_leader" | "hornet_leader" | "mammoth_5" | "mammoth_6" | "mammoth_7" | "bandit" | "marauder_leader" | "marauder" | "marine_leader" | "marine" | "jaguar_leader" | "buccaneer_leader" | number | string
export type Side = "friendly" | "hostile" | "neutral" | number
export type Maneuver = "defend_dodge1" | "defend_dodge2" | "defend_dodge3" | "out_of_action_sphere" | "defend_runaway" | "attack_pursue" | "attack_massive_object" | "attack_medium_fighter" | "loop_the_loop" | "run_to_ship" | number
export type Invulnerability = "none" | "player_can_hit" | "full" | "eject_before_exploding" | number
export type Landing = "yamato" | "reliant" | "bay" | "badanov"
export type PartClass = "hull" | "cockpit" | "turret" | "engine" | "shield_generator" | "comms_transmitter" | "gravity_drive" | "laser_turret" | "missile_turret" | "power_core" | "satellite_dish" | "service_door" | "shaft" | "surface_building" | "twin_power_cores" | "vent_hatch" | "ion_cannon" | "armored_plate" | "cap_gun" | "warp_projector" | "fuel_pod" | number
export type AttachmentKind = "missile" | "gun" | "engine_glow" | "gun_muzzle" | "light" | "pod" | "eject_point" | "case_ejector" | "launch_point" | "dock_point" | number
export type MissileType = "none" | "screamer" | "raptor" | "havoc" | "jack_hammer" | "bandit" | "vagabond" | "solomon" | "imp" | "hawk" | "torpedo" | "fuel_pod" | number | string
export type TurretKind = "aimed" | "spinning" | "launcher"
export type GunType = "laser_cannon" | "pulse_cannon" | "messon_blaster" | "proton_cannon" | "gattling_lasers" | "tachyon_cannon" | "neutron_particle_gun" | "collapser_guns" | "gattling_plasma_cannon" | "vulcan_battery" | "nova_cannon" | "turret_flak" | "turret_lasers" | "allied_huge_gun" | "coalition_huge_gun" | number | string
export type Carrier = "reliant" | "yamato"
export type ObjectiveState = "hidden" | "listed" | "current" | number
export type GameVariable = "jump_ready" | "warp_ready" | "backup_available" | "player_missiles_left" | "mcgann_alive" | "nicolai_petrov_alive" | "ivan_petrov_alive" | "kulov_alive" | "mission_over" | "landing_cleared" | "al_rahan_alive" | "sharif_alive" | "steiner_alive" | "mission_success" | "players" | "krasnaya_alive" | "rameses_alive" | "kozah_alive" | "fixed_gate_alive" | "warp_gate_alive" | "last_success" | "objectives_met" | "czar_alive" | "ghost_alive" | "reliant_alive" | "countdown" | "chapter2_thread3_shown" | "red_dragon_alive" | "yamato_alive" | "ion_cannons_hold_lock" | number | string
export type RadioMode = "now" | "queued" | "if_idle" | number
export type FaceFilm = "talking" | "laughing" | "squadron" | "dying" | number
export type HudInstrument = "caption" | "key_prompt" | "jump_prompt" | "target_markers" | "eject_marker" | "scanner" | "lights" | "view_name" | "subtitle" | "messages" | "nav_marker" | "fuel" | "kills" | "countermeasures" | "ship_status" | "gauges" | "radar" | "reticle" | "clock" | "radio" | "gunnery" | "missiles" | "target_display" | "damage" | "power" | "big_target_display" | "objectives" | "comms" | "wing_status" | "beacon_counter" | "chat_input" | "arena_power_up" | "standings" | "dark_reign_relay" | "tag_bomb_timer" | "shadow_badge" | "vampire_badge" | "team_standings"
export type TargetForm = "small" | "large" | number
export type Quadrant = "left" | "right" | "fore" | "aft"
export type HudContactLook = "other" | "hostile" | "speaker" | "target" | "nav_point"
export type HudLight = "match_speed" | "blind_fire" | "smart_targeting" | "enemy_lock" | "missile_incoming" | "ecm" | "cloak" | "spectral_shields" | "reverse_thrust"
export type Action = "cockpit_camera" | "left_view_camera" | "right_view_camera" | "rear_view_camera" | "flyby_camera" | "target_camera" | "external_camera" | "missile_camera" | "next_enemy_target" | "previous_enemy_target" | "next_friendly_target" | "previous_friendly_target" | "next_subtarget" | "previous_subtarget" | "target_under_reticule" | "target_nearest_enemy" | "target_nearest_friendly" | "target_torpedo" | "smart_target" | "primary_target" | "afterburners" | "afterburner_toggle" | "reverse_thrust" | "jump_drive" | "match_speed" | "accelerate" | "decelerate" | "zero_throttle" | "full_throttle" | "roll_ship_clockwise" | "roll_ship_anti_clockwise" | "nose_up" | "nose_down" | "rotate_clockwise" | "rotate_anti_clockwise" | "strafe_left" | "strafe_right" | "joystick_roll" | "fire_lasers" | "full_guns" | "gunnery_window" | "gunnery_window_locked" | "synchronise_guns" | "toggle_blindfire" | "launch_missile" | "missile_window" | "rotate_missiles_clockwise" | "rotate_missiles_anticlockwise" | "comms_window" | "powerball_window" | "powerball_window_locked" | "full_power_to_gunnery" | "full_power_to_engines" | "full_power_to_shields" | "equalize_power" | "objectives_window" | "wing_status_window" | "wing_status_window_locked" | "damage_window" | "damage_window_locked" | "radar_ranges" | "shield_balancing" | "countermeasures" | "eject" | "cloak_ship" | "ecm" | "spectral_shields" | "attack_my_target" | "back_off" | "help_me" | "permission_to_land" | "display_kills" | "send_comms_message" | "key_config"
export type HudJumpPrompt = "jump" | "warp"
export type HudPart = "caption_text" | "caption_cursor" | "key_prompt_press" | "key_prompt_action" | "key_prompt_key" | "key_prompt_modifier" | "key_prompt_plus" | "view_name_text" | "subtitle_text" | "messages_text" | "fuel_figure" | "kills_figure" | "countermeasures_figure" | "gauges_speed" | "gauges_throttle" | "target_markers_range" | "clock_text" | "radio_speaker" | "radio_face" | "gunnery_gun" | "gunnery_rounds" | "missiles_count" | "missiles_name" | "target_display_name" | "target_display_pilot" | "target_display_range" | "target_display_speed" | "target_display_subtarget" | "damage_title" | "damage_names" | "power_title" | "power_figures" | "power_ball" | "objectives_title" | "objectives_heading" | "objectives_name" | "comms_title" | "comms_numbers" | "comms_items" | "wing_status_title" | "wing_status_numbers" | "target_display_beacons" | "chat_input_text" | "chat_input_caret" | "target_markers_relay" | "target_display_relay" | "tag_bomb_countdown" | "target_markers_bomb" | "target_display_bomb" | "shadow_badge_icon" | "vampire_badge_icon" | "target_markers_vampire" | "target_display_vampires_role" | "team_standings_badge" | "standings_team_badge" | "target_markers_team_badge"
export type HudWindowPhase = "shut" | "opening" | "closing" | "open"
export type Font = "default" | "hud" | "menu_small" | "menu_large"
export type Align = "left" | "center" | "right"
export type FrontEndScreen = "main_menu" | "game_options" | "audio" | "briefing" | "landing_movie" | "pilot_roster" | "saved_games" | "connection" | "video" | "controls" | "mods" | "mod_options" | "game_modes" | "mode_briefing" | "mode_ending" | "mod_catalog" | number
export type Key = "escape" | "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine" | "zero" | "minus" | "equals" | "backspace" | "tab" | "q" | "w" | "e" | "r" | "t" | "y" | "u" | "i" | "o" | "p" | "left_bracket" | "right_bracket" | "enter" | "left_control" | "a" | "s" | "d" | "f" | "g" | "h" | "j" | "k" | "l" | "semicolon" | "apostrophe" | "grave" | "left_shift" | "backslash" | "z" | "x" | "c" | "v" | "b" | "n" | "m" | "comma" | "period" | "slash" | "right_shift" | "keypad_multiply" | "left_alt" | "space" | "caps_lock" | "f1" | "f2" | "f3" | "f4" | "f5" | "f6" | "f7" | "f8" | "f9" | "f10" | "num_lock" | "scroll_lock" | "keypad_7" | "keypad_8" | "keypad_9" | "keypad_minus" | "keypad_4" | "keypad_5" | "keypad_6" | "keypad_plus" | "keypad_1" | "keypad_2" | "keypad_3" | "keypad_0" | "keypad_period" | "non_us_backslash" | "f11" | "f12" | "keypad_enter" | "right_control" | "keypad_divide" | "print_screen" | "right_alt" | "pause" | "home" | "up" | "page_up" | "left" | "right" | "end" | "down" | "page_down" | "insert" | "delete" | "left_windows" | "right_windows" | "menu" | number
export type Modifier = "none" | "shift" | "control" | "alt" | number
export type GamepadButton = "south" | "east" | "west" | "north" | "back" | "guide" | "start" | "left_stick" | "right_stick" | "left_shoulder" | "right_shoulder" | "dpad_up" | "dpad_down" | "dpad_left" | "dpad_right" | "misc1" | "right_paddle1" | "left_paddle1" | "right_paddle2" | "left_paddle2" | "touchpad" | "misc2" | "misc3" | "misc4" | "misc5" | "misc6" | "left_trigger" | "right_trigger" | "right_stick_up" | "right_stick_down" | "right_stick_left" | "right_stick_right"
export type BettyLine = "missiles_gone" | "armor_failing" | "screamer" | "havoc" | "jack_hammer" | "vagabond" | "imp" | "bandit" | "raptor" | "hawk" | "solomon" | "countermeasures_low" | "countermeasures_gone" | "cloak_on" | "cloak_off" | "blind_fire_on" | "blind_fire_off" | "spectral_shields_on" | "spectral_shields_off" | number
export type EffectStage = "before_hud" | "after_hud"
export type Axis = "x" | "y" | "z"
export type OptionKind = "toggle" | "choice" | "number" | "slider" | "text" | "heading"
export type RoomPlace = "news" | "itac" | "simulator" | "locker" | "cd_player"
export type Medal = "silver" | "black_eagle" | "valour" | "legion" | "navy_cross" | "medal_of_honour"
export type YamatoVisit = "never" | "always" | "when_reliant_lost"
export type RoomAction = "none" | "briefing" | "itac" | "fish_tank" | "animated" | "simulator" | "locker" | "news" | "unused" | "cd_player" | number
export type Ending = "playing" | "destroyed" | "rescued" | "captured" | "left" | "total_failure" | "friendly_fire" | "ejecting" | number
export type Rating = "total_failure" | "failure" | "partial_failure" | "partial_success" | "success" | "success_bonus" | number
export type DamageKind = "bullet" | "missile" | "collision" | "crash" | "screamer" | number
export type Order = "do_nothing" | "fly_aimlessly" | "launch_missile" | "launch_jack_hammer" | "warp_in" | "warp_out" | "fly" | "run_away" | "land" | "escort" | "find_new_target" | "explode" | "ripper_grabs_target_object" | "object_attach" | "formation_regroup" | "patrol_route" | "toggle_cloak" | "ship_follow_curve" | "slow_rotate" | "jump_in" | "jump_out" | "find_scoop_up" | "random_spin_slow" | "random_spin_medium" | "random_spin_fast" | "fixed_gate_jump_in" | "fixed_gate_jump_out" | "formation" | "fixed_gate_open" | "fixed_gate_close" | "eject" | "fixed_gate_collapse" | "match_speed" | "dark_reign_shoot" | "move_to_spawn_pos" | "turns_object_lights_on" | "make_boridin_section_break_away" | "rotate_boridin_breakaway_warp_projector" | "start_warp_projection_from_boridin" | "make_ripper_drop_what_its_carrying" | "jump_in_spread" | "jump_out_spread" | "turns_object_lights_off" | "huuuuuuuge_explosion" | "immediately_set_ship_to_zero_velocity_and_rotation" | "fly_ship_backwards" | "player_control" | "multiplayer_control" | "avoid_target" | "torpedo" | "launch" | "fight" | "abandoned" | "scoop_up" | "eject_spin" | "dock" | "fire_ion_cannon" | "ripper_end_drop_object" | "ripper_attach_cargo_pod_to_mammoth" | "eject_fighter_attack" | "disrupted" | "make_capship_list_left" | "make_capship_list_right" | "friendly_fire" | "eject_player" | "ship_follow_curve_backwards" | "mill" | "deathmatch_respawn_effect" | "deathmatch_dark_reign_target" | number
export type OrderPushed = "refused" | "taken" | "conflict"
export type MissionCommand = "print_ship_name" | "create_timer" | "destroy_timer" | "create_flight_group" | "destroy_flight_group" | "wait" | "play_speech" | "wait_for_speech" | "play_comms_movie" | "wait_for_movie" | "print_debug_message" | "set_ai" | "clear_ai" | "set_patrol_route" | "set_pilot" | "set_trigger_state" | "start_director_cam" | "start_ship_animation" | "ship_follow_curve" | "setup_launch" | "start_launch" | "display_sub_title" | "reset_code_priority" | "interrupt_trigger_code" | "comms_from_ship" | "comms_from_pilot" | "set_invulnerability" | "moving_ship_follow_curve" | "disable_object" | "position_relative" | "when_player_last_jumped" | "start_missile_cam" | "start_chase_cam" | "set_player_target" | "set_targetable" | "play_music" | "stop_director_cam" | "set_action_centre" | "dock" | "disable_taunts" | "fly" | "comms_from_ship_once" | "comms_from_pilot_once" | "disable_lights" | "set_environment_fx" | "multi_player_sync" | "disable_generic_comms" | "disable_guns" | "set_nav_point" | "set_escort_point" | "reset_after_burners" | "disable_missiles" | "disable_engines" | "disable_eject" | "set_hostile" | "reset_to_spawn_positions" | "update_environment_fx_state" | "set_primary_target" | "wait_for_jump_or_launch" | "do_not_disturb" | "set_environment_fx_nebula" | "start_ship_animation_reverse" | "snap_to_point" | "play_fosters_last_stand" | "open_instrument" | "close_instrument" | "destroy_sub_object" | "set_objective" | "set_rescue_probabilities" | "is_ship_this_player" | "set_flyback_marker" | "reset_flyback_marker" | "stop_ship_animation" | "set_ship_avoidance" | "match_speed" | "moving_ship_backup_curve" | "wait_for_key" | "terminate_mission" | "turret_set_target" | "set_any_trigger_state" | "wait_for_director_cam" | "kill_all_script_execution_execpt_me" | "stack_director_cam" | "scanner" | "replace_sub_object" | "fire" | "multiplayer_script_sync" | "friendly_fire" | "cloak" | "replenish_weapons" | "wills_blag" | "show_hud_icon" | "disable_listing" | "disable_object_at_next_jump" | "darrens_naughty_blag"
export type MissionCommandResult = "wait" | "run_on" | "hold" | number
export type RestartChoice = "replay_from_briefing" | "replay_from_launch" | "main_menu"
export type Condition = "shot_at" | "destroyed" | "launched" | "camera_reached" | "ship_reached" | "proximity_close" | "proximity_general" | "object_scooped" | "player_ready_to_jump" | "jumped_in" | "fixed_gate_jumped_in" | "player_ready_to_warp" | "jumped_through_hoop" | "player_wants_backup" | "ripper_grabbed_object" | "ripper_dropped_object" | "cloaked" | "decloaked" | "targetted" | "player_l1_doubletap" | "player_l2_doubletap" | "player_r1_doubletap" | "player_r2_doubletap" | "player_l1_l2_r1_r2_pressed" | "player_l1_r1_pressed" | "game_timer_expired" | "tractor_beam_locked" | "tractor_beam_broken" | "inside_object" | "outside_object" | "docked" | "undocked" | "being_chased" | "call_reinforcements" | "explosion_ship" | number
export type PilotTier = "level_0" | "level_1" | "level_2" | number
export type PilotSkill = "low" | "medium" | "high" | number
export type View = "cockpit" | "cockpit_left" | "cockpit_right" | "cockpit_rear" | "chase" | "spectator" | "launch_bay" | "launch_below" | "launch_aside" | "landing_tube" | "landing_aside" | "jump_out" | "jump_in_close" | "jump_in_ahead" | "jump_in_aside" | "target" | "external" | "director" | "pull_back" | "missile" | "eject" | "pickup" | "pod_shot" | "watch" | "watch_marker" | "flyby" | "nanny_dock" | "warp_prepare" | "warp_depart" | "warp_arrive" | "landing_bay" | "landing_ship" | "yamato_beside" | "yamato_ahead" | "yamato_aside" | number

-- Tables of values, which scripts can only read.

export type Orientation = {
    right: vector,
    down: vector,
    forward: vector,
}
export type Target = {
    object: Object?,
    component: number?,
    flight_group: number?,
    squad: number?,
}
export type Quadrants = {
    left: number,
    right: number,
    fore: number,
    aft: number,
}
export type ShipPart = {
    name: string,
    class: PartClass?,
    parent: number?,
    component: number?,
    armor: number?,
    full_armor: number?,
    invulnerable: Invulnerability?,
    destroyed: boolean,
    damaged: boolean,
    position: vector?,
}
export type ShipAttachment = {
    part: number,
    kind: AttachmentKind,
    destroyed: boolean,
    position: vector?,
}
export type GameModeMission = {
    number: number,
    place: number,
    count: number,
}
export type GameMode = {
    name: string,
    label: string,
    description: string?,
    missions: { number | GameModeMissionTable },
    ship: ShipType?,
    loop: boolean?,
    campaign: boolean?,
    briefing: string?,
    briefing_room: Carrier?,
    walk_in: boolean?,
    loadout_ships: { ShipType }?,
    wing_pilots: { PilotNumber }?,
    debriefing: boolean?,
    ending: string?,
    records: string?,
}
export type GameModeMissionTable = {
    number: number,
    as: number?,
    objectives: { string }?,
    hologram: string?,
    last_word: string?,
}
export type Mission = {
    number: number,
    file: string,
}
export type OrderInfo = {
    name: string,
    priority: number,
    flags: OrderFlags,
}
export type OrderFlags = {
    players: boolean,
    one_shot: boolean,
    retaliate: boolean,
    avoidance: boolean,
    send_flight: boolean,
}
export type OrderEntry = {
    order: string | number,
    target: Target,
}
export type RadioLine = {
    mode: RadioMode?,
    face: FaceFilm?,
    once: boolean?,
}
export type HudGuns = {
    group: number,
    groups: number,
    all: boolean,
    synchronized: boolean,
    gun: GunType?,
    charge: number,
    full_charge: number,
    paired: boolean,
    rounds: number?,
}
export type HudMissiles = {
    armed: MissileType?,
    left: number,
    ring: { HudMissile },
}
export type HudMissile = {
    type: MissileType,
    left: number,
    place: number,
}
export type HudTargetDisplay = {
    form: TargetForm,
    name: string?,
    pilot: string?,
    range: number,
    speed: number,
    shields: HudArcs?,
    armor: HudArcs?,
    hits: { Quadrant },
    subtarget_class: PartClass?,
    subtarget: string?,
    subtarget_armor: number?,
    hull: number?,
}
export type HudArcs = {
    left: number,
    right: number,
    fore: number,
    aft: number,
}
export type HudRadar = {
    range: number,
    reach: number,
    zooming: boolean,
    rings: number,
    contacts: { HudContact },
}
export type HudContact = {
    object: Object,
    at: vector,
    height: number,
    look: HudContactLook,
}
export type HudGauges = {
    speed: number,
    asked: number,
    speed_share: number,
    throttle_share: number,
    throttle_brightness: number?,
    charge: number,
    nova: boolean,
}
export type HudShipStatus = {
    shields: HudArcs,
    armor: HudArcs,
    reserve_fore: number,
    reserve_aft: number,
    hits: { Quadrant },
}
export type HudCharges = {
    ecm: number?,
    cloak: number?,
    spectral_shields: number?,
}
export type HudClock = {
    minutes: number,
    seconds: number,
}
export type HudDamage = {
    weapons: number,
    engines: number,
    shields: number,
}
export type HudPower = {
    shields: number,
    weapons: number,
    engines: number,
}
export type HudWingman = {
    object: Object,
    number: number,
    armor: number,
}
export type HudObjectives = {
    showing: number?,
    list: { HudObjective },
}
export type HudObjective = {
    number: number,
    name: string?,
    current: boolean,
}
export type HudBounds = {
    left: number,
    top: number,
    right: number,
    bottom: number,
}
export type HudWindowState = {
    phase: HudWindowPhase,
    opened: number,
}
export type FillStyle = {
    color: vector?,
    alpha: number?,
}
export type ShapeStyle = {
    color: vector?,
    alpha: number?,
    scale: number?,
    sprites: string?,
}
export type TextStyle = {
    font: string?,
    base_font: Font?,
    color: vector?,
    alpha: number?,
    scale: number?,
    align: Align?,
}
export type LineStyle = {
    color: vector?,
    alpha: number?,
    width: number?,
}
export type Size = {
    width: number,
    height: number,
    ink: HudBounds?,
}
export type Pointer = {
    at: vector,
    down: boolean,
}
export type ActionDefinition = {
    label: string,
    key: Key?,
    modifier: Modifier?,
    button: number?,
    gamepad_button: GamepadButton?,
}
export type SoundOptions = {
    volume: number?,
    pitch: number?,
    loop: boolean?,
    pan: number?,
    object: Object?,
    at: vector?,
    near: number?,
    far: number?,
}
export type MusicOptions = {
    loop: boolean?,
    after_fade: boolean?,
}
export type Effect = {
    name: string,
    shader: string,
    stage: EffectStage?,
    order: number?,
    parameters: { number }?,
    enabled: boolean?,
}
export type SurfaceFunction = {
    name: string,
    shader: string,
    textures: { string }?,
    everywhere: boolean?,
    see_through: boolean?,
    writes_depth: boolean?,
    bloom: number?,
    parameters: { number }?,
    enabled: boolean?,
}
export type LightingFunction = {
    name: string,
    shader: string,
    parameters: { number }?,
    enabled: boolean?,
}
export type Page = {
    title: string,
    options: { Option },
}
export type Option = {
    key: string?,
    label: string,
    kind: OptionKind,
    default: (boolean | number | string)?,
    description: string?,
    choices: { Choice }?,
    min: number?,
    max: number?,
    step: number?,
}
export type Choice = {
    value: boolean | number | string,
    label: string,
}
export type ReportPart = {
    scene: string,
    movie: string?,
}
export type Debriefing = {
    failure: { string }?,
    partial_failure: { string }?,
    partial_success: { string }?,
    success: { string }?,
    success_bonus: { string }?,
}
export type NewsItem = {
    title: string,
    paragraphs: { string }?,
    picture: number,
}
export type VideoReport = {
    title: string,
    paragraphs: { string }?,
    still: number,
    movie: string,
    carrier: Carrier,
}
export type ChapterReport = {
    movie: string,
    unless: { GameVariable }?,
    sets: GameVariable?,
}
export type ManeuverMirror = {
    yaw: boolean?,
    pitch: boolean?,
    roll: boolean?,
}
export type ScreenRect = {
    x: number,
    y: number,
    width: number,
    height: number,
}
export type Outcome = {
    ending: Ending,
    rating: Rating,
}
export type HudLayout = {
    offset: vector?,
    scale: number?,
}
export type HudPartLayout = {
    offset: vector?,
    scale: number?,
    align: Align?,
    hidden: boolean?,
    text: string?,
}

-- Objects, missiles and turrets, which scripts hold by handles.

declare extern type Object with
    --- The slot it fills in the mission, from 0.
    slot: number
    --- Its type, such as `predator`.
    type: ShipType
    --- Its class, such as `fighter`; nil for an object without stats, such as a nav point.
    class: ShipClass?
    --- The pilot flying it, whose record sets how it flies and fights: a pilot of the game's by its number, one a mod adds by its qualified name, or `none`.
    pilot: PilotNumber
    --- The side it's on. Setting it changes its side, as a mission's SetHostile does.
    side: Side
    --- Where it is. Setting it moves it there at once, as a mission's SnapToPoint does.
    position: vector
    --- Where its axes point: to its right, down and forward, out of its nose (`openreliant.util`). Setting it turns it at once, its axes made unit length and at right angles first, the forward one keeping its direction.
    orientation: Orientation
    --- How far it moves in a simulation step, of which there are 25 a second. Setting it pushes it, and its engines carry on from there.
    velocity: vector
    --- How fast it moves: the length of its velocity.
    speed: number
    --- How far its model reaches from its middle.
    radius: number
    --- Whether it's the player's ship.
    is_player: boolean
    --- The session ID of the participant bound to this ship. It is nil in standalone play and for unbound ships. This read-only string stays the same when the participant changes ships. On a dedicated host it identifies remote pilots. Presentation scripts see the bindings available on their client.
    participant_id: string?
    --- The order it's following: one of the game's (`Order`), or a mod's by its qualified name; nil for none.
    order: (string | number)?
    --- The combat maneuver it flies while it follows the Fight order: one of the game's by its name (`Maneuver`), or one a mod adds by its number (`records.maneuvers`); nil while it follows another order.
    maneuver: Maneuver?
    --- What the order it's following is aimed at; nil while it follows none.
    target: Target?
    --- The object that last hit it; nil for none, or once that one has left the mission.
    last_attacker: Object?
    --- Its throttle: 1 is full, 2 the afterburner's and -1 reverse thrust's. Its order or its pilot usually sets it each frame.
    throttle: number
    --- How hard it rolls, from -1 to 1. Its order or its pilot usually sets it each frame.
    roll_input: number
    --- How hard it pitches, from -1 to 1. Its order or its pilot usually sets it each frame.
    pitch_input: number
    --- How hard it yaws, from -1 to 1. Its order or its pilot usually sets it each frame.
    yaw_input: number
    --- Whether its afterburner burns.
    afterburning: boolean
    --- The afterburner's fuel left, in seconds of burning. Setting it fills or drains the tank, from 0 up.
    afterburner_fuel: number
    --- How many countermeasures it has left.
    countermeasures: number
    --- Its shields in each quadrant. Each can be set from 0 to what a whole ship of its type has; an object without stats has no shields to set.
    shields: Quadrants
    --- Its armour in each quadrant. Each can be set from 0 to what a whole ship of its type has, and its guns, speed and shields' recharge follow, as damage wears them; an object without stats has no armour to set.
    armor: Quadrants
    --- The share of its armour it has left, from about 1 as it's made down to 0: its weakest quadrant against a quadrant's full armour. Nil for an object without stats.
    hull: number?
    --- What can harm it: anything for `none`, nothing for `full`, only a player's ship for `player_can_hit`, and anything for `eject_before_exploding`, though its pilot ejects first. Setting it is what a mission's SetInvulnerability does.
    invulnerable: Invulnerability
    --- Whether it has started to explode. It takes no more orders.
    exploding: boolean
    --- Whether its pilot has ejected. It takes no more orders.
    ejected: boolean
    --- Whether it's cloaked. Setting it cloaks or uncloaks it, as a mission's Cloak does, where its model can.
    cloaked: boolean
    --- Whether ships can target it. Setting it is what a mission's SetTargetable does: a type that can't be targeted stays so.
    targetable: boolean
    --- Whether its lights are on. Setting it is what a mission's DisableLights does.
    lights: boolean
    --- How the player's ship lands on it, as its type's record has it when it's made (`ShipTypeRecord.landing`); nil where the player can't land on it. Setting it lets the player land on this ship, or keeps the player off it, for the rest of the mission. PERMISSION TO LAND and a mission's land order only bring the player's ship down on a ship that offers a landing.
    landing: Landing?
    --- Whether it's left out of the mission's work, as a mission's DisableObject leaves it.
    disabled: boolean
    --- Whether its guns don't fire and its turrets rest, as a mission's DisableGuns sets.
    guns_disabled: boolean
    --- Whether it can't launch missiles, as a mission's DisableMissiles sets.
    missiles_disabled: boolean
    --- Whether its engines are off: its throttle held at 0, and no afterburner or reverse thrust, as a mission's DisableEngines sets.
    engines_disabled: boolean
    --- Whether the player can't eject from it, as a mission's DisableEject sets.
    eject_disabled: boolean
    --- Whether it keeps to its orders: it doesn't retaliate, come to another's help, rise to a taunt or take the wingmen's commands, as a mission's DoNotDisturb sets.
    do_not_disturb: boolean
    --- Whether it no longer keeps clear of other ships, as a mission's SetShipAvoidance sets.
    avoidance_disabled: boolean
    --- Whether the object is still in the mission. A handle stops being valid once its object is removed or its mission ends.
    function is_valid(self): boolean
    --- Gives it `order`, aimed at `target` or at nothing, as a mission's SetAI does: the order goes on top of its orders if the one it follows gives way. `component` aims it at one part of `target` instead of the whole ship, as a mission's orders can: for Launch, the carrier's launch gate, counting from 0; for Dock, the port. Returns whether it took. Global scripts can give any object orders, and an object's scripts their own object.
    function give_order(self, order: string | number, target: Object?, component: number?): boolean
    --- Starts its Launch, as a mission's StartLaunch does: the first Launch among its orders goes after the short random wait the game gives each ship. Returns whether it had a Launch to start. Global scripts can start any object's launch, and an object's scripts their own.
    function start_launch(self): boolean
    --- Sends the event `name` to the object's scripts, with `data`, which must be plain data. It arrives at the next update.
    function send_event(self, name: string, data: any): ()
    --- Starts the script `name` of the calling mod on the object, as an object script, and passes `data` to its `on_init`. Returns whether it started. Only global scripts can add scripts.
    function add_script(self, name: string, data: any?): boolean
    --- Stops the script `name` of the calling mod on the object. Returns whether it ran there. Only global scripts can remove scripts.
    function remove_script(self, name: string): boolean
    --- `hooks.add`, for the calls that concern this object only: a handler for the hook `name`, with an optional `filter`. Returns the handler's handle. Global scripts can hook any object, and an object's scripts their own.
    function hook(self, name: ObjectHookName, handler: (e: any) -> boolean?, filter: (Filter | (e: any) -> boolean)?): HookHandle
    --- Draws the object with the surface function `name`, the calling mod's by its own name or any mod's by the qualified one, reading `parameters`; nil draws it with its textures' functions again. Returns false if no function of that name is registered. Only player scripts can set it.
    function set_surface(self, name: string?, parameters: { number }?): boolean
    --- Its turrets: its guns that turn to aim, spin their barrels or launch missiles, destroyed ones included, in the order of its guns.
    function turrets(self): { Turret }
    --- Its parts, destroyed ones included, in the order the game numbers them: each part of its model, followed by the parts of the models that part carries, such as a turret's gun. Empty for an object without a model.
    function parts(self): { ShipPart }
    --- The attachment points on its parts, such as engine glows and missile hardpoints, part by part in the order of `object:parts()`.
    function attachments(self): { ShipAttachment }
    --- Destroys it the same way running out of armour does: a ship that lists components, such as a capital ship, loses its hull components, and any other ship explodes, unless its pilot ejects first. Returns false for an object that takes no damage, such as a nav point, and for one that is already exploding or jumping. Global scripts can destroy any object, and an object's scripts their own.
    function destroy(self): boolean
    --- Destroys its component number `component`, counting from 0, the same way a hit that takes its last armour does: the component blows up and takes the rest of its assembly with it, its damaged model shows in its place, and losing a hull part ends the ship. Returns false if the component is already destroyed, or the object is exploding or jumping. Global scripts can destroy any object's components, and an object's scripts their own.
    function destroy_component(self, component: number): boolean
end
declare extern type Missile with
    --- Its type, such as `raptor`, or the qualified name of one a mod adds.
    type: MissileType
    --- The object that launched it, or let it fall; nil once that one has left the mission.
    launcher: Object?
    --- What it flies at. Its guidance turns to a new target from the next frame.
    target: Target
    --- Whether it homes on its target and lights the target's missile warning, as the AI's missiles do; one that doesn't flies straight. As in the original, every missile homes but a player's Screamer outside a multiplayer game, unless a script sets it.
    homes: boolean
    --- The side it's on: its launcher's, as it was launched.
    side: Side
    --- Where it is. Setting it moves it there at once.
    position: vector
    --- Where its axes point: to its right, down and forward, out of its nose (`openreliant.util`). Setting it turns it at once, its axes made unit length and at right angles first, and its guidance turns on from there.
    orientation: Orientation
    --- How far it moves in a simulation step, of which there are 25 a second. Setting it pushes it, and its motor carries on from there.
    velocity: vector
    --- How fast it moves: the length of its velocity.
    speed: number
    --- Whether the missile is still in flight. A handle stops being valid once its flight ends or its mission ends.
    function is_valid(self): boolean
    --- Ends its flight now, as it ends when its time runs out: it blows up where it is, with a shockwave for a Havoc or an Imp. Global scripts can set off any missile, and a missile's own scripts their missile.
    function detonate(self): ()
end
declare extern type Turret with
    --- The object it's on.
    object: Object
    --- What it is: `aimed`, which turns to aim at a target of its own; `spinning`, a gun whose barrels spin up while its object's trigger is held; or `launcher`, which launches missiles. Nil once it's destroyed.
    kind: TurretKind?
    --- Whether it was destroyed with its base. It turns and fires no more.
    destroyed: boolean
    --- The type of the shots it fires; nil for a missile turret, or once it's destroyed.
    gun_type: GunType?
    --- Where its base is; nil once it's destroyed.
    position: vector?
    --- What it aims at: an aimed turret's and a missile turret's own target; nil for a spinning gun, which fires where its object points, or once it's destroyed. Setting it aims the turret, which turns to it, and nil leaves it to look for one.
    target: Target?
    --- Whether its object is still in the mission. A handle stops being valid once its object is removed or its mission ends.
    function is_valid(self): boolean
end

-- The records (`openreliant.records`).

declare extern type Ship with
    name: string
    max_speed: number
    inertia: number
    yaw_rate: number
    yaw_inertia: number
    pitch_rate: number
    pitch_inertia: number
    roll_rate: number
    roll_inertia: number
    shield_power: number
    armor_class: number
    afterburner_fuel: number
    shield_recharge: number
    gun_energy: number
    gun_recharge: number
    rounds: number
end
declare extern type ShipTypeRecord with
    targetable: boolean
    name: number
    class: ShipClass
    side: Side
    display: TargetForm
    landing: Landing?
end
declare extern type Gun with
    name: string
    range: number
    speed: number
    damage: Damage
    fire_rate: number
    shot_energy: number
end
declare extern type Damage with
    shield: number
    hull: number
end
declare extern type MissileRecord with
    name: string
    speed: number
    turn_rate: number
    flight_time: number
    damage: Damage
    lock_time: number
    decoy_chance: number
    lock_range: number
    component_damage: number
end
declare extern type Pilot with
    name: string
    tier_a: PilotTier
    tier_b: PilotTier
    tier_c: PilotTier
    skill: PilotSkill
end
declare extern type Face with
    name: number
    talking: string
    laughing: string
    squadron: string
    dying: string
end
declare extern type CampaignMission with
    hologram: string?
    speech: string?
    last_word: string?
    carrier: Carrier
    objectives: { string }
    date: string?
    tier: number?
    chapter: number?
    medal: Medal?
    induction: boolean
    lesson: boolean
    loadout_ships: { ShipType }?
    only_ship: ShipType?
    television_report: { ReportPart }
    debriefing: Debriefing
    news: { NewsItem }
    video_reports: { VideoReport }
    landing_carrier: Carrier
    yamato_visit: YamatoVisit
    chapter_reports: { ChapterReport }
    alpha_5_pilot: PilotNumber
    alpha_6_pilot: PilotNumber
    wing_twins: boolean
    flying_tigers: boolean
    second_part: boolean
    kamov_wing: boolean
    close_ion_cannons: boolean
    hurried_turrets: boolean
    ripper_from_below: boolean
    wide_advanced_gate: boolean
    counts_kills: boolean
    terminate_ends_well: boolean
    fort_bear_ending: boolean
    cobras_inquiry: boolean
    fifty_first_listed: boolean
end
declare extern type KillboardPilot with
    name: string
    squadron: string
    ship: string?
    kills: number
    mean: number
    spread: number
    portrait: number
    in_45th: boolean
    joins_at: number?
    leaves_after: number?
    sits_out: { number }
end
declare extern type CombatManeuver with
    name: string
    mirror: ManeuverMirror
    min_ticks: number
    max_ticks: number
    script: { string }
end
declare extern type Planet with
    type: ShipType
    spin: number
    tilt: number
    tilt_toward: number
    atmosphere_color: vector?
    atmosphere_inner: number
    atmosphere_outer: number
    atmosphere_surface: string?
    atmosphere_parameters: { number }
end
declare extern type CdPlayerTrack with
    piece: string
    name: string
end
declare extern type RoomView with
    movie: string?
    loop: string?
    label: string
    exits: { number }
    action: RoomAction
    hotspot: ScreenRect
    sound: number?
end
declare extern type GameVariableRecord with
    name: string?
    start: number?
    attempt: number?
    saved: boolean
end
export type Records = {
    ships: { [number | string]: Ship },
    ship_types: { [number | string]: ShipTypeRecord },
    guns: { [number | string]: Gun },
    missiles: { [number | string]: MissileRecord },
    pilots: { [number | string]: Pilot },
    faces: { [number | string]: Face },
    text: { [number | string]: string },
    itac_text: { [number | string]: string },
    --- The campaign's missions, by their numbers, in the order it flies them. Load scripts change it by assigning a new list.
    campaign: { number },
    --- The colour of the light the planets get, nil for the key lights' colour, (1, 1, 0.8), as the original lights them. Only the planets and their atmospheres take this light, so a mod can light them without lighting any other model. Load scripts set it.
    planet_light: vector?,
    --- The settings of each of the campaign's missions, by its number. Load scripts change their fields.
    missions: { [number]: CampaignMission },
    --- The KILLBOARD's pilots, numbered from 1. Load scripts change their fields.
    killboard: { [number]: KillboardPilot },
    --- The combat maneuvers the Fight order flies, numbered from 0 as the game numbers them. Load scripts change their fields and add new ones after the last.
    maneuvers: { [number]: CombatManeuver },
    --- The object types that the game sets up as planets when a mission makes them: lit by the sun alone, always drawn, and colliding with nothing. Each turns about its axis and leans as its entry says, and has its atmosphere. The original's are Neptune to Venus and their far models, in the order of their types. Load scripts can change their fields and add planets after the last one, such as Earth.
    planets: { [number]: Planet },
    --- The CD player's tracks, twelve to a page: the Reliant's, 1 to 12, then the Yamato's, 13 to 24. Load scripts change their fields, and add tracks after the last, up to 96 in all, on pages of their own.
    cd_player: { [number]: CdPlayerTrack },
    --- The rooms' views, the Reliant's and the Yamato's, numbered 1 to 125 in the order they are stored in the executable. Load scripts can change their fields.
    room_views: { [number]: RoomView },
    --- What the campaign does with each of the game's variables, by its number from 0 or by its name. Load scripts change their fields.
    game_variables: { [number | string]: GameVariableRecord },
}

-- The packages made from declarations. `openreliant.self` is the script's own Object.

--- OpenReliant's version, events for the global scripts, and game modes.
export type Core = {
    --- The version of OpenReliant, such as `0.7.0`.
    version: string,
    --- The qualified name of the game mode that runs, such as `arena:arena`; nil in the game's campaign, INSTANT ACTION and anywhere else.
    game_mode: string?,
    --- The mission the game mode that runs is at: the one flown, or between missions the one flown next. nil where no game mode runs.
    game_mode_mission: GameModeMission?,
    --- Registers a game mode, which the main menu's GAME MODES lists. The mod's name qualifies its `name`, and the screen shows its `label` and `description`. `missions` lists the missions it flies in turn: each is the number of a standard `.DTE` file of the game's or a mod's, or a table that also gives the number the mission flies as, the names of its objectives, and its `hologram` and `last_word` in the briefing room. `ship` is the ship the player flies them in; without it, each mission gives the ship. With `loop`, the mode starts again after its last mission. A `campaign` shows the restart screen after a mission is lost or left, and carries on from the mission the player reached. `briefing` names the mod's registered screen that the front end shows before each mission. `briefing_room`, `reliant` or `yamato`, then briefs each mission in that game's briefing room, with the loadout; with `walk_in`, the player walks into the room before each briefing, as in the campaign. `loadout_ships` lists the ships that loadout offers, in order, starting on the first, unless the mission lists its own `loadout_ships`. `wing_pilots` lists the pilots of the player's wingmen, Alpha 2 to 6, in place of the campaign's wing, which the missions flown as the campaign's numbers give the wingmen: each a pilot of the game's by its number, or one a mod adds by its qualified name, and `none` keeps a place's pilot. With `debriefing`, the ITAC debriefs each mission that goes on to the next. `ending` names the mod's registered screen that the front end shows after the last mission. `records` names the mod's script that changes the records for the mode's missions alone: it runs as a load script before each of them, and its changes go back as the mission ends. Only load and menu scripts can use it, as OpenReliant starts. Returns the mode's qualified name.
    register_game_mode: (definition: GameMode) -> string,
    --- Sends the event `name` to the global and mission scripts, with `data`, which must be plain data. It arrives at the next update.
    send_global_event: (name: string, data: any) -> (),
}

--- The mission's objects, the player's ship and the mission itself.
export type World = {
    --- The player's ship, while a mission runs; nil between missions.
    player: Object?,
    --- The mission that runs, with its `number` and its `file`'s name; nil between missions.
    mission: Mission?,
    --- The player's carrier: the ship the player launched from, unless a script sets another (`set_player_carrier`). PERMISSION TO LAND asks it, and its bridge speaks to the player. Nil where there is none, as in a mission the player starts in flight, and between missions.
    player_carrier: Object?,
    --- Every object in the mission, in the order of their slots.
    objects: () -> { Object },
    --- Every missile in flight, newest first.
    missiles: () -> { Missile },
    --- The current ship for an object's `participant_id` in this session. Returns nil between missions, after the participant leaves, or while they have no bound ship.
    participant_ship: (id: string) -> Object?,
    --- Makes `target`, or its component number `component`, the player's target, as a mission's SetPlayerTarget does: the display shows it, and the player stops matching speeds. Returns whether it worked: false for a target the player can't aim at, such as a destroyed component, and between missions.
    set_player_target: (target: Object, component: number?) -> boolean,
    --- Makes `target`, or its component number `component`, the mission's primary target, as a mission's SetPrimaryTarget does: the PRIMARY TARGET key selects it. Nil leaves the mission without one. Returns false between missions.
    set_primary_target: (target: Object?, component: number?) -> boolean,
    --- Objective `objective` of the mission that runs, numbered from 0 to 9 as a mission's SetObjective numbers them, takes `state`, as SetObjective does: `hidden`, `listed`, or `current`, which the objectives window then shows. Returns whether it changed: false between missions, and in a mission whose objectives nothing names.
    set_objective: (objective: number, state: ObjectiveState) -> boolean,
    --- The value of the game's variable `name` in the mission that runs, as the mission's script reads it. Nil between missions.
    variable: (name: GameVariable) -> number?,
    --- Sets the game's variable `name` to `value` in the mission that runs, as the mission's script sets it. The campaign keeps the value from one mission to the next where it keeps the variable. Returns false between missions.
    set_variable: (name: GameVariable, value: number) -> boolean,
    --- Makes `ship` the player's carrier (`player_carrier`): PERMISSION TO LAND asks it, its bridge answers, and the player's ship lands on it where it offers a landing (its `landing`). Nil leaves the player without a carrier. Returns false between missions.
    set_player_carrier: (ship: Object?) -> boolean,
}

--- The objects around the script's own object or missile.
export type Nearby = {
    --- The objects within `radius` of the script's object or missile, or of the player's ship for a player script, nearest first, without it.
    objects: (radius: number) -> { Object },
}

--- What the order table says of each order, the orders each object has, and ending them. An object's give_order gives orders.
export type Orders = {
    --- Registers an order, which `name` qualified with the mod's name names. `update` runs each frame on each ship that follows it, and returns false to end the order; `init` runs as it starts, and `exit` as it ends. They can't give or end orders. Returns the qualified name, which `give_order` and `orders.info` take. The order goes away when the scripts that registered it stop.
    register: (name: string, definition: {priority: number?, flags: OrderFlags?, init: ((ship: Object, target: Object?, seconds: number) -> ())?, update: (ship: Object, target: Object?, seconds: number) -> boolean?, exit: ((ship: Object, target: Object?, seconds: number) -> ())?}) -> string,
    --- The name, priority and flags of `order`: one of the game's, the calling mod's by its own name, or any mod's by the qualified one. Nil for an order that doesn't exist, or a mod's that failed.
    info: (order: string | number) -> OrderInfo?,
    --- The orders `object` has, the one it follows first, each with what it's aimed at. The ones below carry on as each ends.
    stack: (object: Object) -> { OrderEntry },
    --- Ends the order `object` follows, as an order ends itself: its exit runs, and the order below it carries on. Returns whether it had one. Global scripts can end any object's orders, and an object's scripts their own object's.
    cancel: (object: Object) -> boolean,
    --- Drops all of `object`'s orders, as a mission's ClearAI does, where the one it follows gives way. Returns whether they were dropped. Global scripts can drop any object's orders, and an object's scripts their own object's.
    clear: (object: Object) -> boolean,
}

--- Lines said on the radio, as a mission's comms commands say them.
export type Radio = {
    --- The ship `ship` says the speech file `speech` on the radio, a file of the game's or a mod's such as `ms_dice22_001.ut`, its pilot's face showing, as a mission's CommsFromShip does: at once, ending the line playing, unless `line` says otherwise. The line goes through the `radio_say` hook. A ship being destroyed, or a stand-in, says nothing. Returns whether the mission's radio took the line: false between missions.
    say: (ship: Object, speech: string, line: RadioLine?) -> boolean,
    --- Whether the radio is saying a line, or has lines waiting to be said: false between missions, and where nothing is heard.
    busy: () -> boolean,
    --- Pilot `pilot` says the speech file `speech` on the radio, with its face, as a mission's CommsFromPilot does: at once, ending the line playing, unless `line` says otherwise. The pilot is one of the game's by its name or number, or one a mod adds by its qualified name. The line goes through the `radio_say` hook. Returns whether the mission's radio took the line: false between missions.
    say_pilot: (pilot: PilotNumber, speech: string, line: RadioLine?) -> boolean,
}

--- Drawing over the flight display, while it's shown: text, lines and rectangles, in the window's pixels.
export type Hud = {
    --- The game's instruments the mods' displays stand in for this frame, which aren't drawn (`register_display`).
    replaced: { HudInstrument },
    --- Whether the game's instruments show this frame: during a mission, in the view ahead from the cockpit.
    instruments_shown: boolean,
    --- The player's guns as the gunnery window and the targeting cluster show them; nil outside a mission.
    guns: HudGuns?,
    --- The player's missiles as the missile window shows them; nil outside a mission.
    missiles: HudMissiles?,
    --- The target the display shows, with its subtarget as `component`; nil for none, or outside a mission.
    target: Target?,
    --- What the target display shows of its target, in either form, whether or not its window is open; nil without a target or while the display hides it, and outside a mission.
    target_display: HudTargetDisplay?,
    --- The radar: its range, and the contacts it shows; nil outside a mission.
    radar: HudRadar?,
    --- The kills the skull readout shows; nil outside a mission.
    kills: number?,
    --- The seconds of afterburner fuel the fuel readout shows; nil outside a mission.
    fuel: number?,
    --- The countermeasures the coil readout shows; nil outside a mission.
    countermeasures: number?,
    --- Whether the countermeasures readout was lit as the display last drew it: always in the view ahead from the cockpit, except while it's dark in a flash that `ShowHudIcon` sets; false outside the view ahead, and outside a mission.
    countermeasures_lit: boolean,
    --- The targeting cluster about the middle of the screen, as it shows the player's speed, throttle and guns; nil outside a mission.
    gauges: HudGauges?,
    --- The ship status indicator, as it shows the player's shields and armour; nil for a ship without them, or outside a mission.
    ship_status: HudShipStatus?,
    --- The status lights that show, steady or flashing, in the order the display packs them; none outside a mission.
    lights: { HudLight },
    --- The status lights lit as the display last drew them, in the order it packs them: those of `lights`, but a flashing one only while it's lit. A warning that flashes keeps its place in the grid while it's dark; a light that `ShowHudIcon` flashes gives its place up. None outside the view ahead from the cockpit, where the display draws no lights, and outside a mission.
    lights_lit: { HudLight },
    --- The charges of the player's ECM, cloak and spectral shields, which their lights show as bars under them, each from 0 to 1, or nil where the ship doesn't carry the device; nil outside a mission.
    charges: HudCharges?,
    --- The mission's clock as the display shows it: the countdown where the mission counts down, and the time played otherwise; nil outside a mission.
    clock: HudClock?,
    --- The view's name the display writes at the top of the screen, in the views it names; nil in the others, the view ahead from the cockpit among them, and outside a mission.
    view_name: string?,
    --- The date the launch types out at the foot of the screen, as far as it has typed it; nil while it isn't shown, and outside a mission.
    caption: string?,
    --- The damage window, as it shows how well the player's weapons, engines and shields still work as the armour wears, each from 0 to 1, whether or not the window is open; nil outside a mission.
    damage: HudDamage?,
    --- The power window, as it shows the shields', guns' and engines' shares of the player's power, as the whole percentages it writes, whether or not the window is open; nil outside a mission.
    power: HudPower?,
    --- The ships of the player's wing the wing status window shows, the player's first, whether or not the window is open; none outside a mission.
    wingmen: { HudWingman },
    --- The objectives window: the mission's objectives it can show, and the one it shows, whether or not the window is open; nil outside a mission.
    objectives: HudObjectives?,
    --- The items of the radio's menu the comms window lists, in order, as the number keys pick them, whether or not the window is open; none outside a mission.
    comms: { string },
    --- The message lines the display shows, oldest first; none outside a mission.
    messages: { string },
    --- The line `DisplaySubTitle` shows near the foot of the screen in the director's view, whichever view it's in; nil for none, and outside a mission.
    subtitle: string?,
    --- The name the radio's window writes over the speaker's face, while their line plays; nil while a line waits for the window, between lines, and outside a mission.
    speaker_name: string?,
    --- The action whose key `WaitForKey`'s prompt asks the player to press; nil while nothing waits, and outside a mission.
    key_prompt: Action?,
    --- The prompt that flashes in the view ahead for what the mission has ready: the warp's or the jump's; nil for none, and outside a mission.
    jump_prompt: HudJumpPrompt?,
    --- The game's windows that are open, opening or closing (`window_state`); none outside a mission.
    open_windows: { HudInstrument },
    --- Whether it's shown this frame, which is when what's drawn on it shows, and its other fields can be read.
    shown: boolean,
    --- The window's width, in pixels.
    width: number,
    --- The window's height, in pixels.
    height: number,
    --- Registers a display, which `name` qualified with the mod's name names. While the flight display shows, `frame` draws it with this package's functions each frame, until it's turned off with `set_display_enabled`. A failed `frame` turns off that display only. `replaces` lists the game's instruments it stands in for, which aren't drawn while it's on, `layout` moves and scales the instruments it names, and `parts` moves, scales, aligns, rewords or hides the parts of them it names; they keep working, and go back as they were as soon as it's turned off, fails or its mod stops. Returns the qualified name.
    register_display: (name: string, definition: {frame: (seconds: number) -> (), replaces: { HudInstrument }?, layout: { [HudInstrument]: HudLayout }?, parts: { [HudPart]: HudPartLayout }?}) -> string,
    --- Turns the display `name` on or off: the calling mod's by its own name, or any mod's by the qualified one. Returns whether it's registered.
    set_display_enabled: (name: string, enabled: boolean) -> boolean,
    --- Changes where the display `name` puts the game's instruments and their parts, after it registers: the calling mod's by its own name, or any mod's by the qualified one. `layout` and `parts` replace the display's, with the checks `register_display` makes; one left out stays as it was, and a mistake changes nothing. They go back as they were as soon as the display is turned off, fails or its mod stops. Returns whether it's registered.
    set_display_layout: (name: string, placement: {layout: { [HudInstrument]: HudLayout }?, parts: { [HudPart]: HudPartLayout }?}) -> boolean,
    --- Where the game's instrument `instrument` last drew, in the window's pixels, as the mods' displays place it, and even while one stands in for it; nil before it first draws, or outside a mission.
    bounds: (instrument: HudInstrument) -> HudBounds?,
    --- Where the part `part` of the game's instruments last drew, in the window's pixels, as the mods' displays place it, and even while one hides it; nil before it first draws, or outside a mission.
    part_bounds: (part: HudPart) -> HudBounds?,
    --- How far the game's window that holds `instrument` has opened, and whether it's opening or closing, as the display last moved it on, which it does in every view; for the comms, the further open of its two windows. Nil for an instrument outside the windows, and outside a mission.
    window_state: (instrument: HudInstrument) -> HudWindowState?,
    --- Draws a PNG from the calling mod at `at`, with `size` in window pixels (nil uses its native size), tinted by `style`. Files are cached for the script context; one that hasn't been drawn for 2 frames makes room for others when the cache is full.
    picture: (at: vector, file: string, size: vector?, style: FillStyle?) -> (),
    --- Draws the power window's ball, turning with the player's power setting as the window's does, whether or not the window is open, with its top left corner at `at` and `size` in window pixels (nil for its size on the game's display), tinted by `style`. Unlike the window's, it doesn't shake when the ship is hit. Only during a mission.
    power_ball: (at: vector, size: vector?, style: FillStyle?) -> (),
    --- Draws shape `index` with its anchor at `at`, in window pixels. The shape comes from the game's sprite set for this layer (the flight display's, or the front end screen's), or from the set that the style's `sprites` names. The style's `scale` multiplies its size in the game's pixels.
    shape: (at: vector, index: number, style: ShapeStyle?) -> (),
    --- Draws `text` at `at`, in pixels from the window's top left corner, in the game's font, as `style` says.
    text: (at: vector, text: string, style: TextStyle?) -> (),
    --- Draws a line from `from` to `to`, in pixels, as `style` says.
    line: (from: vector, to: vector, style: LineStyle?) -> (),
    --- Fills the rectangle between the corners `from` and `to`, in pixels, as `style` says.
    rectangle: (from: vector, to: vector, style: FillStyle?) -> (),
    --- The size of `text` in window pixels, as `text` draws it, and where its letters' pixels fall from the point it's drawn at: `style` is a text style, or just a number for its scale.
    measure: (text: string, style: (number | TextStyle)?) -> Size,
}

--- Drawing over the menus, the front end's screens and the pause menu, while they're shown: text, lines and rectangles, in the window's pixels.
export type Ui = {
    --- Where the pointer is, in pixels from the window's top left corner, and whether its left button is down; nil before it has been over the window.
    pointer: Pointer?,
    --- Whether it's shown this frame, which is when what's drawn on it shows, and its other fields can be read.
    shown: boolean,
    --- The window's width, in pixels.
    width: number,
    --- The window's height, in pixels.
    height: number,
    --- Registers a screen, which `name` qualified with the mod's name names. While it's shown (`show_screen`), `frame` draws it with this package's functions each frame, and `key` gets each key as it goes down and up. Returns the qualified name.
    register_screen: (name: string, definition: {frame: (seconds: number) -> (), key: ((key: Key, down: boolean) -> ())?}) -> string,
    --- Makes the calling mod's registered screen `name` stand in for the front end's own `screen`, such as `"main_menu"`: while the front end shows `screen`, it runs and draws the mod's screen in its place, over its background. nil gives `screen` back to the front end. Only menu scripts can use it. Returns whether the screen is registered.
    replace_screen: (screen: FrontEndScreen, name: string?) -> boolean,
    --- Asks the front end to go to its screen `screen`, or to the mod's screen that stands in for it. Only menu scripts can use it.
    go_to: (screen: FrontEndScreen) -> (),
    --- Asks the front end to start the game mode `name`: the calling mod's by its own name, or any mod's by the qualified one. Only menu scripts can use it. Returns whether the mode is registered.
    start_game_mode: (name: string) -> boolean,
    --- From a game mode's briefing screen, asks the front end to fly the mode's next mission (`core.game_mode_mission`). Only menu scripts can use it.
    launch_mission: () -> (),
    --- Plays the movie `name`, a Bink file of the game folder's or a mod's such as `"intro.bik"`, or a mod's WebM or Matroska file with the same name, on a cleared screen, as the front end shows its next frame. Escape or the pointer's right button ends it. Only menu scripts can use it.
    play_movie: (name: string) -> (),
    --- Asks the front end to quit the game. Only menu scripts can use it.
    quit: () -> (),
    --- Converts the point `at` on the game's 640 by 480 screen to window pixels, as the front end and the rooms centre that screen in the window. Use it to draw over a spot on one of their pictures.
    from_game_screen: (at: vector) -> vector,
    --- Converts the window pixel `at`, such as the pointer's position, to a point on the game's 640 by 480 screen. The inverse of `from_game_screen`.
    to_game_screen: (at: vector) -> vector,
    --- Shows the screen `name`: the calling mod's by its own name, or any mod's by the qualified one. Nil closes the screen shown. Returns whether it's registered.
    show_screen: (name: string?) -> boolean,
    --- Draws a PNG from the calling mod at `at`, with `size` in window pixels (nil uses its native size), tinted by `style`. Files are cached for the script context; one that hasn't been drawn for 2 frames makes room for others when the cache is full.
    picture: (at: vector, file: string, size: vector?, style: FillStyle?) -> (),
    --- Draws shape `index` with its anchor at `at`, in window pixels. The shape comes from the game's sprite set for this layer (the flight display's, or the front end screen's), or from the set that the style's `sprites` names. The style's `scale` multiplies its size in the game's pixels.
    shape: (at: vector, index: number, style: ShapeStyle?) -> (),
    --- Draws `text` at `at`, in pixels from the window's top left corner, in the game's font, as `style` says.
    text: (at: vector, text: string, style: TextStyle?) -> (),
    --- Draws a line from `from` to `to`, in pixels, as `style` says.
    line: (from: vector, to: vector, style: LineStyle?) -> (),
    --- Fills the rectangle between the corners `from` and `to`, in pixels, as `style` says.
    rectangle: (from: vector, to: vector, style: FillStyle?) -> (),
    --- The size of `text` in window pixels, as `text` draws it, and where its letters' pixels fall from the point it's drawn at: `style` is a text style, or just a number for its scale.
    measure: (text: string, style: (number | TextStyle)?) -> Size,
}

--- Whether keys are held, and the controls bound to actions.
export type Input = {
    --- Registers an action, which `name` qualified with the mod's name names, and which the controls screen lists by its `label` for the player to bind. A default key or button that's already taken stays unbound. Returns the qualified name, which `action_down` and `on_action` use. Only menu scripts can use it.
    register_action: (name: string, definition: ActionDefinition) -> string,
    --- Whether `key` is held down.
    key_down: (key: Key) -> boolean,
    --- Whether the controls bound to `action` are held: its key, or its joystick button. The action is one of the game's (`Action`), the calling mod's by its own name, or any mod's by the qualified one.
    action_down: (action: string | number) -> boolean,
}

--- The camera's view: which it is, switching it, and registering views of the mod's own.
export type Camera = {
    --- The view the camera shows: one of the game's (`View`), or a mod's by its qualified name; nil while no mission is shown.
    view: (string | number)?,
    --- Registers a camera view, which `name` qualified with the mod's name names. `frame` gives the camera's position and orientation each frame; its axes must be unit length, at right angles and right-handed. A failed `frame` goes back to the cockpit view. Returns the qualified name.
    register_view: (name: string, definition: {frame: (object: Object, seconds: number) -> {position: vector, orientation: Orientation}, letterbox: boolean?}) -> string,
    --- Switches to `view`, looking at `object`, or at the player's ship where it's nil. The view is one of the game's (`View`), the calling mod's by its own name, or any mod's by the qualified one. Returns whether it switched: a mission that holds the camera, or shows a cutaway, keeps it, and no more than 16 switches go through in one frame.
    set_view: (view: string | number, object: Object?) -> boolean,
}

--- Sounds: standard game sounds and mod sound files in 2D or 3D, the music, and Betty's lines.
export type Audio = {
    --- The name of the piece of music playing, as passed to `play_music`; nil if no music plays.
    music: string?,
    --- Plays `sound`: the number of a standard game sound (the menu and display sounds), or the name of a sound file in the script's mod, in any format mod sounds support. `options` is a table of settings, or a number for the volume. With `object` or `at`, the sound plays in 3D during a mission. Returns an ID for `stop_sound` and `sound_playing`, or nil if the sound doesn't play.
    play_sound: (sound: number | string, options: (number | SoundOptions)?) -> number?,
    --- Stops the sound with ID `id` if it is still playing. Does nothing if `id` is nil.
    stop_sound: (id: number?) -> (),
    --- Whether the sound with ID `id` is still playing, or paused with the game. False if `id` is nil.
    sound_playing: (id: number?) -> boolean,
    --- Plays the piece `name` from the game's music folder, or a mod's piece with that name, replacing the current music. The piece loops unless `options.loop` is false. With `options.after_fade`, it starts after the current music fades out, as mission music changes do.
    play_music: (name: string, options: MusicOptions?) -> (),
    --- Fades the music out, as the game does before a launch. A piece queued with `after_fade` starts when the fade ends.
    fade_music: () -> (),
    --- Stops the music at once, and drops any piece queued with `after_fade`.
    stop_music: () -> (),
    --- Betty says `line`. Returns whether she does.
    say: (line: BettyLine) -> boolean,
}

--- Post effects: GLSL fragment shaders from the mod, drawn over the whole frame, before the flight display or after it.
export type Postprocessing = {
    --- Registers a post effect: a GLSL fragment shader from the calling mod's file `shader`, drawn over the whole frame. `stage` is `"before_hud"` (the default) or `"after_hud"`, `order` sorts the effects of a stage, lower first, and `parameters` holds up to four numbers its shader reads. Returns the effect's name, qualified with the mod's. The file can include other files of the mod with `#include`. A shader that doesn't compile is an error, with its file and line. See the scripting guide for what the shader reads.
    register: (definition: Effect) -> string,
    --- Turns the calling mod's effect `name` on or off, by its own name or the qualified one. Returns whether the mod has it.
    set_enabled: (name: string, enabled: boolean) -> boolean,
    --- Sets the numbers the calling mod's effect `name` reads, up to four; those left out are 0. Returns whether the mod has it.
    set_parameters: (name: string, parameters: { number }) -> boolean,
}

--- Surface and lighting functions: GLSL functions from the mod that change how surfaces are lit.
export type Shaders = {
    --- Registers a surface function: a GLSL function `surface` from the calling mod's file `shader`, which changes a pixel before it is lit. It draws on the `textures` it names, on every lit surface without a function of its own where `everywhere` is true, and on the objects given it with `object:set_surface`. `parameters` holds up to four numbers it reads, and `bloom`, from 0 to 1, how much of its surfaces' light blooms. Returns the function's name, qualified with the mod's. The file can include other files of the mod with `#include`. A shader that doesn't compile is an error, with its file and line. See the scripting guide for what the function reads and sets.
    register_surface: (definition: SurfaceFunction) -> string,
    --- Registers a lighting function: a GLSL function `lighting` from the calling mod's file `shader`, which changes how much of each light reaches a pixel. One draws at a time: the enabled one registered last. `parameters` holds up to four numbers it reads. Returns the function's name, qualified with the mod's. The file can include other files of the mod with `#include`. A shader that doesn't compile is an error, with its file and line.
    register_lighting: (definition: LightingFunction) -> string,
    --- Turns the calling mod's function `name` on or off, by its own name or the qualified one. Returns whether the mod has it.
    set_enabled: (name: string, enabled: boolean) -> boolean,
    --- Sets the numbers the calling mod's function `name` reads on its textures and everywhere it draws, up to four; those left out are 0. Returns whether the mod has it.
    set_parameters: (name: string, parameters: { number }) -> boolean,
}

--- Sections of plain data for each mod: kept with the saved game, or in the game folder across every game.
export type Storage = {
    --- The section `name` of the calling mod's storage that's kept with the saved game, and starts empty with each new game. Global and object scripts change it; other scripts read it.
    game_section: (name: string) -> Section,
    --- The section `name` of the calling mod's storage that's kept in the game folder, across every game. Any script changes it.
    global_section: (name: string) -> Section,
}

--- Timers, kept with the saved game: game time for global and object scripts, real time for player and menu scripts.
export type Async = {
    --- Registers `handler` under `name`, for the timers of the mod's scripts of the same kind (and on the same object) to run. Register it as the script runs, so that a timer kept with a saved game finds it again after the game is loaded.
    register_timer: (name: string, handler: (data: any) -> ()) -> (),
    --- Runs the function registered under `name` once `seconds` have passed, with `data`, which must be plain data: seconds of game time for global and object scripts, and of real time for player and menu scripts.
    after: (seconds: number, name: string, data: any?) -> (),
}

--- Orientations, turning points between the world and an object's own frame, and angles. Luau's vector library has the rest of the vector maths.
export type Util = {
    --- The point of the world that `point` is in the frame of something at `position` turned as `orientation`: `point`'s x to its right, y down and z forward of it.
    to_world: (position: vector, orientation: Orientation, point: vector) -> vector,
    --- Where the point of the world `point` is in the frame of something at `position` turned as `orientation`: x to its right, y down and z forward of it.
    to_local: (position: vector, orientation: Orientation, point: vector) -> vector,
    --- The angle in radians between the forward axis of something at `position` turned as `orientation` and the direction to `point`: 0 dead ahead, pi straight behind.
    angle_off: (position: vector, orientation: Orientation, point: vector) -> number,
    --- The orientation whose forward axis points along `direction`, turned about its Y axis, then its X axis, with no roll, as the game turns a ship to look at something.
    look_at: (direction: vector) -> Orientation,
    --- `orientation` turned by `angle` radians about its own `axis`: right-handed, so about its Y axis, which points down, a positive angle turns its nose to the right.
    turn: (orientation: Orientation, axis: Axis, angle: number) -> Orientation,
    --- The angles in radians that `orientation` is turned by from looking along the world's Z axis, as the game reads them: x the pitch, y the yaw and z the roll.
    angles: (orientation: Orientation) -> vector,
    --- The orientation turned by `angles` in radians from looking along the world's Z axis, as `angles` gives them: about X, then Y, then Z.
    from_angles: (angles: vector) -> Orientation,
    --- `angle` in radians brought within half a turn either way, from -pi to pi.
    normalize_angle: (angle: number) -> number,
}

--- Reading the game's and the mods' files.
export type Vfs = {
    --- Reads the file `name` as a string of its bytes, the way the game does: a mod's copy (the latest mod's first), else the game folder's own file of that name, such as `missions\mission1.dte`, else the member of the game's `resource.hog`. Nil if there is none.
    read: (name: string) -> string?,
    --- Reads the calling mod's own file `name` as a string of its bytes. Nil if the mod doesn't have it.
    read_mod: (name: string) -> string?,
    --- Whether `vfs.read` would find the file `name`.
    exists: (name: string) -> boolean,
}

--- The options a mod offers the player on the mods screen: declaring the page, and reading the values.
export type Options = {
    --- Declares the page of options the mod offers on the mods screen: a title and up to 64 options. Each option has a `key` that scripts read it by, a `label`, a `kind` and a `default`. A `"toggle"` has a boolean default. A `"choice"` has `choices`, each a `value` and a `label`, and a default among their values. A `"number"` has `min`, `max` and `step`, and a default in the range, and arrows step it. A `"slider"` is a number with a knob to drag, for a wide range. A `"text"` is a line the player types, of up to 24 characters, with a string default. A `"heading"` has only a `label`, and splits a long page. An option may have a `description`, which the screen writes under the list while the pointer is on it. Only load and menu scripts can use it, as OpenReliant starts, and a mod has one page.
    register_page: (page: Page) -> (),
    --- The value of the option `key` of the calling mod's page: what the player set, or the default. A toggle is a boolean, a number is a number, and a choice is the value of the choice set.
    get: (key: string) -> boolean | number | string,
    --- Sets the option `key` of the calling mod's page to `value`, as the player does on the mods screen: a toggle to a boolean, a number to a number, which is held to its range, a choice to one of its values, and a text to a string of up to 24 characters. The value is kept, and menu scripts hear of the change (`on_option_changed`).
    set: (key: string, value: boolean | number | string) -> (),
}

--- Lines and text placed in the world, drawn over the flight display where the camera sees them, for debugging.
export type Debug = {
    --- Draws a line between the points `from` and `to` of the world, as `style` says, where the camera sees them.
    line: (from: vector, to: vector, style: LineStyle?) -> (),
    --- Draws `text` at the point `at` of the world, as `style` says, where the camera sees it.
    text: (at: vector, text: string, style: TextStyle?) -> (),
}

--- Where the player is in the carrier's rooms, and the list the CD player shows.
export type Rooms = {
    --- The carrier whose rooms are on screen; nil while they aren't, as in flight, in the front end, the in-game options and the briefing.
    carrier: Carrier?,
    --- The view the player stands in, or walks into, by its number in `records.room_views`; nil while the rooms aren't on screen.
    view: number?,
    --- The place whose screen shows: `itac`, `simulator`, `locker` or `cd_player`, or `news` while the television's report plays. Nil while the player walks the rooms, and while they aren't on screen.
    place: RoomPlace?,
    --- How many pages the CD player has: `records.cd_player`'s tracks twelve to a page, the Reliant's list on page 1, the Yamato's on page 2, and the tracks mods add on the pages after them.
    cd_player_pages: number,
    --- The page the CD player shows while it's open, from 1 to `cd_player_pages`; nil while it isn't open. It opens on its carrier's page, numbered 1 to 12 as the game numbers each list.
    cd_player_page: number?,
    --- Turns the CD player to page `page`, from 1 to `cd_player_pages`, while it's open, its rows numbered as `records.cd_player` numbers its tracks, from 13 on page 2. The piece chosen plays on, and the pieces that follow it come from its own page. Returns whether the CD player is open.
    set_cd_player_page: (page: number) -> boolean,
}

--- The interfaces other scripts offer, as `I.<name>`: those of the global scripts to global scripts, those of an object's scripts to the object's other scripts, and those of player and menu scripts to each other. Nil for one nobody offers.
export type Interfaces = {
    Flight: {
        to_world: (position: vector, orientation: Orientation, point: vector) -> vector,
        to_local: (position: vector, orientation: Orientation, point: vector) -> vector,
        look_at: (direction: vector) -> Orientation,
        angle_off: (position: vector, orientation: Orientation, point: vector) -> number,
        turn: (orientation: Orientation, axis: Axis, angle: number) -> Orientation,
    },
    AI: {
        register: (name: string, definition: {priority: number?, flags: OrderFlags?, init: ((ship: Object, target: Object?, seconds: number) -> ())?, update: (ship: Object, target: Object?, seconds: number) -> boolean?, exit: ((ship: Object, target: Object?, seconds: number) -> ())?}) -> string,
        info: (order: string | number) -> OrderInfo?,
        stack: (object: Object) -> { OrderEntry },
        cancel: (object: Object) -> boolean,
        clear: (object: Object) -> boolean,
        give_order: (self: Object, order: string | number, target: Object?, component: number?) -> boolean,
    },
    Combat: {
        add_hook: HooksAdd,
        after_hook: HooksAfter,
    },
    Carriers: {
        give_order: (self: Object, order: string | number, target: Object?, component: number?) -> boolean,
        start_launch: (self: Object) -> boolean,
        add_hook: HooksAdd,
        after_hook: HooksAfter,
    },
    Camera: {
        view: (string | number)?,
        register_view: (name: string, definition: {frame: (object: Object, seconds: number) -> {position: vector, orientation: Orientation}, letterbox: boolean?}) -> string,
        set_view: (view: string | number, object: Object?) -> boolean,
    },
    Controls: {
        register_action: (name: string, definition: ActionDefinition) -> string,
        key_down: (key: Key) -> boolean,
        action_down: (action: string | number) -> boolean,
    },
    HUD: {
        replaced: { HudInstrument },
        instruments_shown: boolean,
        guns: HudGuns?,
        missiles: HudMissiles?,
        target: Target?,
        target_display: HudTargetDisplay?,
        radar: HudRadar?,
        kills: number?,
        fuel: number?,
        countermeasures: number?,
        countermeasures_lit: boolean,
        gauges: HudGauges?,
        ship_status: HudShipStatus?,
        lights: { HudLight },
        lights_lit: { HudLight },
        charges: HudCharges?,
        clock: HudClock?,
        view_name: string?,
        caption: string?,
        damage: HudDamage?,
        power: HudPower?,
        wingmen: { HudWingman },
        objectives: HudObjectives?,
        comms: { string },
        messages: { string },
        subtitle: string?,
        speaker_name: string?,
        key_prompt: Action?,
        jump_prompt: HudJumpPrompt?,
        open_windows: { HudInstrument },
        shown: boolean,
        width: number,
        height: number,
        register_display: (name: string, definition: {frame: (seconds: number) -> (), replaces: { HudInstrument }?, layout: { [HudInstrument]: HudLayout }?, parts: { [HudPart]: HudPartLayout }?}) -> string,
        set_display_enabled: (name: string, enabled: boolean) -> boolean,
        set_display_layout: (name: string, placement: {layout: { [HudInstrument]: HudLayout }?, parts: { [HudPart]: HudPartLayout }?}) -> boolean,
        bounds: (instrument: HudInstrument) -> HudBounds?,
        part_bounds: (part: HudPart) -> HudBounds?,
        window_state: (instrument: HudInstrument) -> HudWindowState?,
        picture: (at: vector, file: string, size: vector?, style: FillStyle?) -> (),
        power_ball: (at: vector, size: vector?, style: FillStyle?) -> (),
        shape: (at: vector, index: number, style: ShapeStyle?) -> (),
        text: (at: vector, text: string, style: TextStyle?) -> (),
        line: (from: vector, to: vector, style: LineStyle?) -> (),
        rectangle: (from: vector, to: vector, style: FillStyle?) -> (),
        measure: (text: string, style: (number | TextStyle)?) -> Size,
    },
    Audio: {
        music: string?,
        play_sound: (sound: number | string, options: (number | SoundOptions)?) -> number?,
        stop_sound: (id: number?) -> (),
        sound_playing: (id: number?) -> boolean,
        play_music: (name: string, options: MusicOptions?) -> (),
        fade_music: () -> (),
        stop_music: () -> (),
        say: (line: BettyLine) -> boolean,
    },
    Missions: {
        player: Object?,
        mission: Mission?,
        player_carrier: Object?,
        objects: () -> { Object },
        missiles: () -> { Missile },
        participant_ship: (id: string) -> Object?,
        set_player_target: (target: Object, component: number?) -> boolean,
        set_primary_target: (target: Object?, component: number?) -> boolean,
        set_objective: (objective: number, state: ObjectiveState) -> boolean,
        variable: (name: GameVariable) -> number?,
        set_variable: (name: GameVariable, value: number) -> boolean,
        set_player_carrier: (ship: Object?) -> boolean,
    },
    Campaign: {
        mission: Mission?,
        send_global_event: (name: string, data: any) -> (),
    },
    FrontEnd: {
        pointer: Pointer?,
        shown: boolean,
        width: number,
        height: number,
        register_screen: (name: string, definition: {frame: (seconds: number) -> (), key: ((key: Key, down: boolean) -> ())?}) -> string,
        replace_screen: (screen: FrontEndScreen, name: string?) -> boolean,
        go_to: (screen: FrontEndScreen) -> (),
        start_game_mode: (name: string) -> boolean,
        launch_mission: () -> (),
        play_movie: (name: string) -> (),
        quit: () -> (),
        from_game_screen: (at: vector) -> vector,
        to_game_screen: (at: vector) -> vector,
        show_screen: (name: string?) -> boolean,
        picture: (at: vector, file: string, size: vector?, style: FillStyle?) -> (),
        shape: (at: vector, index: number, style: ShapeStyle?) -> (),
        text: (at: vector, text: string, style: TextStyle?) -> (),
        line: (from: vector, to: vector, style: LineStyle?) -> (),
        rectangle: (from: vector, to: vector, style: FillStyle?) -> (),
        measure: (text: string, style: (number | TextStyle)?) -> Size,
    },
    [string]: any,
}

--- A section of a mod's storage: its fields by name, each plain data. Reading one gives a copy.
export type Section = { [string]: any }

-- The hooks (`openreliant.hooks`). Each handler gets `e`, whose type is named after the hook.
-- Annotate it, as in `function(e: ObjectDamage)`: Luau doesn't work it out from the hook's name.

declare extern type HookHandle with
    --- Removes the handler. Returns whether it was there.
    function remove(self): boolean
end

--- The objects a handler is for: each test that's given must hold.
export type Filter = {
    object: Object?,
    type: (ShipType | { ShipType })?,
    class: (ShipClass | { ShipClass })?,
    side: (Side | { Side })?,
}

--- Damage to `object` from `attacker`. Its shield in `quadrant` takes `value` first. What gets through, times `factor`, damages its armour (`object_armor_damage`). `kind` says what dealt the damage.
declare extern type ObjectDamage with
    object: Object
    quadrant: Quadrant
    value: number
    factor: number
    attacker: Object
    kind: DamageKind
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): ()
end

--- Damage to the armour of `object` in `quadrant`, once its shield there is down: `value` from `attacker`, of `kind`. Armour below zero destroys the object (`object_destroyed`).
declare extern type ObjectArmorDamage with
    object: Object
    quadrant: Quadrant
    value: number
    attacker: Object
    kind: DamageKind
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): ()
end

--- Damage to one of the components of `object`, such as a capital ship's turret or engine: `value` from `attacker`, of `kind`.
declare extern type ComponentDamage with
    object: Object
    value: number
    attacker: Object
    kind: DamageKind
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): ()
end

--- How hard damage of `kind` lands on `object` at the game's difficulty: the result is what `value` becomes.
declare extern type DamageByDifficulty with
    object: Object
    kind: DamageKind
    value: number
    result: number
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): number?
end

--- The end of `object`: its pilot ejects, or it explodes. With `may_spin`, it may spin out as it goes; with `no_eject`, the player's pilot doesn't eject.
declare extern type ObjectDestroyed with
    object: Object
    may_spin: boolean
    no_eject: boolean
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): ()
end

--- `owner` fires a shot of `gun_type` from one of its guns. `heard` says whether the shot makes a sound.
declare extern type BulletFire with
    owner: Object
    gun_type: GunType
    heard: boolean
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): ()
end

--- The radio says a line: the speech file `speech`, its speaker's face playing the film `film`, as `mode` has it, at once (`now`), queued, or queued unless the radio is busy (`if_idle`). A handler can change the names, to say another line, or stop it, so that nothing is said and what waits for it goes on.
declare extern type RadioSay with
    speech: string
    film: string
    mode: RadioMode
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): ()
end

--- The player asks for PERMISSION TO LAND, with its key or the radio's menu, heard at most once in 500 ticks. The pilot asks, and the flight instructor answers in training, or else the player's carrier, where it offers a landing (`world.player_carrier`, the object's `landing`). Once the mission's script has set `landing_cleared`, the answer clears the ship, which lands; otherwise the carrier refuses. A handler that stops it can answer and land the ship its own way, such as with an order of its own.
declare extern type PermissionToLand with
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): ()
end

--- `launcher` launches a missile from one of its racks at `target`.
declare extern type MissileLaunch with
    launcher: Object
    target: Target
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): ()
end

--- One of the missile turrets of `launcher` launches a Screamer at `target`.
declare extern type MissileLaunchTurret with
    launcher: Object
    target: Target
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): ()
end

--- `object` is given `order`, aimed at `target`, on top of its orders. The result says whether it took: `"taken"`, `"refused"` where the object refuses it, the order it runs doesn't give way or it has too many, or `"conflict"` where the order it runs can't give way. A handler that stops the push leaves `"refused"`.
declare extern type OrderPush with
    object: Object
    order: Order
    target: Target
    result: OrderPushed
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): OrderPushed?
end

--- `object` ends the order it runs, which its exit runs for where it has started, and the order below starts again. The result says whether it had one. The orders a mod registers that OpenReliant removes, as the mod's scripts close or the object goes, pop without this hook.
declare extern type OrderPop with
    object: Object
    result: boolean
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): boolean?
end

--- `object`, a ship under the Fight order, chooses its next combat maneuver, which starts on its next update. The result is the maneuver: one of the game's by its name (`Maneuver`), or one a mod adds by its number (`records.maneuvers`). A handler that stops it without setting the result leaves no maneuver, and Fight chooses again on the ship's next update.
declare extern type FightChooseManeuver with
    object: Object
    result: Maneuver
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): Maneuver?
end

--- `object`, a ship under the Fight order, flies its combat maneuver for a frame (`object.maneuver`): the commands of its script run until one waits. A handler that stops it can fly the ship itself.
declare extern type ManeuverRun with
    object: Object
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): ()
end

--- `object` runs its current order, as it does each frame. Each order's routines have hooks of their own, such as `order_fight`.
declare extern type ObjectOrders with
    object: Object
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): ()
end

--- The mission's script runs one of its commands, `command`, on `arguments`: as many as the command takes, the first first, and 0 past them. They're the script's own values: numbers, and the places of the mission's ships and texts in its file. To change them, set `e.arguments` to a new list. The result is what the command gives: `"run_on"` lets the script's thread go on, `"wait"` ends its run until it runs next, and a number is the command's value, which lets it go on too. A handler that stops the command leaves `"run_on"`; one that stops it and sets `"hold"` has the thread wait, and run the command again, on the same arguments and through this hook, the next time it runs.
declare extern type VmCommand with
    command: MissionCommand
    arguments: { number }
    result: MissionCommandResult
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): MissionCommandResult?
end

--- The restart screen, after a mission is lost or left. Its result is the player's choice: `replay_from_briefing`, `replay_from_launch` or `main_menu`. A handler that stops it chooses without the screen: `main_menu`, unless it sets `e.result`.
declare extern type RestartScreen with
    result: RestartChoice
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): RestartChoice?
end

--- `object`, a fighter, turns on whoever last hit it, once it has taken enough damage lately and its order allows it.
declare extern type OrderRetaliate with
    object: Object
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): ()
end

--- What a hook on one of the order table's routines sees.
declare extern type OrderRoutine with
    object: Object
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): ()
end

--- A mission is lost or left, and `movie` plays before the restart screen. In the game's campaign, it is the pilot's funeral where `ending` is `destroyed`, the pilot in the enemy's hands where it is `captured`, the pilot's execution where it is `friendly_fire`, and none where the player left the mission. A game mode's mission plays none. `rating` is how the mission's script rated it, and `mission` is its number.
declare extern type MissionLost with
    ending: Ending
    rating: Rating
    mission: number
    movie: string?
    result: string?
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): string??
end

--- The pilot's career in the game's campaign ends after mission `mission`, and `movie` plays before the main menu: the pilot's transfer where `ending` is `rescued`, after too many pickups, and for a total failure (`ending` `total_failure`) the transfer or, after missions 25 and 27 without the Yamato, the shuttle at Fort Bear. `rating` is how the mission's script rated it.
declare extern type CareerOver with
    ending: Ending
    rating: Rating
    mission: number
    movie: string?
    result: string?
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): string??
end

--- Mission `mission` of the game's campaign awards the pilot `medal`, and `movie`, the medal's ceremony, plays.
declare extern type MedalCeremony with
    medal: Medal
    mission: number
    movie: string?
    result: string?
    --- Runs the rest of the call now: the handlers after this one, then the function.
    function original(self): string??
end

--- `attacker` hits `object`: its component number `component`, or the object as a whole when `component` is nil.
declare extern type ShotAt with
    object: Object
    attacker: Object
    component: number?
end

--- `object` is destroyed, or its component number `component`. `attacker` is what last hit it. Each ship is destroyed once, though its components can be destroyed before it.
declare extern type Destroyed with
    object: Object
    component: number?
    attacker: Object?
end

--- `object` has launched from its carrier.
declare extern type Launched with
    object: Object
end

--- `reached_by` has reached the mission's ship `ship`, a point on a curve it follows or the curve's end.
declare extern type ShipReached with
    ship: number
    reached_by: Object
end

--- The director's camera has reached the mission's ship `ship`, a point on its curve or the curve's end.
declare extern type CameraReached with
    ship: number
end

--- `other` stands close to `object`, within 20 times its radius: `distance` times it. The game looks once a second, and only while one of `object`'s triggers waits for it.
declare extern type ProximityClose with
    object: Object
    other: Object
    distance: number
end

--- `other` stands within the distance that one of `object`'s triggers names, counted in `object`'s radius: `distance` times it. The game looks once a second, and only while such a trigger waits for it.
declare extern type ProximityGeneral with
    object: Object
    other: Object
    distance: number
end

--- `object` has taken `scooped` aboard with its tractor beam.
declare extern type ObjectScooped with
    object: Object
    scooped: Object
end

--- JUMP DRIVE took the jump the mission had ready for `object`, the player's ship.
declare extern type PlayerReadyToJump with
    object: Object
end

--- `object` has jumped in.
declare extern type JumpedIn with
    object: Object
end

--- `object` has come in through the fixed gate `gate`.
declare extern type FixedGateJumpedIn with
    object: Object
    gate: Object
end

--- JUMP DRIVE took the warp the mission had ready for `object`, the player's ship.
declare extern type PlayerReadyToWarp with
    object: Object
end

--- REQUEST BACKUP brought the mission's backup for `object`, the player's ship.
declare extern type PlayerWantsBackup with
    object: Object
end

--- `object`, a Ripper, has `grabbed` aboard.
declare extern type RipperGrabbedObject with
    object: Object
    grabbed: Object
end

--- `object`, a Ripper, has let go of `dropped`, or fitted it to a ship.
declare extern type RipperDroppedObject with
    object: Object
    dropped: Object
end

--- `object` cloaks.
declare extern type Cloaked with
    object: Object
end

--- `object` uncloaks.
declare extern type Decloaked with
    object: Object
end

--- `object`, the player's ship, has gone into a ship through one of its trigger polygons, as into the Stalag's duct.
declare extern type InsideObject with
    object: Object
end

--- `object`, the player's ship, has come out of a ship through one of its trigger polygons.
declare extern type OutsideObject with
    object: Object
end

--- `object` has retrieved its limpet pod and left the docking port.
declare extern type Undocked with
    object: Object
end

--- `object` has docked.
declare extern type Docked with
    object: Object
end

--- The explosion that `object` set off is over.
declare extern type ExplosionShip with
    object: Object
end

--- `flown_by` has flown through `object`, a training hoop, from behind it.
declare extern type JumpedThroughHoop with
    object: Object
    flown_by: Object
end

--- A mission has started: number `number`, from the file `file`. Its first ships are there.
declare extern type MissionStarted with
    number: number
    file: string
end

--- The mission ends: `ending` says how it ended for the player, and `rating` how its script rated it.
declare extern type MissionEnded with
    ending: Ending
    rating: Rating
end

--- `object` has been added to the mission.
declare extern type ObjectAdded with
    object: Object
end

--- `object` is leaving the mission: it has blown up, or its slot is being reset. Its handle stops being valid after this.
declare extern type ObjectRemoved with
    object: Object
end

--- `missile` has been launched by `launcher`, or let fall from it. Its target is set.
declare extern type MissileAdded with
    missile: Missile
    launcher: Object?
end

--- The flight of `missile`, launched by `launcher`, ends: it has struck something or run out of time, and blows up. Its handle stops being valid after this. `launcher` is nil once it has left the mission.
declare extern type MissileRemoved with
    missile: Missile
    launcher: Object?
end

--- `object` has started `order`, which has come to the top of its orders. One-shot orders, which run once and end straight away, don't start.
declare extern type OrderStarted with
    object: Object
    order: Order
end

--- `object` has ended `order`, which it had started, as the order was popped or replaced.
declare extern type OrderEnded with
    object: Object
    order: Order
end

--- The mission's trigger number `trigger` has fired on an event of `condition`. It's one of `object`'s triggers, or a flight group's or a squad's when `object` is nil.
declare extern type TriggerFired with
    trigger: number
    condition: Condition
    object: Object?
end

--- The hooks, which `hooks.add` takes.
export type HookName = "object_damage" | "object_armor_damage" | "component_damage" | "damage_by_difficulty" | "object_destroyed" | "bullet_fire" | "radio_say" | "permission_to_land" | "missile_launch" | "missile_launch_turret" | "order_push" | "order_pop" | "fight_choose_maneuver" | "maneuver_run" | "object_orders" | "vm_command" | "restart_screen" | "order_retaliate" | "order_do_nothing" | "order_fly_aimlessly_init" | "order_fly_aimlessly" | "order_launch_missile" | "order_launch_jack_hammer" | "order_warp_in_init" | "order_warp_in" | "order_warp_out_init" | "order_warp_out" | "order_fly_init" | "order_fly" | "order_run_away" | "order_land_init" | "order_land" | "order_escort_init" | "order_escort" | "order_find_new_target" | "order_explode_init" | "order_explode" | "order_ripper_grabs_target_object_init" | "order_ripper_grabs_target_object" | "order_ripper_grabs_target_object_exit" | "order_object_attach_init" | "order_object_attach" | "order_formation_regroup_init" | "order_formation_regroup" | "order_patrol_route_init" | "order_patrol_route" | "order_toggle_cloak" | "order_ship_follow_curve_init" | "order_ship_follow_curve" | "order_ship_follow_curve_exit" | "order_slow_rotate" | "order_jump_in_init" | "order_jump_in" | "order_jump_out_init" | "order_jump_out" | "order_find_scoop_up" | "order_random_spin_slow_init" | "order_random_spin_medium_init" | "order_random_spin_fast_init" | "order_fixed_gate_jump_in_init" | "order_fixed_gate_jump_in" | "order_fixed_gate_jump_out_init" | "order_fixed_gate_jump_out" | "order_formation_init" | "order_formation" | "order_fixed_gate_open_init" | "order_fixed_gate_open" | "order_fixed_gate_close_init" | "order_fixed_gate_close" | "order_eject_init" | "order_eject" | "order_fixed_gate_collapse_init" | "order_fixed_gate_collapse" | "order_match_speed" | "order_dark_reign_shoot" | "order_move_to_spawn_pos" | "order_turns_object_lights_on_init" | "order_turns_object_lights_on" | "order_make_boridin_section_break_away_init" | "order_rotate_boridin_breakaway_warp_projector_init" | "order_start_warp_projection_from_boridin_init" | "order_start_warp_projection_from_boridin" | "order_make_ripper_drop_what_its_carrying_init" | "order_make_ripper_drop_what_its_carrying" | "order_turns_object_lights_off" | "order_huuuuuuuge_explosion" | "order_immediately_set_ship_to_zero_velocity_and_rotation" | "order_fly_ship_backwards" | "player_controls" | "order_multiplayer_control" | "order_avoid_target_init" | "order_avoid_target" | "order_torpedo_init" | "order_torpedo" | "order_launch_init" | "order_launch" | "order_fight_init" | "order_fight" | "order_abandoned_init" | "order_abandoned" | "order_scoop_up_init" | "order_scoop_up" | "order_scoop_up_exit" | "order_eject_spin_init" | "order_eject_spin" | "order_dock_init" | "order_dock" | "order_dock_exit" | "order_fire_ion_cannon_init" | "order_fire_ion_cannon" | "order_fire_ion_cannon_exit" | "order_ripper_end_drop_object_init" | "order_ripper_end_drop_object" | "order_ripper_attach_cargo_pod_to_mammoth_init" | "order_ripper_attach_cargo_pod_to_mammoth" | "order_eject_fighter_attack" | "order_disrupted_init" | "order_disrupted" | "order_disrupted_exit" | "order_make_capship_list_left" | "order_make_capship_list_right" | "order_friendly_fire_init" | "order_friendly_fire" | "order_eject_player_init" | "order_eject_player" | "order_ship_follow_curve_backwards_init" | "order_ship_follow_curve_backwards" | "order_ship_follow_curve_backwards_exit" | "order_mill_init" | "order_mill" | "order_deathmatch_respawn_effect_init" | "order_deathmatch_respawn_effect" | "order_deathmatch_respawn_effect_exit" | "order_first_step_init" | "mission_lost" | "career_over" | "medal_ceremony" | "shot_at" | "destroyed" | "launched" | "ship_reached" | "camera_reached" | "proximity_close" | "proximity_general" | "object_scooped" | "player_ready_to_jump" | "jumped_in" | "fixed_gate_jumped_in" | "player_ready_to_warp" | "player_wants_backup" | "ripper_grabbed_object" | "ripper_dropped_object" | "cloaked" | "decloaked" | "inside_object" | "outside_object" | "undocked" | "docked" | "explosion_ship" | "jumped_through_hoop" | "mission_started" | "mission_ended" | "object_added" | "object_removed" | "missile_added" | "missile_removed" | "order_started" | "order_ended" | "trigger_fired"

--- The hooks on the game's functions, which `hooks.after` takes.
export type FunctionHookName = "object_damage" | "object_armor_damage" | "component_damage" | "damage_by_difficulty" | "object_destroyed" | "bullet_fire" | "radio_say" | "permission_to_land" | "missile_launch" | "missile_launch_turret" | "order_push" | "order_pop" | "fight_choose_maneuver" | "maneuver_run" | "object_orders" | "vm_command" | "restart_screen" | "order_retaliate" | "order_do_nothing" | "order_fly_aimlessly_init" | "order_fly_aimlessly" | "order_launch_missile" | "order_launch_jack_hammer" | "order_warp_in_init" | "order_warp_in" | "order_warp_out_init" | "order_warp_out" | "order_fly_init" | "order_fly" | "order_run_away" | "order_land_init" | "order_land" | "order_escort_init" | "order_escort" | "order_find_new_target" | "order_explode_init" | "order_explode" | "order_ripper_grabs_target_object_init" | "order_ripper_grabs_target_object" | "order_ripper_grabs_target_object_exit" | "order_object_attach_init" | "order_object_attach" | "order_formation_regroup_init" | "order_formation_regroup" | "order_patrol_route_init" | "order_patrol_route" | "order_toggle_cloak" | "order_ship_follow_curve_init" | "order_ship_follow_curve" | "order_ship_follow_curve_exit" | "order_slow_rotate" | "order_jump_in_init" | "order_jump_in" | "order_jump_out_init" | "order_jump_out" | "order_find_scoop_up" | "order_random_spin_slow_init" | "order_random_spin_medium_init" | "order_random_spin_fast_init" | "order_fixed_gate_jump_in_init" | "order_fixed_gate_jump_in" | "order_fixed_gate_jump_out_init" | "order_fixed_gate_jump_out" | "order_formation_init" | "order_formation" | "order_fixed_gate_open_init" | "order_fixed_gate_open" | "order_fixed_gate_close_init" | "order_fixed_gate_close" | "order_eject_init" | "order_eject" | "order_fixed_gate_collapse_init" | "order_fixed_gate_collapse" | "order_match_speed" | "order_dark_reign_shoot" | "order_move_to_spawn_pos" | "order_turns_object_lights_on_init" | "order_turns_object_lights_on" | "order_make_boridin_section_break_away_init" | "order_rotate_boridin_breakaway_warp_projector_init" | "order_start_warp_projection_from_boridin_init" | "order_start_warp_projection_from_boridin" | "order_make_ripper_drop_what_its_carrying_init" | "order_make_ripper_drop_what_its_carrying" | "order_turns_object_lights_off" | "order_huuuuuuuge_explosion" | "order_immediately_set_ship_to_zero_velocity_and_rotation" | "order_fly_ship_backwards" | "player_controls" | "order_multiplayer_control" | "order_avoid_target_init" | "order_avoid_target" | "order_torpedo_init" | "order_torpedo" | "order_launch_init" | "order_launch" | "order_fight_init" | "order_fight" | "order_abandoned_init" | "order_abandoned" | "order_scoop_up_init" | "order_scoop_up" | "order_scoop_up_exit" | "order_eject_spin_init" | "order_eject_spin" | "order_dock_init" | "order_dock" | "order_dock_exit" | "order_fire_ion_cannon_init" | "order_fire_ion_cannon" | "order_fire_ion_cannon_exit" | "order_ripper_end_drop_object_init" | "order_ripper_end_drop_object" | "order_ripper_attach_cargo_pod_to_mammoth_init" | "order_ripper_attach_cargo_pod_to_mammoth" | "order_eject_fighter_attack" | "order_disrupted_init" | "order_disrupted" | "order_disrupted_exit" | "order_make_capship_list_left" | "order_make_capship_list_right" | "order_friendly_fire_init" | "order_friendly_fire" | "order_eject_player_init" | "order_eject_player" | "order_ship_follow_curve_backwards_init" | "order_ship_follow_curve_backwards" | "order_ship_follow_curve_backwards_exit" | "order_mill_init" | "order_mill" | "order_deathmatch_respawn_effect_init" | "order_deathmatch_respawn_effect" | "order_deathmatch_respawn_effect_exit" | "order_first_step_init" | "mission_lost" | "career_over" | "medal_ceremony"

--- The hooks that concern an object, which an object's `hook` takes.
export type ObjectHookName = "object_damage" | "object_armor_damage" | "component_damage" | "damage_by_difficulty" | "object_destroyed" | "bullet_fire" | "missile_launch" | "missile_launch_turret" | "order_push" | "order_pop" | "fight_choose_maneuver" | "maneuver_run" | "object_orders" | "order_retaliate" | "order_do_nothing" | "order_fly_aimlessly_init" | "order_fly_aimlessly" | "order_launch_missile" | "order_launch_jack_hammer" | "order_warp_in_init" | "order_warp_in" | "order_warp_out_init" | "order_warp_out" | "order_fly_init" | "order_fly" | "order_run_away" | "order_land_init" | "order_land" | "order_escort_init" | "order_escort" | "order_find_new_target" | "order_explode_init" | "order_explode" | "order_ripper_grabs_target_object_init" | "order_ripper_grabs_target_object" | "order_ripper_grabs_target_object_exit" | "order_object_attach_init" | "order_object_attach" | "order_formation_regroup_init" | "order_formation_regroup" | "order_patrol_route_init" | "order_patrol_route" | "order_toggle_cloak" | "order_ship_follow_curve_init" | "order_ship_follow_curve" | "order_ship_follow_curve_exit" | "order_slow_rotate" | "order_jump_in_init" | "order_jump_in" | "order_jump_out_init" | "order_jump_out" | "order_find_scoop_up" | "order_random_spin_slow_init" | "order_random_spin_medium_init" | "order_random_spin_fast_init" | "order_fixed_gate_jump_in_init" | "order_fixed_gate_jump_in" | "order_fixed_gate_jump_out_init" | "order_fixed_gate_jump_out" | "order_formation_init" | "order_formation" | "order_fixed_gate_open_init" | "order_fixed_gate_open" | "order_fixed_gate_close_init" | "order_fixed_gate_close" | "order_eject_init" | "order_eject" | "order_fixed_gate_collapse_init" | "order_fixed_gate_collapse" | "order_match_speed" | "order_dark_reign_shoot" | "order_move_to_spawn_pos" | "order_turns_object_lights_on_init" | "order_turns_object_lights_on" | "order_make_boridin_section_break_away_init" | "order_rotate_boridin_breakaway_warp_projector_init" | "order_start_warp_projection_from_boridin_init" | "order_start_warp_projection_from_boridin" | "order_make_ripper_drop_what_its_carrying_init" | "order_make_ripper_drop_what_its_carrying" | "order_turns_object_lights_off" | "order_huuuuuuuge_explosion" | "order_immediately_set_ship_to_zero_velocity_and_rotation" | "order_fly_ship_backwards" | "player_controls" | "order_multiplayer_control" | "order_avoid_target_init" | "order_avoid_target" | "order_torpedo_init" | "order_torpedo" | "order_launch_init" | "order_launch" | "order_fight_init" | "order_fight" | "order_abandoned_init" | "order_abandoned" | "order_scoop_up_init" | "order_scoop_up" | "order_scoop_up_exit" | "order_eject_spin_init" | "order_eject_spin" | "order_dock_init" | "order_dock" | "order_dock_exit" | "order_fire_ion_cannon_init" | "order_fire_ion_cannon" | "order_fire_ion_cannon_exit" | "order_ripper_end_drop_object_init" | "order_ripper_end_drop_object" | "order_ripper_attach_cargo_pod_to_mammoth_init" | "order_ripper_attach_cargo_pod_to_mammoth" | "order_eject_fighter_attack" | "order_disrupted_init" | "order_disrupted" | "order_disrupted_exit" | "order_make_capship_list_left" | "order_make_capship_list_right" | "order_friendly_fire_init" | "order_friendly_fire" | "order_eject_player_init" | "order_eject_player" | "order_ship_follow_curve_backwards_init" | "order_ship_follow_curve_backwards" | "order_ship_follow_curve_backwards_exit" | "order_mill_init" | "order_mill" | "order_deathmatch_respawn_effect_init" | "order_deathmatch_respawn_effect" | "order_deathmatch_respawn_effect_exit" | "order_first_step_init" | "shot_at" | "destroyed" | "launched" | "ship_reached" | "proximity_close" | "proximity_general" | "object_scooped" | "player_ready_to_jump" | "jumped_in" | "fixed_gate_jumped_in" | "player_ready_to_warp" | "player_wants_backup" | "ripper_grabbed_object" | "ripper_dropped_object" | "cloaked" | "decloaked" | "inside_object" | "outside_object" | "undocked" | "docked" | "explosion_ship" | "jumped_through_hoop" | "object_added" | "object_removed" | "missile_added" | "missile_removed" | "order_started" | "order_ended" | "trigger_fired"

export type HooksAdd = (name: HookName, handler: (e: any) -> boolean?, filter: (Filter | (e: any) -> boolean)?) -> HookHandle
export type HooksAfter = (name: FunctionHookName, handler: (e: any) -> boolean?, filter: (Filter | (e: any) -> boolean)?) -> HookHandle

export type Hooks = {
    --- Adds a handler that runs before the hook's function, or when its event happens.
    add: HooksAdd,
    --- Adds a handler that runs after the hook's function, which sees its result in e.result.
    after: HooksAfter,
}

-- What scripts return.

export type LoadScript = {
    engine_handlers: {
        on_records_loaded: (() -> ())?,
    }?,
}

export type GlobalScript = {
    engine_handlers: {
        on_init: ((data: any?) -> ())?,
        on_save: (() -> any?)?,
        on_load: ((saved: any?) -> ())?,
        on_update: ((seconds: number) -> ())?,
        on_step: (() -> ())?,
        on_mission_start: ((mission: Mission) -> ())?,
        on_mission_end: ((outcome: Outcome) -> ())?,
        on_object_added: ((object: Object) -> ())?,
        on_object_removed: ((object: Object) -> ())?,
        on_interface_override: ((base: { [any]: any }) -> ())?,
    }?,
    event_handlers: { [string]: (data: any) -> boolean? }?,
    interface_name: string?,
    interface: { [any]: any }?,
}

export type ObjectScript = {
    engine_handlers: {
        on_init: ((data: any?) -> ())?,
        on_update: ((seconds: number) -> ())?,
        on_step: (() -> ())?,
        on_added: (() -> ())?,
        on_removed: (() -> ())?,
        on_interface_override: ((base: { [any]: any }) -> ())?,
    }?,
    event_handlers: { [string]: (data: any) -> boolean? }?,
    interface_name: string?,
    interface: { [any]: any }?,
}

export type PlayerScript = {
    engine_handlers: {
        on_init: ((data: any?) -> ())?,
        on_save: (() -> any?)?,
        on_load: ((saved: any?) -> ())?,
        on_frame: ((seconds: number) -> ())?,
        on_mission_start: ((mission: Mission) -> ())?,
        on_mission_end: ((outcome: Outcome) -> ())?,
        on_key_press: ((key: Key) -> ())?,
        on_key_release: ((key: Key) -> ())?,
        on_action: ((action: string) -> ())?,
        on_console_command: ((text: string) -> ())?,
        on_window_resized: ((width: number, height: number) -> ())?,
        on_room_changed: ((view: number?, place: RoomPlace?) -> ())?,
        on_music_changed: ((piece: string?) -> ())?,
        on_interface_override: ((base: { [any]: any }) -> ())?,
    }?,
    event_handlers: { [string]: (data: any) -> boolean? }?,
    interface_name: string?,
    interface: { [any]: any }?,
}

export type MenuScript = {
    engine_handlers: {
        on_init: ((data: any?) -> ())?,
        on_frame: ((seconds: number) -> ())?,
        on_mission_start: ((mission: Mission) -> ())?,
        on_mission_end: ((outcome: Outcome) -> ())?,
        on_key_press: ((key: Key) -> ())?,
        on_key_release: ((key: Key) -> ())?,
        on_action: ((action: string) -> ())?,
        on_console_command: ((text: string) -> ())?,
        on_window_resized: ((width: number, height: number) -> ())?,
        on_room_changed: ((view: number?, place: RoomPlace?) -> ())?,
        on_music_changed: ((piece: string?) -> ())?,
        on_interface_override: ((base: { [any]: any }) -> ())?,
        on_option_changed: ((key: string, value: boolean | number | string) -> ())?,
    }?,
    event_handlers: { [string]: (data: any) -> boolean? }?,
    interface_name: string?,
    interface: { [any]: any }?,
}
