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,8 +240,13 @@ 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)
|
||||||
|
|
||||||
|
if delay and delay>0 then
|
||||||
|
self:ScheduleOnce(delay, SPAWNSTATIC.ReSpawn, self)
|
||||||
|
else
|
||||||
|
|
||||||
local StaticTemplate, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate( self.SpawnTemplatePrefix )
|
local StaticTemplate, CoalitionID, CategoryID, CountryID = _DATABASE:GetStaticGroupTemplate( self.SpawnTemplatePrefix )
|
||||||
|
|
||||||
@ -257,6 +262,9 @@ function SPAWNSTATIC:ReSpawn()
|
|||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
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.
|
||||||
@ -1871,6 +1871,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())
|
||||||
if _airbase and _airbase:GetCoordinate():Get2DDistance(self:GetCoordinate()) <= 5000 then
|
if _airbase and _airbase:GetCoordinate():Get2DDistance(self:GetCoordinate()) <= 5000 then
|
||||||
@ -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,12 +4960,17 @@ 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,26 +5025,24 @@ function WAREHOUSE:onafterChangeCountry(From, Event, To, Country)
|
|||||||
self.queue=nil
|
self.queue=nil
|
||||||
self.queue={}
|
self.queue={}
|
||||||
|
|
||||||
|
if self.airbasename then
|
||||||
|
|
||||||
-- Get airbase of this warehouse.
|
-- Get airbase of this warehouse.
|
||||||
local airbase=AIRBASE:FindByName(self.airbasename)
|
local airbase=AIRBASE:FindByName(self.airbasename)
|
||||||
|
|
||||||
-- Airbase could have been captured before and already belongs to the new coalition.
|
-- Get coalition of the airbase.
|
||||||
-- Check if Warehouse has a arbiase atthached
|
local airbaseCoalition=airbase:GetCoalition()
|
||||||
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
|
if CoalitionNew==airbaseCoalition then
|
||||||
-- Airbase already owned by the coalition that captured the warehouse. Airbase can be used by this warehouse.
|
-- Airbase already owned by the coalition that captured the warehouse. Airbase can be used by this warehouse.
|
||||||
self.airbase=airbase
|
self.airbase=airbase
|
||||||
else
|
else
|
||||||
-- Airbase is owned by other coalition. So this warehouse does not have an airbase unil it is captured.
|
-- Airbase is owned by other coalition. So this warehouse does not have an airbase until it is captured.
|
||||||
self.airbase=nil
|
self.airbase=nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
-- Debug smoke.
|
-- Debug smoke.
|
||||||
if self.Debug then
|
if self.Debug then
|
||||||
if CoalitionNew==coalition.side.RED then
|
if CoalitionNew==coalition.side.RED then
|
||||||
@ -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.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user