@jtff/miztemplate-lib 2.2.0 → 3.0.0-rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/index.js +4 -3
  2. package/lib/jtff-lib-ci.js +1 -307
  3. package/lib/mizlib.js +336 -0
  4. package/lua/lib/Hercules_Cargo.lua +686 -0
  5. package/lua/lib/Moose_.lua +117314 -0
  6. package/lua/lib/Splash_Damage_2_0.lua +472 -0
  7. package/lua/lib/gemman.lua +1 -0
  8. package/lua/lib/mist_4_5_107.lua +9084 -0
  9. package/lua/lib/skynet-iads-compiled.lua +3864 -0
  10. package/lua/settings/settings-RAT.lua +235 -0
  11. package/lua/settings/settings-airboss.lua +142 -0
  12. package/lua/settings/settings-atis.lua +31 -0
  13. package/lua/settings/settings-awacs.lua +58 -0
  14. package/lua/settings/settings-awacsondemand.lua +26 -0
  15. package/lua/settings/settings-beacons.lua +10 -0
  16. package/lua/settings/settings-capwarzone.lua +164 -0
  17. package/lua/settings/settings-capzone.lua +32 -0
  18. package/lua/settings/settings-fac_ranges.lua +17 -0
  19. package/lua/settings/settings-foxzone.lua +14 -0
  20. package/lua/settings/settings-gemman.lua +6 -0
  21. package/lua/settings/settings-global.lua +31 -0
  22. package/lua/settings/settings-intercept.lua +23 -0
  23. package/lua/settings/settings-logistics.lua +22 -0
  24. package/lua/settings/settings-ondemandawacs.lua +29 -0
  25. package/lua/settings/settings-ondemandtankers.lua +29 -0
  26. package/lua/settings/settings-pedros.lua +11 -0
  27. package/lua/settings/settings-ranges.lua +28 -0
  28. package/lua/settings/settings-reapers.lua +25 -0
  29. package/lua/settings/settings-sams.lua +19 -0
  30. package/lua/settings/settings-skynet.lua +239 -0
  31. package/lua/settings/settings-tankers.lua +32 -0
  32. package/lua/settings/settings-training_ranges.lua +37 -0
  33. package/lua/src/010-root_menus.lua +5 -0
  34. package/lua/src/020-mission_functions.lua +1059 -0
  35. package/lua/src/110-set_clients.lua +61 -0
  36. package/lua/src/120-tankers.lua +589 -0
  37. package/lua/src/130-airboss.lua +621 -0
  38. package/lua/src/135-pedro.lua +21 -0
  39. package/lua/src/140-beacons.lua +19 -0
  40. package/lua/src/150-awacs.lua +599 -0
  41. package/lua/src/160-atis.lua +53 -0
  42. package/lua/src/170-cap_zone_training.lua +127 -0
  43. package/lua/src/172-cap_zone_war.lua +190 -0
  44. package/lua/src/173-fox_zone_training.lua +87 -0
  45. package/lua/src/176-random_air_traffic.lua +73 -0
  46. package/lua/src/178-training-intercept.lua +263 -0
  47. package/lua/src/180-logistics.lua +80 -0
  48. package/lua/src/190-ranges.lua +54 -0
  49. package/lua/src/191-sams.lua +49 -0
  50. package/lua/src/193-training_ranges.lua +191 -0
  51. package/lua/src/195-reaper-ondemand.lua +522 -0
  52. package/lua/src/196-fac_ranges.lua +34 -0
  53. package/lua/src/199-skynet.lua +721 -0
  54. package/lua/src/200-mission.lua +3 -0
  55. package/package.json +4 -3
  56. package/resources/radios/.gitkeep +0 -0
  57. package/resources/sounds/CTLD/beacon.ogg +0 -0
  58. package/resources/sounds/CTLD/beaconsilent.ogg +0 -0
  59. package/resources/sounds/Misc/.gitkeep +0 -0
  60. package/resources/sounds/Misc/2_Bips.ogg +0 -0
  61. package/resources/sounds/Misc/Bip.ogg +0 -0
  62. package/resources/sounds/Misc/crash_wood.ogg +0 -0
  63. package/scripts/build.js +2 -1
  64. package/scripts/inject-scripts.js +127 -230
  65. package/scripts/template-update.js +1 -1
