-
Notifications
You must be signed in to change notification settings - Fork 3
/
waypoints.lua
82 lines (66 loc) · 1.73 KB
/
waypoints.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require("utils")
function isClient(units)
for _,unit in ipairs(units) do
if unit.skill == "Client" then
return true
end
end
return false
end
function shouldSkip(units)
if not ignore then return false end
for _,unit in ipairs(units) do
if ignore[unit.type] then
return true
end
end
return false
end
function getRouteFromGroup(groupname, countries)
for _,country in ipairs(countries) do
if country.plane and country.plane.group then
for _,group in ipairs(country.plane.group) do
if group.name == groupname then
return group.route
end
end
end
end
end
function copyRoute(source, destination)
for i,v in ipairs(source) do
if i~=1 then
destination[i] = v
end
end
end
function updateRoute(route, groups)
for _,group in ipairs(groups) do
if isClient(group.units) and not shouldSkip(group.units) then
print("Updating "..group.name.." ["..group.units[1].type.."]")
group.route.points = { group.route.points[1] }
copyRoute(route.points, group.route.points)
end
end
end
dofile(arg[1])
dofile('ignore.lua')
for coalition,_ in pairs(mission.coalition) do
local countries = mission.coalition[coalition].country
templateGroup = "route-template-"..coalition
local route = getRouteFromGroup(templateGroup, countries)
if not route then
print("\nNo group named '"..templateGroup.."' found to copy waypoints from. Skipping coalition")
else
print("\nCopying '"..templateGroup.."'")
for _,country in ipairs(countries) do
if country.plane and country.plane.group then
updateRoute(route, country.plane.group)
end
if country.helicopter and country.helicopter.group then
updateRoute(route, country.helicopter.group)
end
end
end
end
utils.saveTable(arg[2], 'mission', mission)