DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
Bot_TurnToValidForward.c
См. документацию.
1#ifdef ROBOCLIENT
2class BotTurnToValidForward extends BotStateBase
3{
4 private int m_AngleCheck = 5; //5 degree incremental checks
5 private float m_TurnRate = 2;
6
7 private bool m_FoundDirection = false;
8 private vector m_ValidDirection = vector.Zero;
9 private float m_TurnDirection = 1;
10 private float m_MinAngle = 500;
11
12 void BotTurnToValidForward(Bot bot = NULL, BotStateBase parent = NULL)
13 {
14 }
15
16 override void OnEntry (BotEventBase e)
17 {
18 super.OnEntry(e);
19 m_ValidDirection = m_Owner.GetDirection();
20 m_FoundDirection = false;
21 m_MinAngle = 500;
22 m_TurnRate = 2;
23
24#ifdef INPUT_OVERRIDE
25 g_Game.GetPlayer().GetInputInterface().SyncedRemoveOverride_ID(UAAimLeft);
26 g_Game.GetPlayer().GetInputInterface().SyncedRemoveOverride_ID(UAAimRight);
27#endif
28 }
29
30 override void OnExit (BotEventBase e)
31 {
32 super.OnExit(e);
33
34#ifdef INPUT_OVERRIDE
35 g_Game.GetPlayer().GetInputInterface().SyncedRemoveOverride_ID(UAAimLeft);
36 g_Game.GetPlayer().GetInputInterface().SyncedRemoveOverride_ID(UAAimRight);
37#endif
38 }
39
40 BotEventBase GetNextEvent()
41 {
42 if (m_Bot.m_Target && m_Bot.m_Target.IsAlive())
43 return m_Bot.__Atkd__;
44 else
45 return m_Bot.__VaFw__;
46 }
47
48 override void OnUpdate (float dt)
49 {
50 if (!m_FoundDirection)
51 {
52 vector m_OwnerPosition = m_Owner.GetPosition();
53 vector m_WaterPositionCheck = m_OwnerPosition + m_Owner.GetDirection() * 3;
54 if (GetGame().SurfaceIsSea(m_WaterPositionCheck[0], m_WaterPositionCheck[2]))
55 {
56 m_TurnDirection = 1;
57 m_ValidDirection = -m_Owner.GetDirection();
58 m_FoundDirection = true;
59 }
60 else
61 {
62 const vector raycastHeight = "0 0.75 0"; //raycast from a higher point than the feet
63 const float startPosOffset = 0.1; //offset for some issues with vaulting
64 const float raycastDist = 0.8;
65 const float raycastSphereRadius = 0.3;
66 vector startPos = m_OwnerPosition + raycastHeight + startPosOffset * m_Owner.GetDirection();
67 vector endPos = m_OwnerPosition + raycastHeight + raycastDist * m_Owner.GetDirection();
68 vector hitPosition, hitNormal;
69 float hitFraction;
70 Object hitObject = null;
72
73 int leftStreak = 0;
74 int rightStreak = 0;
75 int rotationsAvailable = (360 / m_AngleCheck) / 2 + 1;
76 float lastResortTurnDirection = 0;
77 vector lastResortDirection = vector.Zero;
78
79 for (int i = 1; i < rotationsAvailable; i++)
80 {
81 vector newLeftDirection = vector.RotateAroundZeroDeg(m_Owner.GetDirection(), vector.Up, -m_AngleCheck * i);
82 vector newRightDirection = vector.RotateAroundZeroDeg(m_Owner.GetDirection(), vector.Up, m_AngleCheck * i);
83
84 vector leftEndPos = startPos + newLeftDirection * 3;
85 vector rightEndPos = startPos + newRightDirection * 3;
86
87 //looking for 2 consecutive valid raycast checks
88 bool resLeft = DayZPhysics.SphereCastBullet(startPos, leftEndPos, raycastSphereRadius, collisionMask, m_Owner, hitObject, hitPosition, hitNormal, hitFraction);
89 if (!resLeft)
90 {
91 leftStreak++;
92 lastResortTurnDirection = -1;
93 lastResortDirection = newLeftDirection;
94
95 if (leftStreak == 2)
96 {
97 m_ValidDirection = vector.RotateAroundZeroDeg(m_Owner.GetDirection(), vector.Up, -(m_AngleCheck * (i - 1) + m_AngleCheck / 2));
98 m_TurnDirection = -1;
99 m_FoundDirection = true;
100 break;
101 }
102 }
103 else
104 leftStreak = 0;
105
106 bool resRight = DayZPhysics.SphereCastBullet(startPos, rightEndPos, raycastSphereRadius, collisionMask, m_Owner, hitObject, hitPosition, hitNormal, hitFraction);
107 if (!resRight)
108 {
109 rightStreak++;
110 lastResortTurnDirection = 1;
111 lastResortDirection = newRightDirection;
112 if (rightStreak == 2)
113 {
114 m_ValidDirection = vector.RotateAroundZeroDeg(m_Owner.GetDirection(), vector.Up, m_AngleCheck * (i - 1) + m_AngleCheck / 2);
115 m_TurnDirection = 1;
116 m_FoundDirection = true;
117 break;
118 }
119 }
120 else
121 rightStreak = 0;
122
123 if (!m_FoundDirection)
124 {
125 m_TurnDirection = lastResortTurnDirection;
126 m_ValidDirection = lastResortDirection;
127 m_FoundDirection = true;
128 }
129 }
130 }
131 }
132
133 if (!m_FoundDirection)
134 {
135 m_Bot.ProcessEvent(GetNextEvent());
136 return;
137 }
138
139 float prod = m_Owner.GetDirection().Length() * m_ValidDirection.Length();
140 if (prod == 0)
141 {
142 m_Bot.ProcessEvent(GetNextEvent());
143 return;
144 }
145
146 float dot = vector.Dot(m_Owner.GetDirection(), m_ValidDirection);
147 float angle = Math.Acos(dot / prod);
148 angle = Math.RAD2DEG * angle;
149 if (angle < 3 || angle > m_MinAngle + 0.5)
150 {
151 m_Bot.ProcessEvent(GetNextEvent());
152 return;
153 }
154
155 m_MinAngle = Math.Min(angle, m_MinAngle);
156
157 float slowDown = 1;
158 if (angle < 30)
159 slowDown = angle / 30;
160
161 slowDown = Math.Clamp(slowDown, 0.2, 1);
162
163 int inputID = UAAimLeft;
164 if (m_TurnDirection > 0)
165 inputID = UAAimRight;
166
167#ifdef INPUT_OVERRIDE
168 g_Game.GetPlayer().GetInputInterface().SyncedOverride_ID(inputID, m_TurnDirection * m_TurnRate * slowDown, OverrideInputType.HOLD, false);
169#endif
170
171 super.OnUpdate(dt);
172 }
173}
174#endif
DayZGame g_Game
Определения DayZGame.c:4074
PhxInteractionLayers
Определения DayZPhysics.c:2
float hitFraction
Определения DustKickupEffects.c:23
HandStateEquipped OnEntry
Определения WeaponChambering.c:292
enum ProcessDirectDamageFlags m_Owner
vector m_OwnerPosition
The owner performing the snap callback.
Определения Object.c:12
class WeaponChambering_Chamber_OnEntry extends WeaponChambering_Base OnExit
Определения WeaponChambering.c:352
override void OnEntry(HandEventBase e)
Определения Hand_States.c:34
override void OnExit(WeaponEventBase e)
Определения WeaponChambering.c:439
proto native float Length()
Returns length of vector (magnitude)
static vector RotateAroundZeroDeg(vector vec, vector axis, float angle)
Rotate a vector around 0,0,0 by an angle in degrees.
Определения EnConvert.c:484
class LOD Object
DayZGame GetGame()
Определения gameplay.c:636
proto native void OnUpdate()
Определения 3_Game/DayZ/tools/tools.c:349