14 Commits
Author SHA1 Message Date
XiaoChen c55b615554 - fix bugs for event listener
- change redalarm triggered by random(seems not work as expected)
2025-04-10 21:13:11 +08:00
XiaoChen ec3178c2d6 Update first playable version
- add brief
- fix event handler bugs
2025-04-04 18:02:54 +08:00
XiaoChen d1cdac51a8 Add first version of PowerStationEvent effect(Ver1.0) 2025-04-02 00:42:56 +08:00
XiaoChen 094a79d317 Fix code error 2025-03-31 23:01:44 +08:00
XiaoChen 18000d33ec Add patrol logic ver1.0 2025-03-31 22:59:44 +08:00
XiaoChen f0f158b85d update file list 2025-03-31 22:59:21 +08:00
XiaoChen 511a852c4d Add miscellaneous scripts:
- add red alarm event
- add Power Station event(not done)
2025-03-31 22:59:08 +08:00
XiaoChen 82f76d4d77 Add new lazer codes 2025-03-31 22:57:04 +08:00
XiaoChen a7cfe2137e Update miz file for mission stroies & simple triggers 2025-03-31 22:56:48 +08:00
XiaoChen 365bc3395e Update map 2025-03-25 21:06:12 +08:00
XiaoChen 1183f25802 Init LazerJammer 2025-03-25 21:06:03 +08:00
XiaoChen 0c1114c20a Note ideas 2025-03-25 21:05:50 +08:00
XiaoChen 355921ce5d Update map locations 2025-03-24 19:09:37 +08:00
XiaoChen 4a46af3bf1 - 2025-03-24 10:58:13 +08:00
28 changed files with 1259 additions and 1 deletions
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
+5
View File
@@ -0,0 +1,5 @@
AH64: MGRS GRID: 37 S DU 27680 19875
Cargo:
N34°36'33"
E38°14'34"
+189
View File
@@ -0,0 +1,189 @@
local markIDCounter = 10
local function drawMarks(dmsTable,color)
for i,dms in ipairs(dmsTable) do
local newDecimal = {
lat = dms.lat,
lon = dms.lon,
}
if type(dms.lat) ~= 'number' or type(dms.lon) ~= 'number' then
newDecimal.lat = dms_to_decimal(dms.lat)
newDecimal.lon = dms_to_decimal(dms.lon)
end
local newPoint = coord.LLtoLO(newDecimal.lat,newDecimal.lon)
local newMarkID = markIDCounter
markIDCounter = markIDCounter + 1
local drawColor = {
ring = {0,0,1,1},
fill = {0,0,1,0.5},
}
if string.match(dms.name, "^Red%f[%s]") == 'Red' then
drawColor = {
ring = {1,0,0,1},
fill = {1,0,0,0.5},
}
end
if string.match(dms.name, "^Neutral%f[%s]") == 'Neutral' then
drawColor = {
ring = {1,1,1,1},
fill = {0,1,1,0.5},
}
end
if color then
if color == 1 then
drawColor = {
ring = {1,0,0,1},
fill = {1,0,0,0.5},
}
end
if color == -1 then
drawColor = {
ring = {1,1,1,1},
fill = {0,1,1,0.5},
}
end
end
trigger.action.circleToAll(-1,newMarkID,newPoint,100,drawColor.ring,drawColor.fill,1)
local textPoint = newPoint
textPoint.x = textPoint.x + 500
local textId = markIDCounter
markIDCounter = markIDCounter + 1
trigger.action.textToAll(-1,textId,textPoint,drawColor.ring,{1,1,0,0.3},12,false,dms.name)
end
end
local EventCoords = {
{name="阿勒颇战役(2012-2016)", lat=36.2023, lon=37.1345}, -- 战略交通枢纽[2,6,7,8](@ref)
{name="霍姆斯围城战(2011-2014)", lat=34.7333, lon=36.7167}, -- 早期抗议核心区[1,2,7,8](@ref)
{name="德拉省冲突(2011-)", lat=32.6250, lon=36.1000}, -- 起义发源地[1,4,8](@ref)
{name="伊德利卜省冲突(2015-)", lat=35.9306, lon=36.6339}, -- 反对派最后据点[1,6,7,8](@ref)
{name="哈马省冲突(2011-)", lat=35.1333, lon=36.7500}, -- 反复争夺的农业区[1,2,7,8](@ref)
{name="代尔祖尔争夺战(2014-2019)", lat=35.3333, lon=40.1500}, -- 油田争夺焦点[6,7](@ref)
{name="大马士革陷落(2024)", lat=33.5131, lon=36.2919}, -- 首都政权更迭[2,6,7,8](@ref)
{name="拉塔基亚省仇杀事件(2025)", lat=35.5167, lon=35.7833}, -- 阿拉维派聚居区[5,6](@ref)
{name="戈兰高地争夺(1967-)", lat=33.1253, lon=35.8246} -- 以叙争议区[2,7,8](@ref)
}
local EventCoords2 = {
-- 历史冲突坐标(保留核心事件)
{name="阿勒颇战役(2012-2016)", lat=36.2023, lon=37.1345}, -- 战略交通枢纽[9](@ref)
{name="霍姆斯围城战(2011-2014)", lat=34.7333, lon=36.7167}, -- 早期抗议核心区[9](@ref)
-- 2024-2025年新增冲突坐标
{name="拉塔基亚省屠杀(2025)", lat=35.5167, lon=35.7833}, -- 阿拉维派聚居区大清洗[3,4](@ref)
{name="塔尔图斯安全行动(2025)", lat=34.8833, lon=35.8833}, -- 俄军基地所在省[2,8](@ref)
{name="苏韦达省德鲁兹反叛(2025)", lat=32.7000, lon=36.5667}, -- 德鲁兹人自治运动[5,9](@ref)
{name="哈法镇处决事件(2025)", lat=35.1500, lon=35.9833}, -- 沿海暴力起点[3](@ref)
{name="戈兰高地全面占领(2025)", lat=33.1253, lon=35.8246}, -- 以色列控制区[8,10](@ref)
{name="大马士革政权更迭(2024)", lat=33.5131, lon=36.2919}, -- 首都权力真空[9](@ref)
{name="赫梅米姆难民潮(2025)", lat=35.4167, lon=35.9167}, -- 俄军庇护所[3,8](@ref)
{name="伊德利卜省化武指控(2025)", lat=35.9306, lon=36.6339} -- 反对派最后据点[2,7](@ref)
}
local yuanbao1 = {
-- 霍姆斯省核心战场
{name="主基地选址:霍姆斯省泰亚斯空军基地周边", lat=34.5667, lon=36.9667},
{name="防空体系:以SA-3", lat=34.8000, lon=36.7167},
{name="ZU-23皮卡车机动部署", lat=34.6833, lon=36.5833},
{name="弹药库与物资枢纽,外围部署T-55坦克(固定),BTR-80机动巡逻", lat=34.5500, lon=38.2833},
{name="​通讯站与指挥中心", lat=34.2167, lon=37.1833},
{name="北部前哨", lat=35.1500, lon=36.7500},
{name="南部前哨", lat=33.6500, lon=36.7667},
{name="T-72部署", lat=34.7333, lon=36.7167},
{name="净水站", lat=34.6833, lon=36.5500},
}
local yuanbao2 = {
-- 主基地:隐蔽山谷中的指挥中心
{name="MainBase", lat=35.2156, lon=36.1289}, -- 霍姆斯东北部山谷
-- 弹药库:分散山洞仓库
{name="AmmoDepot_1", lat=35.1987, lon=36.1012}, -- 主基地西南2公里
{name="AmmoDepot_2", lat=35.2314, lon=36.1423}, -- 主基地东北1.5公里
-- 通讯站:山顶中继站
{name="CommsTower", lat=35.2450, lon=36.1350}, -- 制高点覆盖半径50公里
-- 前哨站:公路监控点
{name="Outpost_M4", lat=35.1678, lon=36.0889}, -- M4公路交叉口
{name="Outpost_Coast", lat=35.1800, lon=35.9900}, -- 海岸公路观察点
-- 物资枢纽:公路+直升机集散地
{name="LogisticsHub", lat=35.2000, lon=36.0500}, -- 山谷入口,连接M4公路
-- 防空阵地:分层防御
{name="SAM_SA3", lat=35.2100, lon=36.1100}, -- SA-3覆盖主基地
{name="AAA_ZU23_Hill", lat=35.2250, lon=36.1250},-- 高射炮阵地
{name="SAM_SA18", lat=35.1900, lon=36.0950}, -- 机动近程防空
-- 机场依赖:Khmeimim空军基地
{name="Airbase_Khmeimim", lat=35.4167, lon=35.9483}
}
local CastleCoords = {
-- 十字军城堡(标志性建模)
{name="Krak des Chevaliers (骑士堡)", lat=34.7560, lon=36.2940}, -- 霍姆斯以西,世界文化遗产,游戏内精细建模
{name="Aleppo Citadel (阿勒颇城堡)", lat=36.1992, lon=37.1628}, -- 阿勒颇市中心,部分损毁但地基可见
{name="Margat Castle (马尔加特堡)", lat=35.1500, lon=35.9500}, -- 塔尔图斯附近,海岸山丘上的十字军遗址
-- 阿拉伯/罗马堡垒(地图粗略标识)
{name="Qala'at Saladin (萨拉丁堡)", lat=35.5970, lon=36.0590}, -- 拉塔基亚以东,山巅防御工事遗迹
{name="Palmyra Fortress (帕尔米拉堡垒)", lat=34.5500, lon=38.2670}, -- 沙漠中的罗马边境哨站(近贝尔神庙)
-- 拜占庭/奥斯曼遗址(地形特征点)
{name="Sahyoun Castle (萨赫永堡)", lat=35.5920, lon=36.3310}, -- 伊德利卜省,双层城墙结构
{name="Apamea Citadel (阿帕梅亚卫城)", lat=35.4180, lon=36.3980}, -- 哈马西北,罗马柱廊旁的防御工事
{name="Raqqa Castle (拉卡城堡遗址)", lat=35.9500, lon=39.0100} -- 幼发拉底河畔,奥斯曼时期废墟(地图东部边缘)
}
local DS1 = {
{name="主基地", lat=35.6123, lon=36.1547}, -- 山谷废弃村庄,隐蔽指挥中心
{name="弹药库A", lat=35.5981, lon=36.1689}, -- 山体隧道存储点
{name="弹药库B", lat=35.6234, lon=36.1422}, -- 人工洞穴分散存储
{name="通讯站", lat=35.6315, lon=36.1318}, -- 制高点无线电中继
{name="前哨站北", lat=35.6452, lon=36.1256}, -- 监控M4公路北段
{name="前哨站南", lat=35.5876, lon=36.1623}, -- 监控山谷入口
{name="物资枢纽", lat=35.6028, lon=36.1824}, -- 小镇仓库+直升机起降点
{name="SA-3阵地", lat=35.6189, lon=36.1385}, -- 远程防空覆盖核心区
{name="ZU-23机动区", lat=35.6073, lon=36.1492}, -- 隘口防空火力网
{name="MiG-29支援机场", lat=35.4011, lon=35.9486}, -- Khmeimim空军基地坐标
{name="备用洞穴", lat=35.5902, lon=36.1721}, -- Khmeimim空军基地坐标
}
local DS2 = {
-- 核心机场 (Mig-29A 起降点)
{name = "Tiyas_AFB", lat = 34.5225, lon = 37.6283}, -- 提亚斯空军基地(T-4),Mig-29A 驻扎点
-- 主基地群(半径15km内)
{name = "Main_Base", lat = 34.7012, lon = 37.8045}, -- 沙漠丘陵区,邻近公路且有天然掩体
{name = "Ammo_Depot", lat = 34.6438, lon = 37.7219}, -- 地下洞穴改造弹药库,距主基地8km
{name = "Comms_Center", lat = 34.7321, lon = 37.8923}, -- 高地通讯站,覆盖半径50km
-- 前哨与防御节点(主基地外围10-20km)
{name = "OP_North", lat = 34.8315, lon = 37.7654}, -- 北部山丘观测点,控制M5公路
{name = "OP_South", lat = 34.5689, lon = 37.8456}, -- 南部ZU-23卡车阵地,封锁沙漠路径
{name = "SAM_Site_SA3", lat = 34.6897, lon = 37.9512}, -- SA-3防空阵地,保护东侧空域
-- 物资网络(MI-8运输覆盖)
{name = "Logistics_Hub", lat = 34.6123, lon = 38.0218}, -- 公路/沙漠交界枢纽,BTR车队集散地
{name = "Mountain_Supply", lat = 34.7854, lon = 37.6129} -- 山地区MI-8空投点(ZU-23皮卡驻扎)
}
local palmyrawar = {
{name = "城堡山观察点", lat = 34.5564, lon = 38.2739},
{name = "贝尔神庙IED", lat = 34.5522, lon = 38.2685},
{name = "罗马剧场机枪", lat = 34.5498, lon = 38.2653},
{name = "西郊检查站", lat = 34.5500, lon = 38.2500},
{name = "南郊雷区中心", lat = 34.5350, lon = 38.2750},
{name = "东郊炮兵阵地", lat = 34.5600, lon = 38.3100},
{name = "Tadmur监狱", lat = 34.5620, lon = 38.2850},
{name = "军事机场", lat = 34.4900, lon = 38.2200},
{name = "北路起点-Qatrah", lat = 34.7328, lon = 36.7137},
{name = "南路起点-Sukhnah", lat = 34.8862, lon = 38.8735},
{name = "俄军空军基地", lat = 35.4140, lon = 35.9488}
}
-- drawMarks(powerplant1,1)
-- drawMarks(palmyrawar)
Utils.Debug("DrawMarks")
+43
View File
@@ -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)
+4 -1
View File
@@ -3,7 +3,10 @@ local script_list =
-- Load order must be correct -- Load order must be correct
'mist_4_5_126.lua', 'mist_4_5_126.lua',
'Utils.lua', 'Utils.lua',
'new.lua', -- 'DrawMarks.lua',
-- 'LazerJammer.lua',
'PatrolUnit.lua',
'misc.lua',
} }
local function load_scripts(path, list) local function load_scripts(path, list)
+393
View File
@@ -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
+16
View File
@@ -49,6 +49,8 @@ do
end end
function Utils.getTableSize(table) function Utils.getTableSize(table)
if not table then return end
local tableSize = 0 local tableSize = 0
for _,_ in pairs(table) do for _,_ in pairs(table) do
tableSize = tableSize + 1 tableSize = tableSize + 1
@@ -145,6 +147,20 @@ 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
--- 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 -- @return radians
function Utils.getObjHeading(object) function Utils.getObjHeading(object)
if not object then return false end if not object then return false end
+582
View File
@@ -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
+27
View File
@@ -0,0 +1,27 @@
# 红方
- 激光干扰车
- 检查站馕言文配音
- 接近结束前, 红方会用火箭弹轰炸前线直升机起降点
- 反直升机地雷
# 蓝方
## Eagle
- 制空
- 初次跟Mig29S交锋
## Enfield
- 侦察
- 压制雷达
## Shrike
- 低空侦察
- 跟敌人小规模交战: 会有巡逻队主动打他们
## Hook
- 建立前线FARP
- 预设几个FARP可选区域, 摆放友军单位
- 离得太近会引来巡逻队
## Ground
- 抵近侦察
- 协助防空圈
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 MiB