Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
claymoremine.c
Go to the documentation of this file.
2 {
3  protected const string ANIM_PHASE_PACKED = "Bag";
4  protected const string ANIM_PHASE_DEPLOYED = "Mine";
5  protected const string SELECTION_NAME_LED = "LED";
6 
7  protected ref RemotelyActivatedItemBehaviour m_RAIB;
8  protected ERemoteDetonatorLEDState m_LastLEDState;
9 
10  void ClaymoreMine()
11  {
13 
14  SetAmmoTypes({"ClaymoreMine_Ammo","ClaymoreMine_Secondary_Ammo"});
15  SetParticleExplosion(ParticleList.CLAYMORE_EXPLOSION);
16  SetParticleOrientation("90 0 0");
17 
18  RegisterNetSyncVariableInt("m_RAIB.m_PairDeviceNetIdLow");
19  RegisterNetSyncVariableInt("m_RAIB.m_PairDeviceNetIdHigh");
20  UpdateLED(ERemoteDetonatorLEDState.OFF, true);
21  }
22 
23  override void EOnInit(IEntity other, int extra)
24  {
25  UpdateVisuals();
26  }
27 
28  override void EEKilled(Object killer)
29  {
30  super.EEKilled(killer);
31 #ifdef DIAG_DEVELOPER
32 #ifndef SERVER
33  RemoveDebugVisuals();
34 #endif
35 #endif
36  }
37 
38  override void EEDelete(EntityAI parent)
39  {
40  super.EEDelete(parent);
41 
42 #ifdef DIAG_DEVELOPER
43 #ifndef SERVER
44  RemoveDebugVisuals();
45 #endif
46 #endif
47  }
48 
49  override protected void InitiateExplosion()
50  {
51  if (GetDefused())
52  {
53  return;
54  }
55 
56  super.InitiateExplosion();
57  }
58 
59  override void AfterStoreLoad()
60  {
61  super.AfterStoreLoad();
62 
63  UpdateVisuals();
64  if (GetArmed())
65  {
66  UpdateLED(ERemoteDetonatorLEDState.LIT, true);
67  }
68  }
69 
70  override void OnVariablesSynchronized()
71  {
72  super.OnVariablesSynchronized();
73 
74  if (m_RAIB)
75  {
76  m_RAIB.OnVariableSynchronized();
77  }
78 
79  UpdateVisuals();
80  }
81 
82  override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
83  {
84  super.EEItemLocationChanged(oldLoc, newLoc);
85 
86  if (m_RAIB)
87  {
88  m_RAIB.Pair();
89  }
90  }
91 
92 
93 
94  override RemotelyActivatedItemBehaviour GetRemotelyActivatedItemBehaviour()
95  {
96  return m_RAIB;
97  }
98 
99  override void PairRemote(notnull EntityAI trigger)
100  {
101  m_RAIB.Pair(trigger);
102  }
103 
104  override EntityAI GetPairDevice()
105  {
106  return m_RAIB.GetPairDevice();
107  }
108 
109  override bool CanBeDisarmed()
110  {
111  return GetArmed();
112  }
113 
114  override void OnActivatedByItem(notnull ItemBase item)
115  {
116  if (GetGame().IsServer())
117  {
118  if (m_RAIB.IsPaired() && GetArmed())
119  {
120  if (GetPairDevice() == item)
121  {
122  SetHealth("", "", 0.0);
123  }
124  }
125  }
126  }
127 
128  override void OnArmed()
129  {
130  super.OnArmed();
131 
132  UpdateVisuals();
133  UpdateLED(ERemoteDetonatorLEDState.LIT, true);
134 
135 #ifdef DIAG_DEVELOPER
136 #ifndef SERVER
137  // have to call this function a little later, after claymore transform has been finalized
138  GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(DrawDamageZone, 500);
139 #endif
140 #endif
141  }
142 
143  override void OnDisarmed(bool pWithTool)
144  {
145  super.OnDisarmed(pWithTool);
146 
147 #ifdef DIAG_DEVELOPER
148  RemoveDebugVisuals();
149 #endif
150 
151  SetDefused(pWithTool);
152  UnpairRemote();
153 
154  if (pWithTool)
155  {
156  SetHealth("", "", 0.0);
157  }
158 
159  UpdateVisuals();
160  UpdateLED(ERemoteDetonatorLEDState.OFF, true);
161  }
162 
163  override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
164  {
165  super.OnPlacementComplete(player, position, orientation);
166 
167  if (GetGame().IsServer())
168  {
169  RemoteDetonatorTrigger rdt = RemoteDetonatorTrigger.SpawnInPlayerHands(player);
170  if (rdt)
171  {
172  PairWithDevice(rdt);
173  Arm();
174  }
175  }
176  }
177 
178  protected void UpdateVisuals()
179  {
180  if (GetArmed() || GetDefused())
181  {
182  ShowSelection(ANIM_PHASE_DEPLOYED);
183  HideSelection(ANIM_PHASE_PACKED);
184  if (GetOnViewIndexChanged())
185  {
186  GetOnViewIndexChanged().Invoke();
187  }
188  }
189  else
190  {
191  HideSelection(ANIM_PHASE_DEPLOYED);
192  ShowSelection(ANIM_PHASE_PACKED);
193  if (GetOnViewIndexChanged())
194  {
195  GetOnViewIndexChanged().Invoke();
196  }
197  }
198  }
199 
200  protected void UpdateLED(ERemoteDetonatorLEDState pState, bool pForced = false)
201  {
202  if (pState != m_LastLEDState || pForced)
203  {
204  int selectionIdx = GetHiddenSelectionIndex(SELECTION_NAME_LED);
205 
206  switch (pState)
207  {
208  case ERemoteDetonatorLEDState.LIT:
209  SetObjectTexture(selectionIdx, RemoteDetonator.COLOR_LED_LIT);
210  break;
211  default:
212  SetObjectTexture(selectionIdx, RemoteDetonator.COLOR_LED_OFF);
213  break;
214  }
215 
216  m_LastLEDState = pState;
217  }
218  }
219 
220  override bool IsTakeable()
221  {
222  return !GetArmed() && super.IsTakeable();
223  }
224 
225  override bool IsDeployable()
226  {
227  return true;
228  }
229 
230  override void SetActions()
231  {
232  super.SetActions();
233 
237  }
238 
239  override int GetViewIndex()
240  {
241  if (MemoryPointExists("invView2"))
242  {
243  if (GetArmed())
244  {
245  return 1;
246  }
247  }
248 
249  return 0;
250  }
251 
252  override protected bool UsesGlobalDeploy()
253  {
254  return true;
255  }
256 
257  override string GetDeploySoundset()
258  {
259  return "placeClaymore_SoundSet";
260  }
261 
262  override string GetLoopDeploySoundset()
263  {
264  return "claymore_deploy_Soundset";
265  }
266 
267  override void OnDebugSpawn()
268  {
269  RemoteDetonatorTrigger rdt = RemoteDetonatorTrigger.Cast(SpawnEntityOnGroundPos("RemoteDetonatorTrigger", GetPosition() + GetDirection() * 0.5));
270  PairWithDevice(rdt);
271  Arm();
272  }
273 
274 #ifdef DIAG_DEVELOPER
275  //================================================================
276  // DEBUG
277  //================================================================
278 
279  protected Shape m_DamageZone;
280 
281  override protected string GetDebugText()
282  {
283  string debug_output;
284  debug_output += string.Format("low net id: %1\n", m_RAIB.GetPairDeviceNetIdLow());
285  debug_output += string.Format("high net id: %1\n", m_RAIB.GetPairDeviceNetIdHigh());
286  debug_output += string.Format("pair device: %1\n", m_RAIB.GetPairDevice());
287 
288  return debug_output;
289  }
290 
291  protected void DrawDamageZone()
292  {
293  if (!DiagMenu.GetBool(DiagMenuIDs.WEAPON_CLAYMORE_DEBUG))
294  {
295  return;
296  }
297 
298  auto game = GetGame();
299  string cfgPath = "CfgAmmo " + m_AmmoTypes[0];
300  float hitRange = game.ConfigGetFloat(cfgPath + " indirectHitRange");
301  float hitRangeMultiplier = game.ConfigGetFloat(cfgPath + " indirectHitRangeMultiplier");
302  float verticalAngle = game.ConfigGetFloat(cfgPath + " indirectHitAngle1");
303  float horizontalAngle = game.ConfigGetFloat(cfgPath + " indirectHitAngle2");
304  float range = hitRange * hitRangeMultiplier;
305  vector selfMatrix[4];
306 
307  RemoveDebugVisuals();
308 
309  GetTransform(selfMatrix);
310  m_DamageZone = Debug.DrawFrustum(horizontalAngle, verticalAngle, range);
311  m_DamageZone.SetMatrix(selfMatrix);
312  }
313 
314  void RemoveDebugVisuals()
315  {
316  if ( m_DamageZone )
317  {
318  m_DamageZone.Destroy();
319  m_DamageZone = null;
320  }
321  }
322 #endif
323 }
324 
325 class ClaymoreMinePlacing : ClaymoreMine {}
ItemBase
Definition: inventoryitem.c:730
m_AmmoTypes
protected ref array< string > m_AmmoTypes
Definition: explosivesbase.c:26
GetGame
proto native CGame GetGame()
CALL_CATEGORY_SYSTEM
const int CALL_CATEGORY_SYSTEM
Definition: tools.c:8
SetParticleExplosion
void SetParticleExplosion(int particle)
Definition: explosivesbase.c:294
ActionDeployObject
PlaceObjectActionReciveData ActionReciveData ActionDeployObject()
Definition: actiondeployobject.c:9
ERemoteDetonatorLEDState
ERemoteDetonatorLEDState
Definition: remotedetonator.c:1
GetArmed
bool GetArmed()
Definition: explosivesbase.c:236
DiagMenu
Definition: endebug.c:232
Arm
void Arm()
Definition: explosivesbase.c:207
PairWithDevice
bool PairWithDevice(notnull ItemBase otherDevice)
Definition: itembase.c:4629
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
ClaymoreMine
Definition: claymoremine.c:1
m_LastLEDState
protected ERemoteDetonatorLEDState m_LastLEDState
Definition: remotedetonator.c:13
RemotelyActivatedItemBehaviour
Definition: remotelyactivateditembehaviour.c:1
IEntity
Definition: enentity.c:164
ActionTogglePlaceObject
Definition: actiontoggleplaceobject.c:1
ExplosivesBase
void ExplosivesBase()
Definition: explosivesbase.c:40
DiagMenuIDs
DiagMenuIDs
Definition: ediagmenuids.c:1
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
ParticleList
Definition: particlelist.c:11
vector
Definition: enconvert.c:105
ActionArmExplosive
ActionArmExplosiveCB ActionContinuousBaseCB ActionArmExplosive()
Definition: actionarmexplosive.c:18
SetParticleOrientation
void SetParticleOrientation(vector local_ori)
Definition: explosivesbase.c:310
UnpairRemote
override void UnpairRemote()
Definition: remotedetonator.c:109
SetDefused
protected void SetDefused(bool state)
Definition: explosivesbase.c:277
GetDebugText
string GetDebugText()
Definition: modifierbase.c:68
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
Object
Definition: objecttyped.c:1
m_DamageZone
RepairCarChassisActionReciveData m_DamageZone
RemoteDetonatorTrigger
Definition: remotedetonator.c:46
GetDefused
bool GetDefused()
Definition: explosivesbase.c:272
m_RAIB
protected ref RemotelyActivatedItemBehaviour m_RAIB
Definition: remotedetonator.c:41
Debug
Definition: debug.c:13
SELECTION_NAME_LED
const string SELECTION_NAME_LED
Definition: remotedetonator.c:11
EntityAI
Definition: building.c:5
SetAmmoTypes
void SetAmmoTypes(array< string > pAmmoTypes)
Definition: explosivesbase.c:288
Shape
class DiagMenu Shape
don't call destructor directly. Use Destroy() instead