2015-06-06 05:00:31 +00:00
|
|
|
var i = 0;
|
2015-06-14 22:06:20 +00:00
|
|
|
var spectator = 0;
|
2015-06-06 05:00:31 +00:00
|
|
|
var spectator_offset = 0.5;
|
|
|
|
var range = 3.0;
|
|
|
|
var offset = 0.0;
|
2015-06-14 22:06:20 +00:00
|
|
|
var apply_close = 0;
|
2015-06-06 05:00:31 +00:00
|
|
|
var master = 0;
|
|
|
|
var close = 0;
|
2015-06-14 22:06:20 +00:00
|
|
|
var initialised = 0;
|
2015-06-06 05:00:31 +00:00
|
|
|
|
2015-06-09 19:12:48 +00:00
|
|
|
var ls_spect = nil;
|
|
|
|
var ls_spctoffset = nil;
|
|
|
|
var ls_range = nil;
|
|
|
|
var ls_offset = nil;
|
|
|
|
var ls_close = nil;
|
|
|
|
|
|
|
|
# the compensatelag value are used like that by AIMultiplayer.cxx:
|
|
|
|
#
|
|
|
|
# 1 : old behaviour, trying to keep the plane without doing prediction
|
|
|
|
# 2 : predict the plane position in the futur
|
|
|
|
# 3 : display more in the past to avoid predictions
|
|
|
|
|
2015-06-06 05:00:31 +00:00
|
|
|
var mpCheck = func() {
|
2015-06-09 19:12:48 +00:00
|
|
|
var mpname = getprop("/ai/models/multiplayer["~i~"]/callsign");
|
|
|
|
if (mpname != nil) {
|
2015-06-14 22:06:20 +00:00
|
|
|
if ((spectator) and (master)) {
|
2015-06-06 05:00:31 +00:00
|
|
|
setprop("/ai/models/multiplayer["~i~"]/controls/compensate-lag", 3);
|
|
|
|
setprop("/ai/models/multiplayer["~i~"]/controls/player-lag", -spectator_offset);
|
|
|
|
} else {
|
2015-06-14 22:06:20 +00:00
|
|
|
if ((apply_close) and (master)) {
|
2015-06-08 16:23:34 +00:00
|
|
|
var self = geo.aircraft_position();
|
|
|
|
var x = getprop("/ai/models/multiplayer["~i~"]/position/global-x");
|
|
|
|
var y = getprop("/ai/models/multiplayer["~i~"]/position/global-y");
|
|
|
|
var z = getprop("/ai/models/multiplayer["~i~"]/position/global-z");
|
|
|
|
var ac = geo.Coord.new().set_xyz(x, y, z);
|
|
|
|
var distance = self.distance_to(ac)*M2NM;
|
|
|
|
if ((distance > range)or(distance==nil)) {
|
|
|
|
setprop("/ai/models/multiplayer["~i~"]/controls/compensate-lag", 1);
|
|
|
|
} else {
|
|
|
|
setprop("/ai/models/multiplayer["~i~"]/controls/compensate-lag", 2);
|
2015-06-09 19:12:48 +00:00
|
|
|
setprop("/ai/models/multiplayer["~i~"]/controls/player-lag", offset);
|
2015-06-08 16:23:34 +00:00
|
|
|
}
|
2015-06-06 05:00:31 +00:00
|
|
|
} else {
|
2015-06-08 16:23:34 +00:00
|
|
|
setprop("/ai/models/multiplayer["~i~"]/controls/compensate-lag", 1);
|
|
|
|
}
|
2015-06-06 05:00:31 +00:00
|
|
|
}
|
2015-06-09 19:12:48 +00:00
|
|
|
i += 1;
|
2015-06-06 05:00:31 +00:00
|
|
|
} else {
|
|
|
|
i = 0;
|
|
|
|
if (close) close = 0;
|
|
|
|
}
|
|
|
|
if ((master) or (close)) {
|
|
|
|
settimer(mpCheck, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var mpInit = func() {
|
2015-06-14 22:06:20 +00:00
|
|
|
if (!initialised) {
|
|
|
|
print("initialising the mp lag system");
|
|
|
|
initialised = 1;
|
|
|
|
ls_spect = setlistener("/sim/multiplay/lag/spectator",func { spectator = getprop("/sim/multiplay/lag/spectator")}, 1);
|
|
|
|
ls_spctoffset = setlistener("/sim/multiplay/lag/spectator-offset",func { spectator_offset = getprop("/sim/multiplay/lag/spectator-offset")}, 1);
|
|
|
|
ls_range = setlistener("/sim/multiplay/lag/range",func { range = getprop("/sim/multiplay/lag/range")}, 1);
|
|
|
|
ls_offset = setlistener("/sim/multiplay/lag/offset",func { offset = getprop("/sim/multiplay/lag/offset")}, 1);
|
|
|
|
ls_close = setlistener("/sim/multiplay/lag/apply-close", func { apply_close = getprop("/sim/multiplay/lag/apply-close")}, 1);
|
|
|
|
}
|
2015-06-06 05:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var mpClean = func() {
|
|
|
|
close = 1;
|
|
|
|
master = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
var mpStart = func() {
|
|
|
|
var test = getprop("/sim/multiplay/lag/master");
|
|
|
|
if (test == nil) {
|
|
|
|
settimer(mpStart, 2);
|
|
|
|
} else {
|
|
|
|
setlistener("/sim/multiplay/lag/master", masterSwitch,1);
|
2015-06-09 19:12:48 +00:00
|
|
|
}
|
2015-06-06 05:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var masterSwitch = func() {
|
|
|
|
master = getprop("/sim/multiplay/lag/master");
|
|
|
|
if (master) {
|
|
|
|
mpInit();
|
|
|
|
mpCheck();
|
|
|
|
} else {
|
|
|
|
mpClean();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_setlistener("/sim/signals/nasal-dir-initialized", mpStart);
|