mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Merge pull request #957 from FlightControl-Master/FF/Develop
Various minor updates and fixes.
This commit is contained in:
commit
6d8b8f41ad
@ -604,7 +604,7 @@ function AI_CARGO_APC:onafterPickup( APC, From, Event, To, Coordinate )
|
|||||||
if Coordinate then
|
if Coordinate then
|
||||||
self.RoutePickup = true
|
self.RoutePickup = true
|
||||||
|
|
||||||
local Waypoints = APC:TaskGroundOnRoad( Coordinate, APC:GetSpeedMax()*0.5, "Line abreast" )
|
local Waypoints = APC:TaskGroundOnRoad( Coordinate, APC:GetSpeedMax()*0.5, "Line abreast", true )
|
||||||
|
|
||||||
local TaskFunction = APC:TaskFunction( "AI_CARGO_APC._Pickup", self )
|
local TaskFunction = APC:TaskFunction( "AI_CARGO_APC._Pickup", self )
|
||||||
|
|
||||||
@ -635,7 +635,7 @@ function AI_CARGO_APC:onafterDeploy( APC, From, Event, To, Coordinate )
|
|||||||
|
|
||||||
self.RouteDeploy = true
|
self.RouteDeploy = true
|
||||||
|
|
||||||
local Waypoints = APC:TaskGroundOnRoad( Coordinate, APC:GetSpeedMax()*0.5, "Line abreast" )
|
local Waypoints = APC:TaskGroundOnRoad( Coordinate, APC:GetSpeedMax()*0.5, "Line abreast", true )
|
||||||
|
|
||||||
local TaskFunction = APC:TaskFunction( "AI_CARGO_APC._Deploy", self )
|
local TaskFunction = APC:TaskFunction( "AI_CARGO_APC._Deploy", self )
|
||||||
|
|
||||||
@ -661,7 +661,7 @@ function AI_CARGO_APC:onafterHome( APC, From, Event, To, Coordinate )
|
|||||||
|
|
||||||
self.RouteHome = true
|
self.RouteHome = true
|
||||||
|
|
||||||
local Waypoints = APC:TaskGroundOnRoad( Coordinate, APC:GetSpeedMax()*0.5, "Line abreast" )
|
local Waypoints = APC:TaskGroundOnRoad( Coordinate, APC:GetSpeedMax()*0.5, "Line abreast", true )
|
||||||
|
|
||||||
self:F({Waypoints = Waypoints})
|
self:F({Waypoints = Waypoints})
|
||||||
local Waypoint = Waypoints[#Waypoints]
|
local Waypoint = Waypoints[#Waypoints]
|
||||||
|
|||||||
@ -968,7 +968,7 @@ function AI_FORMATION:onenterFollowing( FollowGroupSet ) --R2.1
|
|||||||
local Alpha_R = ( Alpha_T < 0 ) and Alpha_T + 2 * math.pi or Alpha_T
|
local Alpha_R = ( Alpha_T < 0 ) and Alpha_T + 2 * math.pi or Alpha_T
|
||||||
local Position = math.cos( Alpha_R )
|
local Position = math.cos( Alpha_R )
|
||||||
local GD = ( ( GDv.x )^2 + ( GDv.z )^2 ) ^ 0.5
|
local GD = ( ( GDv.x )^2 + ( GDv.z )^2 ) ^ 0.5
|
||||||
local Distance = GD * Position + - CS * 0,5
|
local Distance = GD * Position + - CS * 0.5
|
||||||
|
|
||||||
-- Calculate the group direction vector
|
-- Calculate the group direction vector
|
||||||
local GV = { x = GV2.x - CV2.x, y = GV2.y - CV2.y, z = GV2.z - CV2.z }
|
local GV = { x = GV2.x - CV2.x, y = GV2.y - CV2.y, z = GV2.z - CV2.z }
|
||||||
|
|||||||
@ -364,7 +364,7 @@ do -- CARGO_GROUP
|
|||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
function CARGO_GROUP:onenterUnBoarding( From, Event, To, ToPointVec2, NearRadius, ... )
|
function CARGO_GROUP:onenterUnBoarding( From, Event, To, ToPointVec2, NearRadius, ... )
|
||||||
--self:F( {From, Event, To, ToPointVec2, NearRadius } )
|
self:F( {From, Event, To, ToPointVec2, NearRadius } )
|
||||||
|
|
||||||
NearRadius = NearRadius or 25
|
NearRadius = NearRadius or 25
|
||||||
|
|
||||||
@ -381,7 +381,13 @@ do -- CARGO_GROUP
|
|||||||
--- @param Cargo.Cargo#CARGO Cargo
|
--- @param Cargo.Cargo#CARGO Cargo
|
||||||
function( Cargo, NearRadius )
|
function( Cargo, NearRadius )
|
||||||
if not Cargo:IsDestroyed() then
|
if not Cargo:IsDestroyed() then
|
||||||
Cargo:__UnBoard( Timer, ToPointVec2, NearRadius )
|
local ToVec=nil
|
||||||
|
if ToPointVec2==nil then
|
||||||
|
ToVec=self.CargoCarrier:GetPointVec2():GetRandomPointVec2InRadius(2*NearRadius, NearRadius)
|
||||||
|
else
|
||||||
|
ToVec=ToPointVec2
|
||||||
|
end
|
||||||
|
Cargo:__UnBoard( Timer, ToVec, NearRadius )
|
||||||
Timer = Timer + 3
|
Timer = Timer + 3
|
||||||
end
|
end
|
||||||
end, { NearRadius }
|
end, { NearRadius }
|
||||||
|
|||||||
@ -1184,29 +1184,56 @@ do -- COORDINATE
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Returns a table of coordinates to a destination using only roads.
|
--- Returns a table of coordinates to a destination using only roads.
|
||||||
-- The first point is the closest point on road of the given coordinate. The last point is the closest point on road of the ToCoord. Hence, the coordinate itself and the final ToCoord are not necessarily included in the path.
|
-- The first point is the closest point on road of the given coordinate.
|
||||||
|
-- By default, the last point is the closest point on road of the ToCoord. Hence, the coordinate itself and the final ToCoord are not necessarily included in the path.
|
||||||
-- @param #COORDINATE self
|
-- @param #COORDINATE self
|
||||||
-- @param #COORDINATE ToCoord Coordinate of destination.
|
-- @param #COORDINATE ToCoord Coordinate of destination.
|
||||||
-- @return #table Table of coordinates on road. If no path on road can be found, nil is returned.
|
-- @param #boolean IncludeEndpoints (Optional) Include the coordinate itself and the ToCoordinate in the path.
|
||||||
function COORDINATE:GetPathOnRoad(ToCoord)
|
-- @return #table Table of coordinates on road. If no path on road can be found, nil is returned or just the endpoints.
|
||||||
|
-- @return #number The length of the total path.
|
||||||
|
function COORDINATE:GetPathOnRoad(ToCoord, IncludeEndpoints)
|
||||||
|
|
||||||
-- DCS API function returning a table of vec2.
|
-- DCS API function returning a table of vec2.
|
||||||
local path = land.findPathOnRoads("roads", self.x, self.z, ToCoord.x, ToCoord.z)
|
local path = land.findPathOnRoads("roads", self.x, self.z, ToCoord.x, ToCoord.z)
|
||||||
|
|
||||||
|
-- Array holding the path coordinates.
|
||||||
local Path={}
|
local Path={}
|
||||||
|
local Way=0
|
||||||
|
|
||||||
if path then
|
-- Include currrent position.
|
||||||
--Path[#Path+1]=self
|
if IncludeEndpoints then
|
||||||
for i, v in ipairs(path) do
|
Path[1]=self
|
||||||
Path[#Path+1]=COORDINATE:NewFromVec2(v)
|
end
|
||||||
|
|
||||||
|
-- Check that DCS routine actually returned a path. There are situations where this is not the case.
|
||||||
|
if path then
|
||||||
|
|
||||||
|
-- Include all points on road.
|
||||||
|
for _,_vec2 in ipairs(path) do
|
||||||
|
Path[#Path+1]=COORDINATE:NewFromVec2(_vec2)
|
||||||
|
--COORDINATE:NewFromVec2(_vec2):SmokeGreen()
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
self:E("Path is nil. No valid path on road could be found.")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Include end point, which might not be on road.
|
||||||
|
if IncludeEndpoints then
|
||||||
|
Path[#Path+1]=ToCoord
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Sum up distances.
|
||||||
|
if #Path>=2 then
|
||||||
|
for i=1,#Path-1 do
|
||||||
|
Way=Way+Path[i+1]:Get2DDistance(Path[i])
|
||||||
end
|
end
|
||||||
--Path[#Path+1]=ToCoord
|
|
||||||
else
|
else
|
||||||
-- There are cases where no path on road can be found.
|
-- There are cases where no path on road can be found.
|
||||||
return nil
|
return nil,nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return Path
|
return Path, Way
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Gets the surface type at the coordinate.
|
--- Gets the surface type at the coordinate.
|
||||||
|
|||||||
@ -148,7 +148,7 @@ do -- TASK_A2G
|
|||||||
local TargetUnit = Task.TargetSetUnit:GetFirst() -- Wrapper.Unit#UNIT
|
local TargetUnit = Task.TargetSetUnit:GetFirst() -- Wrapper.Unit#UNIT
|
||||||
if TargetUnit then
|
if TargetUnit then
|
||||||
local Coordinate = TargetUnit:GetPointVec3()
|
local Coordinate = TargetUnit:GetPointVec3()
|
||||||
self:T( { TargetCoordinate = Coordinate, Coordinate:GetX(), Coordinate:GetAlt(), Coordinate:GetZ() } )
|
self:T( { TargetCoordinate = Coordinate, Coordinate:GetX(), Coordinate:GetY(), Coordinate:GetZ() } )
|
||||||
Task:SetTargetCoordinate( Coordinate, TaskUnit )
|
Task:SetTargetCoordinate( Coordinate, TaskUnit )
|
||||||
end
|
end
|
||||||
self:__RouteToTargetPoint( 0.1 )
|
self:__RouteToTargetPoint( 0.1 )
|
||||||
|
|||||||
@ -1990,8 +1990,9 @@ do -- Route methods
|
|||||||
-- @param Core.Point#COORDINATE ToCoordinate A Coordinate to drive to.
|
-- @param Core.Point#COORDINATE ToCoordinate A Coordinate to drive to.
|
||||||
-- @param #number Speed (Optional) Speed in km/h. The default speed is 20 km/h.
|
-- @param #number Speed (Optional) Speed in km/h. The default speed is 20 km/h.
|
||||||
-- @param #string OffRoadFormation (Optional) The formation at initial and final waypoint. Default is "Off Road".
|
-- @param #string OffRoadFormation (Optional) The formation at initial and final waypoint. Default is "Off Road".
|
||||||
|
-- @param #boolean Shortcut (Optional) If true, controllable will take the direct route if the path on road is 10x longer or path on road is less than 5% of total path.
|
||||||
-- @return Task
|
-- @return Task
|
||||||
function CONTROLLABLE:TaskGroundOnRoad( ToCoordinate, Speed, OffRoadFormation )
|
function CONTROLLABLE:TaskGroundOnRoad( ToCoordinate, Speed, OffRoadFormation, Shortcut )
|
||||||
self:F2({ToCoordinate=ToCoordinate, Speed=Speed, OffRoadFormation=OffRoadFormation})
|
self:F2({ToCoordinate=ToCoordinate, Speed=Speed, OffRoadFormation=OffRoadFormation})
|
||||||
|
|
||||||
-- Defaults.
|
-- Defaults.
|
||||||
@ -2001,26 +2002,65 @@ do -- Route methods
|
|||||||
-- Current coordinate.
|
-- Current coordinate.
|
||||||
local FromCoordinate = self:GetCoordinate()
|
local FromCoordinate = self:GetCoordinate()
|
||||||
|
|
||||||
-- First point on road.
|
-- Get path and path length on road including the end points (From and To).
|
||||||
local FromOnRoad = FromCoordinate:GetClosestPointToRoad()
|
local PathOnRoad, LengthOnRoad=FromCoordinate:GetPathOnRoad(ToCoordinate, true)
|
||||||
|
|
||||||
-- Last Point on road.
|
-- Get the length only(!) on the road.
|
||||||
local ToOnRoad = ToCoordinate:GetClosestPointToRoad()
|
local _,LengthRoad=FromCoordinate:GetPathOnRoad(ToCoordinate, false)
|
||||||
|
|
||||||
|
-- Off road part of the rout: Total=OffRoad+OnRoad.
|
||||||
|
local LengthOffRoad=LengthOnRoad-LengthRoad
|
||||||
|
|
||||||
|
-- Calculate the direct distance between the initial and final points.
|
||||||
|
local LengthDirect=FromCoordinate:Get2DDistance(ToCoordinate)
|
||||||
|
|
||||||
|
-- Debug info.
|
||||||
|
self:T(string.format("Length on road = %.3f km", LengthOnRoad/1000))
|
||||||
|
self:T(string.format("Length directly = %.3f km", LengthDirect/1000))
|
||||||
|
self:T(string.format("Length fraction = %.3f km", LengthOnRoad/LengthDirect))
|
||||||
|
self:T(string.format("Length only road = %.3f km", LengthRoad/1000))
|
||||||
|
self:T(string.format("Length off road = %.3f km", LengthOffRoad/1000))
|
||||||
|
self:T(string.format("Percent on road = %.1f", LengthRoad/LengthOnRoad*100))
|
||||||
|
|
||||||
-- Route, ground waypoints along road.
|
-- Route, ground waypoints along road.
|
||||||
local route={}
|
local route={}
|
||||||
|
|
||||||
|
-- Length on road is 10 times longer than direct route or path on road is very short (<5% of total path).
|
||||||
|
local LongRoad=LengthOnRoad and ((LengthOnRoad > LengthDirect*10) or (LengthRoad/LengthOnRoad*100<5))
|
||||||
|
|
||||||
|
-- Check if a valid path on road could be found.
|
||||||
|
if PathOnRoad then
|
||||||
|
|
||||||
|
-- Check whether the road is very long compared to direct path.
|
||||||
|
if LongRoad and Shortcut then
|
||||||
|
|
||||||
|
-- Road is long ==> we take the short cut.
|
||||||
|
table.insert(route, FromCoordinate:WaypointGround(Speed, OffRoadFormation))
|
||||||
|
table.insert(route, ToCoordinate:WaypointGround(Speed, OffRoadFormation))
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
-- Create waypoints.
|
-- Create waypoints.
|
||||||
table.insert(route, FromCoordinate:WaypointGround(Speed, OffRoadFormation))
|
table.insert(route, FromCoordinate:WaypointGround(Speed, OffRoadFormation))
|
||||||
table.insert(route, FromOnRoad:WaypointGround(Speed, "On Road"))
|
table.insert(route, PathOnRoad[2]:WaypointGround(Speed, "On Road"))
|
||||||
table.insert(route, ToOnRoad:WaypointGround(Speed, "On Road"))
|
table.insert(route, PathOnRoad[#PathOnRoad-1]:WaypointGround(Speed, "On Road"))
|
||||||
|
|
||||||
-- Add the final coordinate because the final might not be on the road.
|
-- Add the final coordinate because the final might not be on the road.
|
||||||
local dist=ToCoordinate:Get2DDistance(ToOnRoad)
|
local dist=ToCoordinate:Get2DDistance(PathOnRoad[#PathOnRoad-1])
|
||||||
if dist>10 then
|
if dist>10 then
|
||||||
table.insert(route, ToCoordinate:WaypointGround(Speed, OffRoadFormation))
|
table.insert(route, ToCoordinate:WaypointGround(Speed, OffRoadFormation))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
-- No path on road could be found (can happen!) ==> Route group directly from A to B.
|
||||||
|
table.insert(route, FromCoordinate:WaypointGround(Speed, OffRoadFormation))
|
||||||
|
table.insert(route, ToCoordinate:WaypointGround(Speed, OffRoadFormation))
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
return route
|
return route
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user