BAirboss = { carrierUnit = nil, Morse = nil, TACAN = nil, TACAN_Mode = nil, TACAN_ON = false, ICLS = nil, ICLS_ON = false, LINK4 = nil, LINK4_ON = false, ACLS_ON = false, } do BAirboss.DefaultSettings = { ['Forrestal'] = { Morse = 'FRS', MarshalRadio = nil, LSORadio = nil, TACAN_ON = false, TACAN = 59, TACAN_Mode = 'X', ICLS_ON = false, ICLS = 19, LINK4 = 339000000, LINK4_ON = false, ACLS_ON = false, }, ['CVN_71'] = { Morse = 'RSV', MarshalRadio = nil, LSORadio = nil, TACAN_ON = false, TACAN = 71, TACAN_Mode = 'X', ICLS_ON = false, ICLS = 11, LINK4 = 331000000, LINK4_ON = false, ACLS_ON = false, }, ['Stennis'] = { Morse = 'STN', MarshalRadio = nil, LSORadio = nil, TACAN_ON = false, TACAN = 74, TACAN_Mode = 'X', ICLS_ON = false, ICLS = 14, LINK4 = 334000000, LINK4_ON = false, 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:setLink4() self:setACLS(true) return self end function BAirboss:getWindBearingAndVel(point) local tPoint = 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:findClearPath(from,heading,range) local dest = Utils.vecTranslate(from,heading,range) range = range or Utils.get2DDist(from,dest) heading = heading or Utils.getDirection(from,dest) local iterator = 50 local partLength = range/iterator for i=1,iterator,1 do local testPoint = Utils.vecTranslate(from,heading,partLength*i) local lastPoint = from if i>1 then lastPoint = Utils.vecTranslate(from,heading,partLength*(i-1)) end if i>10 then lastPoint = Utils.vecTranslate(from,heading,partLength*(i-10)) end if land.getSurfaceType(testPoint) ~= land.SurfaceType.WATER or land.getSurfaceType(testPoint) == land.SurfaceType.SHALLOW_WATER then dest = lastPoint break end end return dest end function BAirboss:turnIntoWind() --Get weather data. local CarrierPoint = self.carrierUnit:getPoint() local windBearing, windSpeed = self:getWindBearingAndVel(CarrierPoint) -- radians & m/s local magnetic = 7 local carrierSpeed = 5/1.944 --m/s local northCorrection = mist.getNorthCorrection(CarrierPoint) local carrierHeading = math.deg(windBearing)+180+9+magnetic if carrierHeading > 360 then carrierHeading = carrierHeading - 360 end trigger.action.outText('northCorrection: '..math.deg(northCorrection),10)--Debug trigger.action.outText('windBearing: '..math.deg(windBearing),10)--Debug trigger.action.outText('carrierHeading: '..carrierHeading,10)--Debug --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: 6 hours long voyage time based on carrier speed. -- No shallow water or land between current location and final waypoint. local totalDistance = carrierSpeed * 6*60*60 --meters local newWaypoint_1 = { point = BAirboss:findClearPath(CarrierPoint,carrierHeading,totalDistance), speed = carrierSpeed } local newWaypoint_2 = { point = BAirboss:findClearPath(newWaypoint_1.point,carrierHeading+90,totalDistance/10), speed = 10/1.944 } local newWaypoint_3 = { point = BAirboss:findClearPath(newWaypoint_2.point,carrierHeading+180,Utils.get2DDist(CarrierPoint,newWaypoint_1.point)), speed = 27/1.944 } local newWaypoint_4 = { point = {x=CarrierPoint.x,y=CarrierPoint.z}, speed = 10/1.944 } local Mission = { id = 'Mission', params = { route = { points = { [1] = { type = "Turning Point", action = "Turning Point", x = newWaypoint_1.point.x, y = newWaypoint_1.point.y, speed = newWaypoint_1.speed, }, [2] = { type = "Turning Point", action = "Turning Point", x = newWaypoint_2.point.x, y = newWaypoint_2.point.y, speed = newWaypoint_2.speed, }, [3] = { type = "Turning Point", action = "Turning Point", x = newWaypoint_3.point.x, y = newWaypoint_3.point.y, speed = newWaypoint_3.speed, }, [4] = { type = "Turning Point", action = "Turning Point", x = newWaypoint_4.point.x, y = newWaypoint_4.point.y, speed = newWaypoint_4.speed, task = { id = 'ComboTask', params = { [1] = { id = 'goToWaypoint', params = { fromWaypointIndex = 4, goToWaypointIndex = 1, } }, } } }, }, }, }, } local Controller = self.carrierUnit:getGroup():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(Channel) self.LINK4 = Channel or BAirboss.DefaultSettings[self.carrierUnit:getTypeName()].LINK4 if self.LINK4 < 1000000 then self.LINK4 = self.LINK4 * 1000000 end local ActivateLink4= { id = 'ActivateLink4', params = { unitId = self.carrierUnit:getID(), frequency = self.LINK4, } } local Controller = self.carrierUnit:getController() if not Controller then return end Controller:setCommand(ActivateLink4) self.LINK4_ON = true return self end -- @param #boolean -- @return #Self function BAirboss:setACLS(switch) switch = switch or true local ACLSTask = { id = 'ActivateACLS', params = { unitId = self.carrierUnit:getID(), } } if not switch then ACLSTask = { id = 'DeactivateACLS', params = {} } end local Controller = self.carrierUnit:getController() if not Controller then return end Controller:setCommand(ACLSTask) self.ACLS_ON = switch return self end end local Airboss_Roosevelt = BAirboss:New('USS Theodore Roosevelt') Airboss_Roosevelt:turnIntoWind() trigger.action.outText('Start',20)