@@ -56,7 +56,7 @@ switch (_operation) do {
56
56
****************/
57
57
case " fireMission" : {
58
58
if (count _args == 0 ) then {
59
- _result = _logic getVariable [" fireMission" , objNull ];
59
+ _result = _logic getVariable [" fireMission" , [] ];
60
60
} else {
61
61
private _position = _args param [0 , [0 ,0 ,0 ], [[]], 3 ];
62
62
private _roundType = _args param [1 , " " , [" " ]];
@@ -90,64 +90,112 @@ switch (_operation) do {
90
90
case " execute" : {
91
91
private _group = _logic getVariable [" group" , grpNull ];
92
92
private _units = (units _group ) select {vehicle _x ! = _x && {gunner (vehicle _x ) == _x }};
93
- private _fireMission = _logic getVariable [" fireMission" , objNull ];
93
+ private _fireMission = _logic getVariable [" fireMission" , [] ];
94
94
private _fireMissionPos = [_fireMission , " position" ] call ALIVE_fnc_hashGet ;
95
95
[_fireMission , " units" , _units ] call ALIVE_fnc_hashSet ;
96
96
[_fireMission , " unitIndex" , 0 ] call ALIVE_fnc_hashSet ;
97
97
[_fireMission , " roundsShot" , 0 ] call ALIVE_fnc_hashSet ;
98
+ [_fireMission , " nextRoundTime" , time ] call ALIVE_fnc_hashSet ;
99
+ /* _units doWatch [_fireMissionPos select 0, _fireMissionPos select 1, 9999]; */
98
100
_units doWatch _fireMissionPos ;
99
101
100
102
_logic setVariable [" fireMission" , _fireMission ];
103
+
104
+ // Attach Fired EH to all vehicles in group
105
+ {
106
+ private _vehicle = vehicle _x ;
107
+ private _firedEH = _vehicle addEventHandler [" Fired" , {
108
+ private _unit = param [0 , objNull ];
109
+ private _magazine = param [5 , " " ];
110
+ private _logic = (group _unit ) getVariable [" logic" , objNull ];
111
+ private _fireMission = _logic getVariable [" fireMission" , []];
112
+ private _roundType = [_fireMission , " roundType" ] call ALIVE_fnc_hashGet ;
113
+ private _roundsShot = [_fireMission , " roundsShot" ] call ALIVE_fnc_hashGet ;
114
+
115
+ if (_magazine == _roundType ) then {
116
+ private _delay = [_fireMission , " delay" ] call ALIVE_fnc_hashGet ;
117
+
118
+ if (_delay > 0 ) then {
119
+ private _units = [_fireMission , " units" ] call ALIVE_fnc_hashGet ;
120
+ private _unitIndex = [_fireMission , " unitIndex" ] call ALIVE_fnc_hashGet ;
121
+
122
+ if ((_unitIndex + 1 ) >= count _units ) then {
123
+ _unitIndex = 0 ;
124
+ } else {
125
+ _unitIndex = _unitIndex + 1 ;
126
+ };
127
+
128
+ [_fireMission , " unitIndex" , _unitIndex ] call ALIVE_fnc_hashSet ;
129
+ [_fireMission , " nextRoundTime" , time + _delay ] call ALIVE_fnc_hashSet ;
130
+ };
131
+
132
+ [_fireMission , " roundsShot" , _roundsShot + 1 ] call ALIVE_fnc_hashSet ;
133
+ _logic setVariable [" fireMission" , _fireMission ];
134
+ };
135
+ }];
136
+ _vehicle setVariable [" sup_artillery_firedEH" , _firedEH ];
137
+ } forEach _units ;
101
138
};
139
+ // TODO: Check if unit is alive, otherwise skip
102
140
case " fire" : {
103
- private _fireMission = _logic getVariable [" fireMission" , objNull ];
104
- private _roundsShot = [_fireMission , " roundsShot " ] call ALIVE_fnc_hashGet ;
141
+ private _fireMission = _logic getVariable [" fireMission" , [] ];
142
+ private _delay = [_fireMission , " delay " ] call ALIVE_fnc_hashGet ;
105
143
private _units = [_fireMission , " units" ] call ALIVE_fnc_hashGet ;
106
- private _unitIndex = [_fireMission , " unitIndex" ] call ALIVE_fnc_hashGet ;
107
- private _unit = _units select _unitIndex ;
108
144
private _position = [_fireMission , " position" ] call ALIVE_fnc_hashGet ;
109
145
private _roundType = [_fireMission , " roundType" ] call ALIVE_fnc_hashGet ;
110
- private _delay = [_fireMission , " delay" ] call ALIVE_fnc_hashGet ;
111
146
112
- _unit doArtilleryFire [
113
- _position ,
114
- _roundType ,
115
- 1
116
- ];
147
+ if (_delay > 0 ) then {
148
+ private _unitIndex = [_fireMission , " unitIndex" ] call ALIVE_fnc_hashGet ;
149
+ private _unit = _units select _unitIndex ;
150
+
151
+ _unit doArtilleryFire [
152
+ _position ,
153
+ _roundType ,
154
+ 1
155
+ ];
117
156
118
- if ((_unitIndex + 1 ) > ((count _units ) - 1 )) then {
119
- _unitIndex = 0 ;
157
+ hint format [" %3: _unit: %1 firing 1 %2" , _unit , _roundType , time ];
120
158
} else {
121
- _unitIndex = _unitIndex + 1 ;
159
+ {
160
+ private _roundCount = [_fireMission , " roundCount" ] call ALIVE_fnc_hashGet ;
161
+
162
+ _x doArtilleryFire [
163
+ _position ,
164
+ _roundType ,
165
+ floor (_roundCount / (count _units )) // TODO: Better distribution
166
+ ];
167
+ } forEach _units ;
122
168
};
123
169
124
- [_fireMission , " nextRoundTime" , time + _delay ] call ALIVE_fnc_hashSet ;
125
- [_fireMission , " unitIndex" , _unitIndex ] call ALIVE_fnc_hashSet ;
126
- [_fireMission , " roundsShot" , _roundsShot + 1 ] call ALIVE_fnc_hashSet ;
127
-
170
+ [_fireMission , " nextRoundTime" , - 1 ] call ALIVE_fnc_hashSet ;
128
171
_logic setVariable [" fireMission" , _fireMission ];
129
172
};
130
173
case " fireNextRound" : {
131
- private _fireMission = _logic getVariable [" fireMission" , objNull ];
174
+ private _fireMission = _logic getVariable [" fireMission" , [] ];
132
175
private _nextRoundTime = [_fireMission , " nextRoundTime" ] call ALIVE_fnc_hashGet ;
133
- _result = (time >= _nextRoundTime );
176
+ _result = (_nextRoundTime ! = - 1 && { time >= _nextRoundTime } );
134
177
};
135
178
case " hasFireMission" : {
136
- private _fireMission = _logic getVariable [" fireMission" , objNull ];
179
+ private _fireMission = _logic getVariable [" fireMission" , [] ];
137
180
_result = (count _fireMission > 0 );
138
181
};
139
182
case " isFireMissionComplete" : {
140
- private _fireMission = _logic getVariable [" fireMission" , objNull ];
183
+ private _fireMission = _logic getVariable [" fireMission" , [] ];
141
184
private _roundCount = [_fireMission , " roundCount" ] call ALIVE_fnc_hashGet ;
142
185
private _roundsShot = [_fireMission , " roundsShot" ] call ALIVE_fnc_hashGet ;
143
186
_result = (_roundsShot >= _roundCount );
144
187
};
188
+ case " isFireMissionDelayed" : {
189
+ private _fireMission = _logic getVariable [" fireMission" , []];
190
+ private _delay = [_fireMission , " delay" ] call ALIVE_fnc_hashGet ;
191
+ _result = (_delay > 0 );
192
+ };
145
193
case " inPosition" : {
146
194
private _group = _logic getVariable [" group" , grpNull ];
147
195
_result = _group getVariable [" sup_artillery_inPosition" , false ];
148
196
};
149
197
case " inRange" : {
150
- private _fireMission = _logic getVariable [" fireMission" , objNull ];
198
+ private _fireMission = _logic getVariable [" fireMission" , [] ];
151
199
private _position = [_fireMission , " position" ] call ALIVE_fnc_hashGet ;
152
200
private _roundType = [_fireMission , " roundType" ] call ALIVE_fnc_hashGet ;
153
201
private _group = _logic getVariable [" group" , grpNull ];
@@ -177,7 +225,6 @@ switch (_operation) do {
177
225
" true" ,
178
226
" (group this) setVariable ['sup_artillery_inPosition', true]"
179
227
];
180
- diag_log format [" _group: %1, _position: %2, _waypoint: %3" , _group , _position , _waypoint ];
181
228
};
182
229
case " spawn" : {
183
230
private _position = position _logic ;
@@ -222,7 +269,7 @@ switch (_operation) do {
222
269
};
223
270
case " onActive" : {
224
271
if (! ([_logic , " inRange" ] call MAINCLASS)) then {
225
- _logic setVariable [" moveToPos" , [3451.45 , 5379.89 ,0 ]]; // TODO: Figure out best firing position
272
+ _logic setVariable [" moveToPos" , [3744.56 , 4757.54 ,0 ]]; // TODO: Figure out best firing position
226
273
};
227
274
};
228
275
case " onFire" : {
@@ -239,6 +286,17 @@ switch (_operation) do {
239
286
private _units = (units _group ) select {vehicle _x ! = _x && {gunner (vehicle _x ) == _x }};
240
287
_units doWatch objNull ;
241
288
289
+ // Cleanup event handlers
290
+ {
291
+ private _vehicle = vehicle _x ;
292
+ private _firedEH = _vehicle getVariable [" sup_artillery_firedEH" , nil ];
293
+
294
+ if (! isNil " _firedEH" ) then {
295
+ _vehicle removeEventHandler [" Fired" , _firedEH ];
296
+ _vehicle setVariable [" sup_artillery_firedEH" , nil ];
297
+ };
298
+ } forEach _units ;
299
+
242
300
_logic setVariable [" fireMission" , []];
243
301
[_logic , " move" , [position _logic ]] call MAINCLASS; // TODO: Find (best) RTB position
244
302
};
0 commit comments