Skip to content

Commit fd6f66c

Browse files
authored
Add files via upload
1 parent 82e1480 commit fd6f66c

File tree

8 files changed

+85
-65
lines changed

8 files changed

+85
-65
lines changed

source/basecode.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,13 @@ void Bot::PushMessageQueue(int message)
6363
if (message == CMENU_SAY)
6464
{
6565
// notify other bots of the spoken text otherwise, bots won't respond to other bots (network messages aren't sent from bots)
66-
int entityIndex = GetIndex();
67-
6866
for (const auto& bot : g_botManager->m_bots)
6967
{
7068
if (bot != nullptr && bot != this)
7169
{
7270
if (m_isAlive == bot->m_isAlive)
7371
{
74-
bot->m_sayTextBuffer.entityIndex = entityIndex;
72+
bot->m_sayTextBuffer.entityIndex = m_index;
7573
strcpy(bot->m_sayTextBuffer.sayText, m_tempStrings);
7674
}
7775
}
@@ -1038,7 +1036,7 @@ void Bot::SwitchChatterIcon(bool show)
10381036

10391037
MESSAGE_BEGIN(MSG_ONE, g_netMsg->GetId(NETMSG_BOTVOICE), nullptr, client.ent); // begin message
10401038
WRITE_BYTE(show); // switch on/off
1041-
WRITE_BYTE(GetIndex());
1039+
WRITE_BYTE(m_index);
10421040
MESSAGE_END();
10431041
}
10441042
}
@@ -1117,7 +1115,7 @@ void Bot::PlayChatterMessage(ChatterMessage message)
11171115
continue;
11181116

11191117
MESSAGE_BEGIN(MSG_ONE, g_netMsg->GetId(NETMSG_SENDAUDIO), nullptr, client.ent); // begin message
1120-
WRITE_BYTE(GetIndex());
1118+
WRITE_BYTE(m_index);
11211119

11221120
if (!(pev->deadflag & DEAD_DEAD))
11231121
WRITE_STRING(FormatBuffer("%s/%s.wav", ebot_chatter_path.GetString(), voice));
@@ -1927,7 +1925,7 @@ void Bot::SetConditions(void)
19271925
// FIXME: it probably should be also team/map dependant
19281926
if (FNullEnt(m_enemy) && (g_timeRoundMid < engine->GetTime()) && !m_isUsingGrenade && m_personality != PERSONALITY_CAREFUL && m_currentWaypointIndex != g_waypoint->FindNearest(m_lastEnemyOrigin))
19291927
{
1930-
desireLevel = 4096.0f - ((1.0f - tempAgression) * Q_rsqrt(distance));
1928+
desireLevel = 4096.0f - ((1.0f - tempAgression) * Q_sqrt(distance));
19311929
desireLevel = (100 * desireLevel) / 4096.0f;
19321930
desireLevel -= retreatLevel;
19331931

@@ -3738,6 +3736,7 @@ void Bot::Think(void)
37383736
m_isZombieBot = IsZombieEntity(GetEntity());
37393737
m_team = GetTeam(GetEntity());
37403738
m_isAlive = IsAlive(GetEntity());
3739+
m_index = GetIndex();
37413740
m_isBomber = pev->weapons & (1 << WEAPON_C4);
37423741

37433742
if (m_isZombieBot)
@@ -4771,13 +4770,13 @@ void Bot::RunTask(void)
47714770
m_myMeshWaypoint = myCampPoint;
47724771
MeshWaypoints.RemoveAll();
47734772

4774-
float max = 10.0f;
4773+
float max = 12.0f;
47754774
if (!FNullEnt(m_enemy))
47764775
{
47774776
if (m_personality == PERSONALITY_RUSHER)
4778-
max = 20.0f;
4777+
max = 16.0f;
47794778
else if (m_personality != PERSONALITY_CAREFUL)
4780-
max = 15.0f;
4779+
max = 8.0f;
47814780
}
47824781

47834782
GetCurrentTask()->time = engine->GetTime() + engine->RandomFloat(4.0f, max);
@@ -5064,7 +5063,7 @@ void Bot::RunTask(void)
50645063

50655064
RadioMessage(Radio_SectorClear);
50665065
}
5067-
else if (!FNullEnt(m_enemy) && m_numEnemiesLeft > 0)
5066+
else if (m_numEnemiesLeft > 0 && !FNullEnt(m_enemy))
50685067
{
50695068
const int friends = m_numFriendsLeft > 0 ? GetNearbyFriendsNearPosition(pev->origin, 768.0f) : 0;
50705069
if (friends < 2 && defuseRemainingTime < timeToBlowUp)
@@ -5331,7 +5330,7 @@ void Bot::RunTask(void)
53315330
m_moveToGoal = false;
53325331
}
53335332
else if (!FNullEnt(m_enemy) || m_enemyOrigin != nullvec)
5334-
destination = m_enemyOrigin + (m_enemy->v.velocity.SkipZ() * 0.5f);
5333+
destination = m_enemyOrigin + (m_enemy->v.velocity.SkipZ() * 0.54f);
53355334
else
53365335
m_enemy = m_lastEnemy;
53375336

