diff --git a/Moose Development/Moose/Functional/RAT2.lua b/Moose Development/Moose/Functional/RAT2.lua index ebc243efa..d22941de7 100644 --- a/Moose Development/Moose/Functional/RAT2.lua +++ b/Moose Development/Moose/Functional/RAT2.lua @@ -133,7 +133,7 @@ function RAT2:_CheckQueueSpawn() if flight:IsInUtero() or flight:IsArrived() or flight:IsDead() then - self:I(string.format("Spawning new flight group %s in status %s", flight.groupname, flight:GetState())) + self:I(string.format("Try Spawning new flight group %s in status %s", flight.groupname, flight:GetState())) -- Get departure and parking. local departure, parking=ratcraft:GetDeparture() @@ -141,9 +141,9 @@ function RAT2:_CheckQueueSpawn() -- Get destination depending on departure. local destination=ratcraft:GetDestination(departure) - if departure and destination then + if departure and destination and parking then - parking=departure.parking or parking + self:I(string.format("Spawning new flight group %s in status %s", flight.groupname, flight:GetState())) -- Try to spawn a ratcraft group. local group=self:_SpawnRatcraft(ratcraft, flight, departure, destination, parking) @@ -836,7 +836,7 @@ function RAT2:_GetFlightplan(ratcraft, departure, destination) -- Mark points at waypoints for debugging. - if self.Debug then + if self.Debug or true then for i,coord in pairs(c) do local coord=coord --Core.Point#COORDINATE local dist=0 diff --git a/Moose Development/Moose/Functional/Range.lua b/Moose Development/Moose/Functional/Range.lua index f8c81f0b2..59e22f608 100644 --- a/Moose Development/Moose/Functional/Range.lua +++ b/Moose Development/Moose/Functional/Range.lua @@ -1341,9 +1341,9 @@ function RANGE:AddBombingTargetUnit(unit, goodhitrange, randommove) -- Debug or error output. if _isstatic==true then - self:T(self.id..string.format("Adding STATIC bombing target %s with good hit range %d. Random move = %s.", name, goodhitrange, tostring(randommove))) + self:I(self.id..string.format("Adding STATIC bombing target %s with good hit range %d. Random move = %s.", name, goodhitrange, tostring(randommove))) elseif _isstatic==false then - self:T(self.id..string.format("Adding UNIT bombing target %s with good hit range %d. Random move = %s.", name, goodhitrange, tostring(randommove))) + self:I(self.id..string.format("Adding UNIT bombing target %s with good hit range %d. Random move = %s.", name, goodhitrange, tostring(randommove))) else self:E(self.id..string.format("ERROR! No bombing target with name %s could be found. Carefully check all UNIT and STATIC names defined in the mission editor!", name)) end diff --git a/Moose Development/Moose/Functional/RatCraft.lua b/Moose Development/Moose/Functional/RatCraft.lua index 2f7d57bd8..bdef075dd 100644 --- a/Moose Development/Moose/Functional/RatCraft.lua +++ b/Moose Development/Moose/Functional/RatCraft.lua @@ -50,6 +50,7 @@ -- @field #string landing Landing type. -- @field #table flights Table of flight groups. -- @field #number Nspawn Number of max spawned aircraft groups. +-- @field #number Nunits Number of units in group. -- @extends Core.Fsm#FSM RATCRAFT = { ClassName = "RATCRAFT", @@ -83,6 +84,7 @@ RATCRAFT = { landing = nil, flights = {}, Nspawn = 2, + Nunits = nil, } --- Generalized asset attributes. Can be used to request assets with certain general characteristics. See [DCS attributes](https://wiki.hoggitworld.com/view/DCS_enum_attributes) on hoggit. @@ -191,6 +193,9 @@ function RATCRAFT:_Init(groupname) self.country=self.templategroup:GetUnit(1):GetCountry() self.category=self.templategroup:GetUnit(1):GetCategory() + + + self.Nunits=#self.templategroup:GetUnits() -- aircraft dimensions self.sizex=self.DCSdesc.box.max.x @@ -225,6 +230,7 @@ function RATCRAFT:AddDepartureAirbase(airbasename, parking) for _,TerminalID in pairs(parking) do local spot=airbase:GetParkingSpotData(TerminalID) if spot then + self:I(string.format("Add in parking spot %d", spot.TerminalID)) table.insert(spots, spot) end end @@ -232,7 +238,7 @@ function RATCRAFT:AddDepartureAirbase(airbasename, parking) departure.name=airbasename departure.type=RATCRAFT.DeType.AIRBASE - departure.parking=parking + departure.parking=spots table.insert(self.departures, departure) return self @@ -353,10 +359,12 @@ function RATCRAFT:GetDeparture() local group=self.templategroup --Wrapper.Group#GROUP -- Get number of free parking spots. - local parking=airbase:FindFreeParkingSpotForAircraft(group) + --local parking=airbase:FindFreeParkingSpotForAircraft(group) + local parking=self:GetParkingDeparture(departure) + -- Check if parking is sufficient. - if #parking>=#group:GetUnits() then + if parking and #parking>=self.Nunits then self:I(string.format("Returning departure %s", departure.name)) return departure, parking @@ -386,6 +394,84 @@ function RATCRAFT:GetDeparture() end +--- Get parking at departure. +-- @param #RATCRAFT self +-- @param #RATCRAFT.Departure departure The chosen departure. +-- @return #table Parking data table or nil if not enough spots. +function RATCRAFT:GetParkingDeparture(departure) + + if departure.type==RATCRAFT.DeType.AIRBASE then + + local airbase=AIRBASE:FindByName(departure.name) + + if airbase then + + local parkingdata=airbase:GetParkingSpotsTable() + + if departure.parking then + --- + -- User specified parking spots + --- + + -- Check if free? + local parking={} + for _,_spot in pairs(parkingdata) do + local spot=_spot --Wrapper.Airbase#AIRBASE.ParkingSpot + self:I(string.format("Checking spot %d", spot.TerminalID)) + -- Check if spot if free? + if spot.Free then + + self:I(string.format("Spot %d is FREE", spot.TerminalID)) + -- Check if spot is in user table? + for _,_park in pairs(departure.parking) do + local park=_park --Wrapper.Airbase#AIRBASE.ParkingSpot + + if park.TerminalID==spot.TerminalID then + self:I(string.format("Adding spot %d to parking", spot.TerminalID)) + table.insert(parking, spot) + end + + end + + end + end + + -- Only return data if sufficient spots available. + if #parking>=self.Nunits then + self:I(string.format("Found valid parking for %d spots", #parking)) + return parking + end + + else + --- + -- Choose parking from what is free + --- + + local parking={} + for _,_spot in pairs(parkingdata) do + local spot=_spot --Wrapper.Airbase#AIRBASE.ParkingSpot + + if spot.Free then + table.insert(parking, spot) + end + + if #parking>=self.Nunits then + return parking + end + + end + end + + + end + + end + + self:I(string.format("Could not find valid parking data")) + return nil +end + + --- Get destination. -- @param #RATCRAFT self -- @param #RATCRAFT.Departure departure The chosen departure. diff --git a/Moose Development/Moose/Ops/FlightGroup.lua b/Moose Development/Moose/Ops/FlightGroup.lua index c3d13f97b..8cb062ff7 100644 --- a/Moose Development/Moose/Ops/FlightGroup.lua +++ b/Moose Development/Moose/Ops/FlightGroup.lua @@ -2297,6 +2297,10 @@ end -- @return #FLIGHTGROUP self function FLIGHTGROUP:_UpdateRoute(n) + if true then + --return + end + -- TODO: what happens if currentwp=#waypoints n=n or self.currentwp+1 @@ -2314,7 +2318,8 @@ function FLIGHTGROUP:_UpdateRoute(n) else if self:IsTaxiing() or self:IsParking() or self:IsSpawned() then local coord=self.group:GetCoordinate() - local current=coord:WaypointAirTakeOffParking(nil, 50) + --local current=coord:WaypointAirTakeOffParking(nil, 50) + local current=coord:WaypointAir( AltType, COORDINATE.WaypointType.TakeOffParkingHot, COORDINATE.WaypointAction.FromParkingAreaHot, 50, true, coord:GetClosestAirbase(), {}, "Takeoff") table.insert(wp, current) end end @@ -2374,7 +2379,7 @@ function FLIGHTGROUP:_UpdateRoute(n) if airbase then -- Route flight to destination/home. - self:RTB(airbase) + --self:RTB(airbase) else -- Let flight orbit. --self:Orbit(self.group:GetCoordinate(), UTILS.FeetToMeters(20000), self.group:GetSpeedMax()*0.4) @@ -2410,7 +2415,7 @@ function FLIGHTGROUP:_UpdateWaypointTasks() if #tasks>0 then for _,task in pairs(tasks) do - local Task=task --#FLIGHTGROUP.Task + local Task=task --#FLIGHTGROUP.Task -- Add task execute. table.insert(taskswp, self.group:TaskFunction("FLIGHTGROUP._TaskExecute", self, Task)) diff --git a/Moose Development/Moose/Wrapper/Airbase.lua b/Moose Development/Moose/Wrapper/Airbase.lua index a307bf794..ed2e27130 100644 --- a/Moose Development/Moose/Wrapper/Airbase.lua +++ b/Moose Development/Moose/Wrapper/Airbase.lua @@ -654,6 +654,7 @@ end -- @param #AIRBASE self -- @param #AIRBASE.TerminalType termtype Terminal type for which marks should be placed. -- @param #boolean mark If false, do not place markers but only give output to DCS.log file. Default true. +-- @return #table Table with marker IDs. function AIRBASE:MarkParkingSpots(termtype, mark) -- Default is true. @@ -668,6 +669,8 @@ function AIRBASE:MarkParkingSpots(termtype, mark) local airbasename=self:GetName() self:E(string.format("Parking spots at %s for termial type %s:", airbasename, tostring(termtype))) + self.parkingmarks=self.parkingmarks or {} + for _,_spot in pairs(parkingdata) do -- Mark text. @@ -676,16 +679,34 @@ function AIRBASE:MarkParkingSpots(termtype, mark) -- Create mark on the F10 map. if mark then - _spot.Coordinate:MarkToAll(_text) + local mid=_spot.Coordinate:MarkToAll(_text) + if self.parkingmarks[_spot.TerminalID] then + _spot.Coordinate:RemoveMark(self.parkingmarks[_spot.TerminalID]) + end + self.parkingmarks[_spot.TerminalID]=mid end -- Info to DCS.log file. local _text=string.format("%s, Term Index=%3d, Term Type=%03d, Free=%5s, TOAC=%5s, Term ID0=%3d, Dist2Rwy=%.1f m", airbasename, _spot.TerminalID, _spot.TerminalType,tostring(_spot.Free),tostring(_spot.TOAC),_spot.TerminalID0,_spot.DistToRwy) - self:E(_text) + self:I(_text) end + + return markers end +--- Place markers of parking spots on the F10 map and update regularly. +-- @param #AIRBASE self +-- @param #AIRBASE.TerminalType termtype Terminal type for which marks should be placed. +-- @param #boolean mark If false, do not place markers but only give output to DCS.log file. Default true. +function AIRBASE:MonitorParkingSpots(termtype, mark) + + local sched,shedid=SCHEDULER:New(self, self.MarkParkingSpots, {self,termtype,mark}, 5, 5) + + +end + + --- Seach unoccupied parking spots at the airbase for a specific group of aircraft. The routine also optionally checks for other unit, static and scenery options in a certain radius around the parking spot. -- The dimension of the spawned aircraft and of the potential obstacle are taken into account. Note that the routine can only return so many spots that are free. -- @param #AIRBASE self