DayZ 1.24
Loading...
Searching...
No Matches
weapon_utils.c File Reference

Go to the source code of this file.

Functions

bool pushToChamberFromAttachedMagazine (Weapon_Base weapon, int muzzleIndex)
 
bool pushToChamberFromInnerMagazine (Weapon_Base weapon, int muzzleIndex)
 
void ejectBulletAndStoreInMagazine (Weapon_Base weapon, int muzzleIndex, Magazine mag, DayZPlayer p)
 
bool magazinesHaveEqualSizes (notnull Magazine mag, notnull Magazine mag2)
 

Function Documentation

◆ ejectBulletAndStoreInMagazine()

void ejectBulletAndStoreInMagazine ( Weapon_Base weapon,
int muzzleIndex,
Magazine mag,
DayZPlayer p )

no magazine configured in parent state, looking in inventory

Definition at line 58 of file weapon_utils.c.

59{
60 float damage = 0;
61 string type = string.Empty;
62 string magazineTypeName = weapon.GetChamberedCartridgeMagazineTypeName(muzzleIndex);
63 if (weapon.EjectCartridge(muzzleIndex, damage, type))
64 {
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 {
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();
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}
void wpnDebugPrint(string s)
Definition Debug.c:9
void DayZPlayerUtils()
cannot be instantiated
static bool IsWeaponLogEnable()
Definition Debug.c:799
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90

References DayZPlayerUtils(), Error(), GetGame(), LogManager::IsWeaponLogEnable(), and wpnDebugPrint().

Referenced by WeaponStateBase::OnEntry().

◆ magazinesHaveEqualSizes()

bool magazinesHaveEqualSizes ( notnull Magazine mag,
notnull Magazine mag2 )

Definition at line 98 of file weapon_utils.c.

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}

References GetGame(), LogManager::IsWeaponLogEnable(), and wpnDebugPrint().

Referenced by WeaponGuardBase::GuardCondition().

◆ pushToChamberFromAttachedMagazine()

bool pushToChamberFromAttachedMagazine ( Weapon_Base weapon,
int muzzleIndex )

Definition at line 1 of file weapon_utils.c.

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}

References Error(), LogManager::IsWeaponLogEnable(), and wpnDebugPrint().

Referenced by WeaponEjectAllMuzzles::OnAbort(), WeaponStateBase::OnEntry(), WeaponEjectCasing::OnEntry(), WeaponFire::OnEntry(), WeaponStateBase::OnExit(), and WeaponEjectAllMuzzles::OnExit().

◆ pushToChamberFromInnerMagazine()

bool pushToChamberFromInnerMagazine ( Weapon_Base weapon,
int muzzleIndex )

Definition at line 33 of file weapon_utils.c.

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}

References Error(), LogManager::IsWeaponLogEnable(), and wpnDebugPrint().

Referenced by WeaponStateBase::OnEntry(), and WeaponFire::OnEntry().