mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
WAREHOUSE v1.0.1
This commit is contained in:
parent
77de1dda2b
commit
bee44b97fd
@ -240,23 +240,31 @@ end
|
|||||||
|
|
||||||
--- Respawns the original @{Static}.
|
--- Respawns the original @{Static}.
|
||||||
-- @param #SPAWNSTATIC self
|
-- @param #SPAWNSTATIC self
|
||||||
|
-- @param #number delay Delay before respawn in seconds.
|
||||||
-- @return #SPAWNSTATIC
|
-- @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 StaticTemplate, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate( self.SpawnTemplatePrefix )
|
||||||
|
|
||||||
local StaticUnitTemplate = StaticTemplate.units[1]
|
|
||||||
StaticTemplate.route = nil
|
|
||||||
StaticTemplate.groupId = nil
|
|
||||||
|
|
||||||
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
|
end
|
||||||
|
|
||||||
return nil
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1764,7 +1764,7 @@ _WAREHOUSEDB = {
|
|||||||
|
|
||||||
--- Warehouse class version.
|
--- Warehouse class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
WAREHOUSE.version="1.0.0"
|
WAREHOUSE.version="1.0.1"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- TODO: Warehouse todo list.
|
-- TODO: Warehouse todo list.
|
||||||
@ -1870,6 +1870,12 @@ function WAREHOUSE:New(warehouse, alias)
|
|||||||
|
|
||||||
-- Set unique ID for this warehouse.
|
-- Set unique ID for this warehouse.
|
||||||
self.uid=_WAREHOUSEDB.WarehouseID
|
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.
|
-- Closest of the same coalition but within 5 km range.
|
||||||
local _airbase=self:GetCoordinate():GetClosestAirbase(nil, self:GetCoalition())
|
local _airbase=self:GetCoordinate():GetClosestAirbase(nil, self:GetCoalition())
|
||||||
@ -3395,8 +3401,13 @@ end
|
|||||||
-- @param #string To To state.
|
-- @param #string To To state.
|
||||||
function WAREHOUSE:onafterStatus(From, Event, To)
|
function WAREHOUSE:onafterStatus(From, Event, To)
|
||||||
|
|
||||||
|
local FSMstate=self:GetState()
|
||||||
|
|
||||||
|
local coalition=self:GetCoalitionName()
|
||||||
|
local country=self:GetCountryName()
|
||||||
|
|
||||||
-- Info.
|
-- 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.
|
-- Check if any pending jobs are done and can be deleted from the queue.
|
||||||
self:_JobDone()
|
self:_JobDone()
|
||||||
@ -4949,11 +4960,16 @@ end
|
|||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
-- @param #string Event Event.
|
-- @param #string Event Event.
|
||||||
-- @param #string To To state.
|
-- @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.
|
-- Info message.
|
||||||
local text=string.format("Respawning warehouse %s.", self.alias)
|
local text=string.format("Respawning warehouse %s", self.alias)
|
||||||
self:_InfoMessage(text)
|
self:_InfoMessage(text)
|
||||||
|
|
||||||
|
if self.warehouse and self.warehouse:IsAlive() then
|
||||||
|
self.warehouse:Destroy()
|
||||||
|
end
|
||||||
|
|
||||||
-- Respawn warehouse.
|
-- Respawn warehouse.
|
||||||
self.warehouse:ReSpawn()
|
self.warehouse:ReSpawn()
|
||||||
@ -4982,19 +4998,26 @@ function WAREHOUSE:onbeforeChangeCountry(From, Event, To, Country)
|
|||||||
return false
|
return false
|
||||||
end
|
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
|
--- 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.
|
-- country.
|
||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
-- @param #string Event Event.
|
-- @param #string Event Event.
|
||||||
-- @param #string To To state.
|
-- @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)
|
function WAREHOUSE:onafterChangeCountry(From, Event, To, Country)
|
||||||
|
|
||||||
local CoalitionOld=self:GetCoalition()
|
local CoalitionOld=self:GetCoalition()
|
||||||
|
|
||||||
-- Respawn warehouse with new coalition/country.
|
self.warehouse:ReSpawn(Country)
|
||||||
self:Respawn(Country)
|
|
||||||
|
|
||||||
local CoalitionNew=self:GetCoalition()
|
local CoalitionNew=self:GetCoalition()
|
||||||
|
|
||||||
@ -5002,24 +5025,22 @@ function WAREHOUSE:onafterChangeCountry(From, Event, To, Country)
|
|||||||
self.queue=nil
|
self.queue=nil
|
||||||
self.queue={}
|
self.queue={}
|
||||||
|
|
||||||
-- Get airbase of this warehouse.
|
if self.airbasename then
|
||||||
local airbase=AIRBASE:FindByName(self.airbasename)
|
|
||||||
|
-- Get airbase of this warehouse.
|
||||||
-- Airbase could have been captured before and already belongs to the new coalition.
|
local airbase=AIRBASE:FindByName(self.airbasename)
|
||||||
-- Check if Warehouse has a arbiase atthached
|
|
||||||
local airbasecoaltion
|
-- Get coalition of the airbase.
|
||||||
if self.airbase~=nil then
|
local airbaseCoalition=airbase:GetCoalition()
|
||||||
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.
|
if CoalitionNew==airbaseCoalition then
|
||||||
airbasecoaltion = nil
|
-- Airbase already owned by the coalition that captured the warehouse. Airbase can be used by this warehouse.
|
||||||
end
|
self.airbase=airbase
|
||||||
|
else
|
||||||
if CoalitionNew==airbasecoaltion then
|
-- Airbase is owned by other coalition. So this warehouse does not have an airbase until it is captured.
|
||||||
-- Airbase already owned by the coalition that captured the warehouse. Airbase can be used by this warehouse.
|
self.airbase=nil
|
||||||
self.airbase=airbase
|
end
|
||||||
else
|
|
||||||
-- Airbase is owned by other coalition. So this warehouse does not have an airbase unil it is captured.
|
|
||||||
self.airbase=nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Debug smoke.
|
-- Debug smoke.
|
||||||
@ -8487,7 +8508,7 @@ function WAREHOUSE:_DebugMessage(text, duration)
|
|||||||
if duration>0 then
|
if duration>0 then
|
||||||
MESSAGE:New(text, duration):ToAllIf(self.Debug)
|
MESSAGE:New(text, duration):ToAllIf(self.Debug)
|
||||||
end
|
end
|
||||||
self:I(self.lid..text)
|
self:T(self.lid..text)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Error message. Message send to all (if duration > 0). Text self:E(text) added to DCS.log file.
|
--- Error message. Message send to all (if duration > 0). Text self:E(text) added to DCS.log file.
|
||||||
|
|||||||
@ -224,7 +224,7 @@ function STATIC:ReSpawn(countryid, Delay)
|
|||||||
else
|
else
|
||||||
|
|
||||||
local SpawnStatic = SPAWNSTATIC:NewFromStatic( self.StaticName, countryid )
|
local SpawnStatic = SPAWNSTATIC:NewFromStatic( self.StaticName, countryid )
|
||||||
|
|
||||||
SpawnStatic:ReSpawn()
|
SpawnStatic:ReSpawn()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user