mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Various for AI_CARGO, CTLD, CSAR, align with dev
This commit is contained in:
@@ -47,19 +47,21 @@ function AI_CARGO:New( Carrier, CargoSet )
|
|||||||
|
|
||||||
self:SetStartState( "Unloaded" )
|
self:SetStartState( "Unloaded" )
|
||||||
|
|
||||||
self:AddTransition( "Unloaded", "Pickup", "*" )
|
-- Board
|
||||||
self:AddTransition( "Loaded", "Deploy", "*" )
|
self:AddTransition( "Unloaded", "Pickup", "Unloaded" )
|
||||||
|
self:AddTransition( "*", "Load", "*" )
|
||||||
|
self:AddTransition( "*", "Reload", "*" )
|
||||||
|
self:AddTransition( "*", "Board", "*" )
|
||||||
|
self:AddTransition( "*", "Loaded", "Loaded" )
|
||||||
|
self:AddTransition( "Loaded", "PickedUp", "Loaded" )
|
||||||
|
|
||||||
self:AddTransition( "*", "Load", "Boarding" )
|
-- Unload
|
||||||
self:AddTransition( "Boarding", "Board", "Boarding" )
|
self:AddTransition( "Loaded", "Deploy", "*" )
|
||||||
self:AddTransition( "Loaded", "Board", "Loaded" )
|
self:AddTransition( "*", "Unload", "*" )
|
||||||
self:AddTransition( "Boarding", "Loaded", "Boarding" )
|
self:AddTransition( "*", "Unboard", "*" )
|
||||||
self:AddTransition( "Boarding", "PickedUp", "Loaded" )
|
self:AddTransition( "*", "Unloaded", "Unloaded" )
|
||||||
|
self:AddTransition( "Unloaded", "Deployed", "Unloaded" )
|
||||||
|
|
||||||
self:AddTransition( "Loaded", "Unload", "Unboarding" )
|
|
||||||
self:AddTransition( "Unboarding", "Unboard", "Unboarding" )
|
|
||||||
self:AddTransition( "Unboarding", "Unloaded", "Unboarding" )
|
|
||||||
self:AddTransition( "Unboarding", "Deployed", "Unloaded" )
|
|
||||||
|
|
||||||
--- Pickup Handler OnBefore for AI_CARGO
|
--- Pickup Handler OnBefore for AI_CARGO
|
||||||
-- @function [parent=#AI_CARGO] OnBeforePickup
|
-- @function [parent=#AI_CARGO] OnBeforePickup
|
||||||
@@ -393,7 +395,7 @@ end
|
|||||||
function AI_CARGO:onafterBoard( Carrier, From, Event, To, Cargo, CarrierUnit, PickupZone )
|
function AI_CARGO:onafterBoard( Carrier, From, Event, To, Cargo, CarrierUnit, PickupZone )
|
||||||
self:F( { Carrier, From, Event, To, Cargo, CarrierUnit:GetName() } )
|
self:F( { Carrier, From, Event, To, Cargo, CarrierUnit:GetName() } )
|
||||||
|
|
||||||
if Carrier and Carrier:IsAlive() and From == "Boarding" then
|
if Carrier and Carrier:IsAlive() then
|
||||||
self:F({ IsLoaded = Cargo:IsLoaded(), Cargo:GetName(), Carrier:GetName() } )
|
self:F({ IsLoaded = Cargo:IsLoaded(), Cargo:GetName(), Carrier:GetName() } )
|
||||||
if not Cargo:IsLoaded() and not Cargo:IsDestroyed() then
|
if not Cargo:IsLoaded() and not Cargo:IsDestroyed() then
|
||||||
self:__Board( -10, Cargo, CarrierUnit, PickupZone )
|
self:__Board( -10, Cargo, CarrierUnit, PickupZone )
|
||||||
@@ -509,7 +511,7 @@ end
|
|||||||
function AI_CARGO:onafterUnboard( Carrier, From, Event, To, Cargo, CarrierUnit, DeployZone, Defend )
|
function AI_CARGO:onafterUnboard( Carrier, From, Event, To, Cargo, CarrierUnit, DeployZone, Defend )
|
||||||
self:F( { Carrier, From, Event, To, Cargo:GetName(), DeployZone = DeployZone, Defend = Defend } )
|
self:F( { Carrier, From, Event, To, Cargo:GetName(), DeployZone = DeployZone, Defend = Defend } )
|
||||||
|
|
||||||
if Carrier and Carrier:IsAlive() and From == "Unboarding" then
|
if Carrier and Carrier:IsAlive() then
|
||||||
if not Cargo:IsUnLoaded() then
|
if not Cargo:IsUnLoaded() then
|
||||||
self:__Unboard( 10, Cargo, CarrierUnit, DeployZone, Defend )
|
self:__Unboard( 10, Cargo, CarrierUnit, DeployZone, Defend )
|
||||||
return
|
return
|
||||||
@@ -580,4 +582,3 @@ function AI_CARGO:onafterDeployed( Carrier, From, Event, To, DeployZone, Defend
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,8 @@ function AI_CARGO_APC:New( APC, CargoSet, CombatRadius )
|
|||||||
self:AddTransition( "*", "Guard", "Unloaded" )
|
self:AddTransition( "*", "Guard", "Unloaded" )
|
||||||
self:AddTransition( "*", "Home", "*" )
|
self:AddTransition( "*", "Home", "*" )
|
||||||
self:AddTransition( "*", "Reload", "Boarding" )
|
self:AddTransition( "*", "Reload", "Boarding" )
|
||||||
|
self:AddTransition( "*", "Deployed", "*" )
|
||||||
|
self:AddTransition( "*", "PickedUp", "*" )
|
||||||
self:AddTransition( "*", "Destroyed", "Destroyed" )
|
self:AddTransition( "*", "Destroyed", "Destroyed" )
|
||||||
|
|
||||||
self:SetCombatRadius( CombatRadius )
|
self:SetCombatRadius( CombatRadius )
|
||||||
|
|||||||
@@ -64,21 +64,25 @@ function AI_CARGO_HELICOPTER:New( Helicopter, CargoSet )
|
|||||||
self.Zone = ZONE_GROUP:New( Helicopter:GetName(), Helicopter, 300 )
|
self.Zone = ZONE_GROUP:New( Helicopter:GetName(), Helicopter, 300 )
|
||||||
|
|
||||||
self:SetStartState( "Unloaded" )
|
self:SetStartState( "Unloaded" )
|
||||||
|
-- Boarding
|
||||||
|
self:AddTransition( "Unloaded", "Pickup", "Unloaded" )
|
||||||
|
self:AddTransition( "*", "Landed", "*" )
|
||||||
|
self:AddTransition( "*", "Load", "*" )
|
||||||
|
self:AddTransition( "*", "Loaded", "Loaded" )
|
||||||
|
self:AddTransition( "Loaded", "PickedUp", "Loaded" )
|
||||||
|
|
||||||
self:AddTransition( "Unloaded", "Pickup", "*" )
|
-- Unboarding
|
||||||
self:AddTransition( "Loaded", "Deploy", "*" )
|
self:AddTransition( "Loaded", "Deploy", "*" )
|
||||||
self:AddTransition( "*", "Loaded", "Loaded" )
|
self:AddTransition( "*", "Queue", "*" )
|
||||||
self:AddTransition( "Unboarding", "Pickup", "Unloaded" )
|
self:AddTransition( "*", "Orbit" , "*" )
|
||||||
self:AddTransition( "Unloaded", "Unboard", "Unloaded" )
|
self:AddTransition( "*", "Destroyed", "*" )
|
||||||
self:AddTransition( "Unloaded", "Unloaded", "Unloaded" )
|
self:AddTransition( "*", "Unload", "*" )
|
||||||
self:AddTransition( "*", "PickedUp", "*" )
|
self:AddTransition( "*", "Unloaded", "Unloaded" )
|
||||||
self:AddTransition( "*", "Landed", "*" )
|
self:AddTransition( "Unloaded", "Deployed", "Unloaded" )
|
||||||
self:AddTransition( "*", "Queue", "*" )
|
|
||||||
self:AddTransition( "*", "Orbit" , "*" )
|
-- RTB
|
||||||
self:AddTransition( "*", "Home" , "*" )
|
self:AddTransition( "*", "Home" , "*" )
|
||||||
|
|
||||||
self:AddTransition( "*", "Destroyed", "Destroyed" )
|
|
||||||
|
|
||||||
--- Pickup Handler OnBefore for AI_CARGO_HELICOPTER
|
--- Pickup Handler OnBefore for AI_CARGO_HELICOPTER
|
||||||
-- @function [parent=#AI_CARGO_HELICOPTER] OnBeforePickup
|
-- @function [parent=#AI_CARGO_HELICOPTER] OnBeforePickup
|
||||||
-- @param #AI_CARGO_HELICOPTER self
|
-- @param #AI_CARGO_HELICOPTER self
|
||||||
@@ -207,6 +211,9 @@ function AI_CARGO_HELICOPTER:New( Helicopter, CargoSet )
|
|||||||
|
|
||||||
self:SetCarrier( Helicopter )
|
self:SetCarrier( Helicopter )
|
||||||
|
|
||||||
|
self.landingspeed = 15 -- kph
|
||||||
|
self.landingheight = 5.5 -- meter
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -255,6 +262,25 @@ function AI_CARGO_HELICOPTER:SetCarrier( Helicopter )
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Set landingspeed and -height for helicopter landings. Adjust after tracing if your helis get stuck after landing.
|
||||||
|
-- @param #AI_CARGO_HELICOPTER self
|
||||||
|
-- @param #number speed Landing speed in kph(!), e.g. 15
|
||||||
|
-- @param #number height Landing height in meters(!), e.g. 5.5
|
||||||
|
-- @return #AI_CARGO_HELICOPTER self
|
||||||
|
-- @usage If your choppers get stuck, add tracing to your script to determine if they hit the right parameters like so:
|
||||||
|
--
|
||||||
|
-- BASE:TraceOn()
|
||||||
|
-- BASE:TraceClass("AI_CARGO_HELICOPTER")
|
||||||
|
--
|
||||||
|
-- Watch the DCS.log for entries stating `Helicopter:<name>, Height = Helicopter:<number>, Velocity = Helicopter:<number>`
|
||||||
|
-- Adjust if necessary.
|
||||||
|
function AI_CARGO_HELICOPTER:SetLandingSpeedAndHeight(speed, height)
|
||||||
|
local _speed = speed or 15
|
||||||
|
local _height = height or 5.5
|
||||||
|
self.landingheight = _height
|
||||||
|
self.landingspeed = _speed
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
--- @param #AI_CARGO_HELICOPTER self
|
--- @param #AI_CARGO_HELICOPTER self
|
||||||
-- @param Wrapper.Group#GROUP Helicopter
|
-- @param Wrapper.Group#GROUP Helicopter
|
||||||
@@ -271,13 +297,13 @@ function AI_CARGO_HELICOPTER:onafterLanded( Helicopter, From, Event, To )
|
|||||||
-- 1 - When the helo lands normally on the ground.
|
-- 1 - When the helo lands normally on the ground.
|
||||||
-- 2 - when the helo is hit and goes RTB or even when it is destroyed.
|
-- 2 - when the helo is hit and goes RTB or even when it is destroyed.
|
||||||
-- For point 2, this is an issue, the infantry may not unload in this case!
|
-- For point 2, this is an issue, the infantry may not unload in this case!
|
||||||
-- So we check if the helo is on the ground, and velocity< 5.
|
-- So we check if the helo is on the ground, and velocity< 15.
|
||||||
-- Only then the infantry can unload (and load too, for consistency)!
|
-- Only then the infantry can unload (and load too, for consistency)!
|
||||||
|
|
||||||
self:F( { Helicopter:GetName(), Height = Helicopter:GetHeight( true ), Velocity = Helicopter:GetVelocityKMH() } )
|
self:T( { Helicopter:GetName(), Height = Helicopter:GetHeight( true ), Velocity = Helicopter:GetVelocityKMH() } )
|
||||||
|
|
||||||
if self.RoutePickup == true then
|
if self.RoutePickup == true then
|
||||||
if Helicopter:GetHeight( true ) <= 5.5 and Helicopter:GetVelocityKMH() < 15 then
|
if Helicopter:GetHeight( true ) <= self.landingheight then --and Helicopter:GetVelocityKMH() < self.landingspeed then
|
||||||
--self:Load( Helicopter:GetPointVec2() )
|
--self:Load( Helicopter:GetPointVec2() )
|
||||||
self:Load( self.PickupZone )
|
self:Load( self.PickupZone )
|
||||||
self.RoutePickup = false
|
self.RoutePickup = false
|
||||||
@@ -285,7 +311,7 @@ function AI_CARGO_HELICOPTER:onafterLanded( Helicopter, From, Event, To )
|
|||||||
end
|
end
|
||||||
|
|
||||||
if self.RouteDeploy == true then
|
if self.RouteDeploy == true then
|
||||||
if Helicopter:GetHeight( true ) <= 5.5 and Helicopter:GetVelocityKMH() < 15 then
|
if Helicopter:GetHeight( true ) <= self.landingheight then --and Helicopter:GetVelocityKMH() < self.landingspeed then
|
||||||
self:Unload( self.DeployZone )
|
self:Unload( self.DeployZone )
|
||||||
self.RouteDeploy = false
|
self.RouteDeploy = false
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
--- **Ops** -- Combat Search and Rescue.
|
--- **Ops** -- Combat Search and Rescue.
|
||||||
--
|
--
|
||||||
-- ===
|
-- ===
|
||||||
@@ -1125,6 +1124,8 @@ end
|
|||||||
-- @return #boolean outcome The outcome.
|
-- @return #boolean outcome The outcome.
|
||||||
function CSAR:_IsLoadingDoorOpen( unit_name )
|
function CSAR:_IsLoadingDoorOpen( unit_name )
|
||||||
self:T(self.lid .. " _IsLoadingDoorOpen")
|
self:T(self.lid .. " _IsLoadingDoorOpen")
|
||||||
|
|
||||||
|
--[[
|
||||||
local ret_val = false
|
local ret_val = false
|
||||||
local unit = Unit.getByName(unit_name)
|
local unit = Unit.getByName(unit_name)
|
||||||
if unit ~= nil then
|
if unit ~= nil then
|
||||||
@@ -1156,8 +1157,9 @@ function CSAR:_IsLoadingDoorOpen( unit_name )
|
|||||||
return ret_val
|
return ret_val
|
||||||
|
|
||||||
end -- nil
|
end -- nil
|
||||||
|
--]]
|
||||||
|
return UTILS.IsLoadingDoorOpen(unit_name)
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- (Internal) Function to check if heli is close to group.
|
--- (Internal) Function to check if heli is close to group.
|
||||||
|
|||||||
@@ -659,6 +659,7 @@ function CTLD:New(Coalition, Prefixes, Alias)
|
|||||||
|
|
||||||
-- setup
|
-- setup
|
||||||
self.CrateDistance = 30 -- list/load crates in this radius
|
self.CrateDistance = 30 -- list/load crates in this radius
|
||||||
|
self.ExtractFactor = 3.33 -- factor for troops extraction, i.e. CrateDistance * Extractfactor
|
||||||
self.prefixes = Prefixes or {"Cargoheli"}
|
self.prefixes = Prefixes or {"Cargoheli"}
|
||||||
--self.I({prefixes = self.prefixes})
|
--self.I({prefixes = self.prefixes})
|
||||||
self.useprefix = true
|
self.useprefix = true
|
||||||
@@ -1117,7 +1118,9 @@ end
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if nearestGroup == nil or nearestDistance > self.CrateDistance then
|
local extractdistance = self.CrateDistance * self.ExtractFactor
|
||||||
|
|
||||||
|
if nearestGroup == nil or nearestDistance > extractdistance then
|
||||||
self:_SendMessage("No units close enough to extract!", 10, false, Group)
|
self:_SendMessage("No units close enough to extract!", 10, false, Group)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@@ -1165,7 +1168,7 @@ end
|
|||||||
|
|
||||||
-- clean up:
|
-- clean up:
|
||||||
table.remove(self.DroppedTroops, nearestGroupIndex)
|
table.remove(self.DroppedTroops, nearestGroupIndex)
|
||||||
nearestGroup:Destroy()
|
nearestGroup:Destroy(false)
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@@ -1390,8 +1393,13 @@ function CTLD:_LoadCratesNearby(Group, Unit)
|
|||||||
-- get nearby crates
|
-- get nearby crates
|
||||||
local finddist = self.CrateDistance or 30
|
local finddist = self.CrateDistance or 30
|
||||||
local nearcrates,number = self:_FindCratesNearby(Group,Unit,finddist) -- #table
|
local nearcrates,number = self:_FindCratesNearby(Group,Unit,finddist) -- #table
|
||||||
if number == 0 or numberonboard == cratelimit then
|
if number == 0 and self.hoverautoloading then
|
||||||
self:_SendMessage("Sorry no loadable crates nearby or fully loaded!", 10, false, Group)
|
return -- exit
|
||||||
|
elseif number == 0 then
|
||||||
|
self:_SendMessage("Sorry no loadable crates nearby!", 10, false, Group)
|
||||||
|
return -- exit
|
||||||
|
elseif numberonboard == cratelimit then
|
||||||
|
self:_SendMessage("Sorry no fully loaded!", 10, false, Group)
|
||||||
return -- exit
|
return -- exit
|
||||||
else
|
else
|
||||||
-- go through crates and load
|
-- go through crates and load
|
||||||
@@ -1415,7 +1423,7 @@ function CTLD:_LoadCratesNearby(Group, Unit)
|
|||||||
table.insert(loaded.Cargo, crate)
|
table.insert(loaded.Cargo, crate)
|
||||||
table.insert(crateidsloaded,crate:GetID())
|
table.insert(crateidsloaded,crate:GetID())
|
||||||
-- destroy crate
|
-- destroy crate
|
||||||
crate:GetPositionable():Destroy()
|
crate:GetPositionable():Destroy(false)
|
||||||
crate.Positionable = nil
|
crate.Positionable = nil
|
||||||
self:_SendMessage(string.format("Crate ID %d for %s loaded!",crate:GetID(),crate:GetName()), 10, false, Group)
|
self:_SendMessage(string.format("Crate ID %d for %s loaded!",crate:GetID(),crate:GetName()), 10, false, Group)
|
||||||
self:_UpdateUnitCargoMass(Unit)
|
self:_UpdateUnitCargoMass(Unit)
|
||||||
@@ -1967,7 +1975,7 @@ function CTLD:_CleanUpCrates(Crates,Build,Number)
|
|||||||
if name == nametype then -- matching crate type
|
if name == nametype then -- matching crate type
|
||||||
table.insert(destIDs,thisID)
|
table.insert(destIDs,thisID)
|
||||||
found = found + 1
|
found = found + 1
|
||||||
nowcrate:GetPositionable():Destroy()
|
nowcrate:GetPositionable():Destroy(false)
|
||||||
nowcrate.Positionable = nil
|
nowcrate.Positionable = nil
|
||||||
end
|
end
|
||||||
if found == numberdest then break end -- got enough
|
if found == numberdest then break end -- got enough
|
||||||
@@ -2651,7 +2659,7 @@ end
|
|||||||
if self.hoverautoloading then
|
if self.hoverautoloading then
|
||||||
for _,_pilot in pairs (self.CtldUnits) do
|
for _,_pilot in pairs (self.CtldUnits) do
|
||||||
local Unit = UNIT:FindByName(_pilot)
|
local Unit = UNIT:FindByName(_pilot)
|
||||||
self:AutoHoverLoad(Unit)
|
if self:CanHoverLoad(Unit) then self:AutoHoverLoad(Unit) end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
|
|||||||
Reference in New Issue
Block a user