@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.
@@ -2,12 +2,62 @@
2
2
  -- ** FoxZone Training **
3
3
  -- *********************************************************
4
4
 
5
+ -- region FoxZoneConfigFunctions
6
+
7
+ -- @type FOXZoneConfig
8
+ -- @field #boolean enable Enable the fox zone training
9
+ -- @field #string name Name of the fox zone training
10
+ -- @field #boolean debug Debug the fox zone training
11
+ -- @field #boolean f10Menu Enable the f10 menu
12
+ -- @field #string launchZoneName Launch zone name
13
+ -- @field #string safeZoneName Safe zone name
14
+ -- @field #boolean missileDestruction Missile destruction
15
+ -- @field #boolean missileLaunchMessages Missile launch messages
16
+ -- @field #boolean drawzone Draw the zone
17
+ -- @field #number distance_small_missile Distance of the small missile detonation in meters
18
+ -- @field #number distance_big_missile Distance of the big missile detonation in meters
19
+
20
+
21
+ --- Parse Fox Zone training config from JSON
22
+ --- @param #JsonObject config Config object to parse
23
+ --- @return #FOXZoneConfig foxZoneConfigJson Parsed FOXZoneConfig object
24
+ function ParseFoxZoneConfigJson(config)
25
+ local json = require('Scripts/json')
26
+ local parser_name = "FOX_ZONE"
27
+ -- **************************************************************************
28
+ -- enable
29
+ -- **************************************************************************
30
+ local foxZoneConfigJson
31
+ if config.enable == true then
32
+ foxZoneConfigJson = config
33
+ else
34
+ foxZoneConfigJson = {
35
+ enable = false,
36
+ }
37
+ end
38
+ Jtff_log.debug(
39
+ string.format(
40
+ "parsed Fox Zone training config for %s Zone, resulting config :\n%s",
41
+ config.type or "",
42
+ json:encode(
43
+ foxZoneConfigJson,
44
+ { indent = true }
45
+ )
46
+ ),
47
+ parser_name
48
+ )
49
+ return foxZoneConfigJson
50
+ end
51
+ -- endregion FoxZoneConfigFunctions
52
+
53
+ -- region FoxZoneFunctions
54
+
5
55
  function toggleMissileScript(objFoxZone)
6
56
  if (objFoxZone:Is("Running")) then
7
- jtff_log.info('stoping Fox Zone : '.. objFoxZone.customconfig.name..'...',"FOX_ZONE")
57
+ Jtff_log.info('stoping Fox Zone : '.. objFoxZone.customconfig.name..'...',"FOX_ZONE")
8
58
  objFoxZone:__Stop(0)
9
59
  else
10
- jtff_log.info('starting Fox Zone : '.. objFoxZone.customconfig.name..'...',"FOX_ZONE")
60
+ Jtff_log.info('starting Fox Zone : '.. objFoxZone.customconfig.name..'...',"FOX_ZONE")
11
61
  objFoxZone:__Start(0)
12
62
  end
13
63
  end
@@ -22,14 +72,24 @@ function getMissileScriptStatus(objFoxZone)
22
72
  end
23
73
  end
24
74
 
75
+ -- endregion FoxZoneFunctions
76
+
25
77
  FoxRangesArray = {}
26
- compteur = 0
27
- MenuCoalitionFoxZoneBlue = MENU_COALITION:New(coalition.side.BLUE, "Missile training Zones", MenuCoalitionBlue)
28
- MenuCoalitionFoxZoneRed = MENU_COALITION:New(coalition.side.RED, "Missile training Zones", MenuCoalitionRed)
29
- for index, foxzoneconfig in ipairs(FoxRangesConfig) do
78
+ local compteur = #FoxRangesArray
79
+
80
+ MenuCoalitionFoxZone = MENU_MISSION:New("Missile training Zones", nil)
81
+
82
+ for index, currentFoxZoneConfigObject in ipairs(FoxRangesConfig) do
83
+ local foxzoneconfig = ParseFoxZoneConfigJson(currentFoxZoneConfigObject)
30
84
  if foxzoneconfig.enable == true then
31
85
  compteur = compteur + 1
32
- jtff_log.info('creation Fox Zone : '.. foxzoneconfig.name..'...',"FOX_ZONE")
86
+ Jtff_log.info(
87
+ string.format(
88
+ 'creation Fox Zone : %s ...',
89
+ foxzoneconfig.name
90
+ ),
91
+ "FOX_ZONE"
92
+ )
33
93
  local objFoxZone = FOX:New()
34
94
  objFoxZone:SetExplosionPower(0.01)
35
95
  :SetExplosionDistance(foxzoneconfig.distance_small_missile or 100)
@@ -37,52 +97,64 @@ for index, foxzoneconfig in ipairs(FoxRangesConfig) do
37
97
  :SetDefaultMissileDestruction(foxzoneconfig.missileDestruction)
38
98
  :SetDefaultLaunchAlerts(foxzoneconfig.missileLaunchMessages)
39
99
  :SetDefaultLaunchMarks(false)
