LuaFormatter, RANGE formatting, and minor code fixes. (#1653)

* Create .lua-format

* Update Range.lua

Format code.

* Display distance in meters from bombtarget.

All other numbers, including menu lists etc. uses meters. Feet kept in parens.

* Fixed displaying of targetname when bombing.
This commit is contained in:
TommyC81 2021-12-06 17:57:36 +04:00 committed by GitHub
parent 389adab9b8
commit 493b090534
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1132 additions and 1096 deletions

View File

@ -0,0 +1,33 @@
# See https://github.com/Koihik/LuaFormatter
# Use '-- LuaFormatter off' and '-- LuaFormatter on' around code blocks to inhibit formatting
column_limit: 500
indent_width: 2
use_tab: false
continuation_indent_width: 2
keep_simple_control_block_one_line: false
keep_simple_function_one_line: false
align_args: true
break_after_functioncall_lp: false
break_before_functioncall_rp: false
align_parameter: true
chop_down_parameter: true
break_after_functiondef_lp: false
break_before_functiondef_rp: false
align_table_field: true
break_after_table_lb: true
break_before_table_rb: true
chop_down_table: true
chop_down_kv_table: true
column_table_limit: 500
table_sep: ','
extra_sep_at_table_end: false
break_after_operator: true
single_quote_to_double_quote: true
double_quote_to_single_quote: false
spaces_before_call: 1
spaces_inside_functiondef_parens: true
spaces_inside_functioncall_parens: true
spaces_inside_table_braces: true
spaces_around_equals_in_field: true
line_breaks_after_function_body: 1

View File

@ -49,7 +49,6 @@
-- === -- ===
-- @module Functional.Range -- @module Functional.Range
-- @image Range.JPG -- @image Range.JPG
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- RANGE class --- RANGE class
-- @type RANGE -- @type RANGE
@ -100,7 +99,7 @@
-- @field #string instructorrelayname Name of relay unit. -- @field #string instructorrelayname Name of relay unit.
-- @field #string soundpath Path inside miz file where the sound files are located. Default is "Range Soundfiles/". -- @field #string soundpath Path inside miz file where the sound files are located. Default is "Range Soundfiles/".
-- @extends Core.Fsm#FSM -- @extends Core.Fsm#FSM
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- *Don't only practice your art, but force your way into its secrets; art deserves that, for it and knowledge can raise man to the Divine.* - Ludwig van Beethoven --- *Don't only practice your art, but force your way into its secrets; art deserves that, for it and knowledge can raise man to the Divine.* - Ludwig van Beethoven
-- --
-- === -- ===
@ -285,10 +284,9 @@
-- Note that it can happen that the RANGE radio menu is not shown. Check that the range object is defined as a **global** variable rather than a local one. -- Note that it can happen that the RANGE radio menu is not shown. Check that the range object is defined as a **global** variable rather than a local one.
-- The could avoid the lua garbage collection to accidentally/falsely deallocate the RANGE objects. -- The could avoid the lua garbage collection to accidentally/falsely deallocate the RANGE objects.
-- --
-- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--
-- @field #RANGE -- @field #RANGE
RANGE={ RANGE = { -- LuaFormatter off
ClassName = "RANGE", ClassName = "RANGE",
Debug = false, Debug = false,
verbose = 0, verbose = 0,
@ -333,34 +331,34 @@ RANGE={
rangecontrolfreq = nil, rangecontrolfreq = nil,
rangecontrol = nil, rangecontrol = nil,
soundpath = "Range Soundfiles/" soundpath = "Range Soundfiles/"
} } -- LuaFormatter on
--- Default range parameters. --- Default range parameters.
-- @list Defaults -- @list Defaults
RANGE.Defaults={ RANGE.Defaults = { -- LuaFormatter off
goodhitrange=25, goodhitrange = 25, -- meters
strafemaxalt=914, strafemaxalt = 914, -- meters AGL
dtBombtrack=0.005, dtBombtrack = 0.005, -- seconds
Tmsg=30, Tmsg = 30, -- seconds
ndisplayresult = 10, ndisplayresult = 10,
rangeradius=5000, rangeradius = 5000, -- meters
TdelaySmoke=3.0, TdelaySmoke = 3.0, -- seconds
boxlength=3000, boxlength = 3000, -- meters
boxwidth=300, boxwidth = 300, -- meters
goodpass=20, goodpass = 20, -- targethits per pass
foulline=610, foulline = 610 -- meters
} } -- LuaFormatter on
--- Target type, i.e. unit, static, or coordinate. --- Target type, i.e. unit, static, or coordinate.
-- @type RANGE.TargetType -- @type RANGE.TargetType
-- @field #string UNIT Target is a unit. -- @field #string UNIT Target is a unit.
-- @field #string STATIC Target is a static. -- @field #string STATIC Target is a static.
-- @field #string COORD Target is a coordinate. -- @field #string COORD Target is a coordinate.
RANGE.TargetType={ RANGE.TargetType = { -- LuaFormatter off
UNIT = "Unit", UNIT = "Unit",
STATIC = "Static", STATIC = "Static",
COORD = "Coordinate", COORD = "Coordinate",
} } -- LuaFormatter on
--- Player settings. --- Player settings.
-- @type RANGE.PlayerData -- @type RANGE.PlayerData
@ -503,7 +501,7 @@ RANGE.Sound = {
IRDecimal = { filename = "IR-Decimal.ogg", duration = 0.54 }, IRDecimal = { filename = "IR-Decimal.ogg", duration = 0.54 },
IRMegaHertz = { filename = "IR-MegaHertz.ogg", duration = 0.87 }, IRMegaHertz = { filename = "IR-MegaHertz.ogg", duration = 0.87 },
IREnterRange = { filename = "IR-EnterRange.ogg", duration = 4.83 }, IREnterRange = { filename = "IR-EnterRange.ogg", duration = 4.83 },
IRExitRange={filename="IR-ExitRange.ogg", duration=3.10}, IRExitRange = { filename = "IR-ExitRange.ogg", duration = 3.10 }
} }
--- Global list of all defined range names. --- Global list of all defined range names.
@ -565,6 +563,7 @@ function RANGE:New(rangename)
-- Start State. -- Start State.
self:SetStartState( "Stopped" ) self:SetStartState( "Stopped" )
-- LuaFormatter off
--- ---
-- Add FSM transitions. -- Add FSM transitions.
-- From State --> Event --> To State -- From State --> Event --> To State
@ -575,6 +574,7 @@ function RANGE:New(rangename)
self:AddTransition("*", "ExitRange", "*") -- Player leaves the range. self:AddTransition("*", "ExitRange", "*") -- Player leaves the range.
self:AddTransition("*", "Save", "*") -- Save player results. self:AddTransition("*", "Save", "*") -- Save player results.
self:AddTransition("*", "Load", "*") -- Load player results. self:AddTransition("*", "Load", "*") -- Load player results.
-- LuaFormatter on
------------------------ ------------------------
--- Pseudo Functions --- --- Pseudo Functions ---
@ -1765,8 +1765,7 @@ function RANGE:OnEventShot(EventData)
local function trackBomb( _ordnance ) local function trackBomb( _ordnance )
-- When the pcall returns a failure the weapon has hit. -- When the pcall returns a failure the weapon has hit.
local _status,_bombPos = pcall( local _status, _bombPos = pcall( function()
function()
return _ordnance:getPoint() return _ordnance:getPoint()
end ) end )
@ -2003,16 +2002,11 @@ end
-- @param #RANGE.PlayerData player Player data table. -- @param #RANGE.PlayerData player Player data table.
function RANGE:onafterImpact( From, Event, To, result, player ) function RANGE:onafterImpact( From, Event, To, result, player )
-- Only display target name if there is more than one bomb target.
local targetname=nil
if #self.bombingTargets>1 then
local targetname=result.name
end
-- Send message to player. -- Send message to player.
local text=string.format("%s, impact %03d° for %d ft", player.playername, result.radial, UTILS.MetersToFeet(result.distance)) local text = string.format( "%s, impact %03d° for %d m (%d ft)", player.playername, result.radial, result.distance, UTILS.MetersToFeet( result.distance ) )
if targetname then -- Only display target name if there is more than one bomb target.
text=text..string.format(" from bulls of target %s.") if #self.bombingTargets > 1 then
text = text .. string.format( " from bulls of target %s.", result.name )
else else
text = text .. "." text = text .. "."
end end
@ -2241,7 +2235,9 @@ function RANGE:_DisplayMyStrafePitResults(_unitName)
else else
-- Sort results table wrt number of hits. -- Sort results table wrt number of hits.
local _sort = function( a,b ) return a.hits > b.hits end local _sort = function( a, b )
return a.hits > b.hits
end
table.sort( _results, _sort ) table.sort( _results, _sort )
-- Prepare message of best results. -- Prepare message of best results.
@ -2315,7 +2311,9 @@ function RANGE:_DisplayStrafePitResults(_unitName)
end end
-- Sort list! -- Sort list!
local _sort = function( a,b ) return a.hits > b.hits end local _sort = function( a, b )
return a.hits > b.hits
end
table.sort( _playerResults, _sort ) table.sort( _playerResults, _sort )
-- Add top 10 results. -- Add top 10 results.
@ -2356,7 +2354,9 @@ function RANGE:_DisplayMyBombingResults(_unitName)
else else
-- Sort results wrt to distance. -- Sort results wrt to distance.
local _sort = function( a,b ) return a.distance < b.distance end local _sort = function( a, b )
return a.distance < b.distance
end
table.sort( _results, _sort ) table.sort( _results, _sort )
-- Loop over results. -- Loop over results.
@ -2426,7 +2426,9 @@ function RANGE:_DisplayBombingResults(_unitName)
end end
-- Sort list of player results. -- Sort list of player results.
local _sort = function( a,b ) return a.distance < b.distance end local _sort = function( a, b )
return a.distance < b.distance
end
table.sort( _playerResults, _sort ) table.sort( _playerResults, _sort )
-- Loop over player results. -- Loop over player results.
@ -2477,7 +2479,7 @@ function RANGE:_DisplayRangeInfo(_unitname)
local range = coord:Get2DDistance( position ) local range = coord:Get2DDistance( position )
-- Bearing string. -- Bearing string.
local Bs=string.format('%03d°', angle) local Bs = string.format( "%03d°", angle )
local texthit local texthit
if self.PlayerSettings[playername].flaredirecthits then if self.PlayerSettings[playername].flaredirecthits then
@ -2644,7 +2646,7 @@ function RANGE:_DisplayRangeWeather(_unitname)
-- Get Beaufort wind scale. -- Get Beaufort wind scale.
local Bn, Bd = UTILS.BeaufortScale( Ws ) local Bn, Bd = UTILS.BeaufortScale( Ws )
local WD=string.format('%03d°', Wd) local WD = string.format( "%03d°", Wd )
local Ts = string.format( "%d°C", T ) local Ts = string.format( "%d°C", T )
local hPa2inHg = 0.0295299830714 local hPa2inHg = 0.0295299830714
@ -2830,7 +2832,9 @@ function RANGE:_CheckInZone(_unitName)
local accur = 0 local accur = 0
if shots > 0 then if shots > 0 then
accur = _result.hits / shots * 100 accur = _result.hits / shots * 100
if accur > 100 then accur = 100 end if accur > 100 then
accur = 100
end
end end
-- Message text. -- Message text.
@ -2961,7 +2965,6 @@ function RANGE:_AddF10Commands(_unitName)
end end
local _statsPath = missionCommands.addSubMenuForGroup( _gid, "Statistics", _rangePath ) local _statsPath = missionCommands.addSubMenuForGroup( _gid, "Statistics", _rangePath )
local _markPath = missionCommands.addSubMenuForGroup( _gid, "Mark Targets", _rangePath ) local _markPath = missionCommands.addSubMenuForGroup( _gid, "Mark Targets", _rangePath )
local _settingsPath = missionCommands.addSubMenuForGroup( _gid, "My Settings", _rangePath ) local _settingsPath = missionCommands.addSubMenuForGroup( _gid, "My Settings", _rangePath )