DayZ 1.24
Loading...
Searching...
No Matches
WeaponAttachMagazine.c
Go to the documentation of this file.
2{
5
7 {
8 m_newMagazine = NULL;
9 m_newSrc = NULL;
10 }
11
12 override void OnEntry(WeaponEventBase e)
13 {
14 if (e)
15 {
16 if (!m_newSrc.IsValid())
17 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RemoveNewMagazineFromInventory m_newSrc=invalid, item not in bubble?");
18
19 if (m_newMagazine && m_newSrc && m_newSrc.IsValid())
20 {
22 m_newMagazine.GetInventory().GetCurrentInventoryLocation(curr);
23
24 if (m_newSrc.GetType() == InventoryLocationType.GROUND && curr.GetType() == InventoryLocationType.ATTACHMENT && curr.GetSlot() == InventorySlots.LEFTHAND)
25 {
26 // already in LH
27 }
28 else
29 {
31 lhand.SetAttachment(e.m_player, m_newMagazine, InventorySlots.LEFTHAND);
33 {
34 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RemoveNewMagazineFromInventory, ok - new magazine removed from inv (inv->LHand)");
35 }
36 else
37 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RemoveNewMagazineFromInventory, error - cannot new remove mag from inv");
38 }
39 }
40 else
41 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RemoveNewMagazineFromInventory, error - no magazines configured for replace (m_old=m_new=NULL)");
42 }
43 super.OnEntry(e);
44 }
45
46 override void OnAbort(WeaponEventBase e)
47 {
48 m_newMagazine = NULL;
49 m_newSrc = NULL;
50
51 super.OnAbort(e);
52 }
53
54 override void OnExit(WeaponEventBase e)
55 {
56 m_weapon.ShowMagazine();
57
58 m_newMagazine = NULL;
59 m_newSrc = NULL;
60 super.OnExit(e);
61 }
62
64 {
65 if (!super.SaveCurrentFSMState(ctx))
66 return false;
67
68 if (!ctx.Write(m_newMagazine))
69 {
70 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RemoveNewMagazineFromInventory.SaveCurrentFSMState: cannot write m_newMagazine for weapon=" + m_weapon);
71 return false;
72 }
73
74 if (!OptionalLocationWriteToContext(m_newSrc, ctx))
75 {
76 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RemoveNewMagazineFromInventory.SaveCurrentFSMState: cannot write m_newSrc for weapon=" + m_weapon);
77 return false;
78 }
79 return true;
80 }
81
82 override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
83 {
84 if (!super.LoadCurrentFSMState(ctx, version))
85 return false;
86
87 if (!ctx.Read(m_newMagazine))
88 {
89 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RemoveNewMagazineFromInventory.LoadCurrentFSMState: cannot read m_newMagazine for weapon=" + m_weapon);
90 return false;
91 }
92
94 {
95 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RemoveNewMagazineFromInventory.LoadCurrentFSMState: cannot read m_newSrc for weapon=" + m_weapon);
96 return false;
97 }
98 return true;
99 }
100};
101
102
104{
105 override void OnEntry(WeaponEventBase e)
106 {
107 if (e)
108 m_weapon.ShowMagazine();
109 super.OnEntry(e);
110 }
111};
112
113
114class WeaponAttachMagazine extends WeaponStateBase
115{
117 int m_actionType;
118
124
126 {
128 m_actionType = actionType;
129
130 // setup nested state machine
131 m_start = new WeaponStartAction(m_weapon, this, m_action, m_actionType);
133 m_attach = new AttachNewMagazine(m_weapon, this);
135 m_onCK = new WeaponCharging_CK(m_weapon, this);
136
137 // events: MS, MA, BE, CK
138 WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
139 WeaponEventBase __ms_ = new WeaponEventAnimMagazineShow;
140 WeaponEventBase __so_ = new WeaponEventAnimSliderOpen;
141 WeaponEventBase __ma_ = new WeaponEventAnimMagazineAttached;
142 WeaponEventBase __ck_ = new WeaponEventAnimCocked;
143
144 m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
145
146 m_fsm.AddTransition(new WeaponTransition(m_start, __ms_, m_attach));
147 m_fsm.AddTransition(new WeaponTransition(m_start, __so_, m_eject));
148 m_fsm.AddTransition(new WeaponTransition(m_eject, __ms_, m_attach));
149 m_fsm.AddTransition(new WeaponTransition(m_attach, __ck_, m_chamber, NULL, new GuardAnd(new WeaponGuardCurrentChamberEmpty(m_weapon), new WeaponGuardHasAmmo(m_weapon)))); // when opened, there is no __be_ event
150 m_fsm.AddTransition(new WeaponTransition(m_attach, __ck_, m_onCK, NULL, new GuardAnd(new WeaponGuardCurrentChamberEmpty(m_weapon), new GuardNot(new WeaponGuardHasAmmo(m_weapon)))));
151 m_fsm.AddTransition(new WeaponTransition(m_attach, _fin_, NULL));
152 m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, NULL));
153 m_fsm.AddTransition(new WeaponTransition(m_onCK, _fin_, NULL));
154
155 // Safety exits
156 m_fsm.AddTransition(new WeaponTransition(m_eject, _fin_, null));
157 m_fsm.AddTransition(new WeaponTransition(m_start, _fin_, null));
158
159
160 m_fsm.SetInitialState(m_start);
161 }
162
163 override void OnEntry(WeaponEventBase e)
164 {
165 if (e)
166 {
167 Magazine mag = e.m_magazine;
168
170 mag.GetInventory().GetCurrentInventoryLocation(newSrc);
171
172 // move to LH
174 lhand.SetAttachment(e.m_player, mag, InventorySlots.LEFTHAND);
176 {
177 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponAttachMagazine, ok - new magazine removed from inv (inv->LHand)");
178 }
179 else
180 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponAttachMagazine, error - cannot new remove mag from inv");
181
183 il.SetAttachment(m_weapon, mag, InventorySlots.MAGAZINE);
184 m_attach.m_newMagazine = mag;
185 m_attach.m_newDst = il;
186 }
187 super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
188 }
189
190 override void OnAbort(WeaponEventBase e)
191 {
192 EntityAI leftHandItem = e.m_player.GetInventory().FindAttachment(InventorySlots.LEFTHAND);
194
195 if (mag)
196 {
197 e.m_player.GetInventory().ClearInventoryReservationEx(mag, null);
199 e.m_player.GetInventory().FindFreeLocationFor(mag, FindInventoryLocationType.CARGO, il);
200
201 if (!il || !il.IsValid())
202 {
203 if (DayZPlayerUtils.HandleDropMagazine(e.m_player, mag))
204 {
205 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponAttachMagazine, ok - no inventory space for old magazine - dropped to ground");
206 }
207 else
208 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponAttachMagazine, error - cannot drop magazine from left hand after not found inventory space for old magazine");
209
210 }
211 else
212 {
214 mag.GetInventory().GetCurrentInventoryLocation(oldSrc);
215
217 {
218 if (LogManager.IsWeaponLogEnable()) wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponAttachMagazine, ok - old magazine removed from wpn (LHand->inv)");
219 }
220 else
221 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponAttachMagazine, error - cannot remove old mag from wpn");
222 }
223 }
224 super.OnAbort(e);
225 }
226};
227
void wpnDebugPrint(string s)
Definition Debug.c:9
void DayZPlayerUtils()
cannot be instantiated
class WeaponGuardIsDestroyed extends WeaponGuardBase m_weapon
Definition Guards.c:602
void WeaponGuardHasAmmo(Weapon_Base w=NULL)
Definition Guards.c:99
FindInventoryLocationType
flags for searching locations in inventory
bool OptionalLocationReadFromContext(out InventoryLocation loc, notnull ParamsReadContext ctx)
InventoryLocationType
types of Inventory Location
bool OptionalLocationWriteToContext(InventoryLocation loc, notnull ParamsWriteContext ctx)
enum FSMTransition WeaponTransition
ref WeaponStateBase m_start
class WeaponEndAction extends WeaponStartAction m_action
ref WeaponChambering_Base m_chamber
ref WeaponEjectCasingMultiMuzzle m_eject
attach mag in LH into weapon
script counterpart to engine's class Inventory
Definition Inventory.c:79
static proto native bool LocationSyncMoveEntity(notnull InventoryLocation src_loc, notnull InventoryLocation dst_loc)
synchronously removes item from current inventory location and adds it to destination no anims involv...
InventoryLocation.
provides access to slot configuration
static bool IsWeaponLogEnable()
Definition Debug.c:799
override void OnEntry(WeaponEventBase e)
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
signalize mechanism manipulation
Definition Events.c:35
weapon finite state machine
simple class starting animation action specified by m_action and m_actionType
represent weapon state base
Definition BulletHide.c:2
void AttachNewMagazine(Weapon_Base w=NULL, WeaponStateBase parent=NULL)
ref InventoryLocation m_newSrc
magazine that will be removed from inventory
int m_actionType
action to be played
void RemoveNewMagazineFromInventory(Weapon_Base w=NULL, WeaponStateBase parent=NULL)
void WeaponStartAction(Weapon_Base w=NULL, WeaponStateBase parent=NULL, WeaponActions action=WeaponActions.NONE, int actionType=-1)
specific action sub-type
WeaponActions m_action
ref AttachNewMagazine m_attach
void WeaponAttachMagazine(Weapon_Base w=NULL, WeaponStateBase parent=NULL, WeaponActions action=WeaponActions.NONE, int actionType=-1)
ref WeaponChamberFromAttMag_W4T m_chamber
override void OnEntry(WeaponEventBase e)
ref WeaponCharging_CK m_onCK
ref WeaponStateBase m_start
source of the cartridge
override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
ref WeaponEjectCasing m_eject
override void OnAbort(WeaponEventBase e)
Magazine m_newMagazine
magazine that will be detached
void WeaponEjectCasing(Weapon_Base w=NULL, WeaponStateBase parent=NULL)
override void OnExit(WeaponEventBase e)
override bool SaveCurrentFSMState(ParamsWriteContext ctx)
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
WeaponActions
actions
Definition human.c:796