Warehouse 0.1.9

Many bugs spotted
This commit is contained in:
funkyfranky 2018-08-16 23:10:23 +02:00
parent 22da329fca
commit 5a2e1f01b4
4 changed files with 112 additions and 100 deletions

View File

@ -2116,7 +2116,7 @@ function RAT:_SpawnWithRoute(_departure, _destination, _takeoff, _landing, _live
end end
-- Modify the spawn template to follow the flight plan. -- Modify the spawn template to follow the flight plan.
local successful=self:_ModifySpawnTemplate(waypoints, livery, _lastpos, departure, takeoff) local successful=self:_ModifySpawnTemplate(waypoints, livery, _lastpos, departure, takeoff, parkingdata)
if not successful then if not successful then
return nil return nil
end end

View File

@ -191,7 +191,7 @@ WAREHOUSE.TransportType = {
--- Warehouse class version. --- Warehouse class version.
-- @field #string version -- @field #string version
WAREHOUSE.version="0.1.8w" WAREHOUSE.version="0.1.9"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO: Warehouse todo list. -- TODO: Warehouse todo list.
@ -1118,7 +1118,7 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
CargoTransport = AI_CARGO_DISPATCHER_HELICOPTER:New(TransportSet, CargoGroups, DeployZoneSet) CargoTransport = AI_CARGO_DISPATCHER_HELICOPTER:New(TransportSet, CargoGroups, DeployZoneSet)
-- Home zone. -- Home zone.
CargoTransport:Setairbase(self.airbase) --CargoTransport:Setairbase(self.airbase)
--CargoTransport:SetHomeZone(self.spawnzone) --CargoTransport:SetHomeZone(self.spawnzone)
elseif Request.transporttype==WAREHOUSE.TransportType.APC then elseif Request.transporttype==WAREHOUSE.TransportType.APC then
@ -1563,17 +1563,21 @@ end
function WAREHOUSE:_RouteAirRat(Aircraft, ToAirbase, Speed) function WAREHOUSE:_RouteAirRat(Aircraft, ToAirbase, Speed)
if Aircraft and Aircraft:IsAlive()~=nil then if Aircraft and Aircraft:IsAlive()~=nil then
-- Get parking data of all units. -- Get parking data of all units.
local parkingdata={} local parkingdata={}
local units=Aircraft:GetUnits() local units=Aircraft:GetUnits()
for _,_unit in pairs(units) do for _,_unit in pairs(units) do
local unit=_unit --Wrapper.Unit#UNIT local unit=_unit --Wrapper.Unit#UNIT
local _spot,_terminal,_distance=unit:GetCoordinate():GetClosestOccupiedParkingSpot(self.airbase) local _spot,_terminal,_distance=unit:GetCoordinate():GetClosestOccupiedParkingSpot(self.airbase)
table.insert(parkingdata, {spot=_spot, TerminalID=_terminal}) table.insert(parkingdata, {Coordinate=_spot, TerminalID=_terminal})
end end
env.info("FF parking data")
self:E(parkingdata)
-- Create a RAT object to use its flight plan. -- Create a RAT object to use its flight plan.
local rat=RAT:New(Aircraft) local rat=RAT:New(Aircraft:GetName())
-- Init some parameters. -- Init some parameters.
rat:SetDeparture(self.airbase:GetName()) rat:SetDeparture(self.airbase:GetName())
@ -1590,12 +1594,16 @@ function WAREHOUSE:_RouteAirRat(Aircraft, ToAirbase, Speed)
Aircraft:Destroy() Aircraft:Destroy()
-- Spawn RAT aircraft at specific parking sports. -- Spawn RAT aircraft at specific parking sports.
local spawnindex=rat:_SpawnWithRoute(self.airbase:GetName(), ToAirbase:GetName(), RAT.wp.cold, nil, nil, nil, nil, nil, parkingdata) local spawnindex=rat:_SpawnWithRoute(self.airbase:GetName(), ToAirbase:GetName(), RAT.wp.hot, nil, nil, nil, nil, nil, parkingdata)
-- Get the group and check it's name. -- Get the group and check it's name.
local group=rat.ratcraft[spawnindex].group --Wrapper.Group#GROUP local group=rat.ratcraft[spawnindex].group --Wrapper.Group#GROUP
self:E(self.wid..string.format("Spawned new RAT aircraft as group %s", group:GetName())) self:E(self.wid..string.format("Spawned new RAT aircraft as group %s", group:GetName()))
group:SmokeBlue()
-- Activate group.
local bla=group:SetCommand({id='Start', params={}})
self:E({bla=bla})
return group return group
end end

View File

@ -680,99 +680,101 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius,
local _spot=parkingspot.Coordinate -- Core.Point#COORDINATE local _spot=parkingspot.Coordinate -- Core.Point#COORDINATE
local _termid=parkingspot.TerminalID 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 AIRBASE._CheckTerminalType(parkingspot.TerminalType, terminaltype) then
if verysafe and (parkingspot.Free==false or parkingspot.TOAC==true) then
-- DCS getParking() routine returned that spot is not free. -- 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.
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))) if verysafe and (parkingspot.Free==false or parkingspot.TOAC==true) then
else -- DCS getParking() routine returned that spot is not free.
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)))
-- Scan a radius of 50 meters around the spot.
local _,_,_,_units,_statics,_sceneries=_spot:ScanObjects(scanradius, scanunits, scanstatics, scanscenery)
-- Loop over objects within scan radius.
local occupied=false
-- Check all units.
for _,unit in pairs(_units) do
local _vec3=unit:getPoint()
local _coord=COORDINATE:NewFromVec3(_vec3)
local _dist=_coord:Get2DDistance(_spot)
local _safe=_overlap(aircraft, true, unit, false,_dist)
if markobstacles then
local l,x,y,z=_GetObjectSize(unit)
_coord:MarkToAll(string.format("Unit %s\nx=%.1f y=%.1f z=%.1f\nl=%.1f d=%.1f\nspot %d safe=%s", unit:getName(),x,y,z,l,_dist, _termid, tostring(_safe)))
end
if scanunits and not _safe then
occupied=true
end
end
-- Check all statics.
for _,static in pairs(_statics) do
local _vec3=static:getPoint()
local _coord=COORDINATE:NewFromVec3(_vec3)
local _dist=_coord:Get2DDistance(_spot)
local _safe=_overlap(aircraft, true, static, false,_dist)
if markobstacles then
local l,x,y,z=_GetObjectSize(static)
_coord:MarkToAll(string.format("Static %s\nx=%.1f y=%.1f z=%.1f\nl=%.1f d=%.1f\nspot %d safe=%s", static:getName(),x,y,z,l,_dist, _termid, tostring(_safe)))
end
if scanstatics and not _safe then
occupied=true
end
end
-- Check all scenery.
for _,scenery in pairs(_sceneries) do
local _vec3=scenery:getPoint()
local _coord=COORDINATE:NewFromVec3(_vec3)
local _dist=_coord:Get2DDistance(_spot)
local _safe=_overlap(aircraft, true, scenery, false,_dist)
if markobstacles then
local l,x,y,z=_GetObjectSize(scenery)
_coord:MarkToAll(string.format("Scenery %s\nx=%.1f y=%.1f z=%.1f\nl=%.1f d=%.1f\nspot %d safe=%s", scenery:getTypeName(),x,y,z,l,_dist, _termid, tostring(_safe)))
end
if scanscenery and not _safe then
occupied=true
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))
else else
self:E(string.format("%s: Parking spot id %d free.", airport, _termid))
if nvalid<_nspots then -- Scan a radius of 50 meters around the spot.
table.insert(validspots, {Coordinate=_spot, TerminalID=_termid}) local _,_,_,_units,_statics,_sceneries=_spot:ScanObjects(scanradius, scanunits, scanstatics, scanscenery)
-- Loop over objects within scan radius.
local occupied=false
-- Check all units.
for _,unit in pairs(_units) do
local _vec3=unit:getPoint()
local _coord=COORDINATE:NewFromVec3(_vec3)
local _dist=_coord:Get2DDistance(_spot)
local _safe=_overlap(aircraft, true, unit, false,_dist)
if markobstacles then
local l,x,y,z=_GetObjectSize(unit)
_coord:MarkToAll(string.format("Unit %s\nx=%.1f y=%.1f z=%.1f\nl=%.1f d=%.1f\nspot %d safe=%s", unit:getName(),x,y,z,l,_dist, _termid, tostring(_safe)))
end
if scanunits and not _safe then
occupied=true
end
end end
nvalid=nvalid+1
-- Check all statics.
for _,static in pairs(_statics) do
local _vec3=static:getPoint()
local _coord=COORDINATE:NewFromVec3(_vec3)
local _dist=_coord:Get2DDistance(_spot)
local _safe=_overlap(aircraft, true, static, false,_dist)
if markobstacles then
local l,x,y,z=_GetObjectSize(static)
_coord:MarkToAll(string.format("Static %s\nx=%.1f y=%.1f z=%.1f\nl=%.1f d=%.1f\nspot %d safe=%s", static:getName(),x,y,z,l,_dist, _termid, tostring(_safe)))
end
if scanstatics and not _safe then
occupied=true
end
end
-- Check all scenery.
for _,scenery in pairs(_sceneries) do
local _vec3=scenery:getPoint()
local _coord=COORDINATE:NewFromVec3(_vec3)
local _dist=_coord:Get2DDistance(_spot)
local _safe=_overlap(aircraft, true, scenery, false,_dist)
if markobstacles then
local l,x,y,z=_GetObjectSize(scenery)
_coord:MarkToAll(string.format("Scenery %s\nx=%.1f y=%.1f z=%.1f\nl=%.1f d=%.1f\nspot %d safe=%s", scenery:getTypeName(),x,y,z,l,_dist, _termid, tostring(_safe)))
end
if scanscenery and not _safe then
occupied=true
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))
else
self:E(string.format("%s: Parking spot id %d free.", airport, _termid))
if nvalid<_nspots then
table.insert(validspots, {Coordinate=_spot, TerminalID=_termid})
end
nvalid=nvalid+1
end
end -- loop over units
-- We found enough spots.
if nvalid>=_nspots then
return validspots
end end
end -- check terminal type
end -- loop over units
-- We found enough spots.
if nvalid>=_nspots then
return validspots
end
end end
-- Retrun spots we found, even if there were not enough. -- Retrun spots we found, even if there were not enough.

View File

@ -119,10 +119,12 @@ end
-- @param DCS#Unit DCSUnit An existing DCS Unit object reference. -- @param DCS#Unit DCSUnit An existing DCS Unit object reference.
-- @return #UNIT self -- @return #UNIT self
function UNIT:Find( DCSUnit ) function UNIT:Find( DCSUnit )
if DCSUnit then
local UnitName = DCSUnit:getName() local UnitName = DCSUnit:getName()
local UnitFound = _DATABASE:FindUnit( UnitName ) local UnitFound = _DATABASE:FindUnit( UnitName )
return UnitFound return UnitFound
end
return nil
end end
--- Find a UNIT in the _DATABASE using the name of an existing DCS Unit. --- Find a UNIT in the _DATABASE using the name of an existing DCS Unit.