Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
bot_hunt.c
Go to the documentation of this file.
1
2
class
BotEventHuntedTargetInSight
:
BotEventBase
3
{
4
//EntityAI m_Entity;
5
//void BotEventEntityAttached (PlayerBase p = NULL, EntityAI att = NULL) { m_Entity = att; }
6
};
7
8
class
BotEventHuntedTargetLost
:
BotEventBase
9
{
10
//EntityAI m_Entity;
11
//void BotEventEntityDetached (PlayerBase p = NULL, EntityAI att = NULL) { m_Entity = att; }
12
};
13
14
15
class
BotHunt
extends
BotStateBase
16
{
17
Man
m_Target
;
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
32
BotEventBase
__InSight__ =
new
BotEventHuntedTargetInSight
;
33
BotEventBase
__Lost__ =
new
BotEventHuntedTargetLost
;
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
42
void
SelectTarget
()
43
{
44
m_Target
=
BotSelectNearestTarget
(
GetPlayerOwner
());
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;
53
SelectTarget
();
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..."
);
83
SelectTarget
();
84
}
85
}
86
}
87
};
88
89
class
BotHunt_Tracking
extends
BotStateBase
90
{
91
EntityAI
m_Target
;
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
174
class
BotHunt_Hunting
extends
BotStateBase
175
{
176
EntityAI
m_Target
;
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
195
Man
BotSelectNearestTarget
(
EntityAI
bot)
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
g_Game
.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
EntityAI
class LogManager EntityAI
m_Target
ref ActionTarget m_Target
Definition
actionbase.c:18
botDebugPrint
void botDebugPrint(string s)
Definition
bot.c:122
BotSelectNearestTarget
Man BotSelectNearestTarget(EntityAI bot)
Definition
bot_hunt.c:195
BotTransition
FSMTransition< BotStateBase, BotEventBase, BotActionBase, BotGuardBase > BotTransition
Definition
botfsm.c:7
BotEventBase
represents event that triggers transition from state to state
Definition
botevents.c:5
BotEventBase::BotEventBase
void BotEventBase(PlayerBase p=NULL, EntityAI e=NULL)
Definition
botevents.c:9
BotEventHuntedTargetInSight
Definition
bot_hunt.c:3
BotEventHuntedTargetLost
Definition
bot_hunt.c:9
BotFSM
Bot Finite State Machine (Hierarchical).
Bot
Definition
bot.c:19
BotStateBase
represent weapon state base
Definition
bot_hunt.c:16
BotStateBase::m_Tracking
ref BotHunt_Tracking m_Tracking
Definition
bot_hunt.c:20
BotStateBase::m_TargetInSight
bool m_TargetInSight
Definition
bot_hunt.c:92
BotStateBase::m_FSM
ref BotFSM m_FSM
hierarchical parent state of this state (or null)
Definition
botstates.c:15
BotStateBase::OnAbort
override void OnAbort(BotEventBase e)
Definition
bot_hunt.c:105
BotStateBase::SelectTarget
void SelectTarget()
Definition
bot_hunt.c:42
BotStateBase::BotStateBase
void BotStateBase(Bot bot=NULL, BotStateBase parent=NULL)
nested state machine (or null)
Definition
botstates.c:17
BotStateBase::BotHunt
void BotHunt(Bot bot=NULL, BotStateBase parent=NULL)
Definition
bot_hunt.c:23
BotStateBase::GetPlayerOwner
PlayerBase GetPlayerOwner()
Definition
botstates.c:19
BotStateBase::m_dtAccumulator
float m_dtAccumulator
Definition
bot_hunt.c:18
BotStateBase::OnExit
override void OnExit(BotEventBase e)
Definition
bot_hunt.c:58
BotStateBase::m_Owner
PlayerBase m_Owner
Definition
botstates.c:12
BotStateBase::OnEntry
override void OnEntry(BotEventBase e)
Definition
bot_hunt.c:50
BotStateBase::m_Hunting
ref BotHunt_Hunting m_Hunting
Definition
bot_hunt.c:21
BotStateBase::OnUpdate
override void OnUpdate(float dt)
Definition
bot_hunt.c:66
BotStateBase::m_Bot
Bot m_Bot
man that this state belongs to
Definition
botstates.c:13
BotStateBase::m_TargetLost
bool m_TargetLost
Definition
bot_hunt.c:93
BotStateBase::m_Target
Man m_Target
Definition
bot_hunt.c:17
EntityAI
Definition
inventoryitem.c:2
Object
Definition
objecttyped.c:2
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition
isboxcollidinggeometryproxyclasses.c:28
vector
Definition
enconvert.c:119
vector::Distance
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
g_Game
DayZGame g_Game
Definition
dayzgame.c:3942
Print
proto void Print(void var)
Prints content of variable to console/log.
GetPosition
vector GetPosition()
Get the world position of the Effect.
Definition
effect.c:473
Games
Dayz
scripts
4_world
systems
bot
bot_hunt.c
Generated by
1.17.0