Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c55b615554 | ||
|
|
ec3178c2d6 | ||
|
|
d1cdac51a8 | ||
|
|
094a79d317 | ||
|
|
18000d33ec | ||
|
|
f0f158b85d | ||
|
|
511a852c4d | ||
|
|
82f76d4d77 | ||
|
|
a7cfe2137e | ||
|
|
365bc3395e | ||
|
|
1183f25802 | ||
|
|
0c1114c20a |
@@ -0,0 +1,5 @@
|
||||
AH64: MGRS GRID: 37 S DU 27680 19875
|
||||
|
||||
Cargo:
|
||||
N34°36'33"
|
||||
E38°14'34"
|
||||
@@ -184,6 +184,6 @@ local palmyrawar = {
|
||||
}
|
||||
|
||||
-- drawMarks(powerplant1,1)
|
||||
drawMarks(palmyrawar)
|
||||
-- drawMarks(palmyrawar)
|
||||
|
||||
Utils.Debug("DrawMarks")
|
||||
@@ -0,0 +1,43 @@
|
||||
local AH64CodeTable = {
|
||||
1533,
|
||||
1688,
|
||||
1788,
|
||||
1782,
|
||||
1777,
|
||||
1732,
|
||||
1621,
|
||||
1111,
|
||||
2111,
|
||||
4121,
|
||||
4311,
|
||||
4511,
|
||||
4711,
|
||||
5111,
|
||||
5311,
|
||||
5511,
|
||||
5711,
|
||||
}
|
||||
|
||||
-- testing code
|
||||
local function startJammer(fromUnitName,targetTable)
|
||||
if not fromUnitName then return end
|
||||
if not targetTable then return end
|
||||
|
||||
local jammerUnit = Unit.getByName(fromUnitName)
|
||||
local ray_InfraRed = Spot.createInfraRed(jammerUnit, {x = 0, y = 1.5, z = 0}, targetTable)
|
||||
local ray_lazer = Spot.createLaser(jammerUnit, {x = 0, y = 1.5, z = 0}, targetTable, 1688)
|
||||
|
||||
if ray_lazer:getCategory() == Spot.Category.LASER and ray_InfraRed:getCategory() == Spot.Category.INFRA_RED then
|
||||
Utils.Debug('LazerJammer active')
|
||||
end
|
||||
end
|
||||
|
||||
local targetPoint = trigger.misc.getZone('JammerZone').point
|
||||
local target = {x=targetPoint.x,y=land.getHeight({x=targetPoint.x,y=targetPoint.z}),z=targetPoint.z}
|
||||
|
||||
timer.scheduleFunction(function (vars)
|
||||
local fromUnitName = vars.unitName
|
||||
local target = vars.target
|
||||
|
||||
startJammer(fromUnitName,target)
|
||||
end,{unitName = 'LazerJammer-1-1', target = target},timer.getTime()+10)
|
||||
@@ -3,7 +3,10 @@ local script_list =
|
||||
-- Load order must be correct
|
||||
'mist_4_5_126.lua',
|
||||
'Utils.lua',
|
||||
'DrawMarks.lua',
|
||||
-- 'DrawMarks.lua',
|
||||
-- 'LazerJammer.lua',
|
||||
'PatrolUnit.lua',
|
||||
'misc.lua',
|
||||
}
|
||||
|
||||
local function load_scripts(path, list)
|
||||
|
||||
@@ -0,0 +1,393 @@
|
||||
-- 向量工具函数
|
||||
local function vec_add(a, b) return {x = a.x + b.x, y = a.y + b.y} end
|
||||
local function vec_sub(a, b) return {x = a.x - b.x, y = a.y - b.y} end
|
||||
local function vec_mul(a, s) return {x = a.x * s, y = a.y * s} end
|
||||
local function vec_len(a) return math.sqrt(a.x^2 + a.y^2) end
|
||||
local function vec_normalize(a)
|
||||
local l = vec_len(a)
|
||||
return l > 0 and {x = a.x/l, y = a.y/l} or {x=0, y=0}
|
||||
end
|
||||
|
||||
PatrolUnit = {}
|
||||
|
||||
-- 设置
|
||||
PatrolUnit.DebugMod = false
|
||||
PatrolUnit.engageRangeTimes = 2 -- EngageRange(meters) = fireRang * engageRangeTimes
|
||||
PatrolUnit.MonitorStartDelay = 1 --init value
|
||||
|
||||
PatrolUnit.DefaultFireRange = 2500
|
||||
PatrolUnit.DefaultEyeHight = 3
|
||||
|
||||
PatrolUnit.MonitorRepeatTime = 30
|
||||
|
||||
PatrolUnit.Database = {
|
||||
['HL_ZU-23'] = {
|
||||
fireRange = 2500,
|
||||
eyeHight = 3,
|
||||
},
|
||||
['Ural-375 ZU-23 Insurgent'] = {
|
||||
fireRange = 2500,
|
||||
eyeHight = 3,
|
||||
},
|
||||
['HL_KORD'] = {
|
||||
fireRange = 1200,
|
||||
eyeHight = 3,
|
||||
},
|
||||
['tt_DSHK'] = {
|
||||
fireRange = 1200,
|
||||
eyeHight = 3,
|
||||
},
|
||||
['tt_KORD'] = {
|
||||
fireRange = 1200,
|
||||
eyeHight = 3,
|
||||
},
|
||||
}
|
||||
PatrolUnit.AllGroups = {}
|
||||
do
|
||||
function PatrolUnit:New(groupName,fireRange,eyeHight)
|
||||
if not groupName then return end
|
||||
|
||||
local obj = {}
|
||||
|
||||
obj.groupName = groupName
|
||||
obj.group = Group.getByName(groupName)
|
||||
if not obj.group then
|
||||
env.error('PatrolUnit:New() - Group: '..groupName..' not found.')
|
||||
return
|
||||
end
|
||||
|
||||
local unit = obj.group:getUnit(1)
|
||||
if not unit then
|
||||
env.error('PatrolUnit:New() - Group: '..groupName..' has no unit(1).')
|
||||
return
|
||||
end
|
||||
|
||||
if PatrolUnit.DebugMod then
|
||||
local unitType = unit:getTypeName()
|
||||
|
||||
if unitType then
|
||||
Utils.Debug('UnitType: '..unitType)
|
||||
end
|
||||
|
||||
if not unitType then
|
||||
Utils.Debug('UnitType: nil')
|
||||
end
|
||||
end
|
||||
|
||||
fireRange = fireRange or PatrolUnit.Database[unit:getTypeName()].fireRange or PatrolUnit.DefaultFireRange
|
||||
eyeHight = eyeHight or PatrolUnit.Database[unit:getTypeName()].eyeHight or PatrolUnit.DefaultEyeHight
|
||||
|
||||
obj.controller = unit:getController()
|
||||
if not obj.controller then
|
||||
env.error('PatrolUnit:New() - Group: '..groupName..' has no controller.')
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
obj.fireRange = fireRange
|
||||
obj.speed = unit:getDesc().speedMax
|
||||
obj.eyeHight = eyeHight
|
||||
obj.engageRange = obj.fireRange*PatrolUnit.engageRangeTimes
|
||||
|
||||
|
||||
obj.MonitorID = nil
|
||||
|
||||
--Debug
|
||||
if PatrolUnit.DebugMod then
|
||||
obj.MarkID = Utils.getMarkID()
|
||||
trigger.action.circleToAll(-1,obj.MarkID,{x=unit:getPoint().x,y=0,z=unit:getPoint().z},obj.fireRange*0.8,{1,0,0,0.5},{1,0,0,0.1},2)
|
||||
end
|
||||
|
||||
setmetatable(obj, self)
|
||||
self.__index = self
|
||||
|
||||
PatrolUnit.AllGroups[obj.groupName] = obj
|
||||
obj:start()
|
||||
|
||||
return obj
|
||||
end
|
||||
|
||||
function PatrolUnit:Remove()
|
||||
if self.group then
|
||||
if self.group:isExist() then
|
||||
self.group:destroy()
|
||||
end
|
||||
end
|
||||
self:stop()
|
||||
|
||||
|
||||
PatrolUnit.AllGroups[self.groupName] = nil
|
||||
end
|
||||
|
||||
function PatrolUnit:GetNewTargets()
|
||||
local Controller = self.controller
|
||||
if not Controller then
|
||||
env.error('PatrolUnit:GetNewTargets() - Can not get Group Controller.')
|
||||
self:Remove()
|
||||
return nil
|
||||
end
|
||||
|
||||
local rawTargetTable = Controller:getDetectedTargets()
|
||||
local visibleTargets = {}
|
||||
for i, detectedTarget in ipairs(rawTargetTable) do
|
||||
if detectedTarget.visible then
|
||||
local detectedTarget_Point = detectedTarget.object:getPoint()
|
||||
if detectedTarget.object:getCategory() == Object.Category.UNIT then
|
||||
if detectedTarget.object:getCategory() == Unit.Category.AIRPLANE or detectedTarget.object:getCategory() == Unit.Category.HELICOPTER then
|
||||
if detectedTarget_Point.y < self.fireRange then
|
||||
if self.DebugMod then
|
||||
Utils.Debug('Add object: '..detectedTarget.object:getName()..' to visibleTargets.')
|
||||
end
|
||||
|
||||
table.insert(visibleTargets,detectedTarget.object)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return visibleTargets
|
||||
end
|
||||
|
||||
function PatrolUnit.calculate_intercept_point(myPointVec2, mySpeed, targetPointVec2, targetSpeed, targetHeading_rad, fireRange)
|
||||
-- 飞行器速度向量
|
||||
local fly_dir = {x = math.cos(targetHeading_rad), y = math.sin(targetHeading_rad)}
|
||||
local targetSpeed_vec = vec_mul(fly_dir, targetSpeed)
|
||||
|
||||
-- 相对位置向量
|
||||
local D = vec_sub(targetPointVec2, myPointVec2)
|
||||
|
||||
-- 相对速度向量
|
||||
-- 构建二次方程:|D + (targetSpeed_vec - mySpeed_dir * mySpeed) * t| = 0
|
||||
-- 展开为:a*t² + b*t + c = 0
|
||||
local a = targetSpeed^2 - mySpeed^2
|
||||
local b = 2 * (D.x*targetSpeed_vec.x + D.y*targetSpeed_vec.y)
|
||||
local c = D.x^2 + D.y^2
|
||||
|
||||
-- 解二次方程
|
||||
local discriminant = b^2 - 4*a*c
|
||||
if a == 0 or discriminant < 0 then return nil end -- 无解
|
||||
|
||||
local t1 = (-b + math.sqrt(discriminant)) / (2*a)
|
||||
local t2 = (-b - math.sqrt(discriminant)) / (2*a)
|
||||
|
||||
-- 取最小正实数解
|
||||
local t = math.huge
|
||||
if t1 > 0 then t = math.min(t, t1) end
|
||||
if t2 > 0 then t = math.min(t, t2) end
|
||||
if t == math.huge then return nil end -- 无有效解
|
||||
|
||||
-- 计算拦截点
|
||||
local intercept_pos = vec_add(myPointVec2, vec_mul(vec_normalize(D), mySpeed * t))
|
||||
|
||||
-- 验证飞行器在[t, t+300]秒内是否进入半径
|
||||
local fly_path_start = vec_add(targetPointVec2, vec_mul(targetSpeed_vec, t))
|
||||
local fly_path_end = vec_add(fly_path_start, vec_mul(targetSpeed_vec, 300))
|
||||
|
||||
-- 计算拦截点到飞行器路径的最短距离
|
||||
local path_vec = vec_sub(fly_path_end, fly_path_start)
|
||||
local path_len = vec_len(path_vec)
|
||||
if path_len == 0 then
|
||||
return vec_len(vec_sub(fly_path_start, intercept_pos)) <= fireRange and intercept_pos or nil
|
||||
end
|
||||
|
||||
local to_intercept = vec_sub(intercept_pos, fly_path_start)
|
||||
local t_proj = (to_intercept.x*path_vec.x + to_intercept.y*path_vec.y) / (path_len^2)
|
||||
t_proj = math.max(0, math.min(1, t_proj)) -- 限制在路径区间内
|
||||
|
||||
local closest_point = vec_add(fly_path_start, vec_mul(path_vec, t_proj))
|
||||
local min_dist = vec_len(vec_sub(closest_point, intercept_pos))
|
||||
|
||||
return min_dist <= fireRange and intercept_pos or nil
|
||||
end
|
||||
|
||||
function PatrolUnit.getPathOnRoads(startPoint_vec3,endPoint_vec3)
|
||||
if not startPoint_vec3 or not endPoint_vec3 then return end
|
||||
|
||||
startPoint_vec3 = Utils.makeVec3(startPoint_vec3)
|
||||
endPoint_vec3 = Utils.makeVec3(endPoint_vec3)
|
||||
|
||||
local points = {}
|
||||
|
||||
local roadPoint_start = {}
|
||||
local roadPoint_end = {}
|
||||
roadPoint_start.x,roadPoint_start.y = land.getClosestPointOnRoads('roads',startPoint_vec3.x,startPoint_vec3.z)
|
||||
roadPoint_end.x,roadPoint_end.y = land.getClosestPointOnRoads('roads',endPoint_vec3.x,endPoint_vec3.z)
|
||||
|
||||
points = {
|
||||
[1] = {
|
||||
x = roadPoint_start.x,
|
||||
y = roadPoint_start.y,
|
||||
speed = math.random(40,60)/3.6,
|
||||
type = AI.Task.WaypointType.TURNING_POINT,
|
||||
action = AI.Task.VehicleFormation.ON_ROAD,
|
||||
},
|
||||
[2] = {
|
||||
x = roadPoint_end.x,
|
||||
y = roadPoint_end.y,
|
||||
speed = math.random(40,60)/3.6,
|
||||
type = AI.Task.WaypointType.TURNING_POINT,
|
||||
action = AI.Task.VehicleFormation.ON_ROAD,
|
||||
},
|
||||
[3] = {
|
||||
x = endPoint_vec3.x,
|
||||
y = endPoint_vec3.z,
|
||||
speed = math.random(40,60)/3.6,
|
||||
type = AI.Task.WaypointType.TURNING_POINT,
|
||||
action = AI.Task.VehicleFormation.OFF_ROAD,
|
||||
},
|
||||
}
|
||||
|
||||
return points
|
||||
end
|
||||
|
||||
function PatrolUnit:CheckVisible(myPoint_vec3, targetPoint_vec3)
|
||||
if not myPoint_vec3 then return end
|
||||
if not targetPoint_vec3 then return end
|
||||
|
||||
myPoint_vec3 = Utils.makeVec3(myPoint_vec3)
|
||||
myPoint_vec3.y = myPoint_vec3.y + self.eyeHight
|
||||
targetPoint_vec3 = Utils.makeVec3(targetPoint_vec3)
|
||||
|
||||
return land.isVisible(myPoint_vec3, targetPoint_vec3)
|
||||
end
|
||||
|
||||
function PatrolUnit._MonitorFunction(vars,time)
|
||||
local self = vars.context
|
||||
local repeatTime = vars.repeatTime
|
||||
|
||||
if not self.group:isExist() then
|
||||
self:Remove()
|
||||
return
|
||||
end
|
||||
|
||||
local myUnit = self.group:getUnit(1)
|
||||
if not myUnit then self:remove() return end
|
||||
if not myUnit:isActive() then return time + repeatTime end
|
||||
if myUnit:getLife() < 1 then self:remove() return end
|
||||
|
||||
local newTargets = self:GetNewTargets()
|
||||
for i, targetUnit in ipairs(newTargets) do
|
||||
if targetUnit then
|
||||
if targetUnit:isActive() and targetUnit:getLife() >= 1 then
|
||||
if self.DebugMod then
|
||||
Utils.Debug('checking target: '..targetUnit:getName())
|
||||
end
|
||||
|
||||
-- 获取坐标
|
||||
local myPoint = myUnit:getPoint()
|
||||
local targetPoint = targetUnit:getPoint()
|
||||
|
||||
-- 目标运动参数
|
||||
local targetVelocity = targetUnit:getVelocity()
|
||||
local targetSpeed = Utils.mag(targetVelocity)
|
||||
local targetHeading = Utils.getObjHeading(targetUnit)
|
||||
|
||||
local directDistance = Utils.get3DDist(myPoint,targetPoint)
|
||||
-- if directDistance <= self.fireRange and self:CheckVisible(myPoint,targetPoint) then
|
||||
if directDistance <= self.fireRange then
|
||||
local StopRoute = {
|
||||
id = 'StopRoute',
|
||||
params = {
|
||||
value = true,
|
||||
}
|
||||
}
|
||||
|
||||
if self.DebugMod then
|
||||
Utils.Debug('In range, engage target: '..targetUnit:getName())
|
||||
trigger.action.setMarkupPositionEnd(self.MarkID,myPoint)
|
||||
end
|
||||
|
||||
self.controller:setCommand(StopRoute)
|
||||
break
|
||||
end
|
||||
-- if directDistance > self.fireRange or self:CheckVisible(myPoint,targetPoint) then
|
||||
if directDistance > self.fireRange then
|
||||
local StopRoute = {
|
||||
id = 'StopRoute',
|
||||
params = {
|
||||
value = false,
|
||||
}
|
||||
}
|
||||
|
||||
if self.DebugMod then
|
||||
Utils.Debug('Continue route')
|
||||
end
|
||||
|
||||
self.controller:setCommand(StopRoute)
|
||||
end
|
||||
|
||||
local interceptPoint = self.calculate_intercept_point({x=myPoint.x,y=myPoint.z},self.speed,{x=targetPoint.x,y=targetPoint.z},targetSpeed,targetHeading,self.fireRange)
|
||||
-- local interceptPoint = nil
|
||||
-- for i=1,100,1 do
|
||||
-- local temp_interceptPoint = self.calculate_intercept_point({x=myPoint.x,y=myPoint.z},self.speed,{x=targetPoint.x,y=targetPoint.z},targetSpeed,targetHeading,self.fireRange)
|
||||
|
||||
-- if self:CheckVisible(interceptPoint,targetPoint) then
|
||||
-- interceptPoint = temp_interceptPoint
|
||||
-- break
|
||||
-- end
|
||||
-- end
|
||||
|
||||
if interceptPoint then
|
||||
|
||||
if self.DebugMod then
|
||||
trigger.action.setMarkupPositionEnd(self.MarkID,Utils.makeVec3(interceptPoint))
|
||||
Utils.Debug('Intercepting target: '..targetUnit:getName())
|
||||
end
|
||||
|
||||
local wayPoints = self.getPathOnRoads(myPoint,interceptPoint)
|
||||
if wayPoints then
|
||||
local Mission = {
|
||||
id = 'Mission',
|
||||
params = {
|
||||
route = {
|
||||
points = wayPoints
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.DebugMod then
|
||||
Utils.Debug('wayPoints set.')
|
||||
end
|
||||
|
||||
self.controller:setTask(Mission)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return time + repeatTime
|
||||
end
|
||||
|
||||
function PatrolUnit:start(Delay,RepeatScanSeconds)
|
||||
local tDelay = Delay or PatrolUnit.MonitorStartDelay
|
||||
PatrolUnit.MonitorStartDelay = tDelay + 1
|
||||
|
||||
local RepeatScanInterval = RepeatScanSeconds or PatrolUnit.MonitorRepeatTime
|
||||
|
||||
if self.MonitorID then
|
||||
self:stop()
|
||||
end
|
||||
|
||||
self.MonitorID = timer.scheduleFunction(self._MonitorFunction,{context = self,repeatTime = RepeatScanInterval},timer.getTime() + tDelay)
|
||||
end
|
||||
|
||||
function PatrolUnit:stop()
|
||||
if not self.MonitorID then return end
|
||||
|
||||
timer.removeFunction(self.MonitorID)
|
||||
self.MonitorID = nil
|
||||
end
|
||||
|
||||
|
||||
local patrolGroupName = 'Red-Patrol-AAA-'
|
||||
for i=1,30,1 do
|
||||
if not Group.getByName(patrolGroupName..i) then return end
|
||||
PatrolUnit:New(patrolGroupName..i)
|
||||
end
|
||||
|
||||
-- local unit = Unit.getByName('Red-Patrol-AAA-8-1')
|
||||
-- Utils.Debug(mist.utils.tableShow(unit:getDesc()))
|
||||
end
|
||||
@@ -49,6 +49,8 @@ do
|
||||
end
|
||||
|
||||
function Utils.getTableSize(table)
|
||||
if not table then return end
|
||||
|
||||
local tableSize = 0
|
||||
for _,_ in pairs(table) do
|
||||
tableSize = tableSize + 1
|
||||
@@ -145,6 +147,20 @@ do
|
||||
return Utils.mag({x = point1.x - point2.x, y = 0, z = point1.z - point2.z})
|
||||
end
|
||||
|
||||
--- Returns distance in meters between two points in 3D space.
|
||||
-- @tparam Vec3 point1 first point
|
||||
-- @tparam Vec3 point2 second point
|
||||
-- @treturn number distancen between given points in 3D space.
|
||||
function Utils.get3DDist(point1, point2)
|
||||
if not point1 then
|
||||
log:warn("Utils.get3DDist 1st input value is nil")
|
||||
end
|
||||
if not point2 then
|
||||
log:warn("Utils.get3DDist 2nd input value is nil")
|
||||
end
|
||||
return Utils.mag({x = point1.x - point2.x, y = point1.y - point2.y, z = point1.z - point2.z})
|
||||
end
|
||||
|
||||
-- @return radians
|
||||
function Utils.getObjHeading(object)
|
||||
if not object then return false end
|
||||
|
||||
@@ -0,0 +1,582 @@
|
||||
-- hanle miscellaneous mission events
|
||||
|
||||
--Red alarm when under attack
|
||||
local redAlarmEvent = {
|
||||
DebugMode = false,
|
||||
redAlarm = false,
|
||||
ignoreList = {
|
||||
['Red-RescueInf-1'] = true,
|
||||
['Red-Scud'] = true,
|
||||
},
|
||||
alarmOffGroups = {
|
||||
['Red-PowerStation-1'] = true,
|
||||
},
|
||||
}
|
||||
do
|
||||
|
||||
function redAlarmEvent:redAlarm_On()
|
||||
if self.redAlarm then return end
|
||||
|
||||
Utils.Debug('==================\n\n敌人因为受到攻击, 拉响了警报!\n\n==================')
|
||||
self.redAlarm = true
|
||||
local redGrounds = coalition.getGroups(1,Group.Category.GROUND)
|
||||
|
||||
for i, group in ipairs(redGrounds) do
|
||||
local groupIsActivate = true
|
||||
for i,unit in ipairs(group:getUnits()) do
|
||||
if not unit:isActive() then
|
||||
groupIsActivate = false
|
||||
end
|
||||
end
|
||||
|
||||
if not groupIsActivate and not redAlarmEvent.ignoreList[group:getName()] then
|
||||
|
||||
if redAlarmEvent.DebugMode then
|
||||
Utils.Debug('Activate Group: '..group:getName())
|
||||
end
|
||||
timer.scheduleFunction(function (group)
|
||||
group:activate()
|
||||
end,group,timer.getTime()+math.random(120,600))
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
function redAlarmEvent:onEvent(event)
|
||||
if not self.redAlarm then
|
||||
if event.id == world.event.S_EVENT_KILL then
|
||||
local object = event.target
|
||||
if not object then return end
|
||||
if not object:isExist() then return end
|
||||
|
||||
if not object.getCoalition then return end
|
||||
if object:getCoalition() ~= coalition.side.RED then return end
|
||||
|
||||
for groupName, value in pairs(redAlarmEvent.alarmOffGroups) do
|
||||
|
||||
if redAlarmEvent.DebugMode then
|
||||
Utils.Debug('redAlarmEvent - Trigger Group: '..object:getName())
|
||||
Utils.Debug('redAlarmEvent - groupName: '..groupName)
|
||||
end
|
||||
|
||||
if object:getName() == groupName then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local objectCategory, unitCategory = Object.getCategory(object)
|
||||
if objectCategory == Object.Category.UNIT then
|
||||
if unitCategory == Unit.Category.GROUND_UNIT or unitCategory == Unit.Category.STRUCTURE then
|
||||
if math.random(1,10) <= 4 then
|
||||
self:redAlarm_On()
|
||||
world.removeEventHandler(redAlarmEvent)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if objectCategory == Object.Category.STATIC then
|
||||
if math.random(1,10) == 1 then
|
||||
self:redAlarm_On()
|
||||
world.removeEventHandler(redAlarmEvent)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
world.addEventHandler(redAlarmEvent)
|
||||
end
|
||||
|
||||
-- Power Station
|
||||
do
|
||||
local PowerStationEvent = {
|
||||
connectedGroupList = {
|
||||
'Red-EWR-CRAM-1',
|
||||
'Red-CWStorage-CRAM-1',
|
||||
'Red-SAMSite-CRAM-1',
|
||||
'Red-EWR-1',
|
||||
'Red-Rescue-SAM-1',
|
||||
},
|
||||
replaceStatics = {
|
||||
['Static M92 Container watchtower lights-1'] = {
|
||||
ori = 'Container_watchtower_lights',
|
||||
replace = 'Container_watchtower',
|
||||
},
|
||||
['Static M92 Container watchtower lights-2-1'] = {
|
||||
ori = 'Container_watchtower_lights',
|
||||
replace = 'Container_watchtower',
|
||||
},
|
||||
['Static M92 Container watchtower lights-3-1'] = {
|
||||
ori = 'Container_watchtower_lights',
|
||||
replace = 'Container_watchtower',
|
||||
},
|
||||
['Static M92 Container watchtower lights-4-1'] = {
|
||||
ori = 'Container_watchtower_lights',
|
||||
replace = 'Container_watchtower',
|
||||
},
|
||||
['Static M92 Container watchtower lights-5-1'] = {
|
||||
ori = 'Container_watchtower_lights',
|
||||
replace = 'Container_watchtower',
|
||||
},
|
||||
['静态 M92 集装箱瞭望塔(有灯光)-1-1'] = {
|
||||
ori = 'Container_watchtower_lights',
|
||||
replace = 'Container_watchtower',
|
||||
},
|
||||
['静态 M92 集装箱瞭望塔(有灯光)-2-1'] = {
|
||||
ori = 'Container_watchtower_lights',
|
||||
replace = 'Container_watchtower',
|
||||
},
|
||||
|
||||
['Static M92 NF-2 LightOn-1-1'] = {
|
||||
ori = 'NF-2_LightOn',
|
||||
replace = 'NF-2_LightOff01',
|
||||
},
|
||||
['Static M92 NF-2_LightOn-2-1'] = {
|
||||
ori = 'NF-2_LightOn',
|
||||
replace = 'NF-2_LightOff01',
|
||||
},
|
||||
['静态 M92 NF-2 泛光灯组(打开)-1-1'] = {
|
||||
ori = 'NF-2_LightOn',
|
||||
replace = 'NF-2_LightOff01',
|
||||
},
|
||||
['静态 M92 NF-2 泛光灯组(打开)-2-1'] = {
|
||||
ori = 'NF-2_LightOn',
|
||||
replace = 'NF-2_LightOff01',
|
||||
},
|
||||
['静态 M92 NF-2 泛光灯组(打开)-3-1'] = {
|
||||
ori = 'NF-2_LightOn',
|
||||
replace = 'NF-2_LightOff01',
|
||||
},
|
||||
['静态 M92 NF-2 泛光灯组(打开)-4-1'] = {
|
||||
ori = 'NF-2_LightOn',
|
||||
replace = 'NF-2_LightOff01',
|
||||
},
|
||||
['静态 M92 NF-2 泛光灯组(打开)-5-1'] = {
|
||||
ori = 'NF-2_LightOn',
|
||||
replace = 'NF-2_LightOff01',
|
||||
},
|
||||
['静态 M92 NF-2 泛光灯组(打开)-6-1'] = {
|
||||
ori = 'NF-2_LightOn',
|
||||
replace = 'NF-2_LightOff01',
|
||||
},
|
||||
['静态 M92 NF-2 泛光灯组(打开)-7-1'] = {
|
||||
ori = 'NF-2_LightOn',
|
||||
replace = 'NF-2_LightOff01',
|
||||
},
|
||||
['静态 M92 NF-2 泛光灯组(打开)-8-1'] = {
|
||||
ori = 'NF-2_LightOn',
|
||||
replace = 'NF-2_LightOff01',
|
||||
},
|
||||
},
|
||||
newStaticObjs = {},
|
||||
}
|
||||
function PowerStationEvent:onEvent(event)
|
||||
if event.id == world.event.S_EVENT_DEAD then
|
||||
local object = event.initiator
|
||||
if not object.getName then return end
|
||||
|
||||
if object:getName() == 'Red-PowerStation-1' then
|
||||
-- 关闭防空
|
||||
for i, groupName in ipairs(PowerStationEvent.connectedGroupList) do
|
||||
local group = Group.getByName(groupName)
|
||||
if group then
|
||||
if group:isExist() and group:getUnits() then
|
||||
local groupIsAlive = false
|
||||
for i, unit in ipairs(group:getUnits()) do
|
||||
if unit:getLife() >= 1 then
|
||||
groupIsAlive= true
|
||||
end
|
||||
end
|
||||
|
||||
if not groupIsAlive then
|
||||
group = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--关闭
|
||||
timer.scheduleFunction(function (group)
|
||||
if not group then return end
|
||||
if not group:isExist() then return end
|
||||
trigger.action.setGroupAIOff(group)
|
||||
end,group,timer.getTime()+math.random(1,10))
|
||||
|
||||
--开启
|
||||
timer.scheduleFunction(function (group)
|
||||
if not group then return end
|
||||
if not group:isExist() then return end
|
||||
trigger.action.setGroupAIOn(group)
|
||||
end,group,timer.getTime()+math.random(180,900))
|
||||
end
|
||||
|
||||
-- 关闭静态物体灯光
|
||||
local objectIndex = 1
|
||||
for groupName, staticData in pairs(PowerStationEvent.replaceStatics) do
|
||||
local staticLight = StaticObject.getByName(groupName)
|
||||
if staticLight then
|
||||
|
||||
local staticPoint = staticLight:getPoint()
|
||||
local staticType_Ori = staticLight:getTypeName()
|
||||
local staticType_Replace = PowerStationEvent.replaceStatics[groupName].replace
|
||||
-- local staticeHeading = math.deg(Utils.getObjHeading(staticLight))
|
||||
local staticeHeading = Utils.getObjHeading(staticLight)
|
||||
local countryId = staticLight:getCountry()
|
||||
|
||||
--- 记录初始状态
|
||||
local staticData = {}
|
||||
-- 记录位置
|
||||
staticData.name = 'lightsOff-'..objectIndex
|
||||
objectIndex = objectIndex + 1
|
||||
staticData.type = staticType_Replace
|
||||
|
||||
staticData.x = staticPoint.x
|
||||
staticData.y = staticPoint.z
|
||||
-- 记录方向
|
||||
staticData.heading = staticeHeading
|
||||
|
||||
--关闭
|
||||
timer.scheduleFunction(function (args)
|
||||
-- 删除旧物体
|
||||
args.staticLight:destroy()
|
||||
-- 刷新新物体
|
||||
timer.scheduleFunction(function (vars)
|
||||
local newStaticObj = coalition.addStaticObject(vars.countryId,vars.staticData)
|
||||
if newStaticObj then
|
||||
PowerStationEvent.replaceStatics[vars.groupName].newObj = newStaticObj
|
||||
end
|
||||
end,{groupName = args.groupName,staticData = args.staticData,countryId = args.countryId},timer.getTime()+0.1)
|
||||
end,{groupName = groupName,staticLight = staticLight,staticData = staticData,countryId = countryId},timer.getTime()+math.random(3,10)*0.1)
|
||||
|
||||
--开启
|
||||
timer.scheduleFunction(function (args)
|
||||
-- 删除旧物体
|
||||
PowerStationEvent.replaceStatics[groupName].newObj:destroy()
|
||||
-- 刷新新物体.
|
||||
timer.scheduleFunction(function (vars)
|
||||
vars.staticData.name = vars.groupName
|
||||
vars.staticData.type = PowerStationEvent.replaceStatics[vars.groupName].ori
|
||||
local newStaticObj = coalition.addStaticObject(vars.countryId,vars.staticData)
|
||||
end,{groupName = args.groupName,staticData = args.staticData,countryId = args.countryId},timer.getTime()+0.1)
|
||||
end,{groupName = groupName,staticData = staticData,countryId = countryId},timer.getTime()+math.random(180,900))
|
||||
end
|
||||
end
|
||||
|
||||
world.removeEventHandler(PowerStationEvent)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
world.addEventHandler(PowerStationEvent)
|
||||
end
|
||||
|
||||
-- Mines
|
||||
do
|
||||
Mines = {}
|
||||
|
||||
Mines.DebugMod = false
|
||||
Mines.DetectionRange = 1500
|
||||
Mines.FireRange = 300
|
||||
|
||||
Mines.TriggerExplode = 0.5 --kg
|
||||
Mines.Warhead_AH = 3 --kg
|
||||
|
||||
Mines.Warhead_AG = 6 --kg
|
||||
|
||||
Mines.MonitorStartDelay = 1
|
||||
Mines.MonitorRepeatTime = 30
|
||||
Mines.ActivatedMonitorRepeatTime = 2
|
||||
|
||||
Mines.MineFieldZonePolygon = Utils.getWayPoints('mineZoneGroup-1')
|
||||
|
||||
if Utils.getTableSize(Mines.MineFieldZonePolygon) < 3 then
|
||||
if Mines.DebugMod then
|
||||
Utils.Debug('Misc.lua - Mines: MineFieldZonePolygon has not enough waypoints.')
|
||||
end
|
||||
return
|
||||
end
|
||||
-- DrawMineZone
|
||||
Utils.drawPolygon(-1,Utils.getMarkID(),Mines.MineFieldZonePolygon,{0,0,0,0.1},{0,0,0,0.1},2)
|
||||
|
||||
|
||||
Mines.AllMines = {}
|
||||
|
||||
function Mines:New(staticObject)
|
||||
if not staticObject then return end
|
||||
|
||||
local obj = {}
|
||||
obj.staticObject = staticObject
|
||||
obj.staticObjectName = staticObject:getName()
|
||||
obj.point = staticObject:getPoint()
|
||||
|
||||
if Mines.DebugMod then
|
||||
trigger.action.circleToAll(-1,Utils.getMarkID(),obj.point,Mines.DetectionRange,{1,0,0,1},{1,0,0,0.3},2)
|
||||
trigger.action.circleToAll(-1,Utils.getMarkID(),obj.point,Mines.FireRange,{1,0,0,1},{1,0,0,0.5},1)
|
||||
end
|
||||
|
||||
setmetatable(obj, self)
|
||||
self.__index = self
|
||||
|
||||
Mines.AllMines[obj.staticObjectName] = obj
|
||||
obj:Start()
|
||||
|
||||
return obj
|
||||
end
|
||||
|
||||
function Mines:Remove(removeStatic)
|
||||
if not Mines.AllMines[self.staticObjectName] then return end
|
||||
self:ActivatedMonitorStop()
|
||||
self:Stop()
|
||||
|
||||
if removeStatic then
|
||||
if self.staticObject then
|
||||
if self.staticObject:isExist() then
|
||||
self.staticObject:destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Mines.AllMines[self.staticObjectName] = nil
|
||||
end
|
||||
|
||||
function Mines:TriggerActive(targetPoint,targetSpeed,targetHeading)
|
||||
if not targetPoint then return end
|
||||
if type(targetPoint) ~= 'table' then return end
|
||||
|
||||
if not self.staticObject:isExist() then
|
||||
self:Remove()
|
||||
return
|
||||
end
|
||||
|
||||
if self.staticObject:getLife() < 1 then
|
||||
self:Remove()
|
||||
return
|
||||
end
|
||||
|
||||
-- trigger explode
|
||||
trigger.action.explosion(self.point,Mines.TriggerExplode)
|
||||
self:Remove(true)
|
||||
|
||||
-- Warhead_AH explode
|
||||
local shellTravelTime = math.random(3,5)*0.1
|
||||
local predictedExplodePoint = Utils.vecTranslate(targetPoint,targetHeading,(targetSpeed*shellTravelTime))
|
||||
predictedExplodePoint.z = predictedExplodePoint.y
|
||||
predictedExplodePoint.y = targetPoint.y
|
||||
|
||||
timer.scheduleFunction(function (predictedExplodePoint)
|
||||
|
||||
local explodePoint = Utils.deepCopy(predictedExplodePoint)
|
||||
|
||||
-- x
|
||||
if math.random(1,10) >= 5 then
|
||||
explodePoint.x = explodePoint.x + math.random(25,80)*0.1
|
||||
else
|
||||
explodePoint.x = explodePoint.x - math.random(25,80)*0.1
|
||||
end
|
||||
|
||||
-- z
|
||||
if math.random(1,10) >= 5 then
|
||||
explodePoint.z = explodePoint.z + math.random(25,80)*0.1
|
||||
else
|
||||
explodePoint.z = explodePoint.z - math.random(25,80)*0.1
|
||||
end
|
||||
|
||||
-- y
|
||||
if math.random(1,10) >= 5 then
|
||||
explodePoint.y = explodePoint.y + math.random(0,50)*0.1
|
||||
else
|
||||
explodePoint.y = explodePoint.y - math.random(0,50)*0.1
|
||||
end
|
||||
|
||||
trigger.action.explosion(explodePoint,Mines.Warhead_AH)
|
||||
end,predictedExplodePoint,timer.getTime()+shellTravelTime)
|
||||
end
|
||||
|
||||
function Mines._ActivatedMonitorFunction(vars,time)
|
||||
local self = vars.context
|
||||
local repeatTime = vars.repeatTime
|
||||
|
||||
if Mines.DebugMod then
|
||||
Utils.Debug('_ActivatedMonitorFunction.')
|
||||
end
|
||||
|
||||
local target = vars.target
|
||||
if not target then return end
|
||||
if not target:isExist() then return end
|
||||
if target:getLife() < 1 then return end
|
||||
|
||||
local targetPoint = target:getPoint()
|
||||
local Distance = Utils.get3DDist(targetPoint,self.point)
|
||||
|
||||
if Mines.DebugMod then
|
||||
Utils.Debug('Distance: '..Distance)
|
||||
end
|
||||
|
||||
if Distance > Mines.DetectionRange then
|
||||
if Mines.DebugMod then
|
||||
Utils.Debug('Enemy unit out mine DetectionRange.')
|
||||
end
|
||||
|
||||
self:ActivatedMonitorStop()
|
||||
self:Start(1)
|
||||
return
|
||||
end
|
||||
|
||||
if Distance <= Mines.FireRange then
|
||||
local chance = math.random(1,10)
|
||||
if chance >= 5 then
|
||||
|
||||
local targetSpeed = Utils.mag(target:getVelocity())
|
||||
local targetHeading = math.deg(Utils.getObjHeading(target))
|
||||
|
||||
trigger.action.outText(target:getName()..'触发了防空地雷!',10)
|
||||
self:TriggerActive(targetPoint,targetSpeed,targetHeading)
|
||||
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
return time + repeatTime
|
||||
end
|
||||
|
||||
function Mines:ActivatedMonitorStart(target,Delay,RepeatScanSeconds)
|
||||
if not target then return end
|
||||
|
||||
Mines.MonitorStartDelay = Delay or Mines.MonitorStartDelay
|
||||
|
||||
local tDelay = Delay or Mines.MonitorStartDelay
|
||||
|
||||
local RepeatScanInterval = RepeatScanSeconds or Mines.ActivatedMonitorRepeatTime
|
||||
|
||||
if self.ActivatedMonitorID then
|
||||
self:ActivatedMonitorStop()
|
||||
end
|
||||
|
||||
self.ActivatedMonitorID = timer.scheduleFunction(self._ActivatedMonitorFunction,{target = target,context = self,repeatTime = RepeatScanInterval},timer.getTime() + tDelay)
|
||||
end
|
||||
|
||||
function Mines:ActivatedMonitorStop()
|
||||
if not self.ActivatedMonitorID then return end
|
||||
|
||||
timer.removeFunction(self.ActivatedMonitorID)
|
||||
self.ActivatedMonitorID = nil
|
||||
end
|
||||
|
||||
function Mines:CheckEnemyInDetectionRange(enemyGroup)
|
||||
if enemyGroup:isExist() then
|
||||
for j,unit in ipairs(enemyGroup:getUnits()) do
|
||||
if unit:getLife() > 1 then
|
||||
local enemyPoint = unit:getPoint()
|
||||
local Distance = Utils.get3DDist(enemyPoint,self.point)
|
||||
|
||||
if Mines.DebugMod then
|
||||
-- Utils.Debug('Distance: '..Distance)
|
||||
end
|
||||
|
||||
if Distance <= self.DetectionRange then
|
||||
if math.random(1,10) < 7 then
|
||||
if Mines.DebugMod then
|
||||
Utils.Debug('Helo unit in mine DetectionRange.')
|
||||
end
|
||||
|
||||
self:ActivatedMonitorStart(unit,1)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function Mines._MonitorFunction(vars,time)
|
||||
local self = vars.context
|
||||
local repeatTime = vars.repeatTime
|
||||
|
||||
if Mines.DebugMod then
|
||||
-- Utils.Debug('_MonitorFunction')
|
||||
end
|
||||
|
||||
--AG
|
||||
local enemyGroundGroups = coalition.getGroups(coalition.side.BLUE,Group.Category.GROUND)
|
||||
for i,group in ipairs(enemyGroundGroups) do
|
||||
for j,unit in ipairs(group:getUnits()) do
|
||||
local enemyPoint = unit:getPoint()
|
||||
if Utils.pointInPolygon(enemyPoint, Mines.MineFieldZonePolygon) then
|
||||
if Mines.DebugMod then
|
||||
Utils.Debug('Ground unit in mine polygon.')
|
||||
end
|
||||
|
||||
local chance = math.random(1,100)
|
||||
if chance > 70 then
|
||||
trigger.action.explosion(enemyPoint,Mines.Warhead_AG)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--AH
|
||||
local enemyHeloGroups = coalition.getGroups(coalition.side.BLUE,Group.Category.HELICOPTER)
|
||||
for i,group in ipairs(enemyHeloGroups) do
|
||||
if self:CheckEnemyInDetectionRange(group) then
|
||||
self:Stop()
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
local enemyPlaneGroups = coalition.getGroups(coalition.side.BLUE,Group.Category.AIRPLANE)
|
||||
for i,group in ipairs(enemyPlaneGroups) do
|
||||
if self:CheckEnemyInDetectionRange(group) then
|
||||
self:Stop()
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return time + repeatTime
|
||||
end
|
||||
|
||||
function Mines:Start(Delay,RepeatScanSeconds)
|
||||
Mines.MonitorStartDelay = Delay or Mines.MonitorStartDelay
|
||||
|
||||
local tDelay = Delay or Mines.MonitorStartDelay
|
||||
Mines.MonitorStartDelay = Mines.MonitorStartDelay + 1
|
||||
|
||||
local RepeatScanInterval = RepeatScanSeconds or Mines.MonitorRepeatTime
|
||||
|
||||
if self.MonitorID then
|
||||
self:Stop()
|
||||
end
|
||||
|
||||
self.MonitorID = timer.scheduleFunction(self._MonitorFunction,{context = self,repeatTime = RepeatScanInterval},timer.getTime() + tDelay)
|
||||
end
|
||||
|
||||
function Mines:Stop()
|
||||
if not self.MonitorID then return end
|
||||
|
||||
timer.removeFunction(self.MonitorID)
|
||||
self.MonitorID = nil
|
||||
end
|
||||
|
||||
--- Init
|
||||
for i=1,200,1 do
|
||||
local myMinesStaticObjName = 'Static Barrel-'..i..'-1'
|
||||
local myMineStaticObj = StaticObject.getByName(myMinesStaticObjName)
|
||||
if myMineStaticObj then
|
||||
local myMine = Mines:New(myMineStaticObj)
|
||||
end
|
||||
|
||||
-- Add mines to alarm ignore
|
||||
redAlarmEvent.alarmOffGroups[myMinesStaticObjName] = true
|
||||
end
|
||||
|
||||
-- Add Patrol to alarm ignore
|
||||
if PatrolUnit then
|
||||
if PatrolUnit.AllGroups then
|
||||
for groupName, value in ipairs(PatrolUnit.AllGroups) do
|
||||
redAlarmEvent.alarmOffGroups[groupName] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,27 @@
|
||||
# 红方
|
||||
- 激光干扰车
|
||||
- 检查站馕言文配音
|
||||
- 接近结束前, 红方会用火箭弹轰炸前线直升机起降点
|
||||
- 反直升机地雷
|
||||
|
||||
# 蓝方
|
||||
## Eagle
|
||||
- 制空
|
||||
- 初次跟Mig29S交锋
|
||||
|
||||
## Enfield
|
||||
- 侦察
|
||||
- 压制雷达
|
||||
|
||||
## Shrike
|
||||
- 低空侦察
|
||||
- 跟敌人小规模交战: 会有巡逻队主动打他们
|
||||
|
||||
## Hook
|
||||
- 建立前线FARP
|
||||
- 预设几个FARP可选区域, 摆放友军单位
|
||||
- 离得太近会引来巡逻队
|
||||
|
||||
## Ground
|
||||
- 抵近侦察
|
||||
- 协助防空圈
|
||||
|
After Width: | Height: | Size: 7.1 MiB |
|
After Width: | Height: | Size: 6.8 MiB |
|
After Width: | Height: | Size: 5.5 MiB |
|
After Width: | Height: | Size: 7.6 MiB |
|
After Width: | Height: | Size: 5.2 MiB |
|
After Width: | Height: | Size: 4.4 MiB |
|
After Width: | Height: | Size: 6.2 MiB |
|
After Width: | Height: | Size: 4.6 MiB |
|
After Width: | Height: | Size: 6.7 MiB |
|
After Width: | Height: | Size: 6.8 MiB |
|
After Width: | Height: | Size: 6.9 MiB |
|
After Width: | Height: | Size: 5.3 MiB |
|
After Width: | Height: | Size: 4.7 MiB |
|
After Width: | Height: | Size: 3.9 MiB |
|
After Width: | Height: | Size: 2.8 MiB |
|
After Width: | Height: | Size: 2.8 MiB |