1
0
Fork 0

Aircraft/Generic/MPCarriers.nas: added support for always tying AI and MP carriers together.

We tie MP and AI carrier together if /sim/mp-carriers/latch-always is true.

This is done by setting /ai/models/carrier[]/ai-latch to the
/ai/models/multiplayer path containing the corresponding Multiplayer
information. C++ code will detect this and copy across the position and
orientation each frame.
This commit is contained in:
Julian Smith 2021-06-24 15:48:14 +01:00
parent 46b1cd62f7
commit 5a4bc3fc53

View file

@ -19,7 +19,11 @@
# mp carriers.
#
var g_auto_attach = props.globals.getNode("/sim/mp-carriers/auto-attach", 1);
printf("g_auto_attach.getValue()=%s", g_auto_attach.getValue());
var g_latch_always = props.globals.getNode("/sim/mp-carriers/latch-always", 1);
printf("fgdata/Aircraft/Generic/MPCarriers.nas: g_auto_attach.getValue()=%s g_latch_always=%s",
g_auto_attach.getValue(),
g_latch_always.getValue(),
);
# Constants
var lat = "position/latitude-deg";
@ -202,6 +206,8 @@ Manager.update = func {
me.message = message;
}
if (!g_latch_always.getValue())
{
# carrier_pos.set_latlon(me.carrier.getNode(lat).getValue(),
# me.carrier.getNode(lon).getValue(),
# me.carrier.getNode(alt).getValue());
@ -219,7 +225,8 @@ Manager.update = func {
rplayer_pos.set_xyz(me.rplayer.getNode(x).getValue(),
me.rplayer.getNode(y).getValue(),
me.rplayer.getNode(z).getValue());
}
var master_course = normalize_course(me.rplayer.getNode(mp_heading).getValue());
var master_speed = me.rplayer.getNode(mp_speed).getValue();
var bearing_to_master = normalize_course(carrier_pos.course_to(rplayer_pos));
@ -332,7 +339,17 @@ Manager.update = func {
me.carrier.getNode("mp-control/aircraft-ai-distance", 1).setValue(distance_aircraft_carrier);
me.carrier.getNode("mp-control/ai-mp-latched", do_latch);
if (do_latch) {
if (g_latch_always.getValue()) {
# Tell C++ to copy MP position/orientation directly on to AI
# position/orientation, every frame.
#
# Set /ai/models/multiplayer[]/ai-latch to "/ai/models/carrier[]".
#
# Set /ai/models/carrier[]/ai-latch to "/ai/models/multiplayer[]".
me.rplayer.getNode("ai-latch", 1).setValue(me.carrier.getPath());
me.carrier.getNode("ai-latch", 1).setValue(me.rplayer.getPath());
}
elsif (do_latch) {
# Latch the local AI carrier to the remote player's
# location only when the local player is far enough away not
# to suffer side effects.
@ -372,6 +389,8 @@ Manager.stop = func {
# Reenable AI control.
if (me.carrier.getNode(c_control_mp_ctrl) != nil)
me.carrier.getNode(c_control_mp_ctrl).setBoolValue(0);
me.rplayer.getNode("ai-latch").setValue("");
me.carrier.getNode("ai-latch").setValue("");
}
##################################################
Manager.die = func {