Merge branch 'FF/Develop' into FF/Fox2

This commit is contained in:
Frank
2020-05-04 11:25:34 +02:00
5 changed files with 98 additions and 58 deletions
@@ -1766,7 +1766,7 @@ _WAREHOUSEDB = {
--- Warehouse class version.
-- @field #string version
WAREHOUSE.version="1.0.0"
WAREHOUSE.version="1.0.1"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO: Warehouse todo list.
@@ -1873,6 +1873,12 @@ function WAREHOUSE:New(warehouse, alias)
-- Set unique ID for this warehouse.
self.uid=_WAREHOUSEDB.WarehouseID
-- Coalition of the warehouse.
self.coalition=self.warehouse:GetCoalition()
-- Country of the warehouse.
self.countryid=self.warehouse:GetCountry()
-- Closest of the same coalition but within 5 km range.
local _airbase=self:GetCoordinate():GetClosestAirbase(nil, self:GetCoalition())
if _airbase and _airbase:GetCoordinate():Get2DDistance(self:GetCoordinate()) <= 5000 then
@@ -3395,8 +3401,13 @@ end
-- @param #string To To state.
function WAREHOUSE:onafterStatus(From, Event, To)
local FSMstate=self:GetState()
local coalition=self:GetCoalitionName()
local country=self:GetCountryName()
-- Info.
self:I(self.lid..string.format("State=%s, Assets=%d, Requests: waiting=%d, pending=%d", self:GetState(), #self.stock, #self.queue, #self.pending))
self:I(self.lid..string.format("State=%s %s [%s]: Assets=%d, Requests: waiting=%d, pending=%d", FSMstate, country, coalition, #self.stock, #self.queue, #self.pending))
-- Check if any pending jobs are done and can be deleted from the queue.
self:_JobDone()
@@ -4947,6 +4958,21 @@ function WAREHOUSE:onafterDefeated(From, Event, To)
end
end
--- Respawn warehouse.
-- @param #WAREHOUSE self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function WAREHOUSE:onafterRespawn(From, Event, To)
-- Info message.
local text=string.format("Respawning warehouse %s", self.alias)
self:_InfoMessage(text)
-- Respawn warehouse.
self.warehouse:ReSpawn()
end
--- On before "ChangeCountry" event. Checks whether a change of country is necessary by comparing the actual country to the the requested one.
-- @param #WAREHOUSE self
@@ -4970,34 +4996,17 @@ function WAREHOUSE:onbeforeChangeCountry(From, Event, To, Country)
return false
end
--- Respawn warehouse.
-- @param #WAREHOUSE self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function WAREHOUSE:onafterRespawn(From, Event, To)
-- Info message.
local text=string.format("Respawning warehouse %s.", self.alias)
self:_InfoMessage(text)
-- Respawn warehouse.
self.warehouse:ReSpawn()
end
--- On after "ChangeCountry" event. Warehouse is respawned with the specified country. All queued requests are deleted and the owned airbase is reset if the coalition is changed by changing the
-- country.
-- @param #WAREHOUSE self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
-- @param DCS#country.id Country which has captured the warehouse.
-- @param DCS#country.id Country Country which has captured the warehouse.
function WAREHOUSE:onafterChangeCountry(From, Event, To, Country)
local CoalitionOld=self:GetCoalition()
-- Respawn warehouse with new coalition/country.
self.warehouse:ReSpawn(Country)
local CoalitionNew=self:GetCoalition()
@@ -5006,22 +5015,22 @@ function WAREHOUSE:onafterChangeCountry(From, Event, To, Country)
self.queue=nil
self.queue={}
-- Airbase could have been captured before and already belongs to the new coalition.
-- Check if Warehouse has a arbiase atthached
local airbasecoaltion
if self.airbase ~= nil then
local airbase=AIRBASE:FindByName(self.airbasename)
airbasecoaltion=airbase:GetCoalition()
else -- Warehouse has no airbase attached so just keep whatever, self.airbase will still be nil since CoalitionNew will not be nil if Warehouse have a airbse attacjed.
airbasecoaltion = nil
end
if self.airbasename then
-- Get airbase of this warehouse.
local airbase=AIRBASE:FindByName(self.airbasename)
-- Get coalition of the airbase.
local airbaseCoalition=airbase:GetCoalition()
if CoalitionNew==airbaseCoalition then
-- Airbase already owned by the coalition that captured the warehouse. Airbase can be used by this warehouse.
self.airbase=airbase
else
-- Airbase is owned by other coalition. So this warehouse does not have an airbase until it is captured.
self.airbase=nil
end
if CoalitionNew==airbasecoaltion then
-- Airbase already owned by the coalition that captured the warehouse. Airbase can be used by this warehouse.
self.airbase=airbase
else
-- Airbase is owned by other coalition. So this warehouse does not have an airbase unil it is captured.
self.airbase=nil
end
-- Debug smoke.
@@ -5035,6 +5044,20 @@ function WAREHOUSE:onafterChangeCountry(From, Event, To, Country)
end
--- On before "Captured" event. Warehouse has been captured by another coalition.
-- @param #WAREHOUSE self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
-- @param DCS#coalition.side Coalition which captured the warehouse.
-- @param DCS#country.id Country which has captured the warehouse.
function WAREHOUSE:onbeforeCaptured(From, Event, To, Coalition, Country)
-- Warehouse respawned.
self:ChangeCountry(Country)
end
--- On after "Captured" event. Warehouse has been captured by another coalition.
-- @param #WAREHOUSE self
-- @param #string From From state.
@@ -5048,8 +5071,6 @@ function WAREHOUSE:onafterCaptured(From, Event, To, Coalition, Country)
local text=string.format("Warehouse %s: We were captured by enemy coalition (side=%d)!", self.alias, Coalition)
self:_InfoMessage(text)
-- Warehouse respawned.
self:ChangeCountry(Country)
end
@@ -5646,7 +5667,7 @@ function WAREHOUSE:_SpawnAssetAircraft(alias, asset, request, parking, uncontrol
-- Check enough parking spots.
if AirbaseCategory==Airbase.Category.HELIPAD then
elseif AirbaseCategory==Airbase.Category.SHIP then
--TODO Figure out what's necessary in this case.
@@ -6107,14 +6128,14 @@ function WAREHOUSE:_OnEventBirth(EventData)
-- Birth is triggered for each unit. We need to make sure not to call this too often!
if not asset.spawned then
-- Remove asset from stock.
self:_DeleteStockItem(asset)
-- Set spawned switch.
asset.spawned=true
asset.spawngroupname=group:GetName()
-- Add group.
if asset.iscargo==true then
request.cargogroupset=request.cargogroupset or SET_GROUP:New()
@@ -6123,15 +6144,15 @@ function WAREHOUSE:_OnEventBirth(EventData)
request.transportgroupset=request.transportgroupset or SET_GROUP:New()
request.transportgroupset:AddGroup(group)
end
-- Set warehouse state.
group:SetState(group, "WAREHOUSE", self)
-- Asset spawned FSM function. We delay this a bit to have all units of the group in the game.
self:__AssetSpawned(1, group, asset, request)
end
else
-- No request?!
self:E(self.lid..string.format("ERROR: Could not get request when asset spawned! FF investigate! Unit name=%s asset spawed=%s", EventData.IniUnitName, tostring(asset.spawned)))
@@ -7518,7 +7539,7 @@ function WAREHOUSE:_FindParkingForAssets(airbase, assets)
end
return coords
end
if airbase:GetAirbaseCategory()==Airbase.Category.SHIP then
-- Scan a radius of 100 meters around the spot.
local _,_,_,units=airbase:GetCoordinate():ScanObjects(200, true, false, false)