| 1 |
############################# |
| 2 |
# Usable with FlightGear |
| 3 |
# Property of Gerard Robin |
| 4 |
# Copyright License: GPL |
| 5 |
# |
| 6 |
# Was by Gerard ROBIN. |
| 7 |
# update: grtux hangar team https://sites.google.com/site/grtuxhangar/ |
| 8 |
# COPYRIGHT |
| 9 |
############################ |
| 10 |
#init Moorage. |
| 11 |
#Replace the generic Seaboat fightgear system which is wrong, and not completed with the list of harbours. |
| 12 |
#This is a customized developpement done from an original idea => the Boeing 314A Project (the nice and accurate FG Clipper) thanks to his unknown Author. |
| 13 |
#We are using the original harbour list which was used by the boeing314 model and using too a specific customized addon list which could be improved. |
| 14 |
#both files are: mooring-pos_boeing314-based.xml, mooring-pos.xml |
| 15 |
############################ |
| 16 |
#Modifications: |
| 17 |
#Wayne Bragg/c172p-detailed, April 2018 |
| 18 |
############################ |
| 19 |
|
| 20 |
#init if allowed and called for |
| 21 |
var mooring_preset = 0; |
| 22 |
var presets = props.globals.getNode("/sim/presets"); |
| 23 |
var seaplanes = props.globals.getNode("/systems/mooring/route").getChildren("seaplane"); |
| 24 |
var harbour = ""; |
| 25 |
var airport = presets.getChild("airport-id").getValue(); |
| 26 |
|
| 27 |
setlistener("/sim/signals/fdm-initialized", |
| 28 |
func { |
| 29 |
setprop("/controls/mooring/port-available", 0); |
| 30 |
if(airport != nil and airport != "") { |
| 31 |
for(var i=0; i<size(seaplanes); i=i+1) { |
| 32 |
harbour = seaplanes[ i ].getChild("airport-id").getValue(); |
| 33 |
if(harbour == airport) { |
| 34 |
setprop("/controls/mooring/port-available", 1); |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
settimer(func{ |
| 39 |
var aircraft = getprop("sim/aircraft"); |
| 40 |
if (aircraft == "c172p"){ |
| 41 |
setprop("fdm/jsbsim/bushkit", 0); |
| 42 |
} else if (aircraft == "c172p-bush26"){ |
| 43 |
setprop("fdm/jsbsim/bushkit", 1); |
| 44 |
} else if (aircraft == "c172p-bush26"){ |
| 45 |
setprop("fdm/jsbsim/bushkit", 2); |
| 46 |
} else if (aircraft == "c172p-floats"){ |
| 47 |
setprop("fdm/jsbsim/bushkit", 3); |
| 48 |
} else if (aircraft == "c172p-amphibious"){ |
| 49 |
setprop("fdm/jsbsim/bushkit", 4); |
| 50 |
} else if (aircraft == "c172p-ski"){ |
| 51 |
setprop("fdm/jsbsim/bushkit", 5); |
| 52 |
} |
| 53 |
if (getprop("/controls/mooring/automatic") and getprop("/controls/mooring/allowed")) { |
| 54 |
seaplane = Mooring.new(); |
| 55 |
} |
| 56 |
if (mooring_preset) { |
| 57 |
mooring_preset=0; |
| 58 |
# force aircraft into proper orientation (bug in presets or reset?) |
| 59 |
setprop("/orientation/roll-deg", 0); |
| 60 |
setprop("/orientation/pitch-deg", 0); |
| 61 |
|
| 62 |
if (getprop("/fdm/jsbsim/settings/damage-flag")) { |
| 63 |
settimer(func { |
| 64 |
setprop("/fdm/jsbsim/settings/damage", 1); |
| 65 |
setprop("/fdm/jsbsim/settings/damage-flag", 0); |
| 66 |
}, 2); |
| 67 |
} |
| 68 |
} |
| 69 |
},1.0); |
| 70 |
} |
| 71 |
); |
| 72 |
setlistener("/controls/mooring/go-to-mooring", |
| 73 |
func { |
| 74 |
if (getprop("/controls/mooring/allowed")) { |
| 75 |
seaplane = Mooring.new(); |
| 76 |
} |
| 77 |
} |
| 78 |
); |
| 79 |
|
| 80 |
Mooring = {}; |
| 81 |
|
| 82 |
Mooring.new = func { |
| 83 |
var obj = { |
| 84 |
parents : [Mooring], |
| 85 |
presets : nil, |
| 86 |
seaplanes : nil, |
| 87 |
}; |
| 88 |
obj.init(); |
| 89 |
return obj; |
| 90 |
}; |
| 91 |
|
| 92 |
Mooring.init = func { |
| 93 |
me.presets = props.globals.getNode("/sim/presets"); |
| 94 |
me.seaplanes = props.globals.getNode("/systems/mooring/route").getChildren("seaplane"); |
| 95 |
me.presetseaplane(); |
| 96 |
} |
| 97 |
|
| 98 |
Mooring.setmoorage = func( index, moorage ) { |
| 99 |
var latitudedeg = me.seaplanes[ index ].getChild("latitude-deg").getValue(); |
| 100 |
var longitudedeg = me.seaplanes[ index ].getChild("longitude-deg").getValue(); |
| 101 |
var headingdeg = me.seaplanes[ index ].getChild("heading-deg").getValue(); |
| 102 |
print (" LAT ",latitudedeg," LON ",longitudedeg," HEAD ",headingdeg); |
| 103 |
|
| 104 |
# overwrite the coordinates from the original airport |
| 105 |
me.presets.getChild("airspeed-kt").setValue(0); |
| 106 |
me.presets.getChild("latitude-deg").setValue(latitudedeg); |
| 107 |
me.presets.getChild("longitude-deg").setValue(longitudedeg); |
| 108 |
me.presets.getChild("heading-deg").setValue(headingdeg); |
| 109 |
me.presets.getChild("roll-deg").setValue(0); |
| 110 |
me.presets.getChild("pitch-deg").setValue(0); |
| 111 |
me.presets.getChild("offset-distance-nm").setValue(0); |
| 112 |
#glideslop-deg not pre initialized in core |
| 113 |
setprop("glideslope-deg", 0.0); |
| 114 |
me.presets.getChild("runway").setValue(""); |
| 115 |
me.presets.getChild("runway-requested").setValue(0); |
| 116 |
me.presets.getChild("airport-id").setValue(""); |
| 117 |
# forces the computation of ground |
| 118 |
me.presets.getChild("altitude-ft").setValue(-9999); |
| 119 |
} |
| 120 |
|
| 121 |
Mooring.presetseaplane = func { |
| 122 |
# to search the harbor |
| 123 |
if(getprop("/sim/sceneryloaded")) { |
| 124 |
mooring_preset = 1; |
| 125 |
me.presetharbour(); |
| 126 |
} |
| 127 |
else |
| 128 |
mooring_preset = 0; |
| 129 |
} |
| 130 |
|
| 131 |
# search the port |
| 132 |
Mooring.presetharbour = func { |
| 133 |
var airport = ""; |
| 134 |
var harbour = ""; |
| 135 |
airport = me.presets.getChild("airport-id").getValue(); |
| 136 |
if(airport != nil and airport != "") { |
| 137 |
for(var i=0; i<size(me.seaplanes); i=i+1) { |
| 138 |
harbour = me.seaplanes[ i ].getChild("airport-id").getValue(); |
| 139 |
if(harbour == airport) { |
| 140 |
print("PORT ",harbour," Index ",i); |
| 141 |
me.setmoorage(i, airport); |
| 142 |
me.prepareseaplane(); |
| 143 |
c172p.oil_consumption.stop(); |
| 144 |
fgcommand("reposition"); |
| 145 |
break; |
| 146 |
} |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
#Specific initialization of the aircraft |
| 152 |
Mooring.prepareseaplane = func{ |
| 153 |
if (getprop("/fdm/jsbsim/settings/damage")) { |
| 154 |
setprop("/fdm/jsbsim/settings/damage-flag", 1); |
| 155 |
setprop("/fdm/jsbsim/settings/damage", 0); |
| 156 |
} |
| 157 |
setprop("/sim/model/c172p/securing/tiedownL-visible", 0); |
| 158 |
setprop("/sim/model/c172p/securing/tiedownR-visible", 0); |
| 159 |
setprop("/sim/model/c172p/securing/tiedownT-visible", 0); |
| 160 |
setprop("/sim/model/c172p/securing/chock", 0); |
| 161 |
} |