Compare commits
2
Commits
f3efdf3c31
...
586f142e78
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
586f142e78 | ||
|
|
c08d8fb7cb |
Binary file not shown.
Binary file not shown.
@@ -11,6 +11,36 @@ Localizations = {
|
|||||||
['Tanker'] = 'Refuling tanker',
|
['Tanker'] = 'Refuling tanker',
|
||||||
['JTAC'] = 'JTAC',
|
['JTAC'] = 'JTAC',
|
||||||
['Carrier'] = 'Carrier',
|
['Carrier'] = 'Carrier',
|
||||||
|
|
||||||
|
---Range
|
||||||
|
--Menu
|
||||||
|
['Range'] = 'Range',
|
||||||
|
['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',
|
||||||
},
|
},
|
||||||
|
|
||||||
--中文
|
--中文
|
||||||
@@ -23,6 +53,36 @@ Localizations = {
|
|||||||
['Tanker'] = '空中加油机',
|
['Tanker'] = '空中加油机',
|
||||||
['JTAC'] = 'JTAC',
|
['JTAC'] = 'JTAC',
|
||||||
['Carrier'] = '航母',
|
['Carrier'] = '航母',
|
||||||
|
|
||||||
|
---Range
|
||||||
|
--Menu
|
||||||
|
['Range'] = '靶场',
|
||||||
|
['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'] = '目标自动重生: 关',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+246
-44
@@ -1,85 +1,286 @@
|
|||||||
Range = {
|
Range = {
|
||||||
|
MonitorRepeatTime = 5, --Seconds
|
||||||
|
MonitorID = nil,
|
||||||
|
|
||||||
|
|
||||||
points = {},
|
points = {},
|
||||||
name = nil,
|
name = nil,
|
||||||
urbanZones = {
|
|
||||||
--[[
|
sectionTypes = {
|
||||||
[1] = {
|
Tree = 'Tree',
|
||||||
points = {},
|
Urban = 'Urban',
|
||||||
active = false,
|
Open = 'Open',
|
||||||
type = 'urban',
|
|
||||||
},
|
},
|
||||||
]]
|
|
||||||
|
targetTypes = {
|
||||||
|
Unarmed = 'Unarmed',
|
||||||
|
Armed = 'Armed',
|
||||||
|
AA = 'AA',
|
||||||
},
|
},
|
||||||
treeZones = {
|
|
||||||
--[[
|
AATypes = {
|
||||||
[1] = {
|
AAA = 'AAA',
|
||||||
points = {},
|
IR = 'IR',
|
||||||
active = false,
|
RADAR = 'Radar',
|
||||||
type = 'tree',
|
TV = 'TV',
|
||||||
},
|
LASER = 'Laser',
|
||||||
]]
|
-- TELE = 'Tele',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
sections = {},
|
||||||
|
|
||||||
playerList = {},
|
playerList = {},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
function Range:New()
|
|
||||||
local zoneGroupNamePrefix = 'RangeZone'
|
function Range:New(zoneName)
|
||||||
for i=1,10,1 do
|
local points = Utils.getWayPoints(zoneName)
|
||||||
local zoneGroupName = zoneGroupNamePrefix..i
|
|
||||||
local points = Utils.getWayPoints(zoneGroupName)
|
|
||||||
if not points then
|
if not points then
|
||||||
break
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.name = zoneName
|
||||||
|
self.points = points
|
||||||
|
|
||||||
|
Utils.drawPolygon(-1,Utils.getMarkID(),points,{0,1,1,1},{0,1,0,0},2)
|
||||||
|
|
||||||
|
for type, value in pairs(self.sectionTypes) do
|
||||||
for j=1,100,1 do
|
for j=1,100,1 do
|
||||||
local sectionName = '-Urban-'..j
|
local sectionName = string.format('%s-%s-%d',zoneName,value,j)
|
||||||
|
|
||||||
points = Utils.getWayPoints(zoneGroupName..sectionName)
|
points = Utils.getWayPoints(sectionName)
|
||||||
if not points then
|
if not points then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
Range.drawPolygon(points)
|
--Debug
|
||||||
trigger.action.textToAll(-1,Utils.getMarkID(),Utils.makeVec3(points[1]),{1,1,1,1},{0,0,0,0},8,false,sectionName)
|
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
|
end
|
||||||
|
|
||||||
for j=1,100,1 do
|
return self
|
||||||
local sectionName = '-Tree-'..j
|
|
||||||
points = Utils.getWayPoints(zoneGroupName..sectionName)
|
|
||||||
if not points then
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Range.drawPolygon(points)
|
function Range._MonitorFunction(vars,time)
|
||||||
trigger.action.textToAll(-1,Utils.getMarkID(),Utils.makeVec3(points[1]),{1,1,1,1},{0,0,0,0},8,false,sectionName)
|
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
|
||||||
|
|
||||||
for j=1,100,1 do
|
if not unitInRangeZone then
|
||||||
local sectionName = '-Open-'..j
|
self:removePlayerProfile(playerUnit)
|
||||||
points = Utils.getWayPoints(zoneGroupName..sectionName)
|
end
|
||||||
if not points then
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Range.drawPolygon(points)
|
if not PlayerName or not playerUnit:isActive() then
|
||||||
trigger.action.textToAll(-1,Utils.getMarkID(),Utils.makeVec3(points[1]),{1,1,1,1},{0,0,0,0},8,false,sectionName)
|
self:removePlayerProfile(playerUnit)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Range:createPlayerProfile()
|
-- Utils.Debug(mist.utils.tableShow(self.playerList))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return time+repeatTime
|
||||||
end
|
end
|
||||||
|
|
||||||
function Range:removePlayerProfile()
|
function Range:start(Delay,RepeatScanSeconds)
|
||||||
|
local tDelay = Delay or 1
|
||||||
|
local RepeatScanInterval = RepeatScanSeconds or Range.MonitorRepeatTime
|
||||||
|
|
||||||
|
if self.MonitorID then
|
||||||
|
self:stop()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Range:setTargetFightBack()
|
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
|
||||||
|
Utils.Debug('removeMenu')
|
||||||
|
missionCommands.removeItemForGroup(groupID,self.playerList[playerName].menu)
|
||||||
|
self.playerList[playerName].menu = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Utils.Debug('createMenu')
|
||||||
|
local MainMenuName = Localizations:translate('Range','cn')
|
||||||
|
local menu = missionCommands.addSubMenuForGroup(groupID,MainMenuName)
|
||||||
|
|
||||||
|
for sectionType, date 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
|
||||||
|
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
|
||||||
|
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.section,vars.targetType,vars.AAType,vars.Move)
|
||||||
|
end,{context = self,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.section,vars.targetType,vars.AAType,vars.Move)
|
||||||
|
end,{context = self,section = sectionType,targetType = targetType,AAType = AAType,Move = false})
|
||||||
|
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.section,vars.targetType,vars.AAType,vars.Move)
|
||||||
|
end,{context = self,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.section,vars.targetType,vars.AAType,vars.Move)
|
||||||
|
end,{context = self,section = sectionType,targetType = targetType,AAType = nil,Move = false})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.playerList[playerName] then
|
||||||
|
local switch = 'Off'
|
||||||
|
|
||||||
|
if self.playerList[playerName].isTargerRedAlert then
|
||||||
|
switch = 'On'
|
||||||
|
end
|
||||||
|
Utils.Debug('switch: '..switch)
|
||||||
|
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.playerList[playerName].isTargerRedAlert = not self.playerList[playerName].isTargerRedAlert
|
||||||
|
self:createMenu(playerGroup)
|
||||||
|
end,{context = self})
|
||||||
|
|
||||||
|
switch = 'Off'
|
||||||
|
if self.playerList[playerName].autoRespawn then
|
||||||
|
switch = 'On'
|
||||||
|
end
|
||||||
|
Utils.Debug('switch: '..switch)
|
||||||
|
local AutoRespawnSwitchName = Localizations:translate(string.format('Auto Respawn Targets: %s',switch),'cn')
|
||||||
|
missionCommands.addCommandForGroup(groupID,AutoRespawnSwitchName,SettingsMenu,function (vars)
|
||||||
|
local self = vars.context
|
||||||
|
self.playerList[playerName].autoRespawn = not self.playerList[playerName].autoRespawn
|
||||||
|
self:createMenu(playerGroup)
|
||||||
|
end,{context = self})
|
||||||
|
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
|
||||||
|
|
||||||
|
Utils.Debug('createPlayerProfile')
|
||||||
|
|
||||||
|
self.playerList[PlayerName] = {
|
||||||
|
autoRespawn = false,
|
||||||
|
isTargerRedAlert = false,
|
||||||
|
activeTarget = nil,
|
||||||
|
menu = nil,
|
||||||
|
}
|
||||||
|
self:createMenu(playerGroup)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Range:removePlayerProfile(playerUnit)
|
||||||
|
if not playerUnit then return end
|
||||||
|
|
||||||
|
local PlayerName = playerUnit:getPlayerName()
|
||||||
|
if not self.playerList[PlayerName] then return end
|
||||||
|
|
||||||
|
self:deactivateTargets(PlayerName)
|
||||||
|
|
||||||
|
self.playerList[PlayerName] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function Range:activeTartgets(section,targetType,AAType,Move)
|
||||||
|
AAType = AAType or 'none'
|
||||||
|
local isMove = 'Stationary'
|
||||||
|
if Move then
|
||||||
|
isMove = 'Moving'
|
||||||
|
end
|
||||||
|
Utils.Debug('section:'..section..' targetType: '..' AAType: '..AAType..' Move: '..isMove)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Range:deactivateTargets(PlayerName)
|
||||||
|
if not self.playerList[PlayerName] then return end
|
||||||
|
if not self.playerList[PlayerName].activeTarget then return end
|
||||||
|
|
||||||
|
self.playerList[PlayerName].activeTarget:destroy()
|
||||||
|
self.playerList[PlayerName].activeTarget = nil
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
self:createMenu(playerGroup)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Range.drawPolygon(points)
|
function Range.drawPolygon(points)
|
||||||
@@ -103,5 +304,6 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Range:New()
|
local range1 = Range:New('RangeZone1')
|
||||||
|
range1:start()
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user