mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
CTLD - added ability to spawn crates on ships
This commit is contained in:
parent
830f76e909
commit
94167152e5
@ -22,7 +22,7 @@
|
|||||||
-- @module Ops.CTLD
|
-- @module Ops.CTLD
|
||||||
-- @image OPS_CTLD.jpg
|
-- @image OPS_CTLD.jpg
|
||||||
|
|
||||||
-- Date: July 2021
|
-- Date: Aug 2021
|
||||||
|
|
||||||
do
|
do
|
||||||
------------------------------------------------------
|
------------------------------------------------------
|
||||||
@ -264,7 +264,7 @@ do
|
|||||||
-- Add zones for loading troops and crates and dropping, building crates
|
-- Add 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 troops and crates.
|
||||||
-- -- "Loadzone" is the name of the zone from the ME. Players can load, if they are inside of the zone.
|
-- -- "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.
|
-- -- 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)
|
-- my_ctld:AddCTLDZone("Loadzone",CTLD.CargoZoneType.LOAD,SMOKECOLOR.Blue,true,true)
|
||||||
--
|
--
|
||||||
@ -279,6 +279,13 @@ do
|
|||||||
--
|
--
|
||||||
-- my_ctld:AddCTLDZone("Movezone2",CTLD.CargoZoneType.MOVE,SMOKECOLOR.White,true,true)
|
-- my_ctld:AddCTLDZone("Movezone2",CTLD.CargoZoneType.MOVE,SMOKECOLOR.White,true,true)
|
||||||
--
|
--
|
||||||
|
-- -- Add a zone of type SHIP to our setup. Players can load troops and crates from this ship
|
||||||
|
-- -- "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 smoke, flares, beacons don't work for this type of loadzone (yet). Also, 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.
|
||||||
|
-- my_ctld:AddCTLDZone("Tarawa",CTLD.CargoZoneType.SHIP,SMOKECOLOR.Blue,true,true,240,20)
|
||||||
--
|
--
|
||||||
-- ## 2. Options
|
-- ## 2. Options
|
||||||
--
|
--
|
||||||
@ -511,11 +518,13 @@ CTLD = {
|
|||||||
-- @field #string name Name of Zone.
|
-- @field #string name Name of Zone.
|
||||||
-- @field #string color Smoke color for zone, e.g. SMOKECOLOR.Red.
|
-- @field #string color Smoke color for zone, e.g. SMOKECOLOR.Red.
|
||||||
-- @field #boolean active Active or not.
|
-- @field #boolean active Active or not.
|
||||||
-- @field #string type Type of zone, i.e. load,drop,move
|
-- @field #string type Type of zone, i.e. load,drop,move,ship
|
||||||
-- @field #boolean hasbeacon Create and run radio beacons if active.
|
-- @field #boolean hasbeacon Create and run radio beacons if active.
|
||||||
-- @field #table fmbeacon Beacon info as #CTLD.ZoneBeacon
|
-- @field #table fmbeacon Beacon info as #CTLD.ZoneBeacon
|
||||||
-- @field #table uhfbeacon Beacon info as #CTLD.ZoneBeacon
|
-- @field #table uhfbeacon Beacon info as #CTLD.ZoneBeacon
|
||||||
-- @field #table vhfbeacon Beacon info as #CTLD.ZoneBeacon
|
-- @field #table vhfbeacon Beacon info as #CTLD.ZoneBeacon
|
||||||
|
-- @field #number shiplength For ships - length of ship
|
||||||
|
-- @field #number shipwidth For ships - width of ship
|
||||||
|
|
||||||
--- Zone Type Info.
|
--- Zone Type Info.
|
||||||
-- @type CTLD.CargoZoneType
|
-- @type CTLD.CargoZoneType
|
||||||
@ -523,6 +532,7 @@ CTLD.CargoZoneType = {
|
|||||||
LOAD = "load",
|
LOAD = "load",
|
||||||
DROP = "drop",
|
DROP = "drop",
|
||||||
MOVE = "move",
|
MOVE = "move",
|
||||||
|
SHIP = "ship",
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Buildable table info.
|
--- Buildable table info.
|
||||||
@ -557,7 +567,7 @@ CTLD.UnitTypes = {
|
|||||||
|
|
||||||
--- CTLD class version.
|
--- CTLD class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
CTLD.version="0.1.4r3"
|
CTLD.version="0.1.5a1"
|
||||||
|
|
||||||
--- Instantiate a new CTLD.
|
--- Instantiate a new CTLD.
|
||||||
-- @param #CTLD self
|
-- @param #CTLD self
|
||||||
@ -643,6 +653,7 @@ function CTLD:New(Coalition, Prefixes, Alias)
|
|||||||
self.pickupZones = {}
|
self.pickupZones = {}
|
||||||
self.dropOffZones = {}
|
self.dropOffZones = {}
|
||||||
self.wpZones = {}
|
self.wpZones = {}
|
||||||
|
self.shipZones = {}
|
||||||
|
|
||||||
-- Cargo
|
-- Cargo
|
||||||
self.Cargo_Crates = {}
|
self.Cargo_Crates = {}
|
||||||
@ -928,6 +939,9 @@ function CTLD:_LoadTroops(Group, Unit, Cargotype)
|
|||||||
local hoverload = self:CanHoverLoad(Unit)
|
local hoverload = self:CanHoverLoad(Unit)
|
||||||
-- check if we are in LOAD zone
|
-- check if we are in LOAD zone
|
||||||
local inzone, zonename, zone, distance = self:IsUnitInZone(Unit,CTLD.CargoZoneType.LOAD)
|
local inzone, zonename, zone, distance = self:IsUnitInZone(Unit,CTLD.CargoZoneType.LOAD)
|
||||||
|
if not inzone then
|
||||||
|
inzone, zonename, zone, distance = self:IsUnitInZone(Unit,CTLD.CargoZoneType.SHIP)
|
||||||
|
end
|
||||||
if not inzone then
|
if not inzone then
|
||||||
self:_SendMessage("You are not close enough to a logistics zone!", 10, false, Group)
|
self:_SendMessage("You are not close enough to a logistics zone!", 10, false, Group)
|
||||||
if not self.debug then return self end
|
if not self.debug then return self end
|
||||||
@ -1186,8 +1200,13 @@ function CTLD:_GetCrates(Group, Unit, Cargo, number, drop)
|
|||||||
-- check if we are in LOAD zone
|
-- check if we are in LOAD zone
|
||||||
local inzone = false
|
local inzone = false
|
||||||
local drop = drop or false
|
local drop = drop or false
|
||||||
|
local ship = nil
|
||||||
|
local width = 20
|
||||||
if not drop then
|
if not drop then
|
||||||
inzone = self:IsUnitInZone(Unit,CTLD.CargoZoneType.LOAD)
|
inzone = self:IsUnitInZone(Unit,CTLD.CargoZoneType.LOAD)
|
||||||
|
if not inzone then
|
||||||
|
inzone, ship, zone, distance, width = self:IsUnitInZone(Unit,CTLD.CargoZoneType.SHIP)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
if self.dropcratesanywhere then -- #1570
|
if self.dropcratesanywhere then -- #1570
|
||||||
inzone = true
|
inzone = true
|
||||||
@ -1233,18 +1252,33 @@ function CTLD:_GetCrates(Group, Unit, Cargo, number, drop)
|
|||||||
for i=1,50 do
|
for i=1,50 do
|
||||||
math.random(90,270)
|
math.random(90,270)
|
||||||
end
|
end
|
||||||
local rheading = math.floor(math.random(90,270) * heading + 1 / 360)
|
local rheading = math.floor(((math.random(90,270) * heading) + 1) / 360)
|
||||||
if not IsHerc then
|
if not IsHerc then
|
||||||
rheading = rheading + 180 -- mirror for Helis
|
rheading = rheading + 180 -- mirror for Helis
|
||||||
end
|
end
|
||||||
if rheading > 360 then rheading = rheading - 360 end -- catch > 360
|
if rheading > 360 then rheading = rheading - 360 end -- catch > 360
|
||||||
local cratecoord = position:Translate(cratedistance,rheading)
|
local cratecoord = position:Translate(cratedistance,rheading)
|
||||||
local cratevec2 = cratecoord:GetVec2()
|
local cratevec2 = cratecoord:GetVec2()
|
||||||
self.CrateCounter = self.CrateCounter + 1
|
self.CrateCounter = self.CrateCounter + 1
|
||||||
|
if type(ship) == "string" then
|
||||||
|
self:T("Spawning on ship "..ship)
|
||||||
|
local Ship = UNIT:FindByName(ship)
|
||||||
|
local shipcoord = Ship:GetCoordinate()
|
||||||
|
local unitcoord = Unit:GetCoordinate()
|
||||||
|
local dist = shipcoord:Get2DDistance(unitcoord)
|
||||||
|
dist = dist - (20 + math.random(1,10))
|
||||||
|
local width = width / 2
|
||||||
|
local Offy = math.random(-width,width)
|
||||||
|
self.Spawned_Crates[self.CrateCounter] = SPAWNSTATIC:NewFromType("container_cargo","Cargos",country.id.GERMANY)
|
||||||
|
--:InitCoordinate(cratecoord)
|
||||||
|
:InitLinkToUnit(Ship,dist,Offy,0)
|
||||||
|
:Spawn(270,cratealias)
|
||||||
|
else
|
||||||
self.Spawned_Crates[self.CrateCounter] = SPAWNSTATIC:NewFromType("container_cargo","Cargos",country.id.GERMANY)
|
self.Spawned_Crates[self.CrateCounter] = SPAWNSTATIC:NewFromType("container_cargo","Cargos",country.id.GERMANY)
|
||||||
:InitCoordinate(cratecoord)
|
:InitCoordinate(cratecoord)
|
||||||
|
--:InitLinkToUnit(Unit,OffsetX,OffsetY,OffsetAngle)
|
||||||
:Spawn(270,cratealias)
|
:Spawn(270,cratealias)
|
||||||
|
end
|
||||||
local templ = cargotype:GetTemplates()
|
local templ = cargotype:GetTemplates()
|
||||||
local sorte = cargotype:GetType()
|
local sorte = cargotype:GetType()
|
||||||
self.CargoCounter = self.CargoCounter +1
|
self.CargoCounter = self.CargoCounter +1
|
||||||
@ -1482,9 +1516,10 @@ function CTLD:_UpdateUnitCargoMass(Unit)
|
|||||||
self:T(self.lid .. " _UpdateUnitCargoMass")
|
self:T(self.lid .. " _UpdateUnitCargoMass")
|
||||||
local calculatedMass = self:_GetUnitCargoMass(Unit)
|
local calculatedMass = self:_GetUnitCargoMass(Unit)
|
||||||
Unit:SetUnitInternalCargo(calculatedMass)
|
Unit:SetUnitInternalCargo(calculatedMass)
|
||||||
local report = REPORT:New("Loadmaster report")
|
--local report = REPORT:New("Loadmaster report")
|
||||||
report:Add("Carrying " .. calculatedMass .. "Kg")
|
--report:Add("Carrying " .. calculatedMass .. "Kg")
|
||||||
self:_SendMessage(report:Text(),10,false,Unit:GetGroup())
|
--self:_SendMessage(report:Text(),10,false,Unit:GetGroup())
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- (Internal) Function to list loaded cargo.
|
--- (Internal) Function to list loaded cargo.
|
||||||
@ -1565,6 +1600,9 @@ function CTLD:_UnloadTroops(Group, Unit)
|
|||||||
-- check if we are in LOAD zone
|
-- check if we are in LOAD zone
|
||||||
local droppingatbase = false
|
local droppingatbase = false
|
||||||
local inzone, zonename, zone, distance = self:IsUnitInZone(Unit,CTLD.CargoZoneType.LOAD)
|
local inzone, zonename, zone, distance = self:IsUnitInZone(Unit,CTLD.CargoZoneType.LOAD)
|
||||||
|
if not inzone then
|
||||||
|
inzone, zonename, zone, distance = self:IsUnitInZone(Unit,CTLD.CargoZoneType.SHIP)
|
||||||
|
end
|
||||||
if inzone then
|
if inzone then
|
||||||
droppingatbase = true
|
droppingatbase = true
|
||||||
end
|
end
|
||||||
@ -2141,6 +2179,8 @@ function CTLD:AddZone(Zone)
|
|||||||
table.insert(self.pickupZones,zone)
|
table.insert(self.pickupZones,zone)
|
||||||
elseif zone.type == CTLD.CargoZoneType.DROP then
|
elseif zone.type == CTLD.CargoZoneType.DROP then
|
||||||
table.insert(self.dropOffZones,zone)
|
table.insert(self.dropOffZones,zone)
|
||||||
|
elseif zone.type == CTLD.CargoZoneType.SHIP then
|
||||||
|
table.insert(self.shipZones,zone)
|
||||||
else
|
else
|
||||||
table.insert(self.wpZones,zone)
|
table.insert(self.wpZones,zone)
|
||||||
end
|
end
|
||||||
@ -2166,6 +2206,8 @@ function CTLD:ActivateZone(Name,ZoneType,NewState)
|
|||||||
table = self.pickupZones
|
table = self.pickupZones
|
||||||
elseif ZoneType == CTLD.CargoZoneType.DROP then
|
elseif ZoneType == CTLD.CargoZoneType.DROP then
|
||||||
table = self.dropOffZones
|
table = self.dropOffZones
|
||||||
|
elseif ZoneType == CTLD.CargoZoneType.SHIP then
|
||||||
|
table = self.shipZones
|
||||||
else
|
else
|
||||||
table = self.wpZones
|
table = self.wpZones
|
||||||
end
|
end
|
||||||
@ -2263,8 +2305,10 @@ end
|
|||||||
-- @param #number Color Smoke/Flare color e.g. #SMOKECOLOR.Red
|
-- @param #number Color Smoke/Flare color e.g. #SMOKECOLOR.Red
|
||||||
-- @param #string Active Is this zone currently active?
|
-- @param #string Active Is this zone currently active?
|
||||||
-- @param #string HasBeacon Does this zone have a beacon if it is active?
|
-- @param #string HasBeacon Does this zone have a beacon if it is active?
|
||||||
|
-- @param #number Shiplength Length of Ship for shipzones
|
||||||
|
-- @param #number Shipwidth Width of Ship for shipzones
|
||||||
-- @return #CTLD self
|
-- @return #CTLD self
|
||||||
function CTLD:AddCTLDZone(Name, Type, Color, Active, HasBeacon)
|
function CTLD:AddCTLDZone(Name, Type, Color, Active, HasBeacon, Shiplength, Shipwidth)
|
||||||
self:T(self.lid .. " AddCTLDZone")
|
self:T(self.lid .. " AddCTLDZone")
|
||||||
|
|
||||||
local ctldzone = {} -- #CTLD.CargoZone
|
local ctldzone = {} -- #CTLD.CargoZone
|
||||||
@ -2284,6 +2328,11 @@ function CTLD:AddCTLDZone(Name, Type, Color, Active, HasBeacon)
|
|||||||
ctldzone.vhfbeacon = nil
|
ctldzone.vhfbeacon = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Type == CTLD.CargoZoneType.SHIP then
|
||||||
|
ctldzone.shiplength = Shiplength or 100
|
||||||
|
ctldzone.shipwidth = Shipwidth or 10
|
||||||
|
end
|
||||||
|
|
||||||
self:AddZone(ctldzone)
|
self:AddZone(ctldzone)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@ -2375,10 +2424,12 @@ end
|
|||||||
-- @param #CTLD.CargoZoneType Zonetype Zonetype
|
-- @param #CTLD.CargoZoneType Zonetype Zonetype
|
||||||
-- @return #boolean Outcome Is in zone or not
|
-- @return #boolean Outcome Is in zone or not
|
||||||
-- @return #string name Closest zone name
|
-- @return #string name Closest zone name
|
||||||
-- @return #string zone Closest Core.Zone#ZONE object
|
-- @return Core.Zone#ZONE zone Closest Core.Zone#ZONE object
|
||||||
-- @return #number distance Distance to closest zone
|
-- @return #number distance Distance to closest zone
|
||||||
|
-- @return #number width Radius of zone or width of ship
|
||||||
function CTLD:IsUnitInZone(Unit,Zonetype)
|
function CTLD:IsUnitInZone(Unit,Zonetype)
|
||||||
self:T(self.lid .. " IsUnitInZone")
|
self:T(self.lid .. " IsUnitInZone")
|
||||||
|
self:T(Zonetype)
|
||||||
local unitname = Unit:GetName()
|
local unitname = Unit:GetName()
|
||||||
local zonetable = {}
|
local zonetable = {}
|
||||||
local outcome = false
|
local outcome = false
|
||||||
@ -2386,6 +2437,8 @@ function CTLD:IsUnitInZone(Unit,Zonetype)
|
|||||||
zonetable = self.pickupZones -- #table
|
zonetable = self.pickupZones -- #table
|
||||||
elseif Zonetype == CTLD.CargoZoneType.DROP then
|
elseif Zonetype == CTLD.CargoZoneType.DROP then
|
||||||
zonetable = self.dropOffZones -- #table
|
zonetable = self.dropOffZones -- #table
|
||||||
|
elseif Zonetype == CTLD.CargoZoneType.SHIP then
|
||||||
|
zonetable = self.shipZones -- #table
|
||||||
else
|
else
|
||||||
zonetable = self.wpZones -- #table
|
zonetable = self.wpZones -- #table
|
||||||
end
|
end
|
||||||
@ -2394,16 +2447,29 @@ function CTLD:IsUnitInZone(Unit,Zonetype)
|
|||||||
local colorret = nil
|
local colorret = nil
|
||||||
local maxdist = 1000000 -- 100km
|
local maxdist = 1000000 -- 100km
|
||||||
local zoneret = nil
|
local zoneret = nil
|
||||||
|
local zonewret = nil
|
||||||
local zonenameret = nil
|
local zonenameret = nil
|
||||||
for _,_cargozone in pairs(zonetable) do
|
for _,_cargozone in pairs(zonetable) do
|
||||||
local czone = _cargozone -- #CTLD.CargoZone
|
local czone = _cargozone -- #CTLD.CargoZone
|
||||||
local unitcoord = Unit:GetCoordinate()
|
local unitcoord = Unit:GetCoordinate()
|
||||||
local zonename = czone.name
|
local zonename = czone.name
|
||||||
local zone = ZONE:FindByName(zonename)
|
|
||||||
zonecoord = zone:GetCoordinate()
|
|
||||||
local active = czone.active
|
local active = czone.active
|
||||||
local color = czone.color
|
local color = czone.color
|
||||||
local zoneradius = zone:GetRadius()
|
local zone = nil
|
||||||
|
local zoneradius = 100
|
||||||
|
local zonewidth = 20
|
||||||
|
if Zonetype == CTLD.CargoZoneType.SHIP then
|
||||||
|
self:T("Checking Type Ship: "..zonename)
|
||||||
|
zone = UNIT:FindByName(zonename)
|
||||||
|
zonecoord = zone:GetCoordinate()
|
||||||
|
zoneradius = czone.shiplength
|
||||||
|
zonewidth = czone.shipwidth
|
||||||
|
else
|
||||||
|
zone = ZONE:FindByName(zonename)
|
||||||
|
zonecoord = zone:GetCoordinate()
|
||||||
|
zoneradius = zone:GetRadius()
|
||||||
|
zonewidth = zoneradius
|
||||||
|
end
|
||||||
local distance = self:_GetDistance(zonecoord,unitcoord)
|
local distance = self:_GetDistance(zonecoord,unitcoord)
|
||||||
if distance <= zoneradius and active then
|
if distance <= zoneradius and active then
|
||||||
outcome = true
|
outcome = true
|
||||||
@ -2412,10 +2478,15 @@ function CTLD:IsUnitInZone(Unit,Zonetype)
|
|||||||
maxdist = distance
|
maxdist = distance
|
||||||
zoneret = zone
|
zoneret = zone
|
||||||
zonenameret = zonename
|
zonenameret = zonename
|
||||||
|
zonewret = zonewidth
|
||||||
colorret = color
|
colorret = color
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return outcome, zonenameret, zoneret, maxdist
|
if Zonetype == CTLD.CargoZoneType.SHIP then
|
||||||
|
return outcome, zonenameret, zoneret, maxdist, zonewret
|
||||||
|
else
|
||||||
|
return outcome, zonenameret, zoneret, maxdist
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- User function - Start smoke in a zone close to the Unit.
|
--- User function - Start smoke in a zone close to the Unit.
|
||||||
@ -2598,6 +2669,9 @@ end
|
|||||||
self:T(self.lid .. " CanHoverLoad")
|
self:T(self.lid .. " CanHoverLoad")
|
||||||
if self:IsHercules(Unit) then return false end
|
if self:IsHercules(Unit) then return false end
|
||||||
local outcome = self:IsUnitInZone(Unit,CTLD.CargoZoneType.LOAD) and self:IsCorrectHover(Unit)
|
local outcome = self:IsUnitInZone(Unit,CTLD.CargoZoneType.LOAD) and self:IsCorrectHover(Unit)
|
||||||
|
if not outcome then
|
||||||
|
outcome = self:IsUnitInZone(Unit,CTLD.CargoZoneType.SHIP) --and self:IsCorrectHover(Unit)
|
||||||
|
end
|
||||||
return outcome
|
return outcome
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -2691,7 +2765,7 @@ end
|
|||||||
-- @return #CTLD self
|
-- @return #CTLD self
|
||||||
function CTLD:onafterStart(From, Event, To)
|
function CTLD:onafterStart(From, Event, To)
|
||||||
self:T({From, Event, To})
|
self:T({From, Event, To})
|
||||||
self:I(self.lid .. "Started.")
|
self:I(self.lid .. "Started ("..self.version..")")
|
||||||
if self.useprefix or self.enableHercules then
|
if self.useprefix or self.enableHercules then
|
||||||
local prefix = self.prefixes
|
local prefix = self.prefixes
|
||||||
if self.enableHercules then
|
if self.enableHercules then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user