diff --git a/Moose Development/Moose/Functional/RAT.lua b/Moose Development/Moose/Functional/RAT.lua index fafa78686..b4274f0d9 100644 --- a/Moose Development/Moose/Functional/RAT.lua +++ b/Moose Development/Moose/Functional/RAT.lua @@ -511,7 +511,7 @@ RAT.id="RAT | " --- RAT version. -- @list version RAT.version={ - version = "2.3.1", + version = "2.3.2", print = true, } @@ -2124,10 +2124,16 @@ function RAT:_SpawnWithRoute(_departure, _destination, _takeoff, _landing, _live if group:InAir() then self.ratcraft[self.SpawnIndex]["Tground"]=nil self.ratcraft[self.SpawnIndex]["Pground"]=nil + self.ratcraft[self.SpawnIndex]["Uground"]=nil self.ratcraft[self.SpawnIndex]["Tlastcheck"]=nil else self.ratcraft[self.SpawnIndex]["Tground"]=timer.getTime() self.ratcraft[self.SpawnIndex]["Pground"]=group:GetCoordinate() + self.ratcraft[self.SpawnIndex]["Uground"]={} + for _,_unit in pairs(group:GetUnits()) do + local _unitname=_unit:GetName() + self.ratcraft[self.SpawnIndex]["Uground"][_unitname]=_unit:GetCoordinate() + end self.ratcraft[self.SpawnIndex]["Tlastcheck"]=timer.getTime() end -- Initial and current position. For calculating the travelled distance. @@ -3361,6 +3367,7 @@ function RAT:Status(message, forID) -- Aircraft is airborne. ratcraft["Tground"]=nil ratcraft["Pground"]=nil + ratcraft["Uground"]=nil ratcraft["Tlastcheck"]=nil else --Aircraft is on ground. @@ -3377,16 +3384,39 @@ function RAT:Status(message, forID) -- If more than Tinactive seconds passed since last check ==> check how much we moved meanwhile. if dTlast > self.Tinactive then - -- If aircraft did not move more than 50 m since last check, we call it stationary and despawn it. - -- Aircraft which are spawned uncontrolled or starting their engines are not counted. + --[[ if Dg<50 and active and status~=RAT.status.EventBirth then - --if Dg<50 and active then stationary=true end + ]] - -- Set the current time to know when the next check is necessary. + -- Loop over all units. + for _,_unit in pairs(group:GetUnits()) do + + if _unit and _unit:IsAlive() then + + -- Unit name, coord and distance since last check. + local unitname=_unit:GetName() + local unitcoord=_unit:GetCoordinate() + local Ug=unitcoord:Get2DDistance(ratcraft.Uground[unitname]) + + -- Debug info + self:T2(RAT.id..string.format("Unit %s travelled distance on ground %.1f m since %d seconds.", unitname, Ug, dTlast)) + + -- If aircraft did not move more than 50 m since last check, we call it stationary and despawn it. + -- Aircraft which are spawned uncontrolled or starting their engines are not counted. + if Ug<50 and active and status~=RAT.status.EventBirth then + stationary=true + end + + -- Update coords. + ratcraft["Uground"][unitname]=unitcoord + end + end + + -- Set the current time to know when the next check is necessary. ratcraft["Tlastcheck"]=Tnow - ratcraft["Pground"]=coords + ratcraft["Pground"]=coords end else @@ -3394,6 +3424,11 @@ function RAT:Status(message, forID) ratcraft["Tground"]=Tnow ratcraft["Tlastcheck"]=Tnow ratcraft["Pground"]=coords + ratcraft["Uground"]={} + for _,_unit in pairs(group:GetUnits()) do + local unitname=_unit:GetName() + ratcraft.Uground[unitname]=_unit:GetCoordinate() + end end end diff --git a/Moose Development/Moose/Wrapper/Airbase.lua b/Moose Development/Moose/Wrapper/Airbase.lua index 635cbfe4a..a7db3796d 100644 --- a/Moose Development/Moose/Wrapper/Airbase.lua +++ b/Moose Development/Moose/Wrapper/Airbase.lua @@ -626,9 +626,9 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius, end -- Function calculating the overlap of two (square) objects. - local function _overlap(mooseobject, dcsobject, dist) - local l1=_GetObjectSize(mooseobject, true) - local l2=_GetObjectSize(dcsobject) + local function _overlap(object1, mooseobject1, object2, mooseobject2, dist) + local l1=_GetObjectSize(object1, mooseobject1) + local l2=_GetObjectSize(object2, mooseobject2) local safedist=(l1/2+l2/2)*1.1 local safe = (dist > safedist) self:T3(string.format("l1=%.1f l2=%.1f s=%.1f d=%.1f ==> safe=%s", l1,l2,safedist,dist,tostring(safe))) @@ -676,10 +676,10 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius, local _termid=parkingspot.TerminalID -- Very safe uses the DCS getParking() info to check if a spot is free. Unfortunately, the function returns free=false until the aircraft has actually taken-off. - if verysafe and parkingspot.Free==false then + if verysafe and (parkingspot.Free==false or parkingspot.TOAC==true) then -- DCS getParking() routine returned that spot is not free. - self:T(string.format("%s: Parking spot id %d NOT free (or aircraft has not taken off yet).", airport, parkingspot.TerminalID)) + self:E(string.format("%s: Parking spot id %d NOT free (or aircraft has not taken off yet). Free=%s, TOAC=%s.", airport, parkingspot.TerminalID, tostring(parkingspot.Free), tostring(parkingspot.TOAC))) else @@ -695,7 +695,7 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius, local _vec3=unit:getPoint() local _coord=COORDINATE:NewFromVec3(_vec3) local _dist=_coord:Get2DDistance(_spot) - local _safe=_overlap(aircraft, unit, _dist) + local _safe=_overlap(aircraft, true, unit, false,_dist) if markobstacles then local l,x,y,z=_GetObjectSize(unit) @@ -712,7 +712,7 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius, local _vec3=static:getPoint() local _coord=COORDINATE:NewFromVec3(_vec3) local _dist=_coord:Get2DDistance(_spot) - local _safe=_overlap(aircraft, static, _dist) + local _safe=_overlap(aircraft, true, static, false,_dist) if markobstacles then local l,x,y,z=_GetObjectSize(static) @@ -728,8 +728,8 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius, for _,scenery in pairs(_sceneries) do local _vec3=scenery:getPoint() local _coord=COORDINATE:NewFromVec3(_vec3) - local _dist=_coord:Get2DDistance(_spot) - local _safe=_overlap(aircraft, scenery, _dist) + local _dist=_coord:Get2DDistance(_spot) + local _safe=_overlap(aircraft, true, scenery, false,_dist) if markobstacles then local l,x,y,z=_GetObjectSize(scenery) @@ -741,6 +741,15 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius, end end + -- Now check the already given spots so that we do not put a large aircraft next to one we already assigned a nearby spot. + for _,_takenspot in pairs(validspots) do + local _dist=_takenspot.Coordinate:Get2DDistance(_spot) + local _safe=_overlap(aircraft, true, aircraft, true,_dist) + if not _safe then + occupied=true + end + end + --_spot:MarkToAll(string.format("Parking spot %d free=%s", parkingspot.TerminalID, tostring(not occupied))) if occupied then self:T(string.format("%s: Parking spot id %d occupied.", airport, _termid)) @@ -752,12 +761,13 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius, nvalid=nvalid+1 end - end + end -- loop over units -- We found enough spots. if nvalid>=_nspots then return validspots end + end -- Retrun spots we found, even if there were not enough.