Added GetSpeedMax function

This commit is contained in:
Frank 2018-05-21 21:43:19 +02:00
parent f7403758ce
commit 25e4d171ab
4 changed files with 53 additions and 6 deletions

View File

@ -609,7 +609,7 @@ function AI_CARGO_APC:onafterPickup( APC, From, Event, To, Coordinate )
if Coordinate then
self.RoutePickup = true
local Waypoints = APC:TaskGroundOnRoad( Coordinate, 150, "Line abreast" )
local Waypoints = APC:TaskGroundOnRoad( Coordinate, APC:GetSpeedMax()*0.8, "Line abreast" )
local TaskFunction = APC:TaskFunction( "AI_CARGO_APC._Pickup", self )

View File

@ -1958,17 +1958,17 @@ do -- Route methods
-- Route, ground waypoints along roads.
local route={}
table.insert(route, FromCoordinate:WaypointGround(Speed, Formation))
table.insert(route, FromCoordinate:WaypointGround(Speed, "Off Road"))
-- Convert coordinates to ground waypoints and insert into table.
for _, coord in ipairs(path) do
table.insert(route, coord:WaypointGround(Speed, Formation))
table.insert(route, coord:WaypointGround(Speed, "On Road"))
end
-- Add the final coordinate because the final coordinate in path is last point on road.
local dist=ToCoordinate:Get2DDistance(path[#path])
if dist>10 then
table.insert(route, ToCoordinate:WaypointGround(Speed, "Vee"))
table.insert(route, ToCoordinate:WaypointGround(Speed, "Off Road"))
end
-- Route controllable to destination.
@ -2059,7 +2059,7 @@ do -- Route methods
PointFrom.y = ControllablePoint.y
PointFrom.type = "Turning Point"
PointFrom.action = Formation or "Cone"
PointFrom.speed = 20 / 1.6
PointFrom.speed = 20 / 3.6
local PointTo = {}
@ -2084,7 +2084,7 @@ do -- Route methods
if Speed then
PointTo.speed = Speed
else
PointTo.speed = 20 / 1.6
PointTo.speed = 20 / 3.6
end
local Points = { PointFrom, PointTo }

View File

@ -350,6 +350,36 @@ function GROUP:GetCountry()
return nil
end
--- Returns the maximum speed of the group.
-- If the group is heterogenious and consists of different units, the max speed of the slowest unit is returned.
-- @param #GROUP self
-- @return #number Speed in km/h.
function GROUP:GetSpeedMax()
self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject()
if DCSGroup then
local Units=self:GetUnits()
local speedmax=nil
for _,unit in pairs(Units) do
local unit=unit --Wrapper.Unit#UNIT
local speed=unit:GetSpeedMax()
if speedmax==nil then
speedmax=speed
elseif speed<speedmax then
speedmax=speed
end
end
return speedmax
end
return nil
end
--- Returns a list of @{Unit} objects of the @{Group}.
-- @param #GROUP self
-- @return #list<Wrapper.Unit#UNIT> The list of @{Unit} objects of the @{Group}.

View File

@ -401,6 +401,23 @@ function UNIT:GetNumber()
return nil
end
--- Returns the unit's max speed in km/h derived from the DCS descriptors.
-- @param #UNIT self
-- @return #number Speed in km/h.
function UNIT:GetSpeedMax()
self:F2( self.UnitName )
local Desc = self:GetDesc()
if Desc then
local SpeedMax = Desc.speedMax
return SpeedMax*3.6
end
return nil
end
--- Returns the unit's group if it exist and nil otherwise.
-- @param Wrapper.Unit#UNIT self
-- @return Wrapper.Group#GROUP The Group of the Unit.