WAREHOUSE v1.0.1

This commit is contained in:
Frank 2020-05-03 23:56:32 +02:00
parent 77de1dda2b
commit bee44b97fd
3 changed files with 66 additions and 37 deletions

View File

@ -240,23 +240,31 @@ end
--- Respawns the original @{Static}.
-- @param #SPAWNSTATIC self
-- @param #number delay Delay before respawn in seconds.
-- @return #SPAWNSTATIC
function SPAWNSTATIC:ReSpawn()
function SPAWNSTATIC:ReSpawn(delay)
local StaticTemplate, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate( self.SpawnTemplatePrefix )
if delay and delay>0 then
self:ScheduleOnce(delay, SPAWNSTATIC.ReSpawn, self)
else
if StaticTemplate then
local StaticUnitTemplate = StaticTemplate.units[1]
StaticTemplate.route = nil
StaticTemplate.groupId = nil
local StaticTemplate, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate( self.SpawnTemplatePrefix )
local Static = coalition.addStaticObject( self.CountryID or CountryID, StaticTemplate.units[1] )
if StaticTemplate then
local StaticUnitTemplate = StaticTemplate.units[1]
StaticTemplate.route = nil
StaticTemplate.groupId = nil
local Static = coalition.addStaticObject( self.CountryID or CountryID, StaticTemplate.units[1] )
return _DATABASE:FindStatic(Static:getName())
end
return _DATABASE:FindStatic(Static:getName())
return nil
end
return nil
return self
end

View File

@ -1764,7 +1764,7 @@ _WAREHOUSEDB = {
--- Warehouse class version.
-- @field #string version
WAREHOUSE.version="1.0.0"
WAREHOUSE.version="1.0.1"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO: Warehouse todo list.
@ -1870,6 +1870,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())
@ -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()
@ -4949,11 +4960,16 @@ end
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function WAREHOUSE:onafterRespawn(From, Event, To)
-- @param #number CountryID The country ID (determines also the coaliton) of the respawned warehouse.
function WAREHOUSE:onafterRespawn(From, Event, To, CountryID)
-- Info message.
local text=string.format("Respawning warehouse %s.", self.alias)
local text=string.format("Respawning warehouse %s", self.alias)
self:_InfoMessage(text)
if self.warehouse and self.warehouse:IsAlive() then
self.warehouse:Destroy()
end
-- Respawn warehouse.
self.warehouse:ReSpawn()
@ -4982,19 +4998,26 @@ function WAREHOUSE:onbeforeChangeCountry(From, Event, To, Country)
return false
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 DCS#country.id Country Country which has captured the warehouse.
function WAREHOUSE:_ChangeCountry(From, Event, To, Country)
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:Respawn(Country)
self.warehouse:ReSpawn(Country)
local CoalitionNew=self:GetCoalition()
@ -5002,24 +5025,22 @@ function WAREHOUSE:onafterChangeCountry(From, Event, To, Country)
self.queue=nil
self.queue={}
-- Get airbase of this warehouse.
local airbase=AIRBASE:FindByName(self.airbasename)
-- 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
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 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
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
end
-- Debug smoke.
@ -8487,7 +8508,7 @@ function WAREHOUSE:_DebugMessage(text, duration)
if duration>0 then
MESSAGE:New(text, duration):ToAllIf(self.Debug)
end
self:I(self.lid..text)
self:T(self.lid..text)
end
--- Error message. Message send to all (if duration > 0). Text self:E(text) added to DCS.log file.

View File

@ -224,7 +224,7 @@ function STATIC:ReSpawn(countryid, Delay)
else
local SpawnStatic = SPAWNSTATIC:NewFromStatic( self.StaticName, countryid )
SpawnStatic:ReSpawn()
end