DayZ 1.24
Loading...
Searching...
No Matches
Grenade_Base.c
Go to the documentation of this file.
8
11
13{
14 protected static float m_DefaultBrightness = 50;
15 protected static float m_DefaultRadius = 20;
16
18 {
19 SetVisibleDuringDaylight(true);
20 SetRadiusTo(m_DefaultRadius);
21 SetBrightnessTo(m_DefaultBrightness);
22 SetFlareVisible(false);
23 SetAmbientColor(1.0, 1.0, 1.0);
24 SetDiffuseColor(1.0, 1.0, 1.0);
25 SetLifetime(0.35);
26 SetDisableShadowsWithinRadius(-1);
27 }
28}
29
30class Grenade_Base : ExplosivesBase
31{
32 protected const float DEFAULT_FUSE_DELAY = 10;
33
35 protected float m_FuseDelay;
36 protected float m_RemainingFuseTime;
37
38 protected bool m_Pinned;
39 protected bool m_Pinnable;
40 //protected bool m_Explodable; //! DEPRECATED; not used anywhere
41
43
44 void Pin()
45 {
46 if (!m_Pinned && m_Pinnable)
47 OnPin();
48 }
49
50 void Unpin()
51 {
52 if (m_Pinned)
53 OnUnpin();
54 }
55
57 override void OnActivatedByTripWire();
58
60 {
61 if (item == this)
62 {
64 return;
65 }
66
67 Unpin();
68 }
69
70 bool IsPinned()
71 {
72 return m_Pinned;
73 }
74
76 {
78 if (m_FuseTimer.IsRunning())
79 return false;
80
81 return m_Pinnable;
82 }
83
85 {
87 }
88
90 {
91 float delay = Math.RandomFloat(1, 20);
92 delay *= 1000;
93 GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(ActivateImmediate, delay, false);
94 }
95
96 void SetPinnable(bool state)
97 {
99 }
100
101 void SetFuseDelay(float delay)
102 {
104 }
105
107 {
108 m_GrenadeType = type;
109 }
110
112 {
113 return m_GrenadeType;
114 }
115
116 protected void Activate()
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 }
134
135 protected void Deactivate()
136 {
137 if (m_FuseTimer.IsRunning())
138 {
139 m_RemainingFuseTime = m_FuseTimer.GetRemaining();
140 m_FuseTimer.Stop();
141 OnDeactivate();
142 }
143 }
144
145 protected override void InitiateExplosion()
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 }
161
164 {
166 }
167
168 protected void OnPin()
169 {
170 m_Pinned = true;
171 if (GetGame().IsServer())
172 {
173 ForceFarBubble(false);
174 SetSynchDirty();
175 }
176
177 Deactivate();
178 }
179
180 protected void OnUnpin()
181 {
182 m_Pinned = false;
183 if (GetGame().IsServer())
184 {
185 ForceFarBubble(true);
186 SetSynchDirty();
187 }
188
190 }
191
192 protected void OnActivateStarted();
193 protected void OnActivateFinished()
194 {
195 if (GetGame().IsServer())
196 {
197 SetHealth("", "", 0.0); // causes explosion when grenade is destroyed
198 SetTakeable(false);
199 }
200 }
201
202 protected void OnActivateImmediate()
203 {
204 if (GetGame().IsServer())
205 {
206 SetHealth("", "", 0.0); // causes explosion when grenade is destroyed
207 SetTakeable(false);
208 }
209 }
210
211 protected void OnDeactivate();
212
214 {
215 super.OnStoreSave(ctx);
216
217 if (GetGame().SaveVersion() >= 107)
218 ctx.Write(m_Pinned);
219 }
220
221 override bool OnStoreLoad(ParamsReadContext ctx, int version)
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 }
237
238 override bool CanBeArmed()
239 {
240 return false;
241 }
242
243 override bool CanBeDisarmed()
244 {
245 return false;
246 }
247
248 override bool CanExplodeInFire()
249 {
250 return true;
251 }
252
253 override void SetActions()
254 {
255 super.SetActions();
256
257 AddAction(ActionUnpin);
258 AddAction(ActionPin);
259 }
260
262 {
263 super.EEItemLocationChanged(oldLoc, newLoc);
264
266 if (newLoc.GetType() != InventoryLocationType.HANDS && !IsPinned())
267 Activate();
268 }
269
270 override void OnWasAttached(EntityAI parent, int slot_id)
271 {
272 super.OnWasAttached(parent, slot_id);
273
274 if (parent.IsAnyInherited({TrapBase, ImprovisedExplosive}))
275 {
276 Deactivate();
277 }
278 }
279
281 {
282 m_Pinned = true;
283 m_FuseTimer = new Timer;
285
286 SetPinnable(true);
288 SetGrenadeType(EGrenadeType.FRAGMENTATION);
289
290 RegisterNetSyncVariableBool("m_Pinned");
291 }
292}
void AddAction(typename actionName)
float m_DefaultRadius
enum eAreaDecayStage m_DefaultBrightness
DamageType
exposed from C++ (do not change)
void OnExplode()
ref array< string > m_AmmoTypes
void FlashGrenadeLight()
EGrenadeType
Definition Grenade_Base.c:2
@ CHEMICAL
Definition Grenade_Base.c:4
@ FRAGMENTATION
Definition Grenade_Base.c:3
@ NON_LETHAL
Definition Grenade_Base.c:6
@ ILLUMINATING
Definition Grenade_Base.c:5
InventoryLocationType
types of Inventory Location
override void SetTakeable(bool pState)
Definition ItemBase.c:8905
override void Explode(int damageType, string ammoType="")
override bool OnStoreLoad(ParamsReadContext ctx, int version)
void OnActivateFinished()
const float DEFAULT_FUSE_DELAY
void ActivateRandomTime()
override void SetActions()
override bool CanExplodeInFire()
override bool CanBeDisarmed()
void SetFuseDelay(float delay)
void OnActivateImmediate()
override bool CanBeArmed()
bool IsPinnable()
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
float m_RemainingFuseTime
ref Timer m_FuseTimer
void SetGrenadeType(EGrenadeType type)
void SetPinnable(bool state)
override void OnActivatedByItem(notnull ItemBase item)
bool IsPinned()
override void OnStoreSave(ParamsWriteContext ctx)
EGrenadeType m_GrenadeType
EGrenadeType GetGrenadeType()
void ActivateImmediate()
void Deactivate()
float m_FuseDelay
override void InitiateExplosion()
void ExplodeGrenade(EGrenadeType grenade_type)
DEPRECATED - for backward compatibility only.
override void OnActivatedByTripWire()
DEPRECATED use OnActivatedByItem.
void OnActivateStarted()
void OnDeactivate()
override void OnWasAttached(EntityAI parent, int slot_id)
void Grenade_Base()
InventoryLocation.
Definition EnMath.c:7
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
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