mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Warehouse 0.1.9
Many bugs spotted
This commit is contained in:
parent
22da329fca
commit
5a2e1f01b4
@ -2116,7 +2116,7 @@ function RAT:_SpawnWithRoute(_departure, _destination, _takeoff, _landing, _live
|
||||
end
|
||||
|
||||
-- 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
|
||||
return nil
|
||||
end
|
||||
|
||||
@ -191,7 +191,7 @@ WAREHOUSE.TransportType = {
|
||||
|
||||
--- Warehouse class version.
|
||||
-- @field #string version
|
||||
WAREHOUSE.version="0.1.8w"
|
||||
WAREHOUSE.version="0.1.9"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO: Warehouse todo list.
|
||||
@ -1118,7 +1118,7 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request)
|
||||
CargoTransport = AI_CARGO_DISPATCHER_HELICOPTER:New(TransportSet, CargoGroups, DeployZoneSet)
|
||||
|
||||
-- Home zone.
|
||||
CargoTransport:Setairbase(self.airbase)
|
||||
--CargoTransport:Setairbase(self.airbase)
|
||||
--CargoTransport:SetHomeZone(self.spawnzone)
|
||||
|
||||
elseif Request.transporttype==WAREHOUSE.TransportType.APC then
|
||||
@ -1563,24 +1563,28 @@ end
|
||||
function WAREHOUSE:_RouteAirRat(Aircraft, ToAirbase, Speed)
|
||||
|
||||
if Aircraft and Aircraft:IsAlive()~=nil then
|
||||
|
||||
-- Get parking data of all units.
|
||||
local parkingdata={}
|
||||
|
||||
local units=Aircraft:GetUnits()
|
||||
for _,_unit in pairs(units) do
|
||||
local unit=_unit --Wrapper.Unit#UNIT
|
||||
local _spot,_terminal,_distance=unit:GetCoordinate():GetClosestOccupiedParkingSpot(self.airbase)
|
||||
table.insert(parkingdata, {spot=_spot, TerminalID=_terminal})
|
||||
table.insert(parkingdata, {Coordinate=_spot, TerminalID=_terminal})
|
||||
end
|
||||
env.info("FF parking data")
|
||||
self:E(parkingdata)
|
||||
|
||||
-- Create a RAT object to use its flight plan.
|
||||
local rat=RAT:New(Aircraft)
|
||||
local rat=RAT:New(Aircraft:GetName())
|
||||
|
||||
-- Init some parameters.
|
||||
rat:SetDeparture(self.airbase:GetName())
|
||||
rat:SetDestination(ToAirbase:GetName())
|
||||
--rat:SetCoalitionAircraft(color)
|
||||
rat:SetCountry(self.country)
|
||||
rat:NoRespawn()
|
||||
rat:SetCountry(self.country)
|
||||
rat:NoRespawn()
|
||||
|
||||
-- Init spawn but do not actually spawn.
|
||||
rat:Spawn(0)
|
||||
@ -1590,12 +1594,16 @@ function WAREHOUSE:_RouteAirRat(Aircraft, ToAirbase, Speed)
|
||||
Aircraft:Destroy()
|
||||
|
||||
-- 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.
|
||||
local group=rat.ratcraft[spawnindex].group --Wrapper.Group#GROUP
|
||||
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
|
||||
end
|
||||
|
||||
|
||||
@ -680,99 +680,101 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius,
|
||||
local _spot=parkingspot.Coordinate -- Core.Point#COORDINATE
|
||||
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 or parkingspot.TOAC==true) then
|
||||
|
||||
-- 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)))
|
||||
|
||||
else
|
||||
if AIRBASE._CheckTerminalType(parkingspot.TerminalType, terminaltype) then
|
||||
|
||||
-- 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 or parkingspot.TOAC==true) then
|
||||
|
||||
-- Scan a radius of 50 meters around the spot.
|
||||
local _,_,_,_units,_statics,_sceneries=_spot:ScanObjects(scanradius, scanunits, scanstatics, scanscenery)
|
||||
-- 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)))
|
||||
|
||||
-- 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
|
||||
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
|
||||
|
||||
-- Scan a radius of 50 meters around the spot.
|
||||
local _,_,_,_units,_statics,_sceneries=_spot:ScanObjects(scanradius, scanunits, scanstatics, scanscenery)
|
||||
|
||||
end -- loop over units
|
||||
|
||||
-- We found enough spots.
|
||||
if nvalid>=_nspots then
|
||||
return validspots
|
||||
end
|
||||
-- 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
|
||||
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 -- check terminal type
|
||||
end
|
||||
|
||||
-- Retrun spots we found, even if there were not enough.
|
||||
|
||||
@ -119,10 +119,12 @@ end
|
||||
-- @param DCS#Unit DCSUnit An existing DCS Unit object reference.
|
||||
-- @return #UNIT self
|
||||
function UNIT:Find( DCSUnit )
|
||||
|
||||
local UnitName = DCSUnit:getName()
|
||||
local UnitFound = _DATABASE:FindUnit( UnitName )
|
||||
return UnitFound
|
||||
if DCSUnit then
|
||||
local UnitName = DCSUnit:getName()
|
||||
local UnitFound = _DATABASE:FindUnit( UnitName )
|
||||
return UnitFound
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Find a UNIT in the _DATABASE using the name of an existing DCS Unit.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user