Minor fixes.

Positionalble: Added isExist because of problems with getting coords from scenery objects.
Suppresson: Fixes. Added new transitions.
PseudoATC: Removed eject.
Artillery: Optimized debug output.
This commit is contained in:
funkyfranky 2018-05-10 15:40:10 +02:00
parent f9d7eea721
commit 6f0507ea7f
5 changed files with 69 additions and 46 deletions

View File

@ -330,7 +330,7 @@
-- @field #ARTY -- @field #ARTY
ARTY={ ARTY={
ClassName="ARTY", ClassName="ARTY",
Debug=true, Debug=false,
targets={}, targets={},
moves={}, moves={},
currentTarget=nil, currentTarget=nil,
@ -384,7 +384,7 @@ ARTY.WeaponType={
ARTY.id="ARTY | " ARTY.id="ARTY | "
--- Arty script version. --- Arty script version.
-- @field #number version -- @field #string version
ARTY.version="0.9.0" ARTY.version="0.9.0"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -799,7 +799,8 @@ function ARTY:onafterStart(Controllable, From, Event, To)
self:_EventFromTo("onafterStart", Event, From, To) self:_EventFromTo("onafterStart", Event, From, To)
-- Debug output. -- Debug output.
local text=string.format("Started ARTY for group %s.", Controllable:GetName()) local text=string.format("Started ARTY version %s for group %s.", ARTY.version, Controllable:GetName())
self:E(ARTY.id..text)
MESSAGE:New(text, 10):ToAllIf(self.Debug) MESSAGE:New(text, 10):ToAllIf(self.Debug)
-- Get Ammo. -- Get Ammo.
@ -954,31 +955,31 @@ function ARTY:_OnEventShot(EventData)
-- Weapon type name for current target. -- Weapon type name for current target.
local _weapontype=self:_WeaponTypeName(self.currentTarget.weapontype) local _weapontype=self:_WeaponTypeName(self.currentTarget.weapontype)
self:T(ARTY.id..string.format("nammo=%d, nshells=%d, nrockets=%d, nmissiles=%d", _nammo, _nshells, _nrockets, _nmissiles)) self:T(ARTY.id..string.format("Group %s ammo: total=%d, shells=%d, rockets=%d, missiles=%d", self.Controllable:GetName(), _nammo, _nshells, _nrockets, _nmissiles))
self:T(ARTY.id..string.format("Weapontype = %s", _weapontype)) self:T2(ARTY.id..string.format("Group %s uses weapontype %s for current target.", self.Controllable:GetName(), _weapontype))
-- Special weapon type requested ==> Check if corresponding ammo is empty. -- Special weapon type requested ==> Check if corresponding ammo is empty.
if self.currentTarget.weapontype==ARTY.WeaponType.Cannon and _nshells==0 then if self.currentTarget.weapontype==ARTY.WeaponType.Cannon and _nshells==0 then
self:T(ARTY.id.."Cannons requested but shells empty.") self:T(ARTY.id.."Group %s, cannons requested but shells empty.", self.Controllable:GetName())
self:CeaseFire(self.currentTarget) self:CeaseFire(self.currentTarget)
return return
elseif self.currentTarget.weapontype==ARTY.WeaponType.Rockets and _nrockets==0 then elseif self.currentTarget.weapontype==ARTY.WeaponType.Rockets and _nrockets==0 then
self:T(ARTY.id.."Rockets requested but rockets empty.") self:T(ARTY.id.."Group %s, rockets requested but rockets empty.", self.Controllable:GetName())
self:CeaseFire(self.currentTarget) self:CeaseFire(self.currentTarget)
return return
elseif self.currentTarget.weapontype==ARTY.WeaponType.UnguidedAny and _nshells+_nrockets==0 then elseif self.currentTarget.weapontype==ARTY.WeaponType.UnguidedAny and _nshells+_nrockets==0 then
self:T(ARTY.id.."Unguided weapon requested but shells AND rockets empty.") self:T(ARTY.id.."Group %s, unguided weapon requested but shells AND rockets empty.", self.Controllable:GetName())
self:CeaseFire(self.currentTarget) self:CeaseFire(self.currentTarget)
return return
elseif (self.currentTarget.weapontype==ARTY.WeaponType.GuidedMissile or self.currentTarget.weapontype==ARTY.WeaponType.CruiseMissile or self.currentTarget.weapontype==ARTY.WeaponType.AntiShipMissile) and _nmissiles==0 then elseif (self.currentTarget.weapontype==ARTY.WeaponType.GuidedMissile or self.currentTarget.weapontype==ARTY.WeaponType.CruiseMissile or self.currentTarget.weapontype==ARTY.WeaponType.AntiShipMissile) and _nmissiles==0 then
self:T(ARTY.id.."Guided, anti-ship or cruise missiles requested but all missiles empty.") self:T(ARTY.id.."Group %s, guided, anti-ship or cruise missiles requested but all missiles empty.", self.Controllable:GetName())
self:CeaseFire(self.currentTarget) self:CeaseFire(self.currentTarget)
return return
@ -995,7 +996,7 @@ function ARTY:_OnEventShot(EventData)
end end
else else
self:E(ARTY.id..string.format("ERROR: No current target?!")) self:E(ARTY.id..string.format("ERROR: No current target for group %s?!", self.Controllable:GetName()))
end end
end end
end end
@ -1042,22 +1043,20 @@ function ARTY:onafterStatus(Controllable, From, Event, To)
-- Group is out of ammo. -- Group is out of ammo.
if self:is("OutOfAmmo") then if self:is("OutOfAmmo") then
env.info(string.format("FF: OutOfAmmo. ==> Rearm")) self:T2(ARTY.id..string.format("%s: OutOfAmmo. ==> Rearm", Controllable:GetName()))
self:Rearm() self:Rearm()
end end
-- Group is out of moving. -- Group is out of moving.
if self:is("Moving") then if self:is("Moving") then
--local _speed=self.Controllable:GetVelocityKMH() self:T2(ARTY.id..string.format("%s: Moving", Controllable:GetName()))
--env.info(string.format("FF: Moving. Velocity = %d km/h", _speed))
env.info(string.format("FF: Moving"))
end end
-- Group is rearming. -- Group is rearming.
if self:is("Rearming") then if self:is("Rearming") then
local _rearmed=self:_CheckRearmed() local _rearmed=self:_CheckRearmed()
env.info(string.format("FF: Rearming. _rearmed = %s", tostring(_rearmed)))
if _rearmed then if _rearmed then
self:T2(ARTY.id..string.format("%s: Rearming ==> Rearmed", Controllable:GetName()))
self:Rearmed() self:Rearmed()
end end
end end
@ -1065,15 +1064,16 @@ function ARTY:onafterStatus(Controllable, From, Event, To)
-- Group finished rearming. -- Group finished rearming.
if self:is("Rearmed") then if self:is("Rearmed") then
local distance=self.Controllable:GetCoordinate():Get2DDistance(self.InitialCoord) local distance=self.Controllable:GetCoordinate():Get2DDistance(self.InitialCoord)
env.info(string.format("FF: Rearmed. Distance ARTY to InitalCoord = %d", distance)) self:T2(ARTY.id..string.format("%s: Rearmed. Distance ARTY to InitalCoord = %d m", Controllable:GetName(), distance))
if distance <= self.RearmingDistance then if distance <= self.RearmingDistance then
self:T2(ARTY.id..string.format("%s: Rearmed ==> CombatReady", Controllable:GetName()))
self:CombatReady() self:CombatReady()
end end
end end
-- Group arrived at destination. -- Group arrived at destination.
if self:is("Arrived") then if self:is("Arrived") then
env.info(string.format("FF: Arrived. ==> CombatReady")) self:T2(ARTY.id..string.format("%s: Arrived ==> CombatReady", Controllable:GetName()))
self:CombatReady() self:CombatReady()
end end
@ -1093,15 +1093,18 @@ function ARTY:onafterStatus(Controllable, From, Event, To)
-- Get a commaned move to another location. -- Get a commaned move to another location.
local _move=self:_CheckMoves() local _move=self:_CheckMoves()
-- Group is combat ready or firing but we have a high prio timed target.
if (self:is("CombatReady") or self:is("Firing")) and _move then if (self:is("CombatReady") or self:is("Firing")) and _move then
-- Group is combat ready or firing but we have a move.
self:T2(ARTY.id..string.format("%s: CombatReady/Firing ==> Move", Controllable:GetName()))
-- Command to move. -- Command to move.
self.currentMove=_move self.currentMove=_move
self:Move(_move.coord, _move.speed, _move.onroad) self:Move(_move.coord, _move.speed, _move.onroad)
elseif self:is("CombatReady") or (self:is("Firing") and _timedTarget) then elseif self:is("CombatReady") or (self:is("Firing") and _timedTarget) then
env.info(string.format("FF: Combatready or firing and high prio timed target.")) -- Group is combat ready or firing but we have a high prio timed target.
self:T2(ARTY.id..string.format("%s: CombatReady or Firing+Timed Target ==> OpenFire", Controllable:GetName()))
-- Engage target. -- Engage target.
if _timedTarget then if _timedTarget then
@ -1137,7 +1140,7 @@ end
function ARTY:onenterCombatReady(Controllable, From, Event, To) function ARTY:onenterCombatReady(Controllable, From, Event, To)
self:_EventFromTo("onenterCombatReady", Event, From, To) self:_EventFromTo("onenterCombatReady", Event, From, To)
-- Debug info -- Debug info
self:T(string.format("FF: onenterComabReady, from=%s, event=%s, to=%s", From, Event, To)) self:T3(ARTY.id..string.format("onenterComabReady, from=%s, event=%s, to=%s", From, Event, To))
end end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -1882,12 +1885,14 @@ function ARTY:GetAmmo(display)
local weapons=#ammotable local weapons=#ammotable
self:T2(ARTY.id..string.format("Number of weapons %d.", weapons)) -- Display ammo table
self:T2({ammotable=ammotable}) if display then
self:E(ARTY.id..string.format("Number of weapons %d.", weapons))
self:T(ARTY.id.."Ammotable:") self:E({ammotable=ammotable})
for id,bla in pairs(ammotable) do self:E(ARTY.id.."Ammotable:")
self:T({id=id, ammo=bla}) for id,bla in pairs(ammotable) do
self:E({id=id, ammo=bla})
end
end end
-- Loop over all weapons. -- Loop over all weapons.
@ -1957,7 +1962,7 @@ function ARTY:GetAmmo(display)
nshells=nshells+Nammo nshells=nshells+Nammo
-- Debug info. -- Debug info.
text=text..string.format("- %d shells of type %s (category=%d mc=%s)\n", Nammo, Tammo, Category, tostring(MissileCategory)) text=text..string.format("- %d shells of type %s (category=%d, missile category=%s)\n", Nammo, Tammo, Category, tostring(MissileCategory))
elseif _gotrocket then elseif _gotrocket then
@ -1965,7 +1970,7 @@ function ARTY:GetAmmo(display)
nrockets=nrockets+Nammo nrockets=nrockets+Nammo
-- Debug info. -- Debug info.
text=text..string.format("- %d rockets of type %s (category=%d mc=%s)\n", Nammo, Tammo, Category, tostring(MissileCategory)) text=text..string.format("- %d rockets of type %s (category=%d, missile category=%s)\n", Nammo, Tammo, Category, tostring(MissileCategory))
elseif _gotmissile then elseif _gotmissile then
@ -1973,12 +1978,12 @@ function ARTY:GetAmmo(display)
nmissiles=nmissiles+Nammo nmissiles=nmissiles+Nammo
-- Debug info. -- Debug info.
text=text..string.format("- %d missiles of type %s (category=%d mc=%s)\n", Nammo, Tammo, Category, tostring(MissileCategory)) text=text..string.format("- %d missiles of type %s (category=%d, missile category=%s)\n", Nammo, Tammo, Category, tostring(MissileCategory))
else else
-- Debug info. -- Debug info.
text=text..string.format("- %d unknown ammo of type %s (category=%d mc=%s)\n", Nammo, Tammo, Category, tostring(MissileCategory)) text=text..string.format("- %d unknown ammo of type %s (category=%d, missile category=%s)\n", Nammo, Tammo, Category, tostring(MissileCategory))
end end
@ -1986,7 +1991,11 @@ function ARTY:GetAmmo(display)
end end
-- Debug text and send message. -- Debug text and send message.
self:T(ARTY.id..text) if display then
self:E(ARTY.id..text)
else
self:T3(ARTY.id..text)
end
MESSAGE:New(text, 10):ToAllIf(display) MESSAGE:New(text, 10):ToAllIf(display)
end end
@ -2112,7 +2121,7 @@ function ARTY:_CheckName(givennames, name)
until (unique) until (unique)
-- Debug output and return new name. -- Debug output and return new name.
self:T(string.format("Original name %s, new name = %s", name, newname)) self:T2(string.format("Original name %s, new name = %s", name, newname))
return newname return newname
end end
@ -2171,6 +2180,8 @@ function ARTY:_WeaponTypeName(tnumber)
name="Cruise Missiles" name="Cruise Missiles"
elseif tnumber==ARTY.WeaponType.GuidedMissile then elseif tnumber==ARTY.WeaponType.GuidedMissile then
name="Guided Missiles" name="Guided Missiles"
elseif tnumber==ARTY.WeaponType.AntiShipMissile then
name="Anti-Ship Missiles"
end end
return name return name
end end
@ -2398,12 +2409,15 @@ function ARTY._PassingWaypoint(group, arty, i, final)
if final then if final then
text=string.format("%s, arrived at destination.", group:GetName()) text=string.format("%s, arrived at destination.", group:GetName())
end end
env.info(ARTY.id..text) arty:T(ARTY.id..text)
--[[
if final then if final then
MESSAGE:New(text, 10):ToCoalitionIf(group:GetCoalition(), arty.Debug or arty.report) MESSAGE:New(text, 10):ToCoalitionIf(group:GetCoalition(), arty.Debug or arty.report)
else else
MESSAGE:New(text, 10):ToAllIf(arty.Debug) MESSAGE:New(text, 10):ToAllIf(arty.Debug)
end end
]]
-- Arrived event. -- Arrived event.
if final and arty.Controllable:GetName()==group:GetName() then if final and arty.Controllable:GetName()==group:GetName() then

View File

@ -146,7 +146,7 @@ function PSEUDOATC:Start()
self:HandleEvent(EVENTS.Takeoff, self._PlayerTakeOff) self:HandleEvent(EVENTS.Takeoff, self._PlayerTakeOff)
self:HandleEvent(EVENTS.PlayerLeaveUnit, self._PlayerLeft) self:HandleEvent(EVENTS.PlayerLeaveUnit, self._PlayerLeft)
self:HandleEvent(EVENTS.Crash, self._PlayerLeft) self:HandleEvent(EVENTS.Crash, self._PlayerLeft)
self:HandleEvent(EVENTS.Ejection, self._PlayerLeft) --self:HandleEvent(EVENTS.Ejection, self._PlayerLeft)
--self:HandleEvent(EVENTS.PilotDead, self._PlayerLeft) --self:HandleEvent(EVENTS.PilotDead, self._PlayerLeft)
else else
self:T(PSEUDOATC.id.."Events are handled by DCS.") self:T(PSEUDOATC.id.."Events are handled by DCS.")
@ -280,6 +280,7 @@ function PSEUDOATC:onEvent(Event)
self:_PlayerLeft(EventData) self:_PlayerLeft(EventData)
end end
--[[
-- Event eject ==> player left unit -- Event eject ==> player left unit
if Event.id == world.event.S_EVENT_EJECTION and _playername then if Event.id == world.event.S_EVENT_EJECTION and _playername then
self:_PlayerLeft(EventData) self:_PlayerLeft(EventData)
@ -289,7 +290,7 @@ function PSEUDOATC:onEvent(Event)
if Event.id == world.event.S_EVENT_PILOT_DEAD and _playername then if Event.id == world.event.S_EVENT_PILOT_DEAD and _playername then
self:_PlayerLeft(EventData) self:_PlayerLeft(EventData)
end end
]]
end end
--- Function called my MOOSE event handler when a player enters a unit. --- Function called my MOOSE event handler when a player enters a unit.
@ -477,7 +478,7 @@ function PSEUDOATC:PlayerTakeOff(unit, place)
-- Bye-Bye message. -- Bye-Bye message.
if place and self.chatty then if place and self.chatty then
local text=string.format("%s, %s, you are airborn. Have a save trip!", place, CallSign) local text=string.format("%s, %s, you are airborne. Have a safe trip!", place, CallSign)
MESSAGE:New(text, self.mdur):ToGroup(group) MESSAGE:New(text, self.mdur):ToGroup(group)
end end
@ -808,8 +809,6 @@ function PSEUDOATC:ReportHeight(id, dt, _clear)
-- Settings. -- Settings.
local settings=_DATABASE:GetPlayerSettings(self.player[id].playername) or _SETTINGS --Core.Settings#SETTINGS local settings=_DATABASE:GetPlayerSettings(self.player[id].playername) or _SETTINGS --Core.Settings#SETTINGS
env.info("FF height = "..height)
-- Height string. -- Height string.
local Hs=string.format("%d ft", UTILS.MetersToFeet(height)) local Hs=string.format("%d ft", UTILS.MetersToFeet(height))
if settings:IsMetric() then if settings:IsMetric() then

View File

@ -357,6 +357,8 @@ function SUPPRESSION:New(group)
self:AddTransition("Retreating", "Retreated", "Retreated") self:AddTransition("Retreating", "Retreated", "Retreated")
self:AddTransition("*", "Dead", "*") self:AddTransition("*", "Dead", "*")
self:AddTransition("TakingCover", "Hit", "TakingCover")
self:AddTransition("FallingBack", "Hit", "FallingBack")
--- User function for OnBefore "Hit" event. --- User function for OnBefore "Hit" event.
-- @function [parent=#SUPPRESSION] OnBeforeHit -- @function [parent=#SUPPRESSION] OnBeforeHit
@ -1078,7 +1080,9 @@ function SUPPRESSION:onafterFallBack(Controllable, From, Event, To, AttackUnit)
local Coord=DCoord:Translate(self.FallbackDist, heading) local Coord=DCoord:Translate(self.FallbackDist, heading)
-- Place marker -- Place marker
local MarkerID=Coord:MarkToAll("Fall back position for group "..Controllable:GetName()) if self.Debug then
local MarkerID=Coord:MarkToAll("Fall back position for group "..Controllable:GetName())
end
-- Smoke the coordinate. -- Smoke the coordinate.
if self.smoke or self.Debug then if self.smoke or self.Debug then
@ -1468,7 +1472,7 @@ end
function SUPPRESSION:_Run(fin, speed, formation, wait) function SUPPRESSION:_Run(fin, speed, formation, wait)
speed=speed or 20 speed=speed or 20
formation=formation or "Vee" formation=formation or "Off road"
wait=wait or 30 wait=wait or 30
local group=self.Controllable -- Wrapper.Controllable#CONTROLLABLE local group=self.Controllable -- Wrapper.Controllable#CONTROLLABLE
@ -1506,9 +1510,12 @@ function SUPPRESSION:_Run(fin, speed, formation, wait)
-- First waypoint is the current position of the group. -- First waypoint is the current position of the group.
wp[1]=ini:WaypointGround(speed, formation) wp[1]=ini:WaypointGround(speed, formation)
local MarkerID=ini:MarkToAll(string.format("Waypoing %d of group %s (initial)", #wp, self.Controllable:GetName()))
tasks[1]=group:TaskFunction("SUPPRESSION._Passing_Waypoint", self, 1, false) tasks[1]=group:TaskFunction("SUPPRESSION._Passing_Waypoint", self, 1, false)
if self.Debug then
local MarkerID=ini:MarkToAll(string.format("Waypoing %d of group %s (initial)", #wp, self.Controllable:GetName()))
end
self:T2(SUPPRESSION.id..string.format("Number of waypoints %d", nx)) self:T2(SUPPRESSION.id..string.format("Number of waypoints %d", nx))
for i=1,nx-2 do for i=1,nx-2 do
@ -1830,7 +1837,7 @@ end
-- @param #string To To state. -- @param #string To To state.
function SUPPRESSION:_EventFromTo(BA, Event, From, To) function SUPPRESSION:_EventFromTo(BA, Event, From, To)
local text=string.format("\n%s: %s EVENT %s: %s --> %s", BA, self.Controllable:GetName(), Event, From, To) local text=string.format("\n%s: %s EVENT %s: %s --> %s", BA, self.Controllable:GetName(), Event, From, To)
self:T(SUPPRESSION.id..text) self:T2(SUPPRESSION.id..text)
end end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

View File

@ -391,7 +391,7 @@ function POSITIONABLE:GetVelocityVec3()
local DCSPositionable = self:GetDCSObject() local DCSPositionable = self:GetDCSObject()
if DCSPositionable then if DCSPositionable and DCSPositionable:isExist() then
local PositionableVelocityVec3 = DCSPositionable:getVelocity() local PositionableVelocityVec3 = DCSPositionable:getVelocity()
self:T3( PositionableVelocityVec3 ) self:T3( PositionableVelocityVec3 )
return PositionableVelocityVec3 return PositionableVelocityVec3
@ -433,7 +433,7 @@ function POSITIONABLE:GetVelocityKMH()
local DCSPositionable = self:GetDCSObject() local DCSPositionable = self:GetDCSObject()
if DCSPositionable then if DCSPositionable and DCSPositionable:isExist() then
local VelocityVec3 = self:GetVelocityVec3() local VelocityVec3 = self:GetVelocityVec3()
local Velocity = ( VelocityVec3.x ^ 2 + VelocityVec3.y ^ 2 + VelocityVec3.z ^ 2 ) ^ 0.5 -- in meters / sec local Velocity = ( VelocityVec3.x ^ 2 + VelocityVec3.y ^ 2 + VelocityVec3.z ^ 2 ) ^ 0.5 -- in meters / sec
local Velocity = Velocity * 3.6 -- now it is in km/h. local Velocity = Velocity * 3.6 -- now it is in km/h.
@ -452,7 +452,7 @@ function POSITIONABLE:GetVelocityMPS()
local DCSPositionable = self:GetDCSObject() local DCSPositionable = self:GetDCSObject()
if DCSPositionable then if DCSPositionable and DCSPositionable:isExist() then
local VelocityVec3 = self:GetVelocityVec3() local VelocityVec3 = self:GetVelocityVec3()
local Velocity = ( VelocityVec3.x ^ 2 + VelocityVec3.y ^ 2 + VelocityVec3.z ^ 2 ) ^ 0.5 -- in meters / sec local Velocity = ( VelocityVec3.x ^ 2 + VelocityVec3.y ^ 2 + VelocityVec3.z ^ 2 ) ^ 0.5 -- in meters / sec
self:T3( Velocity ) self:T3( Velocity )

View File

@ -54,6 +54,9 @@ Functional/Range.lua
Functional/ZoneGoal.lua Functional/ZoneGoal.lua
Functional/ZoneGoalCoalition.lua Functional/ZoneGoalCoalition.lua
Functional/ZoneCaptureCoalition.lua Functional/ZoneCaptureCoalition.lua
Functional/Artillery.lua
Functional/Suppression.lua
Functional/PseudoATC.lua
AI/AI_Balancer.lua AI/AI_Balancer.lua
AI/AI_A2A.lua AI/AI_A2A.lua