DayZ 1.24
Loading...
Searching...
No Matches
Bot.c
Go to the documentation of this file.
1
4{
5 bool CheckTrigger() { return false; }
6};
7
9{
12 override bool CheckTrigger() { return null != m_Owner.GetInventory().FindAttachment(InventorySlots.GetSlotIdFromString("Headgear")); }
13};
14
15
18class Bot
19{
21 protected ref Timer m_Timer = new Timer;
22 protected const float c_TriggerTimeoutMS = 1000.0;
23 //protected const float c_UpdateMS = 2000.0;
24 protected const float c_UpdateMS = 16.0;
25 protected ref BotFSM m_FSM = null;
26 protected bool m_UseTrigger = false;
27 protected bool m_Triggered = false;
31
33 {
34 m_Owner = ow;
35 }
36
38
40 {
42
43 InitFSM();
44
45 if (m_UseTrigger)
46 {
47 if (m_UseTrigger && trigger == null)
48 Error("use trigger, but trigger null");
49
50 m_Triggered = false;
52 botDebugPrint("[bot] + " + m_Owner + " Bot waiting for trigger...");
53 m_Timer.Run(c_TriggerTimeoutMS / 1000.0, this, "OnTrigger", null, true);
54 }
55 else
56 {
57 botDebugPrint("[bot] + " + m_Owner + " Bot Started.");
58 m_Timer.Run(c_UpdateMS / 1000.0, this, "OnTimer", null, true);
59 }
60 }
61
62 void DelayedStart(float ms)
63 {
64 m_Timer.Run(ms / 1000.0, this, "OnDelayedStart", null, false);
65 }
66
67 protected void OnDelayedStart()
68 {
69 Start(false, null);
70
72 m_UseTrigger = false;
73 }
74
75 void Stop()
76 {
77 m_Triggered = false;
78 m_Timer.Stop();
79 m_FSM.Terminate();
80 }
81
82 protected void OnTrigger()
83 {
84 bool triggered = m_BotTrigger.CheckTrigger();
85
86 if (!m_Triggered)
87 {
88 if (triggered)
89 {
90 m_Timer.Stop(); // stop trigger timer
91 m_Triggered = true;
93 m_Timer.Run(c_UpdateMS / 1000.0, this, "OnUpdate", null, true);
94
95 botDebugPrint("[bot] + " + m_Owner + " Started test!");
96 }
97 }
98 else
99 {
100 if (!triggered)
101 {
102 m_Timer.Stop(); // stop update timer
103 m_Triggered = false;
105 m_Timer.Run(c_TriggerTimeoutMS / 1000.0, this, "OnTrigger", null, true);
106
107 botDebugPrint("[bot] + " + m_Owner + " Stopped test!");
108 }
109 }
110 }
111
112 void OnUpdate(float dt)
113 {
114 m_FSM.GetCurrentState().OnUpdate(dt);
115
116 OnTrigger(); // to detect trigger stop
117 }
118
119 void OnTimer()
120 {
121 //m_FSM.GetCurrentState().OnUpdate(c_UpdateMS / 1000.0);
122
123 //OnTrigger(); // to detect trigger stop
124 }
125
126 void InitFSM()
127 {
128 m_FSM = new BotFSM();
129
130 // basic states
132 // unstable (intermediate) states
134 //m_BotTest = new BotTestAttachAndDropCycle(this, NULL);
135 //m_BotTest = new BotTestItemMoveBackAndForth(this, NULL);
136 //m_BotTest = new Bot_TestSpawnOpen(this, NULL);
137 //m_BotTest = new Bot_TestSpawnOpenDestroy(this, NULL);
138 //m_BotTest = new Bot_TestSpawnOpenEat(this, NULL);
139 //m_BotTest = new BotTestSwapG2H(this, NULL);
140 //m_BotTest = new BotTestSwapC2H(this, NULL);
141 //m_BotTest = new BotTestSwapInternal(this, NULL);
142
143 // events
150
152 m_FSM.AddTransition(new BotTransition(BotIdle, ___Bgn__, m_BotTest));
153 m_FSM.AddTransition(new BotTransition(BotIdle, __Stop__, NULL));
154
155 // causes restart of FSM
156 //m_FSM.AddTransition(new BotTransition(m_BotTest , __IChg__, m_BotTest));
157
158 //m_FSM.AddTransition(new BotTransition(m_BotTest , ___OK___, BotIdle));
159 m_FSM.AddTransition(new BotTransition(m_BotTest, __Fail__, BotIdle));
160 m_FSM.AddTransition(new BotTransition(m_BotTest, __Tout__, BotIdle));
162
163 m_FSM.SetInitialState(BotIdle);
164 m_FSM.Start();
165 }
166
168 {
169 if (m_FSM.ProcessEvent(e) == ProcessEventResult.FSM_OK)
170 {
171 botDebugSpam("[botfsm] Processed event e=" + e.ToString());
172 return true;
173 }
174 else
175 {
176 botDebugSpam("[botfsm] FSM refused to process event (no transition): src=" + m_FSM.GetCurrentState().ToString() + " event=" + e.ToString());
177 return false;
178 }
179 }
180};
181
182void botDebugPrint(string s)
183{
184#ifdef BOT_DEBUG
185 PrintToRPT("" + s); // comment/uncomment to hide/see debug logs
186#else
187 //Print("" + s); // comment/uncomment to hide/see debug logs
188#endif
189}
190
191void botDebugSpam(string s)
192{
193#ifdef BOT_DEBUG_SPAM
194 PrintToRPT("" + s); // comment/uncomment to hide/see debug logs
195#else
196 //Print("" + s); // comment/uncomment to hide/see debug logs
197#endif
198}
199
void botDebugSpam(string s)
Definition Bot.c:191
void botDebugPrint(string s)
Definition Bot.c:182
FSMTransition< BotStateBase, BotEventBase, BotActionBase, BotGuardBase > BotTransition
Definition BotFSM.c:7
void Start()
Plays all elements this effects consists of.
Definition Effect.c:149
ProcessEventResult
Definition FSMBase.c:41
represents event that triggers transition from state to state
Definition BotEvents.c:5
Bot Finite State Machine (Hierarchical)
Definition Bot.c:19
bool m_UseTrigger
Definition Bot.c:26
void Bot(PlayerBase ow)
Definition Bot.c:32
void DelayedStart(float ms)
Definition Bot.c:62
void OnTrigger()
Definition Bot.c:82
const float c_TriggerTimeoutMS
Definition Bot.c:22
const float c_UpdateMS
Definition Bot.c:24
ref Timer m_Timer
Definition Bot.c:21
ref BotStateBase m_BotTest
Definition Bot.c:30
PlayerBase m_Owner
Definition Bot.c:20
void Stop()
Definition Bot.c:75
ref BotTrigger m_BotTrigger
Definition Bot.c:29
void SetInstanceType(DayZPlayerInstanceType t)
Definition Bot.c:37
void InitFSM()
Definition Bot.c:126
DayZPlayerInstanceType m_InstanceType
Definition Bot.c:28
bool ProcessEvent(BotEventBase e)
Definition Bot.c:167
void OnTimer()
Definition Bot.c:119
void OnUpdate(float dt)
Definition Bot.c:112
ref BotFSM m_FSM
Definition Bot.c:25
bool m_Triggered
Definition Bot.c:27
void OnDelayedStart()
Definition Bot.c:67
void Start(bool use_trigger, BotTrigger trigger=null)
Definition Bot.c:39
represent weapon state base
Definition Bot_Hunt.c:16
bool CheckTrigger()
Definition Bot.c:5
provides access to slot configuration
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
PlayerBase m_Owner
Definition Bot.c:10
override bool CheckTrigger()
Definition Bot.c:12
void MyBotTrigger(PlayerBase p)
Definition Bot.c:11
DayZPlayerInstanceType
defined in C++
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
proto void PrintToRPT(void var)
Prints content of variable to RPT file (performance warning - each write means fflush!...