diff --git a/json/ecu/default.json b/json/ecu/default.json new file mode 100644 index 0000000..5dda140 --- /dev/null +++ b/json/ecu/default.json @@ -0,0 +1 @@ +{"slots": {"4": {"name": "slot5", "type": {"methods": [], "events": []}}, "-1": {"name": "unit", "type": {"methods": [], "events": []}}, "-2": {"name": "system", "type": {"methods": [], "events": []}}, "-3": {"name": "library", "type": {"methods": [], "events": []}}, "0": {"name": "core", "type": {"methods": [], "events": []}}, "1": {"name": "slot2", "type": {"methods": [], "events": []}}, "2": {"name": "slot3", "type": {"methods": [], "events": []}}, "3": {"name": "slot4", "type": {"methods": [], "events": []}}, "5": {"name": "slot6", "type": {"methods": [], "events": []}}, "6": {"name": "slot7", "type": {"methods": [], "events": []}}, "7": {"name": "slot8", "type": {"methods": [], "events": []}}, "8": {"name": "slot9", "type": {"methods": [], "events": []}}, "9": {"name": "slot10", "type": {"methods": [], "events": []}}}, "handlers": [{"key": "0", "filter": {"slotKey": "-1", "signature": "start()", "args": []}, "code": "-- category panel display helpers\n_autoconf = {}\n_autoconf.panels = {}\n_autoconf.panels_size = 0\n_autoconf.displayCategoryPanel = function(elements, size, title, type, widgetPerData)\n widgetPerData = widgetPerData or false -- default to one widget for all data\n if size > 0 then\n local panel = system.createWidgetPanel(title)\n local widget\n if not widgetPerData then\n widget = system.createWidget(panel, type)\n end\n for i = 1, size do\n if widgetPerData then\n widget = system.createWidget(panel, type)\n end\n system.addDataToWidget(elements[i].getDataId(), widget)\n end\n _autoconf.panels_size = _autoconf.panels_size + 1\n _autoconf.panels[_autoconf.panels_size] = panel\n end\nend\n_autoconf.hideCategoryPanels = function()\n for i=1,_autoconf.panels_size do\n system.destroyWidgetPanel(_autoconf.panels[i])\n end\nend\n-- Proxy array to access auto-plugged slots programmatically\n\ncontainer = {}\ncontainer_size = 0\n-- End of auto-generated code\nNav = Navigator.new(system, core, unit)\nplanetInfluenceThreshold = 0.6\nif antigrav ~= nil then\n antigrav.activate()\n antigrav.show()\nend\n"}, {"key": "1", "filter": {"slotKey": "-2", "signature": "flush()", "args": []}, "code": "local verticalAutoLandingSpeed = 20 --export: Vertical auto landing speec in km/h\nlocal power = 3\nlocal worldUp = vec3(core.getConstructWorldOrientationUp())\nlocal worldForward = vec3(core.getConstructWorldOrientationForward())\nlocal worldRight = vec3(core.getConstructWorldOrientationRight())\nlocal worldVertical = vec3(core.getWorldVertical())\n\n-- are we in deep space or are we near a planet ?\nlocal planetInfluence = Nav.control.getClosestPlanetInfluence()\nif planetInfluence > 0\nthen\n -- stabilize orientation along the gravity\n if (rollPID == nil) then\n rollPID = pid.new(0.2, 0, 10)\n pitchPID = pid.new(0.2, 0, 10)\n end\n\n local yawVelocity = vec3(core.getWorldAngularVelocity()):dot(worldUp)\n local currentRoll = getRoll(worldVertical, worldForward, worldRight)\n local currentPitch = -math.asin(worldForward:dot(worldVertical)) * constants.rad2deg\n rollPID:inject(-currentRoll)\n pitchPID:inject(-currentPitch)\n local yawAcceleration = - power * yawVelocity\n angularAcceleration = rollPID:get() * worldForward + pitchPID:get() * worldRight + yawAcceleration * worldUp\nelse\n -- cancel rotation\n local worldAngularVelocity = vec3(core.getWorldAngularVelocity())\n angularAcceleration = - power * worldAngularVelocity\nend\n\nif planetInfluence > planetInfluenceThreshold\nthen\n -- go down at verticalTargetSpeed when very close to a planet\n targetVelocity = (verticalAutoLandingSpeed / 3.6) * worldVertical\nelse\n -- immobilize ship when not\n targetVelocity = vec3()\nend\nNav:setEngineCommand('torque', vec3(), angularAcceleration)\nstabilization = power * (targetVelocity - vec3(core.getWorldVelocity()))\nNav:setEngineCommand('vertical, brake, horizontal', stabilization -vec3(core.getWorldGravity()), vec3(), false)\n"}, {"key": "2", "filter": {"slotKey": "-2", "signature": "update()", "args": []}, "code": "local accelThreshold = 0.1\nlocal speedThreshold = 0.1\n\n-- auto stopping mechanism when immobile and close to planet\nlocal accel = vec3(Nav.core.getWorldAcceleration()):len()\nlocal speed = vec3(Nav.core.getWorldVelocity()):len()\nif accel < accelThreshold\n and speed < speedThreshold\n and Nav.control.getClosestPlanetInfluence() > planetInfluenceThreshold\nthen\n unit.exit()\nend\n"}], "methods": [], "events": []} \ No newline at end of file diff --git a/json/gunner_module/default.json b/json/gunner_module/default.json new file mode 100644 index 0000000..0f31b38 --- /dev/null +++ b/json/gunner_module/default.json @@ -0,0 +1 @@ +{"slots": {"4": {"name": "slot5", "type": {"methods": [], "events": []}}, "-1": {"name": "unit", "type": {"methods": [], "events": []}}, "-2": {"name": "system", "type": {"methods": [], "events": []}}, "-3": {"name": "library", "type": {"methods": [], "events": []}}, "0": {"name": "core", "type": {"methods": [], "events": []}}, "1": {"name": "slot2", "type": {"methods": [], "events": []}}, "2": {"name": "slot3", "type": {"methods": [], "events": []}}, "3": {"name": "slot4", "type": {"methods": [], "events": []}}, "5": {"name": "slot6", "type": {"methods": [], "events": []}}, "6": {"name": "slot7", "type": {"methods": [], "events": []}}, "7": {"name": "slot8", "type": {"methods": [], "events": []}}, "8": {"name": "slot9", "type": {"methods": [], "events": []}}, "9": {"name": "slot10", "type": {"methods": [], "events": []}}, "10": {"name": "slot11", "type": {"methods": [], "events": []}}, "11": {"name": "slot12", "type": {"methods": [], "events": []}}, "12": {"name": "slot13", "type": {"methods": [], "events": []}}, "13": {"name": "slot14", "type": {"methods": [], "events": []}}, "14": {"name": "slot15", "type": {"methods": [], "events": []}}, "15": {"name": "slot16", "type": {"methods": [], "events": []}}, "16": {"name": "slot17", "type": {"methods": [], "events": []}}, "17": {"name": "slot18", "type": {"methods": [], "events": []}}, "18": {"name": "slot19", "type": {"methods": [], "events": []}}, "19": {"name": "slot20", "type": {"methods": [], "events": []}}, "20": {"name": "slot21", "type": {"methods": [], "events": []}}}, "handlers": [{"key": "0", "filter": {"slotKey": "-1", "signature": "start()", "args": []}, "code": "-- Proxy array to access auto-plugged slots programmatically\n\nweapon = {}\nweapon_size = 0\n\nradar = {}\nradar_size = 0\n-- End of auto-generated code\n"}], "methods": [], "events": []} \ No newline at end of file diff --git a/json/hover_seat/flying.json b/json/hover_seat/flying.json new file mode 100644 index 0000000..3887492 --- /dev/null +++ b/json/hover_seat/flying.json @@ -0,0 +1 @@ +{"slots": {"4": {"name": "slot5", "type": {"methods": [], "events": []}}, "-1": {"name": "unit", "type": {"methods": [], "events": []}}, "-2": {"name": "system", "type": {"methods": [], "events": []}}, "-3": {"name": "library", "type": {"methods": [], "events": []}}, "0": {"name": "core", "type": {"methods": [], "events": []}}, "1": {"name": "slot2", "type": {"methods": [], "events": []}}, "2": {"name": "slot3", "type": {"methods": [], "events": []}}, "3": {"name": "slot4", "type": {"methods": [], "events": []}}, "5": {"name": "slot6", "type": {"methods": [], "events": []}}, "6": {"name": "slot7", "type": {"methods": [], "events": []}}, "7": {"name": "slot8", "type": {"methods": [], "events": []}}, "8": {"name": "slot9", "type": {"methods": [], "events": []}}, "9": {"name": "slot10", "type": {"methods": [], "events": []}}, "10": {"name": "slot11", "type": {"methods": [], "events": []}}, "11": {"name": "slot12", "type": {"methods": [], "events": []}}, "12": {"name": "slot13", "type": {"methods": [], "events": []}}, "13": {"name": "slot14", "type": {"methods": [], "events": []}}, "14": {"name": "slot15", "type": {"methods": [], "events": []}}, "15": {"name": "slot16", "type": {"methods": [], "events": []}}, "16": {"name": "slot17", "type": {"methods": [], "events": []}}, "17": {"name": "slot18", "type": {"methods": [], "events": []}}, "18": {"name": "slot19", "type": {"methods": [], "events": []}}, "19": {"name": "slot20", "type": {"methods": [], "events": []}}, "20": {"name": "slot21", "type": {"methods": [], "events": []}}}, "handlers": [{"key": "0", "filter": {"slotKey": "-1", "signature": "start()", "args": []}, "code": "-- category panel display helpers\n_autoconf = {}\n_autoconf.panels = {}\n_autoconf.panels_size = 0\n_autoconf.displayCategoryPanel = function(elements, size, title, type, widgetPerData)\n widgetPerData = widgetPerData or false -- default to one widget for all data\n if size > 0 then\n local panel = system.createWidgetPanel(title)\n local widget\n if not widgetPerData then\n widget = system.createWidget(panel, type)\n end\n for i = 1, size do\n if widgetPerData then\n widget = system.createWidget(panel, type)\n end\n system.addDataToWidget(elements[i].getDataId(), widget)\n end\n _autoconf.panels_size = _autoconf.panels_size + 1\n _autoconf.panels[_autoconf.panels_size] = panel\n end\nend\n_autoconf.hideCategoryPanels = function()\n for i=1,_autoconf.panels_size do\n system.destroyWidgetPanel(_autoconf.panels[i])\n end\nend\n-- Proxy array to access auto-plugged slots programmatically\nweapon = {}\nweapon_size = 0\n\nspacefueltank = {}\nspacefueltank_size = 0\n\nrocketfueltank = {}\nrocketfueltank_size = 0\n\natmofueltank = {}\natmofueltank_size = 0\n\nradar = {}\nradar_size = 0\n-- End of auto-generated code\npitchInput = 0\nrollInput = 0\nyawInput = 0\nbrakeInput = 0\n\nNav = Navigator.new(system, core, unit)\nNav.axisCommandManager:setupCustomTargetSpeedRanges(axisCommandId.longitudinal, {1000, 5000, 10000, 20000, 30000})\nNav.axisCommandManager:setTargetGroundAltitude(4)\n\n-- Parenting widget\nparentingPanelId = system.createWidgetPanel(\"Docking\")\nparentingWidgetId = system.createWidget(parentingPanelId,\"parenting\")\nsystem.addDataToWidget(unit.getDataId(),parentingWidgetId)\n\n-- Combat stress widget\ncoreCombatStressPanelId = system.createWidgetPanel(\"Core combat stress\")\ncoreCombatStressgWidgetId = system.createWidget(coreCombatStressPanelId,\"core_stress\")\nsystem.addDataToWidget(core.getDataId(),coreCombatStressgWidgetId)\n\n-- element widgets\n-- For now we have to alternate between PVP and non-PVP widgets to have them on the same side.\n_autoconf.displayCategoryPanel(weapon, weapon_size, \"Weapons\", \"weapon\", true)\ncore.show()\n_autoconf.displayCategoryPanel(radar, radar_size, \"Periscope\", \"periscope\")\nplaceRadar = true\nif atmofueltank_size > 0 then\n _autoconf.displayCategoryPanel(atmofueltank, atmofueltank_size, \"Atmo Fuel\", \"fuel_container\")\n if placeRadar then\n _autoconf.displayCategoryPanel(radar, radar_size, \"Radar\", \"radar\")\n placeRadar = false\n end\nend\nif spacefueltank_size > 0 then\n _autoconf.displayCategoryPanel(spacefueltank, spacefueltank_size, \"Space Fuel\", \"fuel_container\")\n if placeRadar then\n _autoconf.displayCategoryPanel(radar, radar_size, \"Radar\", \"radar\")\n placeRadar = false\n end\nend\n_autoconf.displayCategoryPanel(rocketfueltank, rocketfueltank_size, \"Rocket Fuel\", \"fuel_container\")\nif placeRadar then -- We either have only rockets or no fuel tanks at all, uncommon for usual vessels\n _autoconf.displayCategoryPanel(radar, radar_size, \"Radar\", \"radar\")\n placeRadar = false\nend\nif antigrav ~= nil then antigrav.show() end\nif warpdrive ~= nil then warpdrive.show() end\nif gyro ~= nil then gyro.show() end\nif shield ~= nil then shield.show() end\n\n-- freeze the player in he is remote controlling the construct\nif Nav.control.isRemoteControlled() == 1 then\n system.freeze(1)\nend\n\n-- landing gear\n-- make sure every gears are synchonized with the first\ngearExtended = (Nav.control.isAnyLandingGearExtended() == 1) -- make sure it's a lua boolean\nif gearExtended then\n Nav.control.extendLandingGears()\nelse\n Nav.control.retractLandingGears()\nend\n"}, {"key": "1", "filter": {"slotKey": "-1", "signature": "stop()", "args": []}, "code": "_autoconf.hideCategoryPanels()\nif antigrav ~= nil then antigrav.hide() end\nif warpdrive ~= nil then warpdrive.hide() end\nif gyro ~= nil then gyro.hide() end\ncore.hide()\nNav.control.switchOffHeadlights()\n"}, {"key": "2", "filter": {"slotKey": "-2", "signature": "actionStop(left)", "args": [{"value": "left"}]}, "code": "rollInput = rollInput + 1"}, {"key": "3", "filter": {"slotKey": "-2", "signature": "actionStop(backward)", "args": [{"value": "backward"}]}, "code": "pitchInput = pitchInput - 1"}, {"key": "4", "filter": {"slotKey": "-2", "signature": "actionStop(forward)", "args": [{"value": "forward"}]}, "code": "pitchInput = pitchInput + 1"}, {"key": "5", "filter": {"slotKey": "-2", "signature": "actionStart(backward)", "args": [{"value": "backward"}]}, "code": "pitchInput = pitchInput + 1"}, {"key": "6", "filter": {"slotKey": "-2", "signature": "actionStart(gear)", "args": [{"value": "gear"}]}, "code": "gearExtended = not gearExtended\nif gearExtended then\n Nav.control.extendLandingGears()\nelse\n Nav.control.retractLandingGears()\nend\n"}, {"key": "7", "filter": {"slotKey": "-2", "signature": "flush()", "args": []}, "code": "-- constants: use 'myvar = defaultValue --export: description' to expose the variable in context menu\n\nlocal pitchSpeedFactor = 0.8 --export: This factor will increase/decrease the player input along the pitch axis
(higher value may be unstable)
Valid values: Superior or equal to 0.01\nlocal yawSpeedFactor = 1 --export: This factor will increase/decrease the player input along the yaw axis
(higher value may be unstable)
Valid values: Superior or equal to 0.01\nlocal rollSpeedFactor = 1.5 --export: This factor will increase/decrease the player input along the roll axis
(higher value may be unstable)
Valid values: Superior or equal to 0.01\n\nlocal brakeSpeedFactor = 3 --export: When braking, this factor will increase the brake force by brakeSpeedFactor * velocity
Valid values: Superior or equal to 0.01\nlocal brakeFlatFactor = 1 --export: When braking, this factor will increase the brake force by a flat brakeFlatFactor * velocity direction>
(higher value may be unstable)
Valid values: Superior or equal to 0.01\n\nlocal autoRoll = false --export: [Only in atmosphere]
When the pilot stops rolling, flight model will try to get back to horizontal (no roll)\nlocal autoRollFactor = 2 --export: [Only in atmosphere]
When autoRoll is engaged, this factor will increase to strength of the roll back to 0
Valid values: Superior or equal to 0.01\n\nlocal turnAssist = true --export: [Only in atmosphere]
When the pilot is rolling, the flight model will try to add yaw and pitch to make the construct turn better
The flight model will start by adding more yaw the more horizontal the construct is and more pitch the more vertical it is\nlocal turnAssistFactor = 2 --export: [Only in atmosphere]
This factor will increase/decrease the turnAssist effect
(higher value may be unstable)
Valid values: Superior or equal to 0.01\n\nlocal torqueFactor = 2 -- Force factor applied to reach rotationSpeed
(higher value may be unstable)
Valid values: Superior or equal to 0.01\n\n-- validate params\npitchSpeedFactor = math.max(pitchSpeedFactor, 0.01)\nyawSpeedFactor = math.max(yawSpeedFactor, 0.01)\nrollSpeedFactor = math.max(rollSpeedFactor, 0.01)\ntorqueFactor = math.max(torqueFactor, 0.01)\nbrakeSpeedFactor = math.max(brakeSpeedFactor, 0.01)\nbrakeFlatFactor = math.max(brakeFlatFactor, 0.01)\nautoRollFactor = math.max(autoRollFactor, 0.01)\nturnAssistFactor = math.max(turnAssistFactor, 0.01)\n\n-- final inputs\nlocal finalPitchInput = pitchInput + system.getControlDeviceForwardInput()\nlocal finalRollInput = rollInput + system.getControlDeviceYawInput()\nlocal finalYawInput = yawInput - system.getControlDeviceLeftRightInput()\nlocal finalBrakeInput = brakeInput\n\n-- Axis\nlocal worldVertical = vec3(core.getWorldVertical()) -- along gravity\nlocal constructUp = vec3(core.getConstructWorldOrientationUp())\nlocal constructForward = vec3(core.getConstructWorldOrientationForward())\nlocal constructRight = vec3(core.getConstructWorldOrientationRight())\nlocal constructVelocity = vec3(core.getWorldVelocity())\nlocal constructVelocityDir = vec3(core.getWorldVelocity()):normalize()\nlocal currentRollDeg = getRoll(worldVertical, constructForward, constructRight)\nlocal currentRollDegAbs = math.abs(currentRollDeg)\nlocal currentRollDegSign = utils.sign(currentRollDeg)\n\n-- Rotation\nlocal constructAngularVelocity = vec3(core.getWorldAngularVelocity())\nlocal targetAngularVelocity = finalPitchInput * pitchSpeedFactor * constructRight\n + finalRollInput * rollSpeedFactor * constructForward\n + finalYawInput * yawSpeedFactor * constructUp\n\n-- In atmosphere?\nif worldVertical:len() > 0.01 and unit.getAtmosphereDensity() > 0.0 then\n local autoRollRollThreshold = 1.0\n -- autoRoll on AND currentRollDeg is big enough AND player is not rolling\n if autoRoll == true and currentRollDegAbs > autoRollRollThreshold and finalRollInput == 0 then\n local targetRollDeg = utils.clamp(0,currentRollDegAbs-30, currentRollDegAbs+30); -- we go back to 0 within a certain limit\n if (rollPID == nil) then\n rollPID = pid.new(autoRollFactor * 0.01, 0, autoRollFactor * 0.1) -- magic number tweaked to have a default factor in the 1-10 range\n end\n rollPID:inject(targetRollDeg - currentRollDeg)\n local autoRollInput = rollPID:get()\n\n targetAngularVelocity = targetAngularVelocity + autoRollInput * constructForward\n end\n local turnAssistRollThreshold = 20.0\n -- turnAssist AND currentRollDeg is big enough AND player is not pitching or yawing\n if turnAssist == true and currentRollDegAbs > turnAssistRollThreshold and finalPitchInput == 0 and finalYawInput == 0 then\n local rollToPitchFactor = turnAssistFactor * 0.1 -- magic number tweaked to have a default factor in the 1-10 range\n local rollToYawFactor = turnAssistFactor * 0.025 -- magic number tweaked to have a default factor in the 1-10 range\n\n -- rescale (turnAssistRollThreshold -> 180) to (0 -> 180)\n local rescaleRollDegAbs = ((currentRollDegAbs - turnAssistRollThreshold) / (180 - turnAssistRollThreshold)) * 180\n local rollVerticalRatio = 0\n if rescaleRollDegAbs < 90 then\n rollVerticalRatio = rescaleRollDegAbs / 90\n elseif rescaleRollDegAbs < 180 then\n rollVerticalRatio = (180 - rescaleRollDegAbs) / 90\n end\n\n rollVerticalRatio = rollVerticalRatio * rollVerticalRatio\n\n local turnAssistYawInput = - currentRollDegSign * rollToYawFactor * (1.0 - rollVerticalRatio)\n local turnAssistPitchInput = rollToPitchFactor * rollVerticalRatio\n\n targetAngularVelocity = targetAngularVelocity\n + turnAssistPitchInput * constructRight\n + turnAssistYawInput * constructUp\n end\nend\n\n-- Engine commands\nlocal keepCollinearity = 1 -- for easier reading\nlocal dontKeepCollinearity = 0 -- for easier reading\nlocal tolerancePercentToSkipOtherPriorities = 1 -- if we are within this tolerance (in%), we don't go to the next priorities\n\n-- Rotation\nlocal angularAcceleration = torqueFactor * (targetAngularVelocity - constructAngularVelocity)\nlocal airAcceleration = vec3(core.getWorldAirFrictionAngularAcceleration())\nangularAcceleration = angularAcceleration - airAcceleration -- Try to compensate air friction\nNav:setEngineTorqueCommand('torque', angularAcceleration, keepCollinearity, 'airfoil', '', '', tolerancePercentToSkipOtherPriorities)\n\n-- Brakes\nlocal brakeAcceleration = -finalBrakeInput * (brakeSpeedFactor * constructVelocity + brakeFlatFactor * constructVelocityDir)\nNav:setEngineForceCommand('brake', brakeAcceleration)\n\n-- AutoNavigation regroups all the axis command by 'TargetSpeed'\nlocal autoNavigationEngineTags = ''\nlocal autoNavigationAcceleration = vec3()\nlocal autoNavigationUseBrake = false\n\n-- Longitudinal Translation\nlocal longitudinalEngineTags = 'thrust analog longitudinal'\nlocal longitudinalCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)\nif (longitudinalCommandType == axisCommandType.byThrottle) then\n local longitudinalAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromThrottle(longitudinalEngineTags,axisCommandId.longitudinal)\n Nav:setEngineForceCommand(longitudinalEngineTags, longitudinalAcceleration, keepCollinearity)\nelseif (longitudinalCommandType == axisCommandType.byTargetSpeed) then\n local longitudinalAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.longitudinal)\n autoNavigationEngineTags = autoNavigationEngineTags .. ' , ' .. longitudinalEngineTags\n autoNavigationAcceleration = autoNavigationAcceleration + longitudinalAcceleration\n if (Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal) == 0 or -- we want to stop\n Nav.axisCommandManager:getCurrentToTargetDeltaSpeed(axisCommandId.longitudinal) < - Nav.axisCommandManager:getTargetSpeedCurrentStep(axisCommandId.longitudinal) * 0.5) -- if the longitudinal velocity would need some braking\n then\n autoNavigationUseBrake = true\n end\n\nend\n\n-- Lateral Translation\nlocal lateralStrafeEngineTags = 'thrust analog lateral'\nlocal lateralCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.lateral)\nif (lateralCommandType == axisCommandType.byThrottle) then\n local lateralStrafeAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromThrottle(lateralStrafeEngineTags,axisCommandId.lateral)\n Nav:setEngineForceCommand(lateralStrafeEngineTags, lateralStrafeAcceleration, keepCollinearity)\nelseif (lateralCommandType == axisCommandType.byTargetSpeed) then\n local lateralAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral)\n autoNavigationEngineTags = autoNavigationEngineTags .. ' , ' .. lateralStrafeEngineTags\n autoNavigationAcceleration = autoNavigationAcceleration + lateralAcceleration\nend\n\n-- Vertical Translation\nlocal verticalStrafeEngineTags = 'thrust analog vertical'\nlocal verticalCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.vertical)\nif (verticalCommandType == axisCommandType.byThrottle) then\n local verticalStrafeAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromThrottle(verticalStrafeEngineTags,axisCommandId.vertical)\n Nav:setEngineForceCommand(verticalStrafeEngineTags, verticalStrafeAcceleration, keepCollinearity, 'airfoil', 'ground', '', tolerancePercentToSkipOtherPriorities)\nelseif (verticalCommandType == axisCommandType.byTargetSpeed) then\n local verticalAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical)\n autoNavigationEngineTags = autoNavigationEngineTags .. ' , ' .. verticalStrafeEngineTags\n autoNavigationAcceleration = autoNavigationAcceleration + verticalAcceleration\nend\n\n-- Auto Navigation (Cruise Control)\nif (autoNavigationAcceleration:len() > constants.epsilon) then\n if (brakeInput ~= 0 or autoNavigationUseBrake or math.abs(constructVelocityDir:dot(constructForward)) < 0.95) -- if the velocity is not properly aligned with the forward\n then\n autoNavigationEngineTags = autoNavigationEngineTags .. ', brake'\n end\n Nav:setEngineForceCommand(autoNavigationEngineTags, autoNavigationAcceleration, dontKeepCollinearity, '', '', '', tolerancePercentToSkipOtherPriorities)\nend\n\n-- Rockets\nNav:setBoosterCommand('rocket_engine')\n"}, {"key": "8", "filter": {"slotKey": "-2", "signature": "actionStart(groundaltitudeup)", "args": [{"value": "groundaltitudeup"}]}, "code": "Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(1.0)"}, {"key": "9", "filter": {"slotKey": "-2", "signature": "actionLoop(groundaltitudeup)", "args": [{"value": "groundaltitudeup"}]}, "code": "Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(1.0)"}, {"key": "10", "filter": {"slotKey": "-2", "signature": "actionStart(groundaltitudedown)", "args": [{"value": "groundaltitudedown"}]}, "code": "Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(-1.0)"}, {"key": "11", "filter": {"slotKey": "-2", "signature": "actionStart(yawright)", "args": [{"value": "yawright"}]}, "code": "yawInput = yawInput - 1"}, {"key": "12", "filter": {"slotKey": "-2", "signature": "actionStop(yawright)", "args": [{"value": "yawright"}]}, "code": "yawInput = yawInput + 1"}, {"key": "13", "filter": {"slotKey": "-2", "signature": "actionLoop(groundaltitudedown)", "args": [{"value": "groundaltitudedown"}]}, "code": "Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(-1.0)"}, {"key": "14", "filter": {"slotKey": "-2", "signature": "actionStart(brake)", "args": [{"value": "brake"}]}, "code": "brakeInput = brakeInput + 1\nlocal longitudinalCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)\nif (longitudinalCommandType == axisCommandType.byTargetSpeed) then\n local targetSpeed = Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)\n if (math.abs(targetSpeed) > constants.epsilon) then\n Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal, - utils.sign(targetSpeed))\n end\nend\n"}, {"key": "15", "filter": {"slotKey": "-2", "signature": "actionStop(yawleft)", "args": [{"value": "yawleft"}]}, "code": "yawInput = yawInput - 1"}, {"key": "16", "filter": {"slotKey": "-2", "signature": "actionStart(yawleft)", "args": [{"value": "yawleft"}]}, "code": "yawInput = yawInput + 1"}, {"key": "17", "filter": {"slotKey": "-2", "signature": "actionStop(brake)", "args": [{"value": "brake"}]}, "code": "brakeInput = brakeInput - 1"}, {"key": "18", "filter": {"slotKey": "-2", "signature": "actionLoop(brake)", "args": [{"value": "brake"}]}, "code": "local longitudinalCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)\nif (longitudinalCommandType == axisCommandType.byTargetSpeed) then\n local targetSpeed = Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)\n if (math.abs(targetSpeed) > constants.epsilon) then\n Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal, - utils.sign(targetSpeed))\n end\nend\n"}, {"key": "19", "filter": {"slotKey": "-2", "signature": "actionStart(booster)", "args": [{"value": "booster"}]}, "code": "Nav:toggleBoosters()"}, {"key": "20", "filter": {"slotKey": "-2", "signature": "actionLoop(speedup)", "args": [{"value": "speedup"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal, 1.0)"}, {"key": "21", "filter": {"slotKey": "-2", "signature": "actionStart(stopengines)", "args": [{"value": "stopengines"}]}, "code": "Nav.axisCommandManager:resetCommand(axisCommandId.longitudinal)"}, {"key": "22", "filter": {"slotKey": "-2", "signature": "actionStart(speedup)", "args": [{"value": "speedup"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal, 5.0)"}, {"key": "23", "filter": {"slotKey": "-2", "signature": "actionLoop(speeddown)", "args": [{"value": "speeddown"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal, -1.0)"}, {"key": "24", "filter": {"slotKey": "-2", "signature": "actionStart(antigravity)", "args": [{"value": "antigravity"}]}, "code": "if antigrav ~= nil then antigrav.toggle() end"}, {"key": "25", "filter": {"slotKey": "-2", "signature": "actionStart(speeddown)", "args": [{"value": "speeddown"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal, -5.0)"}, {"key": "26", "filter": {"slotKey": "-2", "signature": "actionStart(straferight)", "args": [{"value": "straferight"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral, 1.0)"}, {"key": "27", "filter": {"slotKey": "-2", "signature": "actionStop(right)", "args": [{"value": "right"}]}, "code": "rollInput = rollInput - 1"}, {"key": "28", "filter": {"slotKey": "-2", "signature": "actionStart(right)", "args": [{"value": "right"}]}, "code": "rollInput = rollInput + 1"}, {"key": "29", "filter": {"slotKey": "-2", "signature": "actionStart(strafeleft)", "args": [{"value": "strafeleft"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral, -1.0)"}, {"key": "30", "filter": {"slotKey": "-2", "signature": "actionStop(straferight)", "args": [{"value": "straferight"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral, -1.0)"}, {"key": "31", "filter": {"slotKey": "-2", "signature": "actionStop(strafeleft)", "args": [{"value": "strafeleft"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral, 1.0)"}, {"key": "32", "filter": {"slotKey": "-2", "signature": "actionStop(up)", "args": [{"value": "up"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical, -1.0)\nNav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)\n"}, {"key": "33", "filter": {"slotKey": "-2", "signature": "actionStart(up)", "args": [{"value": "up"}]}, "code": "Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()\nNav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical, 1.0)\n"}, {"key": "34", "filter": {"slotKey": "-2", "signature": "actionStart(down)", "args": [{"value": "down"}]}, "code": "Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()\nNav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical, -1.0)\n"}, {"key": "35", "filter": {"slotKey": "-2", "signature": "actionStop(down)", "args": [{"value": "down"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical, 1.0)\nNav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)\n"}, {"key": "36", "filter": {"slotKey": "-2", "signature": "actionStart(left)", "args": [{"value": "left"}]}, "code": "rollInput = rollInput - 1"}, {"key": "37", "filter": {"slotKey": "-2", "signature": "update()", "args": []}, "code": "Nav:update()"}, {"key": "38", "filter": {"slotKey": "-2", "signature": "actionStart(forward)", "args": [{"value": "forward"}]}, "code": "pitchInput = pitchInput - 1"}, {"key": "39", "filter": {"slotKey": "-2", "signature": "actionStart(light)", "args": [{"value": "light"}]}, "code": "if Nav.control.isAnyHeadlightSwitchedOn() == 1 then\n Nav.control.switchOffHeadlights()\nelse\n Nav.control.switchOnHeadlights()\nend\n"}], "methods": [], "events": []} \ No newline at end of file diff --git a/json/hover_seat/ground.json b/json/hover_seat/ground.json new file mode 100644 index 0000000..439dfd7 --- /dev/null +++ b/json/hover_seat/ground.json @@ -0,0 +1 @@ +{"slots": {"4": {"name": "slot5", "type": {"methods": [], "events": []}}, "-1": {"name": "unit", "type": {"methods": [], "events": []}}, "-2": {"name": "system", "type": {"methods": [], "events": []}}, "-3": {"name": "library", "type": {"methods": [], "events": []}}, "0": {"name": "core", "type": {"methods": [], "events": []}}, "1": {"name": "slot2", "type": {"methods": [], "events": []}}, "2": {"name": "slot3", "type": {"methods": [], "events": []}}, "3": {"name": "slot4", "type": {"methods": [], "events": []}}, "5": {"name": "slot6", "type": {"methods": [], "events": []}}, "6": {"name": "slot7", "type": {"methods": [], "events": []}}, "7": {"name": "slot8", "type": {"methods": [], "events": []}}, "8": {"name": "slot9", "type": {"methods": [], "events": []}}, "9": {"name": "slot10", "type": {"methods": [], "events": []}}, "10": {"name": "slot11", "type": {"methods": [], "events": []}}, "11": {"name": "slot12", "type": {"methods": [], "events": []}}, "12": {"name": "slot13", "type": {"methods": [], "events": []}}, "13": {"name": "slot14", "type": {"methods": [], "events": []}}, "14": {"name": "slot15", "type": {"methods": [], "events": []}}, "15": {"name": "slot16", "type": {"methods": [], "events": []}}, "16": {"name": "slot17", "type": {"methods": [], "events": []}}, "17": {"name": "slot18", "type": {"methods": [], "events": []}}, "18": {"name": "slot19", "type": {"methods": [], "events": []}}, "19": {"name": "slot20", "type": {"methods": [], "events": []}}, "20": {"name": "slot21", "type": {"methods": [], "events": []}}}, "handlers": [{"key": "0", "filter": {"slotKey": "-1", "signature": "start()", "args": []}, "code": "-- category panel display helpers\n_autoconf = {}\n_autoconf.panels = {}\n_autoconf.panels_size = 0\n_autoconf.displayCategoryPanel = function(elements, size, title, type, widgetPerData)\n widgetPerData = widgetPerData or false -- default to one widget for all data\n if size > 0 then\n local panel = system.createWidgetPanel(title)\n local widget\n if not widgetPerData then\n widget = system.createWidget(panel, type)\n end\n for i = 1, size do\n if widgetPerData then\n widget = system.createWidget(panel, type)\n end\n system.addDataToWidget(elements[i].getDataId(), widget)\n end\n _autoconf.panels_size = _autoconf.panels_size + 1\n _autoconf.panels[_autoconf.panels_size] = panel\n end\nend\n_autoconf.hideCategoryPanels = function()\n for i=1,_autoconf.panels_size do\n system.destroyWidgetPanel(_autoconf.panels[i])\n end\nend\n-- Proxy array to access auto-plugged slots programmatically\n\natmofueltank = {}\natmofueltank_size = 0\n\nspacefueltank = {}\nspacefueltank_size = 0\n\nrocketfueltank = {}\nrocketfueltank_size = 0\n\nradar = {}\nradar_size = 0\n\nweapon = {}\nweapon_size = 0\n-- End of auto-generated code\npitchInput = 0\npitchInputFromDevice = 0\nrollInput = 0\nyawInput = 0\nverticalStrafeInput = 0\nlateralStrafeInput = 0\nbrakeInput = 0\ngoingBack = false\ngoingForward = false\nshiftPressed = false\njumpDelta = 0\nbaseAcceleration = 0.8 --export: Acceleration provided when 'forward' is hit, expressed in g\n\nNav = Navigator.new(system, core, unit)\nNav.axisCommandManager:setupCustomTargetSpeedRanges(axisCommandId.longitudinal, {100, 500, 1000, 5000})\nNav.axisCommandManager:setTargetGroundAltitude(6)\n\n-- Parenting widget\nparentingPanelId = system.createWidgetPanel(\"Docking\")\nparentingWidgetId = system.createWidget(parentingPanelId,\"parenting\")\nsystem.addDataToWidget(unit.getDataId(),parentingWidgetId)\n\n-- Combat stress widget\ncoreCombatStressPanelId = system.createWidgetPanel(\"Core combat stress\")\ncoreCombatStressgWidgetId = system.createWidget(coreCombatStressPanelId,\"core_stress\")\nsystem.addDataToWidget(core.getDataId(),coreCombatStressgWidgetId)\n\n-- element widgets\n-- For now we have to alternate between PVP and non-PVP widgets to have them on the same side.\n_autoconf.displayCategoryPanel(weapon, weapon_size, \"Weapons\", \"weapon\", true)\ncore.show()\n_autoconf.displayCategoryPanel(radar, radar_size, \"Periscope\", \"periscope\")\nplaceRadar = true\nif atmofueltank_size > 0 then\n _autoconf.displayCategoryPanel(atmofueltank, atmofueltank_size, \"Atmo Fuel\", \"fuel_container\")\n if placeRadar then\n _autoconf.displayCategoryPanel(radar, radar_size, \"Radar\", \"radar\")\n placeRadar = false\n end\nend\nif spacefueltank_size > 0 then\n _autoconf.displayCategoryPanel(spacefueltank, spacefueltank_size, \"Space Fuel\", \"fuel_container\")\n if placeRadar then\n _autoconf.displayCategoryPanel(radar, radar_size, \"Radar\", \"radar\")\n placeRadar = false\n end\nend\n_autoconf.displayCategoryPanel(rocketfueltank, rocketfueltank_size, \"Rocket Fuel\", \"fuel_container\")\nif placeRadar then -- We either have only rockets or no fuel tanks at all, uncommon for usual vessels\n _autoconf.displayCategoryPanel(radar, radar_size, \"Radar\", \"radar\")\n placeRadar = false\nend\nif antigrav ~= nil then antigrav.show() end\nif gyro ~= nil then gyro.show() end\n\nthrottleStep = 0.25 --export: When pressing the SpeedUp/SpeedDown buttons, this step will be using to increment/decrement the throttle
Valid values: From 0.01 to 1\nthrottleStep = utils.clamp(throttleStep, 0.01, 1)\n\n-- freeze the player in he is remote controlling the construct\nif Nav.control.isRemoteControlled() == 1 then\n system.freeze(1)\nend\n\n-- landing gear\n-- make sure every gears are synchonized with the first\ngearExtended = (Nav.control.isAnyLandingGearExtended() == 1) -- make sure it's a lua boolean\nif gearExtended then\n Nav.control.extendLandingGears()\nelse\n Nav.control.retractLandingGears()\nend\n\n-- forward/backward functions\nstartForward = function ()\n if Nav:isTravelMode() then\n brakeInput = 0\n local throttle = 1\n if not shiftPressed then\n local maxGForward = Nav:maxForceForward() / (self.core.getConstructMass() * 9.81)\n throttle = utils.clamp(baseAcceleration / maxGForward, 0, 1)\n end\n\n Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, throttle)\n goingForward = true\n end\nend\n\nstopForward = function ()\n if Nav:isTravelMode() then\n pitchInput = 0\n Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, 0)\n brakeInput = 0.5\n goingForward = false\n if goingBackward then\n startBackward()\n end\n end\nend\n\ndirection = {forward=1, backward = -1}\nloopDirection = function (direction)\n if Nav:isTravelMode() then\n local currentVelocity = vec3(self.core.getVelocity())\n local axisCRefDirection = vec3(self.core.getConstructOrientationForward())\n\n lastCurrentSpeed = currentVelocity:dot(axisCRefDirection)\n\n if (lastCurrentSpeed * direction < 0) then\n brakeInput = 1\n autobrake = true\n else\n if autobrake == true then\n autobrake = false\n brakeInput = 0\n end\n end\n else\n Nav.axisCommandManager.axisCommands[axisCommandId.longitudinal]:updateCommandFromActionLoop(direction)\n end\nend\n\nstartBackward = function ()\n if Nav:isTravelMode() then\n pitchInput = 0\n brakeInput = 0\n\n local maxGBackward = Nav:maxForceBackward() / (self.core.getConstructMass() * 9.81)\n local throttle = utils.clamp(baseAcceleration / maxGBackward, -1, 0)\n\n Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, throttle)\n goingBack = true\n end\nend\n\nstopBackward = function ()\n if Nav:isTravelMode() then\n pitchInput = 0\n Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, 0)\n brakeInput = 0.5\n goingBack = false\n if goingForward then\n startForward()\n end\n end\nend\n"}, {"key": "1", "filter": {"slotKey": "-1", "signature": "stop()", "args": []}, "code": "_autoconf.hideCategoryPanels()\nif antigrav ~= nil then antigrav.hide() end\nif gyro ~= nil then gyro.hide() end\ncore.hide()\nNav.control.switchOffHeadlights()\n"}, {"key": "2", "filter": {"slotKey": "-2", "signature": "actionStop(forward)", "args": [{"value": "forward"}]}, "code": "stopForward()"}, {"key": "3", "filter": {"slotKey": "-2", "signature": "actionStart(lshift)", "args": [{"value": "lshift"}]}, "code": "shiftPressed = true\nif goingForward then\n Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, 1)\nend\n"}, {"key": "4", "filter": {"slotKey": "-2", "signature": "actionStop(lshift)", "args": [{"value": "lshift"}]}, "code": "shiftPressed = false\nif goingForward then\n local maxGForward = Nav:maxForceForward() / (self.core.getConstructMass() * 9.81)\n local throttle = utils.clamp(baseAcceleration / maxGForward, 0, 1)\n Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, throttle)\nend\n"}, {"key": "5", "filter": {"slotKey": "-2", "signature": "actionStart(left)", "args": [{"value": "left"}]}, "code": "rollInput = rollInput - 1"}, {"key": "6", "filter": {"slotKey": "-2", "signature": "actionStop(left)", "args": [{"value": "left"}]}, "code": "rollInput = rollInput + 1"}, {"key": "7", "filter": {"slotKey": "-2", "signature": "actionStart(right)", "args": [{"value": "right"}]}, "code": "rollInput = rollInput + 1"}, {"key": "8", "filter": {"slotKey": "-2", "signature": "actionStop(right)", "args": [{"value": "right"}]}, "code": "rollInput = rollInput - 1"}, {"key": "9", "filter": {"slotKey": "-2", "signature": "actionStart(straferight)", "args": [{"value": "straferight"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral, 1.0)"}, {"key": "10", "filter": {"slotKey": "-2", "signature": "actionStop(straferight)", "args": [{"value": "straferight"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral, -1.0)"}, {"key": "11", "filter": {"slotKey": "-2", "signature": "actionStart(strafeleft)", "args": [{"value": "strafeleft"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral, -1.0)"}, {"key": "12", "filter": {"slotKey": "-2", "signature": "actionStop(strafeleft)", "args": [{"value": "strafeleft"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral, 1.0)"}, {"key": "13", "filter": {"slotKey": "-2", "signature": "actionStart(up)", "args": [{"value": "up"}]}, "code": "baseAltitude = Nav:getTargetGroundAltitude()\nNav.axisCommandManager:setTargetGroundAltitude(baseAltitude + 4)\n"}, {"key": "14", "filter": {"slotKey": "-2", "signature": "actionLoop(up)", "args": [{"value": "up"}]}, "code": "if unit.isMouseControlActivated() == 0 then\n jumpDelta = utils.clamp(jumpDelta + 0.01, 0, 0.6)\nend\n"}, {"key": "15", "filter": {"slotKey": "-2", "signature": "actionStop(up)", "args": [{"value": "up"}]}, "code": "Nav.axisCommandManager:setTargetGroundAltitude(baseAltitude)\nif unit.isMouseControlActivated() == 0 then\n jumpDelta = 0\nend\n"}, {"key": "16", "filter": {"slotKey": "-2", "signature": "actionStart(down)", "args": [{"value": "down"}]}, "code": "Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()\nNav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical, -1.0)\n"}, {"key": "17", "filter": {"slotKey": "-2", "signature": "actionStop(down)", "args": [{"value": "down"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical, 1.0)\nNav.axisCommandManager:activateGroundEngineAltitudeStabilization(defaultGroundAltitudeStabilization)\n"}, {"key": "18", "filter": {"slotKey": "-2", "signature": "actionStart(groundaltitudeup)", "args": [{"value": "groundaltitudeup"}]}, "code": "Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(1.0)"}, {"key": "19", "filter": {"slotKey": "-2", "signature": "actionLoop(groundaltitudeup)", "args": [{"value": "groundaltitudeup"}]}, "code": "Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(1.0)\njumpDelta = 0\n"}, {"key": "20", "filter": {"slotKey": "-2", "signature": "actionStart(groundaltitudedown)", "args": [{"value": "groundaltitudedown"}]}, "code": "Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(-1.0)"}, {"key": "21", "filter": {"slotKey": "-2", "signature": "actionLoop(groundaltitudedown)", "args": [{"value": "groundaltitudedown"}]}, "code": "Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(-1.0)"}, {"key": "22", "filter": {"slotKey": "-2", "signature": "actionStart(yawright)", "args": [{"value": "yawright"}]}, "code": "yawInput = yawInput - 1"}, {"key": "23", "filter": {"slotKey": "-2", "signature": "actionStop(yawright)", "args": [{"value": "yawright"}]}, "code": "yawInput = yawInput + 1"}, {"key": "24", "filter": {"slotKey": "-2", "signature": "actionStart(yawleft)", "args": [{"value": "yawleft"}]}, "code": "yawInput = yawInput + 1"}, {"key": "25", "filter": {"slotKey": "-2", "signature": "actionStop(yawleft)", "args": [{"value": "yawleft"}]}, "code": "yawInput = yawInput - 1"}, {"key": "26", "filter": {"slotKey": "-2", "signature": "actionStart(brake)", "args": [{"value": "brake"}]}, "code": "brakeInput = brakeInput + 1\nlocal longitudinalCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)\nif (longitudinalCommandType == axisCommandType.byTargetSpeed) then\n local targetSpeed = Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)\n if (math.abs(targetSpeed) > constants.epsilon) then\n Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal, - utils.sign(targetSpeed))\n end\nend\n"}, {"key": "27", "filter": {"slotKey": "-2", "signature": "actionStop(brake)", "args": [{"value": "brake"}]}, "code": "brakeInput = 0"}, {"key": "28", "filter": {"slotKey": "-2", "signature": "actionLoop(brake)", "args": [{"value": "brake"}]}, "code": "local longitudinalCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)\nif (longitudinalCommandType == axisCommandType.byTargetSpeed) then\n local targetSpeed = Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)\n if (math.abs(targetSpeed) > constants.epsilon) then\n Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal, - utils.sign(targetSpeed))\n end\nend\n"}, {"key": "29", "filter": {"slotKey": "-2", "signature": "actionStart(stopengines)", "args": [{"value": "stopengines"}]}, "code": "Nav.axisCommandManager:resetCommand(axisCommandId.longitudinal)"}, {"key": "30", "filter": {"slotKey": "-2", "signature": "actionStart(booster)", "args": [{"value": "booster"}]}, "code": "Nav:toggleBoosters()"}, {"key": "31", "filter": {"slotKey": "-2", "signature": "actionStop(speedup)", "args": [{"value": "speedup"}]}, "code": "stopForward()"}, {"key": "32", "filter": {"slotKey": "-2", "signature": "actionLoop(speedup)", "args": [{"value": "speedup"}]}, "code": "loopDirection(direction.forward)"}, {"key": "33", "filter": {"slotKey": "-2", "signature": "actionStart(speedup)", "args": [{"value": "speedup"}]}, "code": "startForward()"}, {"key": "34", "filter": {"slotKey": "-2", "signature": "actionStart(antigravity)", "args": [{"value": "antigravity"}]}, "code": "if antigrav ~= nil then antigrav.toggle() end"}, {"key": "35", "filter": {"slotKey": "-2", "signature": "actionStop(speeddown)", "args": [{"value": "speeddown"}]}, "code": "stopBackward()"}, {"key": "36", "filter": {"slotKey": "-2", "signature": "actionStart(speeddown)", "args": [{"value": "speeddown"}]}, "code": "startBackward()"}, {"key": "37", "filter": {"slotKey": "-2", "signature": "actionLoop(speeddown)", "args": [{"value": "speeddown"}]}, "code": "loopDirection(direction.backward)"}, {"key": "38", "filter": {"slotKey": "-2", "signature": "update()", "args": []}, "code": "Nav:update()\nif system.getThrottleInputFromMouseWheel() ~= 0.0 then\n brakeInput = 0\nend\n\nif unit.isMouseControlActivated() == 0 then\n local currentVelocity = vec3(self.core.getVelocity())\n local axisCRefDirection = vec3(self.core.getConstructOrientationForward())\n local v = currentVelocity:dot(axisCRefDirection)\n local minv = 20\n local maxPitch = 0.4\n if v < minv or not goingForward then\n pitchInput = 0\n else\n if not goingBack and goingForward then\n pitchInput = utils.clamp((maxPitch/minv) * (v - minv), 0, maxPitch)\n end\n end\nend\n\npitchInput = pitchInput + jumpDelta\n"}, {"key": "39", "filter": {"slotKey": "-2", "signature": "flush()", "args": []}, "code": "-- constants: use 'myvar = defaultValue --export: description' to expose the variable in context menu
in degree
Valid values: Superior or equal to 1\nlocal rollAmplitude = 30 --export: When turning, the auto roll won't go over or under rollAmplitude
in degree
Valid values: Superior or equal to 1\nlocal pitchAmplitude = 25 --export: When pitching, the pitch won't go over or under pitchAmplitude (in degree)\nlocal yawSpeedFactor = 1.5 --export When turning, the inputs will be multiplied by this factor
Valid values: Superior or equal to 0.01\nlocal yawAccelerationFactor = 3 --export: When turning, the yaw response will be multiplied by this factor
Valid values: Superior or equal to 0.01\n\nlocal lateralAntiDriftFactor = 1 --export: When compensating for drift, this factor will increase/decrease the drift force requested to engines
Valid values: Superior or equal to 0.01\nlocal lateralStrafeFactor = 5 --export: This factor will increase/decrease the player input along the horizontal strafe axis axis
Valid values: Superior or equal to 0.01\n\nlocal brakeSpeedFactor = 1 --export: When braking, this factor will increase the brake force by brakeSpeedFactor * velocity
Valid values: Superior or equal to 0.01\nlocal brakeFlatFactor = 4 --export: When braking, this factor will increase the brake force by a flat brakeFlatFactor * velocity direction>
(higher value may be unstable)
Valid values: Superior or equal to 0.01\nlocal autoBrakeSpeed = 15 --export: Auto brake when speed is below that value (in m/s), with no thrust\n\n-- validate params\nbrakeSpeedFactor = math.max(brakeSpeedFactor, 0.01)\nbrakeFlatFactor = math.max(brakeFlatFactor, 0.01)\nrollAmplitude = math.max(rollAmplitude, 1)\npitchAmplitude = math.max(pitchAmplitude, 1)\nyawSpeedFactor = math.max(yawSpeedFactor, 0.01)\nyawAccelerationFactor = math.max(yawAccelerationFactor, 0.01)\n\nif (rollPID == nil) then\n rollPID = pid.new(0.2, 0, 10)\n pitchPID = pid.new(0.2, 0, 10)\nend\n\n-- final inputs\nif Nav.control.isMouseDirectControlActivated() then\n -- in direct control, we tweak the pitch to behave inbetween virtual joystick and direct control\n -- this helps a lot for ground construct control\n pitchInputFromDevice = utils.clamp(pitchInputFromDevice + system.getControlDeviceForwardInput() * system.getActionUpdateDeltaTime(), -1.0, 1.0)\nelse\n pitchInputFromDevice = system.getControlDeviceForwardInput()\nend\nlocal finalPitchInput = pitchInput + pitchInputFromDevice\nlocal finalRollInput = rollInput + system.getControlDeviceYawInput()\nlocal finalYawInput = yawInput - system.getControlDeviceLeftRightInput()\nlocal combinedRollYawInput = utils.clamp(finalRollInput - finalYawInput, -1.0, 1.0);\nlocal finalVerticalStrafeInput = verticalStrafeInput\nlocal finalLateralStrafeInput = lateralStrafeInput;\nlocal finalBrakeInput = brakeInput\n\n-- Axis\nlocal worldVertical = vec3(core.getWorldVertical())\nlocal constructUp = vec3(core.getConstructWorldOrientationUp())\nlocal constructForward = vec3(core.getConstructWorldOrientationForward())\nlocal constructRight = vec3(core.getConstructWorldOrientationRight())\nlocal constructVelocity = vec3(core.getWorldVelocity())\nlocal constructVelocityDir = vec3(core.getWorldVelocity()):normalize()\nlocal constructAngularVelocity = vec3(core.getWorldAngularVelocity())\nlocal constructYawVelocity = constructAngularVelocity:dot(constructUp)\n\n-- Engine commands\nlocal keepCollinearity = 0 -- for easier reading\nlocal dontKeepCollinearity = 1 -- for easier reading\nlocal tolerancePercentToSkipOtherPriorities = 1 -- if we are within this tolerance (in%), we don't go to the next priorities\n\n-- Rotation\nlocal currentRollDeg = getRoll(worldVertical, constructForward, constructRight)\nlocal currentPitchDeg = -math.asin(constructForward:dot(worldVertical)) * constants.rad2deg\nlocal targetRollDeg = utils.clamp(combinedRollYawInput * rollAmplitude, -rollAmplitude, rollAmplitude)\nlocal targetPitchDeg = utils.clamp(finalPitchInput * pitchAmplitude, -pitchAmplitude, pitchAmplitude)\nrollPID:inject(targetRollDeg - currentRollDeg)\npitchPID:inject(targetPitchDeg - currentPitchDeg)\n\nlocal constructYawTargetVelocity = -combinedRollYawInput * yawSpeedFactor\nlocal constructYawTargetAcceleration = yawAccelerationFactor * (constructYawTargetVelocity - constructYawVelocity)\n\nlocal constructTargetAngularVelocity = rollPID:get() * constructForward\n + pitchPID:get() * constructRight\n + constructYawTargetAcceleration * constructUp\n\nNav:setEngineTorqueCommand('torque', constructTargetAngularVelocity, keepCollinearity, 'airfoil', '', '', tolerancePercentToSkipOtherPriorities)\n\n-- Brakes\nif (finalBrakeInput == 0 and autoBrakeSpeed > 0 and Nav.axisCommandManager.throttle == 0 and constructVelocity:len() < autoBrakeSpeed) then\n finalBrakeInput = 1\nend\nlocal brakeAcceleration = -finalBrakeInput * (brakeSpeedFactor * constructVelocity + brakeFlatFactor * constructVelocityDir)\nNav:setEngineForceCommand('brake', brakeAcceleration)\n\n-- AutoNavigation regroups all the axis command by 'TargetSpeed'\nlocal autoNavigationEngineTags = ''\nlocal autoNavigationAcceleration = vec3()\nlocal autoNavigationUseBrake = false\n\n-- Longitudinal Translation\nlocal longitudinalEngineTags = 'thrust analog longitudinal'\nlocal longitudinalCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)\nif (longitudinalCommandType == axisCommandType.byThrottle) then\n local longitudinalAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromThrottle(longitudinalEngineTags,axisCommandId.longitudinal)\n Nav:setEngineForceCommand(longitudinalEngineTags, longitudinalAcceleration, keepCollinearity)\nelseif (longitudinalCommandType == axisCommandType.byTargetSpeed) then\n local longitudinalAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.longitudinal)\n autoNavigationEngineTags = autoNavigationEngineTags .. ' , ' .. longitudinalEngineTags\n autoNavigationAcceleration = autoNavigationAcceleration + longitudinalAcceleration\n if (Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal) == 0 or -- we want to stop\n Nav.axisCommandManager:getCurrentToTargetDeltaSpeed(axisCommandId.longitudinal) < - Nav.axisCommandManager:getTargetSpeedCurrentStep(axisCommandId.longitudinal) * 0.5) -- if the longitudinal velocity would need some braking\n then\n autoNavigationUseBrake = true\n end\n\nend\n\n-- Lateral Translation\nlocal lateralStrafeEngineTags = 'thrust analog lateral'\nlocal lateralCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.lateral)\nif (lateralCommandType == axisCommandType.byThrottle) then\n local lateralStrafeAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromThrottle(lateralStrafeEngineTags,axisCommandId.lateral)\n Nav:setEngineForceCommand(lateralStrafeEngineTags, lateralStrafeAcceleration, keepCollinearity)\nelseif (lateralCommandType == axisCommandType.byTargetSpeed) then\n local lateralAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral)\n autoNavigationEngineTags = autoNavigationEngineTags .. ' , ' .. lateralStrafeEngineTags\n autoNavigationAcceleration = autoNavigationAcceleration + lateralAcceleration\nend\n\n-- Vertical Translation\nlocal verticalStrafeEngineTags = 'thrust analog vertical'\nlocal verticalCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.vertical)\nif (verticalCommandType == axisCommandType.byThrottle) then\n local verticalStrafeAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromThrottle(verticalStrafeEngineTags,axisCommandId.vertical)\n Nav:setEngineForceCommand(verticalStrafeEngineTags, verticalStrafeAcceleration, keepCollinearity, 'airfoil', 'ground', '', tolerancePercentToSkipOtherPriorities)\nelseif (verticalCommandType == axisCommandType.byTargetSpeed) then\n local verticalAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical)\n autoNavigationEngineTags = autoNavigationEngineTags .. ' , ' .. verticalStrafeEngineTags\n autoNavigationAcceleration = autoNavigationAcceleration + verticalAcceleration\nend\n\n-- Auto Navigation (Cruise Control)\nif (autoNavigationAcceleration:len() > constants.epsilon) then\n if (brakeInput ~= 0 or autoNavigationUseBrake or math.abs(constructVelocityDir:dot(constructForward)) < 0.95) -- if the velocity is not properly aligned with the forward\n then\n autoNavigationEngineTags = autoNavigationEngineTags .. ', brake'\n end\n Nav:setEngineForceCommand(autoNavigationEngineTags, autoNavigationAcceleration, dontKeepCollinearity, '', '', '', tolerancePercentToSkipOtherPriorities)\nend\n\n-- Rockets\nNav:setBoosterCommand('rocket_engine')\n"}, {"key": "40", "filter": {"slotKey": "-2", "signature": "actionStart(gear)", "args": [{"value": "gear"}]}, "code": "gearExtended = not gearExtended\nif gearExtended then\n Nav.control.extendLandingGears()\nelse\n Nav.control.retractLandingGears()\nend\n"}, {"key": "41", "filter": {"slotKey": "-2", "signature": "actionStart(light)", "args": [{"value": "light"}]}, "code": "if Nav.control.isAnyHeadlightSwitchedOn() == 1 then\n Nav.control.switchOffHeadlights()\nelse\n Nav.control.switchOnHeadlights()\nend\n"}, {"key": "42", "filter": {"slotKey": "-2", "signature": "actionLoop(backward)", "args": [{"value": "backward"}]}, "code": "loopDirection(direction.backward)"}, {"key": "43", "filter": {"slotKey": "-2", "signature": "actionStart(backward)", "args": [{"value": "backward"}]}, "code": "startBackward()"}, {"key": "44", "filter": {"slotKey": "-2", "signature": "actionStop(backward)", "args": [{"value": "backward"}]}, "code": "stopBackward()"}, {"key": "45", "filter": {"slotKey": "-2", "signature": "actionLoop(forward)", "args": [{"value": "forward"}]}, "code": "loopDirection(direction.forward)"}, {"key": "46", "filter": {"slotKey": "-2", "signature": "actionStart(forward)", "args": [{"value": "forward"}]}, "code": "startForward()"}], "methods": [], "events": []} \ No newline at end of file diff --git a/json/pilot_seat/flying.json b/json/pilot_seat/flying.json new file mode 100644 index 0000000..13250b7 --- /dev/null +++ b/json/pilot_seat/flying.json @@ -0,0 +1 @@ +{"slots": {"4": {"name": "slot5", "type": {"methods": [], "events": []}}, "-1": {"name": "unit", "type": {"methods": [], "events": []}}, "-2": {"name": "system", "type": {"methods": [], "events": []}}, "-3": {"name": "library", "type": {"methods": [], "events": []}}, "0": {"name": "core", "type": {"methods": [], "events": []}}, "1": {"name": "slot2", "type": {"methods": [], "events": []}}, "2": {"name": "slot3", "type": {"methods": [], "events": []}}, "3": {"name": "slot4", "type": {"methods": [], "events": []}}, "5": {"name": "slot6", "type": {"methods": [], "events": []}}, "6": {"name": "slot7", "type": {"methods": [], "events": []}}, "7": {"name": "slot8", "type": {"methods": [], "events": []}}, "8": {"name": "slot9", "type": {"methods": [], "events": []}}, "9": {"name": "slot10", "type": {"methods": [], "events": []}}, "10": {"name": "slot11", "type": {"methods": [], "events": []}}}, "handlers": [{"key": "0", "filter": {"slotKey": "-2", "signature": "actionStart(strafeleft)", "args": [{"value": "strafeleft"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral, -1.0)"}, {"key": "1", "filter": {"slotKey": "-2", "signature": "actionStop(strafeleft)", "args": [{"value": "strafeleft"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral, 1.0)"}, {"key": "2", "filter": {"slotKey": "-2", "signature": "actionStart(up)", "args": [{"value": "up"}]}, "code": "Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()\nNav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical, 1.0)\n"}, {"key": "3", "filter": {"slotKey": "-2", "signature": "actionStop(up)", "args": [{"value": "up"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical, -1.0)\nNav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)\n"}, {"key": "4", "filter": {"slotKey": "-2", "signature": "actionStart(down)", "args": [{"value": "down"}]}, "code": "Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()\nNav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical, -1.0)\n"}, {"key": "5", "filter": {"slotKey": "-2", "signature": "actionStop(down)", "args": [{"value": "down"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical, 1.0)\nNav.axisCommandManager:activateGroundEngineAltitudeStabilization(currentGroundAltitudeStabilization)\n"}, {"key": "6", "filter": {"slotKey": "-2", "signature": "actionLoop(groundaltitudeup)", "args": [{"value": "groundaltitudeup"}]}, "code": "Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(1.0)"}, {"key": "7", "filter": {"slotKey": "-2", "signature": "actionStart(groundaltitudedown)", "args": [{"value": "groundaltitudedown"}]}, "code": "Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(-1.0)"}, {"key": "8", "filter": {"slotKey": "-2", "signature": "actionLoop(groundaltitudedown)", "args": [{"value": "groundaltitudedown"}]}, "code": "Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(-1.0)"}, {"key": "9", "filter": {"slotKey": "-2", "signature": "actionStart(groundaltitudeup)", "args": [{"value": "groundaltitudeup"}]}, "code": "Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(1.0)"}, {"key": "10", "filter": {"slotKey": "-2", "signature": "flush()", "args": []}, "code": "-- constants: use 'myvar = defaultValue --export: description' to expose the variable in context menu\n\nlocal pitchSpeedFactor = 0.8 --export: This factor will increase/decrease the player input along the pitch axis
(higher value may be unstable)
Valid values: Superior or equal to 0.01\nlocal yawSpeedFactor = 1 --export: This factor will increase/decrease the player input along the yaw axis
(higher value may be unstable)
Valid values: Superior or equal to 0.01\nlocal rollSpeedFactor = 1.5 --export: This factor will increase/decrease the player input along the roll axis
(higher value may be unstable)
Valid values: Superior or equal to 0.01\n\nlocal brakeSpeedFactor = 3 --export: When braking, this factor will increase the brake force by brakeSpeedFactor * velocity
Valid values: Superior or equal to 0.01\nlocal brakeFlatFactor = 1 --export: When braking, this factor will increase the brake force by a flat brakeFlatFactor * velocity direction>
(higher value may be unstable)
Valid values: Superior or equal to 0.01\n\nlocal autoRoll = false --export: [Only in atmosphere]
When the pilot stops rolling, flight model will try to get back to horizontal (no roll)\nlocal autoRollFactor = 2 --export: [Only in atmosphere]
When autoRoll is engaged, this factor will increase to strength of the roll back to 0
Valid values: Superior or equal to 0.01\n\nlocal turnAssist = true --export: [Only in atmosphere]
When the pilot is rolling, the flight model will try to add yaw and pitch to make the construct turn better
The flight model will start by adding more yaw the more horizontal the construct is and more pitch the more vertical it is\nlocal turnAssistFactor = 2 --export: [Only in atmosphere]
This factor will increase/decrease the turnAssist effect
(higher value may be unstable)
Valid values: Superior or equal to 0.01\n\nlocal torqueFactor = 2 -- Force factor applied to reach rotationSpeed
(higher value may be unstable)
Valid values: Superior or equal to 0.01\n\n-- validate params\npitchSpeedFactor = math.max(pitchSpeedFactor, 0.01)\nyawSpeedFactor = math.max(yawSpeedFactor, 0.01)\nrollSpeedFactor = math.max(rollSpeedFactor, 0.01)\ntorqueFactor = math.max(torqueFactor, 0.01)\nbrakeSpeedFactor = math.max(brakeSpeedFactor, 0.01)\nbrakeFlatFactor = math.max(brakeFlatFactor, 0.01)\nautoRollFactor = math.max(autoRollFactor, 0.01)\nturnAssistFactor = math.max(turnAssistFactor, 0.01)\n\n-- final inputs\nlocal finalPitchInput = pitchInput + system.getControlDeviceForwardInput()\nlocal finalRollInput = rollInput + system.getControlDeviceYawInput()\nlocal finalYawInput = yawInput - system.getControlDeviceLeftRightInput()\nlocal finalBrakeInput = brakeInput\n\n-- Axis\nlocal worldVertical = vec3(core.getWorldVertical()) -- along gravity\nlocal constructUp = vec3(core.getConstructWorldOrientationUp())\nlocal constructForward = vec3(core.getConstructWorldOrientationForward())\nlocal constructRight = vec3(core.getConstructWorldOrientationRight())\nlocal constructVelocity = vec3(core.getWorldVelocity())\nlocal constructVelocityDir = vec3(core.getWorldVelocity()):normalize()\nlocal currentRollDeg = getRoll(worldVertical, constructForward, constructRight)\nlocal currentRollDegAbs = math.abs(currentRollDeg)\nlocal currentRollDegSign = utils.sign(currentRollDeg)\n\n-- Rotation\nlocal constructAngularVelocity = vec3(core.getWorldAngularVelocity())\nlocal targetAngularVelocity = finalPitchInput * pitchSpeedFactor * constructRight\n + finalRollInput * rollSpeedFactor * constructForward\n + finalYawInput * yawSpeedFactor * constructUp\n\n-- In atmosphere?\nif worldVertical:len() > 0.01 and unit.getAtmosphereDensity() > 0.0 then\n local autoRollRollThreshold = 1.0\n -- autoRoll on AND currentRollDeg is big enough AND player is not rolling\n if autoRoll == true and currentRollDegAbs > autoRollRollThreshold and finalRollInput == 0 then\n local targetRollDeg = utils.clamp(0,currentRollDegAbs-30, currentRollDegAbs+30); -- we go back to 0 within a certain limit\n if (rollPID == nil) then\n rollPID = pid.new(autoRollFactor * 0.01, 0, autoRollFactor * 0.1) -- magic number tweaked to have a default factor in the 1-10 range\n end\n rollPID:inject(targetRollDeg - currentRollDeg)\n local autoRollInput = rollPID:get()\n\n targetAngularVelocity = targetAngularVelocity + autoRollInput * constructForward\n end\n local turnAssistRollThreshold = 20.0\n -- turnAssist AND currentRollDeg is big enough AND player is not pitching or yawing\n if turnAssist == true and currentRollDegAbs > turnAssistRollThreshold and finalPitchInput == 0 and finalYawInput == 0 then\n local rollToPitchFactor = turnAssistFactor * 0.1 -- magic number tweaked to have a default factor in the 1-10 range\n local rollToYawFactor = turnAssistFactor * 0.025 -- magic number tweaked to have a default factor in the 1-10 range\n\n -- rescale (turnAssistRollThreshold -> 180) to (0 -> 180)\n local rescaleRollDegAbs = ((currentRollDegAbs - turnAssistRollThreshold) / (180 - turnAssistRollThreshold)) * 180\n local rollVerticalRatio = 0\n if rescaleRollDegAbs < 90 then\n rollVerticalRatio = rescaleRollDegAbs / 90\n elseif rescaleRollDegAbs < 180 then\n rollVerticalRatio = (180 - rescaleRollDegAbs) / 90\n end\n\n rollVerticalRatio = rollVerticalRatio * rollVerticalRatio\n\n local turnAssistYawInput = - currentRollDegSign * rollToYawFactor * (1.0 - rollVerticalRatio)\n local turnAssistPitchInput = rollToPitchFactor * rollVerticalRatio\n\n targetAngularVelocity = targetAngularVelocity\n + turnAssistPitchInput * constructRight\n + turnAssistYawInput * constructUp\n end\nend\n\n-- Engine commands\nlocal keepCollinearity = 1 -- for easier reading\nlocal dontKeepCollinearity = 0 -- for easier reading\nlocal tolerancePercentToSkipOtherPriorities = 1 -- if we are within this tolerance (in%), we don't go to the next priorities\n\n-- Rotation\nlocal angularAcceleration = torqueFactor * (targetAngularVelocity - constructAngularVelocity)\nlocal airAcceleration = vec3(core.getWorldAirFrictionAngularAcceleration())\nangularAcceleration = angularAcceleration - airAcceleration -- Try to compensate air friction\nNav:setEngineTorqueCommand('torque', angularAcceleration, keepCollinearity, 'airfoil', '', '', tolerancePercentToSkipOtherPriorities)\n\n-- Brakes\nlocal brakeAcceleration = -finalBrakeInput * (brakeSpeedFactor * constructVelocity + brakeFlatFactor * constructVelocityDir)\nNav:setEngineForceCommand('brake', brakeAcceleration)\n\n-- AutoNavigation regroups all the axis command by 'TargetSpeed'\nlocal autoNavigationEngineTags = ''\nlocal autoNavigationAcceleration = vec3()\nlocal autoNavigationUseBrake = false\n\n-- Longitudinal Translation\nlocal longitudinalEngineTags = 'thrust analog longitudinal'\nlocal longitudinalCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)\nif (longitudinalCommandType == axisCommandType.byThrottle) then\n local longitudinalAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromThrottle(longitudinalEngineTags,axisCommandId.longitudinal)\n Nav:setEngineForceCommand(longitudinalEngineTags, longitudinalAcceleration, keepCollinearity)\nelseif (longitudinalCommandType == axisCommandType.byTargetSpeed) then\n local longitudinalAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.longitudinal)\n autoNavigationEngineTags = autoNavigationEngineTags .. ' , ' .. longitudinalEngineTags\n autoNavigationAcceleration = autoNavigationAcceleration + longitudinalAcceleration\n if (Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal) == 0 or -- we want to stop\n Nav.axisCommandManager:getCurrentToTargetDeltaSpeed(axisCommandId.longitudinal) < - Nav.axisCommandManager:getTargetSpeedCurrentStep(axisCommandId.longitudinal) * 0.5) -- if the longitudinal velocity would need some braking\n then\n autoNavigationUseBrake = true\n end\n\nend\n\n-- Lateral Translation\nlocal lateralStrafeEngineTags = 'thrust analog lateral'\nlocal lateralCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.lateral)\nif (lateralCommandType == axisCommandType.byThrottle) then\n local lateralStrafeAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromThrottle(lateralStrafeEngineTags,axisCommandId.lateral)\n Nav:setEngineForceCommand(lateralStrafeEngineTags, lateralStrafeAcceleration, keepCollinearity)\nelseif (lateralCommandType == axisCommandType.byTargetSpeed) then\n local lateralAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral)\n autoNavigationEngineTags = autoNavigationEngineTags .. ' , ' .. lateralStrafeEngineTags\n autoNavigationAcceleration = autoNavigationAcceleration + lateralAcceleration\nend\n\n-- Vertical Translation\nlocal verticalStrafeEngineTags = 'thrust analog vertical'\nlocal verticalCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.vertical)\nif (verticalCommandType == axisCommandType.byThrottle) then\n local verticalStrafeAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromThrottle(verticalStrafeEngineTags,axisCommandId.vertical)\n Nav:setEngineForceCommand(verticalStrafeEngineTags, verticalStrafeAcceleration, keepCollinearity, 'airfoil', 'ground', '', tolerancePercentToSkipOtherPriorities)\nelseif (verticalCommandType == axisCommandType.byTargetSpeed) then\n local verticalAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical)\n autoNavigationEngineTags = autoNavigationEngineTags .. ' , ' .. verticalStrafeEngineTags\n autoNavigationAcceleration = autoNavigationAcceleration + verticalAcceleration\nend\n\n-- Auto Navigation (Cruise Control)\nif (autoNavigationAcceleration:len() > constants.epsilon) then\n if (brakeInput ~= 0 or autoNavigationUseBrake or math.abs(constructVelocityDir:dot(constructForward)) < 0.95) -- if the velocity is not properly aligned with the forward\n then\n autoNavigationEngineTags = autoNavigationEngineTags .. ', brake'\n end\n Nav:setEngineForceCommand(autoNavigationEngineTags, autoNavigationAcceleration, dontKeepCollinearity, '', '', '', tolerancePercentToSkipOtherPriorities)\nend\n\n-- Rockets\nNav:setBoosterCommand('rocket_engine')\n"}, {"key": "11", "filter": {"slotKey": "-2", "signature": "actionStart(light)", "args": [{"value": "light"}]}, "code": "if Nav.control.isAnyHeadlightSwitchedOn() == 1 then\n Nav.control.switchOffHeadlights()\nelse\n Nav.control.switchOnHeadlights()\nend\n"}, {"key": "12", "filter": {"slotKey": "-2", "signature": "actionStart(forward)", "args": [{"value": "forward"}]}, "code": "pitchInput = pitchInput - 1"}, {"key": "13", "filter": {"slotKey": "-2", "signature": "actionStop(forward)", "args": [{"value": "forward"}]}, "code": "pitchInput = pitchInput + 1"}, {"key": "14", "filter": {"slotKey": "-2", "signature": "actionStart(backward)", "args": [{"value": "backward"}]}, "code": "pitchInput = pitchInput + 1"}, {"key": "15", "filter": {"slotKey": "-2", "signature": "actionStop(left)", "args": [{"value": "left"}]}, "code": "rollInput = rollInput + 1"}, {"key": "16", "filter": {"slotKey": "-2", "signature": "actionStart(right)", "args": [{"value": "right"}]}, "code": "rollInput = rollInput + 1"}, {"key": "17", "filter": {"slotKey": "-2", "signature": "actionStop(backward)", "args": [{"value": "backward"}]}, "code": "pitchInput = pitchInput - 1"}, {"key": "18", "filter": {"slotKey": "-2", "signature": "actionStart(left)", "args": [{"value": "left"}]}, "code": "rollInput = rollInput - 1"}, {"key": "19", "filter": {"slotKey": "-2", "signature": "actionStop(straferight)", "args": [{"value": "straferight"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral, -1.0)"}, {"key": "20", "filter": {"slotKey": "-2", "signature": "actionStart(straferight)", "args": [{"value": "straferight"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral, 1.0)"}, {"key": "21", "filter": {"slotKey": "-2", "signature": "actionStop(right)", "args": [{"value": "right"}]}, "code": "rollInput = rollInput - 1"}, {"key": "22", "filter": {"slotKey": "-2", "signature": "update()", "args": []}, "code": "Nav:update()"}, {"key": "23", "filter": {"slotKey": "-2", "signature": "actionStart(gear)", "args": [{"value": "gear"}]}, "code": "gearExtended = not gearExtended\nif gearExtended then\n Nav.control.extendLandingGears()\nelse\n Nav.control.retractLandingGears()\nend\n"}, {"key": "24", "filter": {"slotKey": "-2", "signature": "actionStart(yawleft)", "args": [{"value": "yawleft"}]}, "code": "yawInput = yawInput + 1"}, {"key": "25", "filter": {"slotKey": "-2", "signature": "actionStop(yawright)", "args": [{"value": "yawright"}]}, "code": "yawInput = yawInput + 1"}, {"key": "26", "filter": {"slotKey": "-2", "signature": "actionStart(yawright)", "args": [{"value": "yawright"}]}, "code": "yawInput = yawInput - 1"}, {"key": "27", "filter": {"slotKey": "-2", "signature": "actionStop(yawleft)", "args": [{"value": "yawleft"}]}, "code": "yawInput = yawInput - 1"}, {"key": "28", "filter": {"slotKey": "-2", "signature": "actionStop(brake)", "args": [{"value": "brake"}]}, "code": "brakeInput = brakeInput - 1"}, {"key": "29", "filter": {"slotKey": "-2", "signature": "actionStart(brake)", "args": [{"value": "brake"}]}, "code": "brakeInput = brakeInput + 1\nlocal longitudinalCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)\nif (longitudinalCommandType == axisCommandType.byTargetSpeed) then\n local targetSpeed = Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)\n if (math.abs(targetSpeed) > constants.epsilon) then\n Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal, - utils.sign(targetSpeed))\n end\nend\n"}, {"key": "30", "filter": {"slotKey": "-2", "signature": "actionStart(booster)", "args": [{"value": "booster"}]}, "code": "Nav:toggleBoosters()"}, {"key": "31", "filter": {"slotKey": "-2", "signature": "actionLoop(brake)", "args": [{"value": "brake"}]}, "code": "local longitudinalCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)\nif (longitudinalCommandType == axisCommandType.byTargetSpeed) then\n local targetSpeed = Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)\n if (math.abs(targetSpeed) > constants.epsilon) then\n Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal, - utils.sign(targetSpeed))\n end\nend\n"}, {"key": "32", "filter": {"slotKey": "-2", "signature": "actionStart(stopengines)", "args": [{"value": "stopengines"}]}, "code": "Nav.axisCommandManager:resetCommand(axisCommandId.longitudinal)"}, {"key": "33", "filter": {"slotKey": "-2", "signature": "actionStart(speedup)", "args": [{"value": "speedup"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal, 5.0)"}, {"key": "34", "filter": {"slotKey": "-2", "signature": "actionLoop(speedup)", "args": [{"value": "speedup"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal, 1.0)"}, {"key": "35", "filter": {"slotKey": "-2", "signature": "actionStart(speeddown)", "args": [{"value": "speeddown"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal, -5.0)"}, {"key": "36", "filter": {"slotKey": "-2", "signature": "actionStart(antigravity)", "args": [{"value": "antigravity"}]}, "code": "if antigrav ~= nil then antigrav.toggle() end"}, {"key": "37", "filter": {"slotKey": "-2", "signature": "actionLoop(speeddown)", "args": [{"value": "speeddown"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal, -1.0)"}, {"key": "38", "filter": {"slotKey": "-1", "signature": "stop()", "args": []}, "code": "_autoconf.hideCategoryPanels()\nif antigrav ~= nil then antigrav.hide() end\nif warpdrive ~= nil then warpdrive.hide() end\nif gyro ~= nil then gyro.hide() end\ncore.hide()\nNav.control.switchOffHeadlights()\n"}, {"key": "39", "filter": {"slotKey": "-1", "signature": "start()", "args": []}, "code": "-- category panel display helpers\n_autoconf = {}\n_autoconf.panels = {}\n_autoconf.panels_size = 0\n_autoconf.displayCategoryPanel = function(elements, size, title, type, widgetPerData)\n widgetPerData = widgetPerData or false -- default to one widget for all data\n if size > 0 then\n local panel = system.createWidgetPanel(title)\n local widget\n if not widgetPerData then\n widget = system.createWidget(panel, type)\n end\n for i = 1, size do\n if widgetPerData then\n widget = system.createWidget(panel, type)\n end\n system.addDataToWidget(elements[i].getDataId(), widget)\n end\n _autoconf.panels_size = _autoconf.panels_size + 1\n _autoconf.panels[_autoconf.panels_size] = panel\n end\nend\n_autoconf.hideCategoryPanels = function()\n for i=1,_autoconf.panels_size do\n system.destroyWidgetPanel(_autoconf.panels[i])\n end\nend\n-- Proxy array to access auto-plugged slots programmatically\nradar = {}\nradar_size = 0\n\nweapon = {}\nweapon_size = 0\n\nspacefueltank = {}\nspacefueltank_size = 0\n\natmofueltank = {}\natmofueltank_size = 0\n\nrocketfueltank = {}\nrocketfueltank_size = 0\n-- End of auto-generated code\npitchInput = 0\nrollInput = 0\nyawInput = 0\nbrakeInput = 0\n\nNav = Navigator.new(system, core, unit)\nNav.axisCommandManager:setupCustomTargetSpeedRanges(axisCommandId.longitudinal, {1000, 5000, 10000, 20000, 30000})\nNav.axisCommandManager:setTargetGroundAltitude(4)\n\n-- Parenting widget\nparentingPanelId = system.createWidgetPanel(\"Docking\")\nparentingWidgetId = system.createWidget(parentingPanelId,\"parenting\")\nsystem.addDataToWidget(unit.getDataId(),parentingWidgetId)\n\n-- Combat stress widget\ncoreCombatStressPanelId = system.createWidgetPanel(\"Core combat stress\")\ncoreCombatStressgWidgetId = system.createWidget(coreCombatStressPanelId,\"core_stress\")\nsystem.addDataToWidget(core.getDataId(),coreCombatStressgWidgetId)\n\n-- element widgets\n-- For now we have to alternate between PVP and non-PVP widgets to have them on the same side.\n_autoconf.displayCategoryPanel(weapon, weapon_size, \"Weapons\", \"weapon\", true)\ncore.show()\n_autoconf.displayCategoryPanel(radar, radar_size, \"Periscope\", \"periscope\")\nplaceRadar = true\nif atmofueltank_size > 0 then\n _autoconf.displayCategoryPanel(atmofueltank, atmofueltank_size, \"Atmo Fuel\", \"fuel_container\")\n if placeRadar then\n _autoconf.displayCategoryPanel(radar, radar_size, \"Radar\", \"radar\")\n placeRadar = false\n end\nend\nif spacefueltank_size > 0 then\n _autoconf.displayCategoryPanel(spacefueltank, spacefueltank_size, \"Space Fuel\", \"fuel_container\")\n if placeRadar then\n _autoconf.displayCategoryPanel(radar, radar_size, \"Radar\", \"radar\")\n placeRadar = false\n end\nend\n_autoconf.displayCategoryPanel(rocketfueltank, rocketfueltank_size, \"Rocket Fuel\", \"fuel_container\")\nif placeRadar then -- We either have only rockets or no fuel tanks at all, uncommon for usual vessels\n _autoconf.displayCategoryPanel(radar, radar_size, \"Radar\", \"radar\")\n placeRadar = false\nend\nif antigrav ~= nil then antigrav.show() end\nif warpdrive ~= nil then warpdrive.show() end\nif gyro ~= nil then gyro.show() end\nif shield ~= nil then shield.show() end\n\n-- freeze the player in he is remote controlling the construct\nif Nav.control.isRemoteControlled() == 1 then\n system.freeze(1)\nend\n\n-- landing gear\n-- make sure every gears are synchonized with the first\ngearExtended = (Nav.control.isAnyLandingGearExtended() == 1) -- make sure it's a lua boolean\nif gearExtended then\n Nav.control.extendLandingGears()\nelse\n Nav.control.retractLandingGears()\nend\n"}], "methods": [], "events": []} \ No newline at end of file diff --git a/json/pilot_seat/ground.json b/json/pilot_seat/ground.json new file mode 100644 index 0000000..b88226c --- /dev/null +++ b/json/pilot_seat/ground.json @@ -0,0 +1 @@ +{"slots": {"4": {"name": "slot5", "type": {"methods": [], "events": []}}, "-1": {"name": "unit", "type": {"methods": [], "events": []}}, "-2": {"name": "system", "type": {"methods": [], "events": []}}, "-3": {"name": "library", "type": {"methods": [], "events": []}}, "0": {"name": "core", "type": {"methods": [], "events": []}}, "1": {"name": "slot2", "type": {"methods": [], "events": []}}, "2": {"name": "slot3", "type": {"methods": [], "events": []}}, "3": {"name": "slot4", "type": {"methods": [], "events": []}}, "5": {"name": "slot6", "type": {"methods": [], "events": []}}, "6": {"name": "slot7", "type": {"methods": [], "events": []}}, "7": {"name": "slot8", "type": {"methods": [], "events": []}}, "8": {"name": "slot9", "type": {"methods": [], "events": []}}, "9": {"name": "slot10", "type": {"methods": [], "events": []}}, "10": {"name": "slot11", "type": {"methods": [], "events": []}}}, "handlers": [{"key": "0", "filter": {"slotKey": "-1", "signature": "start()", "args": []}, "code": "-- category panel display helpers\n_autoconf = {}\n_autoconf.panels = {}\n_autoconf.panels_size = 0\n_autoconf.displayCategoryPanel = function(elements, size, title, type, widgetPerData)\n widgetPerData = widgetPerData or false -- default to one widget for all data\n if size > 0 then\n local panel = system.createWidgetPanel(title)\n local widget\n if not widgetPerData then\n widget = system.createWidget(panel, type)\n end\n for i = 1, size do\n if widgetPerData then\n widget = system.createWidget(panel, type)\n end\n system.addDataToWidget(elements[i].getDataId(), widget)\n end\n _autoconf.panels_size = _autoconf.panels_size + 1\n _autoconf.panels[_autoconf.panels_size] = panel\n end\nend\n_autoconf.hideCategoryPanels = function()\n for i=1,_autoconf.panels_size do\n system.destroyWidgetPanel(_autoconf.panels[i])\n end\nend\n-- Proxy array to access auto-plugged slots programmatically\n\natmofueltank = {}\natmofueltank_size = 0\n\nweapon = {}\nweapon_size = 0\n\nspacefueltank = {}\nspacefueltank_size = 0\n\nrocketfueltank = {}\nrocketfueltank_size = 0\n\nradar = {}\nradar_size = 0\n-- End of auto-generated code\npitchInput = 0\npitchInputFromDevice = 0\nrollInput = 0\nyawInput = 0\nverticalStrafeInput = 0\nlateralStrafeInput = 0\nbrakeInput = 0\ngoingBack = false\ngoingForward = false\nshiftPressed = false\njumpDelta = 0\nbaseAcceleration = 0.8 --export: Acceleration provided when 'forward' is hit, expressed in g\n\nNav = Navigator.new(system, core, unit)\nNav.axisCommandManager:setupCustomTargetSpeedRanges(axisCommandId.longitudinal, {100, 500, 1000, 5000})\nNav.axisCommandManager:setTargetGroundAltitude(6)\n\n-- Parenting widget\nparentingPanelId = system.createWidgetPanel(\"Docking\")\nparentingWidgetId = system.createWidget(parentingPanelId,\"parenting\")\nsystem.addDataToWidget(unit.getDataId(),parentingWidgetId)\n\n-- Combat stress widget\ncoreCombatStressPanelId = system.createWidgetPanel(\"Core combat stress\")\ncoreCombatStressgWidgetId = system.createWidget(coreCombatStressPanelId,\"core_stress\")\nsystem.addDataToWidget(core.getDataId(),coreCombatStressgWidgetId)\n\n-- element widgets\n-- For now we have to alternate between PVP and non-PVP widgets to have them on the same side.\n_autoconf.displayCategoryPanel(weapon, weapon_size, \"Weapons\", \"weapon\", true)\ncore.show()\n_autoconf.displayCategoryPanel(radar, radar_size, \"Periscope\", \"periscope\")\nplaceRadar = true\nif atmofueltank_size > 0 then\n _autoconf.displayCategoryPanel(atmofueltank, atmofueltank_size, \"Atmo Fuel\", \"fuel_container\")\n if placeRadar then\n _autoconf.displayCategoryPanel(radar, radar_size, \"Radar\", \"radar\")\n placeRadar = false\n end\nend\nif spacefueltank_size > 0 then\n _autoconf.displayCategoryPanel(spacefueltank, spacefueltank_size, \"Space Fuel\", \"fuel_container\")\n if placeRadar then\n _autoconf.displayCategoryPanel(radar, radar_size, \"Radar\", \"radar\")\n placeRadar = false\n end\nend\n_autoconf.displayCategoryPanel(rocketfueltank, rocketfueltank_size, \"Rocket Fuel\", \"fuel_container\")\nif placeRadar then -- We either have only rockets or no fuel tanks at all, uncommon for usual vessels\n _autoconf.displayCategoryPanel(radar, radar_size, \"Radar\", \"radar\")\n placeRadar = false\nend\nif antigrav ~= nil then antigrav.show() end\nif gyro ~= nil then gyro.show() end\n\nthrottleStep = 0.25 --export: When pressing the SpeedUp/SpeedDown buttons, this step will be using to increment/decrement the throttle
Valid values: From 0.01 to 1\nthrottleStep = utils.clamp(throttleStep, 0.01, 1)\n\n-- freeze the player in he is remote controlling the construct\nif Nav.control.isRemoteControlled() == 1 then\n system.freeze(1)\nend\n\n-- landing gear\n-- make sure every gears are synchonized with the first\ngearExtended = (Nav.control.isAnyLandingGearExtended() == 1) -- make sure it's a lua boolean\nif gearExtended then\n Nav.control.extendLandingGears()\nelse\n Nav.control.retractLandingGears()\nend\n\n-- forward/backward functions\nstartForward = function ()\n if Nav:isTravelMode() then\n brakeInput = 0\n local throttle = 1\n if not shiftPressed then\n local maxGForward = Nav:maxForceForward() / (self.core.getConstructMass() * 9.81)\n throttle = utils.clamp(baseAcceleration / maxGForward, 0, 1)\n end\n\n Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, throttle)\n goingForward = true\n end\nend\n\nstopForward = function ()\n if Nav:isTravelMode() then\n pitchInput = 0\n Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, 0)\n brakeInput = 0.5\n goingForward = false\n if goingBackward then\n startBackward()\n end\n end\nend\n\ndirection = {forward=1, backward = -1}\nloopDirection = function (direction)\n if Nav:isTravelMode() then\n local currentVelocity = vec3(self.core.getVelocity())\n local axisCRefDirection = vec3(self.core.getConstructOrientationForward())\n\n lastCurrentSpeed = currentVelocity:dot(axisCRefDirection)\n\n if (lastCurrentSpeed * direction < 0) then\n brakeInput = 1\n autobrake = true\n else\n if autobrake == true then\n autobrake = false\n brakeInput = 0\n end\n end\n else\n Nav.axisCommandManager.axisCommands[axisCommandId.longitudinal]:updateCommandFromActionLoop(direction)\n end\nend\n\nstartBackward = function ()\n if Nav:isTravelMode() then\n pitchInput = 0\n brakeInput = 0\n\n local maxGBackward = Nav:maxForceBackward() / (self.core.getConstructMass() * 9.81)\n local throttle = utils.clamp(baseAcceleration / maxGBackward, -1, 0)\n\n Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, throttle)\n goingBack = true\n end\nend\n\nstopBackward = function ()\n if Nav:isTravelMode() then\n pitchInput = 0\n Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, 0)\n brakeInput = 0.5\n goingBack = false\n if goingForward then\n startForward()\n end\n end\nend\n"}, {"key": "1", "filter": {"slotKey": "-1", "signature": "stop()", "args": []}, "code": "_autoconf.hideCategoryPanels()\nif antigrav ~= nil then antigrav.hide() end\nif gyro ~= nil then gyro.hide() end\ncore.hide()\nNav.control.switchOffHeadlights()\n"}, {"key": "2", "filter": {"slotKey": "-2", "signature": "actionStop(right)", "args": [{"value": "right"}]}, "code": "rollInput = rollInput - 1"}, {"key": "3", "filter": {"slotKey": "-2", "signature": "actionStart(lshift)", "args": [{"value": "lshift"}]}, "code": "shiftPressed = true\nif goingForward then\n Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, 1)\nend\n"}, {"key": "4", "filter": {"slotKey": "-2", "signature": "actionLoop(backward)", "args": [{"value": "backward"}]}, "code": "loopDirection(direction.backward)"}, {"key": "5", "filter": {"slotKey": "-2", "signature": "actionStart(backward)", "args": [{"value": "backward"}]}, "code": "startBackward()"}, {"key": "6", "filter": {"slotKey": "-2", "signature": "actionStop(backward)", "args": [{"value": "backward"}]}, "code": "stopBackward()"}, {"key": "7", "filter": {"slotKey": "-2", "signature": "actionLoop(forward)", "args": [{"value": "forward"}]}, "code": "loopDirection(direction.forward)"}, {"key": "8", "filter": {"slotKey": "-2", "signature": "actionStart(forward)", "args": [{"value": "forward"}]}, "code": "startForward()"}, {"key": "9", "filter": {"slotKey": "-2", "signature": "actionStop(forward)", "args": [{"value": "forward"}]}, "code": "stopForward()"}, {"key": "10", "filter": {"slotKey": "-2", "signature": "actionStart(right)", "args": [{"value": "right"}]}, "code": "rollInput = rollInput + 1"}, {"key": "11", "filter": {"slotKey": "-2", "signature": "actionStop(lshift)", "args": [{"value": "lshift"}]}, "code": "shiftPressed = false\nif goingForward then\n local maxGForward = Nav:maxForceForward() / (self.core.getConstructMass() * 9.81)\n local throttle = utils.clamp(baseAcceleration / maxGForward, 0, 1)\n Nav.axisCommandManager:setThrottleCommand(axisCommandId.longitudinal, throttle)\nend\n"}, {"key": "12", "filter": {"slotKey": "-2", "signature": "actionStart(left)", "args": [{"value": "left"}]}, "code": "rollInput = rollInput - 1"}, {"key": "13", "filter": {"slotKey": "-2", "signature": "actionStop(left)", "args": [{"value": "left"}]}, "code": "rollInput = rollInput + 1"}, {"key": "14", "filter": {"slotKey": "-2", "signature": "actionStart(light)", "args": [{"value": "light"}]}, "code": "if Nav.control.isAnyHeadlightSwitchedOn() == 1 then\n Nav.control.switchOffHeadlights()\nelse\n Nav.control.switchOnHeadlights()\nend\n"}, {"key": "15", "filter": {"slotKey": "-2", "signature": "actionStart(gear)", "args": [{"value": "gear"}]}, "code": "gearExtended = not gearExtended\nif gearExtended then\n Nav.control.extendLandingGears()\nelse\n Nav.control.retractLandingGears()\nend\n"}, {"key": "16", "filter": {"slotKey": "-2", "signature": "actionStart(up)", "args": [{"value": "up"}]}, "code": "baseAltitude = Nav:getTargetGroundAltitude()\nNav.axisCommandManager:setTargetGroundAltitude(baseAltitude + 4)\n"}, {"key": "17", "filter": {"slotKey": "-2", "signature": "actionLoop(up)", "args": [{"value": "up"}]}, "code": "if unit.isMouseControlActivated() == 0 then\n jumpDelta = utils.clamp(jumpDelta + 0.01, 0, 0.6)\nend\n"}, {"key": "18", "filter": {"slotKey": "-2", "signature": "update()", "args": []}, "code": "Nav:update()\nif system.getThrottleInputFromMouseWheel() ~= 0.0 then\n brakeInput = 0\nend\n\nif unit.isMouseControlActivated() == 0 then\n local currentVelocity = vec3(self.core.getVelocity())\n local axisCRefDirection = vec3(self.core.getConstructOrientationForward())\n local v = currentVelocity:dot(axisCRefDirection)\n local minv = 20\n local maxPitch = 0.4\n if v < minv or not goingForward then\n pitchInput = 0\n else\n if not goingBack and goingForward then\n pitchInput = utils.clamp((maxPitch/minv) * (v - minv), 0, maxPitch)\n end\n end\nend\n\npitchInput = pitchInput + jumpDelta\n"}, {"key": "19", "filter": {"slotKey": "-2", "signature": "flush()", "args": []}, "code": "-- constants: use 'myvar = defaultValue --export: description' to expose the variable in context menu
in degree
Valid values: Superior or equal to 1\nlocal rollAmplitude = 30 --export: When turning, the auto roll won't go over or under rollAmplitude
in degree
Valid values: Superior or equal to 1\nlocal pitchAmplitude = 25 --export: When pitching, the pitch won't go over or under pitchAmplitude (in degree)\nlocal yawSpeedFactor = 1.5 --export When turning, the inputs will be multiplied by this factor
Valid values: Superior or equal to 0.01\nlocal yawAccelerationFactor = 3 --export: When turning, the yaw response will be multiplied by this factor
Valid values: Superior or equal to 0.01\n\nlocal lateralAntiDriftFactor = 1 --export: When compensating for drift, this factor will increase/decrease the drift force requested to engines
Valid values: Superior or equal to 0.01\nlocal lateralStrafeFactor = 5 --export: This factor will increase/decrease the player input along the horizontal strafe axis axis
Valid values: Superior or equal to 0.01\n\nlocal brakeSpeedFactor = 1 --export: When braking, this factor will increase the brake force by brakeSpeedFactor * velocity
Valid values: Superior or equal to 0.01\nlocal brakeFlatFactor = 4 --export: When braking, this factor will increase the brake force by a flat brakeFlatFactor * velocity direction>
(higher value may be unstable)
Valid values: Superior or equal to 0.01\nlocal autoBrakeSpeed = 15 --export: Auto brake when speed is below that value (in m/s), with no thrust\n\n-- validate params\nbrakeSpeedFactor = math.max(brakeSpeedFactor, 0.01)\nbrakeFlatFactor = math.max(brakeFlatFactor, 0.01)\nrollAmplitude = math.max(rollAmplitude, 1)\npitchAmplitude = math.max(pitchAmplitude, 1)\nyawSpeedFactor = math.max(yawSpeedFactor, 0.01)\nyawAccelerationFactor = math.max(yawAccelerationFactor, 0.01)\n\nif (rollPID == nil) then\n rollPID = pid.new(0.2, 0, 10)\n pitchPID = pid.new(0.2, 0, 10)\nend\n\n-- final inputs\nif Nav.control.isMouseDirectControlActivated() then\n -- in direct control, we tweak the pitch to behave inbetween virtual joystick and direct control\n -- this helps a lot for ground construct control\n pitchInputFromDevice = utils.clamp(pitchInputFromDevice + system.getControlDeviceForwardInput() * system.getActionUpdateDeltaTime(), -1.0, 1.0)\nelse\n pitchInputFromDevice = system.getControlDeviceForwardInput()\nend\nlocal finalPitchInput = pitchInput + pitchInputFromDevice\nlocal finalRollInput = rollInput + system.getControlDeviceYawInput()\nlocal finalYawInput = yawInput - system.getControlDeviceLeftRightInput()\nlocal combinedRollYawInput = utils.clamp(finalRollInput - finalYawInput, -1.0, 1.0);\nlocal finalVerticalStrafeInput = verticalStrafeInput\nlocal finalLateralStrafeInput = lateralStrafeInput;\nlocal finalBrakeInput = brakeInput\n\n-- Axis\nlocal worldVertical = vec3(core.getWorldVertical())\nlocal constructUp = vec3(core.getConstructWorldOrientationUp())\nlocal constructForward = vec3(core.getConstructWorldOrientationForward())\nlocal constructRight = vec3(core.getConstructWorldOrientationRight())\nlocal constructVelocity = vec3(core.getWorldVelocity())\nlocal constructVelocityDir = vec3(core.getWorldVelocity()):normalize()\nlocal constructAngularVelocity = vec3(core.getWorldAngularVelocity())\nlocal constructYawVelocity = constructAngularVelocity:dot(constructUp)\n\n-- Engine commands\nlocal keepCollinearity = 0 -- for easier reading\nlocal dontKeepCollinearity = 1 -- for easier reading\nlocal tolerancePercentToSkipOtherPriorities = 1 -- if we are within this tolerance (in%), we don't go to the next priorities\n\n-- Rotation\nlocal currentRollDeg = getRoll(worldVertical, constructForward, constructRight)\nlocal currentPitchDeg = -math.asin(constructForward:dot(worldVertical)) * constants.rad2deg\nlocal targetRollDeg = utils.clamp(combinedRollYawInput * rollAmplitude, -rollAmplitude, rollAmplitude)\nlocal targetPitchDeg = utils.clamp(finalPitchInput * pitchAmplitude, -pitchAmplitude, pitchAmplitude)\nrollPID:inject(targetRollDeg - currentRollDeg)\npitchPID:inject(targetPitchDeg - currentPitchDeg)\n\nlocal constructYawTargetVelocity = -combinedRollYawInput * yawSpeedFactor\nlocal constructYawTargetAcceleration = yawAccelerationFactor * (constructYawTargetVelocity - constructYawVelocity)\n\nlocal constructTargetAngularVelocity = rollPID:get() * constructForward\n + pitchPID:get() * constructRight\n + constructYawTargetAcceleration * constructUp\n\nNav:setEngineTorqueCommand('torque', constructTargetAngularVelocity, keepCollinearity, 'airfoil', '', '', tolerancePercentToSkipOtherPriorities)\n\n-- Brakes\nif (finalBrakeInput == 0 and autoBrakeSpeed > 0 and Nav.axisCommandManager.throttle == 0 and constructVelocity:len() < autoBrakeSpeed) then\n finalBrakeInput = 1\nend\nlocal brakeAcceleration = -finalBrakeInput * (brakeSpeedFactor * constructVelocity + brakeFlatFactor * constructVelocityDir)\nNav:setEngineForceCommand('brake', brakeAcceleration)\n\n-- AutoNavigation regroups all the axis command by 'TargetSpeed'\nlocal autoNavigationEngineTags = ''\nlocal autoNavigationAcceleration = vec3()\nlocal autoNavigationUseBrake = false\n\n-- Longitudinal Translation\nlocal longitudinalEngineTags = 'thrust analog longitudinal'\nlocal longitudinalCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)\nif (longitudinalCommandType == axisCommandType.byThrottle) then\n local longitudinalAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromThrottle(longitudinalEngineTags,axisCommandId.longitudinal)\n Nav:setEngineForceCommand(longitudinalEngineTags, longitudinalAcceleration, keepCollinearity)\nelseif (longitudinalCommandType == axisCommandType.byTargetSpeed) then\n local longitudinalAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.longitudinal)\n autoNavigationEngineTags = autoNavigationEngineTags .. ' , ' .. longitudinalEngineTags\n autoNavigationAcceleration = autoNavigationAcceleration + longitudinalAcceleration\n if (Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal) == 0 or -- we want to stop\n Nav.axisCommandManager:getCurrentToTargetDeltaSpeed(axisCommandId.longitudinal) < - Nav.axisCommandManager:getTargetSpeedCurrentStep(axisCommandId.longitudinal) * 0.5) -- if the longitudinal velocity would need some braking\n then\n autoNavigationUseBrake = true\n end\n\nend\n\n-- Lateral Translation\nlocal lateralStrafeEngineTags = 'thrust analog lateral'\nlocal lateralCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.lateral)\nif (lateralCommandType == axisCommandType.byThrottle) then\n local lateralStrafeAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromThrottle(lateralStrafeEngineTags,axisCommandId.lateral)\n Nav:setEngineForceCommand(lateralStrafeEngineTags, lateralStrafeAcceleration, keepCollinearity)\nelseif (lateralCommandType == axisCommandType.byTargetSpeed) then\n local lateralAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.lateral)\n autoNavigationEngineTags = autoNavigationEngineTags .. ' , ' .. lateralStrafeEngineTags\n autoNavigationAcceleration = autoNavigationAcceleration + lateralAcceleration\nend\n\n-- Vertical Translation\nlocal verticalStrafeEngineTags = 'thrust analog vertical'\nlocal verticalCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.vertical)\nif (verticalCommandType == axisCommandType.byThrottle) then\n local verticalStrafeAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromThrottle(verticalStrafeEngineTags,axisCommandId.vertical)\n Nav:setEngineForceCommand(verticalStrafeEngineTags, verticalStrafeAcceleration, keepCollinearity, 'airfoil', 'ground', '', tolerancePercentToSkipOtherPriorities)\nelseif (verticalCommandType == axisCommandType.byTargetSpeed) then\n local verticalAcceleration = Nav.axisCommandManager:composeAxisAccelerationFromTargetSpeed(axisCommandId.vertical)\n autoNavigationEngineTags = autoNavigationEngineTags .. ' , ' .. verticalStrafeEngineTags\n autoNavigationAcceleration = autoNavigationAcceleration + verticalAcceleration\nend\n\n-- Auto Navigation (Cruise Control)\nif (autoNavigationAcceleration:len() > constants.epsilon) then\n if (brakeInput ~= 0 or autoNavigationUseBrake or math.abs(constructVelocityDir:dot(constructForward)) < 0.95) -- if the velocity is not properly aligned with the forward\n then\n autoNavigationEngineTags = autoNavigationEngineTags .. ', brake'\n end\n Nav:setEngineForceCommand(autoNavigationEngineTags, autoNavigationAcceleration, dontKeepCollinearity, '', '', '', tolerancePercentToSkipOtherPriorities)\nend\n\n-- Rockets\nNav:setBoosterCommand('rocket_engine')\n"}, {"key": "20", "filter": {"slotKey": "-2", "signature": "actionStart(down)", "args": [{"value": "down"}]}, "code": "Nav.axisCommandManager:deactivateGroundEngineAltitudeStabilization()\nNav.axisCommandManager:updateCommandFromActionStart(axisCommandId.vertical, -1.0)\n"}, {"key": "21", "filter": {"slotKey": "-2", "signature": "actionStop(up)", "args": [{"value": "up"}]}, "code": "Nav.axisCommandManager:setTargetGroundAltitude(baseAltitude)\nif unit.isMouseControlActivated() == 0 then\n jumpDelta = 0\nend\n"}, {"key": "22", "filter": {"slotKey": "-2", "signature": "actionStop(down)", "args": [{"value": "down"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.vertical, 1.0)\nNav.axisCommandManager:activateGroundEngineAltitudeStabilization(defaultGroundAltitudeStabilization)\n"}, {"key": "23", "filter": {"slotKey": "-2", "signature": "actionStart(groundaltitudeup)", "args": [{"value": "groundaltitudeup"}]}, "code": "Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(1.0)"}, {"key": "24", "filter": {"slotKey": "-2", "signature": "actionStart(groundaltitudedown)", "args": [{"value": "groundaltitudedown"}]}, "code": "Nav.axisCommandManager:updateTargetGroundAltitudeFromActionStart(-1.0)"}, {"key": "25", "filter": {"slotKey": "-2", "signature": "actionLoop(groundaltitudeup)", "args": [{"value": "groundaltitudeup"}]}, "code": "Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(1.0)\njumpDelta = 0\n"}, {"key": "26", "filter": {"slotKey": "-2", "signature": "actionLoop(groundaltitudedown)", "args": [{"value": "groundaltitudedown"}]}, "code": "Nav.axisCommandManager:updateTargetGroundAltitudeFromActionLoop(-1.0)"}, {"key": "27", "filter": {"slotKey": "-2", "signature": "actionStart(yawright)", "args": [{"value": "yawright"}]}, "code": "yawInput = yawInput - 1"}, {"key": "28", "filter": {"slotKey": "-2", "signature": "actionStop(yawright)", "args": [{"value": "yawright"}]}, "code": "yawInput = yawInput + 1"}, {"key": "29", "filter": {"slotKey": "-2", "signature": "actionStop(yawleft)", "args": [{"value": "yawleft"}]}, "code": "yawInput = yawInput - 1"}, {"key": "30", "filter": {"slotKey": "-2", "signature": "actionStart(yawleft)", "args": [{"value": "yawleft"}]}, "code": "yawInput = yawInput + 1"}, {"key": "31", "filter": {"slotKey": "-2", "signature": "actionStart(brake)", "args": [{"value": "brake"}]}, "code": "brakeInput = brakeInput + 1\nlocal longitudinalCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)\nif (longitudinalCommandType == axisCommandType.byTargetSpeed) then\n local targetSpeed = Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)\n if (math.abs(targetSpeed) > constants.epsilon) then\n Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.longitudinal, - utils.sign(targetSpeed))\n end\nend\n"}, {"key": "32", "filter": {"slotKey": "-2", "signature": "actionStop(brake)", "args": [{"value": "brake"}]}, "code": "brakeInput = 0"}, {"key": "33", "filter": {"slotKey": "-2", "signature": "actionLoop(brake)", "args": [{"value": "brake"}]}, "code": "local longitudinalCommandType = Nav.axisCommandManager:getAxisCommandType(axisCommandId.longitudinal)\nif (longitudinalCommandType == axisCommandType.byTargetSpeed) then\n local targetSpeed = Nav.axisCommandManager:getTargetSpeed(axisCommandId.longitudinal)\n if (math.abs(targetSpeed) > constants.epsilon) then\n Nav.axisCommandManager:updateCommandFromActionLoop(axisCommandId.longitudinal, - utils.sign(targetSpeed))\n end\nend\n"}, {"key": "34", "filter": {"slotKey": "-2", "signature": "actionStart(booster)", "args": [{"value": "booster"}]}, "code": "Nav:toggleBoosters()"}, {"key": "35", "filter": {"slotKey": "-2", "signature": "actionLoop(speedup)", "args": [{"value": "speedup"}]}, "code": "loopDirection(direction.forward)"}, {"key": "36", "filter": {"slotKey": "-2", "signature": "actionStart(stopengines)", "args": [{"value": "stopengines"}]}, "code": "Nav.axisCommandManager:resetCommand(axisCommandId.longitudinal)"}, {"key": "37", "filter": {"slotKey": "-2", "signature": "actionStart(speedup)", "args": [{"value": "speedup"}]}, "code": "startForward()"}, {"key": "38", "filter": {"slotKey": "-2", "signature": "actionStart(speeddown)", "args": [{"value": "speeddown"}]}, "code": "startBackward()"}, {"key": "39", "filter": {"slotKey": "-2", "signature": "actionStop(speedup)", "args": [{"value": "speedup"}]}, "code": "stopForward()"}, {"key": "40", "filter": {"slotKey": "-2", "signature": "actionLoop(speeddown)", "args": [{"value": "speeddown"}]}, "code": "loopDirection(direction.backward)"}, {"key": "41", "filter": {"slotKey": "-2", "signature": "actionStart(antigravity)", "args": [{"value": "antigravity"}]}, "code": "if antigrav ~= nil then antigrav.toggle() end"}, {"key": "42", "filter": {"slotKey": "-2", "signature": "actionStop(speeddown)", "args": [{"value": "speeddown"}]}, "code": "stopBackward()"}, {"key": "43", "filter": {"slotKey": "-2", "signature": "actionStop(straferight)", "args": [{"value": "straferight"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral, -1.0)"}, {"key": "44", "filter": {"slotKey": "-2", "signature": "actionStart(strafeleft)", "args": [{"value": "strafeleft"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral, -1.0)"}, {"key": "45", "filter": {"slotKey": "-2", "signature": "actionStop(strafeleft)", "args": [{"value": "strafeleft"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStop(axisCommandId.lateral, 1.0)"}, {"key": "46", "filter": {"slotKey": "-2", "signature": "actionStart(straferight)", "args": [{"value": "straferight"}]}, "code": "Nav.axisCommandManager:updateCommandFromActionStart(axisCommandId.lateral, 1.0)"}], "methods": [], "events": []} \ No newline at end of file diff --git a/json/programming_board/empty.json b/json/programming_board/empty.json new file mode 100644 index 0000000..e06d953 --- /dev/null +++ b/json/programming_board/empty.json @@ -0,0 +1 @@ +{"slots":{"0":{"name":"slot1","type":{"events":[],"methods":[]}},"1":{"name":"slot2","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[],"methods":[],"events":[]} \ No newline at end of file