Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
humaninventorywithfsm.c
Go to the documentation of this file.
1
5
class
HumanInventoryWithFSM
:
HumanInventory
6
{
7
protected
ref
HandFSM
m_FSM
;
8
protected
ref
HandStateBase
m_Empty
;
9
protected
ref
HandStateBase
m_Equipped
;
10
11
void
HumanInventoryWithFSM
()
12
{
13
m_FSM
=
new
HandFSM
();
14
}
15
16
void
CreateStableStates
()
17
{
18
// stable states are created only if they do not exist already (for example created by derived class like DayZPlayerInventory)
19
// @NOTE: this cannot be done in constructor, as there is NO owner set yet. GetManOwner() will therefore return NULL.
20
if
(!
m_Empty
)
21
m_Empty
=
new
HandStateEmpty(
GetManOwner
());
22
if
(!
m_Equipped
)
23
m_Equipped
=
new
HandStateEquipped
(
GetManOwner
());
24
}
25
26
override
void
Init
()
27
{
28
// setup state machine
29
if
(
LogManager
.
IsInventoryHFSMLogEnable
())
hndDebugPrint
(
"[hndfsm] Initializing Human Inventory FSM"
);
30
31
// basic states
32
CreateStableStates
();
33
34
// events
35
HandEventBase
__T__ =
new
HandEventTake;
36
HandEventBase
__D__ =
new
HandEventDrop;
37
HandEventBase
__Tw_ =
new
HandEventThrow;
38
HandEventBase
__M__ =
new
HandEventMoveTo;
39
HandEventBase
__W__ =
new
HandEventSwap
;
40
HandEventBase
__F__ =
new
HandEventForceSwap;
41
HandEventBase
__X__ =
new
HandEventDestroy;
42
HandEventBase
__Xd_ =
new
HandEventDestroyed;
43
HandEventBase
__R__ =
new
HandEventDestroyAndReplaceWithNew
;
44
HandEventBase
__Re_ =
new
HandEventDestroyAndReplaceWithNewElsewhere;
45
HandEventBase
__Rh_ =
new
HandEventDestroyElsewhereAndReplaceWithNewInHands;
46
HandEventBase
__Rd_ =
new
HandEventReplaced;
47
HandEventBase
__Cd_ =
new
HandEventCreated;
48
HandEventBase
_fin_ =
new
HandEventHumanCommandActionFinished;
49
HandEventBase
_abt_ =
new
HandEventHumanCommandActionAborted;
50
51
52
HandReplacingItemInHands replacing =
new
HandReplacingItemInHands(
GetManOwner
());
53
HandReplacingItemInHands replacingElsewhere =
new
HandReplacingItemInHands(
GetManOwner
());
54
HandReplacingItemElsewhereWithNewInHands replacingElsewhere3 =
new
HandReplacingItemElsewhereWithNewInHands(
GetManOwner
());
55
56
// setup transitions
57
m_FSM
.AddTransition(
new
HandTransition
(
m_Empty
, __T__,
m_Equipped
,
new
HandActionTake,
new
HandGuardHasItemInEvent
(
GetManOwner
())));
58
m_FSM
.AddTransition(
new
HandTransition
(
m_Empty
, __Cd_,
m_Equipped
,
new
HandActionCreated,
new
HandGuardHasItemInEvent
(
GetManOwner
())));
59
60
m_FSM
.AddTransition(
new
HandTransition
(
m_Equipped
, __D__,
m_Empty
,
new
HandActionDrop, null));
61
m_FSM
.AddTransition(
new
HandTransition
(
m_Equipped
, __Tw_,
m_Empty
,
new
HandActionThrow, null));
62
m_FSM
.AddTransition(
new
HandTransition
(
m_Equipped
, __M__,
m_Empty
,
new
HandActionMoveTo,
new
HandGuardAnd(
new
HandGuardHasItemInHands(
GetManOwner
()),
new
HandGuardCanMove(
GetManOwner
()))));
63
m_FSM
.AddTransition(
new
HandTransition
(
m_Equipped
, __X__,
m_Empty
,
new
HandActionDestroy,
new
HandGuardHasItemInHands(
GetManOwner
())));
64
m_FSM
.AddTransition(
new
HandTransition
(
m_Equipped
, __Xd_,
m_Empty
,
new
HandActionDestroyed,
new
HandGuardHasDestroyedItemInHands(
GetManOwner
())));
65
m_FSM
.AddTransition(
new
HandTransition
(
m_Equipped
, __Xd_,
m_Equipped
,
new
HandActionDestroyed,
new
HandGuardNot(
new
HandGuardHasDestroyedItemInHands(
GetManOwner
()))));
66
67
m_FSM
.AddTransition(
new
HandTransition
(
m_Equipped
, __R__, replacing));
68
m_FSM
.AddTransition(
new
HandTransition
(replacing, _fin_,
m_Equipped
));
69
replacing.AddTransition(
new
HandTransition
(replacing.m_Replacing, _abt_,
m_Equipped
));
70
71
m_FSM
.AddTransition(
new
HandTransition
(
m_Equipped
, __Re_, replacingElsewhere));
72
m_FSM
.AddTransition(
new
HandTransition
(replacingElsewhere, _fin_,
m_Empty
));
73
replacingElsewhere.AddTransition(
new
HandTransition
(replacingElsewhere.m_Replacing, _abt_,
m_Equipped
));
74
75
m_FSM
.AddTransition(
new
HandTransition
(
m_Empty
, __Rh_, replacingElsewhere3));
76
m_FSM
.AddTransition(
new
HandTransition
(replacingElsewhere3, _fin_,
m_Equipped
));
77
replacingElsewhere3.AddTransition(
new
HandTransition
(replacingElsewhere3.m_Replacing, _abt_,
m_Empty
));
78
79
m_FSM
.AddTransition(
new
HandTransition
(
m_Equipped
, __Rd_,
m_Equipped
,
new
HandActionReplaced, null));
80
m_FSM
.AddTransition(
new
HandTransition
(
m_Equipped
, __W__,
m_Equipped
,
new
HandActionSwap,
new
HandGuardAnd(
new
HandGuardHasItemInHands(
GetManOwner
()),
new
HandGuardCanSwap(
GetManOwner
()))));
81
m_FSM
.AddTransition(
new
HandTransition
(
m_Equipped
, __F__,
m_Equipped
,
new
HandActionForceSwap,
new
HandGuardAnd(
new
HandGuardHasItemInHands(
GetManOwner
()),
new
HandGuardCanForceSwap(
GetManOwner
()))));
82
83
// start FSM
84
m_FSM
.SetInitialState(
m_Empty
);
85
m_FSM
.Start();
86
87
super.Init();
88
}
89
90
bool
CanProcessHandEvents
() {
return
m_FSM
&&
m_FSM
.IsRunning(); }
91
96
override
bool
ProcessHandEvent
(
HandEventBase
e)
97
{
98
//SyncRemote(e);
99
if
(
m_FSM
.ProcessEvent(e) ==
ProcessEventResult
.FSM_OK)
100
{
101
#ifdef ENABLE_LOGGING
102
if
(
LogManager
.
IsInventoryHFSMLogEnable
() )
103
{
104
Debug
.
InventoryHFSMLog
(
"STS = "
+
GetManOwner
().GetSimulationTimeStamp() , e.ToString(),
"ProcessHandEvent"
, e.m_Player.ToString() );
105
}
106
#endif
107
return
true
;
108
}
109
else
110
{
111
//if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("FSM refused to process event (no transition): src=" + GetCurrentState().ToString() + " event=" + e.ToString());
112
return
false
;
113
}
114
}
115
116
bool
ProcessHandAbortEvent
(
HandEventBase
e)
117
{
118
//SyncRemote(e);
119
ProcessEventResult
aa;
120
m_FSM
.ProcessAbortEvent(e, aa);
121
if
(aa ==
ProcessEventResult
.FSM_OK)
122
{
123
if
(
LogManager
.
IsInventoryHFSMLogEnable
())
hndDebugSpam
(
"[hndfsm] STS = "
+
GetManOwner
().GetSimulationTimeStamp() +
" Processed event e="
+ e.ToString());
124
return
true
;
125
}
126
else
127
{
128
//if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("FSM refused to process event (no transition): src=" + GetCurrentState().ToString() + " event=" + e.ToString());
129
return
false
;
130
}
131
}
132
133
134
void
CheckFSMState
()
135
{
136
if
(
GetEntityInHands
())
137
{
138
if
(!
m_FSM
.IsRunning() ||
GetCurrentStateID
() ==
HandStateID
.Empty)
//forcing when not running or in stable state only
139
m_FSM
.SetCurrentState(
m_Equipped
);
140
}
141
else
142
{
143
if
(!
m_FSM
.IsRunning() ||
GetCurrentStateID
() ==
HandStateID
.Equipped)
//forcing when not running or in stable state only
144
m_FSM
.SetCurrentState(
m_Empty
);
145
}
146
}
147
148
override
bool
OnStoreLoad
(
ParamsReadContext
ctx,
int
version)
149
{
150
if
( !super.OnStoreLoad(ctx, version) )
151
return
false
;
152
153
//@TODO
154
//m_FSM.OnStoreLoad(ctx, version);
155
156
return
true
;
157
}
158
159
override
void
OnStoreSave
(
ParamsWriteContext
ctx)
160
{
161
super.OnStoreSave(ctx);
162
//@TODO
163
//m_FSM.OnStoreSave(ctx, version);
164
}
165
169
int
GetCurrentStateID
() {
return
m_FSM
.GetCurrentStateID(); }
170
171
bool
IsIdle
() {
return
m_FSM
.GetCurrentState().IsIdle(); }
172
176
void
NetSyncCurrentStateID
(
int
id
)
177
{
178
m_FSM
.NetSyncCurrentStateID(
id
);
179
}
180
};
181
Debug
Definition
debug.c:2
Debug::InventoryHFSMLog
static void InventoryHFSMLog(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Definition
debug.c:207
HandEventBase
Abstracted event, not to be used, only inherited.
Definition
hand_events.c:212
HandEventDestroyAndReplaceWithNew
Definition
hand_events.c:826
HandEventSwap
Definition
hand_events.c:726
HandFSM
Hand finite state machine.
HandGuardHasItemInEvent
Definition
hand_guards.c:112
HandStateBase
represent hand state base
Definition
handanimatedforceswapping.c:4
HandStateEquipped
Definition
hand_states.c:33
HumanInventory
inventory for plain man/human
Definition
humaninventory.c:10
HumanInventory::GetEntityInHands
proto native EntityAI GetEntityInHands()
HumanInventory::GetManOwner
Man GetManOwner()
Definition
humaninventory.c:102
HumanInventoryWithFSM::m_Equipped
ref HandStateBase m_Equipped
Definition
humaninventorywithfsm.c:9
HumanInventoryWithFSM::CreateStableStates
void CreateStableStates()
Definition
humaninventorywithfsm.c:16
HumanInventoryWithFSM::GetCurrentStateID
int GetCurrentStateID()
Definition
humaninventorywithfsm.c:169
HumanInventoryWithFSM::CanProcessHandEvents
bool CanProcessHandEvents()
Definition
humaninventorywithfsm.c:90
HumanInventoryWithFSM::OnStoreSave
override void OnStoreSave(ParamsWriteContext ctx)
Definition
humaninventorywithfsm.c:159
HumanInventoryWithFSM::IsIdle
bool IsIdle()
Definition
humaninventorywithfsm.c:171
HumanInventoryWithFSM::ProcessHandEvent
override bool ProcessHandEvent(HandEventBase e)
Definition
humaninventorywithfsm.c:96
HumanInventoryWithFSM::m_FSM
ref HandFSM m_FSM
Definition
humaninventorywithfsm.c:7
HumanInventoryWithFSM::Init
override void Init()
Definition
humaninventorywithfsm.c:26
HumanInventoryWithFSM::CheckFSMState
void CheckFSMState()
Definition
humaninventorywithfsm.c:134
HumanInventoryWithFSM::HumanInventoryWithFSM
void HumanInventoryWithFSM()
Definition
humaninventorywithfsm.c:11
HumanInventoryWithFSM::OnStoreLoad
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition
humaninventorywithfsm.c:148
HumanInventoryWithFSM::m_Empty
ref HandStateBase m_Empty
hand slot state machine
Definition
humaninventorywithfsm.c:8
HumanInventoryWithFSM::ProcessHandAbortEvent
bool ProcessHandAbortEvent(HandEventBase e)
Definition
humaninventorywithfsm.c:116
HumanInventoryWithFSM::NetSyncCurrentStateID
void NetSyncCurrentStateID(int id)
Definition
humaninventorywithfsm.c:176
LogManager
Definition
debug.c:692
LogManager::IsInventoryHFSMLogEnable
static bool IsInventoryHFSMLogEnable()
Definition
debug.c:766
ProcessEventResult
ProcessEventResult
Definition
fsmbase.c:41
ParamsReadContext
Serializer ParamsReadContext
Definition
gameplay.c:15
ParamsWriteContext
Serializer ParamsWriteContext
Definition
gameplay.c:16
HandStateID
HandStateID
states
Definition
hand_states.c:4
hndDebugSpam
void hndDebugSpam(string s)
Definition
handfsm.c:9
hndDebugPrint
void hndDebugPrint(string s)
Definition
handfsm.c:1
HandTransition
FSMTransition< HandStateBase, HandEventBase, HandActionBase, HandGuardBase > HandTransition
Definition
handfsm.c:28
Games
Dayz
scripts
3_game
systems
inventory
humaninventorywithfsm.c
Generated by
1.17.0