@@ -0,0 +1,61 @@
1
+ -- *****************************************************************************
2
+ -- ** Set_Client **
3
+ -- *********************************************************
4
+ Set_CLIENT = SET_CLIENT:New():FilterOnce()
5
+ Set_CLIENT:HandleEvent(EVENTS.Refueling)
6
+ Set_CLIENT:HandleEvent(EVENTS.RefuelingStop)
7
+ Set_CLIENT:HandleEvent(EVENTS.PlayerEnterAircraft)
8
+ function Set_CLIENT:OnEventPlayerEnterAircraft(EventData)
9
+ if (EventData.IniGroup) then
10
+ local clientSetting = SETTINGS:Set( EventData.IniPlayerName)
11
+ clientSetting:SetImperial()
12
+ clientSetting:SetA2G_MGRS()
13
+ clientSetting:SetMenutextShort(true)
14
+ debug_msg(string.format("Add Tanker Menu for group [%s], player name [%s]",EventData.IniGroupName , EventData.IniPlayerName))
15
+ if type(InterceptArray) == 'table' then
16
+ for index, objIntercept in ipairs(InterceptArray) do
17
+ if (objIntercept.menus[EventData.IniUnit:GetCoalition()]) then
18
+ MENU_GROUP_COMMAND:New( EventData.IniGroup, "High Aspect", objIntercept.menus[EventData.IniUnit:GetCoalition()], StartInterceptTraining, {EventData.IniUnit:GetName(),index,-20,20} )
19
+ MENU_GROUP_COMMAND:New( EventData.IniGroup, "Medium Aspect Left", objIntercept.menus[EventData.IniUnit:GetCoalition()], StartInterceptTraining, {EventData.IniUnit:GetName(),index,20,50} )
20
+ MENU_GROUP_COMMAND:New( EventData.IniGroup, "Medium Aspect Right", objIntercept.menus[EventData.IniUnit:GetCoalition()], StartInterceptTraining, {EventData.IniUnit:GetName(),index,-50,-20} )
21
+ MENU_GROUP_COMMAND:New( EventData.IniGroup, "Low Aspect Left", objIntercept.menus[EventData.IniUnit:GetCoalition()], StartInterceptTraining, {EventData.IniUnit:GetName(),index,50,80} )
22
+ MENU_GROUP_COMMAND:New( EventData.IniGroup, "Low Aspect Right", objIntercept.menus[EventData.IniUnit:GetCoalition()], StartInterceptTraining, {EventData.IniUnit:GetName(),index,-80,-50} )
23
+ end
24
+ end
25
+ end
26
+ if EventData.IniUnit:GetCoalition() == coalition.side.BLUE then
27
+ MENU_GROUP_COMMAND:New( EventData.IniGroup, "Nearest Tanker Info", MenuCoalitionTankerBlue, NearestTankerInfo, { EventData.IniUnit, EventData.IniGroup} )
28
+ MENU_GROUP_COMMAND:New( EventData.IniGroup, "All Tankers Info", MenuCoalitionTankerBlue, AllTankersInfo, {EventData.IniUnit,EventData.IniGroup} )
29
+ else
30
+ MENU_GROUP_COMMAND:New( EventData.IniGroup, "Nearest Tanker Info", MenuCoalitionTankerRed, NearestTankerInfo, { EventData.IniUnit, EventData.IniGroup} )
31
+ MENU_GROUP_COMMAND:New( EventData.IniGroup, "All Tankers Info", MenuCoalitionTankerRed, AllTankersInfo, {EventData.IniUnit,EventData.IniGroup} )
32
+ end
33
+ local GroupMenu = MENU_GROUP:New( EventData.IniGroup, "My settings" )
34
+ debug_msg(string.format("Add Immortal Menu for group [%s], player name [%s]",EventData.IniGroupName , EventData.IniPlayerName))
35
+ BASE:SetState( EventData.IniGroup, "isImmortal", false )
36
+ MENU_GROUP_COMMAND:New( EventData.IniGroup, "Switch immortal status", GroupMenu, switchGroupImmortalStatus, EventData.IniGroup )
37
+ --if #AIRBOSSArray > 0 then
38
+ -- MENU_GROUP_COMMAND:New( EventData.IniGroup, "Switch Airboss subtitles", GroupMenu, switchGroupAirbossSubtitlesStatus, EventData.IniGroup )
39
+ --end
40
+ end
41
+ end
42
+ function Set_CLIENT:OnEventRefueling(EventData)
43
+ if (EventData.IniGroup) then
44
+ local client = CLIENT:Find(EventData.IniDCSUnit)
45
+ local clientFuel = EventData.IniUnit:GetTemplateFuel()
46
+ debug_msg(string.format("[%s] Start to refuel at the tanker %[s], current fuel : %.0f Kg",EventData.IniPlayerName , EventData.TgtUnitName, clientFuel))
47
+ BASE:SetState( client, "Fuel", clientFuel )
48
+ end
49
+ end
50
+ function Set_CLIENT:OnEventRefuelingStop(EventData)
51
+ if (EventData.IniGroup) then
52
+ local client = CLIENT:Find(EventData.IniDCSUnit)
53
+ local clientFuelTaken = EventData.IniUnit:GetTemplateFuel() - BASE:GetState(client,"Fuel")
54
+ debug_msg(string.format("[%s] Stop to refuel at the tanker %[s], taken %.0f Kg",EventData.IniPlayerName , EventData.TgtUnitName, clientFuelTaken))
55
+ end
56
+ end
57
+
58
+ Set_CLIENT_Bleu = SET_CLIENT:New():FilterCoalitions(coalition.side.BLUE):FilterOnce()
59
+ debug_msg(string.format("Nbre Blue Client : %i", Set_CLIENT_Bleu:Count()))
60
+ Set_CLIENT_Red = SET_CLIENT:New():FilterCoalitions(coalition.side.RED):FilterOnce()
61
+ debug_msg(string.format("Nbre Red Client : %i", Set_CLIENT_Red:Count()))
@@ -0,0 +1,589 @@
1
+ -- *****************************************************************************
2
+ -- ** Tankers **
3
+ -- *********************************************************
4
+ tankersArray = {}
5
+ compteur = 0
6
+ MenuCoalitionTankerBlue = MENU_COALITION:New(coalition.side.BLUE, "Tankers", MenuCoalitionBlue)
7
+ MenuCoalitionTankerRed = MENU_COALITION:New(coalition.side.RED, "Tankers", MenuCoalitionRed)
8
+ for index, tankerconfig in ipairs(TankersConfig) do
9
+ if tankerconfig.enable == true then
10
+ compteur = compteur + 1
11
+ env.info('creation Tanker : '.. tankerconfig.groupName..'...')
12
+ local objTanker = RECOVERYTANKER:New(UNIT:FindByName(tankerconfig.patternUnit), tankerconfig.groupName)
13
+ :SetTakeoffCold()
14
+ :SetRespawnOnOff(tankerconfig.autorespawn)
15
+ :SetLowFuelThreshold(tankerconfig.fuelwarninglevel)
16
+ :SetAltitude(tankerconfig.altitude)
17
+ :SetSpeed(tankerconfig.speed)
18
+ :SetHomeBase(AIRBASE:FindByName(tankerconfig.baseUnit),tankerconfig.terminalType)
19
+ :SetCallsign(tankerconfig.callsign.name, tankerconfig.callsign.number)
20
+ :SetRecoveryAirboss(tankerconfig.airboss_recovery)
21
+ :SetRadio(tankerconfig.freq)
22
+ :SetModex(tankerconfig.modex)
23
+ :SetTACAN(tankerconfig.tacan.channel, tankerconfig.tacan.morse, tankerconfig.tacan.band)
24
+ :SetRacetrackDistances(tankerconfig.racetrack.front, tankerconfig.racetrack.back)
25
+ objTanker.customconfig = tankerconfig
26
+ function objTanker:OnAfterStart(from, event, to)
27
+ --self:SetTACAN(self.customconfig.tacan.channel, self.customconfig.tacan.morse, self.customconfig.tacan.band )
28
+ self.spawnAbsTime = timer.getAbsTime()
29
+ env.info('popup Tanker : '..self.tanker.GroupName..' at : '..self.spawnAbsTime)
30
+ if self.customconfig.escortgroupname then
31
+ self.escortSpawnObject = SPAWN:NewWithAlias(self.customconfig.escortgroupname,'escort-'.. self.customconfig.groupName)
32
+ :InitRepeatOnEngineShutDown()
33
+ :InitSkill("Excellent")
34
+ :OnSpawnGroup(function(SpawnGroup)
35
+ taskTankerEscort({self, SpawnGroup})
36
+ end)
37
+ self.escortGroupObject = spawnRecoveryTankerEscort(self.escortSpawnObject,self.customconfig)
38
+ if self.customconfig.missionmaxduration then
39
+ self.escortGroupObject:ScheduleOnce(self.customconfig.missionmaxduration*60,
40
+ function(SpawnGroup, airBaseName)
41
+ --trigger.action.outText('RTB schedule trigger Tanker-escort group : '..(SpawnGroup.GroupName)..' airbase'..(airBaseName)..'...', 45)
42
+ SpawnGroup:RouteRTB(AIRBASE:FindByName(airBaseName))
43
+ end,
44
+ self.escortGroupObject,
45
+ self.customconfig.baseUnit
46
+ )
47
+ --trigger.action.outText('Tanker-escort configured to RTB in : '..(self.customconfig.missionmaxduration)..' minutes max...', 45)
48
+ end
49
+ end
50
+ if self.customconfig.missionmaxduration then
51
+ (self.tanker):ScheduleOnce(self.customconfig.missionmaxduration*60,
52
+ function(tankerObject, airBaseName)
53
+ --trigger.action.outText('RTB schedule trigger Tanker group : '..(tankerObject.tanker.GroupName)..' airbase'..(tankerObject.customconfig.baseUnit)..'...', 45)
54
+ tankerObject:RTB(AIRBASE:FindByName(tankerObject.customconfig.baseUnit))
55
+ end,
56
+ self
57
+ )
58
+ --trigger.action.outText('Tanker configured to RTB in : '..(self.customconfig.missionmaxduration)..' minutes max...', 45)
59
+ end
60
+ if (self.customconfig.benefit_coalition == coalition.side.RED) then
61
+ self.menureset = MENU_COALITION_COMMAND:New(
62
+ coalition.side.RED,
63
+ "Reset Tanker "..self.customconfig.callsign.alias..'-'..self.customconfig.callsign.number..'-1',
64
+ MenuCoalitionTankerRed,
65
+ resetRecoveryTanker,
66
+ self
67
+ )
68
+ else
69
+ self.menureset = MENU_COALITION_COMMAND:New(
70
+ coalition.side.BLUE,
71
+ "Reset Tanker "..self.customconfig.callsign.alias..'-'..self.customconfig.callsign.number..'-1',
72
+ MenuCoalitionTankerBlue,
73
+ resetRecoveryTanker,
74
+ self
75
+ )
76
+ end
77
+ end
78
+ function objTanker:OnAfterRTB(from, event, to, airbase)
79
+ if self.customconfig.escortgroupname then
80
+ env.info('Tanker RTB: '..self.tanker.GroupName..'...')
81
+ if self.escortGroupObject:IsAirborne(false) == true then
82
+ env.info('escort RTB : '.. self.escortGroupObject.GroupName..' Tanker : '..self.tanker.GroupName..'...')
83
+ self.escortGroupObject:RouteRTB(airbase)
84
+ else
85
+ --self.escortGroupObject:Destroy(nil, 5)
86
+ end
87
+ end
88
+ --trigger.action.outText('Tanker is RTB : '..(self.customconfig.groupName)..'...', 45)
89
+ end
90
+ function objTanker:OnEventKill(event)
91
+ if self.customconfig.escortgroupname then
92
+ env.info(event.target' Killed !! Sending escort Home')
93
+ self.escortGroupObject:RouteRTB(AIRBASE:FindByName(self.customconfig.baseUnit))
94
+ end
95
+ end
96
+ function objTanker:OnAfterStatus(from, event, to)
97
+ self.tanker:OptionRestrictBurner(true)
98
+ if ((self.customconfig.escortgroupname) and (self.escortGroupObject)) then
99
+ if not(GROUP:FindByName(self.escortGroupObject.GroupName)) then
100
+ env.info('Respawning escort Group '..self.escortGroupObject.GroupName)
101
+ self.escortGroupObject = self.escortSpawnObject
102
+ :SpawnAtAirbase(AIRBASE:FindByName(self.customconfig.baseUnit),SPAWN.Takeoff.Cold, self.customconfig.altitude)
103
+ end
104
+ end
105
+ end
106
+ tankersArray[compteur] = objTanker
107
+ tankersArray[compteur]:Start()
108
+ end
109
+ end
110
+
111
+ -- *****************************************************************************
112
+ -- ** OnDemand Tankers **
113
+ -- *********************************************************
114
+ function triggerOnDemandTanker(type, askedDuration, askedFL, askedSpeed, askedAnchorCoord, askedOrbitHeading, askedOrbitLeg)
115
+ local TankerGroup = nil
116
+ if (OnDemandTankersConfig) then
117
+ for index, OnDemandTanker in ipairs(OnDemandTankersConfig) do
118
+ if ((OnDemandTanker.type == type) and (OnDemandTanker.enable)) then
119
+ debug_msg(string.format('OnDemandTanker : Found type %s Tanker : %s Group!', type, OnDemandTanker.groupName))
120
+ if (askedSpeed and askedSpeed > 0) then
121
+ OnDemandTanker.speed = askedSpeed
122
+ end
123
+ if (askedFL and askedFL > 0) then
124
+ OnDemandTanker.altitude = askedFL * 100
125
+ end
126
+ if ( askedDuration == nil or askedDuration == 0 ) then
127
+ askedDuration = 480
128
+ end
129
+ if (askedOrbitHeading) then
130
+ if (askedOrbitLeg and askedOrbitLeg > 10) then
131
+ --heading et Leg demandés
132
+ OnDemandTanker.orbit = {
133
+ heading = askedOrbitHeading % 360,
134
+ length = askedOrbitLeg,
135
+ }
136
+ else
137
+ --heading demandé et leg non demandé
138
+ if (OnDemandTanker.orbit ) then
139
+ if (not(OnDemandTanker.orbit.length)) then
140
+ OnDemandTanker.orbit = {
141
+ heading = askedOrbitHeading % 360,
142
+ length = 30,
143
+ }
144
+ else
145
+ OnDemandTanker.orbit = {
146
+ heading = askedOrbitHeading % 360,
147
+ length = math.max(10, OnDemandTanker.orbit.length),
148
+ }
149
+ end
150
+ else
151
+ OnDemandTanker.orbit = {
152
+ heading = askedOrbitHeading % 360,
153
+ length = 30,
154
+ }
155
+ end
156
+ end
157
+ else
158
+ --pas de heading demandé
159
+ if (OnDemandTanker.orbit ) then
160
+ if (not(OnDemandTanker.orbit.heading)) then
161
+ OnDemandTanker.orbit.heading = 90
162
+ end
163
+ if (not(OnDemandTanker.orbit.length)) then
164
+ OnDemandTanker.orbit.length = 30
165
+ else
166
+ OnDemandTanker.orbit.length = math.max(10, OnDemandTanker.orbit.length)
167
+ end
168
+ else
169
+ OnDemandTanker.orbit = {
170
+ heading = 90,
171
+ length = 30,
172
+ }
173
+ end
174
+ end
175
+ local set_group_tanker = SET_GROUP:New()
176
+ :FilterActive()
177
+ :FilterPrefixes(OnDemandTanker.groupName)
178
+ :FilterCategories("plane")
179
+ :FilterOnce()
180
+ local aliveTankersGroupList = set_group_tanker:GetSetObjects()
181
+
182
+ local is_tanker_spawned = false
183
+ debug_msg(string.format('OnDemandTanker : Looking for a Group corresponding to template %s', string.format("%s-%s", OnDemandTanker.groupName, OnDemandTanker.type)))
184
+ for index, current_group in ipairs(aliveTankersGroupList) do
185
+ if (
186
+ (not(is_tanker_spawned)) and
187
+ (string.find(
188
+ current_group.GroupName,
189
+ string.format("%s-%s",OnDemandTanker.groupName, OnDemandTanker.type),
190
+ 1,
191
+ true
192
+ ) ~= nil)
193
+ ) then
194
+ debug_msg(string.format('OnDemandTanker Found %s corresponding to template %s', current_group.GroupName, string.format("%s-%s", OnDemandTanker.groupName, OnDemandTanker.type)))
195
+ is_tanker_spawned = true
196
+ TankerGroup = current_group
197
+ end
198
+ end
199
+
200
+ local RTBAirbase = nil
201
+ local TankerRoute = {}
202
+ if (OnDemandTanker.baseUnit) then
203
+ RTBAirbase = AIRBASE:FindByName(OnDemandTanker.baseUnit)
204
+ else
205
+ RTBAirbase = askedAnchorCoord:GetClosestAirbase2(Airbase.Category.AIRDROME, OnDemandTanker.benefit_coalition)
206
+ end
207
+ if (is_tanker_spawned) then
208
+ debug_msg(string.format('OnDemandTanker already in air : rerouting %s', OnDemandTanker.groupName))
209
+ TankerGroup:ClearTasks()
210
+ table.insert(
211
+ TankerRoute,
212
+ askedAnchorCoord
213
+ :SetAltitude(UTILS.FeetToMeters(OnDemandTanker.altitude))
214
+ :WaypointAirTurningPoint(
215
+ nil,
216
+ UTILS.KnotsToKmph(OnDemandTanker.speed),
217
+ {
218
+ {
219
+ id = 'Tanker',
220
+ params = {
221
+ }
222
+ },
223
+ {
224
+ id = 'ControlledTask',
225
+ params = {
226
+ task =
227
+ {
228
+ id = 'Orbit',
229
+ params = {
230
+ pattern = AI.Task.OrbitPattern.RACE_TRACK,
231
+ speed = UTILS.KnotsToMps(OnDemandTanker.speed),
232
+ altitude = UTILS.FeetToMeters(OnDemandTanker.altitude)
233
+ }
234
+ },
235
+ stopCondition = {
236
+ duration = askedDuration * 60
237
+ }
238
+ },
239
+ },
240
+ },
241
+ "Refuel Start"
242
+ )
243
+ )
244
+ table.insert(
245
+ TankerRoute,
246
+ askedAnchorCoord
247
+ :Translate(UTILS.NMToMeters(OnDemandTanker.orbit.length), OnDemandTanker.orbit.heading, true, false)
248
+ :SetAltitude(UTILS.FeetToMeters(OnDemandTanker.altitude))
249
+ :WaypointAirTurningPoint(
250
+ nil,
251
+ UTILS.KnotsToKmph(OnDemandTanker.speed),
252
+ {
253
+ {
254
+ id = 'Tanker',
255
+ params = {
256
+ }
257
+ },
258
+ },
259
+ "Orbit End"
260
+ )
261
+ )
262
+ table.insert(
263
+ TankerRoute,
264
+ RTBAirbase
265
+ :GetCoordinate()
266
+ :WaypointAirLanding(
267
+ UTILS.KnotsToKmph(OnDemandTanker.speed),
268
+ RTBAirbase
269
+ )
270
+ )
271
+ else
272
+ debug_msg(string.format('OnDemandTanker Spawning %s', OnDemandTanker.groupName))
273
+ local SpawnTanker = SPAWN:NewWithAlias(
274
+ OnDemandTanker.groupName,
275
+ string.format("%s-%s",OnDemandTanker.groupName,OnDemandTanker.type)
276
+ )
277
+ if (OnDemandTanker.freq) then
278
+ SpawnTanker:InitRadioFrequency(OnDemandTanker.freq)
279
+ SpawnTanker:InitRadioModulation("AM")
280
+ end
281
+ if (OnDemandTanker.modex) then
282
+ SpawnTanker:InitModex(OnDemandTanker.modex)
283
+ end
284
+ if (OnDemandTanker.baseUnit) then
285
+ TankerGroup = SpawnTanker:SpawnAtAirbase(
286
+ AIRBASE:FindByName(OnDemandTanker.baseUnit),
287
+ SPAWN.Takeoff.Hot,
288
+ nil,
289
+ OnDemandTanker.terminalType
290
+ )
291
+ table.insert(TankerRoute,
292
+ AIRBASE
293
+ :FindByName(OnDemandTanker.baseUnit)
294
+ :GetCoordinate()
295
+ :WaypointAirTakeOffParkingHot()
296
+ )
297
+ else
298
+ TankerGroup = SpawnTanker:SpawnFromCoordinate(
299
+ askedAnchorCoord
300
+ :GetRandomCoordinateInRadius(
301
+ UTILS.NMToMeters(30),
302
+ UTILS.NMToMeters(20)
303
+ )
304
+ :SetAltitude(
305
+ UTILS.FeetToMeters(OnDemandTanker.altitude)
306
+ )
307
+ )
308
+ end
309
+ TankerGroup.customconfig = OnDemandTanker
310
+ TankerGroup.spawnAbsTime = timer.getAbsTime()
311
+ TankerGroup.missionmaxduration = askedDuration
312
+ table.insert(TankerRoute,
313
+ askedAnchorCoord
314
+ :SetAltitude(UTILS.FeetToMeters(OnDemandTanker.altitude))
315
+ :WaypointAirTurningPoint(
316
+ nil,
317
+ UTILS.KnotsToKmph(OnDemandTanker.speed),
318
+ {
319
+ {
320
+ id = 'Tanker',
321
+ params = {
322
+ }
323
+ },
324
+ {
325
+ id = 'ControlledTask',
326
+ params = {
327
+ task =
328
+ {
329
+ id = 'Orbit',
330
+ params = {
331
+ pattern = AI.Task.OrbitPattern.RACE_TRACK,
332
+ speed = UTILS.KnotsToMps(OnDemandTanker.speed),
333
+ altitude = UTILS.FeetToMeters(OnDemandTanker.altitude)
334
+ }
335
+ },
336
+ stopCondition = {
337
+ duration = askedDuration * 60
338
+ }
339
+ },
340
+ },
341
+ },
342
+ "Refuel Start"
343
+ )
344
+ )
345
+ table.insert(TankerRoute,
346
+ askedAnchorCoord
347
+ :Translate(UTILS.NMToMeters(OnDemandTanker.orbit.length), OnDemandTanker.orbit.heading, true, false)
348
+ :SetAltitude(UTILS.FeetToMeters(OnDemandTanker.altitude))
349
+ :WaypointAirTurningPoint(
350
+ nil,
351
+ UTILS.KnotsToKmph(OnDemandTanker.speed),
352
+ {
353
+ {
354
+ id = 'Tanker',
355
+ params = {
356
+ }
357
+ }
358
+ },
359
+ "Orbit End"
360
+ )
361
+ )
362
+ table.insert(TankerRoute,
363
+ RTBAirbase
364
+ :GetCoordinate()
365
+ :WaypointAirLanding(
366
+ UTILS.KnotsToKmph(OnDemandTanker.speed),
367
+ RTBAirbase,
368
+ {},
369
+ 'RTB'
370
+ )
371
+ )
372
+ end
373
+ TankerGroup:Route(TankerRoute)
374
+ TankerGroup:CommandEPLRS(true, 4)
375
+ if (OnDemandTanker.tacan) then
376
+ TankerGroup.beacon=BEACON:New(TankerGroup:GetUnit(1))
377
+ TankerGroup.beacon:ActivateTACAN(OnDemandTanker.tacan.channel, "Y", OnDemandTanker.tacan.morse, true)
378
+ end
379
+ if (OnDemandTanker.callsign) then
380
+ TankerGroup:CommandSetCallsign(OnDemandTanker.callsign.name, OnDemandTanker.callsign.number, 2)
381
+ end
382
+ if OnDemandTanker.escortgroupname then
383
+ TankerGroup.escortSpawnObject = SPAWN:NewWithAlias(OnDemandTanker.escortgroupname,'escort-'.. OnDemandTanker.groupName)
384
+ :InitRepeatOnEngineShutDown()
385
+ :InitSkill("Excellent")
386
+ :OnSpawnGroup(function(SpawnGroup)
387
+ taskGroupEscort({TankerGroup, SpawnGroup})
388
+ end)
389
+ TankerGroup.escortGroupObject = spawnRecoveryTankerEscort(TankerGroup.escortSpawnObject,OnDemandTanker)
390
+ if OnDemandTanker.missionmaxduration then
391
+ TankerGroup.escortGroupObject:ScheduleOnce(OnDemandTanker.missionmaxduration*60,
392
+ function(SpawnGroup, airBaseName)
393
+ --trigger.action.outText('RTB schedule trigger Tanker-escort group : '..(SpawnGroup.GroupName)..' airbase'..(airBaseName)..'...', 45)
394
+ SpawnGroup:RouteRTB(AIRBASE:FindByName(airBaseName))
395
+ end,
396
+ TankerGroup.escortGroupObject,
397
+ OnDemandTanker.baseUnit
398
+ )
399
+ --trigger.action.outText('Tanker-escort configured to RTB in : '..(OnDemandTanker.missionmaxduration)..' minutes max...', 45)
400
+ end
401
+ end
402
+ if (map_marker[TankerGroup:GetName()]) then
403
+ COORDINATE:RemoveMark(map_marker[TankerGroup:GetName()])
404
+ end
405
+ if(OnDemandTanker.tacan) then
406
+ map_marker[TankerGroup:GetName()] = askedAnchorCoord:MarkToCoalition(
407
+ string.format(
408
+ 'OnDemand Tanker %s - TCN %i\nFL %i at %i knots\nFreq %.2f MHz\nOn station for %i minutes\nRacetrack : %i ° for %i nm',
409
+ OnDemandTanker.type,
410
+ OnDemandTanker.tacan.channel,
411
+ UTILS.Round(OnDemandTanker.altitude / 100 , 0),
412
+ OnDemandTanker.speed,
413
+ OnDemandTanker.freq,
414
+ askedDuration,
415
+ OnDemandTanker.orbit.heading,
416
+ OnDemandTanker.orbit.length
417
+ ),
418
+ OnDemandTanker.benefit_coalition,
419
+ true,
420
+ 'OnDemand Tanker %s is Activated'
421
+ )
422
+ else
423
+ map_marker[TankerGroup:GetName()] = askedAnchorCoord:MarkToCoalition(
424
+ string.format(
425
+ 'OnDemand Tanker %s\nFL %i at %i knots\nFreq %.2f MHz\nOn station for %i minutes\nRacetrack : %i ° for %i nm',
426
+ OnDemandTanker.type,
427
+ UTILS.Round(OnDemandTanker.altitude / 100 , 0),
428
+ OnDemandTanker.speed,
429
+ OnDemandTanker.freq,
430
+ askedDuration,
431
+ OnDemandTanker.orbit.heading,
432
+ OnDemandTanker.orbit.length
433
+ ),
434
+ OnDemandTanker.benefit_coalition,
435
+ true,
436
+ 'OnDemand Tanker %s is Activated'
437
+ )
438
+ end
439
+ TankerGroup:HandleEvent(EVENTS.Land)
440
+ TankerGroup:HandleEvent(EVENTS.Crash)
441
+ TankerGroup:HandleEvent(EVENTS.Dead)
442
+ function TankerGroup:OnEventLand(EventData)
443
+ COORDINATE:RemoveMark(map_marker[self:GetName()])
444
+ if self.custommconfig.escortgroupname then
445
+ env.info('Tanker RTB: '..self.GroupName..'...')
446
+ if self.escortGroupObject:IsAirborne(false) == true then
447
+ env.info('escort RTB : '.. self.escortGroupObject.GroupName..' Tanker : '..self.GroupName..'...')
448
+ self.escortGroupObject:RouteRTB()
449
+ else
450
+ --self.escortGroupObject:Destroy(nil, 5)
451
+ end
452
+ end
453
+ end
454
+ function TankerGroup:OnEventCrash(EventData)
455
+ COORDINATE:RemoveMark(map_marker[self:GetName()])
456
+ if self.custommconfig.escortgroupname then
457
+ env.info('Tanker RTB: '..self.GroupName..'...')
458
+ if self.escortGroupObject:IsAirborne(false) == true then
459
+ env.info('escort RTB : '.. self.escortGroupObject.GroupName..' Tanker : '..self.GroupName..'...')
460
+ self.escortGroupObject:RouteRTB()
461
+ else
462
+ --self.escortGroupObject:Destroy(nil, 5)
463
+ end
464
+ end
465
+ end
466
+ function TankerGroup:OnEventDead(EventData)
467
+ COORDINATE:RemoveMark(map_marker[self:GetName()])
468
+ if self.custommconfig.escortgroupname then
469
+ env.info('Tanker RTB: '..self.GroupName..'...')
470
+ if self.escortGroupObject:IsAirborne(false) == true then
471
+ env.info('escort RTB : '.. self.escortGroupObject.GroupName..' Tanker : '..self.GroupName..'...')
472
+ self.escortGroupObject:RouteRTB()
473
+ else
474
+ --self.escortGroupObject:Destroy(nil, 5)
475
+ end
476
+ end
477
+ end
478
+ end
479
+ end
480
+ end
481
+ return TankerGroup;
482
+ end
483
+
484
+ --local RestrToCoal = nil
485
+ tankersOnDemandArray = {}
486
+ local TankerMarkHandler = {}
487
+
488
+ function TankerMarkHandler:onEvent(event)
489
+ local CmdSymbol = "-"
490
+
491
+ if event.id == 25 then
492
+ --trigger.action.outText(" ", 0, true)
493
+ elseif (event.id == 27 and string.find(event.text, CmdSymbol)) then
494
+ --if (event.coalition == RestrToCoal or RestrToCoal == nil) then
495
+ local full = nil
496
+ local remString = nil
497
+ local cmd = nil
498
+ local param1 = nil
499
+ local param1Start = nil
500
+ local param2 = nil
501
+ local param2Start = nil
502
+ local param3 = nil
503
+ local param3Start = nil
504
+ local param4 = nil
505
+ local param4Start = nil
506
+ local param5 = nil
507
+ local param5Start = nil
508
+ local param6 = nil
509
+ local param6Start = nil
510
+ local mcoord = COORDINATE:New(event.pos.x, event.pos.y, event.pos.z)
511
+ local mvec3 = event.pos
512
+
513
+ full = string.sub(event.text, 2)
514
+
515
+ if (string.find(full, CmdSymbol)) then
516
+ param1Start = string.find(full, CmdSymbol)
517
+ cmd = string.sub(full, 0, param1Start-1)
518
+ remString = string.sub(full, param1Start+1)
519
+ if (string.find(remString, CmdSymbol)) then
520
+ param2Start = string.find(remString, CmdSymbol)
521
+ param1 = string.sub(remString, 0, param2Start-1)
522
+ remString = string.sub(remString, param2Start+1)
523
+ if string.find(remString, CmdSymbol) then
524
+ param3Start = string.find(remString, CmdSymbol)
525
+ param2 = string.sub(remString, 0, param3Start-1)
526
+ remString = string.sub(remString, param3Start+1)
527
+ if string.find(remString, CmdSymbol) then
528
+ param4Start = string.find(remString, CmdSymbol)
529
+ param3 = string.sub(remString, 0, param4Start-1)
530
+ remString = string.sub(remString, param4Start+1)
531
+
532
+ if string.find(remString, CmdSymbol) then
533
+ param5Start = string.find(remString, CmdSymbol)
534
+ param4 = string.sub(remString, 0, param5Start-1)
535
+ remString = string.sub(remString, param5Start+1)
536
+
537
+ if string.find(remString, CmdSymbol) then
538
+ param6Start = string.find(remString, CmdSymbol)
539
+ param5 = string.sub(remString, 0, param6Start-1)
540
+ param6 = string.sub(remString, param6Start+1)
541
+ else
542
+ param5 = remString
543
+ end
544
+ else
545
+ param4 = remString
546
+ end
547
+ else
548
+ param3 = remString
549
+ end
550
+ else
551
+ param2 = remString
552
+ end
553
+ else
554
+ param1 = remString
555
+ end
556
+ else
557
+ cmd = full
558
+ end
559
+ if DEBUG_MSG == true then
560
+ trigger.action.outText("Full Text = " .. full, 10)
561
+ trigger.action.outText("Command = " .. cmd, 10)
562
+ if param1 ~= nil then trigger.action.outText("type = " .. param1, 10) end
563
+ if param2 ~= nil then trigger.action.outText("Duration = " .. param2, 10) end
564
+ if param3 ~= nil then trigger.action.outText("FlightLevel = " .. param3, 10) end
565
+ if param4 ~= nil then trigger.action.outText("Speed = " .. param4, 10) end
566
+ if param5 ~= nil then trigger.action.outText("OrbitHeading = " .. param5, 10) end
567
+ if param6 ~= nil then trigger.action.outText("OrbitLeg = " .. param6, 10) end
568
+ end
569
+
570
+ if string.find(cmd, "tanker") then
571
+ if DEBUG_MSG == true then
572
+ trigger.action.outText("DEBUG: On Demand Tanker Started!", 10)
573
+ end
574
+ tankersOnDemandArray[#tankersOnDemandArray+1] = triggerOnDemandTanker(
575
+ param1,
576
+ tonumber(param2),
577
+ tonumber(param3),
578
+ tonumber(param4),
579
+ mcoord,
580
+ tonumber(param5),
581
+ tonumber(param6)
582
+ )
583
+ end
584
+ --end
585
+ end
586
+
587
+ end
588
+
589
+ world.addEventHandler(TankerMarkHandler)