diff --git a/Moose Development/Moose/Functional/Fox2.lua b/Moose Development/Moose/Functional/Fox2.lua index 1d4b93fdc..260fb53a6 100644 --- a/Moose Development/Moose/Functional/Fox2.lua +++ b/Moose Development/Moose/Functional/Fox2.lua @@ -31,7 +31,8 @@ -- @field #table safezones Table of practice zones. -- @field #table launchzones Table of launch zones. -- @field Core.Set#SET_GROUP protectedset Set of protected groups. --- @field #number explosionpower Power of explostion when destroying the missile in kg TNT. +-- @field #number explosionpower Power of explostion when destroying the missile in kg TNT. Default 5 kg TNT. +-- @field #number explosiondist Missile player distance in meters for destroying the missile. Default 100 m. -- @extends Core.Fsm#FSM --- Fox 2! @@ -56,6 +57,7 @@ FOX2 = { launchzones = {}, protectedset = nil, explosionpower = 5, + explosiondist = 100, destroy = nil, } @@ -100,7 +102,7 @@ FOX2.MenuF10Root=nil --- FOX2 class version. -- @field #string version -FOX2.version="0.1.1" +FOX2.version="0.1.3" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- ToDo list @@ -203,6 +205,29 @@ function FOX2:onafterStop(From, Event, To) end +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +-- User Functions +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +--- Add a training zone. Players in the zone are safe. +-- @param #FOX2 self +-- @param Core.Zone#ZONE zone Training zone. +function FOX2:AddSafeZone(zone) + + table.insert(self.safezones, zone) + +end + +--- Add a launch zone. Only missiles launched within these zones will be tracked. +-- @param #FOX2 self +-- @param Core.Zone#ZONE zone Training zone. +function FOX2:AddLaunchZone(zone) + + table.insert(self.safezones, zone) + +end + + --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- Status Functions --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -214,11 +239,40 @@ end -- @param #string To To state. function FOX2:onafterStatus(From, Event, To) - self:I(self.lid..string.format("Missile trainer status.")) + self:I(self.lid..string.format("Missile trainer status: %s", self.GetState())) + + self:_CheckMissileStatus() self:__Status(-30) end +--- Missile status +-- @param #FOX2 self +function FOX2:_CheckMissileStatus() + + local text="Missiles:" + for i,_missile in pairs(self.missiles) do + local missile=_missile --#FOX2.MissileData + + local targetname="unkown" + if missile.targetUnit then + targetname=missile.targetUnit:GetName() + end + local playername="none" + if missile.targetPlayer then + playername=missile.targetPlayer.name + end + local active=tostring(missile.active) + local mtype=missile.missileType + local range=UTILS.MetersToNM(missile.missileRange) + + text=text..string.format("\n%d: active=%s, type=%d, range=%.1f NM, target=%s, player=%s, missilename=%s", i, active, mtype, range, targetname, playername) + + end + self:T(self.lid..text) + +end + ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- Event Functions ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -337,6 +391,13 @@ function FOX2:OnEventShot(EventData) self:E(FOX2.lid..string.format("EVENT SHOT: Missil categ = %s", tostring(missilecategory))) self:E(FOX2.lid..string.format("EVENT SHOT: Missil range = %s", tostring(missilerange))) + + -- Check if fired in launch zone. + if not self:_CheckCoordLaunch(EventData.IniUnit:GetCoordinate()) then + self:T(self.lid.."Missile was not fired in launch zone. No tracking!") + return + end + -- Get the target unit. Note if if _target is not nil, the unit can sometimes not be found! if _target then self:E({target=_target}) @@ -513,15 +574,15 @@ function FOX2:OnEventShot(EventData) self:T2(self.lid..string.format("Distance = %.1f m, v=%.1f m/s, bearing=%03d°, eta=%.1f sec", distance, missileVelocity, bearing, eta)) - -- If missile is 100 m from target ==> destroy missile. - if distance<100 then + -- If missile is 100 m from target ==> destroy missile if in safe zone. + if distance Everything is safe. + if #self.safezones==0 then + return true + end + + -- Loop over all zones. + for _,_zone in pairs(self.safezones) do + local zone=_zone --Core.Zone#ZONE + local inzone=zone:IsCoordinateInZone(coord) + if inzone then + return true + end + end + + return false +end + +--- Check if a coordinate lies within a launch zone. +-- @param #FOX2 self +-- @param Core.Point#COORDINATE coord Coordinate to check. +-- @return #boolean +function FOX2:_CheckCoordLaunch(coord) + + -- No safe zones defined ==> Everything is safe. + if #self.launchzones==0 then + return true + end + + -- Loop over all zones. + for _,_zone in pairs(self.launchzones) do + local zone=_zone --Core.Zone#ZONE + local inzone=zone:IsCoordinateInZone(coord) + if inzone then + return true + end + end + + return false +end + + --- Returns the player data from a unit name. -- @param #FOX2 self -- @param #string unitName Name of the unit. diff --git a/Moose Development/Moose/Ops/Airboss.lua b/Moose Development/Moose/Ops/Airboss.lua index 1aa0b1f6f..755b41d32 100644 --- a/Moose Development/Moose/Ops/Airboss.lua +++ b/Moose Development/Moose/Ops/Airboss.lua @@ -1671,7 +1671,7 @@ AIRBOSS.MenuF10Root=nil --- Airboss class version. -- @field #string version -AIRBOSS.version="0.9.9.8" +AIRBOSS.version="0.9.9.9" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO list @@ -10883,6 +10883,14 @@ function AIRBOSS:_Glideslope(unit, optangle) -- Distance from stern to aircraft. local x=unit:GetCoordinate():Get2DDistance(landingcoord) + -- New approach using distances! + -- TODO: Tarawa, check! + local X,Z=self:_GetDistances() + x=-X + x=x+70 -- 3 wire pos. + + + -- Altitude of unit corrected by the deck height of the carrier. local h=self:_GetAltCarrier(unit) @@ -10990,8 +10998,10 @@ function AIRBOSS:_Lineup(unit, runway) -- Projection of player pos on z component. local z=UTILS.VecDot(Z, C) - --- + --- + local lineup=math.deg(math.atan2(z, x)) + --[[ -- Position of the aircraft in the new coordinate system. local a={x=x, y=0, z=z} @@ -11003,7 +11013,8 @@ function AIRBOSS:_Lineup(unit, runway) -- Current line up and error wrt to final heading of the runway. local lineup=math.deg(math.atan2(c.z, c.x)) - + ]] + return lineup end