Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
weapon_utils.c
Go to the documentation of this file.
1 bool pushToChamberFromAttachedMagazine(Weapon_Base weapon, int muzzleIndex)
2 {
3  Magazine mag = weapon.GetMagazine(muzzleIndex);
4  if (mag && !mag.IsDamageDestroyed())
5  {
6  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromAttachedMagazine, using attached magazine mag=" + mag.ToString()); }
7  float damage;
8  string type;
9  if (mag && mag.LocalAcquireCartridge(damage, type))
10  {
11  weapon.SelectionBulletShow();
12  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromAttachedMagazine, ok - cartridge acquired: dmg=" + damage + " type=" + type); }
13  }
14  else
15  Error("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromAttachedMagazine, error - cannot take cartridge from magazine");
16 
17  if (weapon.PushCartridgeToChamber(muzzleIndex, damage, type))
18  {
19  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromAttachedMagazine, ok - loaded chamber"); }
20  return true;
21  }
22  else
23  Error("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromAttachedMagazine, error - cannot load chamber!");
24  }
25  else
26  {
27  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromAttachedMagazine - magazine destroyer or no attached"); }
28  //Error("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromAttachedMagazine, error - no magazine attached");
29  }
30  return false;
31 }
32 
33 bool pushToChamberFromInnerMagazine(Weapon_Base weapon, int muzzleIndex)
34 {
35 
36  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromInnerMagazine, using inner magazine."); }
37  float damage;
38  string type;
39  if (weapon.PopCartridgeFromInternalMagazine(muzzleIndex,damage, type))
40  {
41  weapon.SelectionBulletShow();
42  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromInnerMagazine, ok - cartridge acquired: dmg=" + damage + " type=" + type); }
43  }
44  else
45  Error("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromInnerMagazine, error - cannot take cartridge from magazine");
46 
47  if (weapon.PushCartridgeToChamber(muzzleIndex, damage, type))
48  {
49  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromInnerMagazine, ok - loaded chamber"); }
50  return true;
51  }
52  else
53  Error("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromInnerMagazine, error - cannot load chamber!");
54 
55  return false;
56 }
57 
58 void ejectBulletAndStoreInMagazine(Weapon_Base weapon, int muzzleIndex, Magazine mag, DayZPlayer p)
59 {
60  float damage = 0;
61  string type = string.Empty;
62  string magazineTypeName = weapon.GetChamberedCartridgeMagazineTypeName(muzzleIndex);
63  if (weapon.EjectCartridge(muzzleIndex, damage, type))
64  {
65  if (LogManager.IsWeaponLogEnable())
66  wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " ejectBulletAndStoreInMagazine, ejected chambered cartridge");
67  }
68  else
69  Error("[wpnfsm] " + Object.GetDebugName(weapon) + " ejectBulletAndStoreInMagazine, error - cannot eject chambered cartridge!");
70 
71  if (!GetGame().IsMultiplayer() || GetGame().IsServer())
72  {
73  if (mag == null)
74  {
76  if (DayZPlayerUtils.HandleStoreCartridge(p, weapon, muzzleIndex, damage, type, magazineTypeName))
77  {
78  if (LogManager.IsWeaponLogEnable())
79  wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " ejectBulletAndStoreInMagazine, ok - cartridge stored in magazine");
80  }
81  else
82  Error("[wpnfsm] " + Object.GetDebugName(weapon) + " ejectBulletAndStoreInMagazine, error - cannot store cartridge!");
83  }
84  else
85  {
86  if (mag.ServerStoreCartridge(damage, type))
87  {
88  mag.SetSynchDirty();
89  if (LogManager.IsWeaponLogEnable())
90  wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " ejectBulletAndStoreInMagazine, ok - cartridge stored in user defined magazine");
91  }
92  else
93  Error("[wpnfsm] " + Object.GetDebugName(weapon) + " ejectBulletAndStoreInMagazine, error - cannot store cartridge in magazine");
94  }
95  }
96 }
97 
98 bool magazinesHaveEqualSizes(notnull Magazine mag, notnull Magazine mag2)
99 {
100  int w, h;
101  GetGame().GetInventoryItemSize(mag, w, h);
102  int w2, h2;
103  GetGame().GetInventoryItemSize(mag2, w2, h2);
104  if (w == w2 && h == h2)
105  {
106  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] guard - same inventory sizes"); }
107  return true;
108  }
109 
110  if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] guard - different inventory sizes"); }
111  return false;
112 }
113 
GetGame
proto native CGame GetGame()
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
LogManager
Definition: debug.c:734
DayZPlayerUtils
private void DayZPlayerUtils()
cannot be instantiated
Definition: dayzplayerutils.c:461
ejectBulletAndStoreInMagazine
void ejectBulletAndStoreInMagazine(Weapon_Base weapon, int muzzleIndex, Magazine mag, DayZPlayer p)
Definition: weapon_utils.c:58
wpnDebugPrint
void wpnDebugPrint(string s)
Definition: debug.c:9
DayZPlayer
Definition: dayzplayerimplement.c:72
Object
Definition: objecttyped.c:1
pushToChamberFromAttachedMagazine
bool pushToChamberFromAttachedMagazine(Weapon_Base weapon, int muzzleIndex)
Definition: weapon_utils.c:1
magazinesHaveEqualSizes
bool magazinesHaveEqualSizes(notnull Magazine mag, notnull Magazine mag2)
Definition: weapon_utils.c:98
Weapon_Base
shorthand
Definition: boltactionrifle_base.c:5
pushToChamberFromInnerMagazine
bool pushToChamberFromInnerMagazine(Weapon_Base weapon, int muzzleIndex)
Definition: weapon_utils.c:33