DayZ 1.24
Loading...
Searching...
No Matches
Grenade_Base Class Reference
Inheritance diagram for Grenade_Base:
[legend]
Collaboration diagram for Grenade_Base:
[legend]

Protected Member Functions

override void CreateLight ()
 
void ~FlashGrenade ()
 
void Pin ()
 
void Unpin ()
 
override void OnActivatedByTripWire ()
 DEPRECATED use OnActivatedByItem.
 
override void OnActivatedByItem (notnull ItemBase item)
 
bool IsPinned ()
 
bool IsPinnable ()
 
void ActivateImmediate ()
 
void ActivateRandomTime ()
 
void SetPinnable (bool state)
 
void SetFuseDelay (float delay)
 
void SetGrenadeType (EGrenadeType type)
 
EGrenadeType GetGrenadeType ()
 
void Activate ()
 
void Deactivate ()
 
override void InitiateExplosion ()
 
void ExplodeGrenade (EGrenadeType grenade_type)
 DEPRECATED - for backward compatibility only.
 
void OnPin ()
 
void OnUnpin ()
 
void OnActivateStarted ()
 
void OnActivateFinished ()
 
void OnActivateImmediate ()
 
void OnDeactivate ()
 
override void OnStoreSave (ParamsWriteContext ctx)
 
override bool OnStoreLoad (ParamsReadContext ctx, int version)
 
override bool CanBeArmed ()
 
override bool CanBeDisarmed ()
 
override bool CanExplodeInFire ()
 
override void SetActions ()
 
