Skip to content

Commit 299a71c

Browse files
authored
Add files via upload
1 parent 356abdb commit 299a71c

File tree

8 files changed

+571
-938
lines changed

8 files changed

+571
-938
lines changed

source/basecode.cpp

Lines changed: 207 additions & 212 deletions
Large diffs are not rendered by default.

source/combat.cpp

Lines changed: 58 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
ConVar ebot_escape("ebot_zombie_escape_mode", "0");
2828
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");
3131
ConVar ebot_sb_mode("ebot_sb_mode", "0");
3232

3333
int Bot::GetNearbyFriendsNearPosition(Vector origin, int radius)
@@ -41,7 +41,7 @@ int Bot::GetNearbyFriendsNearPosition(Vector origin, int radius)
4141
if (!(client.flags & CFLAG_USED) || !(client.flags & CFLAG_ALIVE) || client.team != m_team || client.ent == GetEntity())
4242
continue;
4343

44-
if ((client.origin - origin).GetLength() <= radius)
44+
if ((client.origin - origin).GetLengthSquared() <= radius * radius)
4545
count++;
4646
}
4747

@@ -56,7 +56,7 @@ int Bot::GetNearbyEnemiesNearPosition(Vector origin, int radius)
5656
if (!(client.flags & CFLAG_USED) || !(client.flags & CFLAG_ALIVE) || client.team == m_team)
5757
continue;
5858

59-
if ((client.origin - origin).GetLength() <= radius)
59+
if ((client.origin - origin).GetLengthSquared() <= radius * radius)
6060
count++;
6161
}
6262

@@ -71,10 +71,10 @@ void Bot::ResetCheckEnemy()
7171
for (i = 0; i < checkEnemyNum; i++)
7272
{
7373
m_allEnemy[i] = nullptr;
74-
m_allEnemyDistance[i] = 9999.9f;
74+
m_allEnemyDistance[i] = FLT_MAX;
7575

7676
m_checkEnemy[i] = nullptr;
77-
m_checkEnemyDistance[i] = 9999.9f;
77+
m_checkEnemyDistance[i] = FLT_MAX;
7878
}
7979

8080
for (i = 1; i <= engine->GetMaxClients(); i++)
@@ -111,7 +111,8 @@ void Bot::ResetCheckEnemy()
111111

112112
if (m_allEnemyDistance[i] == m_checkEnemyDistance[y])
113113
{
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())
115116
continue;
116117
}
117118

@@ -135,10 +136,10 @@ void Bot::ResetCheckEnemy()
135136
float Bot::GetEntityDistance(edict_t* entity)
136137
{
137138
if (FNullEnt(entity))
138-
return 9999.0f;
139+
return FLT_MAX;
139140

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))
142143
return distance;
143144

144145
int srcIndex, destIndex;
@@ -153,7 +154,7 @@ float Bot::GetEntityDistance(edict_t* entity)
153154
destIndex = m_currentWaypointIndex;
154155
}
155156

156-
if (!IsValidWaypoint(srcIndex) || !IsValidWaypoint(destIndex < 0) || srcIndex == destIndex)
157+
if (!IsValidWaypoint(srcIndex) || !IsValidWaypoint(destIndex) || srcIndex == destIndex)
157158
return distance;
158159

159160
Path* path = g_waypoint->GetPath(srcIndex);
@@ -185,7 +186,7 @@ bool Bot::LookupEnemy(void)
185186

186187
int i;
187188
edict_t* entity = nullptr, * targetEntity = nullptr;
188-
float enemy_distance = 9999.0f;
189+
float enemy_distance = FLT_MAX;
189190
edict_t* oneTimeCheckEntity = nullptr;
190191

