From 2392c9dc8e91ed63cc6a2e20f1ef30e0f4d5ab5f Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 29 Jun 2020 20:55:32 +0200 Subject: [PATCH] Ops --- Moose Development/Moose/Core/Database.lua | 39 +++++++++++++++++++ Moose Development/Moose/Modules.lua | 1 + Moose Development/Moose/Ops/FlightGroup.lua | 31 +++++++++++---- .../Moose/Wrapper/Controllable.lua | 2 +- 4 files changed, 65 insertions(+), 8 deletions(-) diff --git a/Moose Development/Moose/Core/Database.lua b/Moose Development/Moose/Core/Database.lua index f691fb143..e634bba13 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -82,6 +82,9 @@ DATABASE = { DESTROYS = {}, ZONES = {}, ZONES_GOAL = {}, + WAREHOUSES = {}, + FLIGHTGROUPS = {}, + FLIGHTCONTROLS = {}, } local _DATABASECoalition = @@ -1252,8 +1255,44 @@ function DATABASE:SetPlayerSettings( PlayerName, Settings ) self.PLAYERSETTINGS[PlayerName] = Settings end +--- Add a flight group to the data base. +-- @param #DATABASE self +-- @param Ops.FlightGroup#FLIGHTGROUP flightgroup +function DATABASE:AddFlightGroup(flightgroup) + self:I({NewFlightGroup=flightgroup.groupname}) + self.FLIGHTGROUPS[flightgroup.groupname]=flightgroup +end +--- Get a flight group from the data base. +-- @param #DATABASE self +-- @param #string groupname Group name of the flight group. Can also be passed as GROUP object. +-- @return Ops.FlightGroup#FLIGHTGROUP Flight group object. +function DATABASE:GetFlightGroup(groupname) + -- Get group and group name. + if type(groupname)=="string" then + else + groupname=groupname:GetName() + end + + return self.FLIGHTGROUPS[groupname] +end + +--- Add a flight control to the data base. +-- @param #DATABASE self +-- @param Ops.FlightControl#FLIGHTCONTROL flightcontrol +function DATABASE:AddFlightControl(flightcontrol) + self:F2( { flightcontrol } ) + self.FLIGHTCONTROLS[flightcontrol.airbasename]=flightcontrol +end + +--- Get a flight control object from the data base. +-- @param #DATABASE self +-- @param #string airbasename Name of the associated airbase. +-- @return Ops.FlightControl#FLIGHTCONTROL The FLIGHTCONTROL object.s +function DATABASE:GetFlightControl(airbasename) + return self.FLIGHTCONTROLS[airbasename] +end --- @param #DATABASE self function DATABASE:_RegisterTemplates() diff --git a/Moose Development/Moose/Modules.lua b/Moose Development/Moose/Modules.lua index f2d48f6a2..9ca9bce74 100644 --- a/Moose Development/Moose/Modules.lua +++ b/Moose Development/Moose/Modules.lua @@ -72,6 +72,7 @@ __Moose.Include( 'Scripts/Moose/Ops/RescueHelo.lua' ) __Moose.Include( 'Scripts/Moose/Ops/ATIS.lua' ) __Moose.Include( 'Scripts/Moose/Ops/AirWing.lua' ) __Moose.Include( 'Scripts/Moose/Ops/Auftrag.lua' ) +__Moose.Include( 'Scripts/Moose/Ops/OpsGroup.lua' ) __Moose.Include( 'Scripts/Moose/Ops/FlightGroup.lua' ) __Moose.Include( 'Scripts/Moose/Ops/NavyGroup.lua' ) __Moose.Include( 'Scripts/Moose/Ops/Squadron.lua' ) diff --git a/Moose Development/Moose/Ops/FlightGroup.lua b/Moose Development/Moose/Ops/FlightGroup.lua index 01f48b2c0..d5fae6836 100644 --- a/Moose Development/Moose/Ops/FlightGroup.lua +++ b/Moose Development/Moose/Ops/FlightGroup.lua @@ -229,10 +229,9 @@ FLIGHTGROUP.version="0.5.0" --- Create a new FLIGHTGROUP object and start the FSM. -- @param #FLIGHTGROUP self --- @param Wrapper.Group#GROUP group The group object. Can also be given as #string with the name of the group --- @param #string autostart (Optional) If `true` or `nil` automatically start the FSM (default). If `false`, use FLIGHTGROUP:Start() manually. +-- @param Wrapper.Group#GROUP group The group object. Can also be given as #string with the name of the group. -- @return #FLIGHTGROUP self -function FLIGHTGROUP:New(group, autostart) +function FLIGHTGROUP:New(group) -- First check if we already have a flight group for this group. local fg=_DATABASE:GetFlightGroup(group) @@ -338,6 +337,7 @@ function FLIGHTGROUP:New(group, autostart) self:HandleEvent(EVENTS.Ejection, self.OnEventEjection) self:HandleEvent(EVENTS.Crash, self.OnEventCrash) self:HandleEvent(EVENTS.RemoveUnit, self.OnEventRemoveUnit) + self:HandleEvent(EVENTS.UnitLost, self.OnEventUnitLost) -- Init waypoints. self:InitWaypoints() @@ -1155,6 +1155,18 @@ function FLIGHTGROUP:OnEventCrash(EventData) end +--- Flightgroup event function handling the crash of a unit. +-- @param #FLIGHTGROUP self +-- @param Core.Event#EVENTDATA EventData Event data. +function FLIGHTGROUP:OnEventUnitLost(EventData) + + -- Check that this is the right group. + if EventData and EventData.IniGroup and EventData.IniUnit and EventData.IniGroupName and EventData.IniGroupName==self.groupname then + self:I(self.lid..string.format("EVENT: Unit %s lost!", EventData.IniUnitName)) + end + +end + --- Flightgroup event function handling the crash of a unit. -- @param #FLIGHTGROUP self -- @param Core.Event#EVENTDATA EventData Event data. @@ -3070,7 +3082,7 @@ function FLIGHTGROUP:_SetElementParkingAt(Element, Spot) if Spot then - env.info(string.format("FF Element %s is parking on spot %d", Element.name, Spot.TerminalID)) + self:I(self.lid..string.format("Element %s is parking on spot %d", Element.name, Spot.TerminalID)) if self.flightcontrol then @@ -3204,10 +3216,13 @@ function FLIGHTGROUP:GetParkingSpot(element, maxdist, airbase) airbase=airbase or coord:GetClosestAirbase(nil, self:GetCoalition()) + -- TODO: replace by airbase.parking if AIRBASE is updated. + local parking=airbase:GetParkingSpotsTable() + local spot=nil --Wrapper.Airbase#AIRBASE.ParkingSpot local dist=nil local distmin=math.huge - for _,_parking in pairs(airbase.parking) do + for _,_parking in pairs(parking) do local parking=_parking --Wrapper.Airbase#AIRBASE.ParkingSpot dist=coord:Get2DDistance(parking.Coordinate) if dist