@@ -5440,7 +5439,7 @@ void Bot::RunTask(void)
54405439
m_moveToGoal = false;
54415440
}
54425441
else if (!FNullEnt(m_enemy) || m_enemyOrigin != nullvec)
5443-
destination = m_enemyOrigin + (m_enemy->v.velocity.SkipZ() * 0.5f);
5442+
destination = m_enemyOrigin + (m_enemy->v.velocity.SkipZ() * 0.54f);
54445443
else
54455444
m_enemy = m_lastEnemy;
54465445

@@ -5517,9 +5516,9 @@ void Bot::RunTask(void)
55175516

55185517
src = m_lastEnemyOrigin - pev->velocity;
55195518

5520-
// predict where the enemy is in 0.5 secs
5519+
// predict where the enemy is in 0.54 secs
55215520
if (!FNullEnt(m_enemy))
5522-
src = src + m_enemy->v.velocity * 0.5f;
5521+
src += m_enemy->v.velocity * 0.54f;
55235522

55245523
m_grenade = (src - EyePosition()).Normalize();
55255524

@@ -5569,7 +5568,7 @@ void Bot::RunTask(void)
55695568
m_moveToGoal = false;
55705569
}
55715570
else if (!FNullEnt(m_enemy) || m_enemyOrigin != nullvec)
5572-
destination = m_enemyOrigin + (m_enemy->v.velocity.SkipZ() * 0.5f);
5571+
destination = m_enemyOrigin + (m_enemy->v.velocity.SkipZ() * 0.54f);
55735572

55745573
m_isUsingGrenade = true;
55755574
m_checkTerrain = false;
@@ -6423,7 +6422,7 @@ void Bot::BotAI(void)
64236422

64246423
if (!IsOnLadder())
64256424
{
6426-
if (!FNullEnt(m_enemy) && m_isEnemyReachable)
6425+
if (m_isEnemyReachable && !FNullEnt(m_enemy))
64276426
{
64286427
m_moveToGoal = false; // don't move to goal
64296428
m_navTimeset = engine->GetTime();
@@ -7212,8 +7211,8 @@ Vector Bot::CheckToss(const Vector& start, Vector end)
72127211
if ((midPoint.z < start.z) || (midPoint.z < end.z))
72137212
return nullvec;
72147213

7215-
float timeOne = Q_rsqrt((midPoint.z - start.z) / (0.5f * gravity));
7216-
float timeTwo = Q_rsqrt((midPoint.z - end.z) / (0.5f * gravity));
7214+
float timeOne = Q_sqrt((midPoint.z - start.z) / (0.54f * gravity));
7215+
float timeTwo = Q_sqrt((midPoint.z - end.z) / (0.54f * gravity));
72177216

72187217
if (timeOne < 0.1)
72197218
return nullvec;
@@ -7560,7 +7559,7 @@ void Bot::ReactOnSound(void)
75607559
if (!FNullEnt(m_enemy))
75617560
return;
75627561

7563-
if (g_clients[GetIndex()].timeSoundLasting <= engine->GetTime())
7562+
if (g_clients[m_index].timeSoundLasting <= engine->GetTime())
75647563
return;
75657564

75667565
edict_t* player = nullptr;

source/chatlib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ void Bot::ChatSay(bool teamSay, const char* text, ...)
478478
m_lastChatEnt = GetEntity();
479479

480480
MESSAGE_BEGIN(MSG_ONE, g_netMsg->GetId(NETMSG_SAYTEXT), nullptr, client.ent);
481-
WRITE_BYTE(GetIndex());
481+
WRITE_BYTE(m_index);
482482
WRITE_STRING(tempMessage);
483483
MESSAGE_END();
484484
}

source/combat.cpp

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ bool Bot::LookupEnemy(void)
158158
return false;
159159

160160
int i;
161-
edict_t* entity = nullptr, * targetEntity = nullptr;
161+
edict_t* entity = nullptr;
162+
edict_t* targetEntity = nullptr;
162163
float enemy_distance = FLT_MAX;
163164
edict_t* oneTimeCheckEntity = nullptr;
164165

@@ -196,11 +197,12 @@ bool Bot::LookupEnemy(void)
196197
}
197198
else if (!FNullEnt(m_moveTargetEntity))
198199
{
199-
if (m_team == GetTeam(m_moveTargetEntity) || !IsAlive(m_moveTargetEntity) || GetEntityOrigin(m_moveTargetEntity) == nullvec)
200+
auto origin = GetEntityOrigin(m_moveTargetEntity);
201+
if (m_team == GetTeam(m_moveTargetEntity) || !IsAlive(m_moveTargetEntity) || origin == nullvec)
200202
SetMoveTarget(nullptr);
201203

202204
targetEntity = m_moveTargetEntity;
203-
enemy_distance = (pev->origin - GetEntityOrigin(m_moveTargetEntity)).GetLengthSquared();
205+
enemy_distance = (pev->origin - origin).GetLengthSquared();
204206
}
205207

