mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
SOCKEt
- Added new SOCKET class - Fixed bug in RANGE that self.PlayerSetti**n**gs was misspelled.
This commit is contained in:
parent
999ef36963
commit
eed74d72cd
File diff suppressed because it is too large
Load Diff
@ -569,17 +569,16 @@ RANGE.version = "2.4.0"
|
||||
|
||||
--- RANGE contructor. Creates a new RANGE object.
|
||||
-- @param #RANGE self
|
||||
-- @param #string rangename Name of the range. Has to be unique. Will we used to create F10 menu items etc.
|
||||
-- @param #string RangeName Name of the range. Has to be unique. Will we used to create F10 menu items etc.
|
||||
-- @return #RANGE RANGE object.
|
||||
function RANGE:New( rangename )
|
||||
BASE:F( { rangename = rangename } )
|
||||
function RANGE:New( RangeName )
|
||||
|
||||
-- Inherit BASE.
|
||||
local self = BASE:Inherit( self, FSM:New() ) -- #RANGE
|
||||
|
||||
-- Get range name.
|
||||
-- TODO: make sure that the range name is not given twice. This would lead to problems in the F10 radio menu.
|
||||
self.rangename = rangename or "Practice Range"
|
||||
self.rangename = RangeName or "Practice Range"
|
||||
|
||||
-- Log id.
|
||||
self.id = string.format( "RANGE %s | ", self.rangename )
|
||||
@ -1760,6 +1759,13 @@ function RANGE:OnEventHit( EventData )
|
||||
end
|
||||
end
|
||||
|
||||
--- Range event handler for event shot (when a unit releases a rocket or bomb (but not a fast firing gun).
|
||||
-- @param #RANGE self
|
||||
-- @param #table weapon Weapon
|
||||
function RANGE:_TrackWeapon(weapon)
|
||||
|
||||
end
|
||||
|
||||
--- Range event handler for event shot (when a unit releases a rocket or bomb (but not a fast firing gun).
|
||||
-- @param #RANGE self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
@ -1806,6 +1812,11 @@ function RANGE:OnEventShot( EventData )
|
||||
|
||||
-- Get player unit and name.
|
||||
local _unit, _playername = self:_GetPlayerUnitAndName( _unitName )
|
||||
|
||||
-- Attack parameters.
|
||||
local attackHdg=_unit:GetHeading()
|
||||
local attackAlt=_unit:GetHeight()
|
||||
local attackVel=_unit:GetVelocityKNOTS()
|
||||
|
||||
-- Set this to larger value than the threshold.
|
||||
local dPR = self.BombtrackThreshold * 2
|
||||
@ -1848,7 +1859,6 @@ function RANGE:OnEventShot( EventData )
|
||||
|
||||
-- Check again in ~0.005 seconds ==> 200 checks per second.
|
||||
return timer.getTime() + self.dtBombtrack
|
||||
|
||||
else
|
||||
|
||||
-----------------------------
|
||||
@ -1858,7 +1868,7 @@ function RANGE:OnEventShot( EventData )
|
||||
-- Get closet target to last position.
|
||||
local _closetTarget = nil -- #RANGE.BombTarget
|
||||
local _distance = nil
|
||||
local _closeCoord = nil
|
||||
local _closeCoord = nil --Core.Point#COORDINATE
|
||||
local _hitquality = "POOR"
|
||||
|
||||
-- Get callsign.
|
||||
@ -1886,6 +1896,7 @@ function RANGE:OnEventShot( EventData )
|
||||
|
||||
-- Loop over defined bombing targets.
|
||||
for _, _bombtarget in pairs( self.bombingTargets ) do
|
||||
local bombtarget=_bombtarget --#RANGE.BombTarget
|
||||
|
||||
-- Get target coordinate.
|
||||
local targetcoord = self:_GetBombTargetCoordinate( _bombtarget )
|
||||
@ -1898,15 +1909,15 @@ function RANGE:OnEventShot( EventData )
|
||||
-- Find closest target to last known position of the bomb.
|
||||
if _distance == nil or _temp < _distance then
|
||||
_distance = _temp
|
||||
_closetTarget = _bombtarget
|
||||
_closeCoord = targetcoord
|
||||
_closetTarget = bombtarget
|
||||
_closeCoord = targetcoord
|
||||
if _distance <= 1.53 then -- Rangeboss Edit
|
||||
_hitquality = "SHACK" -- Rangeboss Edit
|
||||
elseif _distance <= 0.5 * _bombtarget.goodhitrange then -- Rangeboss Edit
|
||||
elseif _distance <= 0.5 * bombtarget.goodhitrange then -- Rangeboss Edit
|
||||
_hitquality = "EXCELLENT"
|
||||
elseif _distance <= _bombtarget.goodhitrange then
|
||||
elseif _distance <= bombtarget.goodhitrange then
|
||||
_hitquality = "GOOD"
|
||||
elseif _distance <= 2 * _bombtarget.goodhitrange then
|
||||
elseif _distance <= 2 * bombtarget.goodhitrange then
|
||||
_hitquality = "INEFFECTIVE"
|
||||
else
|
||||
_hitquality = "POOR"
|
||||
@ -1927,6 +1938,7 @@ function RANGE:OnEventShot( EventData )
|
||||
local _results = self.bombPlayerResults[_playername]
|
||||
|
||||
local result = {} -- #RANGE.BombResult
|
||||
result.type = "Bomb Result"
|
||||
result.name = _closetTarget.name or "unknown"
|
||||
result.distance = _distance
|
||||
result.radial = _closeCoord:HeadingTo( impactcoord )
|
||||
@ -1934,11 +1946,15 @@ function RANGE:OnEventShot( EventData )
|
||||
result.quality = _hitquality
|
||||
result.player = playerData.playername
|
||||
result.time = timer.getAbsTime()
|
||||
result.clock = UTILS.SecondsToClock(result.time)
|
||||
result.airframe = playerData.airframe
|
||||
result.roundsFired = 0 -- Rangeboss Edit
|
||||
result.roundsHit = 0 -- Rangeboss Edit
|
||||
result.roundsQuality = "N/A" -- Rangeboss Edit
|
||||
result.rangename = self.rangename
|
||||
result.attackHdg = attackHdg
|
||||
result.attackVel = attackVel
|
||||
result.attackAlt = attackAlt
|
||||
|
||||
-- Add to table.
|
||||
table.insert( _results, result )
|
||||
@ -2078,13 +2094,13 @@ 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
|
||||
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." )
|
||||
text = text .. string.format( " from bulls of target %s.", targetname )
|
||||
else
|
||||
text = text .. "."
|
||||
end
|
||||
@ -2110,11 +2126,15 @@ function RANGE:onafterImpact( From, Event, To, result, player )
|
||||
end
|
||||
|
||||
-- Unit.
|
||||
local unit = UNIT:FindByName( player.unitname )
|
||||
|
||||
-- Send message.
|
||||
self:_DisplayMessageToGroup( unit, text, nil, true )
|
||||
self:T( self.id .. text )
|
||||
if player.unitname then
|
||||
|
||||
-- Get unit.
|
||||
local unit = UNIT:FindByName( player.unitname )
|
||||
|
||||
-- Send message.
|
||||
self:_DisplayMessageToGroup( unit, text, nil, true )
|
||||
self:T( self.id .. text )
|
||||
end
|
||||
|
||||
-- Save results.
|
||||
if self.autosave then
|
||||
@ -3045,9 +3065,11 @@ function RANGE:_CheckInZone( _unitName )
|
||||
|
||||
-- Strafe result.
|
||||
local result = {} -- #RANGE.StrafeResult
|
||||
result.type="Strafe Result"
|
||||
result.player=_playername
|
||||
result.name=_result.zone.name or "unknown"
|
||||
result.time = timer.getAbsTime()
|
||||
result.clock = UTILS.SecondsToClock(result.time)
|
||||
result.roundsFired = shots
|
||||
result.roundsHit = _result.hits
|
||||
result.roundsQuality = resulttext
|
||||
@ -3507,7 +3529,7 @@ function RANGE:_SmokeBombImpactOnOff( unitname )
|
||||
self.PlayerSettings[playername].smokebombimpact = false
|
||||
text = string.format( "%s, %s, smoking impact points of bombs is now OFF.", self.rangename, playername )
|
||||
else
|
||||
self.PlayerSettigs[playername].smokebombimpact = true
|
||||
self.PlayerSettings[playername].smokebombimpact = true
|
||||
text = string.format( "%s, %s, smoking impact points of bombs is now ON.", self.rangename, playername )
|
||||
end
|
||||
self:_DisplayMessageToGroup( unit, text, 5, false, true )
|
||||
@ -3528,7 +3550,7 @@ function RANGE:_SmokeBombDelayOnOff( unitname )
|
||||
self.PlayerSettings[playername].delaysmoke = false
|
||||
text = string.format( "%s, %s, delayed smoke of bombs is now OFF.", self.rangename, playername )
|
||||
else
|
||||
self.PlayerSettigs[playername].delaysmoke = true
|
||||
self.PlayerSettings[playername].delaysmoke = true
|
||||
text = string.format( "%s, %s, delayed smoke of bombs is now ON.", self.rangename, playername )
|
||||
end
|
||||
self:_DisplayMessageToGroup( unit, text, 5, false, true )
|
||||
|
||||
@ -5,6 +5,7 @@ __Moose.Include( 'Scripts/Moose/Utilities/Profiler.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Utilities/Templates.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Utilities/STTS.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Utilities/FiFo.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Utilities/Socket.lua' )
|
||||
|
||||
__Moose.Include( 'Scripts/Moose/Core/Base.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/Beacon.lua' )
|
||||
|
||||
@ -11273,7 +11273,7 @@ end
|
||||
|
||||
--- Get wind speed on carrier deck parallel and perpendicular to runway.
|
||||
-- @param #AIRBOSS self
|
||||
-- @param #number alt Altitude in meters. Default 15 m. (change made from 50m from Discord discussion from Sickdog)
|
||||
-- @param #number alt Altitude in meters. Default 18 m.
|
||||
-- @return #number Wind component parallel to runway im m/s.
|
||||
-- @return #number Wind component perpendicular to runway in m/s.
|
||||
-- @return #number Total wind strength in m/s.
|
||||
@ -11296,7 +11296,7 @@ function AIRBOSS:GetWindOnDeck( alt )
|
||||
zc = UTILS.Rotate2D( zc, -self.carrierparam.rwyangle )
|
||||
|
||||
-- Wind (from) vector
|
||||
local vw = cv:GetWindWithTurbulenceVec3( alt or 15 )
|
||||
local vw = cv:GetWindWithTurbulenceVec3( alt or 18 ) --(change made from 50m to 15m from Discord discussion from Sickdog, next change to 18m due to SC higher deck discord)
|
||||
|
||||
-- Total wind velocity vector.
|
||||
-- Carrier velocity has to be negative. If carrier drives in the direction the wind is blowing from, we have less wind in total.
|
||||
|
||||
117
Moose Development/Moose/Utilities/Socket.lua
Normal file
117
Moose Development/Moose/Utilities/Socket.lua
Normal file
@ -0,0 +1,117 @@
|
||||
--- **Utilities** - Socket.
|
||||
--
|
||||
-- **Main Features:**
|
||||
--
|
||||
-- * Sockets
|
||||
-- * Send messages to Discord
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **funkyfranky**
|
||||
-- @module Utilities.Socket
|
||||
-- @image Utilities_Socket.png
|
||||
|
||||
|
||||
--- SOCKET class.
|
||||
-- @type SOCKET
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @field #number verbose Verbosity level.
|
||||
-- @field #string lid Class id string for output to DCS log file.
|
||||
-- @field #table socket The socket.
|
||||
-- @field #number port The port.
|
||||
-- @field #string host The host.
|
||||
-- @field #table json JSON.
|
||||
-- @extends Core.Fsm#FSM
|
||||
|
||||
--- **It is far more important to be able to hit the target than it is to haggle over who makes a weapon or who pulls a trigger** -- Dwight D Eisenhower
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- # The SOCKET Concept
|
||||
--
|
||||
-- Create a UDP socket server. It enables you to send messages to discord servers via discord bots.
|
||||
--
|
||||
--
|
||||
-- @field #SOCKET
|
||||
SOCKET = {
|
||||
ClassName = "SOCKET",
|
||||
verbose = 0,
|
||||
lid = nil,
|
||||
}
|
||||
|
||||
--- SOCKET class version.
|
||||
-- @field #string version
|
||||
SOCKET.version="0.0.1"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO: A lot!
|
||||
-- TODO: Messages as spoiler.
|
||||
-- TODO: Send images?
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Constructor
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Create a new SOCKET object.
|
||||
-- @param #SOCKET self
|
||||
-- @param #number Port UDP port. Default `10123`.
|
||||
-- @param #string Host Host. Default `"127.0.0.1"`.
|
||||
-- @return #SOCKET self
|
||||
function SOCKET:New(Port, Host)
|
||||
|
||||
-- Inherit everything from FSM class.
|
||||
local self=BASE:Inherit(self, FSM:New()) --#SOCKET
|
||||
|
||||
package.path = package.path..";.\\LuaSocket\\?.lua;"
|
||||
package.cpath = package.cpath..";.\\LuaSocket\\?.dll;"
|
||||
|
||||
self.socket = require("socket")
|
||||
|
||||
self.port=Port or 10123
|
||||
self.host=Host or "127.0.0.1"
|
||||
|
||||
self.json=loadfile("Scripts\\JSON.lua")()
|
||||
|
||||
self.UDPSendSocket=self.socket.udp()
|
||||
self.UDPSendSocket:settimeout(0)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Send a table.
|
||||
-- @param #SOCKET self
|
||||
-- @param #table Table Table to send.
|
||||
-- @param #number Port Port.
|
||||
-- @return #SOCKET self
|
||||
function SOCKET:SendTable(Table, Port)
|
||||
|
||||
local tbl_json_txt = self.json:encode(Table)
|
||||
|
||||
Port=Port or self.port
|
||||
|
||||
self.socket.try(self.UDPSendSocket:sendto(tbl_json_txt, self.host, Port))
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Send a text message.
|
||||
-- @param #SOCKET self
|
||||
-- @param #string Text Test message.
|
||||
-- @param #number Port Port.
|
||||
-- @return #SOCKET self
|
||||
function SOCKET:SendText(Text, Port)
|
||||
|
||||
local message={}
|
||||
|
||||
message.messageType = 1
|
||||
message.messageString = Text
|
||||
|
||||
self:SendTable(message, Port)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
@ -777,8 +777,7 @@ end
|
||||
|
||||
--- Returns the POSITIONABLE height above sea level in meters.
|
||||
-- @param Wrapper.Positionable#POSITIONABLE self
|
||||
-- @return DCS#Vec3 The height of the positionable.
|
||||
-- @return #nil The POSITIONABLE is not existing or alive.
|
||||
-- @return DCS#Vec3 Height of the positionable in meters (or nil, if the object does not exist).
|
||||
function POSITIONABLE:GetHeight() --R2.1
|
||||
self:F2( self.PositionableName )
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user