191192
if (!FNullEnt(m_lastEnemy))
@@ -256,8 +257,6 @@ bool Bot::LookupEnemy(void)
256257
SetMoveTarget(targetEntity);
257258
return false;
258259
}
259-
260-
oneTimeCheckEntity = targetEntity;
261260
}
262261
else
263262
{
@@ -297,7 +296,7 @@ bool Bot::LookupEnemy(void)
297296
if (m_currentWaypointIndex != GetEntityWaypoint(targetEntity))
298297
{
299298
const float distance = GetEntityDistance(m_moveTargetEntity);
300-
if (distance <= enemy_distance + 400.0f)
299+
if (distance <= SquaredF(enemy_distance + 400.0f))
301300
{
302301
const int targetWpIndex = GetEntityWaypoint(targetEntity);
303302
bool shortDistance = false;
@@ -324,12 +323,8 @@ bool Bot::LookupEnemy(void)
324323
}
325324

326325
// 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;
333328

334329
if (!FNullEnt(m_enemy) && FNullEnt(targetEntity))
335330
{
@@ -367,8 +362,7 @@ bool Bot::LookupEnemy(void)
367362
while (srcIndex != destIndex && movePoint <= 3 && srcIndex >= 0 && destIndex >= 0)
368363
{
369364
path = g_waypoint->GetPath(srcIndex);
370-
srcIndex = *(g_waypoint->m_pathMatrix + (srcIndex * g_numWaypoints) + destIndex);
371-
if (srcIndex < 0)
365+
if (!IsValidWaypoint(srcIndex))
372366
continue;
373367

374368
movePoint++;
@@ -384,9 +378,8 @@ bool Bot::LookupEnemy(void)
384378
}
385379
}
386380

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))
390383
{
391384
moveTotarget = false;
392385
if (targetEntity == m_moveTargetEntity && movePoint <= 1)
@@ -620,7 +613,7 @@ bool Bot::IsShootableThruObstacle(edict_t* entity)
620613
TraceLine(dest, source, true, GetEntity(), &tr);
621614
if (tr.flFraction != 1.0f)
622615
{
623-
if ((tr.vecEndPos - dest).GetLength() > 800.0f)
616+
if ((tr.vecEndPos - dest).GetLengthSquared() > SquaredF(800.0f))
624617
return false;
625618

626619
if (tr.vecEndPos.z >= dest.z + 200.0f)
@@ -629,17 +622,17 @@ bool Bot::IsShootableThruObstacle(edict_t* entity)
629622
if (dest.z >= tr.vecEndPos.z + 200.0f)
630623
return false;
631624

632-
obstacleDistance = (tr.vecEndPos - source).GetLength();
625+
obstacleDistance = (tr.vecEndPos - source).GetLengthSquared();
633626
}
634627
}
635628

636-
if (obstacleDistance > 0.0)
629+
if (obstacleDistance > 0.0f)
637630
{
638-
while (currentWeaponPenetrationPower > 0)
631+
while (currentWeaponPenetrationPower > 0.0f)
639632
{
640-
if (obstacleDistance > 75.0)
633+
if (obstacleDistance > SquaredF(75.0f))
641634
{
642-
obstacleDistance -= 75.0f;
635+
obstacleDistance -= SquaredF(75.0f);
643636
currentWeaponPenetrationPower--;
644637
continue;
645638
}
@@ -691,10 +684,9 @@ bool Bot::DoFirePause(float distance)//, FireDelay *fireDelay)
691684
return false;
692685
}
693686

694-
687+
// this function will return true if weapon was fired, false otherwise
695688
void Bot::FireWeapon(void)
696689
{
697-
// this function will return true if weapon was fired, false otherwise
698690
float distance = (m_lookAt - EyePosition()).GetLength(); // how far away is the enemy?
699691

700692
// if using grenade stop this
@@ -932,22 +924,22 @@ void Bot::FireWeapon(void)
932924
bool Bot::KnifeAttack(float attackDistance)
933925
{
934926
edict_t* entity = nullptr;
935-
float distance = 9999.0f;
927+
float distance = FLT_MAX;
936928
if (!FNullEnt(m_enemy))
937929
{
938930
entity = m_enemy;
939-
distance = (pev->origin - GetEntityOrigin(m_enemy)).GetLength();
931+
distance = (pev->origin - GetEntityOrigin(m_enemy)).GetLengthSquared();
940932
}
941933

942934
if (!FNullEnt(m_breakableEntity))
943935
{
944936
if (m_breakable == nullvec)
945937
m_breakable = GetEntityOrigin(m_breakableEntity);
946938

947-
if ((pev->origin - m_breakable).GetLength() < distance)
939+
if ((pev->origin - m_breakable).GetLengthSquared() < distance)
948940
{
949941
entity = m_breakableEntity;
950-
distance = (pev->origin - m_breakable).GetLength();
942+
distance = (pev->origin - m_breakable).GetLengthSquared();
951943
}
952944
}
953945

@@ -1043,12 +1035,12 @@ bool Bot::IsWeaponBadInDistance(int weaponIndex, float distance)
10431035
}
10441036

10451037
// 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)
10471039
return true;
10481040

1049-
if (GetGameMode() == MODE_BASE)
1041+
if (!IsZombieMode())
10501042
{
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)
10521044
return true;
10531045
}
10541046

@@ -1149,7 +1141,8 @@ void Bot::CombatFight(void)
11491141
}
11501142