206208
ResetCheckEnemy();
@@ -506,9 +508,8 @@ bool Bot::IsFriendInLineOfFire(float distance)
506508
MakeVectors(pev->v_angle);
507509

508510
TraceResult tr;
509-
TraceLine(EyePosition(), EyePosition() + pev->v_angle.Normalize() * distance, false, false, GetEntity(), &tr);
511+
TraceLine(EyePosition(), EyePosition() + distance * pev->v_angle.Normalize(), false, false, GetEntity(), &tr);
510512

511-
int i;
512513
if (!FNullEnt(tr.pHit))
513514
{
514515
if (IsAlive(tr.pHit) && m_team == GetTeam(tr.pHit))
@@ -517,7 +518,7 @@ bool Bot::IsFriendInLineOfFire(float distance)
517518
return true;
518519

519520
int entityIndex = ENTINDEX(tr.pHit);
520-
for (i = 0; i < entityNum; i++)
521+
for (int i = 0; i < entityNum; i++)
521522
{
522523
if (g_entityId[i] == -1 || g_entityAction[i] != 1)
523524
continue;
@@ -528,6 +529,21 @@ bool Bot::IsFriendInLineOfFire(float distance)
528529
}
529530
}
530531

532+
for (const auto& client : g_clients)
533+
{
534+
if (client.index < 0)
535+
continue;
536+
537+
if (!(client.flags & CFLAG_USED) || !(client.flags & CFLAG_ALIVE) || client.team != m_team || client.ent == GetEntity())
538+
continue;
539+
540+
Vector origin = client.ent->v.origin;
541+
float friendDistance = (origin - pev->origin).GetLengthSquared();
542+
543+
if (friendDistance <= distance && GetShootingConeDeviation(GetEntity(), &origin) > friendDistance / (friendDistance + 1089.0f))
544+
return true;
545+
}
546+
531547
return false;
532548
}
533549

@@ -644,15 +660,15 @@ bool Bot::DoFirePause(float distance)//, FireDelay *fireDelay)
644660
// this function will return true if weapon was fired, false otherwise
645661
void Bot::FireWeapon(void)
646662
{
647-
float distance = (m_lookAt - EyePosition()).GetLength(); // how far away is the enemy?
648-
649663
// if using grenade stop this
650664
if (m_isUsingGrenade)
651665
{
652-
m_shootTime = engine->GetTime() + 0.2f;
666+
m_shootTime = engine->GetTime() + 0.25f;
653667
return;
654668
}
655669

670+
float distance = (m_lookAt - pev->origin).GetLength(); // how far away is the enemy?
671+
656672
// or if friend in line of fire, stop this too but do not update shoot time
657673
if (!FNullEnt(m_enemy) && IsFriendInLineOfFire(distance))
658674
return;
@@ -682,6 +698,7 @@ void Bot::FireWeapon(void)
682698
if ((m_ammoInClip[selectTab[selectIndex].id] > 0) && !IsWeaponBadInDistance(selectIndex, distance))
683699
chosenWeaponIndex = selectIndex;
684700
}
701+
685702
selectIndex++;
686703
}
687704
selectId = selectTab[chosenWeaponIndex].id;
@@ -918,9 +935,10 @@ bool Bot::KnifeAttack(float attackDistance)
918935

