Compare commits
46
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3adf2faa4a | ||
|
|
47e947c80e | ||
|
|
c42a61c2df | ||
|
|
ca85b0116f | ||
|
|
7f3a1d00a7 | ||
|
|
06fb098b49 | ||
|
|
49eac0a7ed | ||
|
|
fb5ea45a4d | ||
|
|
7ec3006a7e | ||
|
|
9d55f7e017 | ||
|
|
20ef08e16c | ||
|
|
cb05bd0925 | ||
|
|
3e600ead0d | ||
|
|
f30c1a25fb | ||
|
|
8a9718798d | ||
|
|
dd265920cc | ||
|
|
1b8d6154c1 | ||
|
|
ebdc7b898b | ||
|
|
4157c172f1 | ||
|
|
092d24d24a | ||
|
|
c9761b1f84 | ||
|
|
7bafa23bb5 | ||
|
|
7429edb779 | ||
|
|
14c4e124b7 | ||
|
|
ac517b24f6 | ||
|
|
9163433bc8 | ||
|
|
586f142e78 | ||
|
|
c08d8fb7cb | ||
|
|
f3efdf3c31 | ||
|
|
5e2510c169 | ||
|
|
9baed7be1b | ||
|
|
1c88738494 | ||
|
|
5389029648 | ||
|
|
59a450bb18 | ||
|
|
9ce22b0c13 | ||
|
|
9dee80e204 | ||
|
|
b11c50176f | ||
|
|
e863dac489 | ||
|
|
ec17411088 | ||
|
|
4b7a82adfb | ||
|
|
4047499e22 | ||
|
|
ba3bd8f516 | ||
|
|
5655f931ea | ||
|
|
d16e4acbb9 | ||
|
|
9240705a2c | ||
|
|
fa824126fa |
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,138 @@
|
|||||||
|
AARTanker = {
|
||||||
|
AllTankers = {},
|
||||||
|
SpawnPoint_vec2 = {x=-246874,y=562226},
|
||||||
|
|
||||||
|
DefaultSettings = {
|
||||||
|
['KC135_Low'] = {
|
||||||
|
Type = 'KC-135',
|
||||||
|
|
||||||
|
Callsign_Name = 1,
|
||||||
|
Callsign_Number = 1,
|
||||||
|
|
||||||
|
Radio = 335000000,
|
||||||
|
|
||||||
|
TACAN = 35,
|
||||||
|
TACAN_Mode = 'X',
|
||||||
|
|
||||||
|
Alt = 10000/3.28,
|
||||||
|
Speed = 270/1.944,
|
||||||
|
},
|
||||||
|
|
||||||
|
['KC135_High'] = {
|
||||||
|
Type = 'KC-135',
|
||||||
|
|
||||||
|
Callsign_Name = 1,
|
||||||
|
Callsign_Number = 2,
|
||||||
|
|
||||||
|
Radio = 336000000,
|
||||||
|
|
||||||
|
TACAN = 36,
|
||||||
|
TACAN_Mode = 'X',
|
||||||
|
|
||||||
|
Alt = 16000/3.28,
|
||||||
|
Speed = 270/1.944,
|
||||||
|
},
|
||||||
|
|
||||||
|
['KC135MPRS'] = {
|
||||||
|
Type = 'KC-135',
|
||||||
|
|
||||||
|
Callsign_Name = 2,
|
||||||
|
Callsign_Number = 1,
|
||||||
|
|
||||||
|
Radio = 337000000,
|
||||||
|
|
||||||
|
TACAN = 37,
|
||||||
|
TACAN_Mode = 'X',
|
||||||
|
|
||||||
|
Alt = 14000/3.28,
|
||||||
|
Speed = 270/1.944,
|
||||||
|
},
|
||||||
|
|
||||||
|
['KC130'] = {
|
||||||
|
Type = 'KC-135',
|
||||||
|
|
||||||
|
Callsign_Name = 2,
|
||||||
|
Callsign_Number = 2,
|
||||||
|
|
||||||
|
Radio = 330000000,
|
||||||
|
|
||||||
|
TACAN = 36,
|
||||||
|
TACAN_Mode = 'X',
|
||||||
|
|
||||||
|
Alt = 11000/3.28,
|
||||||
|
Speed = 270/1.944,
|
||||||
|
},
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
|
||||||
|
function AARTanker:New(groupName,missionType)
|
||||||
|
if not groupName then return end
|
||||||
|
if type(groupName) ~= 'string' then return end
|
||||||
|
if not missionType then return end
|
||||||
|
|
||||||
|
local obj = {}
|
||||||
|
obj.groupName = groupName
|
||||||
|
obj.group = Group.getByName(groupName) or AARTanker.Spawn(groupName,missionType)
|
||||||
|
obj.missionType = missionType
|
||||||
|
|
||||||
|
obj.TACAN = nil
|
||||||
|
obj.TACAN_Mode = nil
|
||||||
|
obj.TACAN_On = false
|
||||||
|
|
||||||
|
obj.Radio = nil
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return obj
|
||||||
|
end
|
||||||
|
|
||||||
|
function AARTanker.Spawn(groupName,missionType)
|
||||||
|
if not groupName then return end
|
||||||
|
if type(groupName) ~= 'string' then return end
|
||||||
|
if not missionType then return end
|
||||||
|
|
||||||
|
local spawnData = {}
|
||||||
|
spawnData.name = groupName
|
||||||
|
spawnData.task = 'Refueling'
|
||||||
|
spawnData.modulation = radio.modulation.AM
|
||||||
|
spawnData.frequency = AARTanker.DefaultSettings[missionType].Radio
|
||||||
|
spawnData.units = {
|
||||||
|
[1] ={
|
||||||
|
name = groupName..'-1',
|
||||||
|
type = AARTanker.DefaultSettings[missionType].Type,
|
||||||
|
skill = AI.Skill.EXCELLENT,
|
||||||
|
x = 1,
|
||||||
|
y = 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
spawnData.route = AARTanker.getDefaultRoute(missionType)
|
||||||
|
|
||||||
|
local newGroup = coalition.addGroup(country.id.CJTF_BLUE, Group.Category.AIRPLANE, spawnData)
|
||||||
|
if not newGroup:getName() then return end
|
||||||
|
|
||||||
|
return newGroup
|
||||||
|
end
|
||||||
|
|
||||||
|
function AARTanker.getDefaultRoute(missionType)
|
||||||
|
local route = {}
|
||||||
|
route.points = {
|
||||||
|
[1] = {
|
||||||
|
['type'] = 'Turning Point',
|
||||||
|
['action'] = 'Turning Point',
|
||||||
|
['alt'] = AARTanker.DefaultSettings[missionType].Alt,
|
||||||
|
['alt_type'] = 'BARO',
|
||||||
|
['x'] = 1,
|
||||||
|
['y'] = 1,
|
||||||
|
['speed'] = AARTanker.DefaultSettings[missionType].Speed,
|
||||||
|
['task'] = {}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
+169
-43
@@ -3,6 +3,8 @@ BAirboss = {
|
|||||||
|
|
||||||
Morse = nil,
|
Morse = nil,
|
||||||
|
|
||||||
|
ATC = nil,
|
||||||
|
|
||||||
TACAN = nil,
|
TACAN = nil,
|
||||||
TACAN_Mode = nil,
|
TACAN_Mode = nil,
|
||||||
TACAN_ON = false,
|
TACAN_ON = false,
|
||||||
@@ -17,10 +19,48 @@ BAirboss = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
|
BAirboss.AircraftTypes={
|
||||||
|
AV8B="AV8BNA",
|
||||||
|
HORNET="FA-18C_hornet",
|
||||||
|
A4EC="A-4E-C",
|
||||||
|
F14A="F-14A-135-GR",
|
||||||
|
F14B="F-14B",
|
||||||
|
F14A_AI="F-14A",
|
||||||
|
FA18C="F/A-18C",
|
||||||
|
T45C="T-45",
|
||||||
|
S3B="S-3B",
|
||||||
|
S3BTANKER="S-3B Tanker",
|
||||||
|
E2D="E-2C",
|
||||||
|
C2A="C2A_Greyhound",
|
||||||
|
RHINOE="FA-18E",
|
||||||
|
RHINOF="FA-18F",
|
||||||
|
GROWLER="EA-18G",
|
||||||
|
}
|
||||||
|
|
||||||
|
BAirboss.CarrierType = {
|
||||||
|
ROOSEVELT = "CVN_71",
|
||||||
|
LINCOLN = "CVN_72",
|
||||||
|
WASHINGTON = "CVN_73",
|
||||||
|
TRUMAN = "CVN_75",
|
||||||
|
STENNIS = "Stennis",
|
||||||
|
FORRESTAL = "Forrestal",
|
||||||
|
VINSON = "VINSON",
|
||||||
|
HERMES = "HERMES81",
|
||||||
|
INVINCIBLE = "hms_invincible",
|
||||||
|
TARAWA = "LHA_Tarawa",
|
||||||
|
AMERICA = "USS America LHA-6",
|
||||||
|
JCARLOS = "L61",
|
||||||
|
CANBERRA = "L02",
|
||||||
|
KUZNETSOV = "KUZNECOW",
|
||||||
|
}
|
||||||
|
|
||||||
BAirboss.DefaultSettings = {
|
BAirboss.DefaultSettings = {
|
||||||
['Forrestal'] = {
|
[BAirboss.CarrierType.FORRESTAL] = {
|
||||||
Morse = 'FRS',
|
Morse = 'FRS',
|
||||||
|
|
||||||
|
ATC = RadioManager.RegisterChannel(269000000,RadioManager.RadioTypes.Carrier,'CVN 59'),
|
||||||
|
-- ATC = 269000000,
|
||||||
|
|
||||||
MarshalRadio = nil,
|
MarshalRadio = nil,
|
||||||
LSORadio = nil,
|
LSORadio = nil,
|
||||||
|
|
||||||
@@ -37,9 +77,12 @@ do
|
|||||||
ACLS_ON = false,
|
ACLS_ON = false,
|
||||||
},
|
},
|
||||||
|
|
||||||
['CVN_71'] = {
|
[BAirboss.CarrierType.ROOSEVELT] = {
|
||||||
Morse = 'RSV',
|
Morse = 'RSV',
|
||||||
|
|
||||||
|
ATC = RadioManager.RegisterChannel(261000000,RadioManager.RadioTypes.Carrier,'CVN 71'),
|
||||||
|
-- ATC = 261000000,
|
||||||
|
|
||||||
MarshalRadio = nil,
|
MarshalRadio = nil,
|
||||||
LSORadio = nil,
|
LSORadio = nil,
|
||||||
|
|
||||||
@@ -56,9 +99,12 @@ do
|
|||||||
ACLS_ON = false,
|
ACLS_ON = false,
|
||||||
},
|
},
|
||||||
|
|
||||||
['Stennis'] = {
|
[BAirboss.CarrierType.STENNIS] = {
|
||||||
Morse = 'STN',
|
Morse = 'STN',
|
||||||
|
|
||||||
|
ATC = RadioManager.RegisterChannel(264000000,RadioManager.RadioTypes.Carrier,'CVN 74'),
|
||||||
|
-- ATC = 264000000,
|
||||||
|
|
||||||
MarshalRadio = nil,
|
MarshalRadio = nil,
|
||||||
LSORadio = nil,
|
LSORadio = nil,
|
||||||
|
|
||||||
@@ -86,9 +132,12 @@ do
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
self.carrierUnit = Unit.getByName(carrierUnitName)
|
local obj = Utils.deepCopy(self)
|
||||||
|
-- local obj = {}
|
||||||
|
|
||||||
if not self.carrierUnit then
|
obj.carrierUnit = Unit.getByName(carrierUnitName)
|
||||||
|
|
||||||
|
if not obj.carrierUnit then
|
||||||
local errMsg = 'ERROR: Carrier unit %s is not found in mission.'
|
local errMsg = 'ERROR: Carrier unit %s is not found in mission.'
|
||||||
errMsg = string.format(Localizations:translate(errMsg,'cn'),carrierUnitName)
|
errMsg = string.format(Localizations:translate(errMsg,'cn'),carrierUnitName)
|
||||||
|
|
||||||
@@ -97,29 +146,32 @@ do
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
self:setMorse()
|
-- setmetatable(obj,self)
|
||||||
self:setTACAN()
|
-- self.__index = self
|
||||||
self:setICLS()
|
|
||||||
self:setLink4()
|
|
||||||
self:setACLS(true)
|
|
||||||
|
|
||||||
return self
|
timer.scheduleFunction(function (vars, time)
|
||||||
|
local carrier = vars.context
|
||||||
|
carrier:InitBeacons()
|
||||||
|
|
||||||
|
return time+20
|
||||||
|
end,{context = obj},timer.getTime()+5)
|
||||||
|
|
||||||
|
-- timer.scheduleFunction(function (vars)
|
||||||
|
-- local carrier = vars.context
|
||||||
|
-- carrier:setTACAN()
|
||||||
|
-- carrier:setICLS()
|
||||||
|
-- end,{context = obj},timer.getTime()+20)
|
||||||
|
|
||||||
|
-- obj:setMorse()
|
||||||
|
-- obj:setLink4()
|
||||||
|
-- obj:setATC()
|
||||||
|
-- obj:setTACAN()
|
||||||
|
|
||||||
|
env.info('BAirboss - New Carrier: '..carrierUnitName)
|
||||||
|
return obj
|
||||||
end
|
end
|
||||||
|
|
||||||
function BAirboss:getWindBearingAndVel(point)
|
function BAirboss.findClearPath(from,heading,range)
|
||||||
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)
|
local dest = Utils.vecTranslate(from,heading,range)
|
||||||
|
|
||||||
range = range or Utils.get2DDist(from,dest)
|
range = range or Utils.get2DDist(from,dest)
|
||||||
@@ -148,28 +200,41 @@ do
|
|||||||
return dest
|
return dest
|
||||||
end
|
end
|
||||||
|
|
||||||
function BAirboss:turnIntoWind()
|
-- @param DCS.Unit
|
||||||
|
-- @return number ex '13' for '013'
|
||||||
|
function BAirboss.getAirCraftOnBoardNumber(unit)
|
||||||
|
if not unit then return end
|
||||||
|
if unit:getLife()<1 or unit:isActive() then return end
|
||||||
|
|
||||||
|
local onBoard_num_hundred = math.floor(unit:getDrawArgumentValue(442)*10)*100
|
||||||
|
local onBoard_num_tens = math.floor(unit:getDrawArgumentValue(31)*10)*10
|
||||||
|
local onBoard_num_ones = math.floor(unit:getDrawArgumentValue(32)*10)
|
||||||
|
|
||||||
|
return onBoard_num_hundred + onBoard_num_tens + onBoard_num_ones
|
||||||
|
end
|
||||||
|
|
||||||
|
function BAirboss:turnIntoWind(Delay)
|
||||||
--Get weather data.
|
--Get weather data.
|
||||||
local CarrierPoint = self.carrierUnit:getPoint()
|
local CarrierPoint = self.carrierUnit:getPoint()
|
||||||
local windBearing, windSpeed = self:getWindBearingAndVel(CarrierPoint) -- radians & m/s
|
local windBearing, windSpeed = Utils.getWindBearingAndVel(CarrierPoint) -- radians & m/s
|
||||||
|
|
||||||
local magnetic = 7
|
local magnetic = 7
|
||||||
|
|
||||||
local carrierSpeed = 5/1.944 --m/s
|
local carrierSpeed = 5/1.944 --m/s
|
||||||
local northCorrection = mist.getNorthCorrection(CarrierPoint)
|
|
||||||
|
|
||||||
local carrierHeading = math.deg(windBearing)+180+9+magnetic
|
local carrierHeading = math.deg(windBearing)+180+9+magnetic
|
||||||
|
if windSpeed < 1 then
|
||||||
|
carrierHeading = Utils.getObjHeading(self.carrierUnit)
|
||||||
|
carrierHeading = math.deg(carrierHeading)
|
||||||
|
end
|
||||||
|
|
||||||
if carrierHeading > 360 then
|
if carrierHeading > 360 then
|
||||||
carrierHeading = carrierHeading - 360
|
carrierHeading = carrierHeading - 360
|
||||||
end
|
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.
|
--Calculate wind speed on runway in knots. If wind speed < 25 knots, try to make it 25 knots on deck.
|
||||||
if windSpeed <= 20/1.944 then
|
if windSpeed <= 20/1.944 then
|
||||||
carrierSpeed = 25/1.944-windSpeed
|
carrierSpeed = 20/1.944-windSpeed
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Find available waypoint and path.
|
-- Find available waypoint and path.
|
||||||
@@ -178,15 +243,15 @@ do
|
|||||||
local totalDistance = carrierSpeed * 6*60*60 --meters
|
local totalDistance = carrierSpeed * 6*60*60 --meters
|
||||||
|
|
||||||
local newWaypoint_1 = {
|
local newWaypoint_1 = {
|
||||||
point = BAirboss:findClearPath(CarrierPoint,carrierHeading,totalDistance),
|
point = BAirboss.findClearPath(CarrierPoint,carrierHeading,totalDistance),
|
||||||
speed = carrierSpeed
|
speed = carrierSpeed
|
||||||
}
|
}
|
||||||
local newWaypoint_2 = {
|
local newWaypoint_2 = {
|
||||||
point = BAirboss:findClearPath(newWaypoint_1.point,carrierHeading+90,totalDistance/10),
|
point = BAirboss.findClearPath(newWaypoint_1.point,carrierHeading+90,totalDistance/10),
|
||||||
speed = 10/1.944
|
speed = 10/1.944
|
||||||
}
|
}
|
||||||
local newWaypoint_3 = {
|
local newWaypoint_3 = {
|
||||||
point = BAirboss:findClearPath(newWaypoint_2.point,carrierHeading+180,Utils.get2DDist(CarrierPoint,newWaypoint_1.point)),
|
point = BAirboss.findClearPath(newWaypoint_2.point,carrierHeading+180,Utils.get2DDist(CarrierPoint,newWaypoint_1.point)),
|
||||||
speed = 27/1.944
|
speed = 27/1.944
|
||||||
}
|
}
|
||||||
local newWaypoint_4 = {
|
local newWaypoint_4 = {
|
||||||
@@ -245,12 +310,13 @@ do
|
|||||||
}
|
}
|
||||||
|
|
||||||
local Controller = self.carrierUnit:getGroup():getController()
|
local Controller = self.carrierUnit:getGroup():getController()
|
||||||
if not Controller then return end
|
if not Controller then return self end
|
||||||
|
|
||||||
|
Delay = Delay or 1
|
||||||
timer.scheduleFunction(function (Mission)
|
timer.scheduleFunction(function (Mission)
|
||||||
Controller:setTask(Mission)
|
Controller:setTask(Mission)
|
||||||
end,Mission,timer.getTime()+1)
|
end,Mission,timer.getTime()+Delay)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -259,6 +325,39 @@ do
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BAirboss:setATC(frequency,modulation,power)
|
||||||
|
frequency = frequency or BAirboss.DefaultSettings[self.carrierUnit:getTypeName()].ATC
|
||||||
|
if frequency < 1000000 then
|
||||||
|
frequency = frequency * 1000000
|
||||||
|
|
||||||
|
if frequency < 200000000 then
|
||||||
|
frequency = BAirboss.DefaultSettings[self.carrierUnit:getTypeName()].ATC
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
power = power or 1
|
||||||
|
modulation = modulation or radio.modulation.AM
|
||||||
|
|
||||||
|
local SetFrequency = {
|
||||||
|
id = 'SetFrequencyForUnit',
|
||||||
|
params = {
|
||||||
|
frequency = frequency,
|
||||||
|
modulation = modulation,
|
||||||
|
power = power,
|
||||||
|
unitId = self.carrierUnit:getID(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
local Controller = self.carrierUnit:getController()
|
||||||
|
if not Controller then
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
Controller:setCommand(SetFrequency)
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
function BAirboss:setTACAN(Channel,Mode,MorseCode)
|
function BAirboss:setTACAN(Channel,Mode,MorseCode)
|
||||||
self.TACAN = Channel or BAirboss.DefaultSettings[self.carrierUnit:getTypeName()].TACAN
|
self.TACAN = Channel or BAirboss.DefaultSettings[self.carrierUnit:getTypeName()].TACAN
|
||||||
|
|
||||||
@@ -278,7 +377,10 @@ do
|
|||||||
type = 4,
|
type = 4,
|
||||||
system = 3,
|
system = 3,
|
||||||
callsign = self.Morse,
|
callsign = self.Morse,
|
||||||
frequency = Utils.TACANToFrequency(self.TACAN, self.TACAN_Mode)
|
frequency = Utils.TACANToFrequency(self.TACAN, self.TACAN_Mode),
|
||||||
|
channel = Channel,
|
||||||
|
bearing = true,
|
||||||
|
modeChannel = Mode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,10 +466,34 @@ do
|
|||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BAirboss:InitBeacons()
|
||||||
|
|
||||||
|
self:setMorse()
|
||||||
|
self:setICLS()
|
||||||
|
self:setLink4()
|
||||||
|
self:setACLS(true)
|
||||||
|
self:setTACAN()
|
||||||
|
self:setATC()
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local Airboss_Roosevelt = BAirboss:New('USS Theodore Roosevelt')
|
local Airboss_Roosevelt = BAirboss:New('USS Theodore Roosevelt')
|
||||||
|
|
||||||
Airboss_Roosevelt:turnIntoWind()
|
Airboss_Roosevelt:turnIntoWind()
|
||||||
trigger.action.outText('Start',20)
|
|
||||||
|
local Airboss_Sten = BAirboss:New('John C. Stennis')
|
||||||
|
Airboss_Sten:turnIntoWind()
|
||||||
|
|
||||||
|
Utils.Debug("Airboss_Roosevelt: "..Airboss_Roosevelt.carrierUnit:getName())
|
||||||
|
|
||||||
|
Utils.Debug("Airboss_Sten: "..Airboss_Sten.carrierUnit:getName())
|
||||||
|
|
||||||
|
trigger.action.outText('Start BAirboss',10)
|
||||||
@@ -5,14 +5,106 @@ Localizations = {
|
|||||||
["en"] = {
|
["en"] = {
|
||||||
["ERROR: Carrier unit %s is not found in mission."] = "ERROR: Carrier unit %s is not found in mission.",
|
["ERROR: Carrier unit %s is not found in mission."] = "ERROR: Carrier unit %s is not found in mission.",
|
||||||
["world"] = "World",
|
["world"] = "World",
|
||||||
["welcome"] = "Welcome"
|
["welcome"] = "Welcome",
|
||||||
|
['Raion Info: '] = 'Raion Info: ',
|
||||||
|
['GCI'] = 'GCI',
|
||||||
|
['Tanker'] = 'Refuling tanker',
|
||||||
|
['JTAC'] = 'JTAC',
|
||||||
|
['Carrier'] = 'Carrier',
|
||||||
|
|
||||||
|
---Range
|
||||||
|
--Menu
|
||||||
|
['Range'] = 'Range',
|
||||||
|
['Refresh targets'] = 'Refresh targets',
|
||||||
|
['Settings'] = 'Settings',
|
||||||
|
--SectionNames
|
||||||
|
['Spawn targets at %s area'] = 'Spawn targets at %s area',
|
||||||
|
['Tree'] = 'Tree',
|
||||||
|
['Urban'] = 'Urban',
|
||||||
|
['Open'] = 'Open',
|
||||||
|
--TargetTypes
|
||||||
|
['Spawn %s targets'] = 'Spawn %s targets',
|
||||||
|
['Unarmed'] = 'Unarmed' ,
|
||||||
|
['Armed'] = 'Armed' ,
|
||||||
|
['AA'] = 'AA' ,
|
||||||
|
--AATypes
|
||||||
|
['AAA'] = 'AAA',
|
||||||
|
['IR'] = 'IR',
|
||||||
|
['RADAR'] = 'Radar',
|
||||||
|
['TV'] = 'TV',
|
||||||
|
['LASER'] = 'Laser',
|
||||||
|
--isMoving
|
||||||
|
['Moving targets'] = 'Moving targets',
|
||||||
|
['Stationary targets'] = 'Stationary targets',
|
||||||
|
--Fight Back
|
||||||
|
['Targets open fire: Off'] = 'Targets open fire: Off',
|
||||||
|
['Targets open fire: On'] = 'Targets open fire: On',
|
||||||
|
--AutoRespawn
|
||||||
|
['Auto Respawn Targets: On'] = 'Auto Respawn Targets: On',
|
||||||
|
['Auto Respawn Targets: Off'] = 'Auto Respawn Targets: Off',
|
||||||
|
--Message
|
||||||
|
['You have entered range area, you can sapwn targets through radio F10 menu.'] = 'You have entered range area, you can sapwn targets through radio F10 menu.',
|
||||||
|
['You have left rang area.'] = 'You have left rang area.',
|
||||||
|
['There is no range section of %s left.'] = 'There is no range section of %s left.',
|
||||||
|
['Spawn target at %s section area. targetType: %s state: %s'] = 'Spawn target at %s section area. targetType: %s state: %s',
|
||||||
|
['Spawn target at %s section area. targetType: %s AAType: %s state: %s'] = 'Spawn target at %s section area. targetType: %s AAType: %s state: %s',
|
||||||
|
['Your targets are spawned at: '] = 'Your targets are spawned at: ',
|
||||||
|
['and moving to: '] = 'and moving to: ',
|
||||||
|
['Stationary'] = 'Stationary',
|
||||||
|
['Moving'] = 'Moving',
|
||||||
},
|
},
|
||||||
|
|
||||||
--中文
|
--中文
|
||||||
["zh"] = {
|
["cn"] = {
|
||||||
["ERROR: Carrier unit %s is not found in mission."] = "错误: 在任务中没有找到航母单位 %s .",
|
["ERROR: Carrier unit %s is not found in mission."] = "错误: 在任务中没有找到航母单位 %s .",
|
||||||
["world"] = "世界",
|
["world"] = "世界",
|
||||||
["welcome"] = "欢迎"
|
["welcome"] = "欢迎",
|
||||||
|
['Raion Info: '] = "无线电信息: ",
|
||||||
|
['GCI'] = 'GCI',
|
||||||
|
['Tanker'] = '空中加油机',
|
||||||
|
['JTAC'] = 'JTAC',
|
||||||
|
['Carrier'] = '航母',
|
||||||
|
|
||||||
|
---Range
|
||||||
|
--Menu
|
||||||
|
['Range'] = '靶场',
|
||||||
|
['Refresh targets'] = '刷新目标',
|
||||||
|
['Settings'] = '设置',
|
||||||
|
--SectionNames
|
||||||
|
['Spawn targets at %s area'] = '在 %s 区域生成目标',
|
||||||
|
['Tree'] = '树林',
|
||||||
|
['Urban'] = '城市',
|
||||||
|
['Open'] = '开阔地',
|
||||||
|
--TargetTypes
|
||||||
|
['Spawn %s targets'] = '生成 %s 目标',
|
||||||
|
['Unarmed'] = '无武装' ,
|
||||||
|
['Armed'] = '武装' ,
|
||||||
|
['AA'] = '防空' ,
|
||||||
|
--AATypes
|
||||||
|
['AAA'] = '自行防空炮',
|
||||||
|
['IR'] = '红外制导',
|
||||||
|
['Radar'] = '雷达制导',
|
||||||
|
['TV'] = '电视制导',
|
||||||
|
['Laser'] = '激光制导',
|
||||||
|
--isMoving
|
||||||
|
['Moving targets'] = '移动的目标',
|
||||||
|
['Stationary targets'] = '静止的目标',
|
||||||
|
--Fight Back
|
||||||
|
['Targets open fire: Off'] = '目标会反击: 关',
|
||||||
|
['Targets open fire: On'] = '目标会反击: 开',
|
||||||
|
--AutoRespawn
|
||||||
|
['Auto Respawn Targets: On'] = '目标自动重生: 开',
|
||||||
|
['Auto Respawn Targets: Off'] = '目标自动重生: 关',
|
||||||
|
--Message
|
||||||
|
['You have entered range area, you can sapwn targets through radio F10 menu.'] = '你已经进入靶场区域, 可以通过无线电F10菜单选择生成目标.',
|
||||||
|
['You have left rang area.'] = '你已经离开靶场区域.',
|
||||||
|
['There is no range section of %s left.'] = '没有 %s 类型靶场空闲了.',
|
||||||
|
['Spawn target at %s section area. targetType: %s state: %s'] = '在 %s 区域刷新目标. 目标类型: %s 状态: %s',
|
||||||
|
['Spawn target at %s section area. targetType: %s AAType: %s state: %s'] = '在 %s 区域 刷新目标. 目标类型: %s 防空类型: %s 状态: %s',
|
||||||
|
['Your targets are spawned at: '] = '你的目标刷新在: ',
|
||||||
|
['and moving to: '] = '并且将要移动到: ',
|
||||||
|
['Stationary'] = '静止目标',
|
||||||
|
['Moving'] = '运动目标',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ local script_list =
|
|||||||
{
|
{
|
||||||
-- Load order must be correct
|
-- Load order must be correct
|
||||||
-- "mist.lua", --mist_4_5_122
|
-- "mist.lua", --mist_4_5_122
|
||||||
"Moose_.lua",
|
-- "Moose_.lua",
|
||||||
'mist_4_5_126.lua',
|
'mist_4_5_126.lua',
|
||||||
'Localizations.lua',
|
'Localizations.lua',
|
||||||
'Utils.lua',
|
'Utils.lua',
|
||||||
-- "spawnListener.lua",
|
-- "spawnListener.lua",
|
||||||
|
"RadioManager.lua",
|
||||||
"Buta's_Airboss.lua",
|
"Buta's_Airboss.lua",
|
||||||
|
"Range.lua",
|
||||||
-- "Airboss[CN].lua",
|
-- "Airboss[CN].lua",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,239 @@
|
|||||||
|
RadioManager = {
|
||||||
|
drawMarkID = Utils.getMarkID(),
|
||||||
|
|
||||||
|
ChannelList = {},
|
||||||
|
ChannelInterval = 0.025,
|
||||||
|
|
||||||
|
DefaultPublic = {
|
||||||
|
['UHF'] = 251,
|
||||||
|
['VHF'] = 130,
|
||||||
|
},
|
||||||
|
RubbishChannel = 159.975,
|
||||||
|
|
||||||
|
['UHF'] = {
|
||||||
|
min = 200,
|
||||||
|
max = 399.975,
|
||||||
|
},
|
||||||
|
|
||||||
|
['VHF'] = {
|
||||||
|
min = 30,
|
||||||
|
max = 159.950,
|
||||||
|
},
|
||||||
|
|
||||||
|
RadioTypes = {
|
||||||
|
GCI = 'GCI',
|
||||||
|
Tanker = 'Tanker',
|
||||||
|
JTAC = 'JTAC',
|
||||||
|
Carrier = 'Carrier',
|
||||||
|
},
|
||||||
|
|
||||||
|
SpecialRadioRange = {
|
||||||
|
['GCI'] = {
|
||||||
|
min = 250,
|
||||||
|
max = 259,
|
||||||
|
},
|
||||||
|
['Tanker'] = {
|
||||||
|
min = 330,
|
||||||
|
max = 339,
|
||||||
|
},
|
||||||
|
['JTAC'] = {
|
||||||
|
min = 30,
|
||||||
|
max = 39,
|
||||||
|
},
|
||||||
|
['Carrier'] = {
|
||||||
|
min = 260,
|
||||||
|
max = 269,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
local Mhz = 1000000
|
||||||
|
|
||||||
|
-- Init Channel List.
|
||||||
|
for i=RadioManager.UHF.min,RadioManager.UHF.max,RadioManager.ChannelInterval do
|
||||||
|
i = math.floor(i*1000+0.5)/1000
|
||||||
|
|
||||||
|
local isPublic = false
|
||||||
|
local UserCallsign = nil
|
||||||
|
if i==RadioManager.DefaultPublic.UHF then
|
||||||
|
isPublic = true
|
||||||
|
UserCallsign = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local special = false
|
||||||
|
for specialType, range in pairs(RadioManager.SpecialRadioRange) do
|
||||||
|
if i >= range.min and i <= range.max then
|
||||||
|
special = specialType
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
RadioManager.ChannelList[i] = {
|
||||||
|
used = false,
|
||||||
|
isPublic = isPublic,
|
||||||
|
UserCallsign = UserCallsign,
|
||||||
|
special = special,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
for i=RadioManager.VHF.min,RadioManager.VHF.max,RadioManager.ChannelInterval do
|
||||||
|
i = math.floor(i*1000+0.5)/1000
|
||||||
|
|
||||||
|
local isPublic = false
|
||||||
|
local UserCallsign = nil
|
||||||
|
if i==RadioManager.DefaultPublic.VHF then
|
||||||
|
isPublic = true
|
||||||
|
UserCallsign = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local special = false
|
||||||
|
for specialType, range in pairs(RadioManager.SpecialRadioRange) do
|
||||||
|
if i >= range.min and i <= range.max then
|
||||||
|
special = specialType
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
RadioManager.ChannelList[i] = {
|
||||||
|
used = false,
|
||||||
|
isPublic = isPublic,
|
||||||
|
UserCallsign = UserCallsign,
|
||||||
|
special = special,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Register function.
|
||||||
|
function RadioManager.RegisterChannel(channel,radioType,UserCallsign)
|
||||||
|
if not channel then return end
|
||||||
|
if channel < 0 then return RadioManager.RubbishChannel*Mhz end
|
||||||
|
|
||||||
|
-- Serializer
|
||||||
|
radioType = radioType or 'none'
|
||||||
|
|
||||||
|
if channel > RadioManager.UHF.max and channel >= Mhz then
|
||||||
|
channel = math.floor(channel/Mhz*1000+0.5)/1000
|
||||||
|
end
|
||||||
|
|
||||||
|
local channelType = 'UHF'
|
||||||
|
if channel < RadioManager.UHF.min then
|
||||||
|
channelType = 'VHF'
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 如果申请频道不在UHF 和 VHF 范围之内, 则分配为默认公开频道.
|
||||||
|
if type(RadioManager.ChannelList[channel]) ~= 'table' then
|
||||||
|
channel = RadioManager.DefaultPublic[channelType]
|
||||||
|
if radioType then
|
||||||
|
channel = RadioManager.SpecialRadioRange[radioType].min
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 如果申请频道在 UHF 或 VHF 范围之内.
|
||||||
|
local assignedChannel = channel
|
||||||
|
if RadioManager.ChannelList[channel] then
|
||||||
|
if RadioManager.ChannelList[channel].used then -- 如果频道被占用
|
||||||
|
assignedChannel = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if not RadioManager.ChannelList[channel].used then -- 如果频道无占用
|
||||||
|
local isSpecial = RadioManager.ChannelList[channel].special or 'none'
|
||||||
|
if isSpecial ~= radioType then
|
||||||
|
assignedChannel = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if assignedChannel == nil then
|
||||||
|
local range = RadioManager.SpecialRadioRange[radioType] or RadioManager[channelType]
|
||||||
|
|
||||||
|
for i=range.min,range.max,RadioManager.ChannelInterval do
|
||||||
|
i = math.floor(i*1000+0.5)/1000
|
||||||
|
|
||||||
|
local status = RadioManager.ChannelList[i]
|
||||||
|
|
||||||
|
if not status.used then
|
||||||
|
local isSpecial = status.special or 'none'
|
||||||
|
|
||||||
|
if isSpecial == radioType then
|
||||||
|
assignedChannel = i
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assignedChannel = assignedChannel or RadioManager.DefaultPublic[channelType]
|
||||||
|
RadioManager.ChannelList[assignedChannel].used = true
|
||||||
|
|
||||||
|
if not RadioManager.ChannelList[assignedChannel].isPublic then
|
||||||
|
RadioManager.ChannelList[assignedChannel].UserCallsign = UserCallsign
|
||||||
|
end
|
||||||
|
|
||||||
|
if RadioManager.ChannelList[assignedChannel].isPublic then
|
||||||
|
table.insert(RadioManager.ChannelList[assignedChannel].UserCallsign,UserCallsign)
|
||||||
|
end
|
||||||
|
|
||||||
|
return assignedChannel*Mhz
|
||||||
|
end
|
||||||
|
|
||||||
|
function RadioManager:getRadioByName(name)
|
||||||
|
--TODO
|
||||||
|
end
|
||||||
|
|
||||||
|
function RadioManager:drawMapMessageBox()
|
||||||
|
local drawPoint = {
|
||||||
|
x=-417751.093772,
|
||||||
|
y=1,
|
||||||
|
z=177329.42204673,
|
||||||
|
}
|
||||||
|
|
||||||
|
local text = Localizations:translate('Raion Info: ','cn')
|
||||||
|
|
||||||
|
Utils.Debug(RadioManager.ChannelList[264])
|
||||||
|
for radioType, value in pairs(RadioManager.RadioTypes) do
|
||||||
|
Utils.Debug(value)
|
||||||
|
local result = false
|
||||||
|
|
||||||
|
for i = RadioManager.SpecialRadioRange[value].min,RadioManager.SpecialRadioRange[value].max,RadioManager.ChannelInterval do
|
||||||
|
i = math.floor(i*1000+0.5)/1000
|
||||||
|
|
||||||
|
if RadioManager.ChannelList[i].used then
|
||||||
|
local data = {
|
||||||
|
channel = i,
|
||||||
|
UserCallsign = RadioManager.ChannelList[i].UserCallsign or 'no Callsign'
|
||||||
|
}
|
||||||
|
result = result or {}
|
||||||
|
table.insert(result,data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Utils.Debug(result)
|
||||||
|
if result then
|
||||||
|
text = text..'\n'..(Localizations:translate(value,'cn'))..': '
|
||||||
|
for i,data in ipairs(result) do
|
||||||
|
text = text..'\n'..data.channel..'Mhz: '
|
||||||
|
|
||||||
|
local UserCallsign = data.UserCallsign
|
||||||
|
if type(UserCallsign) == 'table' then
|
||||||
|
if #UserCallsign >0 then
|
||||||
|
Utils.Debug(UserCallsign)
|
||||||
|
for i, callsign in ipairs(UserCallsign) do
|
||||||
|
text = text..callsign..' '
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(UserCallsign) == 'string' then
|
||||||
|
text = text..UserCallsign
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
trigger.action.textToAll(-1,RadioManager.drawMarkID, drawPoint, {1,1,0,1}, {0,0,0,0.32}, 19 , false, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- timer.scheduleFunction(function ()
|
||||||
|
-- RadioManager:drawMapMessageBox()
|
||||||
|
-- end,nil,timer.getTime()+5)
|
||||||
|
end
|
||||||
@@ -0,0 +1,760 @@
|
|||||||
|
--[[
|
||||||
|
24.13.31.1714
|
||||||
|
TODO:
|
||||||
|
- finish Range:activeTartgets() done
|
||||||
|
- add function Range:addTargetPreset(group/groupName,targetType) done
|
||||||
|
- add function Range:RemoveTargetPreset(group/groupName,targetType) done
|
||||||
|
|
||||||
|
TODO: 25.1.2.1941
|
||||||
|
- Test bugs for Range. Current: spawning and refreshing and autoRespawn are working fine.
|
||||||
|
]]
|
||||||
|
|
||||||
|
|
||||||
|
Range = {
|
||||||
|
MonitorRepeatTime = 5, --Seconds
|
||||||
|
MonitorID = nil,
|
||||||
|
|
||||||
|
PlayerCanDriveTarget = false,
|
||||||
|
|
||||||
|
points = {},
|
||||||
|
name = nil,
|
||||||
|
|
||||||
|
sectionTypes = {
|
||||||
|
Tree = 'Tree',
|
||||||
|
Urban = 'Urban',
|
||||||
|
Open = 'Open',
|
||||||
|
},
|
||||||
|
|
||||||
|
targetTypes = {
|
||||||
|
Unarmed = 'Unarmed',
|
||||||
|
Armed = 'Armed',
|
||||||
|
AA = 'AA',
|
||||||
|
},
|
||||||
|
|
||||||
|
AATypes = {
|
||||||
|
AAA = 'AAA',
|
||||||
|
IR = 'IR',
|
||||||
|
RADAR = 'Radar',
|
||||||
|
TV = 'TV',
|
||||||
|
-- LASER = 'Laser',
|
||||||
|
-- TELE = 'Tele',
|
||||||
|
},
|
||||||
|
|
||||||
|
targetPresets = {},
|
||||||
|
|
||||||
|
sections = {},
|
||||||
|
|
||||||
|
playerList = {},
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
|
||||||
|
function Range:New(zoneName)
|
||||||
|
local points = Utils.getWayPoints(zoneName)
|
||||||
|
if not points then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local self = Utils.deepCopy(self)
|
||||||
|
|
||||||
|
self.name = zoneName
|
||||||
|
self.points = points
|
||||||
|
|
||||||
|
Utils.drawPolygon(-1,Utils.getMarkID(),points,{0,1,1,1},{0,1,0,0},2)
|
||||||
|
local dangerZonePoints = Utils.getWayPoints(zoneName..'-1')
|
||||||
|
if dangerZonePoints then
|
||||||
|
Utils.drawPolygon(-1,Utils.getMarkID(),dangerZonePoints,{1,0,0,1},{1,0,0,0},2)
|
||||||
|
end
|
||||||
|
|
||||||
|
for type, value in pairs(self.sectionTypes) do
|
||||||
|
for j=1,100,1 do
|
||||||
|
local sectionName = string.format('%s-%s-%d',zoneName,value,j)
|
||||||
|
|
||||||
|
points = Utils.getWayPoints(sectionName)
|
||||||
|
if not points then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
--Debug
|
||||||
|
-- self.drawPolygon(points)
|
||||||
|
-- trigger.action.textToAll(-1,Utils.getMarkID(),Utils.makeVec3(points[1]),{1,1,1,1},{0,0,0,0},8,false,sectionName)
|
||||||
|
|
||||||
|
local sectionData = {
|
||||||
|
name = sectionName,
|
||||||
|
points = points,
|
||||||
|
active = false,
|
||||||
|
}
|
||||||
|
self.sections[value] = self.sections[value] or {}
|
||||||
|
table.insert(self.sections[value],sectionData)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function Range._MonitorFunction(vars,time)
|
||||||
|
local self = vars.context
|
||||||
|
local repeatTime = vars.repeatTime
|
||||||
|
|
||||||
|
local playerUnitList = coalition.getPlayers(coalition.side.BLUE)
|
||||||
|
for i, playerUnit in ipairs(playerUnitList) do
|
||||||
|
|
||||||
|
local PlayerName = playerUnit:getPlayerName()
|
||||||
|
if PlayerName then
|
||||||
|
local playerPoint = playerUnit:getPoint()
|
||||||
|
|
||||||
|
local unitInRangeZone = Utils.pointInPolygon(playerPoint,self.points)
|
||||||
|
if unitInRangeZone then
|
||||||
|
self:createPlayerProfile(playerUnit)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
for playerName, data in pairs(self.playerList) do
|
||||||
|
if not data.group:isExist() then
|
||||||
|
self:removePlayerProfile(playerName)
|
||||||
|
end
|
||||||
|
|
||||||
|
if data.group:isExist() then
|
||||||
|
local playerUnit = data.group:getUnit(1)
|
||||||
|
if playerUnit then
|
||||||
|
local playerPoint = data.group:getUnit(1):getPoint()
|
||||||
|
if not Utils.pointInPolygon(playerPoint,self.points) then
|
||||||
|
self.removePlayerProfile(playerName)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not playerUnit then
|
||||||
|
self.removePlayerProfile(playerName)
|
||||||
|
end
|
||||||
|
|
||||||
|
if data.activeTarget then
|
||||||
|
if data.activeTarget:isExist() then
|
||||||
|
local isAlive = false
|
||||||
|
for i,unit in ipairs(data.activeTarget:getUnits()) do
|
||||||
|
if unit:getLife() >= 1 then
|
||||||
|
isAlive = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not isAlive then
|
||||||
|
if data.autoRespawn then
|
||||||
|
local sectionType = data.targetData.sectionType
|
||||||
|
local targetType = data.targetData.targetType
|
||||||
|
local AAType = data.targetData.AAType
|
||||||
|
local isMove = data.targetData.isMove
|
||||||
|
self:activeTartgets(playerName,sectionType,targetType,AAType,isMove)
|
||||||
|
end
|
||||||
|
if not data.autoRespawn then
|
||||||
|
self:deactivateTargets(playerName)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not data.activeTarget:isExist() then
|
||||||
|
if data.autoRespawn then
|
||||||
|
local sectionType = data.targetData.sectionType
|
||||||
|
local targetType = data.targetData.targetType
|
||||||
|
local AAType = data.targetData.AAType
|
||||||
|
local isMove = data.targetData.isMove
|
||||||
|
self:activeTartgets(playerName,sectionType,targetType,AAType,isMove)
|
||||||
|
end
|
||||||
|
|
||||||
|
if not data.autoRespawn then
|
||||||
|
self:deactivateTargets(playerName)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- --Debug
|
||||||
|
-- for sectionType,sections in pairs(self.sections) do
|
||||||
|
-- for i, section in ipairs(sections) do
|
||||||
|
-- local text = 'not active'
|
||||||
|
-- if section.active then
|
||||||
|
-- text = 'active'
|
||||||
|
-- end
|
||||||
|
|
||||||
|
-- local point = {
|
||||||
|
-- x = section.points[1].x,
|
||||||
|
-- y = 0,
|
||||||
|
-- z = section.points[1].y,
|
||||||
|
-- }
|
||||||
|
-- if not section.tagID then
|
||||||
|
-- section.tagID = Utils.getMarkID()
|
||||||
|
-- trigger.action.textToAll(-1,section.tagID,point,{1,1,0,1},{0,0,0,0},12,false,text)
|
||||||
|
-- end
|
||||||
|
|
||||||
|
-- trigger.action.setMarkupText(section.tagID,text)
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
|
||||||
|
|
||||||
|
return time+repeatTime
|
||||||
|
end
|
||||||
|
|
||||||
|
function Range:start(Delay,RepeatScanSeconds)
|
||||||
|
local tDelay = Delay or 1
|
||||||
|
local RepeatScanInterval = RepeatScanSeconds or Range.MonitorRepeatTime
|
||||||
|
|
||||||
|
if self.MonitorID then
|
||||||
|
self:stop()
|
||||||
|
end
|
||||||
|
|
||||||
|
self.MonitorID = timer.scheduleFunction(self._MonitorFunction,{context = self,repeatTime = RepeatScanInterval},timer.getTime() + tDelay)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Range:stop()
|
||||||
|
timer.removeFunction(self.MonitorID)
|
||||||
|
self.MonitorID = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function Range:createMenu(playerGroup)
|
||||||
|
if not playerGroup then return end
|
||||||
|
|
||||||
|
local groupID = playerGroup:getID()
|
||||||
|
if not groupID then return end
|
||||||
|
|
||||||
|
local playerUnit = playerGroup:getUnit(1)
|
||||||
|
if not playerUnit then return end
|
||||||
|
if not playerUnit:isActive() then return end
|
||||||
|
|
||||||
|
local playerName = playerUnit:getPlayerName()
|
||||||
|
if self.playerList[playerName] then
|
||||||
|
if self.playerList[playerName].menu then
|
||||||
|
missionCommands.removeItemForGroup(groupID,self.playerList[playerName].menu)
|
||||||
|
self.playerList[playerName].menu = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local MainMenuName = Localizations:translate('Range','cn')
|
||||||
|
local menu = missionCommands.addSubMenuForGroup(groupID,MainMenuName)
|
||||||
|
|
||||||
|
for sectionType, data in pairs(self.sections) do
|
||||||
|
local subMenuName_Section = string.format(Localizations:translate('Spawn targets at %s area','cn'),Localizations:translate(sectionType,'cn'))
|
||||||
|
local subMenu_Section = missionCommands.addSubMenuForGroup(groupID,subMenuName_Section,menu)
|
||||||
|
|
||||||
|
for key,targetType in pairs(self.targetTypes) do
|
||||||
|
if self.targetPresets[targetType] then
|
||||||
|
local subMenuName_TargetType = string.format(Localizations:translate('Spawn %s targets','cn'),Localizations:translate(targetType,'cn'))
|
||||||
|
local subMenu_TargetType = missionCommands.addSubMenuForGroup(groupID,subMenuName_TargetType,subMenu_Section)
|
||||||
|
|
||||||
|
if targetType == self.targetTypes.AA then
|
||||||
|
for k,AAType in pairs(self.AATypes) do
|
||||||
|
if self.targetPresets[targetType][AAType] then
|
||||||
|
local subMenuName_AAType = string.format(Localizations:translate('Spawn %s targets','cn'),Localizations:translate(AAType,'cn'))
|
||||||
|
local subMenu_AAType = missionCommands.addSubMenuForGroup(groupID,subMenuName_AAType,subMenu_TargetType)
|
||||||
|
|
||||||
|
local subMenuName_Move = Localizations:translate('Moving targets','cn')
|
||||||
|
missionCommands.addCommandForGroup(groupID,subMenuName_Move,subMenu_AAType,function (vars)
|
||||||
|
local self = vars.context
|
||||||
|
self:activeTartgets(vars.playerName,vars.section,vars.targetType,vars.AAType,vars.Move)
|
||||||
|
end,{context = self,playerName = playerName,section = sectionType,targetType = targetType,AAType = AAType,Move = true})
|
||||||
|
|
||||||
|
local subMenuName_Stationary = Localizations:translate('Stationary targets','cn')
|
||||||
|
missionCommands.addCommandForGroup(groupID,subMenuName_Stationary,subMenu_AAType,function (vars)
|
||||||
|
local self = vars.context
|
||||||
|
self:activeTartgets(vars.playerName,vars.section,vars.targetType,vars.AAType,vars.Move)
|
||||||
|
end,{context = self,playerName = playerName,section = sectionType,targetType = targetType,AAType = AAType,Move = false})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if targetType ~= self.targetTypes.AA then
|
||||||
|
local subMenuName_Move = Localizations:translate('Moving targets','cn')
|
||||||
|
missionCommands.addCommandForGroup(groupID,subMenuName_Move,subMenu_TargetType,function (vars)
|
||||||
|
local self = vars.context
|
||||||
|
self:activeTartgets(vars.playerName,vars.section,vars.targetType,vars.AAType,vars.Move)
|
||||||
|
end,{context = self,playerName = playerName,section = sectionType,targetType = targetType,AAType = nil,Move = true})
|
||||||
|
|
||||||
|
local subMenuName_Stationary = Localizations:translate('Stationary targets','cn')
|
||||||
|
missionCommands.addCommandForGroup(groupID,subMenuName_Stationary,subMenu_TargetType,function (vars)
|
||||||
|
local self = vars.context
|
||||||
|
self:activeTartgets(vars.playerName,vars.section,vars.targetType,vars.AAType,vars.Move)
|
||||||
|
end,{context = self,playerName = playerName,section = sectionType,targetType = targetType,AAType = nil,Move = false})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.playerList[playerName] then
|
||||||
|
if self.playerList[playerName].targetData then
|
||||||
|
local refreshMenuName = string.format('[%s]',Localizations:translate('Refresh targets','cn'))
|
||||||
|
missionCommands.addCommandForGroup(groupID,refreshMenuName,menu,function (vars)
|
||||||
|
local self = vars.context
|
||||||
|
local targetData = self.playerList[playerName].targetData
|
||||||
|
self:activeTartgets(vars.playerName,targetData.sectionType,targetData.targetType,targetData.AAType,targetData.isMove)
|
||||||
|
end,{context = self,playerName = playerName})
|
||||||
|
end
|
||||||
|
|
||||||
|
local switch = 'Off'
|
||||||
|
|
||||||
|
if self.playerList[playerName].isTargerRedAlert then
|
||||||
|
switch = 'On'
|
||||||
|
end
|
||||||
|
|
||||||
|
local SettingsMenuName = Localizations:translate('Settings','cn')
|
||||||
|
local SettingsMenu = missionCommands.addSubMenuForGroup(groupID,SettingsMenuName,menu)
|
||||||
|
|
||||||
|
local FightBackSwitchName = Localizations:translate(string.format('Targets open fire: %s',switch),'cn')
|
||||||
|
missionCommands.addCommandForGroup(groupID,FightBackSwitchName,SettingsMenu,function (vars)
|
||||||
|
local self = vars.context
|
||||||
|
self:setTargetFightBack(vars.playerGroup)
|
||||||
|
end,{context = self,playerGroup = playerGroup})
|
||||||
|
|
||||||
|
switch = 'Off'
|
||||||
|
if self.playerList[playerName].autoRespawn then
|
||||||
|
switch = 'On'
|
||||||
|
end
|
||||||
|
local AutoRespawnSwitchName = Localizations:translate(string.format('Auto Respawn Targets: %s',switch),'cn')
|
||||||
|
missionCommands.addCommandForGroup(groupID,AutoRespawnSwitchName,SettingsMenu,function (vars)
|
||||||
|
local self = vars.context
|
||||||
|
self:setTargetAutoRespawn(vars.playerGroup)
|
||||||
|
end,{context = self,playerGroup = playerGroup})
|
||||||
|
end
|
||||||
|
|
||||||
|
self.playerList[playerName].menu = menu
|
||||||
|
return menu
|
||||||
|
end
|
||||||
|
|
||||||
|
function Range:createPlayerProfile(playerUnit)
|
||||||
|
if not playerUnit then return end
|
||||||
|
|
||||||
|
local PlayerName = playerUnit:getPlayerName()
|
||||||
|
if self.playerList[PlayerName] then return end
|
||||||
|
|
||||||
|
local playerGroup = playerUnit:getGroup()
|
||||||
|
if not playerGroup then return end
|
||||||
|
|
||||||
|
self.playerList[PlayerName] = {
|
||||||
|
group = playerGroup,
|
||||||
|
groupID = playerGroup:getID(),
|
||||||
|
autoRespawn = false,
|
||||||
|
isTargerRedAlert = false,
|
||||||
|
activeTarget = nil,
|
||||||
|
targetData = nil,
|
||||||
|
assignedSection = nil,
|
||||||
|
menu = nil,
|
||||||
|
}
|
||||||
|
self:createMenu(playerGroup)
|
||||||
|
|
||||||
|
local enterText = Localizations:translate('You have entered range area, you can sapwn targets through radio F10 menu.','cn')
|
||||||
|
trigger.action.outTextForGroup(playerGroup:getID(),enterText,10)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Range:removePlayerProfile(playerName)
|
||||||
|
if not playerName then return end
|
||||||
|
|
||||||
|
if not self.playerList[playerName] then return end
|
||||||
|
|
||||||
|
self:deactivateTargets(playerName)
|
||||||
|
missionCommands.removeItemForGroup(self.playerList[playerName].groupID,self.playerList[playerName].menu)
|
||||||
|
|
||||||
|
self.playerList[playerName] = nil
|
||||||
|
|
||||||
|
-- local leaveText = Localizations:translate('You have left rang area.','cn')
|
||||||
|
|
||||||
|
-- if self.playerList[playerName].group:isExist() then
|
||||||
|
-- trigger.action.outTextForGroup(self.playerList[playerName].groupID,leaveText,10)
|
||||||
|
-- end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Range:activeTartgets(playerName,sectionType,targetType,AAType,Move)
|
||||||
|
if not sectionType then return end
|
||||||
|
if not targetType then return end
|
||||||
|
|
||||||
|
AAType = AAType
|
||||||
|
Move = Move or false
|
||||||
|
|
||||||
|
self:deactivateTargets(playerName)
|
||||||
|
|
||||||
|
--Send message
|
||||||
|
local isMove = Localizations:translate('Stationary','cn')
|
||||||
|
if Move then
|
||||||
|
isMove = Localizations:translate('Moving','cn')
|
||||||
|
end
|
||||||
|
|
||||||
|
local baseText = Localizations:translate('Spawn target at %s section area. targetType: %s state: %s','cn')
|
||||||
|
local tSectionType = Localizations:translate(sectionType,'cn')
|
||||||
|
local ttargetType = Localizations:translate(targetType,'cn')
|
||||||
|
local messageText = string.format(baseText,tSectionType,ttargetType,isMove)
|
||||||
|
if AAType then
|
||||||
|
baseText = Localizations:translate('Spawn target at %s section area. targetType: %s AAType: %s state: %s','cn')
|
||||||
|
local tAAtype = Localizations:translate(AAType,'cn')
|
||||||
|
messageText = string.format(baseText,tSectionType,ttargetType,tAAtype,isMove)
|
||||||
|
end
|
||||||
|
trigger.action.outTextForGroup(self.playerList[playerName].groupID,messageText,10)
|
||||||
|
|
||||||
|
--Get sectionZone
|
||||||
|
local sectionZone = self.playerList[playerName].assignedSection or nil
|
||||||
|
if not sectionZone or (not self.playerList[playerName].targetData.sectionType) or (self.playerList[playerName].targetData.sectionType ~= sectionType) then
|
||||||
|
for i=1,#self.sections[sectionType],1 do
|
||||||
|
local zoneNum = math.random(1,#self.sections[sectionType])
|
||||||
|
if not self.sections[sectionType][zoneNum].active then
|
||||||
|
sectionZone = self.sections[sectionType][zoneNum]
|
||||||
|
|
||||||
|
if not Move then
|
||||||
|
self.sections[sectionType][zoneNum].active = true
|
||||||
|
end
|
||||||
|
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not sectionZone then
|
||||||
|
for i=1,#self.sections[sectionType],1 do
|
||||||
|
if not self.sections[sectionType][i].active then
|
||||||
|
sectionZone = self.sections[sectionType][i]
|
||||||
|
|
||||||
|
if not Move then
|
||||||
|
self.sections[sectionType][i].active = true
|
||||||
|
end
|
||||||
|
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not sectionZone then
|
||||||
|
trigger.action.outTextForGroup(string.format(Localizations:translate('There is no range section of %s left.','cn'),Localizations:translate(sectionType,'cn')),10)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
self.playerList[playerName].targetData = {
|
||||||
|
sectionType = sectionType,
|
||||||
|
targetType = targetType,
|
||||||
|
AAType = AAType,
|
||||||
|
isMove = Move,
|
||||||
|
}
|
||||||
|
-- self.playerList[playerName].assignedSection = sectionZone.name
|
||||||
|
self.playerList[playerName].assignedSection = sectionZone
|
||||||
|
end
|
||||||
|
|
||||||
|
--Get targets(typeNames)
|
||||||
|
local groupData = {
|
||||||
|
name = playerName..'_target',
|
||||||
|
task = "Ground Nothing",
|
||||||
|
units = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
local targetList = self.targetPresets[targetType]
|
||||||
|
if AAType then
|
||||||
|
targetList = self.targetPresets[targetType][AAType]
|
||||||
|
end
|
||||||
|
|
||||||
|
for i=1,6,1 do
|
||||||
|
local randomNum = math.random(1,#targetList)
|
||||||
|
groupData.units[i] = {}
|
||||||
|
groupData.units[i].name = groupData.name..'-'..i
|
||||||
|
groupData.units[i].type = targetList[randomNum]
|
||||||
|
groupData.units[i].heading = math.rad(math.random(0,359))
|
||||||
|
groupData.units[i].skill = AI.Skill.EXCELLENT
|
||||||
|
groupData.units[i].playerCanDrive = self.PlayerCanDriveTarget
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get spawn points
|
||||||
|
local centerPoint = nil
|
||||||
|
for i=1,100,1 do
|
||||||
|
local tPoint = Utils.getRandomPointInPoly(sectionZone.points)
|
||||||
|
if land.getSurfaceType(tPoint) ~= land.SurfaceType.WATER or land.getSurfaceType(tPoint) ~= land.SurfaceType.SHALLOW_WATER then
|
||||||
|
centerPoint = tPoint
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not centerPoint then
|
||||||
|
local tHeading = Utils.getDir(sectionZone.points[1],sectionZone.points[math.random(2,#sectionZone.points)])
|
||||||
|
centerPoint = Utils.vecTranslate(sectionZone.points[1],tHeading,200)
|
||||||
|
end
|
||||||
|
groupData.units[1].x = centerPoint.x
|
||||||
|
groupData.units[1].y = centerPoint.z or centerPoint.y
|
||||||
|
|
||||||
|
for k=2,#groupData.units,1 do
|
||||||
|
local tDir = math.random(0,359)
|
||||||
|
local spawnPoint = {}
|
||||||
|
spawnPoint.x = centerPoint.x+200
|
||||||
|
spawnPoint.y = centerPoint.z or centerPoint.y
|
||||||
|
|
||||||
|
for i=1,100,1 do
|
||||||
|
local tPoint = Utils.vecTranslate(centerPoint,tDir,math.random(100,1000)) --Spawn range
|
||||||
|
if Utils.pointInPolygon(tPoint,sectionZone.points) then
|
||||||
|
if land.getSurfaceType(tPoint) ~= land.SurfaceType.WATER or land.getSurfaceType(tPoint) ~= land.SurfaceType.SHALLOW_WATER then
|
||||||
|
spawnPoint = tPoint
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
groupData.units[k].x = spawnPoint.x
|
||||||
|
groupData.units[k].y = spawnPoint.z or spawnPoint.y
|
||||||
|
end
|
||||||
|
|
||||||
|
--Spawn group
|
||||||
|
local targetGroup = coalition.addGroup(country.id.CJTF_RED,Group.Category.GROUND,groupData)
|
||||||
|
if not targetGroup then return end
|
||||||
|
|
||||||
|
self.playerList[playerName].activeTarget = targetGroup
|
||||||
|
|
||||||
|
local Controller = targetGroup:getController()
|
||||||
|
if not Controller then return end
|
||||||
|
|
||||||
|
local targetPointReport = Localizations:translate('Your targets are spawned at: ','cn')
|
||||||
|
--Set Moving
|
||||||
|
if Move then
|
||||||
|
local startPoint = {}
|
||||||
|
startPoint.x, startPoint.y= land.getClosestPointOnRoads('roads',centerPoint.x,(centerPoint.z or centerPoint.y))
|
||||||
|
local finZonePoint = self.sections[sectionType][math.random(1,#self.sections[sectionType])].points[1]
|
||||||
|
local finPoint = {}
|
||||||
|
finPoint.x,finPoint.y = land.getClosestPointOnRoads('roads',finZonePoint.x,(finZonePoint.z or finZonePoint.y))
|
||||||
|
local speed = math.random(5/1.944,15/1.944)
|
||||||
|
local Mission = {
|
||||||
|
id = 'Mission',
|
||||||
|
params = {
|
||||||
|
route = {
|
||||||
|
points = {
|
||||||
|
[1] = {
|
||||||
|
x = startPoint.x,
|
||||||
|
y = startPoint.z or startPoint.y,
|
||||||
|
speed = speed,
|
||||||
|
type = AI.Task.WaypointType.TURNING_POINT,
|
||||||
|
action = AI.Task.VehicleFormation.ON_ROAD,
|
||||||
|
},
|
||||||
|
[2] = {
|
||||||
|
x = finPoint.x,
|
||||||
|
y = finPoint.z or finPoint.y,
|
||||||
|
speed = speed,
|
||||||
|
type = AI.Task.WaypointType.TURNING_POINT,
|
||||||
|
action = AI.Task.VehicleFormation.ON_ROAD,
|
||||||
|
|
||||||
|
},
|
||||||
|
[3] = {
|
||||||
|
x = startPoint.x,
|
||||||
|
y = startPoint.z or startPoint.y,
|
||||||
|
speed = speed,
|
||||||
|
type = AI.Task.WaypointType.TURNING_POINT,
|
||||||
|
action = AI.Task.VehicleFormation.ON_ROAD,
|
||||||
|
task = {
|
||||||
|
id = 'ComboTask',
|
||||||
|
params = {
|
||||||
|
[1] = {
|
||||||
|
id = 'goToWaypoint',
|
||||||
|
params = {
|
||||||
|
fromWaypointIndex = 3,
|
||||||
|
goToWaypointIndex = 1,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local lat, lon, alt = coord.LOtoLL({x=startPoint.x,y=land.getHeight(startPoint),z=startPoint.y})
|
||||||
|
local grid = coord.LLtoMGRS(lat,lon)
|
||||||
|
local LLText = Utils.tostringLL(lat,lon,3)
|
||||||
|
local MGRSText = grid.UTMZone .. ' ' .. grid.MGRSDigraph .. ' ' .. grid.Easting .. ' ' .. grid.Northing
|
||||||
|
targetPointReport = targetPointReport.. '\nLLDM: '..LLText..' \nMGRS: '..MGRSText
|
||||||
|
|
||||||
|
targetPointReport = targetPointReport ..'\n'.. Localizations:translate('and moving to: ','cn')
|
||||||
|
|
||||||
|
lat, lon, alt = coord.LOtoLL({x=finPoint.x,y=land.getHeight(finPoint),z=finPoint.y})
|
||||||
|
grid = coord.LLtoMGRS(lat,lon)
|
||||||
|
LLText = Utils.tostringLL(lat,lon,3,true)
|
||||||
|
MGRSText = grid.UTMZone .. ' ' .. grid.MGRSDigraph .. ' ' .. grid.Easting .. ' ' .. grid.Northing
|
||||||
|
targetPointReport = targetPointReport.. '\nLLDM: '..LLText..' \nMGRS: '..MGRSText
|
||||||
|
|
||||||
|
timer.scheduleFunction(function (Mission)
|
||||||
|
Controller:setTask(Mission)
|
||||||
|
end,Mission,timer.getTime()+5)
|
||||||
|
end
|
||||||
|
|
||||||
|
if not Move then
|
||||||
|
local lat, lon, alt = coord.LOtoLL({x=centerPoint.x,y=land.getHeight(centerPoint),z=centerPoint.y})
|
||||||
|
local grid = coord.LLtoMGRS(lat,lon)
|
||||||
|
local LLText = Utils.tostringLL(lat,lon,3)
|
||||||
|
local MGRSText = grid.UTMZone .. ' ' .. grid.MGRSDigraph .. ' ' .. grid.Easting .. ' ' .. grid.Northing
|
||||||
|
targetPointReport = targetPointReport.. '\nLLDM: '..LLText..' \nMGRS: '..MGRSText
|
||||||
|
end
|
||||||
|
|
||||||
|
trigger.action.outTextForGroup(self.playerList[playerName].groupID,targetPointReport,60)
|
||||||
|
|
||||||
|
--Set fight back
|
||||||
|
if self.playerList[playerName].isTargerRedAlert then
|
||||||
|
timer.scheduleFunction(function (targetGroup)
|
||||||
|
self:setGroupRED(targetGroup)
|
||||||
|
end,targetGroup,timer.getTime()+5)
|
||||||
|
end
|
||||||
|
if not self.playerList[playerName].isTargerRedAlert then
|
||||||
|
timer.scheduleFunction(function (targetGroup)
|
||||||
|
self:setGroupGREEN(targetGroup)
|
||||||
|
end,targetGroup,timer.getTime()+5)
|
||||||
|
end
|
||||||
|
|
||||||
|
self:createMenu(self.playerList[playerName].group)
|
||||||
|
return targetGroup
|
||||||
|
end
|
||||||
|
|
||||||
|
function Range:deactivateTargets(PlayerName)
|
||||||
|
if not self.playerList[PlayerName] then return end
|
||||||
|
if not self.playerList[PlayerName].activeTarget then return end
|
||||||
|
|
||||||
|
if self.playerList[PlayerName].activeTarget:isExist() then
|
||||||
|
self.playerList[PlayerName].activeTarget:destroy()
|
||||||
|
end
|
||||||
|
self.playerList[PlayerName].activeTarget = nil
|
||||||
|
|
||||||
|
self.playerList[PlayerName].assignedSection.active = false
|
||||||
|
end
|
||||||
|
|
||||||
|
function Range:addTargetPreset(groupIdent,targetType,AAtype)
|
||||||
|
local newGroup = groupIdent
|
||||||
|
if type(groupIdent) == "string" then
|
||||||
|
newGroup = Group.getByName(groupIdent)
|
||||||
|
end
|
||||||
|
if not newGroup then return end
|
||||||
|
|
||||||
|
if not targetType then
|
||||||
|
targetType = Range.targetTypes.Armed
|
||||||
|
|
||||||
|
local targetDesc = newGroup:getDesc()
|
||||||
|
|
||||||
|
if targetDesc.attributes.NonAndLightArmoredUnits then
|
||||||
|
targetType = Range.targetTypes.Unarmed
|
||||||
|
end
|
||||||
|
|
||||||
|
if targetDesc.attributes['Air Defence'] then
|
||||||
|
targetType = Range.targetTypes.AA
|
||||||
|
|
||||||
|
if not AAtype then
|
||||||
|
AAtype = Range.AATypes.TV
|
||||||
|
if targetDesc.attributes['IR Guided SAM'] then
|
||||||
|
AAtype = Range.AATypes.IR
|
||||||
|
end
|
||||||
|
if targetDesc.attributes.RADAR_BAND1_FOR_ARM or targetDesc.attributes.RADAR_BAND2_FOR_ARM then
|
||||||
|
AAtype = Range.AATypes.RADAR
|
||||||
|
end
|
||||||
|
if targetDesc.attributes.AAA then
|
||||||
|
AAtype = Range.AATypes.AAA
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self.targetPresets[targetType] = self.targetPresets[targetType] or {}
|
||||||
|
self.targetPresets[targetType][AAtype] = self.targetPresets[targetType][AAtype] or {}
|
||||||
|
table.insert(self.targetPresets[targetType][AAtype],targetDesc['typeName'])
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
self.targetPresets[targetType] = self.targetPresets[targetType] or {}
|
||||||
|
table.insert(self.targetPresets[targetType],targetDesc['typeName'])
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function Range:setTargetFightBack(playerGroup)
|
||||||
|
if not playerGroup then return end
|
||||||
|
|
||||||
|
local playerUnit = playerGroup:getUnit(1)
|
||||||
|
if not playerUnit then return end
|
||||||
|
if not playerUnit:isActive() then return end
|
||||||
|
|
||||||
|
local playerName = playerUnit:getPlayerName()
|
||||||
|
if not playerName then return end
|
||||||
|
|
||||||
|
self.playerList[playerName].isTargerRedAlert = not self.playerList[playerName].isTargerRedAlert
|
||||||
|
if self.playerList[playerName].activeTarget then
|
||||||
|
local Controller = self.playerList[playerName].activeTarget:getController()
|
||||||
|
if Controller then
|
||||||
|
if self.playerList[playerName].isTargerRedAlert then
|
||||||
|
self:setGroupRED(self.playerList[playerName].activeTarget)
|
||||||
|
end
|
||||||
|
if not self.playerList[playerName].isTargerRedAlert then
|
||||||
|
self:setGroupGREEN(self.playerList[playerName].activeTarget)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self:createMenu(playerGroup)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Range:setGroupRED(group)
|
||||||
|
if not group then return end
|
||||||
|
if not group:isExist() then return end
|
||||||
|
|
||||||
|
local Controller = group:getController()
|
||||||
|
if not Controller then return end
|
||||||
|
|
||||||
|
Controller:setOption(AI.Option.Ground.id.ROE,AI.Option.Ground.val.ROE.OPEN_FIRE)
|
||||||
|
Controller:setOption(AI.Option.Ground.id.ALARM_STATE,AI.Option.Ground.val.ALARM_STATE.RED)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Range:setGroupGREEN(group)
|
||||||
|
if not group then return end
|
||||||
|
if not group:isExist() then return end
|
||||||
|
|
||||||
|
local Controller = group:getController()
|
||||||
|
if not Controller then return end
|
||||||
|
|
||||||
|
Controller:setOption(AI.Option.Ground.id.ROE,AI.Option.Ground.val.ROE.WEAPON_HOLD)
|
||||||
|
Controller:setOption(AI.Option.Ground.id.ALARM_STATE,AI.Option.Ground.val.ALARM_STATE.GREEN)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Range:setTargetAutoRespawn(playerGroup)
|
||||||
|
if not playerGroup then return end
|
||||||
|
|
||||||
|
local playerUnit = playerGroup:getUnit(1)
|
||||||
|
if not playerUnit then return end
|
||||||
|
if not playerUnit:isActive() then return end
|
||||||
|
|
||||||
|
local playerName = playerUnit:getPlayerName()
|
||||||
|
if not playerName then return end
|
||||||
|
|
||||||
|
self.playerList[playerName].autoRespawn = not self.playerList[playerName].autoRespawn
|
||||||
|
|
||||||
|
self:createMenu(playerGroup)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Range.drawPolygon(points)
|
||||||
|
local regionPolygonID = Utils.getMarkID()
|
||||||
|
|
||||||
|
if #points == 3 then
|
||||||
|
trigger.action.rectToAll(-1,regionPolygonID,points[1],points[2],points[3],{0,1,0,1},{0,1,0,0.3},1)
|
||||||
|
end
|
||||||
|
|
||||||
|
if #points == 4 then
|
||||||
|
trigger.action.quadToAll(-1,regionPolygonID,
|
||||||
|
points[1],
|
||||||
|
points[2],
|
||||||
|
points[3],
|
||||||
|
points[4],
|
||||||
|
{0,1,0,1},{0,1,0,0.3},1)
|
||||||
|
end
|
||||||
|
|
||||||
|
if #points > 4 then
|
||||||
|
Utils.drawPolygon(-1,regionPolygonID,points,{0,1,0,1},{0,1,0,0.3},1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local range1 = Range:New('RangeZone1')
|
||||||
|
range1:start()
|
||||||
|
|
||||||
|
for i=1,20,1 do
|
||||||
|
local unit = Unit.getByName('test-'..i..'-1')
|
||||||
|
if unit then
|
||||||
|
range1:addTargetPreset(unit)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
-- local group = Group.getByName('Buta_target')
|
||||||
|
|
||||||
|
-- timer.scheduleFunction(function (group)
|
||||||
|
-- group:destroy()
|
||||||
|
-- end,group,timer.getTime()+1)
|
||||||
+390
-2
@@ -1,6 +1,62 @@
|
|||||||
Utils = {}
|
Utils = {
|
||||||
|
MapMarkIDs = {
|
||||||
|
[1] = true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
|
function Utils.getMarkID()
|
||||||
|
local result = nil
|
||||||
|
|
||||||
|
for i,value in ipairs(Utils.MapMarkIDs) do
|
||||||
|
if value then
|
||||||
|
result = i
|
||||||
|
Utils.MapMarkIDs[i] = false
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not result then
|
||||||
|
result = #Utils.MapMarkIDs + 1
|
||||||
|
Utils.MapMarkIDs[result] = false
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
function Utils.Debug(text,displayTime,clearview)
|
||||||
|
if not text then text = 'nil or false' end
|
||||||
|
|
||||||
|
if type(text) ~= 'string' then
|
||||||
|
|
||||||
|
if type(text) ~= 'table' then
|
||||||
|
text = tostring(text)
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(text) == 'table' then
|
||||||
|
if mist then
|
||||||
|
text = mist.utils.tableShow(text)
|
||||||
|
else
|
||||||
|
text = 'no mist, please use mist to debug a table.'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
displayTime = displayTime or 10
|
||||||
|
clearview = clearview or false
|
||||||
|
|
||||||
|
trigger.action.outText(text,displayTime,clearview)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Utils.getTableSize(table)
|
||||||
|
local tableSize = 0
|
||||||
|
for _,_ in pairs(table) do
|
||||||
|
tableSize = tableSize + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
return tableSize
|
||||||
|
end
|
||||||
|
|
||||||
--- Creates a deep copy of a object.
|
--- Creates a deep copy of a object.
|
||||||
-- Usually this object is a table.
|
-- Usually this object is a table.
|
||||||
-- See also: from http://lua-users.org/wiki/CopyTable
|
-- See also: from http://lua-users.org/wiki/CopyTable
|
||||||
@@ -89,6 +145,16 @@ do
|
|||||||
return Utils.mag({x = point1.x - point2.x, y = 0, z = point1.z - point2.z})
|
return Utils.mag({x = point1.x - point2.x, y = 0, z = point1.z - point2.z})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- @return radians
|
||||||
|
function Utils.getObjHeading(object)
|
||||||
|
if not object then return false end
|
||||||
|
|
||||||
|
local objectPos = object:getPosition()
|
||||||
|
local objectHeading = math.atan2(objectPos.x.z, objectPos.x.x)
|
||||||
|
|
||||||
|
return objectHeading
|
||||||
|
end
|
||||||
|
|
||||||
function Utils.getNorthCorrection(gPoint) --gets the correction needed for true north
|
function Utils.getNorthCorrection(gPoint) --gets the correction needed for true north
|
||||||
local point = Utils.deepCopy(gPoint)
|
local point = Utils.deepCopy(gPoint)
|
||||||
if not point.z then --Vec2; convert to Vec3
|
if not point.z then --Vec2; convert to Vec3
|
||||||
@@ -108,7 +174,7 @@ do
|
|||||||
function Utils.getDir(vec, point)
|
function Utils.getDir(vec, point)
|
||||||
local dir = math.atan2(vec.z, vec.x)
|
local dir = math.atan2(vec.z, vec.x)
|
||||||
if point then
|
if point then
|
||||||
dir = dir + mist.getNorthCorrection(point)
|
dir = dir + Utils.getNorthCorrection(point)
|
||||||
end
|
end
|
||||||
if dir < 0 then
|
if dir < 0 then
|
||||||
dir = dir + 2 * math.pi -- put dir in range of 0 to 2*pi
|
dir = dir + 2 * math.pi -- put dir in range of 0 to 2*pi
|
||||||
@@ -124,6 +190,190 @@ do
|
|||||||
return dir
|
return dir
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Utils.getAvgPoint(points)
|
||||||
|
local avgX, avgY, avgZ, totNum = 0, 0, 0, 0
|
||||||
|
for i = 1, #points do
|
||||||
|
--log:warn(points[i])
|
||||||
|
local nPoint = Utils.makeVec3(points[i])
|
||||||
|
if nPoint.z then
|
||||||
|
avgX = avgX + nPoint.x
|
||||||
|
avgY = avgY + nPoint.y
|
||||||
|
avgZ = avgZ + nPoint.z
|
||||||
|
totNum = totNum + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if totNum ~= 0 then
|
||||||
|
return {x = avgX/totNum, y = avgY/totNum, z = avgZ/totNum}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- need to return a Vec3 or Vec2?
|
||||||
|
function Utils.getRandPointInCircle(p, r, innerRadius, maxA, minA)
|
||||||
|
local point = Utils.makeVec3(p)
|
||||||
|
local theta = 2*math.pi*math.random()
|
||||||
|
local radius = r or 1000
|
||||||
|
local minR = innerRadius or 0
|
||||||
|
if maxA and not minA then
|
||||||
|
theta = math.rad(math.random(0, maxA - math.random()))
|
||||||
|
elseif maxA and minA then
|
||||||
|
if minA < maxA then
|
||||||
|
theta = math.rad(math.random(minA, maxA) - math.random())
|
||||||
|
else
|
||||||
|
theta = math.rad(math.random(maxA, minA) - math.random())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local rad = math.random() + math.random()
|
||||||
|
if rad > 1 then
|
||||||
|
rad = 2 - rad
|
||||||
|
end
|
||||||
|
|
||||||
|
local radMult
|
||||||
|
if minR and minR <= radius then
|
||||||
|
--radMult = (radius - innerRadius)*rad + innerRadius
|
||||||
|
radMult = radius * math.sqrt((minR^2 + (radius^2 - minR^2) * math.random()) / radius^2)
|
||||||
|
else
|
||||||
|
radMult = radius*rad
|
||||||
|
end
|
||||||
|
|
||||||
|
local rndCoord
|
||||||
|
if radius > 0 then
|
||||||
|
rndCoord = {x = math.cos(theta)*radMult + point.x, y = math.sin(theta)*radMult + point.z}
|
||||||
|
else
|
||||||
|
rndCoord = {x = point.x, y = point.z}
|
||||||
|
end
|
||||||
|
return rndCoord
|
||||||
|
end
|
||||||
|
|
||||||
|
function Utils.getRandomPointInPoly(zone)
|
||||||
|
--env.info('Zone Size: '.. #zone)
|
||||||
|
local avg = Utils.getAvgPoint(zone)
|
||||||
|
--log:warn(avg)
|
||||||
|
local radius = 0
|
||||||
|
local minR = math.huge
|
||||||
|
local newCoord = {}
|
||||||
|
for i = 1, #zone do
|
||||||
|
if Utils.get2DDist(avg, zone[i]) > radius then
|
||||||
|
radius = Utils.get2DDist(avg, zone[i])
|
||||||
|
end
|
||||||
|
if Utils.get2DDist(avg, zone[i]) < minR then
|
||||||
|
minR = Utils.get2DDist(avg, zone[i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--log:warn('minR: $1', minR)
|
||||||
|
--log:warn('Radius: $1', radius)
|
||||||
|
local lSpawnPos = {}
|
||||||
|
for j = 1, 100 do
|
||||||
|
newCoord = Utils.getRandPointInCircle(avg, radius)
|
||||||
|
if Utils.pointInPolygon(newCoord, zone) then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if j == 100 then
|
||||||
|
newCoord = Utils.getRandPointInCircle(avg, radius)
|
||||||
|
log:warn("Failed to find point in poly; Giving random point from center of the poly")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return newCoord
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Simple rounding function.
|
||||||
|
-- From http://lua-users.org/wiki/SimpleRound
|
||||||
|
-- use negative idp for rounding ahead of decimal place, positive for rounding after decimal place
|
||||||
|
-- @tparam number num number to round
|
||||||
|
-- @param idp
|
||||||
|
function Utils.round(num, idp)
|
||||||
|
local mult = 10^(idp or 0)
|
||||||
|
return math.floor(num * mult + 0.5) / mult
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[acc:
|
||||||
|
in DM: decimal point of minutes.
|
||||||
|
In DMS: decimal point of seconds.
|
||||||
|
position after the decimal of the least significant digit:
|
||||||
|
So:
|
||||||
|
42.32 - acc of 2.
|
||||||
|
]]
|
||||||
|
function Utils.tostringLL(lat, lon, acc, DMS)
|
||||||
|
|
||||||
|
local latHemi, lonHemi
|
||||||
|
if lat > 0 then
|
||||||
|
latHemi = 'N'
|
||||||
|
else
|
||||||
|
latHemi = 'S'
|
||||||
|
end
|
||||||
|
|
||||||
|
if lon > 0 then
|
||||||
|
lonHemi = 'E'
|
||||||
|
else
|
||||||
|
lonHemi = 'W'
|
||||||
|
end
|
||||||
|
|
||||||
|
lat = math.abs(lat)
|
||||||
|
lon = math.abs(lon)
|
||||||
|
|
||||||
|
local latDeg = math.floor(lat)
|
||||||
|
local latMin = (lat - latDeg)*60
|
||||||
|
|
||||||
|
local lonDeg = math.floor(lon)
|
||||||
|
local lonMin = (lon - lonDeg)*60
|
||||||
|
|
||||||
|
if DMS then -- degrees, minutes, and seconds.
|
||||||
|
local oldLatMin = latMin
|
||||||
|
latMin = math.floor(latMin)
|
||||||
|
local latSec = Utils.round((oldLatMin - latMin)*60, acc)
|
||||||
|
|
||||||
|
local oldLonMin = lonMin
|
||||||
|
lonMin = math.floor(lonMin)
|
||||||
|
local lonSec = Utils.round((oldLonMin - lonMin)*60, acc)
|
||||||
|
|
||||||
|
if latSec == 60 then
|
||||||
|
latSec = 0
|
||||||
|
latMin = latMin + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if lonSec == 60 then
|
||||||
|
lonSec = 0
|
||||||
|
lonMin = lonMin + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local secFrmtStr -- create the formatting string for the seconds place
|
||||||
|
if acc <= 0 then -- no decimal place.
|
||||||
|
secFrmtStr = '%02d'
|
||||||
|
else
|
||||||
|
local width = 3 + acc -- 01.310 - that's a width of 6, for example.
|
||||||
|
secFrmtStr = '%0' .. width .. '.' .. acc .. 'f'
|
||||||
|
end
|
||||||
|
|
||||||
|
return string.format('%02d', latDeg) .. ' ' .. string.format('%02d', latMin) .. '\' ' .. string.format(secFrmtStr, latSec) .. '"' .. latHemi .. ' '
|
||||||
|
.. string.format('%02d', lonDeg) .. ' ' .. string.format('%02d', lonMin) .. '\' ' .. string.format(secFrmtStr, lonSec) .. '"' .. lonHemi
|
||||||
|
|
||||||
|
else -- degrees, decimal minutes.
|
||||||
|
latMin = Utils.round(latMin, acc)
|
||||||
|
lonMin = Utils.round(lonMin, acc)
|
||||||
|
|
||||||
|
if latMin == 60 then
|
||||||
|
latMin = 0
|
||||||
|
latDeg = latDeg + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if lonMin == 60 then
|
||||||
|
lonMin = 0
|
||||||
|
lonDeg = lonDeg + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local minFrmtStr -- create the formatting string for the minutes place
|
||||||
|
if acc <= 0 then -- no decimal place.
|
||||||
|
minFrmtStr = '%02d'
|
||||||
|
else
|
||||||
|
local width = 3 + acc -- 01.310 - that's a width of 6, for example.
|
||||||
|
minFrmtStr = '%0' .. width .. '.' .. acc .. 'f'
|
||||||
|
end
|
||||||
|
|
||||||
|
return string.format('%02d', latDeg) .. ' ' .. string.format(minFrmtStr, latMin) .. '\'' .. latHemi .. ' '
|
||||||
|
.. string.format('%02d', lonDeg) .. ' ' .. string.format(minFrmtStr, lonMin) .. '\'' .. lonHemi
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--- Converts a TACAN Channel/Mode couple into a frequency in Hz.
|
--- Converts a TACAN Channel/Mode couple into a frequency in Hz.
|
||||||
-- @param #number TACANChannel The TACAN channel, i.e. the 10 in "10X".
|
-- @param #number TACANChannel The TACAN channel, i.e. the 10 in "10X".
|
||||||
-- @param #string TACANMode The TACAN mode, i.e. the "X" in "10X".
|
-- @param #string TACANMode The TACAN mode, i.e. the "X" in "10X".
|
||||||
@@ -161,6 +411,144 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function Utils.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
|
||||||
|
|
||||||
|
|
||||||
|
--- Returns an array containing a group's units positions.
|
||||||
|
-- e.g.
|
||||||
|
-- {
|
||||||
|
-- [1] = {x = 299435.224, y = -1146632.6773},
|
||||||
|
-- [2] = {x = 663324.6563, y = 322424.1112}
|
||||||
|
-- }
|
||||||
|
-- @tparam number|string groupIdent group id or name
|
||||||
|
-- @treturn table array containing positions of each group member
|
||||||
|
function Utils.getWayPoints(groupIdent)
|
||||||
|
-- search by groupId and allow groupId and groupName as inputs
|
||||||
|
local gpId = groupIdent
|
||||||
|
if type(groupIdent) == 'string' and not tonumber(groupIdent) then
|
||||||
|
local group = Group.getByName(groupIdent)
|
||||||
|
if not group then return end
|
||||||
|
|
||||||
|
gpId = group:getID()
|
||||||
|
end
|
||||||
|
|
||||||
|
for coa_name, coa_data in pairs(env.mission.coalition) do
|
||||||
|
if type(coa_data) == 'table' then
|
||||||
|
if coa_data.country then --there is a country table
|
||||||
|
for cntry_id, cntry_data in pairs(coa_data.country) do
|
||||||
|
for obj_cat_name, obj_cat_data in pairs(cntry_data) do
|
||||||
|
if obj_cat_name == "helicopter" or obj_cat_name == "ship" or obj_cat_name == "plane" or obj_cat_name == "vehicle" then -- only these types have points
|
||||||
|
if ((type(obj_cat_data) == 'table') and obj_cat_data.group and (type(obj_cat_data.group) == 'table') and (#obj_cat_data.group > 0)) then --there's a group!
|
||||||
|
for group_num, group_data in pairs(obj_cat_data.group) do
|
||||||
|
if group_data and group_data.groupId == gpId then -- this is the group we are looking for
|
||||||
|
if group_data.route and group_data.route.points and #group_data.route.points > 0 then
|
||||||
|
local points = {}
|
||||||
|
for point_num, point in pairs(group_data.route.points) do
|
||||||
|
if not point.point then
|
||||||
|
points[point_num] = { x = point.x, y = point.y }
|
||||||
|
else
|
||||||
|
points[point_num] = point.point --it's possible that the ME could move to the point = Vec2 notation.
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return points
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end --if group_data and group_data.name and group_data.name == 'groupname'
|
||||||
|
end --for group_num, group_data in pairs(obj_cat_data.group) do
|
||||||
|
end --if ((type(obj_cat_data) == 'table') and obj_cat_data.group and (type(obj_cat_data.group) == 'table') and (#obj_cat_data.group > 0)) then
|
||||||
|
end --if obj_cat_name == "helicopter" or obj_cat_name == "ship" or obj_cat_name == "plane" or obj_cat_name == "vehicle" or obj_cat_name == "static" then
|
||||||
|
end --for obj_cat_name, obj_cat_data in pairs(cntry_data) do
|
||||||
|
end --for cntry_id, cntry_data in pairs(coa_data.country) do
|
||||||
|
end --if coa_data.country then --there is a country table
|
||||||
|
end --if coa_name == 'red' or coa_name == 'blue' and type(coa_data) == 'table' then
|
||||||
|
end --for coa_name, coa_data in pairs(mission.coalition) do
|
||||||
|
end
|
||||||
|
|
||||||
|
function Utils.pointInPolygon(point, poly, maxalt)
|
||||||
|
point = Utils.makeVec3(point)
|
||||||
|
local px = point.x
|
||||||
|
local pz = point.z
|
||||||
|
local cn = 0
|
||||||
|
local newpoly = Utils.deepCopy(poly)
|
||||||
|
|
||||||
|
if not maxalt or (point.y <= maxalt) then
|
||||||
|
local polysize = #newpoly
|
||||||
|
newpoly[#newpoly + 1] = newpoly[1]
|
||||||
|
|
||||||
|
newpoly[1] = Utils.makeVec3(newpoly[1])
|
||||||
|
|
||||||
|
for k = 1, polysize do
|
||||||
|
newpoly[k+1] = Utils.makeVec3(newpoly[k+1])
|
||||||
|
if ((newpoly[k].z <= pz) and (newpoly[k+1].z > pz)) or ((newpoly[k].z > pz) and (newpoly[k+1].z <= pz)) then
|
||||||
|
local vt = (pz - newpoly[k].z) / (newpoly[k+1].z - newpoly[k].z)
|
||||||
|
if (px < newpoly[k].x + vt*(newpoly[k+1].x - newpoly[k].x)) then
|
||||||
|
cn = cn + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return cn%2 == 1
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Utils.doString(s)
|
||||||
|
local f, err = loadstring(s)
|
||||||
|
if f then
|
||||||
|
return true, f()
|
||||||
|
else
|
||||||
|
return false, err
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Utils.drawPolygon(Coalition,MarkID,vecs,Color,FillColor,LineType,ReadOnly,Text)
|
||||||
|
local s=string.format("trigger.action.markupToAll(7, %d, %d,", Coalition, MarkID)
|
||||||
|
for _,vec in pairs(vecs) do
|
||||||
|
vec = Utils.makeVec3(vec)
|
||||||
|
--s=s..string.format("%s,", UTILS._OneLineSerialize(vec))
|
||||||
|
s=s..string.format("{x=%.1f, y=%.1f, z=%.1f},", vec.x, vec.y, vec.z)
|
||||||
|
end
|
||||||
|
s=s..string.format("{%.3f, %.3f, %.3f, %.3f},", Color[1], Color[2], Color[3], Color[4])
|
||||||
|
s=s..string.format("{%.3f, %.3f, %.3f, %.3f},", FillColor[1], FillColor[2], FillColor[3], FillColor[4])
|
||||||
|
s=s..string.format("%d,", LineType or 1)
|
||||||
|
s=s..string.format("%s", tostring(ReadOnly))
|
||||||
|
if Text and type(Text)=="string" and string.len(Text)>0 then
|
||||||
|
s=s..string.format(", \"%s\"", tostring(Text))
|
||||||
|
end
|
||||||
|
s=s..")"
|
||||||
|
|
||||||
|
-- Execute string command
|
||||||
|
local success=Utils.doString(s)
|
||||||
|
|
||||||
|
if not success then
|
||||||
|
self:E("ERROR: Could not draw polygon")
|
||||||
|
env.info(s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user