From 205f69b3ab17946691e4a1bbefbfd0647741524d Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 5 Oct 2018 01:47:10 +0200 Subject: [PATCH] Warehouse v0.5.7 - Added check if spawn zones are on land - Removed check that ground units cannot go to ships - Added check that spawn zone is 5 km from warehouse (needs to be revised). Coordinate: - added surface type checks api functions --- Moose Development/Moose/Core/Point.lua | 46 ++++++++++++++++++- .../Moose/Functional/Warehouse.lua | 31 ++++++++++--- 2 files changed, 70 insertions(+), 7 deletions(-) diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index 984f6eb5d..ae6475723 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -1383,9 +1383,53 @@ do -- COORDINATE return surface end + --- Checks if the surface type is on land. + -- @param #COORDINATE self + -- @return #boolean If true, the surface type at the coordinate is land. + function COORDINATE:IsSurfaceTypeLand() + return self:GetSurfaceType()==land.SurfaceType.LAND + end + + --- Checks if the surface type is road. + -- @param #COORDINATE self + -- @return #boolean If true, the surface type at the coordinate is land. + function COORDINATE:IsSurfaceTypeLand() + return self:GetSurfaceType()==land.SurfaceType.LAND + end + + + --- Checks if the surface type is road. + -- @param #COORDINATE self + -- @return #boolean If true, the surface type at the coordinate is a road. + function COORDINATE:IsSurfaceTypeRoad() + return self:GetSurfaceType()==land.SurfaceType.ROAD + end + + --- Checks if the surface type is runway. + -- @param #COORDINATE self + -- @return #boolean If true, the surface type at the coordinate is a runway or taxi way. + function COORDINATE:IsSurfaceTypeRunway() + return self:GetSurfaceType()==land.SurfaceType.RUNWAY + end + + --- Checks if the surface type is shallow water. + -- @param #COORDINATE self + -- @return #boolean If true, the surface type at the coordinate is a shallow water. + function COORDINATE:IsSurfaceTypeShallowWater() + return self:GetSurfaceType()==land.SurfaceType.SHALLOW_WATER + end + + --- Checks if the surface type is water. + -- @param #COORDINATE self + -- @return #boolean If true, the surface type at the coordinate is a deep water. + function COORDINATE:IsSurfaceTypeWater() + return self:GetSurfaceType()==land.SurfaceType.WATER + end + + --- Creates an explosion at the point of a certain intensity. -- @param #COORDINATE self - -- @param #number ExplosionIntensity + -- @param #number ExplosionIntensity Intensity of the explosion in kg TNT. function COORDINATE:Explosion( ExplosionIntensity ) self:F2( { ExplosionIntensity } ) trigger.action.explosion( self:GetVec3(), ExplosionIntensity ) diff --git a/Moose Development/Moose/Functional/Warehouse.lua b/Moose Development/Moose/Functional/Warehouse.lua index 2987fe337..c07b5bad3 100644 --- a/Moose Development/Moose/Functional/Warehouse.lua +++ b/Moose Development/Moose/Functional/Warehouse.lua @@ -1536,7 +1536,7 @@ WAREHOUSE.db = { --- Warehouse class version. -- @field #string version -WAREHOUSE.version="0.5.6w" +WAREHOUSE.version="0.5.7" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO: Warehouse todo list. @@ -2651,6 +2651,8 @@ function WAREHOUSE:onafterStart(From, Event, To) self.spawnzone:BoundZone(30, self.country) ]] + --self.spawnzone:GetCoordinate():MarkToCoalition(string.format("Warehouse %s spawn zone", self.alias), self:GetCoalition()) + -- Get the closest point on road wrt spawnzone of ground assets. local _road=self.spawnzone:GetCoordinate():GetClosestPointToRoad() if _road and self.road==nil then @@ -2697,7 +2699,6 @@ function WAREHOUSE:onafterStart(From, Event, To) -- Start the status monitoring. self:__Status(-1) - end --- On after "Stop" event. Stops the warehouse, unhandles all events. @@ -5592,13 +5593,21 @@ function WAREHOUSE:_CheckRequestValid(request) end elseif asset_ground then + + -- Check that both spawn zones are not in water. + local inwater=self.spawnzone:GetCoordinate():IsSurfaceTypeWater() or request.warehouse.spawnzone:GetCoordinate():IsSurfaceTypeWater() + + if inwater then + self:E("ERROR: Incorrect request. Ground asset requested but at least one spawn zone is in water!") + valid=false + end -- No ground assets directly to or from ships. -- TODO: May needs refinement if warehouse is on land and requestor is ship in harbour?! - if (requestcategory==Airbase.Category.SHIP or self:GetAirbaseCategory()==Airbase.Category.SHIP) then - self:E("ERROR: Incorrect request. Ground asset requested but warehouse or requestor is SHIP!") - valid=false - end + --if (requestcategory==Airbase.Category.SHIP or self:GetAirbaseCategory()==Airbase.Category.SHIP) then + -- self:E("ERROR: Incorrect request. Ground asset requested but warehouse or requestor is SHIP!") + -- valid=false + --end if asset_train then @@ -5860,6 +5869,16 @@ function WAREHOUSE:_CheckRequestNow(request) else -- Self propelled case. Nothing to do for now. + + --local dist=self.spawnzone:GetCoordinate():Get2DDistance(self:GetCoordinate()) + local dist=self.warehouse:GetCoordinate():Get2DDistance(request.warehouse.spawnzone:GetCoordinate()) + + if dist>5000 then + -- Not enough or the right transport carriers. + local text=string.format("Warehouse %s: Request denied! Not close enough to spawn zone. Distance = %d m", self.alias, dist) + self:_InfoMessage(text, 5) + return false + end end