6 bool CheckTrigger () {
return false; }
9class MyBotTrigger : BotTrigger
12 void MyBotTrigger (PlayerBase p) {
m_Owner = p; }
13 override bool CheckTrigger () {
return null !=
m_Owner.GetInventory().FindAttachment(InventorySlots.GetSlotIdFromString(
"Headgear")); }
22 protected ref BotFSM m_ActiveFSM = null;
24 private ref BotStateBase m_Attack;
25 private ref BotStateBase m_TurnValidForward;
26 private ref BotStateBase m_MoveForward;
27 protected ref BotStateBase m_IdleState = null;
35 private const vector m_InfectedHalfRange =
"2 0 2";
41 ref BotEventBase ___Bgn__ =
new BotEventStart;
42 ref BotEventBase __Stop__ =
new BotEventStop;
43 ref BotEventBase ___OK___ =
new BotEventEndOK;
44 ref BotEventBase __Fail__ =
new BotEventEndFail;
45 ref BotEventBase __Tout__ =
new BotEventEndTimeout;
46 ref BotEventBase __IChg__ =
new BotEventOnItemInHandsChanged;
47 ref BotEventBase __Obst__ =
new BotEventObstacle;
48 ref BotEventBase __VaFw__ =
new BotEventValidForward;
49 ref BotEventBase __Atkd__ =
new BotEventAttacked;
52 void Bot (PlayerBase ow)
57 m_IdleState =
new BotStateIdle(
this, NULL);
58 m_TurnValidForward =
new BotTurnToValidForward(
this, NULL);
59 m_Attack =
new BotAttack(
this, NULL);
60 m_MoveForward =
new BotMoveForward(
this, NULL);
63 m_States.Insert(m_IdleState.ClassName(), m_IdleState);
64 m_States.Insert(m_MoveForward.ClassName(), m_MoveForward);
65 m_States.Insert(m_TurnValidForward.ClassName(), m_TurnValidForward);
66 m_States.Insert(m_Attack.ClassName(), m_Attack);
67 m_States.Insert(
"None", NULL);
70 m_Events.Insert(__Obst__.ClassName(), __Obst__);
71 m_Events.Insert(__VaFw__.ClassName(), __VaFw__);
72 m_Events.Insert(__Atkd__.ClassName(), __Atkd__);
73 m_Events.Insert(
"None", NULL);
76 m_Actions.Insert(
"None", NULL);
79 m_Guards.Insert(
"None", NULL);
82 RoboclientUtils.ReadStateMachines();
86 RegisterStateMachineDiag();
95 delete m_StateMachines;
98 void RegisterStateMachineDiag()
100 string stateMachineNames;
101 int activeStateMachineIndex = 0;
102 for(
int i = 0; i < m_StateMachines.Count(); i++)
104 stateMachineNames += m_StateMachines.GetElement(i).GetName();
105 if (i != m_StateMachines.Count() - 1)
106 stateMachineNames +=
",";
107 if (m_ActiveFSM == m_StateMachines.GetKey(i))
108 activeStateMachineIndex = i;
112 DiagMenu.RegisterItem(
DiagMenuIDs.ROBOCLIENTS_STATE_MACHINES,
"",
"State Machine",
DiagMenuIDs.ROBOCLIENTS_MENU, stateMachineNames);
113 DiagMenu.SetValue(
DiagMenuIDs.ROBOCLIENTS_STATE_MACHINES, activeStateMachineIndex);
114 DiagMenu.BindCallback(
DiagMenuIDs.ROBOCLIENTS_STATE_MACHINES, PluginDiagMenuClient.CBRoboclientChangeStateMachine);
120 void GetStateMachines()
122 array<BotStateMachineData> stateMachinesData =
new array<BotStateMachineData>;
123 RoboclientUtils.GetStateMachines(stateMachinesData);
124 for (
int i = 0; i < stateMachinesData.Count(); i++)
126 string name = stateMachinesData[i].GetName();
128 stateMachinesData[i].GetFromStates(from);
130 stateMachinesData[i].GetToStates(to);
132 stateMachinesData[i].GetEvents(evnt);
134 stateMachinesData[i].GetActions(action);
137 stateMachinesData[i].GetGuards(guard, guardDecorator);
140 if (from.Count() != to.Count() || from.Count() != evnt.Count() || from.Count() != action.Count() || from.Count() != guardDecorator.Count() || 2 * from.Count() != guard.Count())
143 BotFSM fsm =
new BotFSM();
144 for(
int j = 0; j < from.Count(); j++)
146 BotGuardBase resultGuard = NULL;
147 if (m_Guards[guard[2 * j]])
149 switch (guardDecorator[j])
152 resultGuard = BotGuardNot(m_Guards[guard[2 * j]]);
155 if (m_Guards[guard[2 * j + 1]])
156 resultGuard = BotGuardAnd(m_Guards[guard[2 * j]], m_Guards[guard[2 * j + 1]]);
159 if (m_Guards[guard[2 * j + 1]])
160 resultGuard = BotGuardOr(m_Guards[guard[2 * j]], m_Guards[guard[2 * j + 1]]);
163 if (guardDecorator[j] !=
"None")
168 resultGuard = m_Guards[guard[2 * j]];
170 fsm.AddTransition(
new BotTransition(m_States[from[j]], m_Events[evnt[j]], m_States[to[j]], m_Actions[action[j]], resultGuard));
172 fsm.SetInitialState(m_States[stateMachinesData[i].GetInitialState()]);
173 m_StateMachines.Insert(fsm, stateMachinesData[i]);
174 if (stateMachinesData[i].GetActive())
181 if (!m_ActiveFSM || m_ActiveFSM.IsRunning())
193 m_ActiveFSM.Terminate();
195 g_Game.GetPlayer().GetInputInterface().SyncedRemoveAllOverrides();
209 case EActions.PLAYER_BOT_STOP_CURRENT:
222 if (m_ActiveFSM.IsRunning())
223 m_ActiveFSM.GetCurrentState().OnUpdate(dt);
226 bool GetShouldRespawn()
228 BotStateMachineData data = NULL;
229 if (m_StateMachines.Find(m_ActiveFSM, data))
230 return data.GetRoboRespawn();
231 return RoboclientUtils.GetDefaultRoboRespawn();
236 BotStateMachineData data = NULL;
237 if (m_StateMachines.Find(m_ActiveFSM, data))
238 return data.GetRoboRespawnTime();
239 return RoboclientUtils.GetDefaultRoboRespawnTime();
242 void GetRespawnData(out
bool shouldRespawn, out
int respawnTime)
244 BotStateMachineData data = NULL;
245 if (m_StateMachines.Find(m_ActiveFSM, data))
247 shouldRespawn = data.GetRoboRespawn();
248 respawnTime = data.GetRoboRespawnTime();
251 shouldRespawn = RoboclientUtils.GetDefaultRoboRespawn();
252 respawnTime = RoboclientUtils.GetDefaultRoboRespawnTime();
255 void ChangeStateMachine (
int index)
257 if (index >= m_StateMachines.Count())
261 m_ActiveFSM = m_StateMachines.GetKey(index);
262 if (DiagMenu.GetBool(
DiagMenuIDs.ROBOCLIENTS_ACTIVE))
266 void ChangeStateMachine (
string stateMachineName)
268 BotFSM newStateMachine;
269 for (
int i = 0; i < m_StateMachines.Count(); i++)
271 if (m_StateMachines.GetElement(i).GetName() == stateMachineName)
273 ChangeStateMachine(i);
279 private bool IsEntityEnemy(
EntityAI entity)
281 if (DayZInfected.Cast(entity))
284 PlayerBase p = PlayerBase.Cast(entity);
287 return !p.IsUnconscious();
290 if (DayZAnimal.Cast(entity))
296 void CheckForEnemies(
bool Force =
false)
301 vector min =
m_Owner.GetPosition() - m_InfectedHalfRange;
302 vector max =
m_Owner.GetPosition() + m_InfectedHalfRange +
"0 2 0";
303 array<EntityAI> entities = {};
308 if (Force || m_ActiveFSM.GetCurrentState() != m_Attack)
314 for (
int i = 0; i < entities.Count(); i++)
316 if (entities[i] !=
m_Owner && entities[i].IsAlive() && IsEntityEnemy(entities[i]))
318 if (Force || m_ActiveFSM.GetCurrentState() != m_Attack)
331 void AddTransition(BotStateBase state,
int id)
333 BotEventStartDebug evt =
new BotEventStartDebug(null, null,
id);
335 m_ActiveFSM.AddTransition(
new BotTransition(m_IdleState, evt, state, null,
new BotGuardDebugEventMatches(evt)));
337 m_ActiveFSM.AddTransition(
new BotTransition(state, ___OK___, m_IdleState));
338 m_ActiveFSM.AddTransition(
new BotTransition(state, __Fail__, m_IdleState));
339 m_ActiveFSM.AddTransition(
new BotTransition(state, __Tout__, m_IdleState));
341 m_ActiveFSM.AddTransition(
new BotTransition(state, __Stop__, m_IdleState));
364 m_ActiveFSM =
new BotFSM();
365 AddTransition(
new BotStanceRandomizer(
this, NULL),
EActions.PLAYER_BOT_RANDOMIZE_STANCE);
366 AddTransition(
new BotMovementRandomizer(
this, NULL),
EActions.PLAYER_BOT_RANDOMIZE_MOVEMENT);
367 AddTransition(
new BotTestSpamUserActions(
this, NULL),
EActions.PLAYER_BOT_SPAM_USER_ACTIONS);
368 AddTransition(
new BotTestAttachAndDropCycle(
this, NULL),
EActions.PLAYER_BOT_TEST_ATTACH_AND_DROP_CYCLE);
369 AddTransition(
new BotTestItemMoveBackAndForth(
this, NULL),
EActions.PLAYER_BOT_TEST_ITEM_MOVE_BACK_AND_FORTH);
370 AddTransition(
new Bot_TestSpawnOpen(
this, NULL),
EActions.PLAYER_BOT_TEST_SPAWN_OPEN);
371 AddTransition(
new Bot_TestSpawnOpenDestroy(
this, NULL),
EActions.PLAYER_BOT_TEST_SPAWN_OPEN_DESTROY);
372 AddTransition(
new Bot_TestSpawnOpenEat(
this, NULL),
EActions.PLAYER_BOT_TEST_SPAWN_OPEN_EAT);
373 AddTransition(
new BotTestSwapG2H(
this, NULL),
EActions.PLAYER_BOT_TEST_SWAP_G2H);
375 AddTransition(
new BotTestSwapInternal(
this, NULL),
EActions.PLAYER_BOT_TEST_SWAP_INTERNAL);
379 m_ActiveFSM.SetInitialState(m_IdleState);
387 botDebugSpam(
"[botfsm] Processed event e=" + e.ToString());
392 botDebugSpam(
"[botfsm] FSM refused to process event (no transition): src=" + m_ActiveFSM.GetCurrentState().ToString() +
" event=" + e.ToString());
398void botDebugPrint (
string s)
407void botDebugSpam (
string s)
ref ActionTarget m_Target
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
void DayZPlayerUtils()
cannot be instantiated
void Start()
Plays all elements this effects consists of.
enum ProcessDirectDamageFlags m_Owner
void ProcessEvent(EPresenceNotifierNoiseEventType pEventType)
processing of external one-time events (land, fire, etc.)
DayZPlayerInstanceType
defined in C++
proto void PrintToRPT(void var)
Prints content of variable to RPT file (performance warning - each write means fflush!...
class array< Class T > TStringArray
void Stop()
Stops all elements this effect consists of.
proto native bool StartAction(WeaponActions pAction, int pActionType)
start reload,mechanism,chambering,unjam ...