diff --git a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua index bbbe19ed0..b1422cb11 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua @@ -23,8 +23,8 @@ AI_CARGO_AIRPLANE = { --- Creates a new AI_CARGO_AIRPLANE object. -- @param #AI_CARGO_AIRPLANE self --- @param Wrapper.Group#GROUP Airplane --- @param Core.Set#SET_CARGO CargoSet +-- @param Wrapper.Group#GROUP Airplane Plane used for transportation of cargo. +-- @param Core.Set#SET_CARGO CargoSet Cargo set to be transported. -- @return #AI_CARGO_AIRPLANE function AI_CARGO_AIRPLANE:New( Airplane, CargoSet ) @@ -54,7 +54,7 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet ) -- @param #string From -- @param #string Event -- @param #string To - -- @param Wrapper.Airbase#AIRBASE Airbase + -- @param Wrapper.Airbase#AIRBASE Airbase Airbase where troops are picked up. -- @return #boolean --- Pickup Handler OnAfter for AI_CARGO_AIRPLANE @@ -63,18 +63,18 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet ) -- @param #string From -- @param #string Event -- @param #string To - -- @param Wrapper.Airbase#AIRBASE Airbase + -- @param Wrapper.Airbase#AIRBASE Airbase Airbase where troops are picked up. --- Pickup Trigger for AI_CARGO_AIRPLANE -- @function [parent=#AI_CARGO_AIRPLANE] Pickup -- @param #AI_CARGO_AIRPLANE self - -- @param Wrapper.Airbase#AIRBASE Airbase + -- @param Wrapper.Airbase#AIRBASE Airbase Airbase where troops are picked up. --- Pickup Asynchronous Trigger for AI_CARGO_AIRPLANE -- @function [parent=#AI_CARGO_AIRPLANE] __Pickup -- @param #AI_CARGO_AIRPLANE self - -- @param #number Delay - -- @param Wrapper.Airbase#AIRBASE Airbase + -- @param #number Delay Delay in seconds. + -- @param Wrapper.Airbase#AIRBASE Airbase Airbase where troops are picked up. --- Deploy Handler OnBefore for AI_CARGO_AIRPLANE -- @function [parent=#AI_CARGO_AIRPLANE] OnBeforeDeploy @@ -82,7 +82,8 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet ) -- @param #string From -- @param #string Event -- @param #string To - -- @param Wrapper.Airbase#AIRBASE Airbase + -- @param Wrapper.Airbase#AIRBASE Airbase Destination airbase where troops are deployed. + -- @param #number Speed Speed in km/h for travelling to deploy base. -- @return #boolean --- Deploy Handler OnAfter for AI_CARGO_AIRPLANE @@ -91,20 +92,22 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet ) -- @param #string From -- @param #string Event -- @param #string To - -- @param Wrapper.Airbase#AIRBASE Airbase + -- @param Wrapper.Airbase#AIRBASE Airbase Destination airbase where troops are deployed. + -- @param #number Speed Speed in km/h for travelling to deploy base. --- Deploy Trigger for AI_CARGO_AIRPLANE -- @function [parent=#AI_CARGO_AIRPLANE] Deploy -- @param #AI_CARGO_AIRPLANE self - -- @param Wrapper.Airbase#AIRBASE Airbase + -- @param Wrapper.Airbase#AIRBASE Airbase Destination airbase where troops are deployed. + -- @param #number Speed Speed in km/h for travelling to deploy base. --- Deploy Asynchronous Trigger for AI_CARGO_AIRPLANE -- @function [parent=#AI_CARGO_AIRPLANE] __Deploy -- @param #AI_CARGO_AIRPLANE self - -- @param Wrapper.Airbase#AIRBASE Airbase - -- @param #number Delay - - + -- @param #number Delay Delay in seconds. + -- @param Wrapper.Airbase#AIRBASE Airbase Destination airbase where troops are deployed. + -- @param #number Speed Speed in km/h for travelling to deploy base. + self:SetCarrier( Airplane ) return self @@ -190,13 +193,12 @@ function AI_CARGO_AIRPLANE:FindCarrier( Coordinate, Radius ) end ---- @param #AI_CARGO_AIRPLANE self --- @param Wrapper.Group#GROUP Airplane +--- On after "Landed" event. Called on engine shutdown. +-- @param #AI_CARGO_AIRPLANE self +-- @param Wrapper.Group#GROUP Airplane Transport plane. -- @param From -- @param Event -- @param To - -- @param Wrapper.Airbase#AIRBASE Airbase --- @param #number Speed function AI_CARGO_AIRPLANE:onafterLanded( Airplane, From, Event, To ) if Airplane and Airplane:IsAlive() then @@ -216,8 +218,8 @@ function AI_CARGO_AIRPLANE:onafterLanded( Airplane, From, Event, To ) end - ---- @param #AI_CARGO_AIRPLANE self +--- On after "Pickup" event. Routes transport to pickup airbase. +-- @param #AI_CARGO_AIRPLANE self -- @param Wrapper.Group#GROUP Airplane -- @param From -- @param Event @@ -227,24 +229,34 @@ end function AI_CARGO_AIRPLANE:onafterPickup( Airplane, From, Event, To, Airbase, Speed ) if Airplane and Airplane:IsAlive() then - self:Route( Airplane, Airbase, Speed ) + + -- Aircraft might be on the ground of the pickup airbase already. + if Airplane:InAir() then + self:Route( Airplane, Airbase, Speed ) + end + -- TODO: Improve :Route() so that the aircraft can be routed from another airbase to the pickup airbase. + self.RoutePickup = true + + -- Set airbase as starting point in the next Route() call. self.Airbase = Airbase end end - ---- @param #AI_CARGO_AIRPLANE self +--- On after Depoly event. Routes plane to deploy airbase. +-- @param #AI_CARGO_AIRPLANE self -- @param Wrapper.Group#GROUP Airplane -- @param From -- @param Event -- @param To --- @param Wrapper.Airbase#AIRBASE Airbase --- @param #number Speed +-- @param Wrapper.Airbase#AIRBASE Airbase Airbase where troups should be deployed. +-- @param #number Speed Speed in km/h for travelling to deploy base. function AI_CARGO_AIRPLANE:onafterDeploy( Airplane, From, Event, To, Airbase, Speed ) if Airplane and Airplane:IsAlive() then + + -- Route to self:Route( Airplane, Airbase, Speed ) self.RouteDeploy = true self.Airbase = Airbase @@ -253,26 +265,37 @@ function AI_CARGO_AIRPLANE:onafterDeploy( Airplane, From, Event, To, Airbase, Sp end ---- @param #AI_CARGO_AIRPLANE self --- @param Wrapper.Group#GROUP Airplane +--- On after Load event. +-- @param #AI_CARGO_AIRPLANE self +-- @param Wrapper.Group#GROUP Airplane Transport plane. +-- @param From +-- @param Event +-- @param To +-- @param Wrapper.Point#COORDINATE Coordinate function AI_CARGO_AIRPLANE:onafterLoad( Airplane, From, Event, To, Coordinate ) if Airplane and Airplane:IsAlive() then for _, Cargo in pairs( self.CargoSet:GetSet() ) do + local Cargo=Cargo --Cargo.Cargo#CARGO if Cargo:IsInLoadRadius( Coordinate ) then self:__Board( 5 ) Cargo:Board( Airplane, 25 ) self.Cargo = Cargo break end + end end end ---- @param #AI_CARGO_AIRPLANE self --- @param Wrapper.Group#GROUP Airplane +--- On after Board event. +-- @param #AI_CARGO_AIRPLANE self +-- @param Wrapper.Group#GROUP Airplane Cargo plane. +-- @param From +-- @param Event +-- @param To function AI_CARGO_AIRPLANE:onafterBoard( Airplane, From, Event, To ) if Airplane and Airplane:IsAlive() then @@ -286,8 +309,12 @@ function AI_CARGO_AIRPLANE:onafterBoard( Airplane, From, Event, To ) end ---- @param #AI_CARGO_AIRPLANE self --- @param Wrapper.Group#GROUP Airplane +--- On after Loaded event. +-- @param #AI_CARGO_AIRPLANE self +-- @param Wrapper.Group#GROUP Airplane Cargo plane. +-- @param From +-- @param Event +-- @param To function AI_CARGO_AIRPLANE:onafterLoaded( Airplane, From, Event, To ) if Airplane and Airplane:IsAlive() then @@ -296,8 +323,12 @@ function AI_CARGO_AIRPLANE:onafterLoaded( Airplane, From, Event, To ) end ---- @param #AI_CARGO_AIRPLANE self --- @param Wrapper.Group#GROUP Airplane +--- On after Unload event. +-- @param #AI_CARGO_AIRPLANE self +-- @param Wrapper.Group#GROUP Airplane Cargo plane. +-- @param From +-- @param Event +-- @param To function AI_CARGO_AIRPLANE:onafterUnload( Airplane, From, Event, To ) if Airplane and Airplane:IsAlive() then @@ -307,8 +338,12 @@ function AI_CARGO_AIRPLANE:onafterUnload( Airplane, From, Event, To ) end ---- @param #AI_CARGO_AIRPLANE self --- @param Wrapper.Group#GROUP Airplane +--- On after Unboard event. +-- @param #AI_CARGO_AIRPLANE self +-- @param Wrapper.Group#GROUP Airplane Cargo plane. +-- @param From +-- @param Event +-- @param To function AI_CARGO_AIRPLANE:onafterUnboard( Airplane, From, Event, To ) if Airplane and Airplane:IsAlive() then @@ -321,8 +356,12 @@ function AI_CARGO_AIRPLANE:onafterUnboard( Airplane, From, Event, To ) end ---- @param #AI_CARGO_AIRPLANE self --- @param Wrapper.Group#GROUP Airplane +--- On after Unloaded event. +-- @param #AI_CARGO_AIRPLANE self +-- @param Wrapper.Group#GROUP Airplane Cargo plane. +-- @param From +-- @param Event +-- @param To function AI_CARGO_AIRPLANE:onafterUnloaded( Airplane, From, Event, To ) if Airplane and Airplane:IsAlive() then diff --git a/Moose Development/Moose/AI/AI_G2G_Dispatcher.lua b/Moose Development/Moose/AI/AI_G2G_Dispatcher.lua index f4468f9f9..36f833a80 100644 --- a/Moose Development/Moose/AI/AI_G2G_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_G2G_Dispatcher.lua @@ -185,12 +185,12 @@ do infantry = {}, } + -- @field category WAREHOUSE.category= { Transport=1, - Figherplane=1, + Fighter=1, AWACS=1, - Tanker=1, - + Tanker=1, } --- WAREHOUSE constructor. Creates a new WAREHOUSE object. @@ -205,11 +205,11 @@ do self.homebase=airbase self.coordinate=airbase:GetCoordinate() self.coalition=airbase:GetCoalition() - - - self:AddTransition("*", "Start", "Idle") - self:AddTransition("*", "Status", "*") - self:AddTransition("*", "Request", "*") + + self:AddTransition("*", "Start", "Running") + self:AddTransition("*", "Status", "*") + self:AddTransition("*", "Request", "*") + self:AddTransition("*", "Delivered", "*") --- Triggers the FSM event "Start". -- @function [parent=#WAREHOUSE] Start @@ -236,6 +236,7 @@ do -- @param #WAREHOUSE self -- @param Wrapper.Airbase#AIRBASE Airbase Airbase requesting supply. -- @param #string Asset Asset that is requested. + -- @param #number nAsset Number of assets requested. Default 1. -- @param #string TransportType Type of transport: "Plane", "Helicopter", "APC" --- Triggers the FSM event "Request" after a delay. @@ -244,7 +245,19 @@ do -- @param #number delay Delay in seconds. -- @param Wrapper.Airbase#AIRBASE Airbase Airbase requesting supply. -- @param #string Asset Asset that is requested. + -- @param #number nAsset Number of assets requested. Default 1. -- @param #string TransportType Type of transport: "Plane", "Helicopter", "APC" + + --- Triggers the FSM event "Delivered". + -- @function [parent=#WAREHOUSE] Delivered + -- @param #WAREHOUSE self + -- @param Wrapper.Group#GROUP group Group that was delivered. + + --- Triggers the FSM event "Delivered" after a delay. + -- @function [parent=#WAREHOUSE] __Delivered + -- @param #number delay Delay in seconds. + -- @param #WAREHOUSE self + -- @param Wrapper.Group#GROUP group Group that was delivered. return self end @@ -255,7 +268,7 @@ do -- @param #string Event Event. -- @param #string To To state. function WAREHOUSE:onafterStart(From, Event, To) - env.info("FF starting warehouse of airbase of "..self.homebase:GetName()) + env.info("FF starting warehouse at airbase "..self.homebase:GetName()) -- handle events -- event takeoff @@ -272,7 +285,7 @@ do -- @param #string Event Event. -- @param #string To To state. function WAREHOUSE:onafterStatus(From, Event, To) - env.info("FF checking warehouse status of "..self.homebase:GetName()) + env.info("FF checking warehouse status of airbase "..self.homebase:GetName()) env.info(string.format("FF warehouse at %s: number of transport planes = %d", self.homebase:GetName(), #self.plane)) @@ -295,35 +308,80 @@ do if TransportType=="Air" then - local template=self.plane[math.random(#self.plane)] + -- Get a random template from the stock list. + local _chosenone=math.random(#self.plane) + -- Select template group name. + local template=self.plane[_chosenone] + if template then + -- Spawn plane at warehouse homebase. local Plane=SPAWN:New(template):SpawnAtAirbase(Airbase, nil, nil, nil, false) + if Plane==nil then + -- Plane was not spawned correctly. Try again in 60 seconds. + self:__Request( 60, Airbase, Asset, nAsset, TransportType) + return + else + -- Remove chosen plane from list. + table.remove(self.plane,_chosenone) + end + + -- New empty cargo set. local CargoGroups = SET_CARGO:New() + -- Spawn requested assets. local spawn=SPAWN:New("Infantry Platoon Alpha") for i=1,nAsset do local spawngroup=spawn:SpawnFromVec3(self.homebase:GetZone():GetRandomPointVec3(100,500)) local cargogroup = CARGO_GROUP:New(spawngroup, "Infantry", string.format( "Infantry Platoon %d", i), 5000, 35) - CargoGroups:AddCargo(cargogroup) + CargoGroups:AddCargo(cargogroup) end - local CargoPlane = AI_CARGO_AIRPLANE:New(Plane, CargoGroups) + -- Define cargo airplane. + local CargoPlane = AI_CARGO_AIRPLANE:New(Plane, CargoGroups) + -- Pickup cargo at homebase. CargoPlane:__Pickup(5, self.homebase) - function CargoPlane:onafterLoaded( Airplane, From, Event, To, Cargo) + -- Set warehouse state so that we can retreive it later. + Plane:SetState(Plane, "WAREHOUSE", self) + + -- Once the cargo was loaded start off to deploy airbase. + function CargoPlane:OnAfterLoaded(Airplane, From, Event, To) CargoPlane:__Deploy(10, Airbase, 500) end - + --- Function + -- @param Wrapper.Group#GROUP Airplane + function CargoPlane:OnAfterUnloaded(Airplane, From, Event, To) + local group=CargoPlane.Cargo:GetObject() + local Airplane=Airplane --Wrapper.Group#GROUP + local warehouse Airplane:GetState(Airplane, "WAREHOUSE") --#WAREHOUSE + warehouse:__Delivered(1, group) + end + end end end + + --- Warehouse + -- @param #WAREHOUSE self + -- @param #string From From state. + -- @param #string Event Event. + -- @param #string To To state. + -- @param Wrapper.Group#GROUP Group The group that was delivered. + -- @param #string Asset Asset that is requested. + -- @param #number nAssed Number of groups of that asset requested. + -- @param #string TransportType Type of transport: "Plane", "Helicopter", "APC" + function WAREHOUSE:onafterDelivered(From, Event, To, Group) + local road=Group:GetCoordinate():GetClosestPointToRoad() + local speed=Group:GetSpeedMax()*0.5 + Group:RouteGroundTo(road, speed, "Off Road") + end --- Add an airplane group to the warehouse stock. -- @param #WAREHOUSE self @@ -341,27 +399,44 @@ do local DCSdisplay=DCSunit:getDesc().displayName local DCScategory=DCSgroup:getCategory() local DCStype=DCSunit:getTypeName() - - --env.info(string.format("FF adding %d transport plane template %s type %s, display %s", n, tostring(templateprefix), tostring(typename), tostring(displayname))) - - --[[ - -- Create a table with properties. - self.airplane[templateprefix]=self.airplane[templateprefix] or {} - - -- Increase number in stock. - if self.airplane[templateprefix].nstock then - self.airplane[templateprefix].nstock=self.airplane[templateprefix].nstock+n - else - self.airplane[templateprefix].nstock=n - end - - self.airplane[templateprefix].nstock=n - ]] - + + -- Add this n times to the table. for i=1,n do table.insert(self.plane, templateprefix) end + return self + end + + + --- Add an airplane group to the warehouse stock. + -- @param #WAREHOUSE self + -- @param #string templateprefix Name of the late activated template group as defined in the mission editor. + -- @param #number n Number of groups to add to the warehouse stock. + -- @return #WAREHOUSE self + function WAREHOUSE:AddInfantry(templateprefix, n) + + local n=n or 1 + + local group=GROUP:FindByName(templateprefix) + + if group then + + local DCSgroup=group:GetDCSObject() + local DCSunit=DCSgroup:getUnit(1) + local DCSdesc=DCSunit:getDesc() + local DCSdisplay=DCSunit:getDesc().displayName + local DCScategory=DCSgroup:getCategory() + local DCStype=DCSunit:getTypeName() + + -- Add this n times to the table. + for i=1,n do + table.insert(self.infantry, {templatename=templateprefix, category=DCScategory, typename=DCStype}) + end + + end + + return self end end diff --git a/Moose Development/Moose/Core/Base.lua b/Moose Development/Moose/Core/Base.lua index 83d9cd5a7..1b4d96efb 100644 --- a/Moose Development/Moose/Core/Base.lua +++ b/Moose Development/Moose/Core/Base.lua @@ -798,8 +798,7 @@ end -- @param Object The object that will hold the Value set by the Key. -- @param Key The key that is used as a reference of the value. Note that the key can be a #string, but it can also be any other type! -- @param Value The value to is stored in the object. --- @return The Value set. --- @return #nil The Key was not found and thus the Value could not be retrieved. +-- @return The Value set. function BASE:SetState( Object, Key, Value ) local ClassNameAndID = Object:GetClassNameAndID() @@ -816,7 +815,7 @@ end -- @param #BASE self -- @param Object The object that holds the Value set by the Key. -- @param Key The key that is used to retrieve the value. Note that the key can be a #string, but it can also be any other type! --- @return The Value retrieved. +-- @return The Value retrieved or nil if the Key was not found and thus the Value could not be retrieved. function BASE:GetState( Object, Key ) local ClassNameAndID = Object:GetClassNameAndID() @@ -829,6 +828,10 @@ function BASE:GetState( Object, Key ) return nil end +--- Clear the state of an object. +-- @param #BASE self +-- @param Object The object that holds the Value set by the Key. +-- @param StateName The key that is should be cleared. function BASE:ClearState( Object, StateName ) local ClassNameAndID = Object:GetClassNameAndID()