40
- if foxzoneconfig.launchZoneGroupName then
100
+ local launchGroupObject = GROUP:FindByName(foxzoneconfig.launchZoneName)
101
+ if type(launchGroupObject) ~= 'nil' then
41
102
  objFoxZone.objLaunchZone = ZONE_POLYGON:New(
42
- 'FOX_LAUNCH_ZONE_'..foxzoneconfig.name,
43
- GROUP:FindByName(foxzoneconfig.launchZoneGroupName))
44
- objFoxZone:AddLaunchZone(objFoxZone.objLaunchZone)
103
+ string.format(
104
+ 'FOX_LAUNCH_ZONE_%s',
105
+ foxzoneconfig.name
106
+ ),
107
+ launchGroupObject
108
+ )
45
109
  else
46
- if foxzoneconfig.launchZoneName then
47
- objFoxZone.objLaunchZone = ZONE:New(foxzoneconfig.launchZoneName)
48
- objFoxZone:AddLaunchZone(objFoxZone.objLaunchZone)
49
- end
110
+ objFoxZone.objLaunchZone = ZONE:New(foxzoneconfig.launchZoneName)
50
111
  end
51
- jtff_log.info('Launch zone Polygon created : '.. objFoxZone.objLaunchZone:GetName() ..'...',"FOX_ZONE")
112
+ objFoxZone:AddLaunchZone(objFoxZone.objLaunchZone)
113
+ Jtff_log.info(
114
+ string.format(
115
+ 'Launch zone Polygon %s created ...',
116
+ objFoxZone.objLaunchZone:GetName()
117
+ ),
118
+ "FOX_ZONE"
119
+ )
52
120
  if ((foxzoneconfig.drawzone == true) or false) then
53
121
  objFoxZone.objLaunchZone:DrawZone(
54
- -1,
55
- {1,0,0},
56
- 1,
57
- {1,0,0},
58
- 0.10,
59
- 4,
60
- true,
61
- nil
122
+ -1,
123
+ {1,0,0},
124
+ 1,
125
+ {1,0,0},
126
+ 0.10,
127
+ 4,
128
+ true,
129
+ nil
62
130
  )
63
131
  objFoxZone.objLaunchZone:GetCoordinate():TextToAll(
64
- "Missile trainer " .. foxzoneconfig.name,
65
- -1,
66
- {1,0,0},
67
- 1,
68
- {1,0,0},
69
- 0,
70
- 20,
71
- true
132
+ string.format(
133
+ "Missile trainer %s",
134
+ foxzoneconfig.name
135
+ ),
136
+ -1,
137
+ {1,0,0},
138
+ 1,
139
+ {1,0,0},
140
+ 0,
141
+ 20,
142
+ true
72
143
  )
73
144
  end
74
- if foxzoneconfig.safeZoneGroupName then
145
+ local safeZoneGroupObject = GROUP:FindByName(foxzoneconfig.safeZoneName)
146
+ if type(safeZoneGroupObject) ~= 'nil' then
75
147
  objFoxZone.objSafeZone = ZONE_POLYGON:New(
76
- 'FOX_SAFE_ZONE_'..foxzoneconfig.name,
77
- GROUP:FindByName(foxzoneconfig.safeZoneGroupName))
78
- objFoxZone:AddSafeZone(objFoxZone.objSafeZone)
79
- jtff_log.info('Safe zone Polygon created : '.. objFoxZone.objSafeZone:GetName() ..'...',"FOX_ZONE")
148
+ string.format(
149
+ 'FOX_SAFE_ZONE_%s',
150
+ foxzoneconfig.name
151
+ ),
152
+ safeZoneGroupObject
153
+ )
80
154
  else
81
- if foxzoneconfig.safeZoneName then
82
- objFoxZone.objSafeZone = ZONE:New(foxzoneconfig.safeZoneName)
83
- objFoxZone:AddSafeZone(objFoxZone.objSafeZone)
84
- end
155
+ objFoxZone.objSafeZone = ZONE:New(foxzoneconfig.safeZoneName)
85
156
  end
157
+ objFoxZone:AddSafeZone(objFoxZone.objSafeZone)
86
158
  if foxzoneconfig.debug then
87
159
  objFoxZone:SetDebugOn()
88
160
  end
@@ -93,29 +165,46 @@ for index, foxzoneconfig in ipairs(FoxRangesConfig) do
93
165
  objFoxZone:SetDisableF10Menu()
94
166
  end
95
167
 
96
- objFoxZone.menuZoneBlue = MENU_COALITION:New(coalition.side.BLUE, foxzoneconfig.name, MenuCoalitionFoxZoneBlue)
97
- objFoxZone.menuZoneRed = MENU_COALITION:New(coalition.side.RED, foxzoneconfig.name, MenuCoalitionFoxZoneRed)
168
+ objFoxZone.menuZone = MENU_MISSION:New(foxzoneconfig.name, MenuCoalitionFoxZone)
98
169
 
99
170
  objFoxZone.customconfig = foxzoneconfig
100
171
 
101
172
  -- **** Message to client *****
102
173
  function objFoxZone:OnAfterEnterSafeZone(From, Event, To, player)
