- Finish 'turnIntoWind' function for 'BAirboss'. - Add 'Utils.lua' for some support functions.
276 lines
7.6 KiB
Lua
276 lines
7.6 KiB
Lua
BAirboss = {
|
|
carrierUnit = nil,
|
|
|
|
TACAN = nil,
|
|
TACAN_Mode = nil,
|
|
TACAN_Morse = nil,
|
|
|
|
ICLS = nil,
|
|
ICLS_Morse = nil,
|
|
}
|
|
|
|
do
|
|
BAirboss.DefaultSettings = {
|
|
['Forrestal'] = {
|
|
Morse = 'FRS',
|
|
|
|
MarshalRadio = nil,
|
|
LSORadio = nil,
|
|
|
|
TACAN_ON = false,
|
|
TACAN = 59,
|
|
TACAN_Mode = 'X',
|
|
|
|
ICLS_ON = false,
|
|
ICLS = 19,
|
|
|
|
ACLS_ON = false,
|
|
},
|
|
|
|
['CVN_71'] = {
|
|
Morse = 'RSV',
|
|
|
|
MarshalRadio = nil,
|
|
LSORadio = nil,
|
|
|
|
TACAN_ON = false,
|
|
TACAN = 71,
|
|
TACAN_Mode = 'X',
|
|
|
|
ICLS_ON = false,
|
|
ICLS = 11,
|
|
|
|
ACLS_ON = false,
|
|
},
|
|
|
|
['Stennis'] = {
|
|
Morse = 'STN',
|
|
|
|
MarshalRadio = nil,
|
|
LSORadio = nil,
|
|
|
|
TACAN_ON = false,
|
|
TACAN = 74,
|
|
TACAN_Mode = 'X',
|
|
|
|
ICLS_ON = false,
|
|
ICLS = 14,
|
|
|
|
ACLS_ON = false,
|
|
},
|
|
|
|
}
|
|
|
|
function BAirboss:New(carrierUnitName)
|
|
if not carrierUnitName then return end
|
|
|
|
if type(carrierUnitName) ~= 'string' then
|
|
--errMsg
|
|
|
|
return
|
|
end
|
|
|
|
self.carrierUnit = Unit.getByName(carrierUnitName)
|
|
|
|
if not self.carrierUnit then
|
|
local errMsg = 'ERROR: Carrier unit %s is not found in mission.'
|
|
errMsg = string.format(Localizations:translate(errMsg,'cn'),carrierUnitName)
|
|
|
|
trigger.action.outText(errMsg,120)
|
|
env.error(errMsg)
|
|
return nil
|
|
end
|
|
|
|
self:setMorse()
|
|
self:setTACAN()
|
|
self:setICLS()
|
|
self:setACLS(true)
|
|
|
|
return self
|
|
end
|
|
|
|
function BAirboss:getWindBearingAndVel(point)
|
|
local tPoint = mist.utils.makeVec3(point)
|
|
local gLevel = land.getHeight({x = tPoint.x, y = tPoint.z})
|
|
if tPoint.y <= gLevel then
|
|
tPoint.y = gLevel + 10
|
|
end
|
|
local t = atmosphere.getWind(tPoint)
|
|
local bearing = math.atan2(t.z, t.x)
|
|
local vel = math.sqrt(t.x^2 + t.z^2)
|
|
|
|
return bearing, vel
|
|
end
|
|
|
|
function BAirboss:turnIntoWind()
|
|
--Get weather data.
|
|
local CarrierPoint = self.carrierUnit:getPoint()
|
|
local windBearing, windSpeed = self:getWindBearingAndVel(CarrierPoint) -- radians & m/s
|
|
|
|
local carrierSpeed = 5/1.944 --m/s
|
|
local carrierHeading = (windBearing*180/math.pi)+189
|
|
|
|
if carrierHeading > 360 then
|
|
carrierHeading = carrierHeading - 360
|
|
end
|
|
|
|
--Calculate wind speed on deck in knots. If wind speed < 25 knots, try to make it 25 knots on deck.
|
|
if windSpeed <= 20/1.944 then
|
|
carrierSpeed = 25/1.944-windSpeed
|
|
end
|
|
|
|
-- Find available waypoint and path.
|
|
-- Requirements: 3 hours long voyage time based on carrier speed.
|
|
-- No shallow water or land between current location and final waypoint.
|
|
local totalDistance = carrierSpeed * 3*60*60 --meters
|
|
local finalWaypoint = Utils.vecTranslate(CarrierPoint,carrierHeading,totalDistance)
|
|
|
|
local Mission = {
|
|
id = 'Mission',
|
|
params = {
|
|
route = {
|
|
points = {
|
|
[1] = {
|
|
type = "Turning Point",
|
|
action = "Turning Point",
|
|
x = finalWaypoint.x,
|
|
y = finalWaypoint.y,
|
|
speed = carrierSpeed,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
local partLength = totalDistance/100
|
|
for i=1,100,1 do
|
|
local testPoint = Utils.vecTranslate(CarrierPoint,carrierHeading,partLength*i)
|
|
local lastPoint = CarrierPoint
|
|
if i>1 then
|
|
lastPoint = Utils.vecTranslate(CarrierPoint,carrierHeading,partLength*(i-1))
|
|
end
|
|
|
|
if land.getSurfaceType(testPoint) ~= land.SurfaceType.WATER then
|
|
Mission.params.route.points[1].x = lastPoint.x
|
|
Mission.params.route.points[1].y = lastPoint.y
|
|
|
|
local missionWaypoint2 = Mission.params.route.points[1]
|
|
|
|
local wayPoint2 = CarrierPoint
|
|
for j=1,100,10 do
|
|
local bTestPoint = Utils.vecTranslate(CarrierPoint,carrierHeading+180,totalDistance/100*j)
|
|
local bLastPoint = testPoint
|
|
if j>1 then
|
|
bLastPoint = Utils.vecTranslate(CarrierPoint,carrierHeading+180,totalDistance/100*(j-1))
|
|
end
|
|
|
|
if land.getSurfaceType(bTestPoint) ~= land.SurfaceType.WATER then
|
|
wayPoint2 = bLastPoint
|
|
missionWaypoint2.x = wayPoint2.x
|
|
missionWaypoint2.y = wayPoint2.y
|
|
missionWaypoint2.speed = 27/1.944
|
|
|
|
Mission.params.route.points[2] = missionWaypoint2
|
|
|
|
break
|
|
end
|
|
end
|
|
|
|
break
|
|
end
|
|
end
|
|
|
|
local Controller = self.carrierUnit:getController()
|
|
if not Controller then return end
|
|
|
|
timer.scheduleFunction(function (Mission)
|
|
Controller:setTask(Mission)
|
|
end,Mission,timer.getTime()+1)
|
|
|
|
return self
|
|
end
|
|
|
|
function BAirboss:setMorse(MorseCode)
|
|
self.Morse = MorseCode or BAirboss.DefaultSettings[self.carrierUnit:getTypeName()].Morse
|
|
return self
|
|
end
|
|
|
|
function BAirboss:setTACAN(Channel,Mode,MorseCode)
|
|
self.TACAN = Channel or BAirboss.DefaultSettings[self.carrierUnit:getTypeName()].TACAN
|
|
|
|
local Mode = Mode or BAirboss.DefaultSettings[self.carrierUnit:getTypeName()].TACAN_Mode
|
|
|
|
Mode = string.upper(Mode)
|
|
if Mode~='X' or Mode~='Y' then
|
|
Mode = BAirboss.DefaultSettings[self.carrierUnit:getTypeName()].TACAN_Mode
|
|
end
|
|
self.TACAN_Mode = Mode or BAirboss.DefaultSettings[self.carrierUnit:getTypeName()].TACAN_Mode
|
|
|
|
self:setMorse(MorseCode)
|
|
|
|
local ActivateBeacon ={
|
|
id = 'ActivateBeacon',
|
|
params = {
|
|
type = 4,
|
|
system = 3,
|
|
callsign = self.Morse,
|
|
frequency = Utils.TACANToFrequency(self.TACAN, self.TACAN_Mode)
|
|
}
|
|
}
|
|
|
|
local Controller = self.carrierUnit:getController()
|
|
if not Controller then
|
|
return
|
|
end
|
|
|
|
Controller:setCommand(ActivateBeacon)
|
|
self.TACAN_ON = true
|
|
|
|
return self
|
|
end
|
|
|
|
function BAirboss:setICLS(Channel,MorseCode)
|
|
self.ICLS = Channel or BAirboss.DefaultSettings[self.carrierUnit:getTypeName()].ICLS
|
|
|
|
self:setMorse(MorseCode)
|
|
|
|
local ActivateICLS= {
|
|
id = 'ActivateICLS',
|
|
params = {
|
|
type = 131584,
|
|
channel = self.ICLS,
|
|
unitId = self.carrierUnit:getID(),
|
|
}
|
|
}
|
|
|
|
local Controller = self.carrierUnit:getController()
|
|
if not Controller then return end
|
|
|
|
Controller:setCommand(ActivateICLS)
|
|
self.ICLS_ON = true
|
|
|
|
return self
|
|
end
|
|
|
|
function BAirboss:setLink4()
|
|
|
|
end
|
|
|
|
function BAirboss:setACLS(switch)
|
|
if switch then
|
|
self.ACLS_ON = true
|
|
end
|
|
|
|
if not switch then
|
|
self.ACLS_ON = false
|
|
end
|
|
|
|
return self
|
|
end
|
|
end
|
|
|
|
|
|
local Airboss_Roosevelt = BAirboss:New('USS Theodore Roosevelt')
|
|
|
|
Airboss_Roosevelt:turnIntoWind()
|
|
trigger.action.outText('Start',20) |