|
| 1 | +-- This handles behavior specific to the Su-27 / J-11A |
| 2 | + |
| 3 | +dofile(LockOn_Options.script_path.."/Utilities/logging.lua") |
| 4 | +dofile(LockOn_Options.script_path.."device_commands.lua") |
| 5 | + |
| 6 | +-- Localization function |
| 7 | +local gettext = require("i_18n") |
| 8 | +_ = gettext.translate |
| 9 | + |
| 10 | +local self = GetSelf() |
| 11 | +local sensor_data = get_base_data() |
| 12 | + |
| 13 | +local update_time_step = 0.1 -- Update will be called 10 times per second |
| 14 | +make_default_activity(update_time_step) |
| 15 | + |
| 16 | +local su27_mode_aa = 2 -- 1 == Longitudinal, 2 == Nav, 3 == BVR, 4 == Vert Scan, 5 == Boresight Scan, 6 == Helmet Cue |
| 17 | +local su27_commands_aa = { |
| 18 | + iCommands.MM_FI0, |
| 19 | + iCommands.MM_Nav, |
| 20 | + iCommands.MM_Air_BVR, |
| 21 | + iCommands.MM_Air_VerticalScan, |
| 22 | + iCommands.MM_Air_Boresight, |
| 23 | + iCommands.MM_Air_HelmetCue |
| 24 | +} |
| 25 | + |
| 26 | +self:listen_command(iCommands.MM_Nav) |
| 27 | +self:listen_command(iCommands.MM_Air_BVR) |
| 28 | +self:listen_command(iCommands.MM_Air_Boresight) |
| 29 | +self:listen_command(iCommands.MM_Air_HelmetCue) |
| 30 | +self:listen_command(iCommands.MM_Air_VerticalScan) |
| 31 | +self:listen_command(iCommands.MM_FI0) |
| 32 | +self:listen_command(iCommands.MM_Ground) |
| 33 | + |
| 34 | +---This is called by the elements assigned in clickabledata.lua |
| 35 | +---@param command integer device_command code, what was interacted with |
| 36 | +---@param value number The current value of the clickable element, specifically the arg tied to it |
| 37 | +function SetCommand(command, value) |
| 38 | + FCCLOG.info("Command triggered: " .. command .. ", " .. value) |
| 39 | + |
| 40 | + if command == device_commands.AP_MODE_ATT then |
| 41 | + dispatch_action(nil, iCommands.AP_AttitudeMode) |
| 42 | + |
| 43 | + elseif command == device_commands.AP_MODE_ALT then |
| 44 | + dispatch_action(nil, iCommands.AP_AltBankMode) |
| 45 | + |
| 46 | + elseif command == device_commands.AP_MODE_NAV then |
| 47 | + dispatch_action(nil, iCommands.AP_RouteMode) |
| 48 | + |
| 49 | + elseif command == device_commands.AP_MODE_GCA then |
| 50 | + dispatch_action(nil, iCommands.AP_RadarMode) |
| 51 | + |
| 52 | + elseif command == device_commands.AP_MODE_RESET then |
| 53 | + dispatch_action(nil, iCommands.AP_Disengage) |
| 54 | + |
| 55 | + elseif command == device_commands.AP_MODE_LEVEL then |
| 56 | + dispatch_action(nil, iCommands.AP_LevelMode) |
| 57 | + |
| 58 | + elseif command == device_commands.AP_MODE_DAMPER then |
| 59 | + dispatch_action(nil, iCommands.SYS_DirectControl) |
| 60 | + |
| 61 | + elseif command == device_commands.EOS_TGL then |
| 62 | + dispatch_action(nil, iCommands.TGT_EOSOnOff) |
| 63 | + |
| 64 | + elseif command == device_commands.FLAPS_OFF then |
| 65 | + dispatch_action(nil, iCommands.SYS_FlapsOff) |
| 66 | + |
| 67 | + elseif command == device_commands.FLAPS_ON then |
| 68 | + dispatch_action(nil, iCommands.SYS_FlapsOn) |
| 69 | + |
| 70 | + elseif command == device_commands.HUD_SIGHT then |
| 71 | + dispatch_action(nil, iCommands.MM_Gunsight) |
| 72 | + |
| 73 | + elseif command == device_commands.HUD_MODE then |
| 74 | + dispatch_action(nil, iCommands.SYS_SU27_HUDonHDD) |
| 75 | + |
| 76 | + elseif command == device_commands.MM_AA then |
| 77 | + su27_master_mode_switch(value) |
| 78 | + |
| 79 | + elseif command == device_commands.MM_AG then |
| 80 | + if value > 0 then |
| 81 | + -- Enter last selected AA mode |
| 82 | + dispatch_action(nil, su27_commands_aa[su27_mode_aa]) |
| 83 | + else |
| 84 | + dispatch_action(nil, iCommands.MM_Ground) |
| 85 | + end |
| 86 | + |
| 87 | + elseif command == device_commands.RDR_ZOOM then |
| 88 | + if value > 0 then |
| 89 | + dispatch_action(nil, iCommands.RADAR_ZoomIn) |
| 90 | + else |
| 91 | + dispatch_action(nil, iCommands.RADAR_ZoomOut) |
| 92 | + end |
| 93 | + |
| 94 | + elseif command == device_commands.INTAKE_TGL then |
| 95 | + dispatch_action(nil, iCommands.SYS_IntakeScreens) |
| 96 | + |
| 97 | + elseif command == device_commands.NWS_TGL then |
| 98 | + dispatch_action(nil, iCommands.SYS_NoseWheelSteeringRange) |
| 99 | + |
| 100 | + elseif command == device_commands.RDR_TGL then |
| 101 | + dispatch_action(nil, iCommands.RADAR_Toggle) |
| 102 | + |
| 103 | + elseif command == device_commands.RDR_VERT then |
| 104 | + if value > 0 then |
| 105 | + dispatch_action(nil, iCommands.TGT_SelectorUp) |
| 106 | + elseif value < 0 then |
| 107 | + dispatch_action(nil, iCommands.TGT_SelectorDown) |
| 108 | + else |
| 109 | + dispatch_action(nil, iCommands.TGT_SelectorStop) |
| 110 | + end |
| 111 | + |
| 112 | + elseif command == device_commands.RDR_HORZ then |
| 113 | + if value > 0 then |
| 114 | + dispatch_action(nil, iCommands.TGT_SelectorLeft) |
| 115 | + elseif value < 0 then |
| 116 | + dispatch_action(nil, iCommands.TGT_SelectorRight) |
| 117 | + else |
| 118 | + dispatch_action(nil, iCommands.TGT_SelectorStop) |
| 119 | + end |
| 120 | + |
| 121 | + elseif command == device_commands.RDR_FREQ then |
| 122 | + dispatch_action(nil, iCommands.RADAR_PulseFreq) |
| 123 | + |
| 124 | + elseif command == device_commands.RDR_MODE then |
| 125 | + dispatch_action(nil, iCommands.RADAR_Mode) |
| 126 | + |
| 127 | + elseif command == device_commands.TGT_SIZE then |
| 128 | + if value > 0 then |
| 129 | + dispatch_action(nil, iCommands.TGT_WingspanInc) |
| 130 | + elseif value < 0 then |
| 131 | + dispatch_action(nil, iCommands.TGT_WingspanDec) |
| 132 | + else |
| 133 | + dispatch_action(nil, iCommands.TGT_WingspanStop) |
| 134 | + end |
| 135 | + |
| 136 | + elseif command == device_commands.WEP_RIP_MODE then |
| 137 | + dispatch_action(nil, iCommands.W_SalvoOnOff) |
| 138 | + |
| 139 | + |
| 140 | + -- Listen for user input that might change the current Master Mode |
| 141 | + elseif command == iCommands.MM_FI0 then |
| 142 | + su27_mode_aa = 1 |
| 143 | + |
| 144 | + elseif command == iCommands.MM_Nav then |
| 145 | + su27_mode_aa = 2 |
| 146 | + |
| 147 | + elseif command == iCommands.MM_Air_BVR then |
| 148 | + su27_mode_aa = 3 |
| 149 | + |
| 150 | + elseif command == iCommands.MM_Air_VerticalScan then |
| 151 | + su27_mode_aa = 4 |
| 152 | + |
| 153 | + elseif command == iCommands.MM_Air_Boresight then |
| 154 | + su27_mode_aa = 5 |
| 155 | + |
| 156 | + elseif command == iCommands.MM_Air_HelmetCue then |
| 157 | + su27_mode_aa = 6 |
| 158 | + |
| 159 | + end |
| 160 | + |
| 161 | +end |
| 162 | + |
| 163 | + |
| 164 | +function su27_master_mode_switch(value) |
| 165 | + -- Make sure input value is an integer |
| 166 | + if value > 0 then |
| 167 | + value = 1 |
| 168 | + else |
| 169 | + value = -1 |
| 170 | + end |
| 171 | + |
| 172 | + su27_mode_aa = su27_mode_aa + value |
| 173 | + -- Clamp 1:6, lua arrays are not 0-indexed |
| 174 | + if su27_mode_aa < 1 then |
| 175 | + su27_mode_aa = 1 |
| 176 | + elseif su27_mode_aa > 6 then |
| 177 | + su27_mode_aa = 6 |
| 178 | + end |
| 179 | + |
| 180 | + dispatch_action(nil, su27_commands_aa[su27_mode_aa]) |
| 181 | +end |
| 182 | + |
| 183 | +-- This gets called every update_time_step |
| 184 | +function update() |
| 185 | +end |
| 186 | + |
| 187 | +-- Called automatically after the cockpit has been initialized, maybe? Not sure on the exact timing |
| 188 | +function post_initialize() |
| 189 | + FCCLOG.info("clickable_su27 INIT") |
| 190 | +end |
| 191 | + |
| 192 | +need_to_be_closed = false |
0 commit comments