mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Warehouse and other things
This commit is contained in:
parent
d3273b631f
commit
d53c444c62
@ -51,34 +51,41 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet )
|
||||
--- Pickup Handler OnBefore for AI_CARGO_AIRPLANE
|
||||
-- @function [parent=#AI_CARGO_AIRPLANE] OnBeforePickup
|
||||
-- @param #AI_CARGO_AIRPLANE self
|
||||
-- @param #string From
|
||||
-- @param #string Event
|
||||
-- @param #string To
|
||||
-- @param Wrapper.Group#GROUP Airplane Cargo transport plane.
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase where troops are picked up.
|
||||
-- @param #number Speed in km/h for travelling to pickup base.
|
||||
-- @return #boolean
|
||||
|
||||
--- Pickup Handler OnAfter for AI_CARGO_AIRPLANE
|
||||
-- @function [parent=#AI_CARGO_AIRPLANE] OnAfterPickup
|
||||
-- @param #AI_CARGO_AIRPLANE self
|
||||
-- @param Wrapper.Group#GROUP Airplane Cargo plane.
|
||||
-- @param #string From
|
||||
-- @param #string Event
|
||||
-- @param #string To
|
||||
-- @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
|
||||
-- @function [parent=#AI_CARGO_AIRPLANE] Pickup
|
||||
-- @param #AI_CARGO_AIRPLANE self
|
||||
-- @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
|
||||
-- @function [parent=#AI_CARGO_AIRPLANE] __Pickup
|
||||
-- @param #AI_CARGO_AIRPLANE self
|
||||
-- @param #number Delay Delay in seconds.
|
||||
-- @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
|
||||
-- @function [parent=#AI_CARGO_AIRPLANE] OnBeforeDeploy
|
||||
-- @param #AI_CARGO_AIRPLANE self
|
||||
-- @param Wrapper.Group#GROUP Airplane Cargo plane.
|
||||
-- @param #string From
|
||||
-- @param #string Event
|
||||
-- @param #string To
|
||||
@ -89,6 +96,7 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet )
|
||||
--- Deploy Handler OnAfter for AI_CARGO_AIRPLANE
|
||||
-- @function [parent=#AI_CARGO_AIRPLANE] OnAfterDeploy
|
||||
-- @param #AI_CARGO_AIRPLANE self
|
||||
-- @param Wrapper.Group#GROUP Airplane Cargo plane.
|
||||
-- @param #string From
|
||||
-- @param #string Event
|
||||
-- @param #string To
|
||||
@ -107,7 +115,16 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet )
|
||||
-- @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.
|
||||
|
||||
--- 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 )
|
||||
|
||||
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 Wrapper.Group#GROUP Airplane
|
||||
-- @return #AI_CARGO_AIRPLANE
|
||||
-- @param Wrapper.Group#GROUP Airplane Transport plane.
|
||||
-- @return #AI_CARGO_AIRPLANE self
|
||||
function AI_CARGO_AIRPLANE:SetCarrier( Airplane )
|
||||
|
||||
local AICargo = self
|
||||
@ -184,7 +201,7 @@ end
|
||||
|
||||
--- Find a free Carrier within a range.
|
||||
-- @param #AI_CARGO_AIRPLANE self
|
||||
-- @param Wrapper.Airbase#AIRBASE Airbase
|
||||
-- @param Wrapper.Airbase#AIRBASE Airbase
|
||||
-- @param #number Radius
|
||||
-- @return Wrapper.Group#GROUP NewCarrier
|
||||
function AI_CARGO_AIRPLANE:FindCarrier( Coordinate, Radius )
|
||||
@ -206,9 +223,9 @@ function AI_CARGO_AIRPLANE:FindCarrier( Coordinate, Radius )
|
||||
|
||||
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 Wrapper.Group#GROUP Airplane Transport plane.
|
||||
-- @param Wrapper.Group#GROUP Airplane Cargo transport plane.
|
||||
-- @param From
|
||||
-- @param Event
|
||||
-- @param To
|
||||
@ -220,11 +237,13 @@ function AI_CARGO_AIRPLANE:onafterLanded( Airplane, From, Event, To )
|
||||
|
||||
if Airplane and Airplane:IsAlive() then
|
||||
|
||||
-- Aircraft was sent to this airbase to pickup troops. Initiate loadling.
|
||||
if self.RoutePickup == true then
|
||||
self:Load( Airplane:GetPointVec2() )
|
||||
self.RoutePickup = false
|
||||
end
|
||||
|
||||
-- Aircraft was send to this airbase to deploy troops. Initiate unloading.
|
||||
if self.RouteDeploy == true then
|
||||
self:Unload()
|
||||
self.RouteDeploy = false
|
||||
@ -237,48 +256,66 @@ end
|
||||
|
||||
--- On after "Pickup" event. Routes transport to pickup 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.Group#GROUP Airplane Cargo transport plane.
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param Wrapper.Airbase#AIRBASE Airbase Airbase where the troops as picked up.
|
||||
-- @param #number Speed in km/h for travelling to pickup base.
|
||||
function AI_CARGO_AIRPLANE:onafterPickup( Airplane, From, Event, To, Airbase, Speed )
|
||||
|
||||
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
|
||||
self:Route( Airplane, Airbase, Speed )
|
||||
self.Airbase=nil
|
||||
else
|
||||
self.Airbase=Airplane:GetCoordinate():GetClosestAirbase()
|
||||
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.
|
||||
self.Airbase = Airbase
|
||||
|
||||
-- Aircraft is on a pickup mission.
|
||||
self.RoutePickup = true
|
||||
|
||||
-- Unclear!?
|
||||
self.Transporting = true
|
||||
self.Relocating = false
|
||||
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 Wrapper.Group#GROUP Airplane
|
||||
-- @param From
|
||||
-- @param Event
|
||||
-- @param To
|
||||
-- @param Wrapper.Group#GROUP Airplane Cargo transport plane.
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @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
|
||||
if Airplane and Airplane:IsAlive()~=nil then
|
||||
|
||||
-- Activate uncontrolled airplane.
|
||||
if Airplane:IsAlive()==false then
|
||||
Airplane:SetCommand({id = 'Start', params = {}})
|
||||
end
|
||||
|
||||
-- Route to destination airbase.
|
||||
self:Route( Airplane, Airbase, Speed )
|
||||
|
||||
-- Aircraft is on a depoly mission.
|
||||
self.RouteDeploy = true
|
||||
|
||||
-- Set destination airbase for next :Route() command.
|
||||
self.Airbase = Airbase
|
||||
|
||||
-- Unclear?!
|
||||
self.Transporting = false
|
||||
self.Relocating = false
|
||||
end
|
||||
@ -286,17 +323,16 @@ function AI_CARGO_AIRPLANE:onafterDeploy( Airplane, From, Event, To, Airbase, Sp
|
||||
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 Wrapper.Group#GROUP Airplane Transport plane.
|
||||
-- @param From
|
||||
-- @param Event
|
||||
-- @param To
|
||||
-- @param Wrapper.Point#COORDINATE Coordinate
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @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 )
|
||||
|
||||
if Airplane and Airplane:IsAlive()==true or Airplane:IsAlive()==false then
|
||||
--if Airplane then
|
||||
if Airplane and Airplane:IsAlive()~=nil then
|
||||
|
||||
for _, Cargo in pairs( self.CargoSet:GetSet() ) do
|
||||
self:F({Cargo:GetName()})
|
||||
@ -313,12 +349,12 @@ function AI_CARGO_AIRPLANE:onafterLoad( Airplane, From, Event, To, Coordinate )
|
||||
|
||||
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 Wrapper.Group#GROUP Airplane Cargo plane.
|
||||
-- @param From
|
||||
-- @param Event
|
||||
-- @param To
|
||||
-- @param Wrapper.Group#GROUP Airplane Cargo transport plane.
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function AI_CARGO_AIRPLANE:onafterBoard( Airplane, From, Event, To )
|
||||
|
||||
if Airplane and Airplane:IsAlive() then
|
||||
@ -332,26 +368,28 @@ function AI_CARGO_AIRPLANE:onafterBoard( Airplane, From, Event, To )
|
||||
|
||||
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 Wrapper.Group#GROUP Airplane Cargo plane.
|
||||
-- @param From
|
||||
-- @param Event
|
||||
-- @param To
|
||||
-- @param Wrapper.Group#GROUP Airplane Cargo transport plane.
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function AI_CARGO_AIRPLANE:onafterLoaded( Airplane, From, Event, To )
|
||||
|
||||
env.info("FF troops loaded into cargo plane")
|
||||
|
||||
if Airplane and Airplane:IsAlive() then
|
||||
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 Wrapper.Group#GROUP Airplane Cargo plane.
|
||||
-- @param From
|
||||
-- @param Event
|
||||
-- @param To
|
||||
-- @param Wrapper.Group#GROUP Airplane Cargo transport plane.
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function AI_CARGO_AIRPLANE:onafterUnload( Airplane, From, Event, To )
|
||||
|
||||
if Airplane and Airplane:IsAlive() then
|
||||
@ -361,12 +399,12 @@ function AI_CARGO_AIRPLANE:onafterUnload( Airplane, From, Event, To )
|
||||
|
||||
end
|
||||
|
||||
--- On after Unboard event.
|
||||
--- On after Unboard event. Checks if unboarding process is finished.
|
||||
-- @param #AI_CARGO_AIRPLANE self
|
||||
-- @param Wrapper.Group#GROUP Airplane Cargo plane.
|
||||
-- @param From
|
||||
-- @param Event
|
||||
-- @param To
|
||||
-- @param Wrapper.Group#GROUP Airplane Cargo transport plane.
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function AI_CARGO_AIRPLANE:onafterUnboard( Airplane, From, Event, To )
|
||||
|
||||
if Airplane and Airplane:IsAlive() then
|
||||
@ -379,12 +417,12 @@ function AI_CARGO_AIRPLANE:onafterUnboard( Airplane, From, Event, To )
|
||||
|
||||
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 Wrapper.Group#GROUP Airplane Cargo plane.
|
||||
-- @param From
|
||||
-- @param Event
|
||||
-- @param To
|
||||
-- @param Wrapper.Group#GROUP Airplane Cargo transport plane.
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function AI_CARGO_AIRPLANE:onafterUnloaded( Airplane, From, Event, To )
|
||||
|
||||
if Airplane and Airplane:IsAlive() then
|
||||
@ -393,119 +431,75 @@ function AI_CARGO_AIRPLANE:onafterUnloaded( Airplane, From, Event, To )
|
||||
|
||||
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
|
||||
-- @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()~=nil then
|
||||
|
||||
if Airplane and Airplane:IsAlive() then
|
||||
|
||||
local PointVec3 = Airplane:GetPointVec3()
|
||||
|
||||
local Takeoff = SPAWN.Takeoff.Hot
|
||||
-- Set takeoff type.
|
||||
local Takeoff = SPAWN.Takeoff.Cold
|
||||
|
||||
-- Get template of group.
|
||||
local Template = Airplane:GetTemplate()
|
||||
|
||||
if Template then
|
||||
|
||||
local Points = {}
|
||||
|
||||
if self.Airbase then
|
||||
|
||||
local FromWaypoint = Template.route.points[1]
|
||||
|
||||
-- These are only for ships.
|
||||
FromWaypoint.linkUnit = nil
|
||||
FromWaypoint.helipadId = nil
|
||||
FromWaypoint.airdromeId = nil
|
||||
|
||||
local ParkingSpots = self.Airbase:FindFreeParkingSpotForAircraft( Airplane, AIRBASE.TerminalType.OpenBig )
|
||||
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.
|
||||
for UnitID = 1, #Template.units do
|
||||
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.
|
||||
local UnitTemplate = Template.units[UnitID]
|
||||
|
||||
UnitTemplate.parking = nil
|
||||
UnitTemplate.parking_id = nil
|
||||
UnitTemplate.alt = 0
|
||||
|
||||
local SX = UnitTemplate.x
|
||||
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
|
||||
UnitTemplate.y = TY
|
||||
|
||||
self:T( 'After Translation SpawnTemplate.units['..UnitID..'].x = ' .. UnitTemplate.x .. ', SpawnTemplate.units['..UnitID..'].y = ' .. UnitTemplate.y )
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
Template.x = PointVec3.x
|
||||
Template.y = PointVec3.z
|
||||
|
||||
self:T3( Points )
|
||||
Template.route.points = Points
|
||||
|
||||
Template.uncontrolled=false
|
||||
|
||||
--self:Respawn( Template )
|
||||
|
||||
local GroupSpawned = Airplane:Respawn( Template )
|
||||
|
||||
return GroupSpawned
|
||||
-- Nil check
|
||||
if Template==nil then
|
||||
return
|
||||
end
|
||||
|
||||
end
|
||||
-- Waypoints of the route.
|
||||
local Points={}
|
||||
|
||||
-- To point.
|
||||
local AirbasePointVec2 = Airbase:GetPointVec2()
|
||||
local ToWaypoint = AirbasePointVec2:WaypointAir(
|
||||
POINT_VEC3.RoutePointAltType.BARO,
|
||||
"Land",
|
||||
"Landing",
|
||||
Speed or Airplane:GetSpeedMax()*0.8
|
||||
)
|
||||
ToWaypoint["airdromeId"] = Airbase:GetID()
|
||||
ToWaypoint["speed_locked"] = true
|
||||
|
||||
|
||||
-- If self.Airbase~=nil then group is currently at an airbase, where it should be respawned.
|
||||
if self.Airbase then
|
||||
|
||||
-- Second point of the route. First point is done in RespawnAtCurrentAirbase() routine.
|
||||
Template.route.points[2] = ToWaypoint
|
||||
|
||||
-- Respawn group at the current airbase.
|
||||
Airplane:RespawnAtCurrentAirbase(Template, Takeoff, Uncontrolled)
|
||||
|
||||
else
|
||||
|
||||
-- From point.
|
||||
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
|
||||
|
||||
-- The two route points.
|
||||
Points[1] = FromWaypoint
|
||||
Points[2] = ToWaypoint
|
||||
|
||||
local PointVec3 = Airplane:GetPointVec3()
|
||||
Template.x = PointVec3.x
|
||||
Template.y = PointVec3.z
|
||||
|
||||
Template.route.points = Points
|
||||
|
||||
local GroupSpawned = Airplane:Respawn(Template)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -29,11 +29,11 @@ AI_CARGO_DISPATCHER_AIRPLANE = {
|
||||
|
||||
--- Creates a new AI_CARGO_DISPATCHER_AIRPLANE object.
|
||||
-- @param #AI_CARGO_DISPATCHER_AIRPLANE self
|
||||
-- @param Core.Set#SET_GROUP SetAirplanes
|
||||
-- @param Core.Set#SET_CARGO SetCargos
|
||||
-- @param Core.Set#SET_AIRBASE PickupAirbasesSet
|
||||
-- @param Core.Set#SET_AIRBASE DeployAirbasesSet
|
||||
-- @return #AI_CARGO_DISPATCHER_AIRPLANE
|
||||
-- @param Core.Set#SET_GROUP SetAirplanes Set of cargo transport airplanes.
|
||||
-- @param Core.Set#SET_CARGO SetCargos Set of cargo, which is supposed to be transported.
|
||||
-- @param Core.Set#SET_AIRBASE PickupAirbasesSet Set of airbases where the cargo has to be picked up.
|
||||
-- @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 self
|
||||
-- @usage
|
||||
--
|
||||
-- -- 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 To
|
||||
-- @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 )
|
||||
self:F()
|
||||
|
||||
@ -1218,6 +1222,7 @@ end
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @param #string To
|
||||
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||
-- @param #number Speed
|
||||
-- @param #number UnLoadDistance
|
||||
-- @param #number UnBoardDistance
|
||||
@ -1261,6 +1266,7 @@ end
|
||||
-- @param #string From
|
||||
-- @param #string To
|
||||
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||
-- @param #number Speed
|
||||
function CARGO_PACKAGE:onafterUnBoarded( From, Event, To, CargoCarrier, Speed )
|
||||
self:F()
|
||||
|
||||
@ -1304,6 +1310,8 @@ end
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @param #string To
|
||||
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||
-- @param #number Speed
|
||||
-- @param #number Distance
|
||||
-- @param #number 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 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.
|
||||
function CARGO_GROUP:New( CargoGroup, Type, Name, LoadRadius )
|
||||
local self = BASE:Inherit( self, CARGO_REPORTABLE:New( Type, Name, 0, LoadRadius ) ) -- #CARGO_GROUP
|
||||
function CARGO_GROUP:New( CargoGroup, Type, Name, LoadRadius, NearRadius )
|
||||
local self = BASE:Inherit( self, CARGO_REPORTABLE:New( Type, Name, 0, LoadRadius, NearRadius ) ) -- #CARGO_GROUP
|
||||
self:F( { Type, Name, LoadRadius } )
|
||||
|
||||
self.CargoSet = SET_CARGO:New()
|
||||
@ -98,7 +98,7 @@ do -- CARGO_GROUP
|
||||
local Unit = UNIT:Register( CargoUnitName )
|
||||
--local WeightUnit = Unit:GetDesc().massEmpty
|
||||
--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 )
|
||||
end
|
||||
|
||||
@ -257,10 +257,11 @@ do -- CARGO_GROUP
|
||||
|
||||
--- Enter Boarding State.
|
||||
-- @param #CARGO_GROUP self
|
||||
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @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, ... )
|
||||
--self:F( { CargoCarrier.UnitName, From, Event, To } )
|
||||
|
||||
@ -303,11 +304,12 @@ do -- CARGO_GROUP
|
||||
end
|
||||
|
||||
--- Leave Boarding State.
|
||||
-- @param #CARGO_GROUP self
|
||||
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||
-- @param #CARGO_GROUP self
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @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, ... )
|
||||
--self:F( { CargoCarrier.UnitName, From, Event, To } )
|
||||
|
||||
@ -359,10 +361,11 @@ do -- CARGO_GROUP
|
||||
|
||||
--- Enter UnBoarding State.
|
||||
-- @param #CARGO_GROUP self
|
||||
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @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, ... )
|
||||
self:F( {From, Event, To, ToPointVec2, NearRadius } )
|
||||
|
||||
@ -401,10 +404,11 @@ do -- CARGO_GROUP
|
||||
|
||||
--- Leave UnBoarding State.
|
||||
-- @param #CARGO_GROUP self
|
||||
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @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, ... )
|
||||
--self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
||||
|
||||
@ -438,10 +442,11 @@ do -- CARGO_GROUP
|
||||
|
||||
--- UnBoard Event.
|
||||
-- @param #CARGO_GROUP self
|
||||
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @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, ... )
|
||||
--self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
||||
|
||||
@ -454,10 +459,10 @@ do -- CARGO_GROUP
|
||||
|
||||
--- Enter UnLoaded State.
|
||||
-- @param #CARGO_GROUP self
|
||||
-- @param Core.Point#POINT_VEC2
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @param #string To
|
||||
-- @param Core.Point#POINT_VEC2
|
||||
function CARGO_GROUP:onenterUnLoaded( From, Event, To, ToPointVec2, ... )
|
||||
--self:F( { From, Event, To, ToPointVec2 } )
|
||||
|
||||
@ -467,7 +472,7 @@ do -- CARGO_GROUP
|
||||
self.CargoSet:ForEach(
|
||||
function( Cargo )
|
||||
--Cargo:UnLoad( ToPointVec2 )
|
||||
local RandomVec2=ToPointVec2:GetRandomPointVec2InRadius(10)
|
||||
local RandomVec2=ToPointVec2:GetRandomPointVec2InRadius(20, 10)
|
||||
Cargo:UnLoad( RandomVec2 )
|
||||
end
|
||||
)
|
||||
@ -592,8 +597,7 @@ do -- CARGO_GROUP
|
||||
-- @param #CARGO_GROUP self
|
||||
-- @param Wrapper.Group#GROUP CargoCarrier
|
||||
-- @param #number NearRadius
|
||||
-- @return #boolean The Cargo is near to the Carrier.
|
||||
-- @return #nil The Cargo is not near to the Carrier.
|
||||
-- @return #boolean The Cargo is near to the Carrier or #nil if the Cargo is not near to the Carrier.
|
||||
function CARGO_GROUP:IsNear( CargoCarrier, NearRadius )
|
||||
self:F( {NearRadius = NearRadius } )
|
||||
|
||||
|
||||
@ -42,9 +42,9 @@ do -- CARGO_UNIT
|
||||
-- @param #number LoadRadius (optional)
|
||||
-- @param #number NearRadius (optional)
|
||||
-- @return #CARGO_UNIT
|
||||
function CARGO_UNIT:New( CargoUnit, Type, Name, Weight, NearRadius )
|
||||
local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoUnit, Type, Name, Weight, NearRadius ) ) -- #CARGO_UNIT
|
||||
self:I( { 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, LoadRadius, NearRadius ) ) -- #CARGO_UNIT
|
||||
self:I( { Type, Name, Weight, LoadRadius, NearRadius } )
|
||||
|
||||
self:T( CargoUnit )
|
||||
self.CargoObject = CargoUnit
|
||||
@ -62,6 +62,7 @@ do -- CARGO_UNIT
|
||||
-- @param #string From
|
||||
-- @param #string To
|
||||
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
||||
-- @param #number NearRadius (optional) Defaut 25 m.
|
||||
function CARGO_UNIT:onenterUnBoarding( From, Event, To, ToPointVec2, NearRadius )
|
||||
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
||||
|
||||
@ -131,6 +132,7 @@ do -- CARGO_UNIT
|
||||
-- @param #string From
|
||||
-- @param #string To
|
||||
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
||||
-- @param #number NearRadius (optional) Defaut 100 m.
|
||||
function CARGO_UNIT:onleaveUnBoarding( From, Event, To, ToPointVec2, NearRadius )
|
||||
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
||||
|
||||
@ -158,6 +160,7 @@ do -- CARGO_UNIT
|
||||
-- @param #string From
|
||||
-- @param #string To
|
||||
-- @param Core.Point#POINT_VEC2 ToPointVec2
|
||||
-- @param #number NearRadius (optional) Defaut 100 m.
|
||||
function CARGO_UNIT:onafterUnBoarding( From, Event, To, ToPointVec2, NearRadius )
|
||||
self:F( { From, Event, To, ToPointVec2, NearRadius } )
|
||||
|
||||
@ -281,7 +284,7 @@ do -- CARGO_UNIT
|
||||
-- @param #string From
|
||||
-- @param #string To
|
||||
-- @param Wrapper.Client#CLIENT CargoCarrier
|
||||
-- @param #number NearRadius
|
||||
-- @param #number NearRadius Default 25 m.
|
||||
function CARGO_UNIT:onafterBoarding( From, Event, To, CargoCarrier, NearRadius, ... )
|
||||
--self:F( { From, Event, To, CargoCarrier.UnitName, NearRadius } )
|
||||
|
||||
@ -338,6 +341,7 @@ do -- CARGO_UNIT
|
||||
-- @param #string From
|
||||
-- @param #string To
|
||||
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||
-- @param #number NearRadius Default 25 m.
|
||||
function CARGO_UNIT:onenterBoarding( From, Event, To, CargoCarrier, NearRadius, ... )
|
||||
--self:F( { From, Event, To, CargoCarrier.UnitName, NearRadius } )
|
||||
|
||||
|
||||
@ -1095,6 +1095,37 @@ do -- COORDINATE
|
||||
|
||||
return RoutePoint
|
||||
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.
|
||||
-- @param #COORDINATE self
|
||||
|
||||
@ -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 _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)
|
||||
|
||||
--[[
|
||||
-- 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.
|
||||
if #_instock==0 and TransportType~=WAREHOUSE.TransportType.SELFPROPELLED then
|
||||
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
|
||||
end
|
||||
|
||||
-- TODO: For aircraft check that a parking spot is available.
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
@ -406,6 +388,7 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass
|
||||
self:_DeleteStockItem(_id)
|
||||
end
|
||||
|
||||
-- No transport unit requested. Assets go by themselfes.
|
||||
if TransportType==WAREHOUSE.TransportType.SELFPROPELLED then
|
||||
for _i,_spawngroup in pairs(_spawngroups) do
|
||||
local group=_spawngroup --Wrapper.Group#GROUP
|
||||
@ -415,13 +398,12 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass
|
||||
end
|
||||
|
||||
|
||||
--TODO: naje nearradius depended on types.
|
||||
--TODO: make nearradius depended on transport type and asset type.
|
||||
local _loadradius=5000
|
||||
local _nearradius=35
|
||||
|
||||
-- Add spawned groups to cargo group object.
|
||||
for _i,_spawngroup in pairs(_spawngroups) do
|
||||
--TODO: check near and load radius.
|
||||
local _name=string.format("%s %d",AssetDescriptorValue, _i)
|
||||
env.info(string.format("FF cargo group %d: %s",_i,_name))
|
||||
local cargogroup = CARGO_GROUP:New(_spawngroup, AssetDescriptorValue, _name, _loadradius, _nearradius)
|
||||
@ -430,8 +412,6 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass
|
||||
|
||||
env.info(string.format("FF cargo set object names %s", CargoGroups:GetObjectNames()))
|
||||
|
||||
|
||||
|
||||
|
||||
-- Filter the requested assets.
|
||||
local _transportitem --#WAREHOUSE.Stockitem
|
||||
@ -452,8 +432,8 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass
|
||||
if Plane==nil then
|
||||
-- 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."
|
||||
--self:__Request(60, Airbase, AssetDescriptor, AssetDescriptorValue, nAsset, TransportType)
|
||||
--TODO: despawn units and but them back into the warehouse.
|
||||
MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.Report or self.Debug)
|
||||
--TODO: Despawn asset units and but them back into the warehouse.
|
||||
return
|
||||
else
|
||||
-- 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.
|
||||
function CargoPlane:OnAfterLoaded(Airplane, From, Event, To)
|
||||
CargoPlane:__Deploy(10, Airbase, 500)
|
||||
CargoPlane:__Deploy(10, Airbase)
|
||||
end
|
||||
|
||||
--- Function called when cargo has arrived and was unloaded.
|
||||
@ -520,8 +500,7 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass
|
||||
-- Trigger Delivered event.
|
||||
warehouse:__Delivered(1, group)
|
||||
end
|
||||
|
||||
|
||||
|
||||
elseif TransportType==WAREHOUSE.TransportType.APC then
|
||||
|
||||
-- Spawn APC in spawn zone.
|
||||
@ -574,12 +553,10 @@ end
|
||||
-- @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)
|
||||
env.info("FF warehouse cargo delivered! Croutine to closest point on road")
|
||||
local road=Group:GetCoordinate():GetClosestPointToRoad()
|
||||
local speed=Group:GetSpeedMax()*0.5
|
||||
local speed=Group:GetSpeedMax()*0.6
|
||||
Group:RouteGroundTo(road, speed, "Off Road")
|
||||
end
|
||||
|
||||
|
||||
@ -1372,97 +1372,99 @@ function GROUP:Respawn( Template, Reset )
|
||||
end
|
||||
|
||||
|
||||
--- @param Wrapper.Group#GROUP self
|
||||
function GROUP:RespawnAtAirbase( AirbaseRespawn, Takeoff, TakeoffAltitude ) -- R2.4
|
||||
self:F( { AirbaseRespawn, Takeoff, TakeoffAltitude } )
|
||||
|
||||
local PointVec3 = AirbaseRespawn:GetPointVec3()
|
||||
--- Respawn a group at an airbase.
|
||||
-- Note that the group has to be on parking spots at the airbase already in order for this to work.
|
||||
-- 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} )
|
||||
|
||||
-- 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
|
||||
|
||||
local SpawnTemplate = self:GetTemplate()
|
||||
-- Coordinate of the airbase.
|
||||
local AirbaseCoord=airbase:GetCoordinate()
|
||||
|
||||
-- Spawn template.
|
||||
SpawnTemplate = SpawnTemplate or self:GetTemplate()
|
||||
|
||||
if SpawnTemplate then
|
||||
|
||||
local SpawnPoint = SpawnTemplate.route.points[1]
|
||||
local SpawnPoint = SpawnTemplate.route.points[1]
|
||||
|
||||
-- These are only for ships.
|
||||
SpawnPoint.linkUnit = nil
|
||||
SpawnPoint.helipadId = nil
|
||||
SpawnPoint.airdromeId = nil
|
||||
|
||||
local AirbaseID = AirbaseRespawn:GetID()
|
||||
local AirbaseCategory = AirbaseRespawn:GetDesc().category
|
||||
local AirbaseID = airbase:GetID()
|
||||
local AirbaseCategory = airbase:GetDesc().category
|
||||
|
||||
self:F( { AirbaseCategory = AirbaseCategory, Ship = Airbase.Category.SHIP, Helipad = Airbase.Category.HELIPAD, Airdrome = Airbase.Category.AIRDROME } )
|
||||
|
||||
if AirbaseCategory == Airbase.Category.SHIP then
|
||||
SpawnPoint.linkUnit = AirbaseID
|
||||
SpawnPoint.helipadId = AirbaseID
|
||||
elseif AirbaseCategory == Airbase.Category.HELIPAD then
|
||||
SpawnPoint.linkUnit = AirbaseID
|
||||
if AirbaseCategory == Airbase.Category.SHIP or AirbaseCategory == Airbase.Category.HELIPAD then
|
||||
SpawnPoint.linkUnit = AirbaseID
|
||||
SpawnPoint.helipadId = AirbaseID
|
||||
elseif AirbaseCategory == Airbase.Category.AIRDROME then
|
||||
SpawnPoint.airdromeId = AirbaseID
|
||||
end
|
||||
|
||||
SpawnPoint.alt = 0
|
||||
|
||||
SpawnPoint.type = GROUPTEMPLATE.Takeoff[Takeoff][1] -- type
|
||||
SpawnPoint.alt = AirbaseCoord:GetLandHeight()
|
||||
SpawnPoint.type = GROUPTEMPLATE.Takeoff[Takeoff][1] -- type
|
||||
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 = 1, #SpawnTemplate.units do
|
||||
self:T( 'Before Translation SpawnTemplate.units['..UnitID..'].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units['..UnitID..'].y = ' .. SpawnTemplate.units[UnitID].y )
|
||||
for UnitID,_unit in pairs(units) do
|
||||
|
||||
local unit=_unit --Wrapper.Unit#UNIT
|
||||
|
||||
-- These cause a lot of confusion.
|
||||
local UnitTemplate = SpawnTemplate.units[UnitID]
|
||||
|
||||
UnitTemplate.parking = 15
|
||||
UnitTemplate.parking_id = "30"
|
||||
UnitTemplate.alt = 0
|
||||
|
||||
local SX = UnitTemplate.x
|
||||
local SY = UnitTemplate.y
|
||||
local BX = SpawnPoint.x
|
||||
local BY = SpawnPoint.y
|
||||
local TX = PointVec3.x + ( SX - BX )
|
||||
local TY = PointVec3.z + ( SY - BY )
|
||||
-- Get closest parking spot of current unit. Note that we look for occupied spots since the unit is currently sitting on it!
|
||||
local Parkingspot, TermialID, Distance=unit:GetCoordinate():GetClosestParkingSpot(airbase)
|
||||
|
||||
UnitTemplate.x = TX
|
||||
UnitTemplate.y = TY
|
||||
|
||||
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
|
||||
|
||||
SpawnPoint.x = PointVec3.x
|
||||
SpawnPoint.y = PointVec3.z
|
||||
|
||||
if Takeoff == GROUP.Takeoff.Air then
|
||||
SpawnPoint.alt = PointVec3.y + ( TakeoffAltitude or 200 )
|
||||
--else
|
||||
-- SpawnPoint.alt = PointVec3.y + 10
|
||||
end
|
||||
Parkingspot:MarkToAll("parking spot")
|
||||
env.info(string.format("FF closest parking spot distance = %s, terminal ID=%s", tostring(Distance), tostring(TermialID)))
|
||||
|
||||
SpawnTemplate.x = PointVec3.x
|
||||
SpawnTemplate.y = PointVec3.z
|
||||
|
||||
local GroupSpawned = self:Respawn( SpawnTemplate )
|
||||
|
||||
-- When spawned in the air, we need to generate a Takeoff Event
|
||||
|
||||
if Takeoff == GROUP.Takeoff.Air then
|
||||
for UnitID, UnitSpawned in pairs( GroupSpawned:GetUnits() ) do
|
||||
SCHEDULER:New( nil, BASE.CreateEventTakeoff, { GroupSpawned, timer.getTime(), UnitSpawned:GetDCSObject() } , 1 )
|
||||
end
|
||||
end
|
||||
-- TODO: Hmm, maybe this mixes up heterogenious groups since the order of the units is not the same as in the template.
|
||||
SpawnTemplate.units[UnitID].x = Parkingspot.x
|
||||
SpawnTemplate.units[UnitID].y = Parkingspot.z
|
||||
SpawnTemplate.units[UnitID].alt = Parkingspot.y
|
||||
|
||||
return GroupSpawned
|
||||
SpawnTemplate.units[UnitID].parking = TermialID
|
||||
SpawnTemplate.units[UnitID].parking_id = nil
|
||||
|
||||
end
|
||||
|
||||
SpawnPoint.x = AirbaseCoord.x
|
||||
SpawnPoint.y = AirbaseCoord.z
|
||||
|
||||
SpawnTemplate.x = AirbaseCoord.x
|
||||
SpawnTemplate.y = AirbaseCoord.z
|
||||
|
||||
SpawnTemplate.uncontrolled=Uncontrolled
|
||||
|
||||
self:Destroy()
|
||||
_DATABASE:Spawn( SpawnTemplate )
|
||||
|
||||
self:ResetEvents()
|
||||
|
||||
--local GroupSpawned = self:Respawn( SpawnTemplate )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
return nil
|
||||
|
||||
@ -77,7 +77,6 @@ AI/AI_Cargo_Dispatcher.lua
|
||||
AI/AI_Cargo_Dispatcher_APC.lua
|
||||
AI/AI_Cargo_Dispatcher_Helicopter.lua
|
||||
AI/AI_Cargo_Dispatcher_Airplane.lua
|
||||
AI/AI_G2G_Dispatcher.lua
|
||||
|
||||
Actions/Act_Assign.lua
|
||||
Actions/Act_Route.lua
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user