mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
CTLD - Added Hercules support for crates, troops & vehicles loaded with the help of the ground crew and dropped from the plane. Added weight checks for loaded crates.
This commit is contained in:
parent
a95c49915a
commit
28eb7a678c
@ -22,7 +22,7 @@
|
||||
-- @module Ops.CTLD
|
||||
-- @image OPS_CTLD.jpg
|
||||
|
||||
-- Date: Jan 2022
|
||||
-- Date: Feb 2022
|
||||
|
||||
do
|
||||
------------------------------------------------------
|
||||
@ -299,6 +299,7 @@ CTLD_ENGINEERING = {
|
||||
return -1
|
||||
end
|
||||
end
|
||||
|
||||
------------------------------------------------------
|
||||
--- **CTLD_CARGO** class, extends Core.Base#BASE
|
||||
-- @type CTLD_CARGO
|
||||
@ -389,6 +390,7 @@ CTLD_CARGO = {
|
||||
function CTLD_CARGO:GetMass()
|
||||
return self.PerCrateMass
|
||||
end
|
||||
|
||||
--- Query Name.
|
||||
-- @param #CTLD_CARGO self
|
||||
-- @return #string Name
|
||||
@ -568,11 +570,12 @@ do
|
||||
-- * Additional events to tailor your mission.
|
||||
-- * ANY late activated group can serve as cargo, either as troops, crates, which have to be build on-location, or static like ammo chests.
|
||||
-- * Option to persist (save&load) your dropped troops, crates and vehicles.
|
||||
-- * Weight checks on loaded cargo.
|
||||
--
|
||||
-- ## 0. Prerequisites
|
||||
--
|
||||
-- You need to load an .ogg soundfile for the pilot\'s beacons into the mission, e.g. "beacon.ogg", use a once trigger, "sound to country" for that.
|
||||
-- Create the late-activated troops, vehicles (no statics at this point!) that will make up your deployable forces.
|
||||
-- Create the late-activated troops, vehicles, that will make up your deployable forces.
|
||||
--
|
||||
-- ## 1. Basic Setup
|
||||
--
|
||||
@ -606,7 +609,7 @@ do
|
||||
-- -- add vehicle called "Humvee" using template "Humvee", of type VEHICLE, size 2, i.e. needs two crates to be build
|
||||
-- -- vehicles and FOB will be spawned as crates in a LOAD zone first. Once transported to DROP zones, they can be build into the objects
|
||||
-- my_ctld:AddCratesCargo("Humvee",{"Humvee"},CTLD_CARGO.Enum.VEHICLE,2)
|
||||
-- -- if you want to add weight to your Heli, crates can have a weight in kg **per crate**. Currently no max weight checked. Fly carefully.
|
||||
-- -- if you want to add weight to your Heli, crates can have a weight in kg **per crate**. Fly carefully.
|
||||
-- my_ctld:AddCratesCargo("Humvee",{"Humvee"},CTLD_CARGO.Enum.VEHICLE,2,2775)
|
||||
-- -- if you want to limit your stock, add a number (here: 10) as parameter after weight. No parameter / nil means unlimited stock.
|
||||
-- my_ctld:AddCratesCargo("Humvee",{"Humvee"},CTLD_CARGO.Enum.VEHICLE,2,2775,10)
|
||||
@ -614,7 +617,8 @@ do
|
||||
-- -- add infantry unit called "Forward Ops Base" using template "FOB", of type FOB, size 4, i.e. needs four crates to be build:
|
||||
-- my_ctld:AddCratesCargo("Forward Ops Base",{"FOB"},CTLD_CARGO.Enum.FOB,4)
|
||||
--
|
||||
-- -- add crates to repair FOB or VEHICLE type units - the 2nd parameter needs to match the template you want to repair
|
||||
-- -- add crates to repair FOB or VEHICLE type units - the 2nd parameter needs to match the template you want to repair,
|
||||
-- -- e.g. the "Humvee" here refers back to the "Humvee" crates cargo added above (same template!)
|
||||
-- my_ctld:AddCratesRepair("Humvee Repair","Humvee",CTLD_CARGO.Enum.REPAIR,1)
|
||||
-- my_ctld.repairtime = 300 -- takes 300 seconds to repair something
|
||||
--
|
||||
@ -624,9 +628,9 @@ do
|
||||
--
|
||||
-- ## 1.3 Add logistics zones
|
||||
--
|
||||
-- Add zones for loading troops and crates and dropping, building crates
|
||||
-- Add (normal, round!) zones for loading troops and crates and dropping, building crates
|
||||
--
|
||||
-- -- Add a zone of type LOAD to our setup. Players can load troops and crates.
|
||||
-- -- Add a zone of type LOAD to our setup. Players can load any troops and crates here as defined in 1.2 above.
|
||||
-- -- "Loadzone" is the name of the zone from the ME. Players can load, if they are inside the zone.
|
||||
-- -- Smoke and Flare color for this zone is blue, it is active (can be used) and has a radio beacon.
|
||||
-- my_ctld:AddCTLDZone("Loadzone",CTLD.CargoZoneType.LOAD,SMOKECOLOR.Blue,true,true)
|
||||
@ -646,7 +650,7 @@ do
|
||||
-- -- "Tarawa" is the unitname (callsign) of the ship from the ME. Players can load, if they are inside the zone.
|
||||
-- -- The ship is 240 meters long and 20 meters wide.
|
||||
-- -- Note that you need to adjust the max hover height to deck height plus 5 meters or so for loading to work.
|
||||
-- -- When the ship is moving, forcing hoverload might not be a good idea.
|
||||
-- -- When the ship is moving, avoid forcing hoverload.
|
||||
-- my_ctld:AddCTLDZone("Tarawa",CTLD.CargoZoneType.SHIP,SMOKECOLOR.Blue,true,true,240,20)
|
||||
--
|
||||
-- ## 2. Options
|
||||
@ -682,22 +686,21 @@ do
|
||||
-- Use this function to adjust what a heli type can or cannot do:
|
||||
--
|
||||
-- -- E.g. update unit capabilities for testing. Please stay realistic in your mission design.
|
||||
-- -- Make a Gazelle into a heavy truck, this type can load both crates and troops and eight of each type:
|
||||
-- my_ctld:UnitCapabilities("SA342L", true, true, 8, 8, 12)
|
||||
-- -- Make a Gazelle into a heavy truck, this type can load both crates and troops and eight of each type, up to 4000 kgs:
|
||||
-- my_ctld:UnitCapabilities("SA342L", true, true, 8, 8, 12, 4000)
|
||||
--
|
||||
-- -- Default unit type capabilities are:
|
||||
--
|
||||
-- ["SA342Mistral"] = {type="SA342Mistral", crates=false, troops=true, cratelimit = 0, trooplimit = 4, length = 12},
|
||||
-- ["SA342L"] = {type="SA342L", crates=false, troops=true, cratelimit = 0, trooplimit = 2, length = 12},
|
||||
-- ["SA342M"] = {type="SA342M", crates=false, troops=true, cratelimit = 0, trooplimit = 4, length = 12},
|
||||
-- ["SA342Minigun"] = {type="SA342Minigun", crates=false, troops=true, cratelimit = 0, trooplimit = 2, length = 12},
|
||||
-- ["UH-1H"] = {type="UH-1H", crates=true, troops=true, cratelimit = 1, trooplimit = 8, length = 15},
|
||||
-- ["Mi-8MT"] = {type="Mi-8MTV2", crates=true, troops=true, cratelimit = 2, trooplimit = 12, length = 15},
|
||||
-- ["Ka-50"] = {type="Ka-50", crates=false, troops=false, cratelimit = 0, trooplimit = 0, length = 15},
|
||||
-- ["Mi-24P"] = {type="Mi-24P", crates=true, troops=true, cratelimit = 2, trooplimit = 8, length = 18},
|
||||
-- ["Mi-24V"] = {type="Mi-24V", crates=true, troops=true, cratelimit = 2, trooplimit = 8, length = 18},
|
||||
-- ["Hercules"] = {type="Hercules", crates=true, troops=true, cratelimit = 7, trooplimit = 64, length = 25},
|
||||
-- ["UH-60L"] = {type="UH-60L", crates=true, troops=true, cratelimit = 2, trooplimit = 20, length = 16},
|
||||
-- -- Default unit type capabilities are:
|
||||
-- ["SA342Mistral"] = {type="SA342Mistral", crates=false, troops=true, cratelimit = 0, trooplimit = 4, length = 12, cargoweightlimit = 400},
|
||||
-- ["SA342L"] = {type="SA342L", crates=false, troops=true, cratelimit = 0, trooplimit = 2, length = 12, cargoweightlimit = 400},
|
||||
-- ["SA342M"] = {type="SA342M", crates=false, troops=true, cratelimit = 0, trooplimit = 4, length = 12, cargoweightlimit = 400},
|
||||
-- ["SA342Minigun"] = {type="SA342Minigun", crates=false, troops=true, cratelimit = 0, trooplimit = 2, length = 12, cargoweightlimit = 400},
|
||||
-- ["UH-1H"] = {type="UH-1H", crates=true, troops=true, cratelimit = 1, trooplimit = 8, length = 15, cargoweightlimit = 700},
|
||||
-- ["Mi-8MT"] = {type="Mi-8MT", crates=true, troops=true, cratelimit = 2, trooplimit = 12, length = 15, cargoweightlimit = 3000},
|
||||
-- ["Ka-50"] = {type="Ka-50", crates=false, troops=false, cratelimit = 0, trooplimit = 0, length = 15, cargoweightlimit = 0},
|
||||
-- ["Mi-24P"] = {type="Mi-24P", crates=true, troops=true, cratelimit = 2, trooplimit = 8, length = 18, cargoweightlimit = 700},
|
||||
-- ["Mi-24V"] = {type="Mi-24V", crates=true, troops=true, cratelimit = 2, trooplimit = 8, length = 18, cargoweightlimit = 700},
|
||||
-- ["Hercules"] = {type="Hercules", crates=true, troops=true, cratelimit = 7, trooplimit = 64, length = 25, cargoweightlimit = 19000},
|
||||
-- ["UH-60L"] = {type="UH-60L", crates=true, troops=true, cratelimit = 2, trooplimit = 20, length = 16, cargoweightlimit = 3500},
|
||||
--
|
||||
-- ### 2.1.2 Activate and deactivate zones
|
||||
--
|
||||
@ -977,25 +980,26 @@ CTLD.CargoZoneType = {
|
||||
-- @field #boolean troops Can transport troops.
|
||||
-- @field #number cratelimit Number of crates transportable.
|
||||
-- @field #number trooplimit Number of troop units transportable.
|
||||
-- @field #number cargoweightlimit Max loadable kgs of cargo.
|
||||
CTLD.UnitTypes = {
|
||||
["SA342Mistral"] = {type="SA342Mistral", crates=false, troops=true, cratelimit = 0, trooplimit = 4, length = 12},
|
||||
["SA342L"] = {type="SA342L", crates=false, troops=true, cratelimit = 0, trooplimit = 2, length = 12},
|
||||
["SA342M"] = {type="SA342M", crates=false, troops=true, cratelimit = 0, trooplimit = 4, length = 12},
|
||||
["SA342Minigun"] = {type="SA342Minigun", crates=false, troops=true, cratelimit = 0, trooplimit = 2, length = 12},
|
||||
["UH-1H"] = {type="UH-1H", crates=true, troops=true, cratelimit = 1, trooplimit = 8, length = 15},
|
||||
["Mi-8MTV2"] = {type="Mi-8MTV2", crates=true, troops=true, cratelimit = 2, trooplimit = 12, length = 15},
|
||||
["Mi-8MT"] = {type="Mi-8MTV2", crates=true, troops=true, cratelimit = 2, trooplimit = 12, length = 15},
|
||||
["Ka-50"] = {type="Ka-50", crates=false, troops=false, cratelimit = 0, trooplimit = 0, length = 15},
|
||||
["Mi-24P"] = {type="Mi-24P", crates=true, troops=true, cratelimit = 2, trooplimit = 8, length = 18},
|
||||
["Mi-24V"] = {type="Mi-24V", crates=true, troops=true, cratelimit = 2, trooplimit = 8, length = 18},
|
||||
["Hercules"] = {type="Hercules", crates=true, troops=true, cratelimit = 7, trooplimit = 64, length = 25}, -- 19t cargo, 64 paratroopers.
|
||||
["SA342Mistral"] = {type="SA342Mistral", crates=false, troops=true, cratelimit = 0, trooplimit = 4, length = 12, cargoweightlimit = 400},
|
||||
["SA342L"] = {type="SA342L", crates=false, troops=true, cratelimit = 0, trooplimit = 2, length = 12, cargoweightlimit = 400},
|
||||
["SA342M"] = {type="SA342M", crates=false, troops=true, cratelimit = 0, trooplimit = 4, length = 12, cargoweightlimit = 400},
|
||||
["SA342Minigun"] = {type="SA342Minigun", crates=false, troops=true, cratelimit = 0, trooplimit = 2, length = 12, cargoweightlimit = 400},
|
||||
["UH-1H"] = {type="UH-1H", crates=true, troops=true, cratelimit = 1, trooplimit = 8, length = 15, cargoweightlimit = 700},
|
||||
["Mi-8MTV2"] = {type="Mi-8MTV2", crates=true, troops=true, cratelimit = 2, trooplimit = 12, length = 15, cargoweightlimit = 3000},
|
||||
["Mi-8MT"] = {type="Mi-8MTV2", crates=true, troops=true, cratelimit = 2, trooplimit = 12, length = 15, cargoweightlimit = 3000},
|
||||
["Ka-50"] = {type="Ka-50", crates=false, troops=false, cratelimit = 0, trooplimit = 0, length = 15, cargoweightlimit = 0},
|
||||
["Mi-24P"] = {type="Mi-24P", crates=true, troops=true, cratelimit = 2, trooplimit = 8, length = 18, cargoweightlimit = 700},
|
||||
["Mi-24V"] = {type="Mi-24V", crates=true, troops=true, cratelimit = 2, trooplimit = 8, length = 18, cargoweightlimit = 700},
|
||||
["Hercules"] = {type="Hercules", crates=true, troops=true, cratelimit = 7, trooplimit = 64, length = 25, cargoweightlimit = 19000}, -- 19t cargo, 64 paratroopers.
|
||||
--Actually it's longer, but the center coord is off-center of the model.
|
||||
["UH-60L"] = {type="UH-60L", crates=true, troops=true, cratelimit = 2, trooplimit = 20, length = 16}, -- 4t cargo, 20 (unsec) seats
|
||||
["UH-60L"] = {type="UH-60L", crates=true, troops=true, cratelimit = 2, trooplimit = 20, length = 16, cargoweightlimit = 3500}, -- 4t cargo, 20 (unsec) seats
|
||||
}
|
||||
|
||||
--- CTLD class version.
|
||||
-- @field #string version
|
||||
CTLD.version="1.0.4"
|
||||
CTLD.version="1.0.5"
|
||||
|
||||
--- Instantiate a new CTLD.
|
||||
-- @param #CTLD self
|
||||
@ -1354,6 +1358,7 @@ function CTLD:_GetUnitCapabilities(Unit)
|
||||
capabilities.trooplimit = 0
|
||||
capabilities.type = "generic"
|
||||
capabilities.length = 20
|
||||
capabilities.cargoweightlimit = 0
|
||||
end
|
||||
return capabilities
|
||||
end
|
||||
@ -1409,6 +1414,7 @@ function CTLD:_EventHandler(EventData)
|
||||
-- Herc support
|
||||
--self:T_unit:GetTypeName())
|
||||
if _unit:GetTypeName() == "Hercules" and self.enableHercules then
|
||||
local unitname = event.IniUnitName or "none"
|
||||
self.Loaded_Cargo[unitname] = nil
|
||||
self:_RefreshF10Menus()
|
||||
end
|
||||
@ -2049,16 +2055,25 @@ function CTLD:_FindCratesNearby( _group, _unit, _dist)
|
||||
-- cycle
|
||||
local index = 0
|
||||
local found = {}
|
||||
local loadedmass = self:_GetUnitCargoMass(_unit)
|
||||
local unittype = _unit:GetTypeName()
|
||||
local capabilities = self:_GetUnitCapabilities(_unit) -- #CTLD.UnitCapabilities
|
||||
local maxmass = capabilities.cargoweightlimit
|
||||
local maxloadable = maxmass - loadedmass
|
||||
self:T(self.lid .. " Max loadable mass: " .. maxloadable)
|
||||
for _,_cargoobject in pairs (existingcrates) do
|
||||
local cargo = _cargoobject -- #CTLD_CARGO
|
||||
local static = cargo:GetPositionable() -- Wrapper.Static#STATIC -- crates
|
||||
local staticid = cargo:GetID()
|
||||
local weight = cargo:GetMass() -- weight in kgs of this cargo
|
||||
self:T(self.lid .. " Found cargo mass: " .. weight)
|
||||
if static and static:IsAlive() then
|
||||
local staticpos = static:GetCoordinate()
|
||||
local distance = self:_GetDistance(location,staticpos)
|
||||
if distance <= finddist and static then
|
||||
if distance <= finddist and static and weight <= maxloadable then
|
||||
index = index + 1
|
||||
table.insert(found, staticid, cargo)
|
||||
maxloadable = maxloadable - weight
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -2104,6 +2119,7 @@ function CTLD:_LoadCratesNearby(Group, Unit)
|
||||
if self.Loaded_Cargo[unitname] then
|
||||
loaded = self.Loaded_Cargo[unitname] -- #CTLD.LoadedCargo
|
||||
numberonboard = loaded.Cratesloaded or 0
|
||||
massonboard = self:_GetUnitCargoMass(Unit)
|
||||
else
|
||||
loaded = {} -- #CTLD.LoadedCargo
|
||||
loaded.Troopsloaded = 0
|
||||
@ -2113,10 +2129,11 @@ function CTLD:_LoadCratesNearby(Group, Unit)
|
||||
-- get nearby crates
|
||||
local finddist = self.CrateDistance or 35
|
||||
local nearcrates,number = self:_FindCratesNearby(Group,Unit,finddist) -- #table
|
||||
self:T(self.lid .. " Crates found: " .. number)
|
||||
if number == 0 and self.hoverautoloading then
|
||||
return self -- exit
|
||||
elseif number == 0 then
|
||||
self:_SendMessage("Sorry no loadable crates nearby!", 10, false, Group)
|
||||
self:_SendMessage("Sorry no loadable crates nearby or max cargo weight reached!", 10, false, Group)
|
||||
return self -- exit
|
||||
elseif numberonboard == cratelimit then
|
||||
self:_SendMessage("Sorry no fully loaded!", 10, false, Group)
|
||||
@ -2985,6 +3002,25 @@ function CTLD:_RefreshF10Menus()
|
||||
return self
|
||||
end
|
||||
|
||||
--- [Internal] Function to check if a template exists in the mission.
|
||||
-- @param #CTLD self
|
||||
-- @param #table temptable Table of string names
|
||||
-- @return #boolen outcome
|
||||
function CTLD:_CheckTemplates(temptable)
|
||||
self:T(self.lid .. " _CheckTemplates")
|
||||
local outcome = true
|
||||
if type(temptable) ~= "table" then
|
||||
temptable = {temptable}
|
||||
end
|
||||
for _,_name in pairs(temptable) do
|
||||
if not _DATABASE.Templates.Groups[_name] then
|
||||
outcome = false
|
||||
self:E(self.lid .. "ERROR: Template name " .. _name .. " is missing!")
|
||||
end
|
||||
end
|
||||
return outcome
|
||||
end
|
||||
|
||||
--- User function - Add *generic* troop type loadable as cargo. This type will load directly into the heli without crates.
|
||||
-- @param #CTLD self
|
||||
-- @param #string Name Unique name of this type of troop. E.g. "Anti-Air Small".
|
||||
@ -2996,6 +3032,10 @@ function CTLD:_RefreshF10Menus()
|
||||
function CTLD:AddTroopsCargo(Name,Templates,Type,NoTroops,PerTroopMass,Stock)
|
||||
self:T(self.lid .. " AddTroopsCargo")
|
||||
self:T({Name,Templates,Type,NoTroops,PerTroopMass,Stock})
|
||||
if not self:_CheckTemplates(Templates) then
|
||||
self:E(self.lid .. "Troops Cargo for " .. Name .. " has missing template(s)!" )
|
||||
return self
|
||||
end
|
||||
self.CargoCounter = self.CargoCounter + 1
|
||||
-- Troops are directly loadable
|
||||
local cargo = CTLD_CARGO:New(self.CargoCounter,Name,Templates,Type,false,true,NoTroops,nil,nil,PerTroopMass,Stock)
|
||||
@ -3013,6 +3053,10 @@ end
|
||||
-- @param #number Stock Number of groups in stock. Nil for unlimited.
|
||||
function CTLD:AddCratesCargo(Name,Templates,Type,NoCrates,PerCrateMass,Stock)
|
||||
self:T(self.lid .. " AddCratesCargo")
|
||||
if not self:_CheckTemplates(Templates) then
|
||||
self:E(self.lid .. "Crates Cargo for " .. Name .. " has missing template(s)!" )
|
||||
return self
|
||||
end
|
||||
self.CargoCounter = self.CargoCounter + 1
|
||||
-- Crates are not directly loadable
|
||||
local cargo = CTLD_CARGO:New(self.CargoCounter,Name,Templates,Type,false,false,NoCrates,nil,nil,PerCrateMass,Stock)
|
||||
@ -3055,13 +3099,17 @@ end
|
||||
--- User function - Add *generic* repair crates loadable as cargo. This type will create crates that need to be loaded, moved, dropped and built.
|
||||
-- @param #CTLD self
|
||||
-- @param #string Name Unique name of this type of cargo. E.g. "Humvee".
|
||||
-- @param #string Template Template of VEHICLE or FOB cargo that this can repair.
|
||||
-- @param #string Template Template of VEHICLE or FOB cargo that this can repair. MUST be the same as given in `AddCratesCargo(..)`!
|
||||
-- @param #CTLD_CARGO.Enum Type Type of cargo, here REPAIR.
|
||||
-- @param #number NoCrates Number of crates needed to build this cargo.
|
||||
-- @param #number PerCrateMass Mass in kg of each crate
|
||||
-- @param #number Stock Number of groups in stock. Nil for unlimited.
|
||||
function CTLD:AddCratesRepair(Name,Template,Type,NoCrates, PerCrateMass,Stock)
|
||||
self:T(self.lid .. " AddCratesRepair")
|
||||
if not self:_CheckTemplates(Template) then
|
||||
self:E(self.lid .. "Repair Cargo for " .. Name .. " has a missing template!" )
|
||||
return self
|
||||
end
|
||||
self.CargoCounter = self.CargoCounter + 1
|
||||
-- Crates are not directly loadable
|
||||
local cargo = CTLD_CARGO:New(self.CargoCounter,Name,Template,Type,false,false,NoCrates,nil,nil,PerCrateMass,Stock)
|
||||
@ -3558,7 +3606,8 @@ end
|
||||
-- @param #number Cratelimit Unit can carry number of crates. Default 0.
|
||||
-- @param #number Trooplimit Unit can carry number of troops. Default 0.
|
||||
-- @param #number Length Unit lenght (in mteres) for the load radius. Default 20.
|
||||
function CTLD:UnitCapabilities(Unittype, Cancrates, Cantroops, Cratelimit, Trooplimit, Length)
|
||||
-- @param #number Maxcargoweight Maxmimum weight in kgs this helo can carry. Default 0.
|
||||
function CTLD:UnitCapabilities(Unittype, Cancrates, Cantroops, Cratelimit, Trooplimit, Length, Maxcargoweight)
|
||||
self:T(self.lid .. " UnitCapabilities")
|
||||
local unittype = nil
|
||||
local unit = nil
|
||||
@ -3578,6 +3627,7 @@ end
|
||||
capabilities.cratelimit = Cratelimit or 0
|
||||
capabilities.trooplimit = Trooplimit or 0
|
||||
capabilities.length = Length or 20
|
||||
capabilities.cargoweightlimit = Maxcargoweight or 0
|
||||
self.UnitTypes[unittype] = capabilities
|
||||
return self
|
||||
end
|
||||
@ -4594,6 +4644,655 @@ end
|
||||
return self
|
||||
end
|
||||
end -- end do
|
||||
|
||||
do
|
||||
--- Hercules Cargo Drop Events by Anubis Yinepu
|
||||
-- Moose CTLD OO refactoring by Applevangelist
|
||||
--
|
||||
-- This script will only work for the Herculus mod by Anubis
|
||||
-- Payloads carried by pylons 11, 12 and 13 need to be declared in the Herculus_Loadout.lua file
|
||||
-- Except for Ammo pallets, this script will spawn whatever payload gets launched from pylons 11, 12 and 13
|
||||
-- Pylons 11, 12 and 13 are moveable within the Herculus cargobay area
|
||||
-- Ammo pallets can only be jettisoned from these pylons with no benefit to DCS world
|
||||
-- To benefit DCS world, Ammo pallets need to be off/on loaded using DCS arming and refueling window
|
||||
-- Cargo_Container_Enclosed = true: Cargo enclosed in container with parachute, need to be dropped from 100m (300ft) or more, except when parked on ground
|
||||
-- Cargo_Container_Enclosed = false: Open cargo with no parachute, need to be dropped from 10m (30ft) or less
|
||||
|
||||
------------------------------------------------------
|
||||
--- **CTLD_HERCULES** class, extends Core.Base#BASE
|
||||
-- @type CTLD_HERCULES
|
||||
-- @field #string ClassName
|
||||
-- @field #string lid
|
||||
-- @field #string Name
|
||||
-- @field #string Version
|
||||
-- @extends Core.Base#BASE
|
||||
CTLD_HERCULES = {
|
||||
ClassName = "CTLD_HERCULES",
|
||||
lid = "",
|
||||
Name = "",
|
||||
Version = "0.0.1",
|
||||
}
|
||||
|
||||
--- Define cargo types.
|
||||
-- @type CTLD_HERCULES.Types
|
||||
-- @field #table Type Name of cargo type, container (boolean) in container or not.
|
||||
CTLD_HERCULES.Types = {
|
||||
["ATGM M1045 HMMWV TOW Air [7183lb]"] = {['name'] = "M1045 HMMWV TOW", ['container'] = true},
|
||||
["ATGM M1045 HMMWV TOW Skid [7073lb]"] = {['name'] = "M1045 HMMWV TOW", ['container'] = false},
|
||||
["APC M1043 HMMWV Armament Air [7023lb]"] = {['name'] = "M1043 HMMWV Armament", ['container'] = true},
|
||||
["APC M1043 HMMWV Armament Skid [6912lb]"] = {['name'] = "M1043 HMMWV Armament", ['container'] = false},
|
||||
["SAM Avenger M1097 Air [7200lb]"] = {['name'] = "M1097 Avenger", ['container'] = true},
|
||||
["SAM Avenger M1097 Skid [7090lb]"] = {['name'] = "M1097 Avenger", ['container'] = false},
|
||||
["APC Cobra Air [10912lb]"] = {['name'] = "Cobra", ['container'] = true},
|
||||
["APC Cobra Skid [10802lb]"] = {['name'] = "Cobra", ['container'] = false},
|
||||
["APC M113 Air [21624lb]"] = {['name'] = "M-113", ['container'] = true},
|
||||
["APC M113 Skid [21494lb]"] = {['name'] = "M-113", ['container'] = false},
|
||||
["Tanker M978 HEMTT [34000lb]"] = {['name'] = "M978 HEMTT Tanker", ['container'] = false},
|
||||
["HEMTT TFFT [34400lb]"] = {['name'] = "HEMTT TFFT", ['container'] = false},
|
||||
["SPG M1128 Stryker MGS [33036lb]"] = {['name'] = "M1128 Stryker MGS", ['container'] = false},
|
||||
["AAA Vulcan M163 Air [21666lb]"] = {['name'] = "Vulcan", ['container'] = true},
|
||||
["AAA Vulcan M163 Skid [21577lb]"] = {['name'] = "Vulcan", ['container'] = false},
|
||||
["APC M1126 Stryker ICV [29542lb]"] = {['name'] = "M1126 Stryker ICV", ['container'] = false},
|
||||
["ATGM M1134 Stryker [30337lb]"] = {['name'] = "M1134 Stryker ATGM", ['container'] = false},
|
||||
["APC LAV-25 Air [22520lb]"] = {['name'] = "LAV-25", ['container'] = true},
|
||||
["APC LAV-25 Skid [22514lb]"] = {['name'] = "LAV-25", ['container'] = false},
|
||||
["M1025 HMMWV Air [6160lb]"] = {['name'] = "Hummer", ['container'] = true},
|
||||
["M1025 HMMWV Skid [6050lb]"] = {['name'] = "Hummer", ['container'] = false},
|
||||
["IFV M2A2 Bradley [34720lb]"] = {['name'] = "M-2 Bradley", ['container'] = false},
|
||||
["IFV MCV-80 [34720lb]"] = {['name'] = "MCV-80", ['container'] = false},
|
||||
["IFV BMP-1 [23232lb]"] = {['name'] = "BMP-1", ['container'] = false},
|
||||
["IFV BMP-2 [25168lb]"] = {['name'] = "BMP-2", ['container'] = false},
|
||||
["IFV BMP-3 [32912lb]"] = {['name'] = "BMP-3", ['container'] = false},
|
||||
["ARV BRDM-2 Air [12320lb]"] = {['name'] = "BRDM-2", ['container'] = true},
|
||||
["ARV BRDM-2 Skid [12210lb]"] = {['name'] = "BRDM-2", ['container'] = false},
|
||||
["APC BTR-80 Air [23936lb]"] = {['name'] = "BTR-80", ['container'] = true},
|
||||
["APC BTR-80 Skid [23826lb]"] = {['name'] = "BTR-80", ['container'] = false},
|
||||
["APC BTR-82A Air [24998lb]"] = {['name'] = "BTR-82A", ['container'] = true},
|
||||
["APC BTR-82A Skid [24888lb]"] = {['name'] = "BTR-82A", ['container'] = false},
|
||||
["SAM ROLAND ADS [34720lb]"] = {['name'] = "Roland Radar", ['container'] = false},
|
||||
["SAM ROLAND LN [34720b]"] = {['name'] = "Roland ADS", ['container'] = false},
|
||||
["SAM SA-13 STRELA [21624lb]"] = {['name'] = "Strela-10M3", ['container'] = false},
|
||||
["AAA ZSU-23-4 Shilka [32912lb]"] = {['name'] = "ZSU-23-4 Shilka", ['container'] = false},
|
||||
["SAM SA-19 Tunguska 2S6 [34720lb]"] = {['name'] = "2S6 Tunguska", ['container'] = false},
|
||||
["Transport UAZ-469 Air [3747lb]"] = {['name'] = "UAZ-469", ['container'] = true},
|
||||
["Transport UAZ-469 Skid [3630lb]"] = {['name'] = "UAZ-469", ['container'] = false},
|
||||
["AAA GEPARD [34720lb]"] = {['name'] = "Gepard", ['container'] = false},
|
||||
["SAM CHAPARRAL Air [21624lb]"] = {['name'] = "M48 Chaparral", ['container'] = true},
|
||||
["SAM CHAPARRAL Skid [21516lb]"] = {['name'] = "M48 Chaparral", ['container'] = false},
|
||||
["SAM LINEBACKER [34720lb]"] = {['name'] = "M6 Linebacker", ['container'] = false},
|
||||
["Transport URAL-375 [14815lb]"] = {['name'] = "Ural-375", ['container'] = false},
|
||||
["Transport M818 [16000lb]"] = {['name'] = "M 818", ['container'] = false},
|
||||
["IFV MARDER [34720lb]"] = {['name'] = "Marder", ['container'] = false},
|
||||
["Transport Tigr Air [15900lb]"] = {['name'] = "Tigr_233036", ['container'] = true},
|
||||
["Transport Tigr Skid [15730lb]"] = {['name'] = "Tigr_233036", ['container'] = false},
|
||||
["IFV TPZ FUCH [33440lb]"] = {['name'] = "TPZ", ['container'] = false},
|
||||
["IFV BMD-1 Air [18040lb]"] = {['name'] = "BMD-1", ['container'] = true},
|
||||
["IFV BMD-1 Skid [17930lb]"] = {['name'] = "BMD-1", ['container'] = false},
|
||||
["IFV BTR-D Air [18040lb]"] = {['name'] = "BTR_D", ['container'] = true},
|
||||
["IFV BTR-D Skid [17930lb]"] = {['name'] = "BTR_D", ['container'] = false},
|
||||
["EWR SBORKA Air [21624lb]"] = {['name'] = "Dog Ear radar", ['container'] = true},
|
||||
["EWR SBORKA Skid [21624lb]"] = {['name'] = "Dog Ear radar", ['container'] = false},
|
||||
["ART 2S9 NONA Air [19140lb]"] = {['name'] = "SAU 2-C9", ['container'] = true},
|
||||
["ART 2S9 NONA Skid [19030lb]"] = {['name'] = "SAU 2-C9", ['container'] = false},
|
||||
["ART GVOZDIKA [34720lb]"] = {['name'] = "SAU Gvozdika", ['container'] = false},
|
||||
["APC MTLB Air [26400lb]"] = {['name'] = "MTLB", ['container'] = true},
|
||||
["APC MTLB Skid [26290lb]"] = {['name'] = "MTLB", ['container'] = false},
|
||||
["Generic Crate [20000lb]"] = {['name'] = "Hercules_Container_Parachute", ['container'] = true} --nothing generic in Moose CTLD
|
||||
}
|
||||
|
||||
--- Cargo Object
|
||||
-- @type CTLD_HERCULES.CargoObject
|
||||
-- @field #number Cargo_Drop_Direction
|
||||
-- @field #table Cargo_Contents
|
||||
-- @field #string Cargo_Type_name
|
||||
-- @field #boolean Container_Enclosed
|
||||
-- @field #boolean ParatrooperGroupSpawn
|
||||
-- @field #number Cargo_Country
|
||||
-- @field #boolean offload_cargo
|
||||
-- @field #boolean all_cargo_survive_to_the_ground
|
||||
-- @field #boolean all_cargo_gets_destroyed
|
||||
-- @field #boolean destroy_cargo_dropped_without_parachute
|
||||
-- @field Core.Timer#TIMER scheduleFunctionID
|
||||
|
||||
--- [User] Instantiate a new object
|
||||
-- @param #CTLD_HERCULES self
|
||||
-- @param #string Coalition Coalition side, "red", "blue" or "neutral"
|
||||
-- @param #string Alias Name of this instance
|
||||
-- @param Ops.CTLD#CTLD CtldObject CTLD instance to link into
|
||||
-- @return #CTLD_HERCULES self
|
||||
-- @usage
|
||||
-- Integrate to your CTLD instance like so, where `my_ctld` is a previously created CTLD instance:
|
||||
--
|
||||
-- local herccargo = CTLD_HERCULES:New("blue", "Hercules Test", my_ctld)
|
||||
--
|
||||
-- You also need:
|
||||
-- * A template called "Infantry" for 10 Paratroopers (as set via herccargo.infantrytemplate).
|
||||
-- * Depending on what you are loading with the help of the ground crew, there are 42 more templates for the various vehicles that are loadable.
|
||||
-- There's a **quick check output in the `dcs.log`** which tells you what's there and what not.
|
||||
-- E.g.:
|
||||
-- ...Checking template for APC BTR-82A Air [24998lb] (BTR-82A) ... MISSING)
|
||||
-- ...Checking template for ART 2S9 NONA Skid [19030lb] (SAU 2-C9) ... MISSING)
|
||||
-- ...Checking template for EWR SBORKA Air [21624lb] (Dog Ear radar) ... MISSING)
|
||||
-- ...Checking template for Transport Tigr Air [15900lb] (Tigr_233036) ... OK)
|
||||
--
|
||||
-- Expected template names are the ones in the rounded brackets.
|
||||
function CTLD_HERCULES:New(Coalition, Alias, CtldObject)
|
||||
-- Inherit everything from FSM class.
|
||||
local self=BASE:Inherit(self, FSM:New()) -- #CTLD_HERCULES
|
||||
|
||||
--set Coalition
|
||||
if Coalition and type(Coalition)=="string" then
|
||||
if Coalition=="blue" then
|
||||
self.coalition=coalition.side.BLUE
|
||||
self.coalitiontxt = Coalition
|
||||
elseif Coalition=="red" then
|
||||
self.coalition=coalition.side.RED
|
||||
self.coalitiontxt = Coalition
|
||||
elseif Coalition=="neutral" then
|
||||
self.coalition=coalition.side.NEUTRAL
|
||||
self.coalitiontxt = Coalition
|
||||
else
|
||||
self:E("ERROR: Unknown coalition in CTLD!")
|
||||
end
|
||||
else
|
||||
self.coalition = Coalition
|
||||
self.coalitiontxt = string.lower(UTILS.GetCoalitionName(self.coalition))
|
||||
end
|
||||
|
||||
-- Set alias.
|
||||
if Alias then
|
||||
self.alias=tostring(Alias)
|
||||
else
|
||||
self.alias="UNHCR"
|
||||
if self.coalition then
|
||||
if self.coalition==coalition.side.RED then
|
||||
self.alias="Red CTLD Hercules"
|
||||
elseif self.coalition==coalition.side.BLUE then
|
||||
self.alias="Blue CTLD Hercules"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Set some string id for output to DCS.log file.
|
||||
self.lid=string.format("%s (%s) | ", self.alias, self.coalitiontxt)
|
||||
|
||||
self.infantrytemplate = "Infantry" -- template for a group of 10 paratroopers
|
||||
self.CTLD = CtldObject -- Ops.CTLD#CTLD
|
||||
|
||||
self.verbose = true
|
||||
|
||||
self.j = 0
|
||||
self.carrierGroups = {}
|
||||
self.Cargo = {}
|
||||
self.ParatrooperCount = {}
|
||||
|
||||
self.ObjectTracker = {}
|
||||
|
||||
-- Set some string id for output to DCS.log file.
|
||||
self.lid=string.format("%s (%s) | ", self.alias, self.coalition and UTILS.GetCoalitionName(self.coalition) or "unknown")
|
||||
|
||||
--self:HandleEvent(EVENTS.Birth,self._HandleBirth)
|
||||
self:HandleEvent(EVENTS.Shot, self._HandleShot)
|
||||
|
||||
self:I(self.lid .. "Started")
|
||||
|
||||
self:CheckTemplates()
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- [Internal] Function to check availability of templates
|
||||
-- @param #CTLD_HERCULES self
|
||||
-- @return #CTLD_HERCULES self
|
||||
function CTLD_HERCULES:CheckTemplates()
|
||||
self:T(self.lid .. 'CheckTemplates')
|
||||
-- inject Paratroopers
|
||||
self.Types["Paratroopers 10"] = {
|
||||
name = self.infantrytemplate,
|
||||
container = false,
|
||||
available = false,
|
||||
}
|
||||
local missing = {}
|
||||
local nomissing = 0
|
||||
local found = {}
|
||||
local nofound = 0
|
||||
|
||||
-- list of groundcrew loadables
|
||||
for _index,_tab in pairs (self.Types) do
|
||||
local outcometxt = "MISSING"
|
||||
if _DATABASE.Templates.Groups[_tab.name] then
|
||||
outcometxt = "OK"
|
||||
self.Types[_index].available= true
|
||||
found[_tab.name] = true
|
||||
else
|
||||
self.Types[_index].available = false
|
||||
missing[_tab.name] = true
|
||||
end
|
||||
if self.verbose then
|
||||
self:I(string.format(self.lid .. "Checking template for %s (%s) ... %s", _index,_tab.name,outcometxt))
|
||||
end
|
||||
end
|
||||
for _,_name in pairs(found) do
|
||||
nofound = nofound + 1
|
||||
end
|
||||
for _,_name in pairs(missing) do
|
||||
nomissing = nomissing + 1
|
||||
end
|
||||
self:I(string.format(self.lid .. "Template Check Summary: Found %d, Missing %d, Total %d",nofound,nomissing,nofound+nomissing))
|
||||
return self
|
||||
end
|
||||
|
||||
--- [Internal] Function to spawn a soldier group of 10 units
|
||||
-- @param #CTLD_HERCULES self
|
||||
-- @param Wrapper.Group#GROUP Cargo_Drop_initiator
|
||||
-- @param Core.Point#POINT_VEC3 Cargo_Drop_Position
|
||||
-- @param #string Cargo_Type_name
|
||||
-- @param #number CargoHeading
|
||||
-- @param #number Cargo_Country
|
||||
-- @param #number GroupSpacing
|
||||
-- @return #CTLD_HERCULES self
|
||||
function CTLD_HERCULES:Soldier_SpawnGroup(Cargo_Drop_initiator,Cargo_Drop_Position, Cargo_Type_name, CargoHeading, Cargo_Country, GroupSpacing)
|
||||
--- TODO: Rework into Moose Spawns
|
||||
self:T(self.lid .. 'Soldier_SpawnGroup')
|
||||
self:T(Cargo_Drop_Position)
|
||||
-- create a matching #CTLD_CARGO type
|
||||
local InjectTroopsType = CTLD_CARGO:New(nil,self.infantrytemplate,{self.infantrytemplate},CTLD_CARGO.Enum.TROOPS,true,true,10,nil,false,80)
|
||||
-- get a #ZONE object
|
||||
local position = Cargo_Drop_Position:GetVec2()
|
||||
local dropzone = ZONE_RADIUS:New("Infantry " .. math.random(1,10000),position,100)
|
||||
-- and go:
|
||||
self.CTLD:InjectTroops(dropzone,InjectTroopsType)
|
||||
return self
|
||||
end
|
||||
|
||||
--- [Internal] Function to spawn a group
|
||||
-- @param #CTLD_HERCULES self
|
||||
-- @param Wrapper.Group#GROUP Cargo_Drop_initiator
|
||||
-- @param Core.Point#POINT_VEC3 Cargo_Drop_Position
|
||||
-- @param #string Cargo_Type_name
|
||||
-- @param #number CargoHeading
|
||||
-- @param #number Cargo_Country
|
||||
-- @return #CTLD_HERCULES self
|
||||
function CTLD_HERCULES:Cargo_SpawnGroup(Cargo_Drop_initiator,Cargo_Drop_Position, Cargo_Type_name, CargoHeading, Cargo_Country)
|
||||
--- TODO: Rework into Moose Spawns
|
||||
self:T(self.lid .. "Cargo_SpawnGroup")
|
||||
self:T(Cargo_Type_name)
|
||||
if Cargo_Type_name ~= 'Container red 1' then
|
||||
-- create a matching #CTLD_CARGO type
|
||||
local InjectVehicleType = CTLD_CARGO:New(nil,Cargo_Type_name,{Cargo_Type_name},CTLD_CARGO.Enum.VEHICLE,true,true,1,nil,false,1000)
|
||||
-- get a #ZONE object
|
||||
local position = Cargo_Drop_Position:GetVec2()
|
||||
local dropzone = ZONE_RADIUS:New("Vehicle " .. math.random(1,10000),position,100)
|
||||
-- and go:
|
||||
self.CTLD:InjectVehicles(dropzone,InjectVehicleType)
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- [Internal] Function to spawn static cargo
|
||||
-- @param #CTLD_HERCULES self
|
||||
-- @param Wrapper.Group#GROUP Cargo_Drop_initiator
|
||||
-- @param Core.Point#POINT_VEC3 Cargo_Drop_Position
|
||||
-- @param #string Cargo_Type_name
|
||||
-- @param #number CargoHeading
|
||||
-- @param #boolean dead
|
||||
-- @param #number Cargo_Country
|
||||
-- @return #CTLD_HERCULES self
|
||||
function CTLD_HERCULES:Cargo_SpawnStatic(Cargo_Drop_initiator,Cargo_Drop_Position, Cargo_Type_name, CargoHeading, dead, Cargo_Country)
|
||||
--- TODO: Rework into Moose Static Spawns
|
||||
self:T(self.lid .. "Cargo_SpawnStatic")
|
||||
self:T("Static " .. Cargo_Type_name .. " Dead " .. tostring(dead))
|
||||
local position = Cargo_Drop_Position:GetVec2()
|
||||
local Zone = ZONE_RADIUS:New("Cargo Static " .. math.random(1,10000),position,100)
|
||||
if not dead then
|
||||
-- CTLD_CARGO:New(ID, Name, Templates, Sorte, HasBeenMoved, LoadDirectly, CratesNeeded, Positionable, Dropped, PerCrateMass, Stock)
|
||||
local injectstatic = CTLD_CARGO:New(nil,"Cargo Static Group "..math.random(1,10000),"iso_container",CTLD_CARGO.Enum.STATIC,true,false,1,nil,true,4500,1)
|
||||
self.CTLD:InjectStatics(Zone,injectstatic,true)
|
||||
else
|
||||
--local static = SPAWNSTATIC:NewFromType("iso_container","Cargos",Cargo_Country)
|
||||
--static.InitDead = true
|
||||
--static:SpawnFromZone(Zone,CargoHeading)
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- [Internal] Spawn cargo objects
|
||||
-- @param #CTLD_HERCULES self
|
||||
-- @param Wrapper.Group#GROUP Cargo_Drop_initiator
|
||||
-- @param #number Cargo_Drop_Direction
|
||||
-- @param Core.Point#COORDINATE Cargo_Content_position
|
||||
-- @param #string Cargo_Type_name
|
||||
-- @param #boolean Cargo_over_water
|
||||
-- @param #boolean Container_Enclosed
|
||||
-- @param #boolean ParatrooperGroupSpawn
|
||||
-- @param #boolean offload_cargo
|
||||
-- @param #boolean all_cargo_survive_to_the_ground
|
||||
-- @param #boolean all_cargo_gets_destroyed
|
||||
-- @param #boolean destroy_cargo_dropped_without_parachute
|
||||
-- @param #number Cargo_Country
|
||||
-- @return #CTLD_HERCULES self
|
||||
function CTLD_HERCULES:Cargo_SpawnObjects(Cargo_Drop_initiator,Cargo_Drop_Direction, Cargo_Content_position, Cargo_Type_name, Cargo_over_water, Container_Enclosed, ParatrooperGroupSpawn, offload_cargo, all_cargo_survive_to_the_ground, all_cargo_gets_destroyed, destroy_cargo_dropped_without_parachute, Cargo_Country)
|
||||
self:T(self.lid .. 'Cargo_SpawnObjects')
|
||||
|
||||
local CargoHeading = self.CargoHeading
|
||||
--local Cargo_Drop_Position = {}
|
||||
|
||||
if offload_cargo == true or ParatrooperGroupSpawn == true then
|
||||
if ParatrooperGroupSpawn == true then
|
||||
self:Soldier_SpawnGroup(Cargo_Drop_initiator,Cargo_Content_position, Cargo_Type_name, CargoHeading, Cargo_Country, 0)
|
||||
self:Soldier_SpawnGroup(Cargo_Drop_initiator,Cargo_Content_position, Cargo_Type_name, CargoHeading, Cargo_Country, 5)
|
||||
self:Soldier_SpawnGroup(Cargo_Drop_initiator,Cargo_Content_position, Cargo_Type_name, CargoHeading, Cargo_Country, 10)
|
||||
else
|
||||
self:Cargo_SpawnGroup(Cargo_Drop_initiator,Cargo_Content_position, Cargo_Type_name, CargoHeading, Cargo_Country, 0)
|
||||
end
|
||||
else
|
||||
if all_cargo_gets_destroyed == true or Cargo_over_water == true then
|
||||
if Container_Enclosed == true then
|
||||
--self:Cargo_SpawnStatic(Cargo_Drop_initiator,Cargo_Content_position, Cargo_Type_name, CargoHeading, true, Cargo_Country)
|
||||
if ParatrooperGroupSpawn == false then
|
||||
--self:Cargo_SpawnStatic(Cargo_Drop_initiator,Cargo_Content_position, "Hercules_Container_Parachute_Static", CargoHeading, true, Cargo_Country)
|
||||
end
|
||||
else
|
||||
--self:Cargo_SpawnStatic(Cargo_Drop_initiator,Cargo_Content_position, Cargo_Type_name, CargoHeading, true, Cargo_Country)
|
||||
end
|
||||
else
|
||||
if all_cargo_survive_to_the_ground == true then
|
||||
if ParatrooperGroupSpawn == true then
|
||||
self:Cargo_SpawnStatic(Cargo_Drop_initiator,Cargo_Content_position, Cargo_Type_name, CargoHeading, true, Cargo_Country)
|
||||
else
|
||||
self:Cargo_SpawnGroup(Cargo_Drop_initiator,Cargo_Content_position, Cargo_Type_name, CargoHeading, Cargo_Country)
|
||||
end
|
||||
if Container_Enclosed == true then
|
||||
if ParatrooperGroupSpawn == false then
|
||||
self:Cargo_SpawnStatic(Cargo_Drop_initiator,Cargo_Content_position, "Hercules_Container_Parachute_Static", CargoHeading, false, Cargo_Country)
|
||||
end
|
||||
end
|
||||
end
|
||||
if destroy_cargo_dropped_without_parachute == true then
|
||||
if Container_Enclosed == true then
|
||||
if ParatrooperGroupSpawn == true then
|
||||
self:Soldier_SpawnGroup(Cargo_Drop_initiator,Cargo_Content_position, Cargo_Type_name, CargoHeading, Cargo_Country, 0)
|
||||
else
|
||||
self:Cargo_SpawnGroup(Cargo_Drop_initiator,Cargo_Content_position, Cargo_Type_name, CargoHeading, Cargo_Country)
|
||||
self:Cargo_SpawnStatic(Cargo_Drop_initiator,Cargo_Content_position, "Hercules_Container_Parachute_Static", CargoHeading, false, Cargo_Country)
|
||||
end
|
||||
else
|
||||
self:Cargo_SpawnStatic(Cargo_Drop_initiator,Cargo_Content_position, Cargo_Type_name, CargoHeading, true, Cargo_Country)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- [Internal] Function to calculate object height
|
||||
-- @param #CTLD_HERCULES self
|
||||
-- @param Wrapper.Group#GROUP group The group for which to calculate the height
|
||||
-- @return #number height over ground
|
||||
function CTLD_HERCULES:Calculate_Object_Height_AGL(group)
|
||||
self:T(self.lid .. "Calculate_Object_Height_AGL")
|
||||
if group.ClassName and group.ClassName == "GROUP" then
|
||||
local gcoord = group:GetCoordinate()
|
||||
local height = group:GetHeight()
|
||||
local lheight = gcoord:GetLandHeight()
|
||||
self:T(self.lid .. "Height " .. height - lheight)
|
||||
return height - lheight
|
||||
else
|
||||
-- DCS object
|
||||
--self:T({group})
|
||||
if group:isExist() then
|
||||
local dcsposition = group:getPosition().p
|
||||
local dcsvec2 = {x = dcsposition.x, y = dcsposition.z} -- Vec2
|
||||
local height = math.floor(group:getPosition().p.y - land.getHeight(dcsvec2))
|
||||
self.ObjectTracker[group.id_] = dcsposition -- Vec3
|
||||
self:T(self.lid .. "Height " .. height)
|
||||
--self:T({group.id_,self.ObjectTracker[group.id_]})
|
||||
return height
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- [Internal] Function to check surface type
|
||||
-- @param #CTLD_HERCULES self
|
||||
-- @param Wrapper.Group#GROUP group The group for which to calculate the height
|
||||
-- @return #number height over ground
|
||||
function CTLD_HERCULES:Check_SurfaceType(object)
|
||||
self:T(self.lid .. "Check_SurfaceType")
|
||||
-- LAND,--1 SHALLOW_WATER,--2 WATER,--3 ROAD,--4 RUNWAY--5
|
||||
if object:isExist() then
|
||||
return land.getSurfaceType({x = object:getPosition().p.x, y = object:getPosition().p.z})
|
||||
else
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
--- [Internal] Function to track cargo objects
|
||||
-- @param #CTLD_HERCULES self
|
||||
-- @param #CTLD_HERCULES.CargoObject cargo
|
||||
-- @param Wrapper.Group#GROUP initiator
|
||||
-- @return #number height over ground
|
||||
function CTLD_HERCULES:Cargo_Track(cargo, initiator)
|
||||
self:T(self.lid .. "Cargo_Track")
|
||||
local Cargo_Drop_initiator = initiator
|
||||
if cargo.Cargo_Contents ~= nil then
|
||||
if self:Calculate_Object_Height_AGL(cargo.Cargo_Contents) < 10 then --pallet less than 5m above ground before spawning
|
||||
if self:Check_SurfaceType(cargo.Cargo_Contents) == 2 or self:Check_SurfaceType(cargo.Cargo_Contents) == 3 then
|
||||
cargo.Cargo_over_water = true--pallets gets destroyed in water
|
||||
end
|
||||
local dcsvec3 = self.ObjectTracker[cargo.Cargo_Contents.id_] -- last known position
|
||||
self:T("SPAWNPOSITION: ")
|
||||
self:T({dcsvec3})
|
||||
local Vec2 = {
|
||||
x=dcsvec3.x,
|
||||
y=dcsvec3.z,
|
||||
}
|
||||
local vec3 = COORDINATE:NewFromVec2(Vec2)
|
||||
self.ObjectTracker[cargo.Cargo_Contents.id_] = nil
|
||||
self:Cargo_SpawnObjects(Cargo_Drop_initiator,cargo.Cargo_Drop_Direction, vec3, cargo.Cargo_Type_name, cargo.Cargo_over_water, cargo.Container_Enclosed, cargo.ParatrooperGroupSpawn, cargo.offload_cargo, cargo.all_cargo_survive_to_the_ground, cargo.all_cargo_gets_destroyed, cargo.destroy_cargo_dropped_without_parachute, cargo.Cargo_Country)
|
||||
if cargo.Cargo_Contents:isExist() then
|
||||
cargo.Cargo_Contents:destroy()--remove pallet+parachute before hitting ground and replace with Cargo_SpawnContents
|
||||
end
|
||||
--timer.removeFunction(cargo.scheduleFunctionID)
|
||||
cargo.scheduleFunctionID:Stop()
|
||||
cargo = {}
|
||||
end
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- [Internal] Function to calc north correction
|
||||
-- @param #CTLD_HERCULES self
|
||||
-- @param Core.Point#POINT_Vec3 point Position Vec3
|
||||
-- @return #number north correction
|
||||
function CTLD_HERCULES:Calculate_Cargo_Drop_initiator_NorthCorrection(point)
|
||||
self:T(self.lid .. "Calculate_Cargo_Drop_initiator_NorthCorrection")
|
||||
if not point.z then --Vec2; convert to Vec3
|
||||
point.z = point.y
|
||||
point.y = 0
|
||||
end
|
||||
local lat, lon = coord.LOtoLL(point)
|
||||
local north_posit = coord.LLtoLO(lat + 1, lon)
|
||||
return math.atan2(north_posit.z - point.z, north_posit.x - point.x)
|
||||
end
|
||||
|
||||
--- [Internal] Function to calc initiator heading
|
||||
-- @param #CTLD_HERCULES self
|
||||
-- @param Wrapper.Group#GROUP Cargo_Drop_initiator
|
||||
-- @return #number north corrected heading
|
||||
function CTLD_HERCULES:Calculate_Cargo_Drop_initiator_Heading(Cargo_Drop_initiator)
|
||||
self:T(self.lid .. "Calculate_Cargo_Drop_initiator_Heading")
|
||||
local Heading = Cargo_Drop_initiator:GetHeading()
|
||||
Heading = Heading + self:Calculate_Cargo_Drop_initiator_NorthCorrection(Cargo_Drop_initiator:GetVec3())
|
||||
if Heading < 0 then
|
||||
Heading = Heading + (2 * math.pi)-- put heading in range of 0 to 2*pi
|
||||
end
|
||||
return Heading + 0.06 -- rad
|
||||
end
|
||||
|
||||
--- [Internal] Function to initialize dropped cargo
|
||||
-- @param #CTLD_HERCULES self
|
||||
-- @param Wrapper.Group#GROUP Initiator
|
||||
-- @param #table Cargo_Contents Table 'weapon' from event data
|
||||
-- @param #string Cargo_Type_name Name of this cargo
|
||||
-- @param #boolean Container_Enclosed Is container?
|
||||
-- @param #boolean SoldierGroup Is soldier group?
|
||||
-- @param #boolean ParatrooperGroupSpawnInit Is paratroopers?
|
||||
-- @return #CTLD_HERCULES self
|
||||
function CTLD_HERCULES:Cargo_Initialize(Initiator, Cargo_Contents, Cargo_Type_name, Container_Enclosed, SoldierGroup, ParatrooperGroupSpawnInit)
|
||||
self:T(self.lid .. "Cargo_Initialize")
|
||||
local Cargo_Drop_initiator = Initiator:GetName()
|
||||
if Cargo_Drop_initiator ~= nil then
|
||||
if ParatrooperGroupSpawnInit == true then
|
||||
self:T("Paratrooper Drop")
|
||||
-- Paratroopers
|
||||
if not self.ParatrooperCount[Cargo_Drop_initiator] then
|
||||
self.ParatrooperCount[Cargo_Drop_initiator] = 1
|
||||
else
|
||||
self.ParatrooperCount[Cargo_Drop_initiator] = self.ParatrooperCount[Cargo_Drop_initiator] + 1
|
||||
end
|
||||
|
||||
local Paratroopers = self.ParatrooperCount[Cargo_Drop_initiator]
|
||||
|
||||
self:T("Paratrooper Drop Number " .. self.ParatrooperCount[Cargo_Drop_initiator])
|
||||
|
||||
local SpawnParas = false
|
||||
|
||||
if math.fmod(Paratroopers,10) == 0 then
|
||||
SpawnParas = true
|
||||
end
|
||||
|
||||
self.j = self.j + 1
|
||||
self.Cargo[self.j] = {}
|
||||
self.Cargo[self.j].Cargo_Drop_Direction = self:Calculate_Cargo_Drop_initiator_Heading(Initiator)
|
||||
self.Cargo[self.j].Cargo_Contents = Cargo_Contents
|
||||
self.Cargo[self.j].Cargo_Type_name = Cargo_Type_name
|
||||
self.Cargo[self.j].Container_Enclosed = Container_Enclosed
|
||||
self.Cargo[self.j].ParatrooperGroupSpawn = SpawnParas
|
||||
self.Cargo[self.j].Cargo_Country = Initiator:GetCountry()
|
||||
|
||||
if self:Calculate_Object_Height_AGL(Initiator) < 5.0 then --aircraft on ground
|
||||
self.Cargo[self.j].offload_cargo = true
|
||||
elseif self:Calculate_Object_Height_AGL(Initiator) < 10.0 then --aircraft less than 10m above ground
|
||||
self.Cargo[self.j].all_cargo_survive_to_the_ground = true
|
||||
elseif self:Calculate_Object_Height_AGL(Initiator) < 100.0 then --aircraft more than 10m but less than 100m above ground
|
||||
self.Cargo[self.j].all_cargo_gets_destroyed = true
|
||||
else
|
||||
self.Cargo[self.j].all_cargo_gets_destroyed = false
|
||||
end
|
||||
|
||||
local timer = TIMER:New(self.Cargo_Track,self,self.Cargo[self.j],Initiator)
|
||||
self.Cargo[self.j].scheduleFunctionID = timer
|
||||
timer:Start(5,2,600)
|
||||
|
||||
else
|
||||
-- no paras
|
||||
self.j = self.j + 1
|
||||
self.Cargo[self.j] = {}
|
||||
self.Cargo[self.j].Cargo_Drop_Direction = self:Calculate_Cargo_Drop_initiator_Heading(Initiator)
|
||||
self.Cargo[self.j].Cargo_Contents = Cargo_Contents
|
||||
self.Cargo[self.j].Cargo_Type_name = Cargo_Type_name
|
||||
self.Cargo[self.j].Container_Enclosed = Container_Enclosed
|
||||
self.Cargo[self.j].ParatrooperGroupSpawn = false
|
||||
self.Cargo[self.j].Cargo_Country = Initiator:GetCountry()
|
||||
|
||||
if self:Calculate_Object_Height_AGL(Initiator) < 5.0 then--aircraft on ground
|
||||
self.Cargo[self.j].offload_cargo = true
|
||||
elseif self:Calculate_Object_Height_AGL(Initiator) < 10.0 then--aircraft less than 10m above ground
|
||||
self.Cargo[self.j].all_cargo_survive_to_the_ground = true
|
||||
elseif self:Calculate_Object_Height_AGL(Initiator) < 100.0 then--aircraft more than 10m but less than 100m above ground
|
||||
self.Cargo[self.j].all_cargo_gets_destroyed = true
|
||||
else
|
||||
self.Cargo[self.j].destroy_cargo_dropped_without_parachute = true --aircraft more than 100m above ground
|
||||
end
|
||||
|
||||
local timer = TIMER:New(self.Cargo_Track,self,self.Cargo[self.j],Initiator)
|
||||
self.Cargo[self.j].scheduleFunctionID = timer
|
||||
timer:Start(5,2,600)
|
||||
end
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- [Internal] Function to change cargotype per group (Wrench)
|
||||
-- @param #CTLD_HERCULES self
|
||||
-- @param #number key Carrier key id
|
||||
-- @param #string cargoType Type of cargo
|
||||
-- @param #number cargoNum Number of cargo objects
|
||||
-- @return #CTLD_HERCULES self
|
||||
function CTLD_HERCULES:SetType(key,cargoType,cargoNum)
|
||||
self:T(self.lid .. "SetType")
|
||||
self.carrierGroups[key]['cargoType'] = cargoType
|
||||
self.carrierGroups[key]['cargoNum'] = cargoNum
|
||||
return self
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- EventHandlers
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- [Internal] Function to capture SHOT event
|
||||
-- @param #CTLD_HERCULES self
|
||||
-- @param Core.Event#EVENTDATA Cargo_Drop_Event The event data
|
||||
-- @return #CTLD_HERCULES self
|
||||
function CTLD_HERCULES:_HandleShot(Cargo_Drop_Event)
|
||||
self:T(self.lid .. "Shot Event ID:" .. Cargo_Drop_Event.id)
|
||||
if Cargo_Drop_Event.id == EVENTS.Shot then
|
||||
|
||||
local GT_Name = ""
|
||||
local SoldierGroup = false
|
||||
local ParatrooperGroupSpawnInit = false
|
||||
|
||||
local GT_DisplayName = Weapon.getDesc(Cargo_Drop_Event.weapon).typeName:sub(15, -1)--Remove "weapons.bombs." from string
|
||||
self:T(string.format("%sCargo_Drop_Event: %s", self.lid, Weapon.getDesc(Cargo_Drop_Event.weapon).typeName))
|
||||
|
||||
if (GT_DisplayName == "Squad 30 x Soldier [7950lb]") then
|
||||
self:Cargo_Initialize(Cargo_Drop_Event.IniGroup, Cargo_Drop_Event.weapon, "Soldier M4 GRG", false, true, true)
|
||||
end
|
||||
|
||||
if self.Types[GT_DisplayName] then
|
||||
local GT_Name = self.Types[GT_DisplayName]['name']
|
||||
local Cargo_Container_Enclosed = self.Types[GT_DisplayName]['container']
|
||||
self:Cargo_Initialize(Cargo_Drop_Event.IniGroup, Cargo_Drop_Event.weapon, GT_Name, Cargo_Container_Enclosed)
|
||||
end
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- [Internal] Function to capture BIRTH event
|
||||
-- @param #CTLD_HERCULES self
|
||||
-- @param Core.Event#EVENTDATA event The event data
|
||||
-- @return #CTLD_HERCULES self
|
||||
function CTLD_HERCULES:_HandleBirth(event)
|
||||
-- not sure what this is needed for? I think this for setting generic crates "content" setting.
|
||||
self:T(self.lid .. "Birth Event ID:" .. event.id)
|
||||
--[[
|
||||
if event.id == EVENTS.Birth then
|
||||
local desc = event.initiator:getDesc()
|
||||
if desc["displayName"] == "Hercules" then
|
||||
local grpTab = {}
|
||||
grpTab['object'] = event.IniGroup
|
||||
grpTab['name'] = event.IniGroupName
|
||||
grpTab['cargoType'] = 'Container red 1'
|
||||
grpTab['cargoNum'] = 1
|
||||
grpTab['key'] = #self.carrierGroups + 1
|
||||
|
||||
table.insert(self.carrierGroups,grpTab)
|
||||
|
||||
local hercCargoMenu = MENU_GROUP:New(event.IniGroup,"CargoTypes",nil)
|
||||
local mlrs = MENU_GROUP_COMMAND:New(event.IniGroup,"MLRS",hercCargoMenu,self.SetType,self,grpTab['key'],'MLRS',1)
|
||||
local mlrs = MENU_GROUP_COMMAND:New(event.IniGroup,"Mortar",hercCargoMenu,self.SetType,self,grpTab['key'],'2B11 mortar',8)
|
||||
local mlrs = MENU_GROUP_COMMAND:New(event.IniGroup,"M-109",hercCargoMenu,self.SetType,self,grpTab['key'],'M-109',1)
|
||||
local mlrs = MENU_GROUP_COMMAND:New(event.IniGroup,"FOB Crate",hercCargoMenu,self.SetType,self,grpTab['key'],'Container red 1',1)
|
||||
end
|
||||
end
|
||||
--]]
|
||||
return self
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------
|
||||
-- End Ops.CTLD.lua
|
||||
-------------------------------------------------------------------
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user