DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
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
20 ref BotHunt_Tracking m_Tracking;
21 ref BotHunt_Hunting m_Hunting;
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
70 m_dtAccumulator += dt;
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
89class BotHunt_Tracking extends BotStateBase
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 {
135 m_TargetInSight = true;
136 }
137 else
138 {
139 m_TargetInSight = false;
140 }
141
142 if (!m_TargetInSight)
143 {
144 GetPlayerOwner().GetInputController().OverrideMovementSpeed(true, 1);
145 GetPlayerOwner().GetInputController().OverrideMovementAngle(true, 1);
146 }
147 else
148 {
149 GetPlayerOwner().GetInputController().OverrideMovementSpeed(false, 0);
150 GetPlayerOwner().GetInputController().OverrideMovementAngle(false, 0);
151 }
152
153 /*if ((.GetInputController().LimitsIsSprintDisabled()))
154 .GetInputController().OverrideMovementSpeed( true, 2 );
155 else
156 .GetInputController().OverrideMovementSpeed( true, 3 );*/
157
158 }
159 else
160 {
161 if (m_Tracking)
162 {
163 m_TargetLost = true;
164 m_TargetInSight = false;
165 m_Tracking = false;
166
167 GetPlayerOwner().GetInputController().OverrideMovementSpeed(false, 0);
168 GetPlayerOwner().GetInputController().OverrideMovementAngle(false, 0);
169 }
170 }
171 }
172};
173
174class BotHunt_Hunting extends BotStateBase
175{
177
178 override void OnEntry (BotEventBase e)
179 {
180 super.OnEntry(e);
181 }
182
183 override void OnAbort (BotEventBase e) { super.OnAbort(e); }
184
185 override void OnExit (BotEventBase e)
186 {
187 super.OnExit(e);
188 }
189
190 override void OnUpdate (float dt)
191 {
192 }
193};
194
196{
197 /*ref array<Man> players = new array<Man>;
198 g_Game.GetWorld().GetPlayerList( players );
199
200 bool minimal_distance_ok = true;
201
202 float min_dist = 1234567.0;
203 int min_index = -1;
204 for ( int i = 0; i < players.Count(); i++ )
205 {
206 float d = vector.Distance(players.Get(i).GetPosition(), bot.GetPosition());
207 if ( d < min_dist )
208 {
209 min_dist = d;
210 min_index = i;
211 }
212 }
213
214 if (min_index != -1)
215 return players.Get(min_index);
216
217 return null;*/
218 vector pos = bot.GetPosition();
219 //vector dir = player.GetDirection();
220
221 array<Object> objects = new array<Object>;
222 array<CargoBase> proxyCargos = new array<CargoBase>;
223 GetGame().GetObjectsAtPosition(pos, 100.0, objects, proxyCargos);
224
225 float min_dist = 1234567.0;
226 int min_index = -1;
227 int c = objects.Count();
228 for (int i = 0; i < c; i++)
229 {
230 Object o = objects[i];
231 if (o == bot)
232 continue;
233
234 float d = vector.Distance(o.GetPosition(), bot.GetPosition());
235 if ( d < min_dist )
236 {
237 min_dist = d;
238 min_index = i;
239 }
240 }
241
242 if (min_index != -1)
243 {
244 botDebugPrint("[bot] + " + bot + " BotSelectNearestTarget idx=" + min_index + " dist=" + min_dist + " obj=" + o);
245 return Man.Cast( objects.Get(min_index) );
246 }
247 return null;
248}
249
250
ref ActionTarget m_Target
Definition ActionBase.c:17
void botDebugPrint(string s)
Definition Bot.c:182
Man BotSelectNearestTarget(EntityAI bot)
Definition Bot_Hunt.c:195
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
ref BotHunt_Tracking m_Tracking
Definition Bot_Hunt.c:20
override void OnAbort(BotEventBase e)
Definition Bot_Hunt.c:105
void SelectTarget()
Definition Bot_Hunt.c:42
void BotHunt(Bot bot=NULL, BotStateBase parent=NULL)
Definition Bot_Hunt.c:23
PlayerBase GetPlayerOwner()
Definition BotStates.c:19
float m_dtAccumulator
Definition Bot_Hunt.c:18
override void OnExit(BotEventBase e)
Definition Bot_Hunt.c:58
override void OnEntry(BotEventBase e)
Definition Bot_Hunt.c:50
ref BotHunt_Hunting m_Hunting
Definition Bot_Hunt.c:21
override void OnUpdate(float dt)
Definition Bot_Hunt.c:66
proto native void GetObjectsAtPosition(vector pos, float radius, out array< Object > objects, out array< CargoBase > proxyCargos)
Returns list of all objects in circle "radius" around position "pos".
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
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.