103
- local message = '[' .. player.name .. '] You\'re entering in the missile trainer area ' .. foxzoneconfig.name .. '. Missile script is [' .. objFoxZone:GetState() .. ']'
174
+ local message = string.format(
175
+ '[%s] You\'re entering in the missile trainer area %s. Missile script is [%s]',
176
+ player.name,
177
+ foxzoneconfig.name,
178
+ objFoxZone:GetState()
179
+ )
104
180
  MESSAGE:NewType(message, MESSAGE.Type.Overview):ToClient(player.client)
105
181
  end
106
182
 
107
183
  function objFoxZone:OnAfterExitSafeZone(From, Event, To, player)
108
- local message = '[' .. player.name .. '] You\'re leaving the missile trainer area ' .. foxzoneconfig.name .. '. Missile script is [' .. objFoxZone:GetState() .. ']'
184
+ local message = string.format(
185
+ '[%s] You\'re leaving the missile trainer area %s. Missile script is [%s]',
186
+ player.name,
187
+ foxzoneconfig.name,
188
+ objFoxZone:GetState()
189
+ )
109
190
  MESSAGE:NewType(message, MESSAGE.Type.Overview):ToClient(player.client)
110
191
  end
111
192
 
112
193
  function objFoxZone:OnAfterStop(From, Event, To)
113
- local message = 'Missile script in training area [' .. foxzoneconfig.name .. '] missile script has been de-activated. Missile script is [' .. objFoxZone:GetState() .. ']'
194
+ local message = string.format(
195
+ 'Training area [%s] -> Script has been unactivated. Missile script is [%s]',
196
+ foxzoneconfig.name,
197
+ objFoxZone:GetState()
198
+ )
114
199
  MESSAGE:NewType(message, MESSAGE.Type.Overview):ToAll()
115
200
  end
116
201
 
117
202
  function objFoxZone:OnAfterStart(From, Event, To)
118
- local message = 'Training area [' .. foxzoneconfig.name .. '] missile script has been activated. Missile script is [' .. objFoxZone:GetState() .. ']'
203
+ local message = string.format(
204
+ 'Training area [%s] -> Script has been activated. Missile script is [%s]',
205
+ foxzoneconfig.name,
206
+ objFoxZone:GetState()
207
+ )
119
208
  MESSAGE:NewType(message, MESSAGE.Type.Overview):ToAll()
120
209
  end
121
210
 
@@ -135,8 +224,8 @@ for index, foxzoneconfig in ipairs(FoxRangesConfig) do
135
224
  else
136
225
  message = playerNameTargeted .. ' HAS BEEN SHOT DOWN BY ' .. unitShooter:GetName()
137
226
  end
138
- jtff_log.info(message,"FOX_ZONE")
139
- Set_CLIENT:ForEachClientInZone(objFoxZone.objSafeZone, function(clientInZone)
227
+ Jtff_log.info(message,"FOX_ZONE")
228
+ Set_AllClients:ForEachClientInZone(objFoxZone.objSafeZone, function(clientInZone)
140
229
  if clientInZone:IsAlive() then
141
230
  MESSAGE:NewType(message, MESSAGE.Type.Update):ToClient(clientInZone)
142
231
  end
@@ -146,28 +235,14 @@ for index, foxzoneconfig in ipairs(FoxRangesConfig) do
146
235
 
147
236
  FoxRangesArray[compteur] = objFoxZone
148
237
  FoxRangesArray[compteur]:Start()
149
- FoxRangesArray[compteur].commandToggleBlue = MENU_COALITION_COMMAND:New(
150
- coalition.side.BLUE,
238
+ FoxRangesArray[compteur].commandToggle = MENU_MISSION_COMMAND:New(
151
239
  "Toggle missile script",
152
- FoxRangesArray[compteur].menuZoneBlue,
240
+ FoxRangesArray[compteur].menuZone,
153
241
  toggleMissileScript,
154
242
  FoxRangesArray[compteur])
155
- FoxRangesArray[compteur].commandToggleRed = MENU_COALITION_COMMAND:New(
156
- coalition.side.RED,
157
- "Toggle missile script",
158
- FoxRangesArray[compteur].menuZoneRed,
159
- toggleMissileScript,
160
- FoxRangesArray[compteur])
161
- FoxRangesArray[compteur].commandStatusBlue = MENU_COALITION_COMMAND:New(
162
- coalition.side.BLUE,
163
- "missile script status",
164
- FoxRangesArray[compteur].menuZoneBlue,
165
- getMissileScriptStatus,
166
- FoxRangesArray[compteur])
167
- FoxRangesArray[compteur].commandStatusRed = MENU_COALITION_COMMAND:New(
168
- coalition.side.RED,
243
+ FoxRangesArray[compteur].commandStatus = MENU_MISSION_COMMAND:New(
169
244
  "missile script status",
170
- FoxRangesArray[compteur].menuZoneRed,
245
+ FoxRangesArray[compteur].menuZone,
171
246
  getMissileScriptStatus,
172
247
  FoxRangesArray[compteur])
173
248
  end