From b37afb1362efd46e3f77277af674db8880b24eec Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Wed, 11 Oct 2023 00:55:07 -0700 Subject: [PATCH] BotLib: break func_breakable entities within their path. --- src/botlib/bot.h | 3 +++ src/botlib/bot.qc | 16 +++++++++++++++- src/botlib/bot_combat.qc | 10 ++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/botlib/bot.h b/src/botlib/bot.h index 5a40873a..2381ed96 100644 --- a/src/botlib/bot.h +++ b/src/botlib/bot.h @@ -64,6 +64,8 @@ class bot:player float m_flEnemyDist; weapontype_t m_wtWeaponType; vector m_vecLastPOI; + float m_flForceWeaponAttack; + vector m_vecForceWeaponAttackPos; void(void) bot; @@ -88,6 +90,7 @@ class bot:player virtual void(entity) SetEnemy; virtual float(void) GetRunSpeed; virtual float(void) GetWalkSpeed; + nonvirtual void ForceWeaponAttack(vector, float); virtual void(string) SetName; }; diff --git a/src/botlib/bot.qc b/src/botlib/bot.qc index cc8a5b9f..ad2e81e2 100644 --- a/src/botlib/bot.qc +++ b/src/botlib/bot.qc @@ -353,7 +353,8 @@ bot::RunAI(void) if (enemyvisible) { WeaponAttack(); } - } + } else if (m_flForceWeaponAttack > time) + WeaponAttack(); BrainThink(enemyvisible, enemydistant); CheckRoute(); @@ -382,6 +383,10 @@ bot::RunAI(void) aimpos = m_eTarget.origin; } + /* force bot to fire at a position if desired */ + if (m_flForceWeaponAttack > time) + aimpos = m_vecForceWeaponAttackPos; + /* aim ahead if aimpos is somehow invalid */ if (aimpos == [0,0,0]) { makevectors(angles); @@ -470,6 +475,15 @@ bot::RunAI(void) RouteClear(); } + /* if there's a breakable in the way... */ + traceline(origin, aimpos, MOVE_NORMAL, this); + + /* Hackish: If there's a func_breakable in the way... */ + if (trace_ent.classname == "func_breakable") { + NSEntity traceEnt = (NSEntity)trace_ent; + ForceWeaponAttack(traceEnt.WorldSpaceCenter(), 1.0f); + } + /* now we'll set the movevalues relative to the input_angle */ if ((m_iCurNode >= 0 && Route_GetNodeFlags(&m_pRoute[m_iCurNode]) & LF_WALK) || shouldwalk) vecDirection = normalize(aimpos - origin) * GetWalkSpeed(); diff --git a/src/botlib/bot_combat.qc b/src/botlib/bot_combat.qc index d6445ce2..d98f5dc5 100644 --- a/src/botlib/bot_combat.qc +++ b/src/botlib/bot_combat.qc @@ -88,6 +88,9 @@ bot::WeaponAttack(void) should_attack = 1; } + if (m_flForceWeaponAttack > time) + should_attack = 1; + if (should_attack && m_flAttackTime < time) { if (!m_iAttackMode) { input_buttons |= INPUT_BUTTON0; @@ -121,6 +124,13 @@ bot::WeaponAttack(void) m_iAttackMode = 0; } +void +bot::ForceWeaponAttack(vector attackPos, float attackTime) +{ + m_vecForceWeaponAttackPos = attackPos; + m_flForceWeaponAttack = attackTime + time; +} + var float g_botalert_timer; void