Warehouse 0.1.4

zone: fixed GetRandomCoordinate inner, outer missing
controllable: fixed path cannot be found
group: added getrange
unit: added getrange
This commit is contained in:
funkyfranky 2018-08-13 00:36:34 +02:00
parent 195459d6d8
commit d91166c3c4
8 changed files with 782 additions and 331 deletions

View File

@ -295,7 +295,8 @@ end
--- Sends a MESSAGE to a Coalition if the given Condition is true. --- Sends a MESSAGE to a Coalition if the given Condition is true.
-- @param #MESSAGE self -- @param #MESSAGE self
-- @param CoalitionSide needs to be filled out by the defined structure of the standard scripting engine @{coalition.side}. -- @param CoalitionSide needs to be filled out by the defined structure of the standard scripting engine @{coalition.side}.
-- @return #MESSAGE -- @param #boolean Condition Sends the message only if the condition is true.
-- @return #MESSAGE self
function MESSAGE:ToCoalitionIf( CoalitionSide, Condition ) function MESSAGE:ToCoalitionIf( CoalitionSide, Condition )
self:F( CoalitionSide ) self:F( CoalitionSide )

View File

@ -1098,11 +1098,14 @@ do -- COORDINATE
--- Gets the nearest airbase with respect to the current coordinates. --- Gets the nearest airbase with respect to the current coordinates.
-- @param #COORDINATE self -- @param #COORDINATE self
-- @param #number AirbaseCategory Category of the airbase. -- @param #number Category (Optional) Category of the airbase. Enumerator of @{Wrapper.Airbase#AIRBASE.Category}.
-- @param #number Coalition (Optional) Coalition of the airbase.
-- @return Wrapper.Airbase#AIRBASE Closest Airbase to the given coordinate. -- @return Wrapper.Airbase#AIRBASE Closest Airbase to the given coordinate.
-- @return #number Distance to the closest airbase in meters. -- @return #number Distance to the closest airbase in meters.
function COORDINATE:GetClosestAirbase(AirbaseCategory) function COORDINATE:GetClosestAirbase(Category, Coalition)
local airbases=AIRBASE.GetAllAirbases()
-- Get all airbases of the map.
local airbases=AIRBASE.GetAllAirbases(Coalition)
local closest=nil local closest=nil
local distmin=nil local distmin=nil
@ -1110,7 +1113,7 @@ do -- COORDINATE
for _,_airbase in pairs(airbases) do for _,_airbase in pairs(airbases) do
local airbase=_airbase --Wrapper.Airbase#AIRBASE local airbase=_airbase --Wrapper.Airbase#AIRBASE
local category=airbase:GetDesc().category local category=airbase:GetDesc().category
if AirbaseCategory and AirbaseCategory==category or AirbaseCategory==nil then if Category and Category==category or Category==nil then
local dist=self:Get2DDistance(airbase:GetCoordinate()) local dist=self:Get2DDistance(airbase:GetCoordinate())
if closest==nil then if closest==nil then
distmin=dist distmin=dist
@ -1257,6 +1260,8 @@ do -- COORDINATE
Path[#Path+1]=COORDINATE:NewFromVec2(_vec2) Path[#Path+1]=COORDINATE:NewFromVec2(_vec2)
--COORDINATE:NewFromVec2(_vec2):SmokeGreen() --COORDINATE:NewFromVec2(_vec2):SmokeGreen()
end end
--COORDINATE:NewFromVec2(path[1]):SmokeBlue()
--COORDINATE:NewFromVec2(path[#path]):SmokeBlue()
else else
self:E("Path is nil. No valid path on road could be found.") self:E("Path is nil. No valid path on road could be found.")

View File

@ -496,7 +496,7 @@ end
--- Sets the coalition of the spawned group. Note that it might be necessary to also set the country explicitly! --- Sets the coalition of the spawned group. Note that it might be necessary to also set the country explicitly!
-- @param #SPAWN self -- @param #SPAWN self
-- @param #DCS.coalition Coaliton Coaliton of the group as number of enumerator, i.e. 0=coaliton.side.NEUTRAL, 1=coaliton.side.RED, 2=coalition.side.BLUE. -- @param DCS#coalition.side Coalition Coalition of the group as number of enumerator, i.e. 0=coaliton.side.NEUTRAL, 1=coaliton.side.RED, 2=coalition.side.BLUE.
-- @return #SPAWN self -- @return #SPAWN self
function SPAWN:InitCoalition( Coalition ) function SPAWN:InitCoalition( Coalition )
self:F({coalition=Coalition}) self:F({coalition=Coalition})

View File

@ -933,7 +933,7 @@ end
function ZONE_RADIUS:GetRandomCoordinate( inner, outer ) function ZONE_RADIUS:GetRandomCoordinate( inner, outer )
self:F( self.ZoneName, inner, outer ) self:F( self.ZoneName, inner, outer )
local Coordinate = COORDINATE:NewFromVec2( self:GetRandomVec2() ) local Coordinate = COORDINATE:NewFromVec2( self:GetRandomVec2(inner, outer) )
self:T3( { Coordinate = Coordinate } ) self:T3( { Coordinate = Coordinate } )

File diff suppressed because it is too large Load Diff

View File

@ -2026,7 +2026,8 @@ do -- Route methods
-- @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. -- @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 DCS#Task Task.
-- @return #boolean If true, path on road is possible. If false, task will route the group directly to its destination.
function CONTROLLABLE:TaskGroundOnRoad( ToCoordinate, Speed, OffRoadFormation, Shortcut ) function CONTROLLABLE:TaskGroundOnRoad( ToCoordinate, Speed, OffRoadFormation, Shortcut )
self:F2({ToCoordinate=ToCoordinate, Speed=Speed, OffRoadFormation=OffRoadFormation}) self:F2({ToCoordinate=ToCoordinate, Speed=Speed, OffRoadFormation=OffRoadFormation})
@ -2044,11 +2045,20 @@ do -- Route methods
local _,LengthRoad=FromCoordinate:GetPathOnRoad(ToCoordinate, false) local _,LengthRoad=FromCoordinate:GetPathOnRoad(ToCoordinate, false)
-- Off road part of the rout: Total=OffRoad+OnRoad. -- Off road part of the rout: Total=OffRoad+OnRoad.
local LengthOffRoad=LengthOnRoad-LengthRoad local LengthOffRoad
local LongRoad
-- Calculate the direct distance between the initial and final points. -- Calculate the direct distance between the initial and final points.
local LengthDirect=FromCoordinate:Get2DDistance(ToCoordinate) local LengthDirect=FromCoordinate:Get2DDistance(ToCoordinate)
if PathOnRoad then
-- Off road part of the rout: Total=OffRoad+OnRoad.
LengthOffRoad=LengthOnRoad-LengthRoad
-- Length on road is 10 times longer than direct route or path on road is very short (<5% of total path).
LongRoad=LengthOnRoad and ((LengthOnRoad > LengthDirect*10) or (LengthRoad/LengthOnRoad*100<5))
-- Debug info. -- Debug info.
self:T(string.format("Length on road = %.3f km", LengthOnRoad/1000)) 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 directly = %.3f km", LengthDirect/1000))
@ -2057,15 +2067,14 @@ do -- Route methods
self:T(string.format("Length off road = %.3f km", LengthOffRoad/1000)) self:T(string.format("Length off road = %.3f km", LengthOffRoad/1000))
self:T(string.format("Percent on road = %.1f", LengthRoad/LengthOnRoad*100)) self:T(string.format("Percent on road = %.1f", LengthRoad/LengthOnRoad*100))
end
-- Route, ground waypoints along road. -- Route, ground waypoints along road.
local route={} local route={}
local canroad=false
-- 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. -- Check if a valid path on road could be found.
if PathOnRoad then if PathOnRoad then
-- Check whether the road is very long compared to direct path. -- Check whether the road is very long compared to direct path.
if LongRoad and Shortcut then if LongRoad and Shortcut then
@ -2088,6 +2097,7 @@ do -- Route methods
end end
canroad=true
else else
-- No path on road could be found (can happen!) ==> Route group directly from A to B. -- No path on road could be found (can happen!) ==> Route group directly from A to B.
@ -2096,7 +2106,7 @@ do -- Route methods
end end
return route return route, canroad
end end
--- Make a task for a TRAIN Controllable to drive towards a specific point using railroad. --- Make a task for a TRAIN Controllable to drive towards a specific point using railroad.

View File

@ -413,6 +413,38 @@ function GROUP:GetSpeedMax()
return nil return nil
end end
--- Returns the maximum range of the group.
-- If the group is heterogenious and consists of different units, the smallest range of all units is returned.
-- @param #GROUP self
-- @return #number Range in meters.
function GROUP:GetRange()
self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject()
if DCSGroup then
local Units=self:GetUnits()
local Rangemin=nil
for _,unit in pairs(Units) do
local unit=unit --Wrapper.Unit#UNIT
local range=unit:GetRange()
if range then
if Rangemin==nil then
Rangemin=range
elseif range<Rangemin then
Rangemin=range
end
end
end
return Rangemin
end
return nil
end
--- Returns a list of @{Wrapper.Unit} objects of the @{Wrapper.Group}. --- Returns a list of @{Wrapper.Unit} objects of the @{Wrapper.Group}.
-- @param #GROUP self -- @param #GROUP self

View File

@ -416,6 +416,28 @@ function UNIT:GetSpeedMax()
return nil return nil
end end
--- Returns the unit's max range in meters derived from the DCS descriptors.
-- For ground units it will return a range of 10,000 km as they have no real range.
-- @param #UNIT self
-- @return #number Range in meters.
function UNIT:GetRange()
self:F2( self.UnitName )
local Desc = self:GetDesc()
if Desc then
local Range = Desc.range --This is in nautical miles for some reason.
if Range then
Range=UTILS.NMToMeters(Range)
else
Range=10000000 --10.000 km if no range
end
return Range
end
return nil
end
--- Returns the unit's group if it exist and nil otherwise. --- Returns the unit's group if it exist and nil otherwise.
-- @param Wrapper.Unit#UNIT self -- @param Wrapper.Unit#UNIT self
-- @return Wrapper.Group#GROUP The Group of the Unit. -- @return Wrapper.Group#GROUP The Group of the Unit.