This commit is contained in:
Frank 2019-06-24 23:17:18 +02:00
parent 1a534108bf
commit ac1d07ec66
3 changed files with 187 additions and 166 deletions

View File

@ -1102,7 +1102,7 @@ function AI_FORMATION:onenterFollowing( FollowGroupSet ) --R2.1
if FollowGroup:GetState( FollowGroup, "Mode" ) == self.__Enum.Mode.Formation then if FollowGroup:GetState( FollowGroup, "Mode" ) == self.__Enum.Mode.Formation then
self:I({Mode=FollowGroup:GetState( FollowGroup, "Mode" )}) self:T({Mode=FollowGroup:GetState( FollowGroup, "Mode" )})
FollowGroup:OptionROTEvadeFire() FollowGroup:OptionROTEvadeFire()
FollowGroup:OptionROEReturnFire() FollowGroup:OptionROEReturnFire()

View File

@ -99,6 +99,7 @@
-- @field #boolean autorelocate ARTY group will automatically move to within the max/min firing range. -- @field #boolean autorelocate ARTY group will automatically move to within the max/min firing range.
-- @field #number autorelocatemaxdist Max distance [m] the ARTY group will travel to get within firing range. Default 50000 m = 50 km. -- @field #number autorelocatemaxdist Max distance [m] the ARTY group will travel to get within firing range. Default 50000 m = 50 km.
-- @field #boolean autorelocateonroad ARTY group will use mainly road to automatically get within firing range. Default is false. -- @field #boolean autorelocateonroad ARTY group will use mainly road to automatically get within firing range. Default is false.
-- @field #number coalition The coalition of the arty group.
-- @extends Core.Fsm#FSM_CONTROLLABLE -- @extends Core.Fsm#FSM_CONTROLLABLE
--- Enables mission designers easily to assign targets for artillery units. Since the implementation is based on a Finite State Model (FSM), the mission designer can --- Enables mission designers easily to assign targets for artillery units. Since the implementation is based on a Finite State Model (FSM), the mission designer can
@ -587,6 +588,7 @@ ARTY={
autorelocate=false, autorelocate=false,
autorelocatemaxdist=50000, autorelocatemaxdist=50000,
autorelocateonroad=false, autorelocateonroad=false,
coalition=nil,
} }
--- Weapong type ID. See [here](http://wiki.hoggit.us/view/DCS_enum_weapon_flag). --- Weapong type ID. See [here](http://wiki.hoggit.us/view/DCS_enum_weapon_flag).
@ -689,7 +691,7 @@ ARTY.id="ARTY | "
--- Arty script version. --- Arty script version.
-- @field #string version -- @field #string version
ARTY.version="1.1.0" ARTY.version="1.1.1"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -782,6 +784,9 @@ function ARTY:New(group, alias)
-- Set the group name -- Set the group name
self.groupname=group:GetName() self.groupname=group:GetName()
-- Get coalition.
self.coalition=group:GetCoalition()
-- Set an alias name. -- Set an alias name.
if alias~=nil then if alias~=nil then
self.alias=tostring(alias) self.alias=tostring(alias)
@ -1931,8 +1936,8 @@ function ARTY:onafterStart(Controllable, From, Event, To)
self.Controllable:OptionROEHoldFire() self.Controllable:OptionROEHoldFire()
-- Add event handler. -- Add event handler.
self:HandleEvent(EVENTS.Shot, self._OnEventShot) self:HandleEvent(EVENTS.Shot) --, self._OnEventShot)
self:HandleEvent(EVENTS.Dead, self._OnEventDead) self:HandleEvent(EVENTS.Dead) --, self._OnEventDead)
--self:HandleEvent(EVENTS.MarkAdded, self._OnEventMarkAdded) --self:HandleEvent(EVENTS.MarkAdded, self._OnEventMarkAdded)
-- Add DCS event handler - necessary for S_EVENT_MARK_* events. So we only start it, if this was requested. -- Add DCS event handler - necessary for S_EVENT_MARK_* events. So we only start it, if this was requested.
@ -2010,7 +2015,7 @@ function ARTY:_StatusReport(display)
end end
text=text..string.format("******************************************************") text=text..string.format("******************************************************")
env.info(ARTY.id..text) env.info(ARTY.id..text)
MESSAGE:New(text, 20):Clear():ToCoalitionIf(self.Controllable:GetCoalition(), display) MESSAGE:New(text, 20):Clear():ToCoalitionIf(self.coalition, display)
end end
@ -2021,7 +2026,7 @@ end
--- Eventhandler for shot event. --- Eventhandler for shot event.
-- @param #ARTY self -- @param #ARTY self
-- @param Core.Event#EVENTDATA EventData -- @param Core.Event#EVENTDATA EventData
function ARTY:_OnEventShot(EventData) function ARTY:OnEventShot(EventData)
self:F(EventData) self:F(EventData)
-- Weapon data. -- Weapon data.
@ -2299,7 +2304,7 @@ end
function ARTY:_OnEventMarkRemove(Event) function ARTY:_OnEventMarkRemove(Event)
-- Get battery coalition and name. -- Get battery coalition and name.
local batterycoalition=self.Controllable:GetCoalition() local batterycoalition=self.coalition
--local batteryname=self.groupname --local batteryname=self.groupname
if Event.text~=nil and Event.text:find("BATTERY") then if Event.text~=nil and Event.text:find("BATTERY") then
@ -2385,7 +2390,7 @@ function ARTY:_OnEventMarkChange(Event)
_coord.y=_coord:GetLandHeight() _coord.y=_coord:GetLandHeight()
-- Get battery coalition and name. -- Get battery coalition and name.
local batterycoalition=self.Controllable:GetCoalition() local batterycoalition=self.coalition
local batteryname=self.groupname local batteryname=self.groupname
-- Check if the coalition is the same or an authorization key has been defined. -- Check if the coalition is the same or an authorization key has been defined.
@ -2496,7 +2501,7 @@ function ARTY:_OnEventMarkChange(Event)
if _assign.setrearmingplace and self.ismobile then if _assign.setrearmingplace and self.ismobile then
self:SetRearmingPlace(_coord) self:SetRearmingPlace(_coord)
_coord:RemoveMark(Event.idx) _coord:RemoveMark(Event.idx)
_coord:MarkToCoalition(string.format("Rearming place for battery %s", self.groupname), self.Controllable:GetCoalition(), false, string.format("New rearming place for battery %s defined.", self.groupname)) _coord:MarkToCoalition(string.format("Rearming place for battery %s", self.groupname), self.coalition, false, string.format("New rearming place for battery %s defined.", self.groupname))
if self.Debug then if self.Debug then
_coord:SmokeOrange() _coord:SmokeOrange()
end end
@ -2504,7 +2509,7 @@ function ARTY:_OnEventMarkChange(Event)
if _assign.setrearminggroup then if _assign.setrearminggroup then
_coord:RemoveMark(Event.idx) _coord:RemoveMark(Event.idx)
local rearminggroupcoord=_assign.setrearminggroup:GetCoordinate() local rearminggroupcoord=_assign.setrearminggroup:GetCoordinate()
rearminggroupcoord:MarkToCoalition(string.format("Rearming group for battery %s", self.groupname), self.Controllable:GetCoalition(), false, string.format("New rearming group for battery %s defined.", self.groupname)) rearminggroupcoord:MarkToCoalition(string.format("Rearming group for battery %s", self.groupname), self.coalition, false, string.format("New rearming group for battery %s defined.", self.groupname))
self:SetRearmingGroup(_assign.setrearminggroup) self:SetRearmingGroup(_assign.setrearminggroup)
if self.Debug then if self.Debug then
rearminggroupcoord:SmokeOrange() rearminggroupcoord:SmokeOrange()
@ -2608,17 +2613,19 @@ end
--- Event handler for event Dead. --- Event handler for event Dead.
-- @param #ARTY self -- @param #ARTY self
-- @param Core.Event#EVENTDATA EventData -- @param Core.Event#EVENTDATA EventData
function ARTY:_OnEventDead(EventData) function ARTY:OnEventDead(EventData)
self:F(EventData) self:F(EventData)
-- Name of controllable. -- Name of controllable.
local _name=self.groupname local _name=self.groupname
env.info("FF Dead event for arty group")
-- Check for correct group. -- Check for correct group.
if EventData.IniGroupName==_name then if EventData.IniGroupName==_name then
-- Dead Unit. -- Dead Unit.
self:T2(string.format("%s: Captured dead event for unit %s.", _name, EventData.IniUnitName)) self:I(string.format("%s: Captured dead event for unit %s.", _name, tostring(EventData.IniUnitName)))
-- FSM Dead event. We give one second for update of data base. -- FSM Dead event. We give one second for update of data base.
self:__Dead(1) self:__Dead(1)
@ -2639,6 +2646,12 @@ end
function ARTY:onafterStatus(Controllable, From, Event, To) function ARTY:onafterStatus(Controllable, From, Event, To)
self:_EventFromTo("onafterStatus", Event, From, To) self:_EventFromTo("onafterStatus", Event, From, To)
-- FSM state.
local fsmstate=self:GetState()
self:I(ARTY.id..string.format("Status of group %s: %s", self.alias, fsmstate))
if self.Controllable and self.Controllable:IsAlive() then
-- We have a cargo group ==> check if group was loaded into a carrier. -- We have a cargo group ==> check if group was loaded into a carrier.
if self.cargogroup then if self.cargogroup then
if self.cargogroup:IsLoaded() and not self:is("InTransit") then if self.cargogroup:IsLoaded() and not self:is("InTransit") then
@ -2778,6 +2791,10 @@ function ARTY:onafterStatus(Controllable, From, Event, To)
-- Call status again in ~10 sec. -- Call status again in ~10 sec.
self:__Status(self.StatusInterval) self:__Status(self.StatusInterval)
else
self:E(string.format("Arty group %s is not alive!", self.groupname))
end
end end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -2925,7 +2942,7 @@ function ARTY:onafterOpenFire(Controllable, From, Event, To, target)
-- Send message. -- Send message.
local text=string.format("%s, opening fire on target %s with %d %s. Distance %.1f km.", Controllable:GetName(), target.name, target.nshells, _type, range/1000) local text=string.format("%s, opening fire on target %s with %d %s. Distance %.1f km.", Controllable:GetName(), target.name, target.nshells, _type, range/1000)
self:T(ARTY.id..text) self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(Controllable:GetCoalition(), self.report) MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report)
--if self.Debug then --if self.Debug then
-- local _coord=target.coord --Core.Point#COORDINATE -- local _coord=target.coord --Core.Point#COORDINATE
@ -2959,7 +2976,7 @@ function ARTY:onafterCeaseFire(Controllable, From, Event, To, target)
-- Send message. -- Send message.
local text=string.format("%s, ceasing fire on target %s.", Controllable:GetName(), target.name) local text=string.format("%s, ceasing fire on target %s.", Controllable:GetName(), target.name)
self:T(ARTY.id..text) self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(Controllable:GetCoalition(), self.report) MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report)
-- Get target array index. -- Get target array index.
local id=self:_GetTargetIndexByName(target.name) local id=self:_GetTargetIndexByName(target.name)
@ -3013,7 +3030,7 @@ function ARTY:onafterWinchester(Controllable, From, Event, To)
-- Send message. -- Send message.
local text=string.format("%s, winchester!", Controllable:GetName()) local text=string.format("%s, winchester!", Controllable:GetName())
self:T(ARTY.id..text) self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(Controllable:GetCoalition(), self.report or self.Debug) MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report or self.Debug)
end end
@ -3079,7 +3096,7 @@ function ARTY:onafterRearm(Controllable, From, Event, To)
-- Send message. -- Send message.
local text=string.format("%s, %s, request rearming at rearming place.", Controllable:GetName(), self.RearmingGroup:GetName()) local text=string.format("%s, %s, request rearming at rearming place.", Controllable:GetName(), self.RearmingGroup:GetName())
self:T(ARTY.id..text) self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(Controllable:GetCoalition(), self.report or self.Debug) MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report or self.Debug)
-- Distances. -- Distances.
local dA=coordARTY:Get2DDistance(self.RearmingPlaceCoord) local dA=coordARTY:Get2DDistance(self.RearmingPlaceCoord)
@ -3104,7 +3121,7 @@ function ARTY:onafterRearm(Controllable, From, Event, To)
-- Send message. -- Send message.
local text=string.format("%s, %s, request rearming.", Controllable:GetName(), self.RearmingGroup:GetName()) local text=string.format("%s, %s, request rearming.", Controllable:GetName(), self.RearmingGroup:GetName())
self:T(ARTY.id..text) self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(Controllable:GetCoalition(), self.report or self.Debug) MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report or self.Debug)
-- Distance between ARTY group and rearming unit. -- Distance between ARTY group and rearming unit.
local distance=coordARTY:Get2DDistance(coordRARM) local distance=coordARTY:Get2DDistance(coordRARM)
@ -3123,7 +3140,7 @@ function ARTY:onafterRearm(Controllable, From, Event, To)
-- Send message. -- Send message.
local text=string.format("%s, moving to rearming place.", Controllable:GetName()) local text=string.format("%s, moving to rearming place.", Controllable:GetName())
self:T(ARTY.id..text) self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(Controllable:GetCoalition(), self.report or self.Debug) MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report or self.Debug)
-- Distance. -- Distance.
local dA=coordARTY:Get2DDistance(self.RearmingPlaceCoord) local dA=coordARTY:Get2DDistance(self.RearmingPlaceCoord)
@ -3152,7 +3169,7 @@ function ARTY:onafterRearmed(Controllable, From, Event, To)
-- Send message. -- Send message.
local text=string.format("%s, rearming complete.", Controllable:GetName()) local text=string.format("%s, rearming complete.", Controllable:GetName())
self:T(ARTY.id..text) self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(Controllable:GetCoalition(), self.report or self.Debug) MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report or self.Debug)
-- "Rearm" tactical nukes as well. -- "Rearm" tactical nukes as well.
self.Nukes=self.Nukes0 self.Nukes=self.Nukes0
@ -3204,7 +3221,7 @@ function ARTY:_CheckRearmed()
if _rearmpc>1 then if _rearmpc>1 then
local text=string.format("%s, rearming %d %% complete.", self.alias, _rearmpc) local text=string.format("%s, rearming %d %% complete.", self.alias, _rearmpc)
self:T(ARTY.id..text) self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(self.Controllable:GetCoalition(), self.report or self.Debug) MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report or self.Debug)
end end
-- Return if ammo is full. -- Return if ammo is full.
@ -3299,7 +3316,7 @@ function ARTY:onafterArrived(Controllable, From, Event, To)
-- Send message -- Send message
local text=string.format("%s, arrived at destination.", Controllable:GetName()) local text=string.format("%s, arrived at destination.", Controllable:GetName())
self:T(ARTY.id..text) self:T(ARTY.id..text)
MESSAGE:New(text, 10):ToCoalitionIf(Controllable:GetCoalition(), self.report or self.Debug) MESSAGE:New(text, 10):ToCoalitionIf(self.coalition, self.report or self.Debug)
-- Remove executed move from queue. -- Remove executed move from queue.
if self.currentMove then if self.currentMove then
@ -3354,16 +3371,20 @@ function ARTY:onafterDead(Controllable, From, Event, To)
self:_EventFromTo("onafterDead", Event, From, To) self:_EventFromTo("onafterDead", Event, From, To)
-- Number of units left in the group. -- Number of units left in the group.
--[[
local units=self.Controllable:GetUnits() local units=self.Controllable:GetUnits()
local nunits=0 local nunits=0
if units~=nil then if units~=nil then
nunits=#units nunits=#units
end end
]]
local nunits=self.Controllable:CountAliveUnits()
-- Message. -- Message.
local text=string.format("%s, one of our units just died! %d units left.", self.groupname, nunits) local text=string.format("%s, one of our units just died! %d units left.", self.groupname, nunits)
MESSAGE:New(text, 5):ToAllIf(self.Debug) MESSAGE:New(text, 5):ToAllIf(self.Debug)
self:T(ARTY.id..text) self:I(ARTY.id..text)
-- Go to stop state. -- Go to stop state.
if nunits==0 then if nunits==0 then
@ -3382,7 +3403,7 @@ function ARTY:onafterStop(Controllable, From, Event, To)
self:_EventFromTo("onafterStop", Event, From, To) self:_EventFromTo("onafterStop", Event, From, To)
-- Debug info. -- Debug info.
self:T(ARTY.id..string.format("Stopping ARTY FSM for group %s.", Controllable:GetName())) self:I(ARTY.id..string.format("Stopping ARTY FSM for group %s.", tostring(Controllable:GetName())))
-- Cease Fire on current target. -- Cease Fire on current target.
if self.currentTarget then if self.currentTarget then
@ -3933,7 +3954,7 @@ function ARTY:_MarkerKeyAuthentification(text)
-- Set battery and coalition. -- Set battery and coalition.
--local batteryname=self.groupname --local batteryname=self.groupname
local batterycoalition=self.Controllable:GetCoalition() local batterycoalition=self.coalition
-- Get assignment. -- Get assignment.
local mykey=nil local mykey=nil
@ -4248,7 +4269,7 @@ function ARTY:_MarkRequestMoves()
else else
text=text..string.format("\n- no queued relocations") text=text..string.format("\n- no queued relocations")
end end
MESSAGE:New(text, 20):Clear():ToCoalition(self.Controllable:GetCoalition()) MESSAGE:New(text, 20):Clear():ToCoalition(self.coalition)
end end
--- Request Targets. --- Request Targets.
@ -4266,7 +4287,7 @@ function ARTY:_MarkRequestTargets()
else else
text=text..string.format("\n- no queued targets") text=text..string.format("\n- no queued targets")
end end
MESSAGE:New(text, 20):Clear():ToCoalition(self.Controllable:GetCoalition()) MESSAGE:New(text, 20):Clear():ToCoalition(self.coalition)
end end
--- Create a name for an engagement initiated by placing a marker. --- Create a name for an engagement initiated by placing a marker.
@ -4448,7 +4469,7 @@ function ARTY:_CheckTargetsInRange()
-- Inform coalition that target is now in range. -- Inform coalition that target is now in range.
local text=string.format("%s, target %s is now in range.", self.alias, _target.name) local text=string.format("%s, target %s is now in range.", self.alias, _target.name)
self:T(ARTY.id..text) self:T(ARTY.id..text)
MESSAGE:New(text,10):ToCoalitionIf(self.Controllable:GetCoalition(), self.report or self.Debug) MESSAGE:New(text,10):ToCoalitionIf(self.coalition, self.report or self.Debug)
end end
end end
@ -4485,7 +4506,7 @@ function ARTY:_CheckTargetsInRange()
end end
-- Send info message. -- Send info message.
MESSAGE:New(_name.." assigned.", 10):ToCoalitionIf(self.Controllable:GetCoalition(), self.report or self.Debug) MESSAGE:New(_name.." assigned.", 10):ToCoalitionIf(self.coalition, self.report or self.Debug)
-- Assign relocation move. -- Assign relocation move.
self:AssignMoveCoord(_tocoord, nil, nil, self.autorelocateonroad, false, _name, true) self:AssignMoveCoord(_tocoord, nil, nil, self.autorelocateonroad, false, _name, true)
@ -4918,7 +4939,7 @@ function ARTY:_TargetInRange(target, message)
-- Debug output. -- Debug output.
if not _inrange then if not _inrange then
self:T(ARTY.id..text) self:T(ARTY.id..text)
MESSAGE:New(text, 5):ToCoalitionIf(self.Controllable:GetCoalition(), (self.report and message) or (self.Debug and message)) MESSAGE:New(text, 5):ToCoalitionIf(self.coalition, (self.report and message) or (self.Debug and message))
end end
-- Remove target if ARTY group cannot move, e.g. Mortas. No chance to be ever in range - unless they are cargo. -- Remove target if ARTY group cannot move, e.g. Mortas. No chance to be ever in range - unless they are cargo.

