Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FiringRangeTarget.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/FiringRange", description: "Handeles behaviour of target. Evaluates a hit.", color: "0 0 255 255")]
6
8{
11};
12
14{
17};
18
19class SCR_FiringRangeTarget : BaseBuilding
20{
21
23 protected int m_iDesiredState;
24
26 [Attribute("3", UIWidgets.Slider, "Target in stays in folded position for... seconds", "1 100 3")]
27 protected float m_fTimeInFoldedPosition;
28
30 [Attribute("1", UIWidgets.Slider, "How far is the target from shooting line.", "1 9999 50")]
31 protected int m_iTargetDistance;
32
34 [Attribute("3", UIWidgets.Slider, "Target stays in erected position for... seconds", "0.5 10 0.5")]
35 protected float m_fTimeInErectedPosition;
36
38 [Attribute( defvalue: "0", uiwidget: UIWidgets.CheckBox, desc: "Set if the target has to be used as hit indicator." )]
39 protected bool m_bIsIndicator;
40
41 // If true, target is reset to standing position after set time
42 [Attribute( defvalue: "1", uiwidget: UIWidgets.CheckBox, desc: "Set if the target should be reset to erected position." ), RplProp()]
43 private bool m_bAutoResetTarget;
44
45 //Internal value for keeping target down for a while
46 [RplProp()]
47 protected bool m_bWaitInPosition = false;
48
49 // Signal manager to pass signals into proc anim
50 private SignalsManagerComponent m_SignalManager;
51 private int m_iTargetHitSignal;
52
53 // Firing range controller
54 private SCR_FiringRangeController m_LineController;
55 private SCR_FiringRangeManager m_FiringRangeManager;
56
57 // Proc anim component
58 private ProcAnimComponent m_ProcAnimComponent;
59
60 // RPL component
61 private RplComponent m_RplComponent;
62
63 // time for how long the target should stay folded
64 protected float m_fFallenTargetTimer;
65
66 // Variable preventing multiple hit evaluation
67 protected bool m_bTargetHit = false;
68
69 // Owner of the target (parent entity)
70 private IEntity m_OwnerEntity = null;
71
72 // Target owenr (player)
73 private int m_iTargetOwner = -1;
74
75 //--- Target modes
76 private int m_iTargetMode = -1;
77
78 // value of hit (score)
79 private int m_iHitValue;
80
81 // state of the target for JIP
82 private int m_iTargetState;
83
84 private IEntity m_FiringLineController;
85
86 ref ScriptInvoker Event_TargetChangeState = new ScriptInvoker;
87
88 // target scoring points
89 const float SCORE_CENTER = 10;
90 const float SCORE_CIRCLE_1 = 5;
91 const float SCORE_CIRCLE_2 = 3;
92 const float SCORE_CIRCLE_3 = 1;
93
94 // definition of areas on target for scoring
95 // 10 points area
96 const float AREA_10_W_LEFT = 0.03;
97 const float AREA_10_W_RIGHT = -0.03;
98 const float AREA_10_H_UP = 1.15;
99 const float AREA_10_H_DOWN = 1.03;
100
101 // 5 points area
102 const float AREA_5_W_LEFT = 0.08;
103 const float AREA_5_W_RIGHT = -0.08;
104 const float AREA_5_H_UP = 1.2;
105 const float AREA_5_H_DOWN = 0.98;
106
107 // 3 points area
108 const float AREA_3_W_LEFT = 0.13;
109 const float AREA_3_W_RIGHT = -0.13;
110 const float AREA_3_H_UP = 1.32;
111 const float AREA_3_H_DOWN = 0.84;
112
113 // 1 point area
114 const float AREA_1_W_LEFT = 0.28;
115 const float AREA_1_W_RIGHT = -0.28;
116 const float AREA_1_H_UP = 1.77;
117 const float AREA_1_H_DOWN = 0.5;
118
119 const float AREA_BOTTOM_VALID = 0.40;
120
121 //------------------------------------------------------------------------------------------------
122 override void OnDamage(float damage,
124 IEntity pHitEntity,
125 inout vector outMat[3], // Hit position/direction/normal
126 IEntity damageSource,
127 notnull Instigator instigator,
128 int colliderID,
129 float speed)
130 {
131
132 if (IsProxy())
133 return;
134
135 // don't continue if projectile hit the stand of the target.
136 if (!IsHitValid(CoordToLocal(outMat[0])))
137 return;
138
139 super.OnDamage(damage,type,pHitEntity,outMat,damageSource,instigator,colliderID,speed);
140
141 // check if target is in erected state
142 if (GetState() != ETargetState.TARGET_UP)
143 return;
144
145 // target was already hit. Multiple execution check
146 if (m_bTargetHit)
147 return;
148 m_bTargetHit = true;
149
150 SetState(ETargetState.TARGET_DOWN);
151
152 // activate entity EOnFrame
153 SetEventMask(EntityEvent.FRAME);
154
155 // get lobby
156 // get ID of the player who hits the target
157 int playerID = instigator.GetInstigatorPlayerID();
158
159 // check if the player is also the owner of the target or the target is in training mode
160 if (m_iTargetOwner == playerID || m_iTargetMode == ETargetMode.TRAINING)
161 {
162 // Check if the Firing range manager exists
163 if (!m_FiringRangeManager)
164 return;
165
166 if (GetValidityOfHit(CoordToLocal(outMat[0])))
167 m_FiringRangeManager.AddIndicator(CoordToLocal(outMat[0]),VectorToLocal(outMat[2] * -0.1), pHitEntity);
168 }
169
170 // only if owner of the target is the player, count score
171 if (m_iTargetOwner == playerID && m_iTargetMode == ETargetMode.COMPETITION)
172 {
173 GetHitValue(CoordToLocal(outMat[0]),playerID);
174 }
175 }
176
177 //------------------------------------------------------------------------------------------------
179 void SetState(int state)
180 {
181 Rpc(SetStateMP, state);
182 SetStateMP(state);
183 Replication.BumpMe();
184 }
185
186 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
187 void SetStateMP(int state)
188 {
189 m_iDesiredState = state;
190 Event_TargetChangeState.Invoke(state, this);
191 if (m_iDesiredState == ETargetState.TARGET_DOWN)
192 {
193 // Reset time for how long the target should lie down.
195 // Start timer which will erect target.
196 m_bWaitInPosition = true;
197 // Animate target
198 if (m_SignalManager)
199 m_SignalManager.SetSignalValue(m_iTargetHitSignal, ETargetState.TARGET_DOWN);
200 // Play sound
201 SCR_SoundManagerModule.CreateAndPlayAudioSource(this, SCR_SoundEvent.SOUND_TARGET_DOWN);
202 // Count the targets
203 if (m_LineController)
204 m_LineController.CountPopUpTargets();
205 Replication.BumpMe();
206 }
207 else
208 {
210 m_bTargetHit = false;
211 m_bWaitInPosition = false;
212 // Animate target
213 if (m_SignalManager)
214 m_SignalManager.SetSignalValue(m_iTargetHitSignal, ETargetState.TARGET_UP);
215 // Play sound
216 SCR_SoundManagerModule.CreateAndPlayAudioSource(this, SCR_SoundEvent.SOUND_TARGET_UP);
217
218 Replication.BumpMe();
219 }
220 }
221
222 //------------------------------------------------------------------------------------------------
224 bool IsProxy()
225 {
226 return (m_RplComponent && m_RplComponent.IsProxy());
227 }
228
229 //------------------------------------------------------------------------------------------------
231 int GetState()
232 {
233 if (!m_SignalManager)
234 return 0;
235 return m_SignalManager.GetSignalValue(m_SignalManager.FindSignal("target_hit"));
236 }
237
238 //------------------------------------------------------------------------------------------------
240 int GetSetDistance()
241 {
242 return m_iTargetDistance;
243 }
244
245 //------------------------------------------------------------------------------------------------
247 int GetTargetOwner()
248 {
249 return m_iTargetOwner;
250 }
251
252 //------------------------------------------------------------------------------------------------
254 void SetTargetOwner(int playerID)
255 {
256 m_iTargetOwner = playerID;
257 }
258
259 //------------------------------------------------------------------------------------------------
261 void SetTargetMode(int targetMode)
262 {
263 m_iTargetMode = targetMode;
264 }
265
266 //------------------------------------------------------------------------------------------------
268 int GetErectedDuration()
269 {
270 //recalculate seconds to miliseconds
271 return m_fTimeInErectedPosition * 1000;
272 }
273
274 //------------------------------------------------------------------------------------------------
276 bool GetValidityOfHit(vector coordOfHit)
277 {
278 float HitY = coordOfHit[1];
279 if (HitY > AREA_1_H_DOWN)
280 return true;
281
282 return false;
283 }
284
285 //------------------------------------------------------------------------------------------------
287 void SetAutoResetTarget(bool state)
288 {
289 m_bAutoResetTarget = state;
290 }
291
292 //------------------------------------------------------------------------------------------------
294 bool IsHitValid(vector coordOfHit)
295 {
296 float HitX = coordOfHit[0];
297 float HitY = coordOfHit[1];
298
299 if (HitX < AREA_1_W_LEFT && HitX > AREA_1_W_RIGHT && HitY < AREA_1_H_UP && HitY > AREA_BOTTOM_VALID)
300 return true;
301
302 return false;
303 }
304
305 //------------------------------------------------------------------------------------------------
307 bool IsIndicator()
308 {
309 return m_bIsIndicator;
310 }
311
312 //------------------------------------------------------------------------------------------------
314 void GetHitValue(vector coordOfHit, int playerID)
315 {
316 PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerID);
317 if (!playerController)
318 return;
319
320 float HitX = coordOfHit[0];
321 float HitY = coordOfHit[1];
322
323 if (HitX < AREA_10_W_LEFT && HitX > AREA_10_W_RIGHT && HitY < AREA_10_H_UP && HitY > AREA_10_H_DOWN)
324 m_iHitValue = SCORE_CENTER;
325
326 else if (HitX < AREA_5_W_LEFT && HitX > AREA_5_W_RIGHT && HitY < AREA_5_H_UP && HitY > AREA_5_H_DOWN)
327 m_iHitValue = SCORE_CIRCLE_1;
328
329 else if (HitX < AREA_3_W_LEFT && HitX > AREA_3_W_RIGHT && HitY < AREA_3_H_UP && HitY > AREA_3_H_DOWN)
330 m_iHitValue = SCORE_CIRCLE_2;
331
332 else if (HitX < AREA_1_W_LEFT && HitX > AREA_1_W_RIGHT && HitY < AREA_1_H_UP && HitY > AREA_1_H_DOWN)
333 m_iHitValue = SCORE_CIRCLE_3;
334
335 m_FiringRangeManager.CountPlayerScore(m_iTargetOwner, m_iHitValue);
336 }
337
338 //------------------------------------------------------------------------------------------------
339 override void EOnFrame(IEntity owner, float timeSlice)
340 {
341 // This counter runs, if the target was animated down after hit and at the same time m_bAutoResetTarget is true (that means target is in default mode, not in competition one)
342 if (m_bWaitInPosition && m_bAutoResetTarget)
343 {
345 {
346 m_fFallenTargetTimer+= timeSlice;
347 }
348 else
349 {
350 // Flip target back to standing position
351 SetState(ETargetState.TARGET_UP);
352 // deactivate entity EOnFrame
353 ClearEventMask(EntityEvent.FRAME);
354 }
355 }
356 }
357
358 //------------------------------------------------------------------------------------------------
359 override bool RplSave(ScriptBitWriter writer)
360 {
361 // Save targets state.
362 m_iTargetState = GetState();
363 writer.Write(m_iTargetState, 1);
364 return true;
365 }
366
367 //------------------------------------------------------------------------------------------------
368 override bool RplLoad(ScriptBitReader reader)
369 {
370 // Load targets state.
371 if (!reader.Read(m_iTargetState, 1)) return false;
372 SetState(m_iTargetState);
373 return true;
374 }
375
376 //------------------------------------------------------------------------------------------------
377 override void EOnInit(IEntity owner)
378 {
379 m_SignalManager = SignalsManagerComponent.Cast(FindComponent(SignalsManagerComponent));
380 m_ProcAnimComponent = ProcAnimComponent.Cast(FindComponent(ProcAnimComponent));
381
382 if (!m_SignalManager)
383 return;
384
385 // Get the signal index
386 m_iTargetHitSignal = m_SignalManager.FindSignal("target_hit");
387 SetTargetMode(ETargetMode.TRAINING);
388
389 m_OwnerEntity = owner.GetParent();
390 if (!m_OwnerEntity)
391 return;
392
393 m_LineController = SCR_FiringRangeController.Cast(m_OwnerEntity);
394 if (!m_LineController)
395 return;
396
397 if (m_bIsIndicator)
398 m_LineController.SetIndicator(owner);
399
400 m_FiringRangeManager = SCR_FiringRangeManager.Cast(m_OwnerEntity.GetParent());
401 if (!m_FiringRangeManager)
402 return;
403
404 m_RplComponent = RplComponent.Cast(m_FiringRangeManager.FindComponent(RplComponent));
405 }
406
407 //------------------------------------------------------------------------------------------------
408 void SCR_FiringRangeTarget(IEntitySource src, IEntity parent)
409 {
410 SetEventMask(EntityEvent.INIT);
411 m_FiringLineController = parent;
412 }
413
414 //------------------------------------------------------------------------------------------------
415 void ~SCR_FiringRangeTarget()
416 {
417 }
418};
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
SCR_CharacterBloodHitZone OnDamage
Resilience - incapacitation or death, depending on game mode settings.
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
EDamageType type
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
enum EVehicleType IEntity
proto external IEntity GetParent()
Main replication API.
Definition Replication.c:14
int m_iDesiredState
Current state at any given time.
float m_fTimeInErectedPosition
Time, for how long target stays in erected position.
bool m_bIsIndicator
Set if the target is firing line indicator or regular target.
float m_fTimeInFoldedPosition
Delay for how long target stays down.
int m_iTargetDistance
Distance of the target.
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EDamageType
Definition EDamageType.c:13
proto external EParticleEffectState GetState()
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134