Skip to content

Commit ca3f99a

Browse files
authored
Add files via upload
1 parent 152dee2 commit ca3f99a

File tree

9 files changed

+290
-661
lines changed

9 files changed

+290
-661
lines changed

source/basecode.cpp

Lines changed: 124 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,21 @@ ConVar ebot_use_radio("ebot_use_radio", "1");
4343
ConVar ebot_anti_block("ebot_anti_block", "0");
4444
ConVar ebot_zm_dark_mode("ebot_zm_dark_mode", "0");
4545
ConVar ebot_force_flashlight("ebot_force_flashlight", "0");
46-
ConVar ebot_use_flare("ebot_zombie_mode_use_flares", "1");
46+
ConVar ebot_use_flare("ebot_zm_use_flares", "1");
4747
ConVar ebot_chat_percent("ebot_chat_percent", "20");
4848
ConVar ebot_eco_rounds("ebot_eco_rounds", "1");
4949

5050
ConVar ebot_chatter_path("ebot_chatter_path", "radio/bot");
5151

52+
/*ConVar ebot_enable_lasermine("ebot_enable_lasermine", "0");
53+
ConVar ebot_lasermine_max("ebot_lasermine_max", "2");
54+
ConVar ebot_lasermine_classname("ebot_lasermine_classname", "zp_lasermine");*/
55+
5256
// this function get the current message from the bots message queue
5357
int Bot::GetMessageQueue(void)
5458
{
5559
int message = m_messageQueue[m_actMessageIndex++];
5660
m_actMessageIndex &= 0x1f; // wraparound
57-
5861
return message;
5962
}
6063

@@ -66,18 +69,16 @@ void Bot::PushMessageQueue(int message)
6669
// notify other bots of the spoken text otherwise, bots won't respond to other bots (network messages aren't sent from bots)
6770
int entityIndex = GetIndex();
6871

69-
for (const auto& client : g_clients)
72+
for (int i = 0; i < engine->GetMaxClients(); i++)
7073
{
71-
Bot* otherBot = g_botManager->GetBot(client.ent);
74+
Bot* otherBot = g_botManager->GetBot(i);
7275
if (otherBot != nullptr && otherBot->pev != pev)
7376
{
74-
if (IsAlive(GetEntity()) == otherBot->m_notKilled)
77+
if (m_notKilled == IsAlive(otherBot->GetEntity()))
7578
{
7679
otherBot->m_sayTextBuffer.entityIndex = entityIndex;
7780
strcpy(otherBot->m_sayTextBuffer.sayText, m_tempStrings);
7881
}
79-
80-
otherBot->m_sayTextBuffer.timeNextChat = engine->GetTime() + otherBot->m_sayTextBuffer.chatDelay;
8182
}
8283
}
8384
}
@@ -176,13 +177,6 @@ bool Bot::IsEnemyViewable(edict_t* entity, bool setEnemy, bool checkOnly)
176177
if (m_damageTime < engine->GetTime())
177178
m_backCheckEnemyTime = engine->GetTime() + engine->RandomFloat(0.5f, 1.5f);
178179
}
179-
else if (IsDeathmatchMode())
180-
{
181-
if (!FNullEnt(m_enemy))
182-
return false;
183-
184-
m_backCheckEnemyTime = engine->GetTime() + float(50 / m_skill);
185-
}
186180
else if (GetGameMod() == MODE_ZP)
187181
m_backCheckEnemyTime = engine->GetTime() + engine->RandomFloat(0.15f, 0.5f);
188182
else
@@ -439,6 +433,19 @@ void Bot::ZmCampPointAction(int mode)
439433
}
440434
}
441435

