@jtff/miztemplate-lib 3.10.14 → 4.0.0

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.
@@ -1,22 +1,101 @@
1
+ -- region RATConfigFunctions
2
+
3
+ -- @type RATConfig
4
+ -- @field #string name Name of the RAT scenario.
5
+ -- @field #boolean enable Enable the RAT scenario.
6
+ -- @field #number constant_alive_groups Number of groups to keep alive at all times.
7
+ -- @field #RATGroupConfig[] aircrafts_groupconfigs Table of aircraft group configurations.
8
+
9
+ -- @type RATGroupConfig
10
+ -- @field #string[] templatename Template name (string or table of strings).
11
+ -- @field #number minimun_spawns Minimum number of spawns.
12
+ -- @field #number inactive_timer Inactive timer in seconds.
13
+ -- @field #boolean atcmessage_enable Enable ATC messages.
14
+ -- @field #number flightlevelmin Flight level in feet.
15
+ -- @field #number flightlevelmaw Flight level in feet.
16
+ -- @field #number speed Speed in knots.
17
+ -- @field #table liveries Table of liveries.
18
+ -- @field #boolean allow_immortal Allow immortal groups.
19
+ -- @field #boolean allow_invisible Allow invisible groups.
20
+ -- @field #boolean commute Allow commute.
21
+ -- @field #boolean despawnAirborne Allow Despawn when entering arrival zone.
22
+ -- @field #RATAirbasesConfig airbases_names Table of airbases names.
23
+
24
+ -- @type RATAirbasesConfig
25
+ -- @field #string[] departure Departure airbases or zone names.
26
+ -- @field #string[] arrival Arrival airbases or zone names.
27
+
28
+ --- Parse a RAT config Object.
29
+ -- @param #JsonObject config Config object to parse
30
+ -- @return #RATConfig ratConfigJson Parsed QRA config object
31
+ function ParseRATConfigJson(config)
32
+ local json = require('Scripts/json')
33
+ local parser_name = "RAT"
34
+ -- **************************************************************************
35
+ -- enable
36
+ -- **************************************************************************
37
+ local ratConfigJson = {}
38
+ if config.enable == true then
39
+ ratConfigJson = config
40
+ else
41
+ ratConfigJson = {
42
+ enable = false,
43
+ }
44
+ end
45
+ Jtff_log.debug(
46
+ string.format(
47
+ "parsed RAT config for %s, resulting config :\n%s",
48
+ config.name or "",
49
+ json:encode(
50
+ ratConfigJson,
51
+ { indent = true }
52
+ )
53
+ ),
54
+ parser_name
55
+ )
56
+ return ratConfigJson
57
+ end
58
+
59
+ -- endregion RATConfigFunctions
60
+
61
+ -- region RATFunctions
62
+ -- endregion RATFunctions
63
+
1
64
  -- *****************************************************************************
2
65
  -- ** Random Air Traffic **
3
66
  -- *********************************************************
4
67
  RATManagerArray = {}
5
- compteur = 0
6
- for index, ratconfig in ipairs(RATConfig) do
68
+ local compteur = #RATManagerArray
69
+
70
+ for index, currentRATConfigObject in ipairs(RATConfig) do
71
+ local ratconfig = ParseRATConfigJson(currentRATConfigObject)
7
72
  if ratconfig.enable == true then
8
- jtff_log.info(string.format("RATManager %s Enable",ratconfig.name),"RAT")
73
+ Jtff_log.info(
74
+ string.format(
75
+ "RATManager %s Enable",
76
+ ratconfig.name
77
+ ),
78
+ "RAT"
79
+ )
9
80
  compteur = compteur +1
10
81
  local ratManagerName = ratconfig.name or "unknown"
11
82
  RATManagerArray[compteur] = RATMANAGER:New(ratconfig.constant_alive_groups or nil)
12
83
  RATManagerArray[compteur].RATObjectsArray = {}
84
+
13
85
  for index_planegroup, planegroupconfig in ipairs(ratconfig.aircrafts_groupconfigs) do
14
86
  if (type(planegroupconfig.templatename) == "string") then
15
87
  planegroupconfig.templatename = {planegroupconfig.templatename}
16
88
  end
17
89
  if (type(planegroupconfig.templatename) == "table") then
18
90
  for templateindex, templatename in ipairs(planegroupconfig.templatename) do
19
- jtff_log.debug(string.format("RATManager %s - template %s", ratManagerName ,templatename),"RAT")
91
+ Jtff_log.debug(
92
+ string.format(
93
+ "RATManager %s - template %s",
94
+ ratManagerName,
95
+ templatename
96
+ ),
97
+ "RAT"
98
+ )
20
99
  RATManagerArray[compteur].RATObjectsArray[templateindex] = RAT:New(templatename)