11511143
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();
11531146
if (!(pev->flags & FL_DUCKING))
11541147
m_waypointOrigin = m_destOrigin;
11551148
}
@@ -1162,24 +1155,25 @@ void Bot::CombatFight(void)
11621155

11631156
const bool NPCEnemy = !IsValidPlayer(m_enemy);
11641157
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;
11661160

11671161
if (NPCEnemy || enemyIsZombie)
11681162
{
11691163
if (m_currentWeapon == WEAPON_KNIFE)
11701164
{
1171-
if (!(::IsInViewCone(pev->origin, m_enemy) && !NPCEnemy))
1165+
if (!(::IsInViewCone(myVec, m_enemy) && !NPCEnemy))
11721166
baseDistance = -1.0f;
11731167
}
11741168

11751169
const Vector speedFactor = m_enemyOrigin + m_enemy->v.velocity * ebot_zombie_speed_factor.GetFloat();
11761170

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))
11791173
{
11801174
if (m_skill >= 50)
11811175
{
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)))
11831177
ThrowFrostNade();
11841178
else
11851179
ThrowFireNade();
@@ -1277,8 +1271,8 @@ void Bot::CombatFight(void)
12771271
SetLastEnemy(m_enemy);
12781272
m_destOrigin = m_enemyOrigin - m_lastWallOrigin;
12791273

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!
12821276
{
12831277
m_moveSpeed = -pev->maxspeed;
12841278
return;
@@ -1325,9 +1319,9 @@ void Bot::CombatFight(void)
13251319
{
13261320
if (ChanceOf(75))
13271321
{
1328-
if (distance < 768.0f)
1322+
if (distance < SquaredF(768.0f))
13291323
m_fightStyle = 0;
1330-
else if (distance < 1024.0f)
1324+
else if (distance < SquaredF(1024.0f))
13311325
{
13321326
if (ChanceOf(UsesSubmachineGun() ? 50 : 30))
13331327
m_fightStyle = 0;
@@ -1362,7 +1356,7 @@ void Bot::CombatFight(void)
13621356
}
13631357
}
13641358

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)
13661360
{
13671361
if (m_strafeSetTime < engine->GetTime())
13681362
{
@@ -1407,7 +1401,7 @@ void Bot::CombatFight(void)
14071401
if (m_jumpTime + 10.0f < engine->GetTime() && !IsOnLadder() && ChanceOf(m_isReloading ? 5 : 2) && pev->velocity.GetLength2D() > float(m_skill + 50.0f) && !UsesSniper())
14081402
pev->button |= IN_JUMP;
14091403

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)
14111405
m_moveSpeed = 0.0f;
14121406

14131407
if (m_currentWeapon == WEAPON_KNIFE)
@@ -1593,6 +1587,15 @@ void Bot::SelectBestWeapon(void)
15931587
if (!m_isSlowThink)
15941588
return;
15951589

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+
15961599
if (ebot_sb_mode.GetBool())
15971600
{
15981601
if (m_currentWeapon != WEAPON_HEGRENADE && m_currentWeapon != WEAPON_FBGRENADE && m_currentWeapon != WEAPON_SMGRENADE)
@@ -1612,15 +1615,6 @@ void Bot::SelectBestWeapon(void)
16121615
if (FNullEnt(m_enemy) && m_isReloading)
16131616
return;
16141617

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-
16241618
if (!IsZombieMode())
16251619
{
16261620
if (m_numEnemiesLeft == 0)
@@ -1629,7 +1623,7 @@ void Bot::SelectBestWeapon(void)
16291623
return;
16301624
}
16311625

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))
16331627
{
16341628
SelectWeaponByName("weapon_knife");
16351629
return;
@@ -1785,7 +1779,7 @@ bool Bot::IsGroupOfEnemies(Vector location, int numEnemies, int radius)
17851779
if (!(client.flags & CFLAG_USED) || !(client.flags & CFLAG_ALIVE) || client.ent == GetEntity())
17861780
continue;
17871781

1788-
if ((GetEntityOrigin(client.ent) - location).GetLength() < radius)
1782+
if ((GetEntityOrigin(client.ent) - location).GetLengthSquared() < (radius * radius))
17891783
{
17901784
// don't target our teammates...
17911785
if (client.team == m_team)

0 commit comments

Comments
 (0)