436+
/*int Bot::GetLasermineCount(void)
437+
{
438+
int count = 0;
439+
edict_t* lasermine = nullptr;
440+
while (!FNullEnt(lasermine = FIND_ENTITY_BY_CLASSNAME(lasermine, ebot_lasermine_classname.GetString())))
441+
{
442+
if (lasermine->v.owner == GetEntity())
443+
count++;
444+
}
445+
446+
return count;
447+
}*/
448+
442449
void Bot::AvoidEntity(void)
443450
{
444451
if (IsZombieMode() || FNullEnt(m_avoidEntity) || (m_avoidEntity->v.flags & FL_ONGROUND) || (m_avoidEntity->v.effects & EF_NODRAW))
@@ -493,7 +500,7 @@ void Bot::AvoidEntity(void)
493500

494501
if (strcmp(STRING(entity->v.classname), "grenade") == 0)
495502
{
496-
if (strcmp(STRING(entity->v.model) + 9, "flashbang.mdl") == 0 && GetGameMod() != MODE_BASE && !IsDeathmatchMode())
503+
if (IsZombieMode() && strcmp(STRING(entity->v.model) + 9, "flashbang.mdl") == 0)
497504
continue;
498505

499506
if (strcmp(STRING(entity->v.model) + 9, "hegrenade.mdl") == 0 && (GetTeam(entity->v.owner) == m_team && entity->v.owner != GetEntity()))
@@ -1953,7 +1960,7 @@ void Bot::SetConditions(void)
19531960
else if (m_heardSoundTime < engine->GetTime())
19541961
m_states &= ~STATE_HEARENEMY;
19551962

1956-
if (FNullEnt(m_enemy) && !FNullEnt(m_lastEnemy) && m_lastEnemyOrigin != nullvec && (GetGameMod() == MODE_BASE || IsDeathmatchMode()) && (pev->origin - m_lastEnemyOrigin).GetLength() < 1600.0f)
1963+
if (FNullEnt(m_enemy) && !FNullEnt(m_lastEnemy) && m_lastEnemyOrigin != nullvec && !IsZombieMode() && (pev->origin - m_lastEnemyOrigin).GetLength() < 1600.0f)
19571964
{
19581965
TraceResult tr;
19591966
TraceLine(EyePosition(), m_lastEnemyOrigin, true, true, GetEntity(), &tr);
@@ -2744,6 +2751,13 @@ bool Bot::ReactOnEnemy(void)
27442751
{
27452752
m_isEnemyReachable = false;
27462753

2754+
if (pev->flags & FL_DUCKING)
2755+
{
2756+
if (enemyDistance < 32.0f)
2757+
m_isEnemyReachable = true;
2758+
goto last;
2759+
}
2760+
27472761
// end of the path, before repathing check the distance if we can reach to enemy
27482762
if (m_navNode == nullptr)
27492763
{
@@ -2756,22 +2770,16 @@ bool Bot::ReactOnEnemy(void)
27562770
m_isEnemyReachable = true;
27572771
goto last;
27582772
}
2773+
else if (g_waypoint->GetPath(ownIndex)->flags & WAYPOINT_FALLRISK)
2774+
goto last;
27592775
else if (IsVisibleForKnifeAttack(enemyHead, GetEntity()))
27602776
{
2761-
if (pev->flags & FL_DUCKING)
2762-
{
2763-
if (enemyDistance <= 48.0f)
2764-
m_isEnemyReachable = true;
2765-
}
2766-
else
2767-
{
2768-
float radius = 48.0f;
2769-
if (IsValidWaypoint(ownIndex) && !(currentWaypoint->flags & WAYPOINT_FALLCHECK))
2770-
radius += currentWaypoint->radius;
2777+
float radius = 128.0f;
2778+
if (IsValidWaypoint(ownIndex) && !(currentWaypoint->flags & WAYPOINT_FALLCHECK))
2779+
radius += currentWaypoint->radius;
27712780

2772-
if (enemyDistance > radius)
2773-
m_isEnemyReachable = true;
2774-
}
2781+
if (enemyDistance > radius)
2782+
m_isEnemyReachable = true;
27752783

27762784
goto last;
27772785
}
@@ -2792,30 +2800,37 @@ bool Bot::ReactOnEnemy(void)
27922800
}
27932801
else if (pev->flags & FL_DUCKING && m_enemy->v.flags & FL_DUCKING) // danger...
27942802
{
2795-
if (enemyDistance <= (fabsf(m_enemy->v.speed) + 300.0f))
2803+
extern ConVar ebot_zp_escape_distance;
2804+
if (enemyDistance <= fabsf(m_enemy->v.speed) + ebot_zp_escape_distance.GetFloat())
27962805
{
27972806
m_isEnemyReachable = true;
27982807
goto last;
27992808
}
28002809
}
2810+
else if (g_waypoint->GetPath(ownIndex)->flags & WAYPOINT_FALLRISK)
2811+
goto last;
28012812
else if (GetCurrentTask()->taskID == TASK_CAMP)
28022813
{
28032814
if (enemyIndex == m_zhCampPointIndex)
28042815
m_isEnemyReachable = true;
2805-
else if (enemyDistance <= (fabsf(m_enemy->v.speed) + 300.0f))
2816+
else
28062817
{
2807-
for (int j = 0; j < Const_MaxPathIndex; j++)
2818+
extern ConVar ebot_zp_escape_distance;
2819+
if (enemyDistance <= fabsf(m_enemy->v.speed) + ebot_zp_escape_distance.GetFloat())
28082820
{
2809-
Vector origin = GetBottomOrigin(GetEntity());
2821+
for (int j = 0; j < Const_MaxPathIndex; j++)
2822+
{
2823+
Vector origin = GetBottomOrigin(GetEntity());
28102824

2811-
TraceResult tr;
2812-
TraceLine(Vector(origin.x, origin.y, (origin.z + 10.0f)), enemyHead, true, false, GetEntity(), &tr);
2825+
TraceResult tr;
2826+
TraceLine(Vector(origin.x, origin.y, (origin.z + 10.0f)), enemyHead, true, false, GetEntity(), &tr);
28132827

2814-
auto enemyWaypoint = g_waypoint->GetPath(enemyIndex);
2815-
if (tr.flFraction == 1.0f && enemyWaypoint->index[j] == ownIndex && !(enemyWaypoint->connectionFlags[j] & PATHFLAG_JUMP))
2816-
{
2817-
m_isEnemyReachable = true;
2818-
break;
2828+
auto enemyWaypoint = g_waypoint->GetPath(enemyIndex);
2829+
if (tr.flFraction == 1.0f && enemyWaypoint->index[j] == ownIndex && !(enemyWaypoint->connectionFlags[j] & PATHFLAG_JUMP))
2830+
{
2831+
m_isEnemyReachable = true;
2832+
break;
2833+
}
28192834
}
28202835
}
28212836
}
@@ -2830,7 +2845,8 @@ bool Bot::ReactOnEnemy(void)
28302845
TraceLine(Vector(origin.x, origin.y, (origin.z + 10.0f)), enemyHead, true, false, GetEntity(), &tr);
28312846

28322847
// human improve
2833-
if (enemyDistance <= (fabsf(m_enemy->v.speed) + 300.0f) && tr.flFraction == 1.0f)
2848+
extern ConVar ebot_zp_escape_distance;
2849+
if (enemyDistance <= fabsf(m_enemy->v.speed) + ebot_zp_escape_distance.GetFloat() && tr.flFraction == 1.0f)
28342850
m_isEnemyReachable = true;
28352851
else
28362852
m_isEnemyReachable = false;
@@ -3635,7 +3651,10 @@ void Bot::ChooseAimDirection(void)
36353651
}
36363652

36373653
if (flags & AIM_OVERRIDE)
3654+
{
3655+
m_aimStopTime = 0.0f;
36383656
m_lookAt = m_camp;
3657+
}
36393658
else if (flags & AIM_GRENADE)
36403659
m_lookAt = m_throw + Vector(0.0f, 0.0f, 1.0f * m_grenade.z);
36413660
else if (flags & AIM_ENEMY)
@@ -4418,13 +4437,62 @@ void Bot::RunTask(void)
44184437
const float timeToBlowUp = GetBombTimeleft();
44194438
float defuseRemainingTime = m_hasDefuser ? 7.0f : 12.0f - engine->GetTime();
44204439

4421-
switch (GetCurrentTask()->taskID)
4440+
auto x = GetCurrentTask()->taskID;
4441+
/*/if (x == TASK_PLACELASER)
4442+
{
4443+
if (m_laserminePosition == nullvec)
4444+
{
4445+
TaskComplete();
4446+
return;
4447+
}
4448+
4449+
if (m_lasermineCount >= ebot_lasermine_max.GetInt())
4450+
{
4451+
TaskComplete();
4452+
return;
4453+
}
4454+
4455+
int currentCount = m_lasermineCount;
4456+
bool moveTowards = false;
4457+
float distance = (pev->origin - m_laserminePosition).GetLength();
4458+
4459+
if (distance <= 300.0f)
4460+
{
4461+
m_aimFlags |= AIM_OVERRIDE;
4462+
m_camp = m_laserminePosition;
4463+
4464+
if (distance <= 80.0f)
4465+
{
4466+
moveTowards = true;
4467+
m_moveSpeed = GetWalkSpeed();
4468+
FakeClientCommand(GetEntity(), "+setlaser");
4469+
m_lasermineCount = GetLasermineCount();
4470+
}
4471+
}
4472+
else
4473+
m_aimFlags |= AIM_NAVPOINT;
4474+
4475+
if (!moveTowards)
4476+
{
4477+
int index = g_waypoint->FindNearest(m_laserminePosition);
4478+
if (IsValidWaypoint(index))
4479+
FindPath(m_currentWaypointIndex, index);
4480+
else
4481+
TaskComplete();
4482+
}
4483+
4484+
if (currentCount != m_lasermineCount)
4485+
TaskComplete();
4486+
4487+
return;
4488+
}*/
4489+
4490+
switch (x)
44224491
{
44234492
// normal task
44244493
case TASK_NORMAL:
44254494
TaskNormal(destIndex, i, src);
44264495
break;
4427-
44284496
// bot sprays messy logos all over the place...
44294497
case TASK_SPRAYLOGO:
44304498
m_aimFlags |= AIM_ENTITY;
@@ -4624,7 +4692,7 @@ void Bot::RunTask(void)
46244692

46254693
// plain attacking
46264694
case TASK_FIGHTENEMY:
4627-
if (IsZombieMode())
4695+
if (IsZombieMode() && !m_isZombieBot)
46284696
{
46294697
TaskNormal(i, destIndex, src);
46304698
return;
@@ -4726,7 +4794,7 @@ void Bot::RunTask(void)
47264794

47274795
// camping behaviour
47284796
case TASK_GOINGFORCAMP:
4729-
if ((m_isZombieBot || (IsZombieMode() && g_waypoint->m_zmHmPoints.IsEmpty()) || (IsDeathmatchMode() && pev->health > pev->max_health / 1.6))
4797+
if ((m_isZombieBot || (IsZombieMode() && g_waypoint->m_zmHmPoints.IsEmpty()))
47304798
|| (GetGameMod() == MODE_BASE && (g_mapType & MAP_CS) && m_team == TEAM_COUNTER && HasHostage())
47314799
|| (!IsZombieMode() && !FNullEnt(m_enemy) && m_currentWeapon == WEAPON_KNIFE)
47324800
|| (m_personality == PERSONALITY_CAREFUL && GetGameMod() == MODE_BASE && !FNullEnt(m_enemy) && m_numFriendsLeft < m_numEnemiesLeft)
@@ -5431,6 +5499,7 @@ void Bot::RunTask(void)
54315499

54325500
RemoveCertainTask(TASK_FIGHTENEMY);
54335501

5502+
extern ConVar ebot_zp_escape_distance;
54345503
if (IsZombieMode() && !FNullEnt(m_enemy))
54355504
{
54365505
if (m_isZombieBot)
@@ -5440,7 +5509,7 @@ void Bot::RunTask(void)
54405509
m_moveSpeed = pev->maxspeed;
54415510
m_moveToGoal = false;
54425511
}
5443-
else if ((GetEntityOrigin(m_enemy) - pev->origin).GetLength() <= (fabsf(m_enemy->v.speed) + 300.0f))
5512+
else if ((GetEntityOrigin(m_enemy) - pev->origin).GetLength() <= fabsf(m_enemy->v.speed) + ebot_zp_escape_distance.GetFloat())
54445513
{
54455514
destination = GetEntityOrigin(m_enemy);
54465515
m_destOrigin = destination;
@@ -5538,6 +5607,7 @@ void Bot::RunTask(void)
55385607

55395608
RemoveCertainTask(TASK_FIGHTENEMY);
55405609

5610+
extern ConVar ebot_zp_escape_distance;
55415611
if (IsZombieMode() && !FNullEnt(m_enemy))
55425612
{
55435613
if (m_isZombieBot)
@@ -5547,7 +5617,7 @@ void Bot::RunTask(void)
55475617
m_moveSpeed = pev->maxspeed;
55485618
m_moveToGoal = false;
55495619
}
5550-
else if ((GetEntityOrigin(m_enemy) - pev->origin).GetLength() <= (fabsf(m_enemy->v.speed) + 300.0f))
5620+
else if ((GetEntityOrigin(m_enemy) - pev->origin).GetLength() <= fabsf(m_enemy->v.speed) + 300.0f)
55515621
{
55525622
destination = GetEntityOrigin(m_enemy);
55535623
m_destOrigin = destination;
@@ -6527,7 +6597,7 @@ void Bot::BotAI(void)
65276597
{
65286598
m_checkKnifeSwitch = false;
65296599

6530-
if (GetGameMod() == MODE_BASE && IsDeathmatchMode())
6600+
if (!IsZombieMode())
65316601
{
65326602
if (ebot_spraypaints.GetBool() && engine->RandomInt(1, 10) < 2)
65336603
PushTask(TASK_SPRAYLOGO, TASKPRI_SPRAYLOGO, -1, engine->GetTime() + 1.0f, false);
@@ -6646,7 +6716,7 @@ void Bot::BotAI(void)
66466716
if (m_currentWeapon == WEAPON_KNIFE)
66476717
SelectBestWeapon();
66486718

6649-
if (m_isEnemyReachable && !FNullEnt(m_enemy))
6719+
if (!FNullEnt(m_enemy) && m_isEnemyReachable)
66506720
{
66516721
m_moveToGoal = false; // don't move to goal
66526722
m_navTimeset = engine->GetTime();
@@ -6812,9 +6882,10 @@ void Bot::BotAI(void)
68126882
}
68136883
else
68146884
m_isBlocked = CheckCloseAvoidance(directionNormal);
6885+
68156886
m_isStuck = false;
68166887

6817-
if ((m_moveSpeed <= -10 || m_moveSpeed >= 10 || m_strafeSpeed >= 10 || m_strafeSpeed <= -10) && m_lastCollTime < engine->GetTime())
6888+
if ((m_moveSpeed >= 10 || m_strafeSpeed >= 10) && m_lastCollTime < engine->GetTime())
68186889
{
68196890
if (m_damageTime >= engine->GetTime())
68206891
{
@@ -7208,6 +7279,7 @@ bool Bot::HasHostage(void)
72087279
return true;
72097280
}
72107281
}
7282+
72117283
return false;
72127284
}
72137285

@@ -7508,7 +7580,7 @@ void Bot::MoveToVector(Vector to)
75087580
if (!IsValidWaypoint(m_currentWaypointIndex))
75097581
{
75107582
// we dont have a current waypoint, try find nearest
7511-
int index = m_isStuck ? g_waypoint->FindNearest(pev->origin, 9999.0f, -1, GetEntity()) : FindWaypoint(false);
7583+
int index = m_isStuck ? FindWaypoint(false) : g_waypoint->FindNearest(pev->origin, 9999.0f, -1, GetEntity());
75127584
if (IsValidWaypoint(index))
75137585
FindPath(index, g_waypoint->FindNearest(to));
75147586

@@ -7694,7 +7766,7 @@ bool Bot::OutOfBombTimer(void)
76947766

76957767
void Bot::ReactOnSound(void)
76967768
{
7697-
if (GetGameMod() != MODE_BASE && !IsDeathmatchMode())
7769+
if (IsZombieMode())
76987770
return;
76997771

77007772
if (!m_isSlowThink)

source/chatlib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void Bot::PrepareChatMessage(char* text)
325325
}
326326

327327
// this function checks is string contain keyword, and generates relpy to it
328-
bool CheckKeywords(char* tempMessage, char* reply)
328+
bool Bot::CheckKeywords(char* tempMessage, char* reply)
329329
{
330330
if (!ebot_chat.GetBool() || IsNullString(tempMessage))
331331
return false;

0 commit comments

Comments
 (0)