919936
if (kaMode > 0)
920937
{
921-
float distanceSkipZ = (pev->origin - GetEntityOrigin(entity)).GetLengthSquared2D();
938+
Vector entityOrigin = GetEntityOrigin(entity);
939+
float distanceSkipZ = (pev->origin - entityOrigin).GetLengthSquared2D();
922940

923-
if (pev->origin.z > GetEntityOrigin(entity).z && distanceSkipZ < SquaredF(64.0f))
941+
if (pev->origin.z > entityOrigin.z && distanceSkipZ < SquaredF(64.0f))
924942
{
925943
pev->button |= IN_DUCK;
926944
m_campButtons |= IN_DUCK;
@@ -931,7 +949,7 @@ bool Bot::KnifeAttack(float attackDistance)
931949
pev->button &= ~IN_DUCK;
932950
m_campButtons &= ~IN_DUCK;
933951

934-
if (pev->origin.z + 150.0f < GetEntityOrigin(entity).z && distanceSkipZ < SquaredF(300.0f))
952+
if (pev->origin.z + 150.0f < entityOrigin.z && distanceSkipZ < SquaredF(300.0f))
935953
pev->button |= IN_JUMP;
936954
}
937955

@@ -992,7 +1010,7 @@ void Bot::FocusEnemy(void)
9921010
if (m_enemySurpriseTime > engine->GetTime())
9931011
return;
9941012

995-
float distance = (m_lookAt - EyePosition()).GetLengthSquared2D(); // how far away is the enemy scum?
1013+
float distance = (m_lookAt - EyePosition()).GetLengthSquared(); // how far away is the enemy scum?
9961014

9971015
if (distance < SquaredF(128.0f))
9981016
{

source/control.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,10 @@ Bot* BotControl::FindOneValidAliveBot(void)
265265
{
266266
Array <int> foundBots;
267267

268-
for (const auto& client : g_clients)
268+
for (const auto& bot : m_bots)
269269
{
270-
if (client.index < 0)
271-
continue;
272-
273-
if (m_bots[client.index] != nullptr && m_bots[client.index]->m_isAlive)
274-
foundBots.Push(client.index);
270+
if (bot != nullptr && bot->m_isAlive)
271+
foundBots.Push(bot->m_index);
275272
}
276273

277274
if (!foundBots.IsEmpty())
@@ -307,7 +304,7 @@ void BotControl::DoJoinQuitStuff(void)
307304
if (min > max)
308305
max = min * 1.5f;
309306

310-
m_randomJoinTime = AddTime(RANDOM_FLOAT(min, max));
307+
m_randomJoinTime = AddTime(engine->RandomFloat(min, max));
311308
}
312309

313310
void BotControl::Think(void)
@@ -863,7 +860,7 @@ Bot* BotControl::GetHighestSkillBot(int team)
863860
{
864861
if (highFragBot->m_skill > bestSkill)
865862
{
866-
bestIndex = bot->GetIndex();
863+
bestIndex = bot->m_index;
867864
bestSkill = highFragBot->m_skill;
868865
}
869866
}

source/interface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,21 +2800,21 @@ void SetPing(edict_t* to)
28002800
{
28012801
// start a new message
28022802
MESSAGE_BEGIN(MSG_ONE_UNRELIABLE, SVC_PINGS, nullptr, to);
2803-
WRITE_BYTE((bot->m_pingOffset[sending] * 64) + (1 + 2 * bot->GetIndex()));
2803+
WRITE_BYTE((bot->m_pingOffset[sending] * 64) + (1 + 2 * bot->m_index));
28042804
WRITE_SHORT(bot->m_ping[sending]);
28052805
sending++;
28062806
}
28072807
case 1:
28082808
{
28092809
// append additional data
2810-
WRITE_BYTE((bot->m_pingOffset[sending] * 128) + (2 + 4 * bot->GetIndex()));
2810+
WRITE_BYTE((bot->m_pingOffset[sending] * 128) + (2 + 4 * bot->m_index));
28112811
WRITE_SHORT(bot->m_ping[sending]);
28122812
sending++;
28132813
}
28142814
case 2:
28152815
{
28162816
// append additional data and end message
2817-
WRITE_BYTE(4 + 8 * bot->GetIndex());
2817+
WRITE_BYTE(4 + 8 * bot->m_index);
28182818
WRITE_SHORT(bot->m_ping[sending]);
28192819
WRITE_BYTE(0);
28202820
MESSAGE_END();

0 commit comments

Comments
 (0)