diff --git a/Moose Development/Moose/Core/SpawnStatic.lua b/Moose Development/Moose/Core/SpawnStatic.lua index 66c3581d0..8f96a1c60 100644 --- a/Moose Development/Moose/Core/SpawnStatic.lua +++ b/Moose Development/Moose/Core/SpawnStatic.lua @@ -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 diff --git a/Moose Development/Moose/Functional/Warehouse.lua b/Moose Development/Moose/Functional/Warehouse.lua index 4e3d70898..ce48be657 100644 --- a/Moose Development/Moose/Functional/Warehouse.lua +++ b/Moose Development/Moose/Functional/Warehouse.lua @@ -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) diff --git a/Moose Development/Moose/Ops/Airboss.lua b/Moose Development/Moose/Ops/Airboss.lua index 552c559d1..5a35a8b60 100644 --- a/Moose Development/Moose/Ops/Airboss.lua +++ b/Moose Development/Moose/Ops/Airboss.lua @@ -1273,11 +1273,17 @@ AIRBOSS.AircraftCarrier={ --- Carrier types. -- @type AIRBOSS.CarrierType +-- @field #string ROOSEVELT USS Theodore Roosevelt (CVN-71) +-- @field #string LINCOLN USS Abraham Lincoln (CVN-72) +-- @field #string WASHINGTON USS George Washington (CVN-73) -- @field #string STENNIS USS John C. Stennis (CVN-74) -- @field #string VINSON USS Carl Vinson (CVN-70) -- @field #string TARAWA USS Tarawa (LHA-1) -- @field #string KUZNETSOV Admiral Kuznetsov (CV 1143.5) AIRBOSS.CarrierType={ + ROOSEVELT="CVN_71", + LINCOLN="CVN_72", + WASHINGTON="CVN_73", STENNIS="Stennis", VINSON="VINSON", TARAWA="LHA_Tarawa", @@ -1929,6 +1935,12 @@ function AIRBOSS:New(carriername, alias) -- Init carrier parameters. if self.carriertype==AIRBOSS.CarrierType.STENNIS then self:_InitStennis() + elseif self.carriertype==AIRBOSS.CarrierType.ROOSEVELT then + self:_InitStennis() + elseif self.carriertype==AIRBOSS.CarrierType.LINCOLN then + self:_InitStennis() + elseif self.carriertype==AIRBOSS.CarrierType.WASHINGTON then + self:_InitStennis() elseif self.carriertype==AIRBOSS.CarrierType.VINSON then -- TODO: Carl Vinson parameters. self:_InitStennis() diff --git a/Moose Development/Moose/Utilities/Enums.lua b/Moose Development/Moose/Utilities/Enums.lua index e59b958f5..da73fd4b6 100644 --- a/Moose Development/Moose/Utilities/Enums.lua +++ b/Moose Development/Moose/Utilities/Enums.lua @@ -238,7 +238,6 @@ ENUMS.FormationOld.FixedWing.SpreadFour=7 ENUMS.FormationOld.FixedWing.BomberElement=12 ENUMS.FormationOld.FixedWing.BomberElementHeight=13 ENUMS.FormationOld.FixedWing.FighterVic=14 -ENUMS.FormationOld={} ENUMS.FormationOld.RotaryWing={} ENUMS.FormationOld.RotaryWing.Wedge=8 ENUMS.FormationOld.RotaryWing.Echelon=9 diff --git a/Moose Development/Moose/Wrapper/Static.lua b/Moose Development/Moose/Wrapper/Static.lua index 16b07c03f..9df2fd594 100644 --- a/Moose Development/Moose/Wrapper/Static.lua +++ b/Moose Development/Moose/Wrapper/Static.lua @@ -224,7 +224,7 @@ function STATIC:ReSpawn(countryid, Delay) else local SpawnStatic = SPAWNSTATIC:NewFromStatic( self.StaticName, countryid ) - + SpawnStatic:ReSpawn() end