26
26
27
27
ConVar ebot_escape (" ebot_zombie_escape_mode" , " 0" );
28
28
ConVar ebot_zp_use_grenade_percent (" ebot_zm_use_grenade_percent" , " 10" );
29
- ConVar ebot_zp_escape_distance (" ebot_zm_escape_distance" , " 200 " );
30
- ConVar ebot_zombie_speed_factor (" ebot_zombie_speed_factor" , " 1.0 " );
29
+ ConVar ebot_zp_escape_distance (" ebot_zm_escape_distance" , " 300 " );
30
+ ConVar ebot_zombie_speed_factor (" ebot_zombie_speed_factor" , " 0.5 " );
31
31
ConVar ebot_sb_mode (" ebot_sb_mode" , " 0" );
32
32
33
33
int Bot::GetNearbyFriendsNearPosition (Vector origin, int radius)
@@ -41,7 +41,7 @@ int Bot::GetNearbyFriendsNearPosition(Vector origin, int radius)
41
41
if (!(client.flags & CFLAG_USED) || !(client.flags & CFLAG_ALIVE) || client.team != m_team || client.ent == GetEntity ())
42
42
continue ;
43
43
44
- if ((client.origin - origin).GetLength () <= radius)
44
+ if ((client.origin - origin).GetLengthSquared () <= radius * radius)
45
45
count++;
46
46
}
47
47
@@ -56,7 +56,7 @@ int Bot::GetNearbyEnemiesNearPosition(Vector origin, int radius)
56
56
if (!(client.flags & CFLAG_USED) || !(client.flags & CFLAG_ALIVE) || client.team == m_team)
57
57
continue ;
58
58
59
- if ((client.origin - origin).GetLength () <= radius)
59
+ if ((client.origin - origin).GetLengthSquared () <= radius * radius)
60
60
count++;
61
61
}
62
62
@@ -71,10 +71,10 @@ void Bot::ResetCheckEnemy()
71
71
for (i = 0 ; i < checkEnemyNum; i++)
72
72
{
73
73
m_allEnemy[i] = nullptr ;
74
- m_allEnemyDistance[i] = 9999 . 9f ;
74
+ m_allEnemyDistance[i] = FLT_MAX ;
75
75
76
76
m_checkEnemy[i] = nullptr ;
77
- m_checkEnemyDistance[i] = 9999 . 9f ;
77
+ m_checkEnemyDistance[i] = FLT_MAX ;
78
78
}
79
79
80
80
for (i = 1 ; i <= engine->GetMaxClients (); i++)
@@ -111,7 +111,8 @@ void Bot::ResetCheckEnemy()
111
111
112
112
if (m_allEnemyDistance[i] == m_checkEnemyDistance[y])
113
113
{
114
- if ((pev->origin - GetEntityOrigin (m_allEnemy[i])).GetLength () > (pev->origin - GetEntityOrigin (m_checkEnemy[y])).GetLength ())
114
+ Vector myVec = pev->origin + pev->velocity * m_frameInterval;
115
+ if ((myVec - GetEntityOrigin (m_allEnemy[i])).GetLengthSquared2D () > (myVec - GetEntityOrigin (m_checkEnemy[y])).GetLengthSquared2D ())
115
116
continue ;
116
117
}
117
118
@@ -135,10 +136,10 @@ void Bot::ResetCheckEnemy()
135
136
float Bot::GetEntityDistance (edict_t * entity)
136
137
{
137
138
if (FNullEnt (entity))
138
- return 9999 . 0f ;
139
+ return FLT_MAX ;
139
140
140
- float distance = (pev->origin - GetEntityOrigin (entity)).GetLength ();
141
- if (distance <= 128 .0f )
141
+ float distance = (pev->origin - GetEntityOrigin (entity)).GetLengthSquared ();
142
+ if (distance <= SquaredF ( 128 .0f ) )
142
143
return distance;
143
144
144
145
int srcIndex, destIndex;
@@ -153,7 +154,7 @@ float Bot::GetEntityDistance(edict_t* entity)
153
154
destIndex = m_currentWaypointIndex;
154
155
}
155
156
156
- if (!IsValidWaypoint (srcIndex) || !IsValidWaypoint (destIndex < 0 ) || srcIndex == destIndex)
157
+ if (!IsValidWaypoint (srcIndex) || !IsValidWaypoint (destIndex) || srcIndex == destIndex)
157
158
return distance;
158
159
159
160
Path* path = g_waypoint->GetPath (srcIndex);
@@ -185,7 +186,7 @@ bool Bot::LookupEnemy(void)
185
186
186
187
int i;
187
188
edict_t * entity = nullptr , * targetEntity = nullptr ;
188
- float enemy_distance = 9999 . 0f ;
189
+ float enemy_distance = FLT_MAX ;
189
190
edict_t * oneTimeCheckEntity = nullptr ;
190
191
191
192
if (!FNullEnt (m_lastEnemy))
@@ -256,8 +257,6 @@ bool Bot::LookupEnemy(void)
256
257
SetMoveTarget (targetEntity);
257
258
return false ;
258
259
}
259
-
260
- oneTimeCheckEntity = targetEntity;
261
260
}
262
261
else
263
262
{
@@ -297,7 +296,7 @@ bool Bot::LookupEnemy(void)
297
296
if (m_currentWaypointIndex != GetEntityWaypoint (targetEntity))
298
297
{
299
298
const float distance = GetEntityDistance (m_moveTargetEntity);
300
- if (distance <= enemy_distance + 400 .0f )
299
+ if (distance <= SquaredF ( enemy_distance + 400 .0f ) )
301
300
{
302
301
const int targetWpIndex = GetEntityWaypoint (targetEntity);
303
302
bool shortDistance = false ;
@@ -324,12 +323,8 @@ bool Bot::LookupEnemy(void)
324
323
}
325
324
326
325
// last checking
327
- if (!FNullEnt (targetEntity))
328
- {
329
- enemy_distance = GetEntityDistance (targetEntity);
330
- if (!IsEnemyViewable (targetEntity, true , true ))
331
- targetEntity = nullptr ;
332
- }
326
+ if (!FNullEnt (targetEntity) && !IsEnemyViewable (targetEntity, true , true ))
327
+ targetEntity = nullptr ;
333
328
334
329
if (!FNullEnt (m_enemy) && FNullEnt (targetEntity))
335
330
{
@@ -367,8 +362,7 @@ bool Bot::LookupEnemy(void)
367
362
while (srcIndex != destIndex && movePoint <= 3 && srcIndex >= 0 && destIndex >= 0 )
368
363
{
369
364
path = g_waypoint->GetPath (srcIndex);
370
- srcIndex = *(g_waypoint->m_pathMatrix + (srcIndex * g_numWaypoints) + destIndex);
371
- if (srcIndex < 0 )
365
+ if (!IsValidWaypoint (srcIndex))
372
366
continue ;
373
367
374
368
movePoint++;
@@ -384,9 +378,8 @@ bool Bot::LookupEnemy(void)
384
378
}
385
379
}
386
380
387
- enemy_distance = (GetEntityOrigin (targetEntity) - pev->origin ).GetLength ();
388
- if ((enemy_distance <= 150 .0f && movePoint <= 1 ) ||
389
- (targetEntity == m_moveTargetEntity && movePoint <= 2 ))
381
+ enemy_distance = (GetEntityOrigin (targetEntity) - pev->origin ).GetLengthSquared ();
382
+ if ((enemy_distance <= SquaredF (150 .0f ) && movePoint <= 1 ) || (targetEntity == m_moveTargetEntity && movePoint <= 2 ))
390
383
{
391
384
moveTotarget = false ;
392
385
if (targetEntity == m_moveTargetEntity && movePoint <= 1 )
@@ -620,7 +613,7 @@ bool Bot::IsShootableThruObstacle(edict_t* entity)
620
613
TraceLine (dest, source, true , GetEntity (), &tr);
621
614
if (tr.flFraction != 1 .0f )
622
615
{
623
- if ((tr.vecEndPos - dest).GetLength () > 800 .0f )
616
+ if ((tr.vecEndPos - dest).GetLengthSquared () > SquaredF ( 800 .0f ) )
624
617
return false ;
625
618
626
619
if (tr.vecEndPos .z >= dest.z + 200 .0f )
@@ -629,17 +622,17 @@ bool Bot::IsShootableThruObstacle(edict_t* entity)
629
622
if (dest.z >= tr.vecEndPos .z + 200 .0f )
630
623
return false ;
631
624
632
- obstacleDistance = (tr.vecEndPos - source).GetLength ();
625
+ obstacleDistance = (tr.vecEndPos - source).GetLengthSquared ();
633
626
}
634
627
}
635
628
636
- if (obstacleDistance > 0.0 )
629
+ if (obstacleDistance > 0 .0f )
637
630
{
638
- while (currentWeaponPenetrationPower > 0 )
631
+ while (currentWeaponPenetrationPower > 0 . 0f )
639
632
{
640
- if (obstacleDistance > 75.0 )
633
+ if (obstacleDistance > SquaredF ( 75 .0f ) )
641
634
{
642
- obstacleDistance -= 75 .0f ;
635
+ obstacleDistance -= SquaredF ( 75 .0f ) ;
643
636
currentWeaponPenetrationPower--;
644
637
continue ;
645
638
}
@@ -691,10 +684,9 @@ bool Bot::DoFirePause(float distance)//, FireDelay *fireDelay)
691
684
return false ;
692
685
}
693
686
694
-
687
+ // this function will return true if weapon was fired, false otherwise
695
688
void Bot::FireWeapon (void )
696
689
{
697
- // this function will return true if weapon was fired, false otherwise
698
690
float distance = (m_lookAt - EyePosition ()).GetLength (); // how far away is the enemy?
699
691
700
692
// if using grenade stop this
@@ -932,22 +924,22 @@ void Bot::FireWeapon(void)
932
924
bool Bot::KnifeAttack (float attackDistance)
933
925
{
934
926
edict_t * entity = nullptr ;
935
- float distance = 9999 . 0f ;
927
+ float distance = FLT_MAX ;
936
928
if (!FNullEnt (m_enemy))
937
929
{
938
930
entity = m_enemy;
939
- distance = (pev->origin - GetEntityOrigin (m_enemy)).GetLength ();
931
+ distance = (pev->origin - GetEntityOrigin (m_enemy)).GetLengthSquared ();
940
932
}
941
933
942
934
if (!FNullEnt (m_breakableEntity))
943
935
{
944
936
if (m_breakable == nullvec)
945
937
m_breakable = GetEntityOrigin (m_breakableEntity);
946
938
947
- if ((pev->origin - m_breakable).GetLength () < distance)
939
+ if ((pev->origin - m_breakable).GetLengthSquared () < distance)
948
940
{
949
941
entity = m_breakableEntity;
950
- distance = (pev->origin - m_breakable).GetLength ();
942
+ distance = (pev->origin - m_breakable).GetLengthSquared ();
951
943
}
952
944
}
953
945
@@ -1043,12 +1035,12 @@ bool Bot::IsWeaponBadInDistance(int weaponIndex, float distance)
1043
1035
}
1044
1036
1045
1037
// shotguns is too inaccurate at long distances, so weapon is bad
1046
- if ((weaponID == WEAPON_M3 || weaponID == WEAPON_XM1014) && distance > 750 .0f )
1038
+ if ((weaponID == WEAPON_M3 || weaponID == WEAPON_XM1014) && distance > 768 .0f )
1047
1039
return true ;
1048
1040
1049
- if (GetGameMode () == MODE_BASE )
1041
+ if (! IsZombieMode () )
1050
1042
{
1051
- if ((weaponID == WEAPON_SCOUT || weaponID == WEAPON_AWP || weaponID == WEAPON_G3SG1 || weaponID == WEAPON_SG550) && distance < 300 .0f )
1043
+ if ((weaponID == WEAPON_SCOUT || weaponID == WEAPON_AWP || weaponID == WEAPON_G3SG1 || weaponID == WEAPON_SG550) && distance <= 384 .0f )
1052
1044
return true ;
1053
1045
}
1054
1046
@@ -1149,7 +1141,8 @@ void Bot::CombatFight(void)
1149
1141
}
1150
1142
1151
1143
pev->button |= IN_ATTACK;
1152
- m_destOrigin = m_enemyOrigin + m_enemy->v .velocity ;
1144
+
1145
+ m_destOrigin = m_enemyOrigin + m_enemy->v .velocity * ebot_zombie_speed_factor.GetFloat ();
1153
1146
if (!(pev->flags & FL_DUCKING))
1154
1147
m_waypointOrigin = m_destOrigin;
1155
1148
}
@@ -1162,24 +1155,25 @@ void Bot::CombatFight(void)
1162
1155
1163
1156
const bool NPCEnemy = !IsValidPlayer (m_enemy);
1164
1157
const bool enemyIsZombie = IsZombieEntity (m_enemy);
1165
- float baseDistance = ebot_zp_escape_distance.GetFloat ();
1158
+ float baseDistance = SquaredF (ebot_zp_escape_distance.GetFloat ());
1159
+ Vector myVec = pev->origin + pev->velocity * m_frameInterval;
1166
1160
1167
1161
if (NPCEnemy || enemyIsZombie)
1168
1162
{
1169
1163
if (m_currentWeapon == WEAPON_KNIFE)
1170
1164
{
1171
- if (!(::IsInViewCone (pev-> origin , m_enemy) && !NPCEnemy))
1165
+ if (!(::IsInViewCone (myVec , m_enemy) && !NPCEnemy))
1172
1166
baseDistance = -1 .0f ;
1173
1167
}
1174
1168
1175
1169
const Vector speedFactor = m_enemyOrigin + m_enemy->v .velocity * ebot_zombie_speed_factor.GetFloat ();
1176
1170
1177
- const float distance = (pev-> origin - speedFactor).GetLength ();
1178
- if (m_isSlowThink && distance <= 768 .0f && m_enemy->v .health > 100 && ChanceOf (ebot_zp_use_grenade_percent.GetInt ()))
1171
+ const float distance = (myVec - speedFactor).GetLengthSquared ();
1172
+ if (m_isSlowThink && distance <= SquaredF ( 768 .0f ) && m_enemy->v .health > 100 && ChanceOf (ebot_zp_use_grenade_percent.GetInt ()) && m_enemy-> v . velocity . GetLengthSquared () > SquaredF ( 10 . 0f ))
1179
1173
{
1180
1174
if (m_skill >= 50 )
1181
1175
{
1182
- if (pev->weapons & (1 << WEAPON_FBGRENADE) && (m_enemy->v .speed >= m_enemy->v .maxspeed || distance <= 384 .0f ))
1176
+ if (pev->weapons & (1 << WEAPON_FBGRENADE) && (m_enemy->v .speed >= m_enemy->v .maxspeed || distance <= SquaredF ( 384 .0f ) ))
1183
1177
ThrowFrostNade ();
1184
1178
else
1185
1179
ThrowFireNade ();
@@ -1277,8 +1271,8 @@ void Bot::CombatFight(void)
1277
1271
SetLastEnemy (m_enemy);
1278
1272
m_destOrigin = m_enemyOrigin - m_lastWallOrigin;
1279
1273
1280
- float distance = (pev->origin - m_lookAt).GetLength (); // how far away is the enemy scum?
1281
- if (m_currentWeapon != WEAPON_KNIFE && distance <= 256 .0f ) // get back!
1274
+ float distance = (( pev->origin + pev-> velocity * m_frameInterval) - m_lookAt).GetLengthSquared (); // how far away is the enemy scum?
1275
+ if (m_currentWeapon != WEAPON_KNIFE && distance <= SquaredF ( 256 .0f ) ) // get back!
1282
1276
{
1283
1277
m_moveSpeed = -pev->maxspeed ;
1284
1278
return ;
@@ -1325,9 +1319,9 @@ void Bot::CombatFight(void)
1325
1319
{
1326
1320
if (ChanceOf (75 ))
1327
1321
{
1328
- if (distance < 768 .0f )
1322
+ if (distance < SquaredF ( 768 .0f ) )
1329
1323
m_fightStyle = 0 ;
1330
- else if (distance < 1024 .0f )
1324
+ else if (distance < SquaredF ( 1024 .0f ) )
1331
1325
{
1332
1326
if (ChanceOf (UsesSubmachineGun () ? 50 : 30 ))
1333
1327
m_fightStyle = 0 ;
@@ -1362,7 +1356,7 @@ void Bot::CombatFight(void)
1362
1356
}
1363
1357
}
1364
1358
1365
- if (m_fightStyle == 0 || ((pev->button & IN_RELOAD) || m_isReloading) || (UsesPistol () && distance < 768 .0f ) || m_currentWeapon == WEAPON_KNIFE)
1359
+ if (m_fightStyle == 0 || ((pev->button & IN_RELOAD) || m_isReloading) || (UsesPistol () && distance < SquaredF ( 768 .0f ) ) || m_currentWeapon == WEAPON_KNIFE)
1366
1360
{
1367
1361
if (m_strafeSetTime < engine->GetTime ())
1368
1362
{
@@ -1407,7 +1401,7 @@ void Bot::CombatFight(void)
1407
1401
if (m_jumpTime + 10 .0f < engine->GetTime () && !IsOnLadder () && ChanceOf (m_isReloading ? 5 : 2 ) && pev->velocity .GetLength2D () > float (m_skill + 50 .0f ) && !UsesSniper ())
1408
1402
pev->button |= IN_JUMP;
1409
1403
1410
- if (m_moveSpeed > 0 .0f && distance > 512 .0f && m_currentWeapon != WEAPON_KNIFE)
1404
+ if (m_moveSpeed > 0 .0f && distance > SquaredF ( 512 .0f ) && m_currentWeapon != WEAPON_KNIFE)
1411
1405
m_moveSpeed = 0 .0f ;
1412
1406
1413
1407
if (m_currentWeapon == WEAPON_KNIFE)
@@ -1593,6 +1587,15 @@ void Bot::SelectBestWeapon(void)
1593
1587
if (!m_isSlowThink)
1594
1588
return ;
1595
1589
1590
+ if (GetCurrentTask ()->taskID == TASK_THROWHEGRENADE)
1591
+ return ;
1592
+
1593
+ if (GetCurrentTask ()->taskID == TASK_THROWFBGRENADE)
1594
+ return ;
1595
+
1596
+ if (GetCurrentTask ()->taskID == TASK_THROWSMGRENADE)
1597
+ return ;
1598
+
1596
1599
if (ebot_sb_mode.GetBool ())
1597
1600
{
1598
1601
if (m_currentWeapon != WEAPON_HEGRENADE && m_currentWeapon != WEAPON_FBGRENADE && m_currentWeapon != WEAPON_SMGRENADE)
@@ -1612,15 +1615,6 @@ void Bot::SelectBestWeapon(void)
1612
1615
if (FNullEnt (m_enemy) && m_isReloading)
1613
1616
return ;
1614
1617
1615
- if (GetCurrentTask ()->taskID == TASK_THROWHEGRENADE)
1616
- return ;
1617
-
1618
- if (GetCurrentTask ()->taskID == TASK_THROWFBGRENADE)
1619
- return ;
1620
-
1621
- if (GetCurrentTask ()->taskID == TASK_THROWSMGRENADE)
1622
- return ;
1623
-
1624
1618
if (!IsZombieMode ())
1625
1619
{
1626
1620
if (m_numEnemiesLeft == 0 )
@@ -1629,7 +1623,7 @@ void Bot::SelectBestWeapon(void)
1629
1623
return ;
1630
1624
}
1631
1625
1632
- if (!FNullEnt (m_enemy) && GetCurrentTask ()->taskID == TASK_FIGHTENEMY && (pev->origin - GetEntityOrigin (m_enemy)).GetLength () <= 128 .0f )
1626
+ if (!FNullEnt (m_enemy) && GetCurrentTask ()->taskID == TASK_FIGHTENEMY && (pev->origin - GetEntityOrigin (m_enemy)).GetLengthSquared () <= SquaredF ( 128 .0f ) )
1633
1627
{
1634
1628
SelectWeaponByName (" weapon_knife" );
1635
1629
return ;
@@ -1785,7 +1779,7 @@ bool Bot::IsGroupOfEnemies(Vector location, int numEnemies, int radius)
1785
1779
if (!(client.flags & CFLAG_USED) || !(client.flags & CFLAG_ALIVE) || client.ent == GetEntity ())
1786
1780
continue ;
1787
1781
1788
- if ((GetEntityOrigin (client.ent ) - location).GetLength () < radius)
1782
+ if ((GetEntityOrigin (client.ent ) - location).GetLengthSquared () < ( radius * radius) )
1789
1783
{
1790
1784
// don't target our teammates...
1791
1785
if (client.team == m_team)
0 commit comments