- Add more functions for 'Utils.lua'.

- Update logic for BAirboss.
This commit is contained in:
2024-12-17 19:25:58 +08:00
parent e90707e0cf
commit 676ab1213e
3 changed files with 260 additions and 54 deletions
+152 -54
View File
@@ -1,12 +1,19 @@
BAirboss = {
carrierUnit = nil,
Morse = nil,
TACAN = nil,
TACAN_Mode = nil,
TACAN_Morse = nil,
TACAN_ON = false,
ICLS = nil,
ICLS_Morse = nil,
ICLS_ON = false,
LINK4 = nil,
LINK4_ON = false,
ACLS_ON = false,
}
do
@@ -24,6 +31,9 @@ do
ICLS_ON = false,
ICLS = 19,
LINK4 = 339000000,
LINK4_ON = false,
ACLS_ON = false,
},
@@ -40,6 +50,9 @@ do
ICLS_ON = false,
ICLS = 11,
LINK4 = 331000000,
LINK4_ON = false,
ACLS_ON = false,
},
@@ -56,6 +69,9 @@ do
ICLS_ON = false,
ICLS = 14,
LINK4 = 334000000,
LINK4_ON = false,
ACLS_ON = false,
},
@@ -84,13 +100,14 @@ do
self:setMorse()
self:setTACAN()
self:setICLS()
self:setLink4()
self:setACLS(true)
return self
end
function BAirboss:getWindBearingAndVel(point)
local tPoint = mist.utils.makeVec3(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
@@ -102,13 +119,43 @@ do
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 carrierSpeed = 5/1.944 --m/s
local carrierHeading = (windBearing*180/math.pi)+189
-- local carrierHeading = (windBearing*180/math.pi)+189
local carrierHeading = (windBearing*180/math.pi)+189+Utils.getNorthCorrection(CarrierPoint)
if carrierHeading > 360 then
carrierHeading = carrierHeading - 360
@@ -118,13 +165,36 @@ do
if windSpeed <= 20/1.944 then
carrierSpeed = 25/1.944-windSpeed
end
trigger.action.outText('windSpeed: '..(windSpeed*1.944),10) --Debug
trigger.action.outText('carrierSpeed: '..(carrierSpeed*1.944),10) --Debug
-- Find available waypoint and path.
-- Requirements: 3 hours long voyage time based on carrier speed.
-- Requirements: 6 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 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
}
trigger.action.circleToAll(-1,1,{x=newWaypoint_1.point.x,y=0,z=newWaypoint_1.point.y},5000,{1,0,0,1},{1,0,0,0.3},1)--Debug
trigger.action.circleToAll(-1,2,{x=newWaypoint_2.point.x,y=0,z=newWaypoint_2.point.y},5000,{1,0,0,1},{1,0,0,0.3},1)--Debug
trigger.action.circleToAll(-1,3,{x=newWaypoint_3.point.x,y=0,z=newWaypoint_3.point.y},5000,{1,0,0,1},{1,0,0,0.3},1)--Debug
trigger.action.circleToAll(-1,4,{x=newWaypoint_4.point.x,y=0,z=newWaypoint_4.point.y},5000,{1,0,0,1},{1,0,0,0.3},1)--Debug
local Mission = {
id = 'Mission',
params = {
@@ -133,53 +203,48 @@ do
[1] = {
type = "Turning Point",
action = "Turning Point",
x = finalWaypoint.x,
y = finalWaypoint.y,
speed = carrierSpeed,
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 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
@@ -252,19 +317,52 @@ do
return self
end
function BAirboss:setLink4()
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)
if switch then
self.ACLS_ON = true
end
switch = switch or true
local ACLSTask = {
id = 'ActivateACLS',
params = {
unitId = self.carrierUnit:getID(),
}
}
if not switch then
self.ACLS_ON = false
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