22
33void Bot::AttackStart (void )
44{
5- DeleteSearchNodes ();
5+ m_navNode. Clear ();
66}
77
88void Bot::AttackUpdate (void )
@@ -19,13 +19,12 @@ void Bot::AttackUpdate(void)
1919 FindEnemyEntities ();
2020 LookAtEnemies ();
2121 FacePosition ();
22- CheckReload ();
2322
2423 if (!m_hasEnemiesNear && !m_hasEntitiesNear)
2524 {
2625 if (g_bombPlanted && (m_team == Team::Counter || IsBombDefusing (g_waypoint->GetBombPosition ())))
2726 {
28- if (! FNullEnt (m_nearestEnemy) && IsAlive (m_nearestEnemy))
27+ if (IsAlive (m_nearestEnemy))
2928 CheckGrenadeThrow (m_nearestEnemy);
3029
3130 FinishCurrentProcess (" no target exist" );
@@ -57,16 +56,15 @@ void Bot::AttackUpdate(void)
5756 {
5857 const bool usesSniper = UsesSniper ();
5958 if (!usesSniper)
60- SelectBestWeapon (true , true );
59+ SelectBestWeapon ();
6160
62- const float minRange = squaredf (384 .0f );
6361 const float distance = GetTargetDistance ();
64- if (distance > minRange )
62+ if (distance > squaredf ( 384 . 0f ) )
6563 {
6664 if (!CheckWallOnBehind () && !CheckWallOnForward () && !CheckWallOnLeft () && !CheckWallOnRight ())
6765 {
68- if (usesSniper && pev->fov == 90 .0f && !(pev->button & IN_ATTACK2) && !(pev->oldbuttons & IN_ATTACK2))
69- pev->button |= IN_ATTACK2;
66+ if (usesSniper && pev->fov == 90 .0f && !(pev->buttons & IN_ATTACK2) && !(pev->oldbuttons & IN_ATTACK2))
67+ pev->buttons |= IN_ATTACK2;
7068
7169 wait = cclampf (csqrtf (distance) * 0 .01f , 5 .0f , 15 .0f );
7270 }
@@ -87,8 +85,11 @@ void Bot::AttackUpdate(void)
8785 {
8886 SetWalkTime (7 .0f );
8987 FinishCurrentProcess (" no target exist" );
88+
89+ if (!(pev->oldbuttons & IN_RELOAD))
90+ pev->buttons |= IN_RELOAD; // press reload button
9091 }
91- else if (! FNullEnt (m_nearestEnemy) && IsAlive (m_nearestEnemy))
92+ else if (IsAlive (m_nearestEnemy))
9293 CheckGrenadeThrow (m_nearestEnemy);
9394
9495 return ;
@@ -97,16 +98,31 @@ void Bot::AttackUpdate(void)
9798 FireWeapon ();
9899
99100 const float distance = GetTargetDistance ();
100- const int melee = (g_gameVersion & Game::HalfLife) ? WeaponHL::Crowbar : Weapon::Knife;
101+ int melee = (g_gameVersion & Game::HalfLife) ? WeaponHL::Crowbar : Weapon::Knife;
101102 if (m_currentWeapon == melee)
102103 {
103104 if (IsEnemyReachable ())
104105 {
105- DeleteSearchNodes ();
106+ m_navNode. Clear ();
106107 MoveTo (m_enemyOrigin);
107108 }
109+ else if (!m_navNode.IsEmpty ())
110+ FollowPath ();
108111 else
109- FollowPath (m_enemyOrigin);
112+ {
113+ if (!FNullEnt (m_nearestEnemy))
114+ melee = g_waypoint->FindNearest (m_nearestEnemy->v .origin , 256 .0f , -1 , m_nearestEnemy);
115+ else
116+ melee = g_waypoint->FindNearest (m_enemyOrigin);
117+
118+ if (IsValidWaypoint (melee))
119+ FindPath (m_currentWaypointIndex, melee);
120+ else
121+ {
122+ m_moveSpeed = pev->maxspeed ;
123+ m_strafeSpeed = 0 .0f ;
124+ }
125+ }
110126
111127 return ;
112128 }
@@ -124,16 +140,16 @@ void Bot::AttackUpdate(void)
124140 if (m_currentWeapon == WeaponHL::Mp5_HL && distance > squaredf (300 .0f ) && distance < squaredf (800 .0f ))
125141 {
126142 if (!(pev->oldbuttons & IN_ATTACK2) && !m_isSlowThink && crandomint (1 , 3 ) == 1 )
127- pev->button |= IN_ATTACK2;
143+ pev->buttons |= IN_ATTACK2;
128144 }
129145 else if (m_currentWeapon == WeaponHL::Crowbar && m_personality != Personality::Careful)
130- pev->button |= IN_ATTACK;
146+ pev->buttons |= IN_ATTACK;
131147 }
132148
133149 int approach;
134150 if (!m_hasEnemiesNear && !m_hasEntitiesNear) // if suspecting enemy stand still
135151 approach = 49 ;
136- else if (!(g_gameVersion & Game::HalfLife) && (m_isReloading || m_isVIP)) // if reloading or vip back off
152+ else if (!(g_gameVersion & Game::HalfLife) && ((pev-> buttons & IN_RELOAD || pev-> oldbuttons & IN_RELOAD) || m_isVIP)) // if reloading or vip back off
137153 approach = 29 ;
138154 else
139155 {
@@ -203,17 +219,13 @@ void Bot::AttackUpdate(void)
203219 }
204220 }
205221
206- if (m_fightStyle == 0 || (( pev->button & IN_RELOAD) || m_isReloading ) || (UsesPistol () && distance < squaredf (768 .0f )) || m_currentWeapon == melee)
222+ if (m_fightStyle == 0 || (pev->buttons & IN_RELOAD || pev-> oldbuttons & IN_RELOAD ) || (UsesPistol () && distance < squaredf (768 .0f )) || m_currentWeapon == melee)
207223 {
208224 if (m_strafeSetTime < time)
209225 {
210226 // to start strafing, we have to first figure out if the target is on the left side or right side
211227 MakeVectors (m_nearestEnemy->v .v_angle );
212-
213- const Vector& dirToPoint = (pev->origin - m_enemyOrigin).Normalize2D ();
214- const Vector& rightSide = g_pGlobals->v_right .Normalize2D ();
215-
216- if ((dirToPoint | rightSide) < 0 )
228+ if (((pev->origin - m_enemyOrigin).Normalize2D () | g_pGlobals->v_right .Normalize2D ()) < 0 )
217229 m_combatStrafeDir = 1 ;
218230 else
219231 m_combatStrafeDir = 0 ;
@@ -245,8 +257,8 @@ void Bot::AttackUpdate(void)
245257 }
246258 }
247259
248- if (m_jumpTime + 2 .0f < time && !IsOnLadder () && chanceof (m_isReloading ? 5 : 2 ) && ! UsesSniper ( ) && pev->velocity .GetLength2D () > float (m_skill + 50 ))
249- pev->button |= IN_JUMP;
260+ if (m_jumpTime + 2 .0f < time && !IsOnLadder () && ! UsesSniper ( ) && chanceof ( 5 ) && pev->velocity .GetLength2D () > static_cast < float > (m_skill + 50 ))
261+ pev->buttons |= IN_JUMP;
250262
251263 if (m_moveSpeed > 0 .0f && distance > squaredf (512 .0f ) && m_currentWeapon != melee)
252264 m_moveSpeed = 0 .0f ;
@@ -256,8 +268,7 @@ void Bot::AttackUpdate(void)
256268 }
257269 else if (m_fightStyle == 1 )
258270 {
259- const Vector& src = pev->origin - Vector (0 , 0 , 18 .0f );
260- if (!(m_visibility & (Visibility::Head | Visibility::Body)) && IsVisible (src, m_nearestEnemy))
271+ if (!(m_visibility & (Visibility::Head | Visibility::Body)) && IsVisible (pev->origin - Vector (0 , 0 , 18 .0f ), m_nearestEnemy))
261272 m_duckTime = time + 1 .0f ;
262273
263274 m_moveSpeed = 0 .0f ;
@@ -270,12 +281,6 @@ void Bot::AttackUpdate(void)
270281 m_strafeSpeed = 0 .0f ;
271282 }
272283
273- if (m_isReloading)
274- {
275- m_moveSpeed = -pev->maxspeed ;
276- m_duckTime = 0 .0f ;
277- }
278-
279284 if (!IsInWater () && !IsOnLadder () && (m_moveSpeed > 0 .0f || m_strafeSpeed > 0 .0f ))
280285 {
281286 MakeVectors (pev->v_angle );
@@ -284,12 +289,11 @@ void Bot::AttackUpdate(void)
284289 {
285290 m_strafeSpeed = -m_strafeSpeed;
286291 m_moveSpeed = -m_moveSpeed;
287- pev->button &= ~IN_JUMP;
292+ pev->buttons &= ~IN_JUMP;
288293 }
289294 }
290295
291- const Vector directionOld = m_enemyOrigin - pev->origin ;
292- m_moveAngles = directionOld.ToAngles ();
296+ m_moveAngles = (m_enemyOrigin - pev->origin ).ToAngles ();
293297 m_moveAngles.ClampAngles ();
294298}
295299
0 commit comments