mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-22 16:05:25 +00:00
Warehouse and other things
This commit is contained in:
@@ -51,34 +51,41 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet )
|
|||||||
--- Pickup Handler OnBefore for AI_CARGO_AIRPLANE
|
--- Pickup Handler OnBefore for AI_CARGO_AIRPLANE
|
||||||
-- @function [parent=#AI_CARGO_AIRPLANE] OnBeforePickup
|
-- @function [parent=#AI_CARGO_AIRPLANE] OnBeforePickup
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
-- @param #string From
|
-- @param Wrapper.Group#GROUP Airplane Cargo transport plane.
|
||||||
-- @param #string Event
|
-- @param #string From From state.
|
||||||
-- @param #string To
|
-- @param #string Event Event.
|
||||||
|
-- @param #string To To state.
|
||||||
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase where troops are picked up.
|
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase where troops are picked up.
|
||||||
|
-- @param #number Speed in km/h for travelling to pickup base.
|
||||||
-- @return #boolean
|
-- @return #boolean
|
||||||
|
|
||||||
--- Pickup Handler OnAfter for AI_CARGO_AIRPLANE
|
--- Pickup Handler OnAfter for AI_CARGO_AIRPLANE
|
||||||
-- @function [parent=#AI_CARGO_AIRPLANE] OnAfterPickup
|
-- @function [parent=#AI_CARGO_AIRPLANE] OnAfterPickup
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
|
-- @param Wrapper.Group#GROUP Airplane Cargo plane.
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase where troops are picked up.
|
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase where troops are picked up.
|
||||||
|
-- @param #number Speed in km/h for travelling to pickup base.
|
||||||
|
|
||||||
--- Pickup Trigger for AI_CARGO_AIRPLANE
|
--- Pickup Trigger for AI_CARGO_AIRPLANE
|
||||||
-- @function [parent=#AI_CARGO_AIRPLANE] Pickup
|
-- @function [parent=#AI_CARGO_AIRPLANE] Pickup
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase where troops are picked up.
|
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase where troops are picked up.
|
||||||
|
-- @param #number Speed in km/h for travelling to pickup base.
|
||||||
|
|
||||||
--- Pickup Asynchronous Trigger for AI_CARGO_AIRPLANE
|
--- Pickup Asynchronous Trigger for AI_CARGO_AIRPLANE
|
||||||
-- @function [parent=#AI_CARGO_AIRPLANE] __Pickup
|
-- @function [parent=#AI_CARGO_AIRPLANE] __Pickup
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
-- @param #number Delay Delay in seconds.
|
-- @param #number Delay Delay in seconds.
|
||||||
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase where troops are picked up.
|
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase where troops are picked up.
|
||||||
|
-- @param #number Speed in km/h for travelling to pickup base.
|
||||||
|
|
||||||
--- Deploy Handler OnBefore for AI_CARGO_AIRPLANE
|
--- Deploy Handler OnBefore for AI_CARGO_AIRPLANE
|
||||||
-- @function [parent=#AI_CARGO_AIRPLANE] OnBeforeDeploy
|
-- @function [parent=#AI_CARGO_AIRPLANE] OnBeforeDeploy
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
|
-- @param Wrapper.Group#GROUP Airplane Cargo plane.
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
@@ -89,6 +96,7 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet )
|
|||||||
--- Deploy Handler OnAfter for AI_CARGO_AIRPLANE
|
--- Deploy Handler OnAfter for AI_CARGO_AIRPLANE
|
||||||
-- @function [parent=#AI_CARGO_AIRPLANE] OnAfterDeploy
|
-- @function [parent=#AI_CARGO_AIRPLANE] OnAfterDeploy
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
|
-- @param Wrapper.Group#GROUP Airplane Cargo plane.
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
@@ -108,6 +116,15 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet )
|
|||||||
-- @param Wrapper.Airbase#AIRBASE Airbase Destination airbase where troops are deployed.
|
-- @param Wrapper.Airbase#AIRBASE Airbase Destination airbase where troops are deployed.
|
||||||
-- @param #number Speed Speed in km/h for travelling to deploy base.
|
-- @param #number Speed Speed in km/h for travelling to deploy base.
|
||||||
|
|
||||||
|
--- On after Loaded event, i.e. triggered when the cargo is inside the carrier.
|
||||||
|
-- @function [parent=#AI_CARGO_AIRPLANE] OnAfterLoaded
|
||||||
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
|
-- @param Wrapper.Group#GROUP Airplane Cargo plane.
|
||||||
|
-- @param From
|
||||||
|
-- @param Event
|
||||||
|
-- @param To
|
||||||
|
|
||||||
|
-- Set carrier.
|
||||||
self:SetCarrier( Airplane )
|
self:SetCarrier( Airplane )
|
||||||
|
|
||||||
return self
|
return self
|
||||||
@@ -126,10 +143,10 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- Set the Carrier.
|
--- Set the Carrier (controllable). Also initializes events for carrier and defines the coalition.
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
-- @param Wrapper.Group#GROUP Airplane
|
-- @param Wrapper.Group#GROUP Airplane Transport plane.
|
||||||
-- @return #AI_CARGO_AIRPLANE
|
-- @return #AI_CARGO_AIRPLANE self
|
||||||
function AI_CARGO_AIRPLANE:SetCarrier( Airplane )
|
function AI_CARGO_AIRPLANE:SetCarrier( Airplane )
|
||||||
|
|
||||||
local AICargo = self
|
local AICargo = self
|
||||||
@@ -184,7 +201,7 @@ end
|
|||||||
|
|
||||||
--- Find a free Carrier within a range.
|
--- Find a free Carrier within a range.
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
-- @param Wrapper.Airbase#AIRBASE Airbase
|
-- @param Wrapper.Airbase#AIRBASE Airbase
|
||||||
-- @param #number Radius
|
-- @param #number Radius
|
||||||
-- @return Wrapper.Group#GROUP NewCarrier
|
-- @return Wrapper.Group#GROUP NewCarrier
|
||||||
function AI_CARGO_AIRPLANE:FindCarrier( Coordinate, Radius )
|
function AI_CARGO_AIRPLANE:FindCarrier( Coordinate, Radius )
|
||||||
@@ -206,9 +223,9 @@ function AI_CARGO_AIRPLANE:FindCarrier( Coordinate, Radius )
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after "Landed" event. Called on engine shutdown.
|
--- On after "Landed" event. Called on engine shutdown and initiates the pickup mission or unloading event.
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
-- @param Wrapper.Group#GROUP Airplane Transport plane.
|
-- @param Wrapper.Group#GROUP Airplane Cargo transport plane.
|
||||||
-- @param From
|
-- @param From
|
||||||
-- @param Event
|
-- @param Event
|
||||||
-- @param To
|
-- @param To
|
||||||
@@ -220,11 +237,13 @@ function AI_CARGO_AIRPLANE:onafterLanded( Airplane, From, Event, To )
|
|||||||
|
|
||||||
if Airplane and Airplane:IsAlive() then
|
if Airplane and Airplane:IsAlive() then
|
||||||
|
|
||||||
|
-- Aircraft was sent to this airbase to pickup troops. Initiate loadling.
|
||||||
if self.RoutePickup == true then
|
if self.RoutePickup == true then
|
||||||
self:Load( Airplane:GetPointVec2() )
|
self:Load( Airplane:GetPointVec2() )
|
||||||
self.RoutePickup = false
|
self.RoutePickup = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Aircraft was send to this airbase to deploy troops. Initiate unloading.
|
||||||
if self.RouteDeploy == true then
|
if self.RouteDeploy == true then
|
||||||
self:Unload()
|
self:Unload()
|
||||||
self.RouteDeploy = false
|
self.RouteDeploy = false
|
||||||
@@ -237,48 +256,66 @@ end
|
|||||||
|
|
||||||
--- On after "Pickup" event. Routes transport to pickup airbase.
|
--- On after "Pickup" event. Routes transport to pickup airbase.
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
-- @param Wrapper.Group#GROUP Airplane
|
-- @param Wrapper.Group#GROUP Airplane Cargo transport plane.
|
||||||
-- @param From
|
-- @param #string From From state.
|
||||||
-- @param Event
|
-- @param #string Event Event.
|
||||||
-- @param To
|
-- @param #string To To state.
|
||||||
-- @param Wrapper.Airbase#AIRBASE Airbase
|
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase where the troops as picked up.
|
||||||
-- @param #number Speed
|
-- @param #number Speed in km/h for travelling to pickup base.
|
||||||
function AI_CARGO_AIRPLANE:onafterPickup( Airplane, From, Event, To, Airbase, Speed )
|
function AI_CARGO_AIRPLANE:onafterPickup( Airplane, From, Event, To, Airbase, Speed )
|
||||||
|
|
||||||
if Airplane and Airplane:IsAlive() then
|
if Airplane and Airplane:IsAlive() then
|
||||||
|
|
||||||
-- Aircraft might be on the ground of the pickup airbase already.
|
-- Two cases. Aircraft spawned in air or at an airbase.
|
||||||
if Airplane:InAir() then
|
if Airplane:InAir() then
|
||||||
self:Route( Airplane, Airbase, Speed )
|
self.Airbase=nil
|
||||||
|
else
|
||||||
|
self.Airbase=Airplane:GetCoordinate():GetClosestAirbase()
|
||||||
end
|
end
|
||||||
-- TODO: Improve :Route() so that the aircraft can be routed from another airbase to the pickup airbase.
|
|
||||||
|
|
||||||
self.RoutePickup = true
|
-- Route aircraft to pickup airbase.
|
||||||
|
self:Route( Airplane, Airbase, Speed )
|
||||||
|
|
||||||
-- Set airbase as starting point in the next Route() call.
|
-- Set airbase as starting point in the next Route() call.
|
||||||
self.Airbase = Airbase
|
self.Airbase = Airbase
|
||||||
|
|
||||||
|
-- Aircraft is on a pickup mission.
|
||||||
|
self.RoutePickup = true
|
||||||
|
|
||||||
|
-- Unclear!?
|
||||||
self.Transporting = true
|
self.Transporting = true
|
||||||
self.Relocating = false
|
self.Relocating = false
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after Depoly event. Routes plane to deploy airbase.
|
--- On after Depoly event. Routes plane to the airbase where the troops are deployed.
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
-- @param Wrapper.Group#GROUP Airplane
|
-- @param Wrapper.Group#GROUP Airplane Cargo transport plane.
|
||||||
-- @param From
|
-- @param #string From From state.
|
||||||
-- @param Event
|
-- @param #string Event Event.
|
||||||
-- @param To
|
-- @param #string To To state.
|
||||||
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase where troups should be deployed.
|
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase where troups should be deployed.
|
||||||
-- @param #number Speed Speed in km/h for travelling to deploy base.
|
-- @param #number Speed Speed in km/h for travelling to deploy base.
|
||||||
function AI_CARGO_AIRPLANE:onafterDeploy( Airplane, From, Event, To, Airbase, Speed )
|
function AI_CARGO_AIRPLANE:onafterDeploy( Airplane, From, Event, To, Airbase, Speed )
|
||||||
|
|
||||||
if Airplane and Airplane:IsAlive() then
|
if Airplane and Airplane:IsAlive()~=nil then
|
||||||
|
|
||||||
-- Route to
|
-- Activate uncontrolled airplane.
|
||||||
|
if Airplane:IsAlive()==false then
|
||||||
|
Airplane:SetCommand({id = 'Start', params = {}})
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Route to destination airbase.
|
||||||
self:Route( Airplane, Airbase, Speed )
|
self:Route( Airplane, Airbase, Speed )
|
||||||
|
|
||||||
|
-- Aircraft is on a depoly mission.
|
||||||
self.RouteDeploy = true
|
self.RouteDeploy = true
|
||||||
|
|
||||||
|
-- Set destination airbase for next :Route() command.
|
||||||
self.Airbase = Airbase
|
self.Airbase = Airbase
|
||||||
|
|
||||||
|
-- Unclear?!
|
||||||
self.Transporting = false
|
self.Transporting = false
|
||||||
self.Relocating = false
|
self.Relocating = false
|
||||||
end
|
end
|
||||||
@@ -286,17 +323,16 @@ function AI_CARGO_AIRPLANE:onafterDeploy( Airplane, From, Event, To, Airbase, Sp
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- On after Load event.
|
--- On after Load event. Checks if cargo is inside the load radius and if so starts the boarding process.
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
-- @param Wrapper.Group#GROUP Airplane Transport plane.
|
-- @param Wrapper.Group#GROUP Airplane Transport plane.
|
||||||
-- @param From
|
-- @param #string From From state.
|
||||||
-- @param Event
|
-- @param #string Event Event.
|
||||||
-- @param To
|
-- @param #string To To state.
|
||||||
-- @param Wrapper.Point#COORDINATE Coordinate
|
-- @param Wrapper.Point#COORDINATE Coordinate Place where the cargo is guided to if it is inside the load radius.
|
||||||
function AI_CARGO_AIRPLANE:onafterLoad( Airplane, From, Event, To, Coordinate )
|
function AI_CARGO_AIRPLANE:onafterLoad( Airplane, From, Event, To, Coordinate )
|
||||||
|
|
||||||
if Airplane and Airplane:IsAlive()==true or Airplane:IsAlive()==false then
|
if Airplane and Airplane:IsAlive()~=nil then
|
||||||
--if Airplane then
|
|
||||||
|
|
||||||
for _, Cargo in pairs( self.CargoSet:GetSet() ) do
|
for _, Cargo in pairs( self.CargoSet:GetSet() ) do
|
||||||
self:F({Cargo:GetName()})
|
self:F({Cargo:GetName()})
|
||||||
@@ -313,12 +349,12 @@ function AI_CARGO_AIRPLANE:onafterLoad( Airplane, From, Event, To, Coordinate )
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after Board event.
|
--- On after Board event. Cargo is inside the load radius and boarding is performed.
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
-- @param Wrapper.Group#GROUP Airplane Cargo plane.
|
-- @param Wrapper.Group#GROUP Airplane Cargo transport plane.
|
||||||
-- @param From
|
-- @param #string From From state.
|
||||||
-- @param Event
|
-- @param #string Event Event.
|
||||||
-- @param To
|
-- @param #string To To state.
|
||||||
function AI_CARGO_AIRPLANE:onafterBoard( Airplane, From, Event, To )
|
function AI_CARGO_AIRPLANE:onafterBoard( Airplane, From, Event, To )
|
||||||
|
|
||||||
if Airplane and Airplane:IsAlive() then
|
if Airplane and Airplane:IsAlive() then
|
||||||
@@ -332,26 +368,28 @@ function AI_CARGO_AIRPLANE:onafterBoard( Airplane, From, Event, To )
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after Loaded event.
|
--- On after Loaded event. Cargo is inside the carrier and ready to be transported.
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
-- @param Wrapper.Group#GROUP Airplane Cargo plane.
|
-- @param Wrapper.Group#GROUP Airplane Cargo transport plane.
|
||||||
-- @param From
|
-- @param #string From From state.
|
||||||
-- @param Event
|
-- @param #string Event Event.
|
||||||
-- @param To
|
-- @param #string To To state.
|
||||||
function AI_CARGO_AIRPLANE:onafterLoaded( Airplane, From, Event, To )
|
function AI_CARGO_AIRPLANE:onafterLoaded( Airplane, From, Event, To )
|
||||||
|
|
||||||
|
env.info("FF troops loaded into cargo plane")
|
||||||
|
|
||||||
if Airplane and Airplane:IsAlive() then
|
if Airplane and Airplane:IsAlive() then
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- On after Unload event.
|
--- On after Unload event. Cargo is beeing unloaded, i.e. the unboarding process is started.
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
-- @param Wrapper.Group#GROUP Airplane Cargo plane.
|
-- @param Wrapper.Group#GROUP Airplane Cargo transport plane.
|
||||||
-- @param From
|
-- @param #string From From state.
|
||||||
-- @param Event
|
-- @param #string Event Event.
|
||||||
-- @param To
|
-- @param #string To To state.
|
||||||
function AI_CARGO_AIRPLANE:onafterUnload( Airplane, From, Event, To )
|
function AI_CARGO_AIRPLANE:onafterUnload( Airplane, From, Event, To )
|
||||||
|
|
||||||
if Airplane and Airplane:IsAlive() then
|
if Airplane and Airplane:IsAlive() then
|
||||||
@@ -361,12 +399,12 @@ function AI_CARGO_AIRPLANE:onafterUnload( Airplane, From, Event, To )
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after Unboard event.
|
--- On after Unboard event. Checks if unboarding process is finished.
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
-- @param Wrapper.Group#GROUP Airplane Cargo plane.
|
-- @param Wrapper.Group#GROUP Airplane Cargo transport plane.
|
||||||
-- @param From
|
-- @param #string From From state.
|
||||||
-- @param Event
|
-- @param #string Event Event.
|
||||||
-- @param To
|
-- @param #string To To state.
|
||||||
function AI_CARGO_AIRPLANE:onafterUnboard( Airplane, From, Event, To )
|
function AI_CARGO_AIRPLANE:onafterUnboard( Airplane, From, Event, To )
|
||||||
|
|
||||||
if Airplane and Airplane:IsAlive() then
|
if Airplane and Airplane:IsAlive() then
|
||||||
@@ -379,12 +417,12 @@ function AI_CARGO_AIRPLANE:onafterUnboard( Airplane, From, Event, To )
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after Unloaded event.
|
--- On after Unloaded event. Cargo has been unloaded, i.e. the unboarding process is finished.
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
-- @param Wrapper.Group#GROUP Airplane Cargo plane.
|
-- @param Wrapper.Group#GROUP Airplane Cargo transport plane.
|
||||||
-- @param From
|
-- @param #string From From state.
|
||||||
-- @param Event
|
-- @param #string Event Event.
|
||||||
-- @param To
|
-- @param #string To To state.
|
||||||
function AI_CARGO_AIRPLANE:onafterUnloaded( Airplane, From, Event, To )
|
function AI_CARGO_AIRPLANE:onafterUnloaded( Airplane, From, Event, To )
|
||||||
|
|
||||||
if Airplane and Airplane:IsAlive() then
|
if Airplane and Airplane:IsAlive() then
|
||||||
@@ -393,119 +431,75 @@ function AI_CARGO_AIRPLANE:onafterUnloaded( Airplane, From, Event, To )
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Route the airplane from one airport or it's current position to another airbase.
|
||||||
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
|
-- @param Wrapper.Group#GROUP Airplane Airplane group to be routed.
|
||||||
|
-- @param Wrapper.Airbase#AIRBASE Airbase Destination airbase.
|
||||||
|
-- @param #number Speed Speed in km/h. Default is 80% of max possible speed the group can do.
|
||||||
|
-- @param #boolean Uncontrolled If true, spawn group in uncontrolled state.
|
||||||
|
function AI_CARGO_AIRPLANE:Route( Airplane, Airbase, Speed, Uncontrolled )
|
||||||
|
|
||||||
--- @param #AI_CARGO_AIRPLANE self
|
if Airplane and Airplane:IsAlive()~=nil then
|
||||||
-- @param Wrapper.Group#GROUP Airplane
|
|
||||||
-- @param Wrapper.Airbase#AIRBASE Airbase
|
|
||||||
-- @param #number Speed
|
|
||||||
function AI_CARGO_AIRPLANE:Route( Airplane, Airbase, Speed )
|
|
||||||
|
|
||||||
if Airplane and Airplane:IsAlive() then
|
-- Set takeoff type.
|
||||||
|
local Takeoff = SPAWN.Takeoff.Cold
|
||||||
local PointVec3 = Airplane:GetPointVec3()
|
|
||||||
|
|
||||||
local Takeoff = SPAWN.Takeoff.Hot
|
|
||||||
|
|
||||||
|
-- Get template of group.
|
||||||
local Template = Airplane:GetTemplate()
|
local Template = Airplane:GetTemplate()
|
||||||
|
|
||||||
if Template then
|
-- Nil check
|
||||||
|
if Template==nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local Points = {}
|
-- Waypoints of the route.
|
||||||
|
local Points={}
|
||||||
|
|
||||||
if self.Airbase then
|
-- To point.
|
||||||
|
local AirbasePointVec2 = Airbase:GetPointVec2()
|
||||||
local FromWaypoint = Template.route.points[1]
|
local ToWaypoint = AirbasePointVec2:WaypointAir(
|
||||||
|
POINT_VEC3.RoutePointAltType.BARO,
|
||||||
-- These are only for ships.
|
"Land",
|
||||||
FromWaypoint.linkUnit = nil
|
"Landing",
|
||||||
FromWaypoint.helipadId = nil
|
Speed or Airplane:GetSpeedMax()*0.8
|
||||||
FromWaypoint.airdromeId = nil
|
)
|
||||||
|
ToWaypoint["airdromeId"] = Airbase:GetID()
|
||||||
local ParkingSpots = self.Airbase:FindFreeParkingSpotForAircraft( Airplane, AIRBASE.TerminalType.OpenBig )
|
ToWaypoint["speed_locked"] = true
|
||||||
local AirbaseID = self.Airbase:GetID()
|
|
||||||
local AirbaseCategory = self.Airbase:GetDesc().category
|
|
||||||
|
|
||||||
FromWaypoint.airdromeId = AirbaseID
|
|
||||||
|
|
||||||
FromWaypoint.alt = 0
|
|
||||||
|
|
||||||
FromWaypoint.type = GROUPTEMPLATE.Takeoff[Takeoff][1] -- type
|
|
||||||
FromWaypoint.action = GROUPTEMPLATE.Takeoff[Takeoff][2] -- action
|
|
||||||
|
|
||||||
|
|
||||||
-- Translate the position of the Group Template to the Vec3.
|
-- If self.Airbase~=nil then group is currently at an airbase, where it should be respawned.
|
||||||
for UnitID = 1, #Template.units do
|
if self.Airbase then
|
||||||
self:T( 'Before Translation SpawnTemplate.units['..UnitID..'].x = ' .. Template.units[UnitID].x .. ', SpawnTemplate.units['..UnitID..'].y = ' .. Template.units[UnitID].y )
|
|
||||||
|
|
||||||
-- These cause a lot of confusion.
|
-- Second point of the route. First point is done in RespawnAtCurrentAirbase() routine.
|
||||||
local UnitTemplate = Template.units[UnitID]
|
Template.route.points[2] = ToWaypoint
|
||||||
|
|
||||||
UnitTemplate.parking = nil
|
-- Respawn group at the current airbase.
|
||||||
UnitTemplate.parking_id = nil
|
Airplane:RespawnAtCurrentAirbase(Template, Takeoff, Uncontrolled)
|
||||||
UnitTemplate.alt = 0
|
|
||||||
|
|
||||||
local SX = UnitTemplate.x
|
else
|
||||||
local SY = UnitTemplate.y
|
|
||||||
local BX = FromWaypoint.x
|
|
||||||
local BY = FromWaypoint.y
|
|
||||||
local TX = PointVec3.x + ( SX - BX )
|
|
||||||
local TY = PointVec3.z + ( SY - BY )
|
|
||||||
|
|
||||||
UnitTemplate.x = TX
|
-- From point.
|
||||||
UnitTemplate.y = TY
|
local GroupPoint = Airplane:GetVec2()
|
||||||
|
local FromWaypoint = {}
|
||||||
|
FromWaypoint.x = GroupPoint.x
|
||||||
|
FromWaypoint.y = GroupPoint.y
|
||||||
|
FromWaypoint.type = "Turning Point"
|
||||||
|
FromWaypoint.action = "Turning Point"
|
||||||
|
FromWaypoint.speed = Airplane:GetSpeedMax()*0.8
|
||||||
|
|
||||||
self:T( 'After Translation SpawnTemplate.units['..UnitID..'].x = ' .. UnitTemplate.x .. ', SpawnTemplate.units['..UnitID..'].y = ' .. UnitTemplate.y )
|
-- The two route points.
|
||||||
end
|
Points[1] = FromWaypoint
|
||||||
|
Points[2] = ToWaypoint
|
||||||
FromWaypoint.x = PointVec3.x
|
|
||||||
FromWaypoint.y = PointVec3.z
|
|
||||||
|
|
||||||
Points[#Points+1] = FromWaypoint
|
|
||||||
else
|
|
||||||
|
|
||||||
local GroupPoint = Airplane:GetVec2()
|
|
||||||
local GroupVelocity = Airplane:GetUnit(1):GetDesc().speedMax
|
|
||||||
|
|
||||||
local FromWaypoint = {}
|
|
||||||
FromWaypoint.x = GroupPoint.x
|
|
||||||
FromWaypoint.y = GroupPoint.y
|
|
||||||
FromWaypoint.type = "Turning Point"
|
|
||||||
FromWaypoint.action = "Turning Point"
|
|
||||||
FromWaypoint.speed = GroupVelocity
|
|
||||||
|
|
||||||
Points[#Points+1] = FromWaypoint
|
|
||||||
end
|
|
||||||
|
|
||||||
local AirbasePointVec2 = Airbase:GetPointVec2()
|
|
||||||
local ToWaypoint = AirbasePointVec2:WaypointAir(
|
|
||||||
POINT_VEC3.RoutePointAltType.BARO,
|
|
||||||
"Land",
|
|
||||||
"Landing",
|
|
||||||
Speed or Airplane:GetUnit(1):GetDesc().speedMax
|
|
||||||
)
|
|
||||||
|
|
||||||
ToWaypoint["airdromeId"] = Airbase:GetID()
|
|
||||||
ToWaypoint["speed_locked"] = true,
|
|
||||||
|
|
||||||
self:F( ToWaypoint )
|
|
||||||
|
|
||||||
Points[#Points+1] = ToWaypoint
|
|
||||||
|
|
||||||
|
local PointVec3 = Airplane:GetPointVec3()
|
||||||
Template.x = PointVec3.x
|
Template.x = PointVec3.x
|
||||||
Template.y = PointVec3.z
|
Template.y = PointVec3.z
|
||||||
|
|
||||||
self:T3( Points )
|
|
||||||
Template.route.points = Points
|
Template.route.points = Points
|
||||||
|
|
||||||
Template.uncontrolled=false
|
local GroupSpawned = Airplane:Respawn(Template)
|
||||||
|
|
||||||
--self:Respawn( Template )
|
|
||||||
|
|
||||||
local GroupSpawned = Airplane:Respawn( Template )
|
|
||||||
|
|
||||||
return GroupSpawned
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -29,11 +29,11 @@ AI_CARGO_DISPATCHER_AIRPLANE = {
|
|||||||
|
|
||||||
--- Creates a new AI_CARGO_DISPATCHER_AIRPLANE object.
|
--- Creates a new AI_CARGO_DISPATCHER_AIRPLANE object.
|
||||||
-- @param #AI_CARGO_DISPATCHER_AIRPLANE self
|
-- @param #AI_CARGO_DISPATCHER_AIRPLANE self
|
||||||
-- @param Core.Set#SET_GROUP SetAirplanes
|
-- @param Core.Set#SET_GROUP SetAirplanes Set of cargo transport airplanes.
|
||||||
-- @param Core.Set#SET_CARGO SetCargos
|
-- @param Core.Set#SET_CARGO SetCargos Set of cargo, which is supposed to be transported.
|
||||||
-- @param Core.Set#SET_AIRBASE PickupAirbasesSet
|
-- @param Core.Set#SET_AIRBASE PickupAirbasesSet Set of airbases where the cargo has to be picked up.
|
||||||
-- @param Core.Set#SET_AIRBASE DeployAirbasesSet
|
-- @param Core.Set#SET_AIRBASE DeployAirbasesSet Set of airbases where the cargo is deployed. Choice for each cargo is random.
|
||||||
-- @return #AI_CARGO_DISPATCHER_AIRPLANE
|
-- @return #AI_CARGO_DISPATCHER_AIRPLANE self
|
||||||
-- @usage
|
-- @usage
|
||||||
--
|
--
|
||||||
-- -- Create a new cargo dispatcher
|
-- -- Create a new cargo dispatcher
|
||||||
|
|||||||
@@ -1,139 +0,0 @@
|
|||||||
--- **AI** - (R2.4) - Manages automatic ground troups dispatching to the battle field.
|
|
||||||
--
|
|
||||||
--
|
|
||||||
-- Features:
|
|
||||||
--
|
|
||||||
-- * Some nice stuff.
|
|
||||||
--
|
|
||||||
-- # QUICK START GUIDE
|
|
||||||
--
|
|
||||||
-- ===
|
|
||||||
--
|
|
||||||
-- ### Authors: **funkyfranky**
|
|
||||||
--
|
|
||||||
-- @module AI.AI_G2G_Dispatcher
|
|
||||||
-- @image AI_Air_To_Air_Dispatching.JPG
|
|
||||||
|
|
||||||
do -- AI_G2G_DISPATCHER
|
|
||||||
|
|
||||||
--- AI_G2G_DISPATCHER class.
|
|
||||||
-- @type AI_G2G_DISPATCHER
|
|
||||||
-- @field #string ClassName Name of the class.
|
|
||||||
-- @field Functional.Detection#DETECTION_AREAS Detection Detection object responsible for identifying enemies.
|
|
||||||
-- @extends Tasking.DetectionManager#DETECTION_MANAGER
|
|
||||||
|
|
||||||
--- Create an automatic ground .
|
|
||||||
--
|
|
||||||
-- ===
|
|
||||||
--
|
|
||||||
-- # Demo Missions
|
|
||||||
--
|
|
||||||
-- ### [AI\_A2A\_DISPATCHER Demo Missions](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/release-2-2-pre/AID%20-%20AI%20Dispatching)
|
|
||||||
--
|
|
||||||
-- ===
|
|
||||||
--
|
|
||||||
-- # YouTube Channel
|
|
||||||
--
|
|
||||||
-- ### [DCS WORLD - MOOSE - A2A GCICAP - Build an automatic A2A Defense System](https://www.youtube.com/playlist?list=PL7ZUrU4zZUl0S4KMNUUJpaUs6zZHjLKNx)
|
|
||||||
--
|
|
||||||
-- ===
|
|
||||||
--
|
|
||||||
-- 
|
|
||||||
--
|
|
||||||
-- Blabla.
|
|
||||||
--
|
|
||||||
-- ===
|
|
||||||
--
|
|
||||||
-- # USAGE GUIDE
|
|
||||||
--
|
|
||||||
--
|
|
||||||
--
|
|
||||||
-- @field #AI_G2G_DISPATCHER
|
|
||||||
AI_G2G_DISPATCHER = {
|
|
||||||
ClassName = "AI_G2G_DISPATCHER",
|
|
||||||
Detection = nil,
|
|
||||||
Homebase = {},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- AI_G2G_DISPATCHER constructor. Creates a new AI_G2G_DISPATCHER object.
|
|
||||||
-- @param #AI_G2G_DISPATCHER self
|
|
||||||
-- @param Functional.Detection#DETECTION_BASE Detection The DETECTION object that will detects targets using the the Early Warning Radar network.
|
|
||||||
-- @return #AI_G2G_DISPATCHER self
|
|
||||||
function AI_G2G_DISPATCHER:New(Detection)
|
|
||||||
|
|
||||||
-- Inherits from DETECTION_MANAGER
|
|
||||||
local self = BASE:Inherit(self, DETECTION_MANAGER:New(nil, Detection)) -- #AI_G2G_DISPATCHER
|
|
||||||
|
|
||||||
self.Detection = Detection -- Functional.Detection#DETECTION_AREAS
|
|
||||||
|
|
||||||
self:AddTransition( "Started", "Assign", "Started" )
|
|
||||||
|
|
||||||
self:__Start(5)
|
|
||||||
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Adds an APC group to transport troops to the front line.
|
|
||||||
-- @param #AI_G2G_DISPATCHER self
|
|
||||||
-- @param Wrapper.Group#GROUP group APC group.
|
|
||||||
-- @return #AI_G2G_DISPATCHER self
|
|
||||||
function AI_G2G_DISPATCHER:AddTransportAPC(group, homebase, resources)
|
|
||||||
self.TransportAPC[group]={}
|
|
||||||
self.TransportAPC[group].group=group
|
|
||||||
self.TransportAPC[group].homebase=homebase
|
|
||||||
self.TransportAPC[group].resources=resources
|
|
||||||
|
|
||||||
-- Add homebase
|
|
||||||
if not self:GetHomebase(homebase) then
|
|
||||||
self:AddHomebase(homebase)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Adds an APC group to transport troops to the front line.
|
|
||||||
-- @param #AI_G2G_DISPATCHER self
|
|
||||||
-- @param Functional.Detection#DETECTION_BASE.DetectedItem DetectedItem The detected item.
|
|
||||||
function AI_G2G_DISPATCHER:EvaluateDetectedItem(DetectedItem)
|
|
||||||
local _coord=DetectedItem.Coordinate
|
|
||||||
_coord:MarkToAll("detected")
|
|
||||||
|
|
||||||
|
|
||||||
local _id=DetectedItem.ID
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Adds an APC group to transport troops to the front line.
|
|
||||||
-- @param #AI_G2G_DISPATCHER self
|
|
||||||
-- @param Functional.Detection#DETECTION_BASE Detection The detection created by the @{Functional.Detection#DETECTION_BASE} derived object.
|
|
||||||
-- @return #boolean True if you want the task assigning to continue while false will cancel the loop.
|
|
||||||
function AI_G2G_DISPATCHER:ProcessDetected(Detection)
|
|
||||||
|
|
||||||
|
|
||||||
-- Now that all obsolete tasks are removed, loop through the detected targets.
|
|
||||||
for DetectedItemID, DetectedItem in pairs( Detection:GetDetectedItems() ) do
|
|
||||||
|
|
||||||
local DetectedItem = DetectedItem -- Functional.Detection#DETECTION_BASE.DetectedItem
|
|
||||||
local DetectedSet = DetectedItem.Set -- Core.Set#SET_UNIT
|
|
||||||
local DetectedCount = DetectedSet:Count()
|
|
||||||
local DetectedZone = DetectedItem.Zone
|
|
||||||
|
|
||||||
self:F( { "Target ID", DetectedItem.ItemID } )
|
|
||||||
DetectedSet:Flush( self )
|
|
||||||
|
|
||||||
local DetectedID = DetectedItem.ID
|
|
||||||
local DetectionIndex = DetectedItem.Index
|
|
||||||
local DetectedItemChanged = DetectedItem.Changed
|
|
||||||
|
|
||||||
env.info(string.format("FF detected item id %d, index = %d, changed = %s", DetectedID, DetectedItem.Index, tostring(DetectedItem.Changed)))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
@@ -1203,6 +1203,10 @@ end
|
|||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
-- @param Wrapper.Unit#UNIT CargoCarrier
|
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||||
|
-- @param #number Speed
|
||||||
|
-- @param #number BoardDistance
|
||||||
|
-- @param #number LoadDistance
|
||||||
|
-- @param #number Angle
|
||||||
function CARGO_PACKAGE:onafterOnBoarded( From, Event, To, CargoCarrier, Speed, BoardDistance, LoadDistance, Angle )
|
function CARGO_PACKAGE:onafterOnBoarded( From, Event, To, CargoCarrier, Speed, BoardDistance, LoadDistance, Angle )
|
||||||
self:F()
|
self:F()
|
||||||
|
|
||||||
@@ -1218,6 +1222,7 @@ end
|
|||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
|
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||||
-- @param #number Speed
|
-- @param #number Speed
|
||||||
-- @param #number UnLoadDistance
|
-- @param #number UnLoadDistance
|
||||||
-- @param #number UnBoardDistance
|
-- @param #number UnBoardDistance
|
||||||
@@ -1261,6 +1266,7 @@ end
|
|||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
-- @param Wrapper.Unit#UNIT CargoCarrier
|
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||||
|
-- @param #number Speed
|
||||||
function CARGO_PACKAGE:onafterUnBoarded( From, Event, To, CargoCarrier, Speed )
|
function CARGO_PACKAGE:onafterUnBoarded( From, Event, To, CargoCarrier, Speed )
|
||||||
self:F()
|
self:F()
|
||||||
|
|
||||||
@@ -1304,6 +1310,8 @@ end
|
|||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
|
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||||
|
-- @param #number Speed
|
||||||
-- @param #number Distance
|
-- @param #number Distance
|
||||||
-- @param #number Angle
|
-- @param #number Angle
|
||||||
function CARGO_PACKAGE:onafterUnLoad( From, Event, To, CargoCarrier, Speed, Distance, Angle )
|
function CARGO_PACKAGE:onafterUnLoad( From, Event, To, CargoCarrier, Speed, Distance, Angle )
|
||||||
|
|||||||
@@ -61,8 +61,8 @@ do -- CARGO_GROUP
|
|||||||
-- @param #number LoadRadius (optional) Distance in meters until which a cargo is loaded into the carrier. Cargo outside this radius has to be routed by other means to within the radius to be loaded.
|
-- @param #number LoadRadius (optional) Distance in meters until which a cargo is loaded into the carrier. Cargo outside this radius has to be routed by other means to within the radius to be loaded.
|
||||||
-- @param #number NearRadius (optional) Once the units are within this radius of the carrier, they are actually loaded, i.e. disappear from the scene.
|
-- @param #number NearRadius (optional) Once the units are within this radius of the carrier, they are actually loaded, i.e. disappear from the scene.
|
||||||
-- @return #CARGO_GROUP Cargo group object.
|
-- @return #CARGO_GROUP Cargo group object.
|
||||||
function CARGO_GROUP:New( CargoGroup, Type, Name, LoadRadius )
|
function CARGO_GROUP:New( CargoGroup, Type, Name, LoadRadius, NearRadius )
|
||||||
local self = BASE:Inherit( self, CARGO_REPORTABLE:New( Type, Name, 0, LoadRadius ) ) -- #CARGO_GROUP
|
local self = BASE:Inherit( self, CARGO_REPORTABLE:New( Type, Name, 0, LoadRadius, NearRadius ) ) -- #CARGO_GROUP
|
||||||
self:F( { Type, Name, LoadRadius } )
|
self:F( { Type, Name, LoadRadius } )
|
||||||
|
|
||||||
self.CargoSet = SET_CARGO:New()
|
self.CargoSet = SET_CARGO:New()
|
||||||
@@ -98,7 +98,7 @@ do -- CARGO_GROUP
|
|||||||
local Unit = UNIT:Register( CargoUnitName )
|
local Unit = UNIT:Register( CargoUnitName )
|
||||||
--local WeightUnit = Unit:GetDesc().massEmpty
|
--local WeightUnit = Unit:GetDesc().massEmpty
|
||||||
--WeightGroup = WeightGroup + WeightUnit
|
--WeightGroup = WeightGroup + WeightUnit
|
||||||
local CargoUnit = CARGO_UNIT:New( Unit, Type, CargoUnitName, 10 )
|
local CargoUnit = CARGO_UNIT:New( Unit, Type, CargoUnitName, 10, LoadRadius, NearRadius )
|
||||||
self.CargoSet:Add( CargoUnitName, CargoUnit )
|
self.CargoSet:Add( CargoUnitName, CargoUnit )
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -257,10 +257,11 @@ do -- CARGO_GROUP
|
|||||||
|
|
||||||
--- Enter Boarding State.
|
--- Enter Boarding State.
|
||||||
-- @param #CARGO_GROUP self
|
-- @param #CARGO_GROUP self
|
||||||
-- @param Wrapper.Unit#UNIT CargoCarrier
|
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
|
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||||
|
-- @param #number NearRadius If distance is smaller than this number, cargo is loaded into the carrier.
|
||||||
function CARGO_GROUP:onenterBoarding( From, Event, To, CargoCarrier, NearRadius, ... )
|
function CARGO_GROUP:onenterBoarding( From, Event, To, CargoCarrier, NearRadius, ... )
|
||||||
--self:F( { CargoCarrier.UnitName, From, Event, To } )
|
--self:F( { CargoCarrier.UnitName, From, Event, To } )
|
||||||
|
|
||||||
@@ -304,10 +305,11 @@ do -- CARGO_GROUP
|
|||||||
|
|
||||||
--- Leave Boarding State.
|
--- Leave Boarding State.
|
||||||
-- @param #CARGO_GROUP self
|
-- @param #CARGO_GROUP self
|
||||||
-- @param Wrapper.Unit#UNIT CargoCarrier
|
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
|
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||||
|
-- @param #number NearRadius If distance is smaller than this number, cargo is loaded into the carrier.
|
||||||
function CARGO_GROUP:onafterBoarding( From, Event, To, CargoCarrier, NearRadius, ... )
|
function CARGO_GROUP:onafterBoarding( From, Event, To, CargoCarrier, NearRadius, ... )
|
||||||
--self:F( { CargoCarrier.UnitName, From, Event, To } )
|
--self:F( { CargoCarrier.UnitName, From, Event, To } )
|
||||||
|
|
||||||
@@ -359,10 +361,11 @@ do -- CARGO_GROUP
|
|||||||
|
|
||||||
--- Enter UnBoarding State.
|
--- Enter UnBoarding State.
|
||||||
-- @param #CARGO_GROUP self
|
-- @param #CARGO_GROUP self
|
||||||
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
|
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
||||||
|
-- @param #number NearRadius If distance is smaller than this number, cargo is loaded into the carrier.
|
||||||
function CARGO_GROUP:onenterUnBoarding( From, Event, To, ToPointVec2, NearRadius, ... )
|
function CARGO_GROUP:onenterUnBoarding( From, Event, To, ToPointVec2, NearRadius, ... )
|
||||||
self:F( {From, Event, To, ToPointVec2, NearRadius } )
|
self:F( {From, Event, To, ToPointVec2, NearRadius } )
|
||||||
|
|
||||||
@@ -401,10 +404,11 @@ do -- CARGO_GROUP
|
|||||||
|
|
||||||
--- Leave UnBoarding State.
|
--- Leave UnBoarding State.
|
||||||
-- @param #CARGO_GROUP self
|
-- @param #CARGO_GROUP self
|
||||||
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
|
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
||||||
|
-- @param #number NearRadius If distance is smaller than this number, cargo is loaded into the carrier.
|
||||||
function CARGO_GROUP:onleaveUnBoarding( From, Event, To, ToPointVec2, NearRadius, ... )
|
function CARGO_GROUP:onleaveUnBoarding( From, Event, To, ToPointVec2, NearRadius, ... )
|
||||||
--self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
--self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
||||||
|
|
||||||
@@ -438,10 +442,11 @@ do -- CARGO_GROUP
|
|||||||
|
|
||||||
--- UnBoard Event.
|
--- UnBoard Event.
|
||||||
-- @param #CARGO_GROUP self
|
-- @param #CARGO_GROUP self
|
||||||
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
|
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
||||||
|
-- @param #number NearRadius If distance is smaller than this number, cargo is loaded into the carrier.
|
||||||
function CARGO_GROUP:onafterUnBoarding( From, Event, To, ToPointVec2, NearRadius, ... )
|
function CARGO_GROUP:onafterUnBoarding( From, Event, To, ToPointVec2, NearRadius, ... )
|
||||||
--self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
--self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
||||||
|
|
||||||
@@ -454,10 +459,10 @@ do -- CARGO_GROUP
|
|||||||
|
|
||||||
--- Enter UnLoaded State.
|
--- Enter UnLoaded State.
|
||||||
-- @param #CARGO_GROUP self
|
-- @param #CARGO_GROUP self
|
||||||
-- @param Core.Point#POINT_VEC2
|
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
|
-- @param Core.Point#POINT_VEC2
|
||||||
function CARGO_GROUP:onenterUnLoaded( From, Event, To, ToPointVec2, ... )
|
function CARGO_GROUP:onenterUnLoaded( From, Event, To, ToPointVec2, ... )
|
||||||
--self:F( { From, Event, To, ToPointVec2 } )
|
--self:F( { From, Event, To, ToPointVec2 } )
|
||||||
|
|
||||||
@@ -467,7 +472,7 @@ do -- CARGO_GROUP
|
|||||||
self.CargoSet:ForEach(
|
self.CargoSet:ForEach(
|
||||||
function( Cargo )
|
function( Cargo )
|
||||||
--Cargo:UnLoad( ToPointVec2 )
|
--Cargo:UnLoad( ToPointVec2 )
|
||||||
local RandomVec2=ToPointVec2:GetRandomPointVec2InRadius(10)
|
local RandomVec2=ToPointVec2:GetRandomPointVec2InRadius(20, 10)
|
||||||
Cargo:UnLoad( RandomVec2 )
|
Cargo:UnLoad( RandomVec2 )
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
@@ -592,8 +597,7 @@ do -- CARGO_GROUP
|
|||||||
-- @param #CARGO_GROUP self
|
-- @param #CARGO_GROUP self
|
||||||
-- @param Wrapper.Group#GROUP CargoCarrier
|
-- @param Wrapper.Group#GROUP CargoCarrier
|
||||||
-- @param #number NearRadius
|
-- @param #number NearRadius
|
||||||
-- @return #boolean The Cargo is near to the Carrier.
|
-- @return #boolean The Cargo is near to the Carrier or #nil if the Cargo is not near to the Carrier.
|
||||||
-- @return #nil The Cargo is not near to the Carrier.
|
|
||||||
function CARGO_GROUP:IsNear( CargoCarrier, NearRadius )
|
function CARGO_GROUP:IsNear( CargoCarrier, NearRadius )
|
||||||
self:F( {NearRadius = NearRadius } )
|
self:F( {NearRadius = NearRadius } )
|
||||||
|
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ do -- CARGO_UNIT
|
|||||||
-- @param #number LoadRadius (optional)
|
-- @param #number LoadRadius (optional)
|
||||||
-- @param #number NearRadius (optional)
|
-- @param #number NearRadius (optional)
|
||||||
-- @return #CARGO_UNIT
|
-- @return #CARGO_UNIT
|
||||||
function CARGO_UNIT:New( CargoUnit, Type, Name, Weight, NearRadius )
|
function CARGO_UNIT:New( CargoUnit, Type, Name, Weight, LoadRadius, NearRadius )
|
||||||
local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoUnit, Type, Name, Weight, NearRadius ) ) -- #CARGO_UNIT
|
local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoUnit, Type, Name, Weight, LoadRadius, NearRadius ) ) -- #CARGO_UNIT
|
||||||
self:I( { Type, Name, Weight, NearRadius } )
|
self:I( { Type, Name, Weight, LoadRadius, NearRadius } )
|
||||||
|
|
||||||
self:T( CargoUnit )
|
self:T( CargoUnit )
|
||||||
self.CargoObject = CargoUnit
|
self.CargoObject = CargoUnit
|
||||||
@@ -62,6 +62,7 @@ do -- CARGO_UNIT
|
|||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
||||||
|
-- @param #number NearRadius (optional) Defaut 25 m.
|
||||||
function CARGO_UNIT:onenterUnBoarding( From, Event, To, ToPointVec2, NearRadius )
|
function CARGO_UNIT:onenterUnBoarding( From, Event, To, ToPointVec2, NearRadius )
|
||||||
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
||||||
|
|
||||||
@@ -131,6 +132,7 @@ do -- CARGO_UNIT
|
|||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
||||||
|
-- @param #number NearRadius (optional) Defaut 100 m.
|
||||||
function CARGO_UNIT:onleaveUnBoarding( From, Event, To, ToPointVec2, NearRadius )
|
function CARGO_UNIT:onleaveUnBoarding( From, Event, To, ToPointVec2, NearRadius )
|
||||||
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
||||||
|
|
||||||
@@ -158,6 +160,7 @@ do -- CARGO_UNIT
|
|||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
||||||
|
-- @param #number NearRadius (optional) Defaut 100 m.
|
||||||
function CARGO_UNIT:onafterUnBoarding( From, Event, To, ToPointVec2, NearRadius )
|
function CARGO_UNIT:onafterUnBoarding( From, Event, To, ToPointVec2, NearRadius )
|
||||||
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
||||||
|
|
||||||
@@ -281,7 +284,7 @@ do -- CARGO_UNIT
|
|||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
-- @param Wrapper.Client#CLIENT CargoCarrier
|
-- @param Wrapper.Client#CLIENT CargoCarrier
|
||||||
-- @param #number NearRadius
|
-- @param #number NearRadius Default 25 m.
|
||||||
function CARGO_UNIT:onafterBoarding( From, Event, To, CargoCarrier, NearRadius, ... )
|
function CARGO_UNIT:onafterBoarding( From, Event, To, CargoCarrier, NearRadius, ... )
|
||||||
--self:F( { From, Event, To, CargoCarrier.UnitName, NearRadius } )
|
--self:F( { From, Event, To, CargoCarrier.UnitName, NearRadius } )
|
||||||
|
|
||||||
@@ -338,6 +341,7 @@ do -- CARGO_UNIT
|
|||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
-- @param Wrapper.Unit#UNIT CargoCarrier
|
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||||
|
-- @param #number NearRadius Default 25 m.
|
||||||
function CARGO_UNIT:onenterBoarding( From, Event, To, CargoCarrier, NearRadius, ... )
|
function CARGO_UNIT:onenterBoarding( From, Event, To, CargoCarrier, NearRadius, ... )
|
||||||
--self:F( { From, Event, To, CargoCarrier.UnitName, NearRadius } )
|
--self:F( { From, Event, To, CargoCarrier.UnitName, NearRadius } )
|
||||||
|
|
||||||
|
|||||||
@@ -1096,6 +1096,37 @@ do -- COORDINATE
|
|||||||
return RoutePoint
|
return RoutePoint
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Gets the nearest airbase with respect to the current coordinates.
|
||||||
|
-- @param #COORDINATE self
|
||||||
|
-- @param #number AirbaseCategory Category of the airbase.
|
||||||
|
-- @return Wrapper.Airbase#AIRBASE Closest Airbase to the given coordinate.
|
||||||
|
-- @return #number Distance to the closest airbase in meters.
|
||||||
|
function COORDINATE:GetClosestAirbase(AirbaseCategory)
|
||||||
|
local airbases=AIRBASE.GetAllAirbases()
|
||||||
|
|
||||||
|
local closest=nil
|
||||||
|
local distmin=nil
|
||||||
|
-- Loop over all airbases.
|
||||||
|
for _,_airbase in pairs(airbases) do
|
||||||
|
local airbase=_airbase --Wrapper.Airbase#AIRBASE
|
||||||
|
local category=airbase:GetDesc().category
|
||||||
|
if AirbaseCategory and AirbaseCategory==category or AirbaseCategory==nil then
|
||||||
|
local dist=self:Get2DDistance(airbase:GetCoordinate())
|
||||||
|
if closest==nil then
|
||||||
|
distmin=dist
|
||||||
|
closest=airbase
|
||||||
|
else
|
||||||
|
if dist<distmin then
|
||||||
|
distmin=dist
|
||||||
|
closest=airbase
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return closest,distmin
|
||||||
|
end
|
||||||
|
|
||||||
--- Gets the nearest parking spot.
|
--- Gets the nearest parking spot.
|
||||||
-- @param #COORDINATE self
|
-- @param #COORDINATE self
|
||||||
-- @param Wrapper.Airbase#AIRBASE airbase (Optional) Search only parking spots at this airbase.
|
-- @param Wrapper.Airbase#AIRBASE airbase (Optional) Search only parking spots at this airbase.
|
||||||
|
|||||||
@@ -1,172 +0,0 @@
|
|||||||
--- **Functional** - (R2.4) JTAC
|
|
||||||
--
|
|
||||||
-- ===
|
|
||||||
--
|
|
||||||
-- JTAC mimic
|
|
||||||
--
|
|
||||||
-- ## Features:
|
|
||||||
--
|
|
||||||
-- * Feature 1
|
|
||||||
-- * Feature 2
|
|
||||||
--
|
|
||||||
-- ====
|
|
||||||
--
|
|
||||||
-- # Demo Missions
|
|
||||||
--
|
|
||||||
-- ### [MOOSE - ALL Demo Missions](https://github.com/FlightControl-Master/MOOSE_MISSIONS)
|
|
||||||
--
|
|
||||||
-- ====
|
|
||||||
--
|
|
||||||
-- # YouTube Channel
|
|
||||||
--
|
|
||||||
-- ### [MOOSE YouTube Channel](https://www.youtube.com/channel/UCjrA9j5LQoWsG4SpS8i79Qg)
|
|
||||||
--
|
|
||||||
-- ===
|
|
||||||
--
|
|
||||||
-- ### Author: **[funkyfranky](https://forums.eagle.ru/member.php?u=115026)**
|
|
||||||
--
|
|
||||||
-- ### Contributions: [FlightControl](https://forums.eagle.ru/member.php?u=89536)
|
|
||||||
--
|
|
||||||
-- ====
|
|
||||||
-- @module Functional.Jtac
|
|
||||||
-- @image JTAC.JPG
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
||||||
--- JTAC class
|
|
||||||
-- @type JTAC
|
|
||||||
-- @field #string ClassName Name of the class.
|
|
||||||
|
|
||||||
--- Easy assignment of JTAC.
|
|
||||||
--
|
|
||||||
-- A new ARTY object can be created with the @{#ARTY.New}(*group*) contructor.
|
|
||||||
-- The parameter *group* has to be a MOOSE Group object and defines ARTY group.
|
|
||||||
--
|
|
||||||
-- The ARTY FSM process can be started by the @{#ARTY.Start}() command.
|
|
||||||
--
|
|
||||||
-- ## The ARTY Process
|
|
||||||
--
|
|
||||||
-- 
|
|
||||||
--
|
|
||||||
--
|
|
||||||
--
|
|
||||||
-- @field #JTAC
|
|
||||||
JTAC={
|
|
||||||
ClassName="JTAC",
|
|
||||||
Debug=false,
|
|
||||||
}
|
|
||||||
|
|
||||||
--- Some ID to identify who we are in output of the DCS.log file.
|
|
||||||
-- @field #string id
|
|
||||||
JTAC.id="JTAC | "
|
|
||||||
|
|
||||||
--- Arty script version.
|
|
||||||
-- @field #string version
|
|
||||||
JTAC.version="0.0.1"
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
-- TODO list:
|
|
||||||
-- TODO: a lot.
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
--- Creates a new JTAC object.
|
|
||||||
-- @param #JTAC self
|
|
||||||
-- @param Wrapper.Group#GROUP group The GROUP object for which artillery tasks should be assigned.
|
|
||||||
-- @param alias (Optional) Alias name the group will be calling itself when sending messages. Default is the group name.
|
|
||||||
-- @return #JTAC JTAC object or nil if group does not exist or is not a ground or naval group.
|
|
||||||
function JTAC:New(group, alias)
|
|
||||||
BASE:F2(group)
|
|
||||||
|
|
||||||
-- Inherits from FSM_CONTROLLABLE
|
|
||||||
local self=BASE:Inherit(self, FSM_CONTROLLABLE:New()) -- #JTAC
|
|
||||||
|
|
||||||
-- Check that group is present.
|
|
||||||
if group then
|
|
||||||
self:T(JTAC.id..string.format("JTAC script version %s. Added group %s.", JTAC.version, group:GetName()))
|
|
||||||
else
|
|
||||||
self:E(JTAC.id.."ERROR: Requested JTAC group does not exist! (Has to be a MOOSE group.)")
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Set the controllable for the FSM.
|
|
||||||
self:SetControllable(group)
|
|
||||||
|
|
||||||
---------------
|
|
||||||
-- Transitions:
|
|
||||||
---------------
|
|
||||||
|
|
||||||
-- Entry.
|
|
||||||
self:AddTransition("*", "Start", "Ready")
|
|
||||||
self:AddTransition("Ready", "LaserOn", "Lasing")
|
|
||||||
self:AddTransition("Lasing", "Lasing", "Lasing")
|
|
||||||
self:AddTransition("Lasing", "LaserOff", "Ready")
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
||||||
-- FSM Start Event
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
--- After "Start" event.
|
|
||||||
-- @param #JTAC self
|
|
||||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable Controllable of the group.
|
|
||||||
-- @param #string From From state.
|
|
||||||
-- @param #string Event Event.
|
|
||||||
-- @param #string To To state.
|
|
||||||
function JTAC:onafterStart(Controllable, From, Event, To)
|
|
||||||
--self:_EventFromTo("onafterStart", Event, From, To)
|
|
||||||
|
|
||||||
-- Debug output.
|
|
||||||
local text=string.format("Started JTAC version %s for group %s.", JTAC.version, Controllable:GetName())
|
|
||||||
self:E(JTAC.id..text)
|
|
||||||
MESSAGE:New(text, 5):ToAllIf(self.Debug)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
--- After "LaserOn" event.
|
|
||||||
-- @param #JTAC self
|
|
||||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable Controllable of the group.
|
|
||||||
-- @param #string From From state.
|
|
||||||
-- @param #string Event Event.
|
|
||||||
-- @param #string To To state.
|
|
||||||
-- @param Wrapper.Unit#UNIT Target Target that should be lased.
|
|
||||||
function JTAC:onafterLaserOn(Controllable, From, Event, To, Target)
|
|
||||||
--self:_EventFromTo("onafterStart", Event, From, To)
|
|
||||||
|
|
||||||
-- Debug output.
|
|
||||||
local text=string.format("JTAC %s lasing target %s.", Controllable:GetName(), Target:GetName())
|
|
||||||
self:E(JTAC.id..text)
|
|
||||||
MESSAGE:New(text, 5):ToAllIf(self.Debug)
|
|
||||||
|
|
||||||
-- Start lasing.
|
|
||||||
Controllable:LaseUnit(Target, self.LaserCode, self.Duration)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--- After "LaserOff" event.
|
|
||||||
-- @param #JTAC self
|
|
||||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable Controllable of the group.
|
|
||||||
-- @param #string From From state.
|
|
||||||
-- @param #string Event Event.
|
|
||||||
-- @param #string To To state.
|
|
||||||
function JTAC:onafterLaserOff(Controllable, From, Event, To)
|
|
||||||
--self:_EventFromTo("onafterStart", Event, From, To)
|
|
||||||
|
|
||||||
-- Debug output.
|
|
||||||
local text=string.format("JTAC %s stoped lasing.", Controllable:GetName())
|
|
||||||
self:E(JTAC.id..text)
|
|
||||||
MESSAGE:New(text, 5):ToAllIf(self.Debug)
|
|
||||||
|
|
||||||
-- Turn of laser.
|
|
||||||
Controllable:LaseOff()
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -328,29 +328,9 @@ function WAREHOUSE:onbeforeRequest(From, Event, To, Airbase, AssetDescriptor, As
|
|||||||
local _stockitem=_stockrequest[1] --#WAREHOUSE.Stockitem
|
local _stockitem=_stockrequest[1] --#WAREHOUSE.Stockitem
|
||||||
local _assetattribute=self:_GetAttribute(_stockitem.templatename)
|
local _assetattribute=self:_GetAttribute(_stockitem.templatename)
|
||||||
|
|
||||||
-- Shortcut
|
-- Get assets in stock which are of the right type.
|
||||||
local _instock=self:_FilterStock(self.stock, WAREHOUSE.Descriptor.ATTRIBUTE, TransportType)
|
local _instock=self:_FilterStock(self.stock, WAREHOUSE.Descriptor.ATTRIBUTE, TransportType)
|
||||||
|
|
||||||
--[[
|
|
||||||
-- Check the availability of transport units.
|
|
||||||
if _TT == WAREHOUSE.TransportType.AIRPLANE then
|
|
||||||
_instock=self:_FilterStock(self.stock, WAREHOUSE.Descriptor.ATTRIBUTE, WAREHOUSE.Attribute.TRANSPORT_PLANE)
|
|
||||||
elseif _TT == WAREHOUSE.TransportType.HELICOPTER then
|
|
||||||
_instock=self:_FilterStock(self.stock, WAREHOUSE.Descriptor.ATTRIBUTE, WAREHOUSE.Attribute.TRANSPORT_HELO)
|
|
||||||
elseif _TT == WAREHOUSE.TransportType.GROUND then
|
|
||||||
_instock=self:_FilterStock(self.stock, WAREHOUSE.Descriptor.ATTRIBUTE, WAREHOUSE.Attribute.TRANSPORT_APC)
|
|
||||||
elseif _TT == WAREHOUSE.TransportType.SHIP then
|
|
||||||
_instock=0
|
|
||||||
elseif _TT == WAREHOUSE.TransportType.TRAIN then
|
|
||||||
_instock=0
|
|
||||||
elseif _TT == WAREHOUSE.TransportType.SELFPROPELLED then
|
|
||||||
_instock=_stockrequest
|
|
||||||
else
|
|
||||||
self:E(self.wid..string.format("ERROR: unknown transport type requested! type = %s", tostring(TransportType)))
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
]]
|
|
||||||
|
|
||||||
-- Check that a transport unit is available.
|
-- Check that a transport unit is available.
|
||||||
if #_instock==0 and TransportType~=WAREHOUSE.TransportType.SELFPROPELLED then
|
if #_instock==0 and TransportType~=WAREHOUSE.TransportType.SELFPROPELLED then
|
||||||
local text=string.format("Request denied! No transport unit currently available.")
|
local text=string.format("Request denied! No transport unit currently available.")
|
||||||
@@ -359,6 +339,8 @@ function WAREHOUSE:onbeforeRequest(From, Event, To, Airbase, AssetDescriptor, As
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO: For aircraft check that a parking spot is available.
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -406,6 +388,7 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass
|
|||||||
self:_DeleteStockItem(_id)
|
self:_DeleteStockItem(_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- No transport unit requested. Assets go by themselfes.
|
||||||
if TransportType==WAREHOUSE.TransportType.SELFPROPELLED then
|
if TransportType==WAREHOUSE.TransportType.SELFPROPELLED then
|
||||||
for _i,_spawngroup in pairs(_spawngroups) do
|
for _i,_spawngroup in pairs(_spawngroups) do
|
||||||
local group=_spawngroup --Wrapper.Group#GROUP
|
local group=_spawngroup --Wrapper.Group#GROUP
|
||||||
@@ -415,13 +398,12 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--TODO: naje nearradius depended on types.
|
--TODO: make nearradius depended on transport type and asset type.
|
||||||
local _loadradius=5000
|
local _loadradius=5000
|
||||||
local _nearradius=35
|
local _nearradius=35
|
||||||
|
|
||||||
-- Add spawned groups to cargo group object.
|
-- Add spawned groups to cargo group object.
|
||||||
for _i,_spawngroup in pairs(_spawngroups) do
|
for _i,_spawngroup in pairs(_spawngroups) do
|
||||||
--TODO: check near and load radius.
|
|
||||||
local _name=string.format("%s %d",AssetDescriptorValue, _i)
|
local _name=string.format("%s %d",AssetDescriptorValue, _i)
|
||||||
env.info(string.format("FF cargo group %d: %s",_i,_name))
|
env.info(string.format("FF cargo group %d: %s",_i,_name))
|
||||||
local cargogroup = CARGO_GROUP:New(_spawngroup, AssetDescriptorValue, _name, _loadradius, _nearradius)
|
local cargogroup = CARGO_GROUP:New(_spawngroup, AssetDescriptorValue, _name, _loadradius, _nearradius)
|
||||||
@@ -431,8 +413,6 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass
|
|||||||
env.info(string.format("FF cargo set object names %s", CargoGroups:GetObjectNames()))
|
env.info(string.format("FF cargo set object names %s", CargoGroups:GetObjectNames()))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Filter the requested assets.
|
-- Filter the requested assets.
|
||||||
local _transportitem --#WAREHOUSE.Stockitem
|
local _transportitem --#WAREHOUSE.Stockitem
|
||||||
if TransportType ~= WAREHOUSE.TransportType.SELFPROPELLED then
|
if TransportType ~= WAREHOUSE.TransportType.SELFPROPELLED then
|
||||||
@@ -452,8 +432,8 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass
|
|||||||
if Plane==nil then
|
if Plane==nil then
|
||||||
-- Plane was not spawned correctly. Try again in 60 seconds.
|
-- Plane was not spawned correctly. Try again in 60 seconds.
|
||||||
local text="Technical problems with the transport plane occurred. Request was cancelled! Try again later."
|
local text="Technical problems with the transport plane occurred. Request was cancelled! Try again later."
|
||||||
--self:__Request(60, Airbase, AssetDescriptor, AssetDescriptorValue, nAsset, TransportType)
|
MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.Report or self.Debug)
|
||||||
--TODO: despawn units and but them back into the warehouse.
|
--TODO: Despawn asset units and but them back into the warehouse.
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
-- Remove chosen transport asset from list.
|
-- Remove chosen transport asset from list.
|
||||||
@@ -472,7 +452,7 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass
|
|||||||
|
|
||||||
--- Once the cargo was loaded start off to deploy airbase.
|
--- Once the cargo was loaded start off to deploy airbase.
|
||||||
function CargoPlane:OnAfterLoaded(Airplane, From, Event, To)
|
function CargoPlane:OnAfterLoaded(Airplane, From, Event, To)
|
||||||
CargoPlane:__Deploy(10, Airbase, 500)
|
CargoPlane:__Deploy(10, Airbase)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Function called when cargo has arrived and was unloaded.
|
--- Function called when cargo has arrived and was unloaded.
|
||||||
@@ -521,7 +501,6 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass
|
|||||||
warehouse:__Delivered(1, group)
|
warehouse:__Delivered(1, group)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
elseif TransportType==WAREHOUSE.TransportType.APC then
|
elseif TransportType==WAREHOUSE.TransportType.APC then
|
||||||
|
|
||||||
-- Spawn APC in spawn zone.
|
-- Spawn APC in spawn zone.
|
||||||
@@ -574,12 +553,10 @@ end
|
|||||||
-- @param #string Event Event.
|
-- @param #string Event Event.
|
||||||
-- @param #string To To state.
|
-- @param #string To To state.
|
||||||
-- @param Wrapper.Group#GROUP Group The group that was delivered.
|
-- @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)
|
function WAREHOUSE:onafterDelivered(From, Event, To, Group)
|
||||||
|
env.info("FF warehouse cargo delivered! Croutine to closest point on road")
|
||||||
local road=Group:GetCoordinate():GetClosestPointToRoad()
|
local road=Group:GetCoordinate():GetClosestPointToRoad()
|
||||||
local speed=Group:GetSpeedMax()*0.5
|
local speed=Group:GetSpeedMax()*0.6
|
||||||
Group:RouteGroundTo(road, speed, "Off Road")
|
Group:RouteGroundTo(road, speed, "Off Road")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1372,15 +1372,34 @@ function GROUP:Respawn( Template, Reset )
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- @param Wrapper.Group#GROUP self
|
--- Respawn a group at an airbase.
|
||||||
function GROUP:RespawnAtAirbase( AirbaseRespawn, Takeoff, TakeoffAltitude ) -- R2.4
|
-- Note that the group has to be on parking spots at the airbase already in order for this to work.
|
||||||
self:F( { AirbaseRespawn, Takeoff, TakeoffAltitude } )
|
-- So each unit of the group is respawned at exactly the same parking spot as it currently occupies.
|
||||||
|
-- @param Wrapper.Group#GROUP self
|
||||||
|
-- @param #table SpawnTemplate (Optional) The spawn template for the group. If no template is given it is exacted from the group.
|
||||||
|
-- @param Core.Spawn#SPAWN.Takeoff Takeoff (Optional) Takeoff type. Sould be either SPAWN.Takeoff.Cold or SPAWN.Takeoff.Hot. Default is SPAWN.Takeoff.Hot.
|
||||||
|
-- @param #boolean Uncontrolled (Optional) If true, spawn in uncontrolled state.
|
||||||
|
-- @return Wrapper.Group#GROUP Group spawned at airbase or nil if group could not be spawned.
|
||||||
|
function GROUP:RespawnAtCurrentAirbase(SpawnTemplate, Takeoff, Uncontrolled) -- R2.4
|
||||||
|
self:F( { Airbase, Takeoff} )
|
||||||
|
|
||||||
local PointVec3 = AirbaseRespawn:GetPointVec3()
|
-- Get closest airbase. Should be the one we care currently on.
|
||||||
|
local airbase=self:GetCoordinate():GetClosestAirbase()
|
||||||
|
|
||||||
|
if airbase then
|
||||||
|
env.info("FF closest airbase = "..airbase:GetName())
|
||||||
|
else
|
||||||
|
env.info("FF could not find closest airbase!")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
-- Takeoff type. Default hot.
|
||||||
Takeoff = Takeoff or SPAWN.Takeoff.Hot
|
Takeoff = Takeoff or SPAWN.Takeoff.Hot
|
||||||
|
|
||||||
local SpawnTemplate = self:GetTemplate()
|
-- Coordinate of the airbase.
|
||||||
|
local AirbaseCoord=airbase:GetCoordinate()
|
||||||
|
|
||||||
|
-- Spawn template.
|
||||||
|
SpawnTemplate = SpawnTemplate or self:GetTemplate()
|
||||||
|
|
||||||
if SpawnTemplate then
|
if SpawnTemplate then
|
||||||
|
|
||||||
@@ -1391,78 +1410,61 @@ function GROUP:RespawnAtAirbase( AirbaseRespawn, Takeoff, TakeoffAltitude ) -- R
|
|||||||
SpawnPoint.helipadId = nil
|
SpawnPoint.helipadId = nil
|
||||||
SpawnPoint.airdromeId = nil
|
SpawnPoint.airdromeId = nil
|
||||||
|
|
||||||
local AirbaseID = AirbaseRespawn:GetID()
|
local AirbaseID = airbase:GetID()
|
||||||
local AirbaseCategory = AirbaseRespawn:GetDesc().category
|
local AirbaseCategory = airbase:GetDesc().category
|
||||||
|
|
||||||
self:F( { AirbaseCategory = AirbaseCategory, Ship = Airbase.Category.SHIP, Helipad = Airbase.Category.HELIPAD, Airdrome = Airbase.Category.AIRDROME } )
|
self:F( { AirbaseCategory = AirbaseCategory, Ship = Airbase.Category.SHIP, Helipad = Airbase.Category.HELIPAD, Airdrome = Airbase.Category.AIRDROME } )
|
||||||
|
|
||||||
if AirbaseCategory == Airbase.Category.SHIP then
|
if AirbaseCategory == Airbase.Category.SHIP or AirbaseCategory == Airbase.Category.HELIPAD then
|
||||||
SpawnPoint.linkUnit = AirbaseID
|
SpawnPoint.linkUnit = AirbaseID
|
||||||
SpawnPoint.helipadId = AirbaseID
|
|
||||||
elseif AirbaseCategory == Airbase.Category.HELIPAD then
|
|
||||||
SpawnPoint.linkUnit = AirbaseID
|
|
||||||
SpawnPoint.helipadId = AirbaseID
|
SpawnPoint.helipadId = AirbaseID
|
||||||
elseif AirbaseCategory == Airbase.Category.AIRDROME then
|
elseif AirbaseCategory == Airbase.Category.AIRDROME then
|
||||||
SpawnPoint.airdromeId = AirbaseID
|
SpawnPoint.airdromeId = AirbaseID
|
||||||
end
|
end
|
||||||
|
|
||||||
SpawnPoint.alt = 0
|
SpawnPoint.alt = AirbaseCoord:GetLandHeight()
|
||||||
|
SpawnPoint.type = GROUPTEMPLATE.Takeoff[Takeoff][1] -- type
|
||||||
SpawnPoint.type = GROUPTEMPLATE.Takeoff[Takeoff][1] -- type
|
|
||||||
SpawnPoint.action = GROUPTEMPLATE.Takeoff[Takeoff][2] -- action
|
SpawnPoint.action = GROUPTEMPLATE.Takeoff[Takeoff][2] -- action
|
||||||
|
|
||||||
|
-- Get the units of the group.
|
||||||
|
local units=self:GetUnits()
|
||||||
|
|
||||||
-- Translate the position of the Group Template to the Vec3.
|
for UnitID,_unit in pairs(units) do
|
||||||
for UnitID = 1, #SpawnTemplate.units do
|
|
||||||
self:T( 'Before Translation SpawnTemplate.units['..UnitID..'].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units['..UnitID..'].y = ' .. SpawnTemplate.units[UnitID].y )
|
|
||||||
|
|
||||||
-- These cause a lot of confusion.
|
local unit=_unit --Wrapper.Unit#UNIT
|
||||||
local UnitTemplate = SpawnTemplate.units[UnitID]
|
|
||||||
|
|
||||||
UnitTemplate.parking = 15
|
-- Get closest parking spot of current unit. Note that we look for occupied spots since the unit is currently sitting on it!
|
||||||
UnitTemplate.parking_id = "30"
|
local Parkingspot, TermialID, Distance=unit:GetCoordinate():GetClosestParkingSpot(airbase)
|
||||||
UnitTemplate.alt = 0
|
|
||||||
|
|
||||||
local SX = UnitTemplate.x
|
Parkingspot:MarkToAll("parking spot")
|
||||||
local SY = UnitTemplate.y
|
env.info(string.format("FF closest parking spot distance = %s, terminal ID=%s", tostring(Distance), tostring(TermialID)))
|
||||||
local BX = SpawnPoint.x
|
|
||||||
local BY = SpawnPoint.y
|
|
||||||
local TX = PointVec3.x + ( SX - BX )
|
|
||||||
local TY = PointVec3.z + ( SY - BY )
|
|
||||||
|
|
||||||
UnitTemplate.x = TX
|
-- TODO: Hmm, maybe this mixes up heterogenious groups since the order of the units is not the same as in the template.
|
||||||
UnitTemplate.y = TY
|
SpawnTemplate.units[UnitID].x = Parkingspot.x
|
||||||
|
SpawnTemplate.units[UnitID].y = Parkingspot.z
|
||||||
|
SpawnTemplate.units[UnitID].alt = Parkingspot.y
|
||||||
|
|
||||||
|
SpawnTemplate.units[UnitID].parking = TermialID
|
||||||
|
SpawnTemplate.units[UnitID].parking_id = nil
|
||||||
|
|
||||||
if Takeoff == GROUP.Takeoff.Air then
|
|
||||||
UnitTemplate.alt = PointVec3.y + ( TakeoffAltitude or 200 )
|
|
||||||
--else
|
|
||||||
-- UnitTemplate.alt = PointVec3.y + 10
|
|
||||||
end
|
|
||||||
self:T( 'After Translation SpawnTemplate.units['..UnitID..'].x = ' .. UnitTemplate.x .. ', SpawnTemplate.units['..UnitID..'].y = ' .. UnitTemplate.y )
|
|
||||||
end
|
end
|
||||||
|
|
||||||
SpawnPoint.x = PointVec3.x
|
SpawnPoint.x = AirbaseCoord.x
|
||||||
SpawnPoint.y = PointVec3.z
|
SpawnPoint.y = AirbaseCoord.z
|
||||||
|
|
||||||
if Takeoff == GROUP.Takeoff.Air then
|
SpawnTemplate.x = AirbaseCoord.x
|
||||||
SpawnPoint.alt = PointVec3.y + ( TakeoffAltitude or 200 )
|
SpawnTemplate.y = AirbaseCoord.z
|
||||||
--else
|
|
||||||
-- SpawnPoint.alt = PointVec3.y + 10
|
|
||||||
end
|
|
||||||
|
|
||||||
SpawnTemplate.x = PointVec3.x
|
SpawnTemplate.uncontrolled=Uncontrolled
|
||||||
SpawnTemplate.y = PointVec3.z
|
|
||||||
|
|
||||||
local GroupSpawned = self:Respawn( SpawnTemplate )
|
self:Destroy()
|
||||||
|
_DATABASE:Spawn( SpawnTemplate )
|
||||||
|
|
||||||
-- When spawned in the air, we need to generate a Takeoff Event
|
self:ResetEvents()
|
||||||
|
|
||||||
if Takeoff == GROUP.Takeoff.Air then
|
--local GroupSpawned = self:Respawn( SpawnTemplate )
|
||||||
for UnitID, UnitSpawned in pairs( GroupSpawned:GetUnits() ) do
|
|
||||||
SCHEDULER:New( nil, BASE.CreateEventTakeoff, { GroupSpawned, timer.getTime(), UnitSpawned:GetDCSObject() } , 1 )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return GroupSpawned
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ AI/AI_Cargo_Dispatcher.lua
|
|||||||
AI/AI_Cargo_Dispatcher_APC.lua
|
AI/AI_Cargo_Dispatcher_APC.lua
|
||||||
AI/AI_Cargo_Dispatcher_Helicopter.lua
|
AI/AI_Cargo_Dispatcher_Helicopter.lua
|
||||||
AI/AI_Cargo_Dispatcher_Airplane.lua
|
AI/AI_Cargo_Dispatcher_Airplane.lua
|
||||||
AI/AI_G2G_Dispatcher.lua
|
|
||||||
|
|
||||||
Actions/Act_Assign.lua
|
Actions/Act_Assign.lua
|
||||||
Actions/Act_Route.lua
|
Actions/Act_Route.lua
|
||||||
|
|||||||
Reference in New Issue
Block a user