mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
WAREHOUSE
- Added runway destroyed check.
This commit is contained in:
parent
9cac2674c4
commit
0c07a660ee
@ -84,6 +84,8 @@
|
|||||||
-- @field #number lowfuelthresh Low fuel threshold. Triggers the event AssetLowFuel if for any unit fuel goes below this number.
|
-- @field #number lowfuelthresh Low fuel threshold. Triggers the event AssetLowFuel if for any unit fuel goes below this number.
|
||||||
-- @field #boolean respawnafterdestroyed If true, warehouse is respawned after it was destroyed. Assets are kept.
|
-- @field #boolean respawnafterdestroyed If true, warehouse is respawned after it was destroyed. Assets are kept.
|
||||||
-- @field #number respawndelay Delay before respawn in seconds.
|
-- @field #number respawndelay Delay before respawn in seconds.
|
||||||
|
-- @field #number runwaydestroyed Time stamp timer.getAbsTime() when the runway was destroyed.
|
||||||
|
-- @field #number runwayrepairtime Time in seconds until runway will be repaired after it was destroyed. Default is 3600 sec (one hour).
|
||||||
-- @extends Core.Fsm#FSM
|
-- @extends Core.Fsm#FSM
|
||||||
|
|
||||||
--- Have your assets at the right place at the right time - or not!
|
--- Have your assets at the right place at the right time - or not!
|
||||||
@ -1893,6 +1895,7 @@ function WAREHOUSE:New(warehouse, alias)
|
|||||||
-- Defaults
|
-- Defaults
|
||||||
self:SetMarker(true)
|
self:SetMarker(true)
|
||||||
self:SetReportOff()
|
self:SetReportOff()
|
||||||
|
self:SetRunwayRepairtime()
|
||||||
--self:SetVerbosityLevel(0)
|
--self:SetVerbosityLevel(0)
|
||||||
|
|
||||||
-- Add warehouse to database.
|
-- Add warehouse to database.
|
||||||
@ -1944,6 +1947,8 @@ function WAREHOUSE:New(warehouse, alias)
|
|||||||
self:AddTransition("Attacked", "Captured", "Running") -- Warehouse was captured by another coalition. It must have been attacked first.
|
self:AddTransition("Attacked", "Captured", "Running") -- Warehouse was captured by another coalition. It must have been attacked first.
|
||||||
self:AddTransition("*", "AirbaseCaptured", "*") -- Airbase was captured by other coalition.
|
self:AddTransition("*", "AirbaseCaptured", "*") -- Airbase was captured by other coalition.
|
||||||
self:AddTransition("*", "AirbaseRecaptured", "*") -- Airbase was re-captured from other coalition.
|
self:AddTransition("*", "AirbaseRecaptured", "*") -- Airbase was re-captured from other coalition.
|
||||||
|
self:AddTransition("*", "RunwayDestroyed", "*") -- Runway of the airbase was destroyed.
|
||||||
|
self:AddTransition("*", "RunwayRepaired", "*") -- Runway of the airbase was repaired.
|
||||||
self:AddTransition("*", "AssetDead", "*") -- An asset group died.
|
self:AddTransition("*", "AssetDead", "*") -- An asset group died.
|
||||||
self:AddTransition("*", "Destroyed", "Destroyed") -- Warehouse was destroyed. All assets in stock are gone and warehouse is stopped.
|
self:AddTransition("*", "Destroyed", "Destroyed") -- Warehouse was destroyed. All assets in stock are gone and warehouse is stopped.
|
||||||
self:AddTransition("Destroyed", "Respawn", "Running") -- Respawn warehouse after it was destroyed.
|
self:AddTransition("Destroyed", "Respawn", "Running") -- Respawn warehouse after it was destroyed.
|
||||||
@ -3245,6 +3250,44 @@ function WAREHOUSE:FindAssetInDB(group)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Check if runway is operational.
|
||||||
|
-- @param #WAREHOUSE self
|
||||||
|
-- @return #boolean If true, runway is operational.
|
||||||
|
function WAREHOUSE:IsRunwayOperational()
|
||||||
|
if self.airbase then
|
||||||
|
if self.runwaydestroyed then
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Set the time until the runway(s) of an airdrome are repaired after it has been destroyed.
|
||||||
|
-- Note that this is the time, the DCS engine uses not something we can control on a user level or we could get via scripting.
|
||||||
|
-- You need to input the value. On the DCS forum it was stated that this is currently one hour. Hence this is the default value.
|
||||||
|
-- @param #WAREHOUSE self
|
||||||
|
-- @param #number RepairTime Time in seconds until the runway is repaired. Default 3600 sec (one hour).
|
||||||
|
-- @return #WAREHOUSE self
|
||||||
|
function WAREHOUSE:SetRunwayRepairtime(RepairTime)
|
||||||
|
self.runwayrepairtime=RepairTime or 3600
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Check if runway is operational.
|
||||||
|
-- @param #WAREHOUSE self
|
||||||
|
-- @return #number Time in seconds until the runway is repaired. Will return 0 if runway is repaired.
|
||||||
|
function WAREHOUSE:GetRunwayRepairtime()
|
||||||
|
if self.runwaydestroyed then
|
||||||
|
local Tnow=timer.getAbsTime()
|
||||||
|
local Tsince=Tnow-self.runwaydestroyed
|
||||||
|
local Trepair=math.max(self.runwayrepairtime-Tsince, 0)
|
||||||
|
return Trepair
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- FSM states
|
-- FSM states
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@ -3426,6 +3469,14 @@ function WAREHOUSE:onafterStatus(From, Event, To)
|
|||||||
-- Check if warehouse is being attacked or has even been captured.
|
-- Check if warehouse is being attacked or has even been captured.
|
||||||
self:_CheckConquered()
|
self:_CheckConquered()
|
||||||
|
|
||||||
|
if self:IsRunwayOperational()==false then
|
||||||
|
local Trepair=self:GetRunwayRepairtime()
|
||||||
|
self:I(self.lid..string.format("Runway destroyed! Will be repaired in %d sec", Trepair))
|
||||||
|
if Trepair==0 then
|
||||||
|
self:RunwayRepaired()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Check if requests are valid and remove invalid one.
|
-- Check if requests are valid and remove invalid one.
|
||||||
self:_CheckRequestConsistancy(self.queue)
|
self:_CheckRequestConsistancy(self.queue)
|
||||||
|
|
||||||
@ -5132,6 +5183,38 @@ function WAREHOUSE:onafterAirbaseRecaptured(From, Event, To, Coalition)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- On after "RunwayDestroyed" event.
|
||||||
|
-- @param #WAREHOUSE self
|
||||||
|
-- @param #string From From state.
|
||||||
|
-- @param #string Event Event.
|
||||||
|
-- @param #string To To state.
|
||||||
|
-- @param DCS#coalition.side Coalition Coalition side which originally captured the warehouse.
|
||||||
|
function WAREHOUSE:onafterRunwayDestroyed(From, Event, To)
|
||||||
|
|
||||||
|
-- Message.
|
||||||
|
local text=string.format("Warehouse %s: Runway %s destroyed!", self.alias, self.airbasename)
|
||||||
|
self:_InfoMessage(text)
|
||||||
|
|
||||||
|
self.runwaydestroyed=timer.getAbsTime()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
--- On after "RunwayRepaired" event.
|
||||||
|
-- @param #WAREHOUSE self
|
||||||
|
-- @param #string From From state.
|
||||||
|
-- @param #string Event Event.
|
||||||
|
-- @param #string To To state.
|
||||||
|
function WAREHOUSE:onafterRunwayRepaired(From, Event, To)
|
||||||
|
|
||||||
|
-- Message.
|
||||||
|
local text=string.format("Warehouse %s: Runway %s repaired!", self.alias, self.airbasename)
|
||||||
|
self:_InfoMessage(text)
|
||||||
|
|
||||||
|
self.runwaydestroyed=nil
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- On before "AssetSpawned" event. Checks whether the asset was already set to "spawned" for groups with multiple units.
|
--- On before "AssetSpawned" event. Checks whether the asset was already set to "spawned" for groups with multiple units.
|
||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
@ -6335,6 +6418,9 @@ function WAREHOUSE:_OnEventCrashOrDead(EventData)
|
|||||||
-- Trigger Destroyed event.
|
-- Trigger Destroyed event.
|
||||||
self:Destroyed()
|
self:Destroyed()
|
||||||
end
|
end
|
||||||
|
if self.airbase and self.airbasename and self.airbasename==EventData.IniUnitName then
|
||||||
|
self:RunwayDestroyed()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--self:I(self.lid..string.format("Warehouse %s captured event dead or crash or unit %s.", self.alias, tostring(EventData.IniUnitName)))
|
--self:I(self.lid..string.format("Warehouse %s captured event dead or crash or unit %s.", self.alias, tostring(EventData.IniUnitName)))
|
||||||
@ -7080,13 +7166,21 @@ function WAREHOUSE:_CheckRequestNow(request)
|
|||||||
-- Check available parking for air asset units.
|
-- Check available parking for air asset units.
|
||||||
if self.airbase and (_assetcategory==Group.Category.AIRPLANE or _assetcategory==Group.Category.HELICOPTER) then
|
if self.airbase and (_assetcategory==Group.Category.AIRPLANE or _assetcategory==Group.Category.HELICOPTER) then
|
||||||
|
|
||||||
|
if self:IsRunwayOperational() then
|
||||||
|
|
||||||
local Parking=self:_FindParkingForAssets(self.airbase,_assets)
|
local Parking=self:_FindParkingForAssets(self.airbase,_assets)
|
||||||
|
|
||||||
--if Parking==nil and not (self.category==Airbase.Category.HELIPAD) then
|
--if Parking==nil and not (self.category==Airbase.Category.HELIPAD) then
|
||||||
if Parking==nil then
|
if Parking==nil then
|
||||||
local text=string.format("Warehouse %s: Request denied! Not enough free parking spots for all requested assets at the moment.", self.alias)
|
local text=string.format("Warehouse %s: Request denied! Not enough free parking spots for all requested assets at the moment.", self.alias)
|
||||||
self:_InfoMessage(text, 5)
|
self:_InfoMessage(text, 5)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
-- Runway destroyed.
|
||||||
|
local text=string.format("Warehouse %s: Request denied! Runway is still destroyed", self.alias)
|
||||||
|
self:_InfoMessage(text, 5)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -7132,7 +7226,9 @@ function WAREHOUSE:_CheckRequestNow(request)
|
|||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
-- Self propelled case. Nothing to do for now.
|
---
|
||||||
|
-- Self propelled case
|
||||||
|
---
|
||||||
|
|
||||||
-- Ground asset checks.
|
-- Ground asset checks.
|
||||||
if _assetcategory==Group.Category.GROUND then
|
if _assetcategory==Group.Category.GROUND then
|
||||||
|
|||||||
@ -2846,7 +2846,7 @@ function AUFTRAG:_TargetFromObject(Object)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Debug info.
|
-- Debug info.
|
||||||
self:T(self.lid..string.format("Mission Target %s Type=%s, Ntargets=%d, Lifepoints=%d", self.engageTarget.lid, self.engageTarget.lid, self.engageTarget.Ntargets0, self.engageTarget:GetLife()))
|
self:I(self.lid..string.format("Mission Target %s Type=%s, Ntargets=%d, Lifepoints=%d", self.engageTarget.lid, self.engageTarget.lid, self.engageTarget.Ntargets0, self.engageTarget:GetLife()))
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2782,6 +2782,10 @@ function OPSGROUP:RouteToMission(mission, delay)
|
|||||||
self:ScheduleOnce(delay, OPSGROUP.RouteToMission, self, mission)
|
self:ScheduleOnce(delay, OPSGROUP.RouteToMission, self, mission)
|
||||||
else
|
else
|
||||||
|
|
||||||
|
if self:IsDead() then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- ID of current waypoint.
|
-- ID of current waypoint.
|
||||||
local uid=self:GetWaypointCurrent().uid
|
local uid=self:GetWaypointCurrent().uid
|
||||||
|
|
||||||
|
|||||||
@ -550,10 +550,20 @@ function SQUADRON:AddTacanChannel(ChannelMin, ChannelMax)
|
|||||||
|
|
||||||
ChannelMax=ChannelMax or ChannelMin
|
ChannelMax=ChannelMax or ChannelMin
|
||||||
|
|
||||||
|
if ChannelMin>126 then
|
||||||
|
self:E(self.lid.."ERROR: TACAN Channel must be <= 126! Will not add to available channels")
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
if ChannelMax>126 then
|
||||||
|
self:E(self.lid.."WARNING: TACAN Channel must be <= 126! Adjusting ChannelMax to 126")
|
||||||
|
ChannelMax=126
|
||||||
|
end
|
||||||
|
|
||||||
for i=ChannelMin,ChannelMax do
|
for i=ChannelMin,ChannelMax do
|
||||||
self.tacanChannel[i]=true
|
self.tacanChannel[i]=true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get an unused TACAN channel.
|
--- Get an unused TACAN channel.
|
||||||
|
|||||||
@ -425,7 +425,7 @@ function TARGET:OnEventUnitDeadOrLost(EventData)
|
|||||||
if EventData and EventData.IniUnitName then
|
if EventData and EventData.IniUnitName then
|
||||||
|
|
||||||
-- Debug info.
|
-- Debug info.
|
||||||
self:I(self.lid..string.format("EVENT: Unit %s dead or lost!", EventData.IniUnitName))
|
self:T(self.lid..string.format("EVENT: Unit %s dead or lost!", tostring(EventData.IniUnitName)))
|
||||||
|
|
||||||
-- Get target.
|
-- Get target.
|
||||||
local target=self:GetTargetByName(EventData.IniUnitName)
|
local target=self:GetTargetByName(EventData.IniUnitName)
|
||||||
@ -438,7 +438,7 @@ function TARGET:OnEventUnitDeadOrLost(EventData)
|
|||||||
if target and target.Status==TARGET.ObjectStatus.ALIVE then
|
if target and target.Status==TARGET.ObjectStatus.ALIVE then
|
||||||
|
|
||||||
-- Debug message.
|
-- Debug message.
|
||||||
self:I(self.lid..string.format("EVENT: target unit %s dead or lost ==> destroyed", target.Name))
|
self:T(self.lid..string.format("EVENT: target unit %s dead or lost ==> destroyed", tostring(target.Name)))
|
||||||
|
|
||||||
-- Trigger object destroyed event.
|
-- Trigger object destroyed event.
|
||||||
self:ObjectDestroyed(target)
|
self:ObjectDestroyed(target)
|
||||||
@ -1008,7 +1008,7 @@ function TARGET:CountTargets()
|
|||||||
|
|
||||||
for _,_unit in pairs(units or {}) do
|
for _,_unit in pairs(units or {}) do
|
||||||
local unit=_unit --Wrapper.Unit#UNIT
|
local unit=_unit --Wrapper.Unit#UNIT
|
||||||
if unit and unit:IsAlive() and unit:GetLife()>1 then
|
if unit and unit:IsAlive()~=nil and unit:GetLife()>1 then
|
||||||
N=N+1
|
N=N+1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user