Add true and false global variables as aliases for boolean types to distinguish the use of "int" from "bool".
This commit is contained in:
parent
b12e139b2c
commit
9ed54d98b6
10
aerotow.nas
10
aerotow.nas
@ -9,6 +9,16 @@
|
|||||||
# under the GNU Public License v3 (GPLv3)
|
# under the GNU Public License v3 (GPLv3)
|
||||||
#
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# Global aliases for boolean types to distinguish the use of "int" from "bool".
|
||||||
|
# NOTE: unfortunately, it doesn't work as an assignment of a default value for a function parameter!
|
||||||
|
#
|
||||||
|
var true = 1;
|
||||||
|
var false = 0;
|
||||||
|
|
||||||
|
#
|
||||||
|
# Global object of Aerotow
|
||||||
|
#
|
||||||
var g_Aerotow = nil;
|
var g_Aerotow = nil;
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -327,11 +327,11 @@
|
|||||||
<binding>
|
<binding>
|
||||||
<command>nasal</command>
|
<command>nasal</command>
|
||||||
<script><![CDATA[
|
<script><![CDATA[
|
||||||
setprop("/sim/hitches/aerotow/tow/length", 60.0);
|
setprop("/sim/hitches/aerotow/tow/length", 60.0); # hitch.nas 60.0
|
||||||
setprop("/sim/hitches/aerotow/tow/brake-force", 100000.0);
|
setprop("/sim/hitches/aerotow/tow/brake-force", 100000.0); # hitch.nas 12345.0
|
||||||
setprop("/sim/hitches/aerotow/tow/elastic-constant", 10000.0);
|
setprop("/sim/hitches/aerotow/tow/elastic-constant", 10000.0); # hitch.nas 9111.0
|
||||||
setprop("/sim/hitches/aerotow/rope/rope-diameter-mm", 20);
|
setprop("/sim/hitches/aerotow/rope/rope-diameter-mm", 20); # hitch.nas 20
|
||||||
setprop("/sim/hitches/aerotow/tow/weight-per-m-kg-m", 1.0);
|
setprop("/sim/hitches/aerotow/tow/weight-per-m-kg-m", 0.35); # hitch.nas 0.35
|
||||||
]]></script>
|
]]></script>
|
||||||
</binding>
|
</binding>
|
||||||
</button>
|
</button>
|
||||||
|
@ -55,7 +55,7 @@ var Aerotow = {
|
|||||||
me.message.success("Aerotow on the way");
|
me.message.success("Aerotow on the way");
|
||||||
|
|
||||||
# Stop playing engine sound
|
# Stop playing engine sound
|
||||||
setprop(me.addonNodePath ~ "/addon-devel/sound/enable", 0);
|
setprop(me.addonNodePath ~ "/addon-devel/sound/enable", false);
|
||||||
|
|
||||||
# Wait a second for the engine sound to turn off
|
# Wait a second for the engine sound to turn off
|
||||||
Timer.new().singleShot(1, me, func () {
|
Timer.new().singleShot(1, me, func () {
|
||||||
@ -80,15 +80,15 @@ var Aerotow = {
|
|||||||
#
|
#
|
||||||
# Main function to prepare AI scenario and run it.
|
# Main function to prepare AI scenario and run it.
|
||||||
#
|
#
|
||||||
# Return 1 on successful, otherwise 0.
|
# Return true on successful, otherwise false.
|
||||||
#
|
#
|
||||||
startAerotow: func () {
|
startAerotow: func () {
|
||||||
if (!me.scenario.unload()) {
|
if (!me.scenario.unload()) {
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!me.scenario.generateXml()) {
|
if (!me.scenario.generateXml()) {
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return me.scenario.load();
|
return me.scenario.load();
|
||||||
@ -97,10 +97,10 @@ var Aerotow = {
|
|||||||
#
|
#
|
||||||
# Function for unload our AI scenario.
|
# Function for unload our AI scenario.
|
||||||
#
|
#
|
||||||
# Return 1 on successful, otherwise 0.
|
# Return true on successful, otherwise false.
|
||||||
#
|
#
|
||||||
stopAerotow: func () {
|
stopAerotow: func () {
|
||||||
var withMessages = 1;
|
var withMessages = true;
|
||||||
return me.scenario.unload(withMessages);
|
return me.scenario.unload(withMessages);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -50,7 +50,7 @@ var Aircraft = {
|
|||||||
#
|
#
|
||||||
# name - Name of aircraft to check.
|
# name - Name of aircraft to check.
|
||||||
#
|
#
|
||||||
# Return 1 when match, otherwise 0.
|
# Return true when match, otherwise false.
|
||||||
#
|
#
|
||||||
isModelName: func (name) {
|
isModelName: func (name) {
|
||||||
return name == me.name or name == me.nameMenuCall;
|
return name == me.name or name == me.nameMenuCall;
|
||||||
@ -69,8 +69,8 @@ var Aircraft = {
|
|||||||
# Return selected Aircraft object
|
# Return selected Aircraft object
|
||||||
#
|
#
|
||||||
# addon - Addon object
|
# addon - Addon object
|
||||||
# isRouteMode - Use 1 to get the plane for the "Aerotow Route" dialog,
|
# isRouteMode - Use true to get the plane for the "Aerotow Route" dialog,
|
||||||
# use 0 (default) for call the airplane for towing.
|
# use false (default) for call the airplane for towing.
|
||||||
#
|
#
|
||||||
getSelected: func (addon, isRouteMode = 0) {
|
getSelected: func (addon, isRouteMode = 0) {
|
||||||
var name = Aircraft.getSelectedAircraftName(addon, isRouteMode);
|
var name = Aircraft.getSelectedAircraftName(addon, isRouteMode);
|
||||||
@ -89,10 +89,10 @@ var Aircraft = {
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
# addon - Addon object
|
# addon - Addon object
|
||||||
# isRouteMode - Use 1 to get the plane for the "Aerotow Route" dialog,
|
# isRouteMode - Use true to get the plane for the "Aerotow Route" dialog,
|
||||||
# use 0 (default) for call the airplane for towing.
|
# use false (default) for call the airplane for towing.
|
||||||
#
|
#
|
||||||
getSelectedAircraftName: func (addon, isRouteMode = 0) {
|
getSelectedAircraftName: func (addon, isRouteMode) {
|
||||||
if (isRouteMode) {
|
if (isRouteMode) {
|
||||||
return getprop(addon.node.getPath() ~ "/addon-devel/route/ai-model") or g_Aircrafts[0].name;
|
return getprop(addon.node.getPath() ~ "/addon-devel/route/ai-model") or g_Aircrafts[0].name;
|
||||||
}
|
}
|
||||||
|
@ -64,9 +64,9 @@ var RouteDialog = {
|
|||||||
calculateAltChangeAndTotals: func () {
|
calculateAltChangeAndTotals: func () {
|
||||||
var totalDistance = 0.0;
|
var totalDistance = 0.0;
|
||||||
var totalAlt = 0.0;
|
var totalAlt = 0.0;
|
||||||
var isEnd = 0;
|
var isEnd = false;
|
||||||
|
|
||||||
var isRouteMode = 1;
|
var isRouteMode = true;
|
||||||
var aircraft = Aircraft.getSelected(me.addon, isRouteMode);
|
var aircraft = Aircraft.getSelected(me.addon, isRouteMode);
|
||||||
|
|
||||||
for (var i = 0; i < me.maxRouteWaypoints; i += 1) {
|
for (var i = 0; i < me.maxRouteWaypoints; i += 1) {
|
||||||
@ -84,7 +84,7 @@ var RouteDialog = {
|
|||||||
totalAlt += altChange;
|
totalAlt += altChange;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
isEnd = 1;
|
isEnd = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ var Thermal = {
|
|||||||
#
|
#
|
||||||
# Add thermal 300 m before glider position.
|
# Add thermal 300 m before glider position.
|
||||||
#
|
#
|
||||||
# Return 1 on successful, otherwise 0.
|
# Return true on successful, otherwise false.
|
||||||
#
|
#
|
||||||
add: func () {
|
add: func () {
|
||||||
var heading = getprop("/orientation/heading-deg") or 0;
|
var heading = getprop("/orientation/heading-deg") or 0;
|
||||||
@ -87,10 +87,10 @@ var Thermal = {
|
|||||||
|
|
||||||
if (fgcommand("add-aiobject", args)) {
|
if (fgcommand("add-aiobject", args)) {
|
||||||
me.message.success("The thermal has been added");
|
me.message.success("The thermal has been added");
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
me.message.error("Adding thermal failed");
|
me.message.error("Adding thermal failed");
|
||||||
return 0;
|
return false;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -124,17 +124,17 @@ var FlightPlan = {
|
|||||||
#
|
#
|
||||||
# Initialize flight plan and set it to property tree
|
# Initialize flight plan and set it to property tree
|
||||||
#
|
#
|
||||||
# Return 1 on successful, otherwise 0.
|
# Return true on successful, otherwise false.
|
||||||
#
|
#
|
||||||
initial: func () {
|
initial: func () {
|
||||||
var location = me.getLocation();
|
var location = me.getLocation();
|
||||||
if (location == nil) {
|
if (location == nil) {
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var aircraft = Aircraft.getSelected(me.addon);
|
var aircraft = Aircraft.getSelected(me.addon);
|
||||||
|
|
||||||
var isGliderPos = 0;
|
var isGliderPos = false;
|
||||||
me.initAircraftVariable(location, isGliderPos);
|
me.initAircraftVariable(location, isGliderPos);
|
||||||
|
|
||||||
# inittial readonly waypoint
|
# inittial readonly waypoint
|
||||||
@ -189,28 +189,28 @@ var FlightPlan = {
|
|||||||
|
|
||||||
setprop(me.addonNodePath ~ "/addon-devel/route/wpts/description", "Default route around the start location");
|
setprop(me.addonNodePath ~ "/addon-devel/route/wpts/description", "Default route around the start location");
|
||||||
|
|
||||||
return 1;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
#
|
#
|
||||||
# Generate the XML file with the flight plane for our plane for AI scenario.
|
# Generate the XML file with the flight plane for our plane for AI scenario.
|
||||||
# The file will be stored to $Fobj.HOME/Export/aerotown-addon-flightplan.xml.
|
# The file will be stored to $HOME/Export/Addons/org.flightgear.addons.Aerotow/AI/FlightPlans/aerotown-addon-flightplan.xml.
|
||||||
#
|
#
|
||||||
# Return 1 on successful, otherwise 0.
|
# Return true on successful, otherwise false.
|
||||||
#
|
#
|
||||||
generateXml: func () {
|
generateXml: func () {
|
||||||
me.wptCount = 0;
|
me.wptCount = 0;
|
||||||
|
|
||||||
var location = me.getLocation();
|
var location = me.getLocation();
|
||||||
if (location == nil) {
|
if (location == nil) {
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
me.flightPlanWriter.open();
|
me.flightPlanWriter.open();
|
||||||
|
|
||||||
var aircraft = Aircraft.getSelected(me.addon);
|
var aircraft = Aircraft.getSelected(me.addon);
|
||||||
|
|
||||||
var isGliderPos = 1;
|
var isGliderPos = true;
|
||||||
me.initAircraftVariable(location, isGliderPos);
|
me.initAircraftVariable(location, isGliderPos);
|
||||||
|
|
||||||
# Start at 2 o'clock from the glider...
|
# Start at 2 o'clock from the glider...
|
||||||
@ -218,7 +218,7 @@ var FlightPlan = {
|
|||||||
me.addWptGround({"hdgChange": 60, "dist": 25}, {"altChange": 0, "ktas": 5});
|
me.addWptGround({"hdgChange": 60, "dist": 25}, {"altChange": 0, "ktas": 5});
|
||||||
|
|
||||||
# Reset coord and heading
|
# Reset coord and heading
|
||||||
isGliderPos = 0;
|
isGliderPos = false;
|
||||||
me.initAircraftVariable(location, isGliderPos);
|
me.initAircraftVariable(location, isGliderPos);
|
||||||
|
|
||||||
var gliderOffsetM = me.getGliderOffsetFromRunwayThreshold(location);
|
var gliderOffsetM = me.getGliderOffsetFromRunwayThreshold(location);
|
||||||
@ -268,7 +268,7 @@ var FlightPlan = {
|
|||||||
|
|
||||||
me.flightPlanWriter.close();
|
me.flightPlanWriter.close();
|
||||||
|
|
||||||
return 1;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -286,9 +286,9 @@ var FlightPlan = {
|
|||||||
# Initialize AI aircraft variable
|
# Initialize AI aircraft variable
|
||||||
#
|
#
|
||||||
# location - Object of location from which the glider start.
|
# location - Object of location from which the glider start.
|
||||||
# isGliderPos - Pass 1 for set AI aircraft's coordinates as glider position, 0 set coordinates as runway threshold.
|
# isGliderPos - Pass true for set AI aircraft's coordinates as glider position, false set coordinates as runway threshold.
|
||||||
#
|
#
|
||||||
initAircraftVariable: func (location, isGliderPos = 1) {
|
initAircraftVariable: func (location, isGliderPos) {
|
||||||
var gliderCoord = geo.aircraft_position();
|
var gliderCoord = geo.aircraft_position();
|
||||||
|
|
||||||
# Set coordinates as glider position or runway threshold
|
# Set coordinates as glider position or runway threshold
|
||||||
@ -318,7 +318,7 @@ var FlightPlan = {
|
|||||||
return rwyThreshold.distance_to(gliderCoord);
|
return rwyThreshold.distance_to(gliderCoord);
|
||||||
}
|
}
|
||||||
|
|
||||||
# We are not on the runway
|
# We are not on the runway, return 0 distance
|
||||||
return 0;
|
return 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ var Scenario = {
|
|||||||
obj.listeners = [];
|
obj.listeners = [];
|
||||||
obj.routeDialog = RouteDialog.new(addon, message);
|
obj.routeDialog = RouteDialog.new(addon, message);
|
||||||
obj.flightPlan = FlightPlan.new(addon, message, obj.routeDialog);
|
obj.flightPlan = FlightPlan.new(addon, message, obj.routeDialog);
|
||||||
obj.isScenarioLoaded = 0;
|
obj.isScenarioLoaded = false;
|
||||||
obj.scenarioPath = addon.storagePath ~ "/" ~ Scenario.FILENAME_SCENARIO;
|
obj.scenarioPath = addon.storagePath ~ "/" ~ Scenario.FILENAME_SCENARIO;
|
||||||
|
|
||||||
obj.flightPlan.initial();
|
obj.flightPlan.initial();
|
||||||
@ -64,11 +64,13 @@ var Scenario = {
|
|||||||
|
|
||||||
#
|
#
|
||||||
# Generate the XML file with the AI scenario.
|
# Generate the XML file with the AI scenario.
|
||||||
# The file will be stored to $FG_HOME/Export/aerotown-addon.xml.
|
# The file will be stored to $FG_HOME/Export/Addons/org.flightgear.addons.Aerotow/aerotown-addon.xml.
|
||||||
|
#
|
||||||
|
# Return true on successful, otherwise false
|
||||||
#
|
#
|
||||||
generateXml: func () {
|
generateXml: func () {
|
||||||
if (!me.flightPlan.generateXml()) {
|
if (!me.flightPlan.generateXml()) {
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var scenarioXml = {
|
var scenarioXml = {
|
||||||
@ -82,7 +84,7 @@ var Scenario = {
|
|||||||
"class": "aerotow-dragger",
|
"class": "aerotow-dragger",
|
||||||
"model": Aircraft.getSelected(me.addon).modelPath,
|
"model": Aircraft.getSelected(me.addon).modelPath,
|
||||||
"flightplan": FlightPlan.FILENAME_FLIGHTPLAN,
|
"flightplan": FlightPlan.FILENAME_FLIGHTPLAN,
|
||||||
"repeat": 1,
|
"repeat": true, # start again indefinitely
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,7 +95,7 @@ var Scenario = {
|
|||||||
|
|
||||||
me.addScenarioToPropertyList();
|
me.addScenarioToPropertyList();
|
||||||
|
|
||||||
return 1;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -114,67 +116,67 @@ var Scenario = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
#
|
#
|
||||||
# Return 1 if scenario is already added to "/sim/ai/scenarios" property list, otherwise return 0.
|
# Return true if scenario is already added to "/sim/ai/scenarios" property list, otherwise return false.
|
||||||
#
|
#
|
||||||
isAlreadyAdded: func () {
|
isAlreadyAdded: func () {
|
||||||
foreach (var scenario; props.globals.getNode("/sim/ai/scenarios").getChildren("scenario")) {
|
foreach (var scenario; props.globals.getNode("/sim/ai/scenarios").getChildren("scenario")) {
|
||||||
var id = scenario.getChild("id");
|
var id = scenario.getChild("id");
|
||||||
if (id != nil and id.getValue() == Scenario.SCENARIO_ID) {
|
if (id != nil and id.getValue() == Scenario.SCENARIO_ID) {
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
#
|
#
|
||||||
# Load scenario
|
# Load scenario
|
||||||
#
|
#
|
||||||
# Return 1 on successful, otherwise 0.
|
# Return true on successful, otherwise false.
|
||||||
#
|
#
|
||||||
load: func () {
|
load: func () {
|
||||||
var args = props.Node.new({ "name": Scenario.SCENARIO_ID });
|
var args = props.Node.new({ "name": Scenario.SCENARIO_ID });
|
||||||
if (fgcommand("load-scenario", args)) {
|
if (fgcommand("load-scenario", args)) {
|
||||||
me.isScenarioLoaded = 1;
|
me.isScenarioLoaded = true;
|
||||||
me.message.success("Let's fly!");
|
me.message.success("Let's fly!");
|
||||||
|
|
||||||
# Enable engine sound
|
# Enable engine sound
|
||||||
setprop(me.addonNodePath ~ "/addon-devel/sound/enable", 1);
|
setprop(me.addonNodePath ~ "/addon-devel/sound/enable", true);
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
me.message.error("Tow failed!");
|
me.message.error("Tow failed!");
|
||||||
return 0;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
#
|
#
|
||||||
# Unload scenario
|
# Unload scenario
|
||||||
#
|
#
|
||||||
# withMessages - Set 1 to display messages.
|
# withMessages - Set true to display messages.
|
||||||
#
|
#
|
||||||
# Return 1 on successful, otherwise 0.
|
# Return true on successful, otherwise false.
|
||||||
#
|
#
|
||||||
unload: func (withMessages = 0) {
|
unload: func (withMessages = 0) {
|
||||||
if (me.isScenarioLoaded) {
|
if (me.isScenarioLoaded) {
|
||||||
var args = props.Node.new({ "name": Scenario.SCENARIO_ID });
|
var args = props.Node.new({ "name": Scenario.SCENARIO_ID });
|
||||||
if (fgcommand("unload-scenario", args)) {
|
if (fgcommand("unload-scenario", args)) {
|
||||||
me.isScenarioLoaded = 0;
|
me.isScenarioLoaded = false;
|
||||||
|
|
||||||
if (withMessages) {
|
if (withMessages) {
|
||||||
me.message.success("Aerotown disabled");
|
me.message.success("Aerotown disabled");
|
||||||
}
|
}
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (withMessages) {
|
if (withMessages) {
|
||||||
me.message.error("Aerotown disable failed");
|
me.message.error("Aerotown disable failed");
|
||||||
}
|
}
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (withMessages) {
|
if (withMessages) {
|
||||||
me.message.success("Aerotown already disabled");
|
me.message.success("Aerotown already disabled");
|
||||||
}
|
}
|
||||||
return 1;
|
return true;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -33,7 +33,7 @@ var Timer = {
|
|||||||
var timer = maketimer(delaySec, self, func () {
|
var timer = maketimer(delaySec, self, func () {
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
timer.singleShot = 1;
|
timer.singleShot = true;
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
return timer;
|
return timer;
|
||||||
|
Loading…
Reference in New Issue
Block a user