21
100
  if (type(planegroupconfig.airbases_names) == "table" ) then
22
101
  RATManagerArray[compteur].RATObjectsArray[templateindex]:SetTakeoff("cold")
@@ -30,6 +109,9 @@ for index, ratconfig in ipairs(RATConfig) do
30
109
  RATManagerArray[compteur].RATObjectsArray[templateindex]:DestinationZone()
31
110
  end
32
111
  end
112
+ if (type(planegroupconfig.despawnAirborne) == "boolean" and planegroupconfig.despawnAirborne == true) then
113
+ RATManagerArray[compteur].RATObjectsArray[templateindex]:DestinationZone()
114
+ end
33
115
  RATManagerArray[compteur].RATObjectsArray[templateindex]:SetDeparture(planegroupconfig.airbases_names.departure)
34
116
  RATManagerArray[compteur].RATObjectsArray[templateindex]:SetDestination(planegroupconfig.airbases_names.arrival)
35
117
  end
@@ -41,8 +123,11 @@ for index, ratconfig in ipairs(RATConfig) do
41
123
  else
42
124
  RATManagerArray[compteur].RATObjectsArray[templateindex]:ATC_Messages(false)
43
125
  end
44
- if (type(planegroupconfig.flightlevel) == "number" ) then
45
- RATManagerArray[compteur].RATObjectsArray[templateindex]:SetFLcruise(planegroupconfig.flightlevel)
126
+ if (type(planegroupconfig.flightlevelmin) == "number" ) then
127
+ RATManagerArray[compteur].RATObjectsArray[templateindex]:SetFLmin(planegroupconfig.flightlevelmin)
128
+ end
129
+ if (type(planegroupconfig.flightlevelmax) == "number" ) then
130
+ RATManagerArray[compteur].RATObjectsArray[templateindex]:SetFLmax(planegroupconfig.flightlevelmax)
46
131
  end
47
132
  if (type(planegroupconfig.speed) == "number") then
48
133
  RATManagerArray[compteur].RATObjectsArray[templateindex]:SetMaxCruiseSpeed(UTILS.KnotsToKmph(planegroupconfig.speed))
@@ -53,23 +138,27 @@ for index, ratconfig in ipairs(RATConfig) do
53
138
  if (type(planegroupconfig.allow_immortal) == "boolean" and planegroupconfig.allow_immortal == true) then
54
139
  RATManagerArray[compteur].RATObjectsArray[templateindex]:Immortal()
55
140
  end
56
- if (type(planegroupconfig.allow_invisible) == "boolean" and planegroupconfig.allow_invisible == true) then
141
+ if not(type(planegroupconfig.allow_invisible) == "boolean" and planegroupconfig.allow_invisible == false) then
57
142
  RATManagerArray[compteur].RATObjectsArray[templateindex]:Invisible()
58
143
  end
59
144
  if (type(planegroupconfig.commute) == "boolean" and planegroupconfig.commute == true) then
60
145
  RATManagerArray[compteur].RATObjectsArray[templateindex]:Commute(true)
61
146
  end
62
147
  RATManagerArray[compteur].RATObjectsArray[templateindex]:SetEPLRS(true)
148
+ RATManagerArray[compteur].RATObjectsArray[templateindex]:SetROT(ENUMS.ROT.NoReaction)
63
149
  RATManagerArray[compteur]:Add(RATManagerArray[compteur].RATObjectsArray[templateindex], planegroupconfig.minimun_spawns)
64
- --RATManagerArray[compteur].RATObjectsArray[templateindex]:SetSpawnInterval(planegroupconfig.inactive_timer)
65
- --RATManagerArray[compteur].RATObjectsArray[templateindex]:InitRepeat()
66
- --RATManagerArray[compteur].RATObjectsArray[templateindex]:Spawn()
67
150
  end
68
151
  else
69
- jtff_log.error(string.format("RAT error in template name type : %s", planegroupconfig.templatename),"RAT")
152
+ Jtff_log.error(
153
+ string.format(
154
+ "RAT error in template name type : %s",
155
+ planegroupconfig.templatename
156
+ ),
157
+ "RAT"
158
+ )
70
159
  end
71
160
  end
72
161
  RATManagerArray[compteur].customconfig = ratconfig
73
- RATManagerArray[compteur]:Start(spawnStandardDelay)
162
+ RATManagerArray[compteur]:Start(SpawnStandardDelay)
74
163
  end
75
164
  end