Merge pull request #840 from FlightControl-Master/FF-Servant

RANGE 1.0.1
This commit is contained in:
Frank 2018-03-22 00:31:08 +01:00 committed by GitHub
commit 7a4a3217df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,8 @@
-- Implementation is based on the [Simple Range Script](https://forums.eagle.ru/showthread.php?t=157991) by [Ciribob](https://forums.eagle.ru/member.php?u=112175), which itself was motivated -- Implementation is based on the [Simple Range Script](https://forums.eagle.ru/showthread.php?t=157991) by [Ciribob](https://forums.eagle.ru/member.php?u=112175), which itself was motivated
-- by a script by SNAFU [see here](https://forums.eagle.ru/showthread.php?t=109174). -- by a script by SNAFU [see here](https://forums.eagle.ru/showthread.php?t=109174).
-- --
-- [476th - Air Weapons Range Objects mod](http://www.476vfightergroup.com/downloads.php?do=file&id=287) is highly recommended for this class.
--
-- ## Features -- ## Features
-- --
-- * Bomb and rocket impact point from closest range target is measured and distance reported to the player. -- * Bomb and rocket impact point from closest range target is measured and distance reported to the player.
@ -36,7 +38,7 @@
-- --
-- # YouTube Channel -- # YouTube Channel
-- --
-- ### [MOOSE YouTube Channel](https://www.youtube.com/playlist?list=PL7ZUrU4zZUl1jirWIo4t4YxqN-HxjqRkL) -- ### [MOOSE - On the Range - Demonstration Video](https://www.youtube.com/watch?v=kIXcxNB9_3M)
-- --
-- === -- ===
-- --
@ -54,7 +56,7 @@
-- @field #boolean Debug If true, debug info is send as messages on the screen. -- @field #boolean Debug If true, debug info is send as messages on the screen.
-- @field #string rangename Name of the range. -- @field #string rangename Name of the range.
-- @field Core.Point#COORDINATE location Coordinate of the range. -- @field Core.Point#COORDINATE location Coordinate of the range.
-- @field #number rangeradius Radius of range defining its total size for e.g. smoking bomb impact points. Default 10 km. -- @field #number rangeradius Radius of range defining its total size for e.g. smoking bomb impact points and sending radio messages. Default 10 km.
-- @field #table strafeTargets Table of strafing targets. -- @field #table strafeTargets Table of strafing targets.
-- @field #table bombingTargets Table of targets to bomb. -- @field #table bombingTargets Table of targets to bomb.
-- @field #number nbombtargets Number of bombing targets. -- @field #number nbombtargets Number of bombing targets.
@ -155,6 +157,8 @@
-- ### Goldwater Range -- ### Goldwater Range
-- This example shows hot to set up the Barry M. Goldwater range. It consists of two strafe pits each has two targets plus three bombing targets. -- This example shows hot to set up the Barry M. Goldwater range. It consists of two strafe pits each has two targets plus three bombing targets.
-- --
-- The [476th - Air Weapons Range Objects mod](http://www.476vfightergroup.com/downloads.php?do=file&id=287) is used in this example.
--
-- -- Strafe pits. Each pit can consist of multiple targets. Here we have two pits and each of the pits has two targets. These are names of the corresponding units defined in the ME. -- -- Strafe pits. Each pit can consist of multiple targets. Here we have two pits and each of the pits has two targets. These are names of the corresponding units defined in the ME.
-- local strafepit_left={"GWR Strafe Pit Left 1", "GWR Strafe Pit Left 2"} -- local strafepit_left={"GWR Strafe Pit Left 1", "GWR Strafe Pit Left 2"}
-- local strafepit_right={"GWR Strafe Pit Right 1", "GWR Strafe Pit Right 2"} -- local strafepit_right={"GWR Strafe Pit Right 1", "GWR Strafe Pit Right 2"}
@ -219,7 +223,7 @@ RANGE.id="RANGE | "
--- Range script version. --- Range script version.
-- @field #number version -- @field #number version
RANGE.version="1.0.0" RANGE.version="1.0.1"
--TODO list --TODO list
--TODO: Add statics for strafe pits. --TODO: Add statics for strafe pits.
@ -303,9 +307,12 @@ function RANGE:Start()
if self.eventmoose then if self.eventmoose then
-- Events are handled my MOOSE. -- Events are handled my MOOSE.
self:T(RANGE.id.."Events are handled by MOOSE.") self:T(RANGE.id.."Events are handled by MOOSE.")
self:HandleEvent(EVENTS.Birth, self._OnBirth) --self:HandleEvent(EVENTS.Birth, self._OnBirth)
self:HandleEvent(EVENTS.Hit, self._OnHit) --self:HandleEvent(EVENTS.Hit, self._OnHit)
self:HandleEvent(EVENTS.Shot, self._OnShot) --self:HandleEvent(EVENTS.Shot, self._OnShot)
self:HandleEvent(EVENTS.Birth)
self:HandleEvent(EVENTS.Hit)
self:HandleEvent(EVENTS.Shot)
else else
-- Events are handled directly by DCS. -- Events are handled directly by DCS.
self:T(RANGE.id.."Events are handled directly by DCS.") self:T(RANGE.id.."Events are handled directly by DCS.")
@ -549,7 +556,7 @@ function RANGE:AddBombingTargets(unitnames, goodhitrange, static)
self:AddBombingTargetUnit(_unit, goodhitrange) self:AddBombingTargetUnit(_unit, goodhitrange)
self:T(RANGE.id..string.format("Adding bombing target %s with hit range %d.", name, goodhitrange)) self:T(RANGE.id..string.format("Adding bombing target %s with hit range %d.", name, goodhitrange))
else else
self:E(RANGE.id..string.fromat("ERROR! Could not find bombing target %s.", name)) self:E(RANGE.id..string.format("ERROR! Could not find bombing target %s.", name))
end end
end end
@ -588,7 +595,12 @@ end
function RANGE:onEvent(Event) function RANGE:onEvent(Event)
self:F3(Event) self:F3(Event)
if Event == nil or Event.initiator == nil or Unit.getByName(Event.initiator:getName()) == nil then if Event == nil or Event.initiator == nil then
self:T2("Skipping onEvent. Event or Event.initiator unknown.")
return true
end
if Unit.getByName(Event.initiator:getName()) == nil then
self:T2("Skipping onEvent. Initiator unit name unknown.")
return true return true
end end
@ -610,9 +622,6 @@ function RANGE:onEvent(Event)
if Event.target then if Event.target then
EventData.TgtUnitName = Event.target:getName() EventData.TgtUnitName = Event.target:getName()
EventData.TgtDCSGroup = Event.target:getGroup()
EventData.TgtGroupName = Event.target:getGroup():getName()
EventData.TgtGroup = GROUP:FindByName(EventData.TgtGroupName)
EventData.TgtUnit = UNIT:FindByName(EventData.TgtUnitName) EventData.TgtUnit = UNIT:FindByName(EventData.TgtUnitName)
end end
@ -628,22 +637,24 @@ function RANGE:onEvent(Event)
self:T3(RANGE.id..string.format("EVENT: Ini group = %s" , tostring(EventData.IniGroupName))) self:T3(RANGE.id..string.format("EVENT: Ini group = %s" , tostring(EventData.IniGroupName)))
self:T3(RANGE.id..string.format("EVENT: Ini player = %s" , tostring(_playername))) self:T3(RANGE.id..string.format("EVENT: Ini player = %s" , tostring(_playername)))
self:T3(RANGE.id..string.format("EVENT: Tgt unit = %s" , tostring(EventData.TgtUnitName))) self:T3(RANGE.id..string.format("EVENT: Tgt unit = %s" , tostring(EventData.TgtUnitName)))
self:T3(RANGE.id..string.format("EVENT: Tgt group = %s" , tostring(EventData.IniGroupName))) self:T3(RANGE.id..string.format("EVENT: Wpn type = %s" , tostring(EventData.WeaponTypeName)))
self:T3(RANGE.id..string.format("EVENT: Wpn type = %s" , tostring(EventData.WeapoinTypeName)))
-- Call event Birth function. -- Call event Birth function.
if Event.id==world.event.S_EVENT_BIRTH and _playername then if Event.id==world.event.S_EVENT_BIRTH and _playername then
self:_OnBirth(EventData) self:OnEventBirth(EventData)
--self:_OnBirth(EventData)
end end
-- Call event Shot function. -- Call event Shot function.
if Event.id==world.event.S_EVENT_SHOT and _playername and Event.weapon then if Event.id==world.event.S_EVENT_SHOT and _playername and Event.weapon then
self:_OnShot(EventData) self:OnEventShot(EventData)
--self:_OnShot(EventData)
end end
-- Call event Hit function. -- Call event Hit function.
if Event.id==world.event.S_EVENT_HIT and _playername and DCStgtunit then if Event.id==world.event.S_EVENT_HIT and _playername and DCStgtunit then
self:_OnHit(EventData) self:OnEventHit(EventData)
--self:_OnHit(EventData)
end end
end end
@ -652,7 +663,8 @@ end
--- Range event handler for event birth. --- Range event handler for event birth.
-- @param #RANGE self -- @param #RANGE self
-- @param Core.Event#EVENTDATA EventData -- @param Core.Event#EVENTDATA EventData
function RANGE:_OnBirth(EventData) function RANGE:OnEventBirth(EventData)
--function RANGE:_OnBirth(EventData)
self:F({eventbirth = EventData}) self:F({eventbirth = EventData})
local _unitName=EventData.IniUnitName local _unitName=EventData.IniUnitName
@ -700,7 +712,8 @@ end
--- Range event handler for event hit. --- Range event handler for event hit.
-- @param #RANGE self -- @param #RANGE self
-- @param Core.Event#EVENTDATA EventData -- @param Core.Event#EVENTDATA EventData
function RANGE:_OnHit(EventData) function RANGE:OnEventHit(EventData)
--function RANGE:_OnHit(EventData)
self:F({eventhit = EventData}) self:F({eventhit = EventData})
-- Player info -- Player info
@ -716,7 +729,6 @@ function RANGE:_OnHit(EventData)
self:T3(RANGE.id.."HIT: Ini unit = "..tostring(EventData.IniUnitName)) self:T3(RANGE.id.."HIT: Ini unit = "..tostring(EventData.IniUnitName))
self:T3(RANGE.id.."HIT: Ini group = "..tostring(EventData.IniGroupName)) self:T3(RANGE.id.."HIT: Ini group = "..tostring(EventData.IniGroupName))
self:T3(RANGE.id.."HIT: Tgt target = "..tostring(EventData.TgtUnitName)) self:T3(RANGE.id.."HIT: Tgt target = "..tostring(EventData.TgtUnitName))
self:T3(RANGE.id.."HIT: Tgt group = "..tostring(EventData.TgtGroupName))
-- Current strafe target of player. -- Current strafe target of player.
local _currentTarget = self.strafeStatus[_unitID] local _currentTarget = self.strafeStatus[_unitID]
@ -787,7 +799,8 @@ end
--- Range event handler for event shot (when a unit releases a rocket or bomb (but not a fast firing gun). --- Range event handler for event shot (when a unit releases a rocket or bomb (but not a fast firing gun).
-- @param #RANGE self -- @param #RANGE self
-- @param Core.Event#EVENTDATA EventData -- @param Core.Event#EVENTDATA EventData
function RANGE:_OnShot(EventData) function RANGE:OnEventShot(EventData)
--function RANGE:_OnShot(EventData)
self:F({eventshot = EventData}) self:F({eventshot = EventData})
-- Weapon data. -- Weapon data.
@ -901,10 +914,10 @@ function RANGE:_OnShot(EventData)
-- Send message to player. -- Send message to player.
local _message = string.format("%s, impact %d m from bullseye of target %s. %s hit.", _callsign, _distance, _closetTarget.name, _hitquality) local _message = string.format("%s, impact %d m from bullseye of target %s. %s hit.", _callsign, _distance, _closetTarget.name, _hitquality)
-- Sendmessage. -- Send message.
self:_DisplayMessageToGroup(_unit, _message, nil, true) self:_DisplayMessageToGroup(_unit, _message, nil, true)
else elseif _distance <= self.rangeradius then
-- Sendmessage -- Send message
local _message=string.format("%s, weapon fell more than %.1f km away from nearest range target. No score!", _callsign, self.scorebombdistance/1000) local _message=string.format("%s, weapon fell more than %.1f km away from nearest range target. No score!", _callsign, self.scorebombdistance/1000)
self:_DisplayMessageToGroup(_unit, _message, nil, true) self:_DisplayMessageToGroup(_unit, _message, nil, true)
end end
@ -1863,7 +1876,12 @@ function RANGE:_GetPlayerUnitAndName(_unitName)
self:F(_unitName) self:F(_unitName)
if _unitName ~= nil then if _unitName ~= nil then
-- Get DCS unit from its name.
local DCSunit=Unit.getByName(_unitName) local DCSunit=Unit.getByName(_unitName)
if DCSunit then
local playername=DCSunit:getPlayerName() local playername=DCSunit:getPlayerName()
local unit=UNIT:Find(DCSunit) local unit=UNIT:Find(DCSunit)
@ -1871,8 +1889,12 @@ function RANGE:_GetPlayerUnitAndName(_unitName)
if DCSunit and unit and playername then if DCSunit and unit and playername then
return unit, playername return unit, playername
end end
end end
end
-- Return nil if we could not find a player.
return nil,nil return nil,nil
end end