-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem.flush.lua
More file actions
83 lines (65 loc) · 3.02 KB
/
system.flush.lua
File metadata and controls
83 lines (65 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
-- Darkwinde START: system.flush()
-- Telemeter
-- >> Distance can be between 1 and 100.
-- >> Scripting Wiki for telemeter is wrong. For MaxDistance it is mentioned 20m
-- >> !!! Telemeter even works (hidden) behind honeycomb
-- system.print(telemeter.getDistance())
local environmentParameter = getEnvironmentParameter(environmentID)
-- Check if telemeter unit exists
if telemeterExists then
landing = telemeter.getDistance() > 0 and telemeter.getDistance() < environmentParameter["surfaceDistanceLanding"]
surfaceLow = telemeter.getDistance() > 0 and telemeter.getDistance() <= environmentParameter["surfaceDistanceLow"]
else
landing, surfaceLow, surfaceBrake = false , false, false
end
-- Set general altitude stabilization according to the environment
if surfaceLow and unit.getSurfaceEngineAltitudeStabilization() ~= 0 and
unit.getSurfaceEngineAltitudeStabilization() ~= environmentParameter["surfaceDistanceLow"] then
unit.activateGroundEngineAltitudeStabilization(environmentParameter["surfaceDistanceLow"])
end
-- Start and landing condition to stay on surface
if lockBrake then
brakeInput = 1
if surfaceLow or docked then
unit.setEngineThrust("vertical thrust", 0) -- default tags are in lower case and space seperated
unit.deactivateGroundEngineAltitudeStabilization()
end
end
-- Use brake to stabalize near ground level
if surfaceBrake and surfaceLow then
brakeInput = 1
elseif surfaceBrake and not surfaceLow then
surfaceBrake = false
brakeInput = 0
elseif not surfaceBrake and surfaceLow then
surfaceBrake = true
brakeInput = 1
end
-- In space it is not necessary to use engine stabilization / maneuver engine at high speed
if (environmentID == 2 and velocity_kmh > 5000) or not verticalEngines then
--unit.setEngineThrust("vertical thrust", 0)
Nav:setEngineCommand("vertical thrust", vec3.zero, vec3.zero)
--unit.deactivateGroundEngineAltitudeStabilization()
end
-- As we want the AGG to stabalize our altitude, we need to deactivate vertical engines
if antigrav ~= nil then
local aggData = json.decode(antigrav.getData())
-- But only in case we are within AGG field, outside happy maneuver
if aggData.antiGPower > 0 then
unit.setEngineThrust("vertical thrust", 0)
unit.deactivateGroundEngineAltitudeStabilization()
-- Stop oscillate effect around target altitude
if aggAltitudeTarget == aggData.baseAltitude and core.g() < 0.1 and velocity_kmh >= 1 then
brakeInput = 1
else
-- Stop oscillate effect by short braking on high amplitude level
-- Atmo brakes are not direcly at full force, therefor oscillate effect takes longer
if aggAltitudeTarget ~= aggData.baseAltitude and core.g() < 0.1 and velocity_kmh > 16 then
brakeInput = 1
else
brakeInput = 0
end
end
end
end
-- Darkwinde END: system.flush()