DayZ 1.24
Loading...
Searching...
No Matches
Bot_Hunt.c
Go to the documentation of this file.
1
3{
4 //EntityAI m_Entity;
5 //void BotEventEntityAttached (PlayerBase p = NULL, EntityAI att = NULL) { m_Entity = att; }
6};
7
9{
10 //EntityAI m_Entity;
11 //void BotEventEntityDetached (PlayerBase p = NULL, EntityAI att = NULL) { m_Entity = att; }
12};
13
14
15class BotHunt extends BotStateBase
16{
18 float m_dtAccumulator = 0.0;
19
22
23 void BotHunt(Bot bot = NULL, BotStateBase parent = NULL)
24 {
25 // setup nested state machine
26 m_FSM = new BotFSM(this); // @NOTE: set owner of the submachine fsm
27
28 m_Tracking = new BotHunt_Tracking(m_Bot, this);
29 m_Hunting = new BotHunt_Hunting(m_Bot, this);
30
31 // events
34
35 // transitions
36 m_FSM.AddTransition(new BotTransition(m_Tracking, __InSight__, m_Hunting));
37 m_FSM.AddTransition(new BotTransition(m_Hunting, __Lost__, m_Tracking));
38
39 m_FSM.SetInitialState(m_Tracking);
40 }
41
43 {
45 m_Tracking.m_Target = m_Target;
46 m_Hunting.m_Target = m_Target;
47 botDebugPrint("[bot] + " + m_Owner + " hunt SelectTarget target=" + m_Target);
48 }
49
50 override void OnEntry(BotEventBase e)
51 {
52 m_dtAccumulator = 0.0;
54
55 super.OnEntry(e);
56 }
57
58 override void OnExit(BotEventBase e)
59 {
60 m_dtAccumulator = 0.0;
61 m_Target = null;
62
63 super.OnExit(e);
64 }
65
66 override void OnUpdate(float dt)
67 {
68 super.OnUpdate(dt);
69
71
72 /*float rescanTime = 3.0;
73 if (m_dtAccumulator >= rescanTime)
74 if (m_weapon.CanProcessWeaponEvents())
75 m_Bot.ProcessEvent(new WeaponEventReloadTimeout(p));*/
76
77 if (m_Target == null)
78 {
79 int acc = m_dtAccumulator;
80 if (acc % 5 == 0)
81 {
82 Print("Searching...");
84 }
85 }
86 }
87};
88
90{
92 bool m_TargetInSight = false;
93 bool m_TargetLost = false;
94 bool m_Tracking = true;
95
96 override void OnEntry(BotEventBase e)
97 {
98 super.OnEntry(e);
99
100 m_TargetLost = false;
101 m_TargetInSight = false;
102 m_Tracking = false;
103 }
104
105 override void OnAbort(BotEventBase e)
106 {
107 m_TargetLost = false;
108 m_TargetInSight = false;
109 m_Tracking = false;
110
111 super.OnAbort(e);
112 }
113
114 override void OnExit(BotEventBase e)
115 {
116 m_TargetLost = false;
117 m_TargetInSight = false;
118 m_Tracking = false;
119
120 super.OnExit(e);
121 }
122
123 override void OnUpdate(float dt)
124 {
125 if (m_Target)
126 {
127 m_Tracking = true;
128 vector targetPos = m_Target.GetPosition();
129 botDebugPrint("[bot] + " + m_Owner + " hunt Tracking target=" + m_Target + " pos=" + targetPos);
130
131 // tmp dist check
132 float d = vector.Distance(m_Target.GetPosition(), GetPlayerOwner().GetPosition());
133 if (d < 2.0)
134 m_TargetInSight = true;
135 else
136 m_TargetInSight = false;
137
138 if (!m_TargetInSight)
139 {
140 GetPlayerOwner().GetInputController().OverrideMovementSpeed(true, 1);
141 GetPlayerOwner().GetInputController().OverrideMovementAngle(true, 1);
142 }
143 else
144 {
145 GetPlayerOwner().GetInputController().OverrideMovementSpeed(false, 0);
146 GetPlayerOwner().GetInputController().OverrideMovementAngle(false, 0);
147 }
148
149 /*if ((.GetInputController().LimitsIsSprintDisabled()))
150 .GetInputController().OverrideMovementSpeed( true, 2 );
151 else
152 .GetInputController().OverrideMovementSpeed( true, 3 );*/
153
154 }
155 else
156 {
157 if (m_Tracking)
158 {
159 m_TargetLost = true;
160 m_TargetInSight = false;
161 m_Tracking = false;
162
163 GetPlayerOwner().GetInputController().OverrideMovementSpeed(false, 0);
164 GetPlayerOwner().GetInputController().OverrideMovementAngle(false, 0);
165 }
166 }
167 }
168};
169
170class BotHunt_Hunting extends BotStateBase
171{
173
174 override void OnEntry(BotEventBase e)
175 {
176 super.OnEntry(e);
177 }
178
179 override void OnAbort(BotEventBase e) { super.OnAbort(e); }
180
181 override void OnExit(BotEventBase e)
182 {
183 super.OnExit(e);
184 }
185
186 override void OnUpdate(float dt)
187 {
188 }
189};
190
192{
193 /*ref array<Man> players = new array<Man>;
194 g_Game.GetWorld().GetPlayerList( players );
195
196 bool minimal_distance_ok = true;
197
198 float min_dist = 1234567.0;
199 int min_index = -1;
200 for ( int i = 0; i < players.Count(); i++ )
201 {
202 float d = vector.Distance(players.Get(i).GetPosition(), bot.GetPosition());
203 if ( d < min_dist )
204 {
205 min_dist = d;
206 min_index = i;
207 }
208 }
209
210 if (min_index != -1)
211 return players.Get(min_index);
212
213 return null;*/
214 vector pos = bot.GetPosition();
215 //vector dir = player.GetDirection();
216
219 GetGame().GetObjectsAtPosition(pos, 100.0, objects, proxyCargos);
220
221 float min_dist = 1234567.0;
222 int min_index = -1;
223 int c = objects.Count();
224 for (int i = 0; i < c; i++)
225 {
226 Object o = objects[i];
227 if (o == bot)
228 continue;
229
230 float d = vector.Distance(o.GetPosition(), bot.GetPosition());
231 if (d < min_dist)
232 {
233 min_dist = d;
234 min_index = i;
235 }
236 }
237
238 if (min_index != -1)
239 {
240 botDebugPrint("[bot] + " + bot + " BotSelectNearestTarget idx=" + min_index + " dist=" + min_dist + " obj=" + o);
241 return Man.Cast(objects.Get(min_index));
242 }
243 return null;
244}
245
ref ActionTarget m_Target
Definition ActionBase.c:17
void botDebugPrint(string s)
Definition Bot.c:182
Man BotSelectNearestTarget(EntityAI bot)
Definition Bot_Hunt.c:191
FSMTransition< BotStateBase, BotEventBase, BotActionBase, BotGuardBase > BotTransition
Definition BotFSM.c:7
enum ProcessDirectDamageFlags m_Owner
class JsonUndergroundAreaTriggerData GetPosition
class WeaponFireWithEject extends WeaponFire m_dtAccumulator
represents event that triggers transition from state to state
Definition BotEvents.c:5
Bot Finite State Machine (Hierarchical)
Definition Bot.c:19
represent weapon state base
Definition Bot_Hunt.c:16
void BotHunt(Bot bot=NULL, BotStateBase parent=NULL)
Definition Bot_Hunt.c:23
override void OnUpdate(float dt)
Definition Bot_Hunt.c:66
override void OnEntry(BotEventBase e)
Definition Bot_Hunt.c:50
override void OnAbort(BotEventBase e)
Definition Bot_Hunt.c:105
float m_dtAccumulator
Definition Bot_Hunt.c:18
PlayerBase GetPlayerOwner()
Definition BotStates.c:19
ref BotHunt_Tracking m_Tracking
Definition Bot_Hunt.c:20
override void OnExit(BotEventBase e)
Definition Bot_Hunt.c:58
void SelectTarget()
Definition Bot_Hunt.c:42
ref BotHunt_Hunting m_Hunting
Definition Bot_Hunt.c:21
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.