diff --git a/Moose Development/Moose/Ops/ArmyGroup.lua b/Moose Development/Moose/Ops/ArmyGroup.lua index dfc0e7abf..fdb9fda9f 100644 --- a/Moose Development/Moose/Ops/ArmyGroup.lua +++ b/Moose Development/Moose/Ops/ArmyGroup.lua @@ -1046,9 +1046,9 @@ function ARMYGROUP:onafterOutOfAmmo(From, Event, To) -- Fist, check if we want to rearm once out-of-ammo. if self.rearmOnOutOfAmmo then - local truck=self:FindNearestAmmoSupply(30) + local truck, dist=self:FindNearestAmmoSupply(30) if truck then - self:T(self.lid..string.format("Found Ammo Truck %s [%s]")) + self:T(self.lid..string.format("Found Ammo Truck %s [%s]", truck:GetName(), truck:GetTypeName())) local Coordinate=truck:GetCoordinate() self:Rearm(Coordinate, Formation) return @@ -1159,16 +1159,22 @@ function ARMYGROUP:onafterRTZ(From, Event, To, Zone, Formation) if zone then - -- Debug info. - self:I(self.lid..string.format("RTZ to Zone %s", zone:GetName())) - - local Coordinate=zone:GetRandomCoordinate() - - -- Add waypoint after current. - local wp=self:AddWaypoint(Coordinate, nil, uid, Formation, true) - - -- Set if we want to resume route after reaching the detour waypoint. - wp.detour=0 + if self:IsInZone(zone) then + self:Returned() + else + + -- Debug info. + self:I(self.lid..string.format("RTZ to Zone %s", zone:GetName())) + + local Coordinate=zone:GetRandomCoordinate() + + -- Add waypoint after current. + local wp=self:AddWaypoint(Coordinate, nil, uid, Formation, true) + + -- Set if we want to resume route after reaching the detour waypoint. + wp.detour=0 + + end else self:E(self.lid.."ERROR: No RTZ zone given!") @@ -1684,7 +1690,7 @@ function ARMYGROUP:FindNearestAmmoSupply(Radius) local unit=_unit --Wrapper.Unit#UNIT -- Check coaliton and if unit can supply ammo. - if unit:GetCoalition()==myCoalition and unit:IsAmmoSupply() then + if unit:IsAlive() and unit:GetCoalition()==myCoalition and unit:IsAmmoSupply() and unit:GetVelocityKMH()<1 then -- Distance. local d=coord:Get2DDistance(unit:GetCoord()) @@ -1693,8 +1699,10 @@ function ARMYGROUP:FindNearestAmmoSupply(Radius) if d%d[%d] /%d [%s] Dist=%.1f NM ETA=%s - Speed=%.1f (%.1f) kts, Depth=%.1f m, Hdg=%03d, Turn=%s Collision=%d IntoWind=%s", - fsmstate, roe, als, nTaskTot, nMissions, wpidxCurr, wpuidCurr, wpidxNext, wpuidNext, wpN, wpF, wpDist, wpETA, speed, speedExpected, alt, self.heading, turning, freepath, intowind) + fsmstate, roe, als, nTaskTot, nMissions, wpidxCurr, wpuidCurr, wpidxNext, wpuidNext, wpN, wpF, wpDist, wpETA, speed, speedExpected, alt, self.heading or 0, turning, freepath, intowind) self:I(self.lid..text) end @@ -809,6 +820,21 @@ function NAVYGROUP:Status(From, Event, To) end + --- + -- Engage Detected Targets + --- + if self:IsCruising() and self.detectionOn and self.engagedetectedOn then + + local targetgroup, targetdist=self:_GetDetectedTarget() + + -- If we found a group, we engage it. + if targetgroup then + self:I(self.lid..string.format("Engaging target group %s at distance %d meters", targetgroup:GetName(), targetdist)) + self:EngageTarget(targetgroup) + end + + end + --- -- Cargo --- @@ -973,6 +999,8 @@ function NAVYGROUP:onafterUpdateRoute(From, Event, To, n, N, Speed, Depth) -- Waypoint. local wp=UTILS.DeepCopy(self.waypoints[i]) --Ops.OpsGroup#OPSGROUP.Waypoint + + --env.info(string.format("FF i=%d UID=%d n=%d, N=%d", i, wp.uid, n, N)) -- Speed. if Speed then @@ -1012,9 +1040,17 @@ function NAVYGROUP:onafterUpdateRoute(From, Event, To, n, N, Speed, Depth) if self:IsEngaging() or not self.passedfinalwp then + + --[[ + env.info("FF:") + for i=2,#waypoints do + local wp=waypoints[i] --Ops.OpsGroup#OPSGROUP.Waypoint + self:I(self.lid..string.format("[%d] UID=%d", i-1, wp.uid)) + end + ]] -- Debug info. - self:T(self.lid..string.format("Updateing route: WP %d-->%d (%d/%d), Speed=%.1f knots, Depth=%d m", self.currentwp, n, #waypoints, #self.waypoints, UTILS.MpsToKnots(self.speedWp), self.altWp)) + self:I(self.lid..string.format("Updateing route: WP %d-->%d (%d/%d), Speed=%.1f knots, Depth=%d m", self.currentwp, n, #waypoints, #self.waypoints, UTILS.MpsToKnots(self.speedWp), self.altWp)) -- Route group to all defined waypoints remaining. self:Route(waypoints) @@ -1311,6 +1347,114 @@ function NAVYGROUP:onafterCollisionWarning(From, Event, To, Distance) self.collisionwarning=true end +--- On after "EngageTarget" event. +-- @param #NAVYGROUP self +-- @param #string From From state. +-- @param #string Event Event. +-- @param #string To To state. +-- @param Wrapper.Group#GROUP Group the group to be engaged. +function NAVYGROUP:onafterEngageTarget(From, Event, To, Target) + self:T(self.lid.."Engaging Target") + + if Target:IsInstanceOf("TARGET") then + self.engage.Target=Target + else + self.engage.Target=TARGET:New(Target) + end + + -- Target coordinate. + self.engage.Coordinate=UTILS.DeepCopy(self.engage.Target:GetCoordinate()) + + + local intercoord=self:GetCoordinate():GetIntermediateCoordinate(self.engage.Coordinate, 0.9) + + + + -- Backup ROE and alarm state. + self.engage.roe=self:GetROE() + self.engage.alarmstate=self:GetAlarmstate() + + -- Switch ROE and alarm state. + self:SwitchAlarmstate(ENUMS.AlarmState.Auto) + self:SwitchROE(ENUMS.ROE.OpenFire) + + -- ID of current waypoint. + local uid=self:GetWaypointCurrent().uid + + -- Add waypoint after current. + self.engage.Waypoint=self:AddWaypoint(intercoord, nil, uid, Formation, true) + + -- Set if we want to resume route after reaching the detour waypoint. + self.engage.Waypoint.detour=1 + +end + +--- Update engage target. +-- @param #NAVYGROUP self +function NAVYGROUP:_UpdateEngageTarget() + + if self.engage.Target and self.engage.Target:IsAlive() then + + -- Get current position vector. + local vec3=self.engage.Target:GetVec3() + + -- Distance to last known position of target. + local dist=UTILS.VecDist3D(vec3, self.engage.Coordinate:GetVec3()) + + -- Check if target moved more than 100 meters. + if dist>100 then + + --env.info("FF Update Engage Target Moved "..self.engage.Target:GetName()) + + -- Update new position. + self.engage.Coordinate:UpdateFromVec3(vec3) + + -- ID of current waypoint. + local uid=self:GetWaypointCurrent().uid + + -- Remove current waypoint + self:RemoveWaypointByID(self.engage.Waypoint.uid) + + local intercoord=self:GetCoordinate():GetIntermediateCoordinate(self.engage.Coordinate, 0.9) + + -- Add waypoint after current. + self.engage.Waypoint=self:AddWaypoint(intercoord, nil, uid, Formation, true) + + -- Set if we want to resume route after reaching the detour waypoint. + self.engage.Waypoint.detour=0 + + end + + else + + -- Target not alive any more == Disengage. + self:Disengage() + + end + +end + +--- On after "Disengage" event. +-- @param #NAVYGROUP self +-- @param #string From From state. +-- @param #string Event Event. +-- @param #string To To state. +function NAVYGROUP:onafterDisengage(From, Event, To) + self:T(self.lid.."Disengage Target") + + -- Restore previous ROE and alarm state. + self:SwitchROE(self.engage.roe) + self:SwitchAlarmstate(self.engage.alarmstate) + + -- Remove current waypoint + if self.engage.Waypoint then + self:RemoveWaypointByID(self.engage.Waypoint.uid) + end + + -- Check group is done + self:_CheckGroupDone(1) +end + ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- Routing diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index 48a360302..02c70076b 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -3663,20 +3663,34 @@ function OPSGROUP:onafterTaskExecute(From, Event, To, Task) -- Just stay put. --TODO: Change ALARM STATE - else -- If task is scheduled (not waypoint) set task. if Task.type==OPSGROUP.TaskType.SCHEDULED or Task.ismission then + local DCSTask=nil --UTILS.DeepCopy(Task.dcstask) + + -- BARRAGE is special! + if Task.dcstask.id==AUFTRAG.SpecialTask.BARRAGE then + --env.info("FF Barrage") + local vec2=self:GetVec2() + local param=Task.dcstask.params + local heading=param.heading or math.random(1, 360) + local distance=param.distance or 100 + local tvec2=UTILS.Vec2Translate(vec2, distance, heading) + DCSTask=CONTROLLABLE.TaskFireAtPoint(nil, tvec2, param.radius, param.shots, param.weaponType, param.altitude) + else + DCSTask=Task.dcstask + end + local DCStasks={} - if Task.dcstask.id=='ComboTask' then + if DCSTask.id=='ComboTask' then -- Loop over all combo tasks. - for TaskID, Task in ipairs(Task.dcstask.params.tasks) do + for TaskID, Task in ipairs(DCSTask.params.tasks) do table.insert(DCStasks, Task) end else - table.insert(DCStasks, Task.dcstask) + table.insert(DCStasks, DCSTask) end -- Combo task. @@ -3853,7 +3867,7 @@ function OPSGROUP:onafterTaskDone(From, Event, To, Task) if self.currentmission and self.currentmission==Mission.auftragsnummer then self.currentmission=nil end - env.info("Remove mission waypoints") + self:T(self.lid.."Remove mission waypoints") self:_RemoveMissionWaypoints(Mission, false) end @@ -4474,7 +4488,7 @@ function OPSGROUP:RouteToMission(mission, delay) end -- Get ingress waypoint. - if mission.type==AUFTRAG.Type.PATROLZONE then + if mission.type==AUFTRAG.Type.PATROLZONE or mission.type==AUFTRAG.Type.BARRAGE then local zone=mission.engageTarget:GetObject() --Core.Zone#ZONE waypointcoord=zone:GetRandomCoordinate(nil , nil, surfacetypes) else @@ -5041,6 +5055,8 @@ end -- @param #number UID The goto waypoint unique ID. -- @param #number Speed (Optional) Speed to waypoint in knots. function OPSGROUP:onafterGotoWaypoint(From, Event, To, UID, Speed) + + --env.info("FF goto waypoint uid="..tostring(UID)) local n=self:GetWaypointIndex(UID) @@ -5050,10 +5066,10 @@ function OPSGROUP:onafterGotoWaypoint(From, Event, To, UID, Speed) Speed=Speed or self:GetSpeedToWaypoint(n) -- Debug message - self:T(self.lid..string.format("Goto Waypoint UID=%d index=%d from %d at speed %.1f knots", UID, n, self.currentwp, Speed)) + self:I(self.lid..string.format("Goto Waypoint UID=%d index=%d from %d at speed %.1f knots", UID, n, self.currentwp, Speed)) -- Update the route. - self:__UpdateRoute(-0.01, n, nil, Speed) + self:__UpdateRoute(0.1, n, nil, Speed) end @@ -8388,7 +8404,7 @@ end function OPSGROUP:_CheckStuck() -- Cases we are not stuck. - if self:IsHolding() or self:Is("Rearming") or self:IsWaiting() then + if self:IsHolding() or self:Is("Rearming") or self:IsWaiting() or self:HasPassedFinalWaypoint() then return end @@ -9764,7 +9780,7 @@ function OPSGROUP:SwitchRadio(Frequency, Modulation) Modulation=Modulation or self.radioDefault.Modu if self:IsFlightgroup() and not self.radio.On then - env.info("FF radio OFF") + --env.info("FF radio OFF") self.group:SetOption(AI.Option.Air.id.SILENCE, false) end diff --git a/Moose Development/Moose/Wrapper/Controllable.lua b/Moose Development/Moose/Wrapper/Controllable.lua index 428b931a2..ab5f35250 100644 --- a/Moose Development/Moose/Wrapper/Controllable.lua +++ b/Moose Development/Moose/Wrapper/Controllable.lua @@ -1437,8 +1437,8 @@ function CONTROLLABLE:TaskFireAtPoint( Vec2, Radius, AmmoCount, WeaponType, Alti id = 'FireAtPoint', params = { point = Vec2, - x=Vec2.x, - y=Vec2.y, + x = Vec2.x, + y = Vec2.y, zoneRadius = Radius, radius = Radius, expendQty = 100, -- dummy value @@ -1460,7 +1460,7 @@ function CONTROLLABLE:TaskFireAtPoint( Vec2, Radius, AmmoCount, WeaponType, Alti DCSTask.params.weaponType=WeaponType end - --self:I(DCSTask) + --BASE:I(DCSTask) return DCSTask end