mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
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:
parent
389adab9b8
commit
493b090534
33
Moose Development/Moose/.lua-format
Normal file
33
Moose Development/Moose/.lua-format
Normal 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
|
||||
@ -49,7 +49,6 @@
|
||||
-- ===
|
||||
-- @module Functional.Range
|
||||
-- @image Range.JPG
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
--- RANGE class
|
||||
-- @type RANGE
|
||||
@ -100,7 +99,7 @@
|
||||
-- @field #string instructorrelayname Name of relay unit.
|
||||
-- @field #string soundpath Path inside miz file where the sound files are located. Default is "Range Soundfiles/".
|
||||
-- @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
|
||||
--
|
||||
-- ===
|
||||
@ -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.
|
||||
-- The could avoid the lua garbage collection to accidentally/falsely deallocate the RANGE objects.
|
||||
--
|
||||
--
|
||||
--
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- @field #RANGE
|
||||
RANGE={
|
||||
RANGE = { -- LuaFormatter off
|
||||
ClassName = "RANGE",
|
||||
Debug = false,
|
||||
verbose = 0,
|
||||
@ -333,34 +331,34 @@ RANGE={
|
||||
rangecontrolfreq = nil,
|
||||
rangecontrol = nil,
|
||||
soundpath = "Range Soundfiles/"
|
||||
}
|
||||
} -- LuaFormatter on
|
||||
|
||||
--- Default range parameters.
|
||||
-- @list Defaults
|
||||
RANGE.Defaults={
|
||||
goodhitrange=25,
|
||||
strafemaxalt=914,
|
||||
dtBombtrack=0.005,
|
||||
Tmsg=30,
|
||||
RANGE.Defaults = { -- LuaFormatter off
|
||||
goodhitrange = 25, -- meters
|
||||
strafemaxalt = 914, -- meters AGL
|
||||
dtBombtrack = 0.005, -- seconds
|
||||
Tmsg = 30, -- seconds
|
||||
ndisplayresult = 10,
|
||||
rangeradius=5000,
|
||||
TdelaySmoke=3.0,
|
||||
boxlength=3000,
|
||||
boxwidth=300,
|
||||
goodpass=20,
|
||||
foulline=610,
|
||||
}
|
||||
rangeradius = 5000, -- meters
|
||||
TdelaySmoke = 3.0, -- seconds
|
||||
boxlength = 3000, -- meters
|
||||
boxwidth = 300, -- meters
|
||||
goodpass = 20, -- targethits per pass
|
||||
foulline = 610 -- meters
|
||||
} -- LuaFormatter on
|
||||
|
||||
--- Target type, i.e. unit, static, or coordinate.
|
||||
-- @type RANGE.TargetType
|
||||
-- @field #string UNIT Target is a unit.
|
||||
-- @field #string STATIC Target is a static.
|
||||
-- @field #string COORD Target is a coordinate.
|
||||
RANGE.TargetType={
|
||||
RANGE.TargetType = { -- LuaFormatter off
|
||||
UNIT = "Unit",
|
||||
STATIC = "Static",
|
||||
COORD = "Coordinate",
|
||||
}
|
||||
} -- LuaFormatter on
|
||||
|
||||
--- Player settings.
|
||||
-- @type RANGE.PlayerData
|
||||
@ -503,7 +501,7 @@ RANGE.Sound = {
|
||||
IRDecimal = { filename = "IR-Decimal.ogg", duration = 0.54 },
|
||||
IRMegaHertz = { filename = "IR-MegaHertz.ogg", duration = 0.87 },
|
||||
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.
|
||||
@ -565,6 +563,7 @@ function RANGE:New(rangename)
|
||||
-- Start State.
|
||||
self:SetStartState( "Stopped" )
|
||||
|
||||
-- LuaFormatter off
|
||||
---
|
||||
-- Add FSM transitions.
|
||||
-- From State --> Event --> To State
|
||||
@ -575,6 +574,7 @@ function RANGE:New(rangename)
|
||||
self:AddTransition("*", "ExitRange", "*") -- Player leaves the range.
|
||||
self:AddTransition("*", "Save", "*") -- Save player results.
|
||||
self:AddTransition("*", "Load", "*") -- Load player results.
|
||||
-- LuaFormatter on
|
||||
|
||||
------------------------
|
||||
--- Pseudo Functions ---
|
||||
@ -1765,8 +1765,7 @@ function RANGE:OnEventShot(EventData)
|
||||
local function trackBomb( _ordnance )
|
||||
|
||||
-- When the pcall returns a failure the weapon has hit.
|
||||
local _status,_bombPos = pcall(
|
||||
function()
|
||||
local _status, _bombPos = pcall( function()
|
||||
return _ordnance:getPoint()
|
||||
end )
|
||||
|
||||
@ -2003,16 +2002,11 @@ end
|
||||
-- @param #RANGE.PlayerData player Player data table.
|
||||
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.
|
||||
local text=string.format("%s, impact %03d° for %d ft", player.playername, result.radial, UTILS.MetersToFeet(result.distance))
|
||||
if targetname then
|
||||
text=text..string.format(" from bulls of target %s.")
|
||||
local text = string.format( "%s, impact %03d° for %d m (%d ft)", player.playername, result.radial, result.distance, UTILS.MetersToFeet( result.distance ) )
|
||||
-- Only display target name if there is more than one bomb target.
|
||||
if #self.bombingTargets > 1 then
|
||||
text = text .. string.format( " from bulls of target %s.", result.name )
|
||||
else
|
||||
text = text .. "."
|
||||
end
|
||||
@ -2241,7 +2235,9 @@ function RANGE:_DisplayMyStrafePitResults(_unitName)
|
||||
else
|
||||
|
||||
-- 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 )
|
||||
|
||||
-- Prepare message of best results.
|
||||
@ -2315,7 +2311,9 @@ function RANGE:_DisplayStrafePitResults(_unitName)
|
||||
end
|
||||
|
||||
-- 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 )
|
||||
|
||||
-- Add top 10 results.
|
||||
@ -2356,7 +2354,9 @@ function RANGE:_DisplayMyBombingResults(_unitName)
|
||||
else
|
||||
|
||||
-- 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 )
|
||||
|
||||
-- Loop over results.
|
||||
@ -2426,7 +2426,9 @@ function RANGE:_DisplayBombingResults(_unitName)
|
||||
end
|
||||
|
||||
-- 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 )
|
||||
|
||||
-- Loop over player results.
|
||||
@ -2477,7 +2479,7 @@ function RANGE:_DisplayRangeInfo(_unitname)
|
||||
local range = coord:Get2DDistance( position )
|
||||
|
||||
-- Bearing string.
|
||||
local Bs=string.format('%03d°', angle)
|
||||
local Bs = string.format( "%03d°", angle )
|
||||
|
||||
local texthit
|
||||
if self.PlayerSettings[playername].flaredirecthits then
|
||||
@ -2644,7 +2646,7 @@ function RANGE:_DisplayRangeWeather(_unitname)
|
||||
-- Get Beaufort wind scale.
|
||||
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 hPa2inHg = 0.0295299830714
|
||||
@ -2830,7 +2832,9 @@ function RANGE:_CheckInZone(_unitName)
|
||||
local accur = 0
|
||||
if shots > 0 then
|
||||
accur = _result.hits / shots * 100
|
||||
if accur > 100 then accur = 100 end
|
||||
if accur > 100 then
|
||||
accur = 100
|
||||
end
|
||||
end
|
||||
|
||||
-- Message text.
|
||||
@ -2961,7 +2965,6 @@ function RANGE:_AddF10Commands(_unitName)
|
||||
|
||||
end
|
||||
|
||||
|
||||
local _statsPath = missionCommands.addSubMenuForGroup( _gid, "Statistics", _rangePath )
|
||||
local _markPath = missionCommands.addSubMenuForGroup( _gid, "Mark Targets", _rangePath )
|
||||
local _settingsPath = missionCommands.addSubMenuForGroup( _gid, "My Settings", _rangePath )
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user