override void EEItemLocationChanged (notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
 
override void OnWasAttached (EntityAI parent, int slot_id)
 
void Grenade_Base ()
 

Protected Attributes

const float DEFAULT_FUSE_DELAY = 10
 
ref Timer m_FuseTimer
 
float m_FuseDelay
 
float m_RemainingFuseTime
 
bool m_Pinned
 
bool m_Pinnable
 
EGrenadeType m_GrenadeType
 

Private Member Functions

override void OnExplosionEffects (Object source, Object directHit, int componentIndex, string surface, vector pos, vector surfNormal, float energyFactor, float explosionFactor, bool isWater, string ammoType)
 
void FlashGrenade ()
 
void M67Grenade ()
 
void ~M67Grenade ()
 
void RGD5Grenade ()
 
void ~RGD5Grenade ()
 

Private Attributes

const float FX_RANGE_MAX_MULT = 1.0
 

Detailed Description

Definition at line 1 of file FlashGrenade.c.

Constructor & Destructor Documentation

◆ ~FlashGrenade()

void Grenade_Base::~FlashGrenade ( )
inlineprotected

Definition at line 90 of file FlashGrenade.c.

90{}

◆ ~M67Grenade()

void Grenade_Base::~M67Grenade ( )
inlineprivate

Definition at line 10 of file M67Grenade.c.

10{}

◆ ~RGD5Grenade()

void Grenade_Base::~RGD5Grenade ( )
inlineprivate

Definition at line 10 of file RGD5Grenade.c.

10{}

◆ Grenade_Base()

void Grenade_Base::Grenade_Base ( )
inlineprotected

Definition at line 280 of file Grenade_Base.c.

281 {
282 m_Pinned = true;
283 m_FuseTimer = new Timer;
285
286 SetPinnable(true);
288 SetGrenadeType(EGrenadeType.FRAGMENTATION);
289
290 RegisterNetSyncVariableBool("m_Pinned");
291 }
EGrenadeType
Definition Grenade_Base.c:2
const float DEFAULT_FUSE_DELAY
void SetFuseDelay(float delay)
float m_RemainingFuseTime
ref Timer m_FuseTimer
void SetGrenadeType(EGrenadeType type)
void SetPinnable(bool state)

References DEFAULT_FUSE_DELAY, m_FuseTimer, m_Pinned, m_RemainingFuseTime, SetFuseDelay(), SetGrenadeType(), and SetPinnable().

Member Function Documentation

◆ Activate()

void Grenade_Base::Activate ( )
inlineprotected

run only the remaining part (already unpinned and pinned)

Definition at line 116 of file Grenade_Base.c.

117 {
118 if (!m_FuseTimer.IsRunning())
119 {
121 if (m_RemainingFuseTime > 0)
122 {
123 //Debug.Log(string.Format("Grenade activated num of seconds to explosion: %1", m_RemainingFuseTime));
124 m_FuseTimer.Run(m_RemainingFuseTime, this, "OnActivateFinished");
125 }
126 else
127 {
128 //Debug.Log(string.Format("Grenade activated num of seconds to explosion: %1", m_FuseDelay));
129 m_FuseTimer.Run(m_FuseDelay, this, "OnActivateFinished");
130 }
131
132 }
133 }
float m_FuseDelay

References m_FuseDelay, m_FuseTimer, and m_RemainingFuseTime.

Referenced by EEItemLocationChanged().

◆ ActivateImmediate()

void Grenade_Base::ActivateImmediate ( )
inlineprotected

Definition at line 84 of file Grenade_Base.c.

85 {
87 }
void OnActivateImmediate()

References OnActivateImmediate().

Referenced by ActivateRandomTime().

◆ ActivateRandomTime()

void Grenade_Base::ActivateRandomTime ( )
inlineprotected

to millis

Definition at line 89 of file Grenade_Base.c.

90 {
91 float delay = Math.RandomFloat(1, 20);
92 delay *= 1000;
93 GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(ActivateImmediate, delay, false);
94 }
void ActivateImmediate()
Definition EnMath.c:7
proto native CGame GetGame()
static proto float RandomFloat(float min, float max)
Returns a random float number between and min[inclusive] and max[exclusive].
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10

References ActivateImmediate(), CALL_CATEGORY_GAMEPLAY, GetGame(), and Math::RandomFloat().

◆ CanBeArmed()

override bool Grenade_Base::CanBeArmed ( )
inlineprotected

Definition at line 238 of file Grenade_Base.c.

239 {
240 return false;
241 }

◆ CanBeDisarmed()

override bool Grenade_Base::CanBeDisarmed ( )
inlineprotected

Definition at line 243 of file Grenade_Base.c.

244 {
245 return false;
246 }

◆ CanExplodeInFire()

override bool Grenade_Base::CanExplodeInFire ( )
inlineprotected

Definition at line 248 of file Grenade_Base.c.

249 {
250 return true;
251 }

◆ CreateLight()

override void Grenade_Base::CreateLight ( )
inlineprotected

Definition at line 85 of file FlashGrenade.c.

86 {
88 }
ExplosiveLight m_Light
light
void FlashGrenadeLight()
class JsonUndergroundAreaTriggerData GetPosition

References FlashGrenadeLight(), GetPosition, and m_Light.

◆ Deactivate()

void Grenade_Base::Deactivate ( )
inlineprotected

Definition at line 135 of file Grenade_Base.c.

136 {
137 if (m_FuseTimer.IsRunning())
138 {
139 m_RemainingFuseTime = m_FuseTimer.GetRemaining();
140 m_FuseTimer.Stop();
141 OnDeactivate();
142 }
143 }
void OnDeactivate()

References m_FuseTimer, m_RemainingFuseTime, and OnDeactivate().

Referenced by OnPin(), and OnWasAttached().

◆ EEItemLocationChanged()

override void Grenade_Base::EEItemLocationChanged ( notnull InventoryLocation oldLoc,
notnull InventoryLocation newLoc )
inlineprotected

activate grenade when it leaves player hands (safety handle released)

Definition at line 261 of file Grenade_Base.c.

262 {
263 super.EEItemLocationChanged(oldLoc, newLoc);
264
266 if (newLoc.GetType() != InventoryLocationType.HANDS && !IsPinned())
267 Activate();
268 }
InventoryLocationType
types of Inventory Location
bool IsPinned()

References Activate(), and IsPinned().

◆ ExplodeGrenade()

void Grenade_Base::ExplodeGrenade ( EGrenadeType grenade_type)
inlineprotected

DEPRECATED - for backward compatibility only.

Definition at line 163 of file Grenade_Base.c.

164 {
166 }
override void InitiateExplosion()

References InitiateExplosion().

◆ FlashGrenade()

void Grenade_Base::FlashGrenade ( )
inlineprivate

Definition at line 77 of file FlashGrenade.c.

78 {
79 SetAmmoType("FlashGrenade_Ammo");
80 SetFuseDelay(2);
81 SetGrenadeType(EGrenadeType.ILLUMINATING);
83 }
void SetParticleExplosion(int particle)
void SetAmmoType(string pAmmoType)
static const int GRENADE_M84

References ParticleList::GRENADE_M84, SetAmmoType(), SetFuseDelay(), SetGrenadeType(), and SetParticleExplosion().

◆ GetGrenadeType()

EGrenadeType Grenade_Base::GetGrenadeType ( )
inlineprotected

Definition at line 111 of file Grenade_Base.c.

112 {
113 return m_GrenadeType;
114 }
EGrenadeType m_GrenadeType

References m_GrenadeType.

Referenced by InitiateExplosion().

◆ InitiateExplosion()

override void Grenade_Base::InitiateExplosion ( )
inlineprotected

Definition at line 145 of file Grenade_Base.c.

146 {
147 switch (GetGrenadeType())
148 {
149 case EGrenadeType.FRAGMENTATION:
150 case EGrenadeType.ILLUMINATING:
151 for (int i = 0; i < m_AmmoTypes.Count(); i++)
152 Explode(DamageType.EXPLOSION, m_AmmoTypes[i]);
153 break;
154 case EGrenadeType.CHEMICAL:
155 case EGrenadeType.NON_LETHAL:
156 break;
157 }
158
159 OnExplode();
160 }
DamageType
exposed from C++ (do not change)
void OnExplode()
ref array< string > m_AmmoTypes
override void Explode(int damageType, string ammoType="")
EGrenadeType GetGrenadeType()

References Explode(), GetGrenadeType(), m_AmmoTypes, and OnExplode().

Referenced by ExplodeGrenade().

◆ IsPinnable()

bool Grenade_Base::IsPinnable ( )
inlineprotected

cannot be pinned once the fuse has started

Definition at line 75 of file Grenade_Base.c.

76 {
78 if (m_FuseTimer.IsRunning())
79 return false;
80
81 return m_Pinnable;
82 }

References m_FuseTimer, and m_Pinnable.

◆ IsPinned()

bool Grenade_Base::IsPinned ( )
inlineprotected

Definition at line 70 of file Grenade_Base.c.

71 {
72 return m_Pinned;
73 }

References m_Pinned.

Referenced by EEItemLocationChanged().

◆ M67Grenade()

void Grenade_Base::M67Grenade ( )
inlineprivate

Definition at line 3 of file M67Grenade.c.

4 {
5 SetAmmoType("M67Grenade_Ammo");
8 }
static const int M67

References ParticleList::M67, SetAmmoType(), SetFuseDelay(), and SetParticleExplosion().

◆ OnActivatedByItem()

override void Grenade_Base::OnActivatedByItem ( notnull ItemBase item)
inlineprotected

Definition at line 59 of file Grenade_Base.c.

60 {
61 if (item == this)
62 {
64 return;
65 }
66
67 Unpin();
68 }
void OnActivateFinished()

References OnActivateFinished(), and Unpin().

◆ OnActivatedByTripWire()

override void Grenade_Base::OnActivatedByTripWire ( )
protected

DEPRECATED use OnActivatedByItem.

◆ OnActivateFinished()

void Grenade_Base::OnActivateFinished ( )
inlineprotected

Definition at line 193 of file Grenade_Base.c.

194 {
195 if (GetGame().IsServer())
196 {
197 SetHealth("", "", 0.0); // causes explosion when grenade is destroyed
198 SetTakeable(false);
199 }
200 }
override void SetTakeable(bool pState)
Definition ItemBase.c:8905

References GetGame(), and SetTakeable().

Referenced by Grenade_ChemGas::EOnContact(), and OnActivatedByItem().

◆ OnActivateImmediate()

void Grenade_Base::OnActivateImmediate ( )
inlineprotected

Definition at line 202 of file Grenade_Base.c.

203 {
204 if (GetGame().IsServer())
205 {
206 SetHealth("", "", 0.0); // causes explosion when grenade is destroyed
207 SetTakeable(false);
208 }
209 }

References GetGame(), and SetTakeable().

Referenced by ActivateImmediate().

◆ OnActivateStarted()

void Grenade_Base::OnActivateStarted ( )
protected

Referenced by OnUnpin().

◆ OnDeactivate()

void Grenade_Base::OnDeactivate ( )
protected

Referenced by Deactivate().

◆ OnExplosionEffects()

override void Grenade_Base::OnExplosionEffects ( Object source,
Object directHit,
int componentIndex,
string surface,
vector pos,
vector surfNormal,
float energyFactor,
float explosionFactor,
bool isWater,
string ammoType )
inlineprivate

values less than 1.0 make no sense

removes possible obstacles made by items around the grenade(or on the same position)

Definition at line 5 of file FlashGrenade.c.

6 {
8
10
11 if (player)
12 {
13 vector headPos = player.GetDamageZonePos("Head"); // animated position in the middle of the zone
14 float ammoRangeKill = GetGame().ConfigGetFloat(string.Format("CfgAmmo %1 indirectHitRange", ammoType));
15 float ammoRangeMaxMult = 4.0;
16
17 string indirectHitRangeMultiplier = string.Format("CfgAmmo %1 indirectHitRangeMultiplier", ammoType);
18 if (GetGame().ConfigIsExisting(indirectHitRangeMultiplier))
19 {
21 ammoRangeMaxMult = Math.Clamp(GetGame().ConfigGetFloat(indirectHitRangeMultiplier), 1.0, float.MAX);
22 }
23
26
27 float dist = vector.Distance(headPos, pos);
28 float distSq = vector.DistanceSq(headPos, pos);
30
31 if (distSq <= radiusMaxSq)
32 {
33 // ignore collisions with parent if fireplace
35 EntityAI parent = invItem.GetHierarchyParent();
37
38 if (!parent || !parent.IsFireplace())
39 parent = null;
40 else if (parent)
41 excluded.Insert(parent);
42
44 excluded.Insert(this); //Ignore self for visibility check
45
46 //There shouldn't be cases justifying we go further than first entry (if in fireplace, self does not impact)
48 rayParams.flags = CollisionFlags.ALLOBJECTS;
50
53 for (int i = 0; i < results.Count(); i++)
54 {
55 if (results[i].obj && !results[i].obj.IsInherited(ItemBase))
56 hitObjects.Insert(results[i].obj);
57 }
58
59 //If player is not first index, object is between player and grenade
60 if (hitObjects.Count() && PlayerBase.Cast(hitObjects[0]))
61 {
62 float effectCoef;
64 {
65 effectCoef = 1.0; //edge case, landed right on the edge
66 }
68 effectCoef = Math.Clamp(effectCoef, 0.1, 100.0);
69
70 player.OnPlayerReceiveFlashbangHitStart(MiscGameplayFunctions.IsPlayerOrientedTowardPos(player, pos, 60));
71 player.GetFlashbangEffect().SetupFlashbangValues(effectCoef, effectCoef, effectCoef);
72 }
73 }
74 }
75 }
const int MAX
Definition EnConvert.c:27
PlayerBase GetPlayer()
static proto bool RaycastRVProxy(notnull RaycastRVParams in, out notnull array< ref RaycastRVResult > results, array< Object > excluded=null)
const float FX_RANGE_MAX_MULT
Definition FlashGrenade.c:3
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
CollisionFlags
Definition EnDebug.c:141
static proto float SqrFloat(float f)
Returns squared value.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.

References Math::Clamp(), vector::Distance(), vector::DistanceSq(), GetGame(), GetPlayer(), MAX, DayZPhysics::RaycastRVProxy(), and Math::SqrFloat().

◆ OnPin()

void Grenade_Base::OnPin ( )
inlineprotected

Definition at line 168 of file Grenade_Base.c.

169 {
170 m_Pinned = true;
171 if (GetGame().IsServer())
172 {
173 ForceFarBubble(false);
174 SetSynchDirty();
175 }
176
177 Deactivate();
178 }
void Deactivate()

References Deactivate(), GetGame(), and m_Pinned.

Referenced by Pin().

◆ OnStoreLoad()

override bool Grenade_Base::OnStoreLoad ( ParamsReadContext ctx,
int version )
inlineprotected

Definition at line 221 of file Grenade_Base.c.

222 {
223 if (!super.OnStoreLoad(ctx, version))
224 return false;
225
226 bool pinned;
227 if (version >= 107)
228 {
229 if (!ctx.Read(pinned))
230 return false;
231
233 }
234
235 return true;
236 }

References m_Pinned.

◆ OnStoreSave()

override void Grenade_Base::OnStoreSave ( ParamsWriteContext ctx)
inlineprotected

Definition at line 213 of file Grenade_Base.c.

214 {
215 super.OnStoreSave(ctx);
216
217 if (GetGame().SaveVersion() >= 107)
218 ctx.Write(m_Pinned);
219 }

References GetGame(), and m_Pinned.

◆ OnUnpin()

void Grenade_Base::OnUnpin ( )
inlineprotected

Definition at line 180 of file Grenade_Base.c.

181 {
182 m_Pinned = false;
183 if (GetGame().IsServer())
184 {
185 ForceFarBubble(true);
186 SetSynchDirty();
187 }
188
190 }
void OnActivateStarted()

References GetGame(), m_Pinned, and OnActivateStarted().

Referenced by Unpin().

◆ OnWasAttached()

override void Grenade_Base::OnWasAttached ( EntityAI parent,
int slot_id )
inlineprotected

Definition at line 270 of file Grenade_Base.c.

271 {
272 super.OnWasAttached(parent, slot_id);
273
274 if (parent.IsAnyInherited({TrapBase, ImprovisedExplosive}))
275 {
276 Deactivate();
277 }
278 }

References Deactivate().

◆ Pin()

void Grenade_Base::Pin ( )
inlineprotected

Definition at line 44 of file Grenade_Base.c.

45 {
46 if (!m_Pinned && m_Pinnable)
47 OnPin();
48 }

References m_Pinnable, m_Pinned, and OnPin().

◆ RGD5Grenade()

void Grenade_Base::RGD5Grenade ( )
inlineprivate

Definition at line 3 of file RGD5Grenade.c.

4 {
5 SetAmmoType("RGD5Grenade_Ammo");
8 }
static const int RGD5

References ParticleList::RGD5, SetAmmoType(), SetFuseDelay(), and SetParticleExplosion().

◆ SetActions()

override void Grenade_Base::SetActions ( )
inlineprotected

Definition at line 253 of file Grenade_Base.c.

254 {
255 super.SetActions();
256
257 AddAction(ActionUnpin);
258 AddAction(ActionPin);
259 }
void AddAction(typename actionName)

References AddAction().

◆ SetFuseDelay()

void Grenade_Base::SetFuseDelay ( float delay)
inlineprotected

Definition at line 101 of file Grenade_Base.c.

102 {
104 }

References m_FuseDelay.

Referenced by FlashGrenade(), Grenade_Base(), M67Grenade(), and RGD5Grenade().

◆ SetGrenadeType()

void Grenade_Base::SetGrenadeType ( EGrenadeType type)
inlineprotected

Definition at line 106 of file Grenade_Base.c.

107 {
108 m_GrenadeType = type;
109 }

References m_GrenadeType.

Referenced by FlashGrenade(), Grenade_Base(), and Grenade_ChemGas::Grenade_ChemGas().

◆ SetPinnable()

void Grenade_Base::SetPinnable ( bool state)
inlineprotected

Definition at line 96 of file Grenade_Base.c.

97 {
99 }

References m_Pinnable.

Referenced by Grenade_Base(), and Grenade_ChemGas::Grenade_ChemGas().

◆ Unpin()

void Grenade_Base::Unpin ( )
inlineprotected

Definition at line 50 of file Grenade_Base.c.

51 {
52 if (m_Pinned)
53 OnUnpin();
54 }

References m_Pinned, and OnUnpin().

Referenced by OnActivatedByItem().

Member Data Documentation

◆ DEFAULT_FUSE_DELAY

const float Grenade_Base::DEFAULT_FUSE_DELAY = 10
protected

Definition at line 32 of file Grenade_Base.c.

Referenced by Grenade_Base().

◆ FX_RANGE_MAX_MULT

const float Grenade_Base::FX_RANGE_MAX_MULT = 1.0
private

Definition at line 3 of file FlashGrenade.c.

◆ m_FuseDelay

float Grenade_Base::m_FuseDelay
protected

Definition at line 35 of file Grenade_Base.c.

Referenced by Activate(), and SetFuseDelay().

◆ m_FuseTimer

ref Timer Grenade_Base::m_FuseTimer
protected

Definition at line 34 of file Grenade_Base.c.

Referenced by Activate(), Deactivate(), Grenade_Base(), and IsPinnable().

◆ m_GrenadeType

EGrenadeType Grenade_Base::m_GrenadeType
protected

Definition at line 42 of file Grenade_Base.c.

Referenced by GetGrenadeType(), and SetGrenadeType().

◆ m_Pinnable

bool Grenade_Base::m_Pinnable
protected

Definition at line 39 of file Grenade_Base.c.

Referenced by IsPinnable(), Pin(), and SetPinnable().

◆ m_Pinned

bool Grenade_Base::m_Pinned
protected

◆ m_RemainingFuseTime

float Grenade_Base::m_RemainingFuseTime
protected

Definition at line 36 of file Grenade_Base.c.

Referenced by Activate(), Deactivate(), and Grenade_Base().


The documentation for this class was generated from the following files: