Warehouse v0.4.4

- Fixed little bug in warehouse.
- Added home event function to cargo airplane. Planes are now going home after job is done.
- Added false option for :Destroy() to generate no event.
- Added false parameter to respawn function.
This commit is contained in:
funkyfranky 2018-09-12 23:04:39 +02:00
parent a6ea157b4f
commit 54ae3ed62b
3 changed files with 40 additions and 12 deletions

View File

@ -251,7 +251,6 @@ function AI_CARGO_AIRPLANE:onafterLanded( Airplane, From, Event, To )
-- Aircraft was sent to this airbase to pickup troops. Initiate loadling.
if self.RoutePickup == true then
env.info("FF load airplane "..Airplane:GetName())
self:Load( self.PickupZone )
self.RoutePickup = false
self.Relocating = true
@ -281,15 +280,15 @@ end
-- @param Core.Zone#ZONE_AIRBASE PickupZone
function AI_CARGO_AIRPLANE:onafterPickup( Airplane, From, Event, To, Coordinate, Speed, PickupZone )
if Airplane and Airplane:IsAlive()~=nil then
env.info("FF onafterpick aircraft alive")
if Airplane and Airplane:IsAlive() then
--env.info("FF onafterpick aircraft alive")
self.PickupZone = PickupZone
-- Get closest airbase of current position.
local ClosestAirbase, DistToAirbase=Airplane:GetCoordinate():GetClosestAirbase()
env.info("FF onafterpickup closest airbase "..ClosestAirbase:GetName())
--env.info("FF onafterpickup closest airbase "..ClosestAirbase:GetName())
-- Two cases. Aircraft spawned in air or at an airbase.
if Airplane:InAir() then
@ -298,15 +297,16 @@ function AI_CARGO_AIRPLANE:onafterPickup( Airplane, From, Event, To, Coordinate,
self.Airbase=ClosestAirbase
end
-- Set pickup airbase.
local Airbase = PickupZone:GetAirbase()
-- Distance from closest to pickup airbase ==> we need to know if we are already at the pickup airbase.
local Dist = Airbase:GetCoordinate():Get2DDistance(ClosestAirbase:GetCoordinate())
env.info("Distance closest to pickup airbase = "..Dist)
--env.info("Distance closest to pickup airbase = "..Dist)
if Airplane:InAir() or Dist>500 then
env.info("FF onafterpickup routing to airbase "..ClosestAirbase:GetName())
--env.info("FF onafterpickup routing to airbase "..ClosestAirbase:GetName())
-- Route aircraft to pickup airbase.
self:Route( Airplane, Airbase, Speed )
@ -318,7 +318,7 @@ function AI_CARGO_AIRPLANE:onafterPickup( Airplane, From, Event, To, Coordinate,
self.RoutePickup = true
else
env.info("FF onafterpick calling landed")
--env.info("FF onafterpick calling landed")
-- We are already at the right airbase ==> Landed ==> triggers loading of troops. Is usually called at engine shutdown event.
self.RoutePickup=true
@ -329,7 +329,7 @@ function AI_CARGO_AIRPLANE:onafterPickup( Airplane, From, Event, To, Coordinate,
self.Transporting = false
self.Relocating = true
else
env.info("FF onafterpick aircraft not alive")
--env.info("FF onafterpick aircraft not alive")
end
@ -447,7 +447,7 @@ end
-- @param #boolean Uncontrolled If true, spawn group in uncontrolled state.
function AI_CARGO_AIRPLANE:Route( Airplane, Airbase, Speed, Uncontrolled )
if Airplane and Airplane:IsAlive()~=nil then
if Airplane and Airplane:IsAlive() then
-- Set takeoff type.
local Takeoff = SPAWN.Takeoff.Cold
@ -510,3 +510,29 @@ function AI_CARGO_AIRPLANE:Route( Airplane, Airbase, Speed, Uncontrolled )
end
end
end
--- On after Home event. Aircraft will be routed to their home base.
-- @param #AI_CARGO_AIRPLANE self
-- @param Wrapper.Group#GROUP Airplane The cargo plane.
-- @param From From state.
-- @param Event Event.
-- @param To To State.
-- @param Core.Point#COORDINATE Coordinate Home place (not used).
-- @param #number Speed Speed in km/h to fly to the home airbase (zone). Default is 80% of max possible speed the unit can go.
-- @param Core.Zone#ZONE_AIRBASE HomeZone The home airbase (zone) where the plane should return to.
function AI_CARGO_AIRPLANE:onafterHome(Airplane, From, Event, To, Coordinate, Speed, HomeZone )
if Airplane and Airplane:IsAlive() then
-- We are going home!
self.RouteHome = true
-- Home Base.
local HomeBase=HomeZone:GetAirbase()
self.Airbase=HomeBase
-- Now route the airplane home
self:Route(Airplane, HomeBase, Speed)
end
end

View File

@ -991,7 +991,7 @@ WAREHOUSE.db = {
--- Warehouse class version.
-- @field #string version
WAREHOUSE.version="0.4.3"
WAREHOUSE.version="0.4.4"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO: Warehouse todo list.
@ -4862,7 +4862,7 @@ function WAREHOUSE:_CheckRequestValid(request)
-- Convert relative to absolute number if necessary.
local nasset=request.ntransport
if type(request.nasset)=="string" then
if type(request.ntransport)=="string" then
nasset=self:_QuantityRel2Abs(request.ntransport,_nassets)
end

View File

@ -288,6 +288,8 @@ function GROUP:Destroy( GenerateEvent )
else
self:CreateEventDead( timer.getTime(), UnitData )
end
elseif GenerateEvent==false then
-- Do nothing!
else
self:CreateEventRemoveUnit( timer.getTime(), UnitData )
end
@ -1524,7 +1526,7 @@ function GROUP:RespawnAtCurrentAirbase(SpawnTemplate, Takeoff, Uncontrolled) --
SpawnTemplate.uncontrolled=Uncontrolled
-- Destroy old group.
self:Destroy()
self:Destroy(false)
--SCHEDULER:New(nil, DATABASE.Spawn, {_DATABASE, SpawnTemplate}, 0.00001)