Overview
The Aircraft class holds information about an aircraft in the simulation, including position, attitude, configuration, damage state, and packet history.
Constructor
Creates a new Aircraft instance.
Optional parent object reference (typically a Player instance)
Properties
Reference to the parent object (if any)
Aircraft identifier/model name (e.g., “F-15C”, “A-10A”)
position
list[float, float, float]
default:"[0,0,0]"
Aircraft position as [x, y, z] coordinates in meters
attitude
list[float, float, float]
default:"[0,0,0]"
Aircraft attitude as [pitch, yaw, roll] in radians
Initial configuration dictionary from ADDOBJECT packet (IFF, AFTBURNR, etc.)
Custom configuration values set by plugins or server logic
Current life/health value. -1 indicates uninitialized.
Previous life/health value for damage detection
Aircraft object ID assigned by the server
The most recent airplane state packet received
Flag tracking if engine damage warning has been sent
Timestamp of last over-G warning message
Flag indicating if aircraft was recently repaired
Methods
reset
Resets the aircraft to initial state, clearing all properties.
Resets:
name to empty string
position to [0,0,0]
attitude to [0,0,0]
initial_config to
custom_config to
life to -1
prev_life to -1
id to -1
last_packet to None
damage_engine_warn_sent to False
just_repaired to False
Example:
aircraft.reset()
print(aircraft.name) # ""
print(aircraft.position) # [0, 0, 0]
set_position
set_position(position: list) -> None
Sets the aircraft position from an airplane state packet.
position
list[float, float, float]
required
Position coordinates as [x, y, z] in meters
Example:
aircraft.set_position([1000.0, 2000.0, 5000.0])
print(aircraft.position) # [1000.0, 2000.0, 5000.0]
set_attitude
set_attitude(attitude: list) -> None
Sets the aircraft attitude from an airplane state packet.
attitude
list[float, float, float]
required
Attitude angles as [pitch, yaw, roll] in radians
Example:
aircraft.set_attitude([0.1, 0.0, 0.05])
print(aircraft.attitude) # [0.1, 0.0, 0.05]
get_position
get_position() -> list[float, float, float]
Returns the current position of the aircraft.
return
list[float, float, float]
Aircraft position as [x, y, z] coordinates
Example:
pos = aircraft.get_position()
print(f"X: {pos[0]}, Y: {pos[1]}, Z: {pos[2]}")
get_altitude
Returns the aircraft altitude in meters.
Altitude in meters (z-coordinate from position)
Example:
alt = aircraft.get_altitude()
print(f"Altitude: {alt}m")
get_attitude
get_attitude() -> list[float, float, float]
Returns the current attitude of the aircraft.
return
list[float, float, float]
Aircraft attitude as [pitch, yaw, roll] in radians
Example:
att = aircraft.get_attitude()
print(f"Pitch: {att[0]}, Yaw: {att[1]}, Roll: {att[2]}")
set_initial_config
set_initial_config(config: dict) -> None
Sets or updates initial configuration values.
Dictionary of configuration key-value pairs to merge into initial_config
Behavior:
- Merges provided config into existing
initial_config
- Does not clear existing values
Example:
aircraft.set_initial_config({
"IFF": 1,
"AFTBURNR": "TRUE",
"FUEL": "100"
})
print(aircraft.initial_config)
# {'IFF': 1, 'AFTBURNR': 'TRUE', 'FUEL': '100'}
get_initial_config_value
get_initial_config_value(key: str) -> any | None
Retrieves a value from the initial configuration.
The configuration key to retrieve
The configuration value if key exists, otherwise None
Example:
iff = aircraft.get_initial_config_value("IFF")
if iff is not None:
print(f"Team: {iff}")
afterburner = aircraft.get_initial_config_value("AFTBURNR")
if afterburner == "TRUE":
print("Afterburner available")
set_custom_config_value
set_custom_config_value(key: str, value: any) -> None
Sets a custom configuration value.
The configuration key to set
Note: This stores the value locally. Sending to client requires separate implementation.
Example:
aircraft.set_custom_config_value("max_speed", 850)
aircraft.set_custom_config_value("custom_livery", "blue_angels")
print(aircraft.custom_config)
# {'max_speed': 850, 'custom_livery': 'blue_angels'}
add_state
add_state(packet: FSNETCMD_AIRPLANESTATE) -> FSNETCMD_AIRPLANESTATE | None
Processes an airplane state packet and updates aircraft state.
packet
FSNETCMD_AIRPLANESTATE
required
The airplane state packet to process
return
FSNETCMD_AIRPLANESTATE | None
Returns the packet if it matches this aircraft’s ID, otherwise None
Behavior:
- Validates
packet.player_id matches self.id
- Initializes
life on first packet if unset
- Updates
prev_life with current life
- Updates
life from packet
- Updates position and attitude
- Stores packet reference in
last_packet
Example:
state_packet = FSNETCMD_AIRPLANESTATE()
state_packet.player_id = 12345
state_packet.life = 1000
state_packet.position = [1500.0, 2500.0, 6000.0]
state_packet.atti = [0.1, 0.2, 0.05]
aircraft.id = 12345
result = aircraft.add_state(state_packet)
if result:
print(f"Life: {aircraft.life}")
print(f"Position: {aircraft.position}")
print(f"Damage taken: {aircraft.prev_life - aircraft.life}")
check_command
check_command(command: FSNETCMD_AIRCMD) -> None
Checks an aircraft command packet and updates configuration if it matches this aircraft.
The aircraft command packet to process
Behavior:
- Validates
command.aircraft_id matches self.id
- If command contains data, updates
initial_config with command[0] as key and command[1] as value
- Logs command for debugging
Example:
cmd_packet = FSNETCMD_AIRCMD()
cmd_packet.aircraft_id = 12345
cmd_packet.command = ["AFTBURNR", "TRUE"]
aircraft.id = 12345
aircraft.check_command(cmd_packet)
print(aircraft.initial_config["AFTBURNR"]) # "TRUE"
set_afterburner
set_afterburner(enabled: bool) -> FSNETCMD_AIRCMD | None
Toggles afterburner if available on the aircraft.
True to enable afterburner, False to disable
Aircraft command packet to send, or None if afterburner not available
Behavior:
- Checks if
AFTBURNR config value is “TRUE”
- Returns command packet if available, otherwise
None
Example:
aircraft.set_initial_config({"AFTBURNR": "TRUE"})
aircraft.id = 12345
cmd = aircraft.set_afterburner(True)
if cmd:
print("Afterburner command created")
# Send cmd packet to client
else:
print("Afterburner not available on this aircraft")
Usage Example
from lib.Aircraft import Aircraft
from lib.PacketManager.packets import FSNETCMD_AIRPLANESTATE, FSNETCMD_ADDOBJECT
# Create new aircraft
aircraft = Aircraft()
# Set up initial configuration
aircraft.name = "F-15C"
aircraft.id = 12345
aircraft.set_position([0, 0, 1000])
aircraft.set_initial_config({
"IFF": 1,
"AFTBURNR": "TRUE",
"FUEL": "100"
})
# Process state updates
state = FSNETCMD_AIRPLANESTATE()
state.player_id = 12345
state.life = 1000
state.position = [100.0, 200.0, 1500.0]
state.atti = [0.05, 0.1, 0.02]
if aircraft.add_state(state):
alt = aircraft.get_altitude()
print(f"Aircraft at {alt}m altitude")
# Check for damage
if aircraft.life < aircraft.prev_life:
damage = aircraft.prev_life - aircraft.life
print(f"Damage taken: {damage}")
# Enable afterburner if available
cmd = aircraft.set_afterburner(True)
if cmd:
print("Afterburner enabled")