View File

@ -553,14 +553,14 @@ function AIRBASE:GetParkingSpotsTable(termtype)
local spots={} local spots={}
for _,_spot in pairs(parkingdata) do for _,_spot in pairs(parkingdata) do
if AIRBASE._CheckTerminalType(_spot.Term_Type, termtype) then if AIRBASE._CheckTerminalType(_spot.Term_Type, termtype) then
self:I({_spot=_spot}) self:T2({_spot=_spot})
local _free=_isfree(_spot) local _free=_isfree(_spot)
local _coord=COORDINATE:NewFromVec3(_spot.vTerminalPos) local _coord=COORDINATE:NewFromVec3(_spot.vTerminalPos)
table.insert(spots, {Coordinate=_coord, TerminalID=_spot.Term_Index, TerminalType=_spot.Term_Type, TOAC=_spot.TO_AC, Free=_free, TerminalID0=_spot.Term_Index_0, DistToRwy=_spot.fDistToRW}) table.insert(spots, {Coordinate=_coord, TerminalID=_spot.Term_Index, TerminalType=_spot.Term_Type, TOAC=_spot.TO_AC, Free=_free, TerminalID0=_spot.Term_Index_0, DistToRwy=_spot.fDistToRW})
end end
end end
self:I({ spots = spots } ) self:T2({ spots = spots } )
return spots return spots
end end
@ -711,7 +711,7 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius,
local _spot=parkingspot.Coordinate -- Core.Point#COORDINATE local _spot=parkingspot.Coordinate -- Core.Point#COORDINATE
local _termid=parkingspot.TerminalID local _termid=parkingspot.TerminalID
self:I({_termid=_termid}) self:T2({_termid=_termid})
if AIRBASE._CheckTerminalType(parkingspot.TerminalType, terminaltype) then if AIRBASE._CheckTerminalType(parkingspot.TerminalType, terminaltype) then