diff --git a/Pongbot/Bot/Brain/BotBrain.cpp b/Pongbot/Bot/Brain/BotBrain.cpp index 36f0137..c175a9c 100644 --- a/Pongbot/Bot/Brain/BotBrain.cpp +++ b/Pongbot/Bot/Brain/BotBrain.cpp @@ -57,17 +57,10 @@ void BotBrain::_DefaultThink() // Melee combat BotVisibleTarget currentTarget = bot->GetBotVisibles()->GetMostImportantTarget(); - if (currentTarget.IsValid() && bot->GetSelectedWeaponSlot() == WeaponSlot::WEAPON_MELEE) + if (currentTarget.IsValid() && bot->GetSelectedWeaponSlot() == WeaponSlot::WEAPON_MELEE + && !_IsCurrentBotTaskOfType(typeid(BotTaskAggressiveCombat))) { - if (!_IsBotInMeleeFight) - { - _IsBotInMeleeFight = true; - _SetBotTask(new BotTaskAggressiveCombat(bot, currentTarget.GetEntity(), WeaponSlot::WEAPON_MELEE)); - } - } - else - { - _IsBotInMeleeFight = false; + _SetBotTask(new BotTaskAggressiveCombat(bot, currentTarget.GetEntity(), WeaponSlot::WEAPON_MELEE)); } /* Filler Tasks in case the bot has nothing to do */ @@ -152,6 +145,11 @@ bool BotBrain::_HasBotTask() const return _BotTask; } +bool BotBrain::_IsCurrentBotTaskOfType(const std::type_info& type) const +{ + return typeid(_BotTask) == type; +} + void BotBrain::_ClearTask() { delete _BotTask; @@ -162,7 +160,6 @@ void BotBrain::_ResetState() { _States = 0; _IsBotDead = false; - _IsBotInMeleeFight = false; } void BotBrain::_AddState(BotState state) diff --git a/Pongbot/Bot/Brain/BotBrain.h b/Pongbot/Bot/Brain/BotBrain.h index 4f6eed0..6ec5977 100644 --- a/Pongbot/Bot/Brain/BotBrain.h +++ b/Pongbot/Bot/Brain/BotBrain.h @@ -11,8 +11,8 @@ enum BotState class BotBrain : public IEventHooker { public: - BotBrain(Bot* bot) : _ABot(bot), _BotTask(nullptr), _IsBotDead(false), _ThinkTime(0.f), _States(0), - _IsBotInMeleeFight(false) {} /* To invoke OnSpawn() */ + BotBrain(Bot* bot) : _ABot(bot), _BotTask(nullptr), _IsBotDead(false), _ThinkTime(0.f), + _States(0) {} /* To invoke OnSpawn() */ public: void OnThink(); @@ -24,6 +24,7 @@ class BotBrain : public IEventHooker Bot* _GetBot() const; void _SetBotTask(BotTask* task); bool _HasBotTask() const; + bool _IsCurrentBotTaskOfType(const std::type_info& type) const; void _AddState(BotState state); void _RemoveState(BotState state); bool _HasState(BotState state) const; @@ -34,13 +35,11 @@ class BotBrain : public IEventHooker float _ThinkTime; unsigned int _States; bool _IsBotDead; - bool _IsBotInMeleeFight; void _DefaultThink(); void _ClearTask(); void _ResetState(); virtual void _OnThink() = 0; - virtual void _OnSpawn() = 0; -}; - + virtual void _OnSpawn() {}; +}; \ No newline at end of file diff --git a/Pongbot/Bot/Brain/BotBrainMed.cpp b/Pongbot/Bot/Brain/BotBrainMed.cpp index 698509d..24d09a2 100644 --- a/Pongbot/Bot/Brain/BotBrainMed.cpp +++ b/Pongbot/Bot/Brain/BotBrainMed.cpp @@ -12,7 +12,8 @@ void BotBrainMed::_OnThink() Bot* bot = _GetBot(); BotVisibles* botVisibles = bot->GetBotVisibles(); - if (_CurrentHealTarget && !botVisibles->IsEntityVisible(_CurrentHealTarget)) + if (!_IsCurrentBotTaskOfType(typeid(BotTaskMedHealTarget)) + || (_CurrentHealTarget && !botVisibles->IsEntityVisible(_CurrentHealTarget))) { _CurrentHealTarget = nullptr; } diff --git a/Pongbot/Bot/Brain/BotBrainPyro.cpp b/Pongbot/Bot/Brain/BotBrainPyro.cpp index 5cc8b69..e322aa5 100644 --- a/Pongbot/Bot/Brain/BotBrainPyro.cpp +++ b/Pongbot/Bot/Brain/BotBrainPyro.cpp @@ -9,21 +9,9 @@ void BotBrainPyro::_OnThink() Bot* bot = _GetBot(); BotVisibleTarget currentTarget = bot->GetBotVisibles()->GetMostImportantTarget(); - if (currentTarget.IsValid() && bot->GetSelectedWeaponSlot() == WEAPON_PRIMARY) + if (currentTarget.IsValid() && bot->GetSelectedWeaponSlot() == WEAPON_PRIMARY + && !_IsCurrentBotTaskOfType(typeid(BotTaskAggressiveCombat))) { - if (!_IsRushingEnemy) - { - _IsRushingEnemy = true; - _SetBotTask(new BotTaskAggressiveCombat(bot, currentTarget.GetEntity(), WEAPON_PRIMARY)); - } + _SetBotTask(new BotTaskAggressiveCombat(bot, currentTarget.GetEntity(), WEAPON_PRIMARY)); } - else - { - _IsRushingEnemy = false; - } -} - -void BotBrainPyro::_OnSpawn() -{ - _IsRushingEnemy = false; } \ No newline at end of file diff --git a/Pongbot/Bot/Brain/BotBrainPyro.h b/Pongbot/Bot/Brain/BotBrainPyro.h index 21199f4..6fe01d4 100644 --- a/Pongbot/Bot/Brain/BotBrainPyro.h +++ b/Pongbot/Bot/Brain/BotBrainPyro.h @@ -4,11 +4,8 @@ class BotBrainPyro : public BotBrain { public: - BotBrainPyro(Bot* bot) : BotBrain(bot), _IsRushingEnemy(false) {} + BotBrainPyro(Bot* bot) : BotBrain(bot) {} private: - bool _IsRushingEnemy; - virtual void _OnThink(); - virtual void _OnSpawn(); }; \ No newline at end of file diff --git a/Pongbot/Bot/Brain/BotBrainSniper.cpp b/Pongbot/Bot/Brain/BotBrainSniper.cpp index 9669835..395e98c 100644 --- a/Pongbot/Bot/Brain/BotBrainSniper.cpp +++ b/Pongbot/Bot/Brain/BotBrainSniper.cpp @@ -10,24 +10,10 @@ void BotBrainSniper::_OnThink() Bot* bot = _GetBot(); BotVisibleTarget visibleTarget = bot->GetBotVisibles()->GetMostImportantTarget(); - if (visibleTarget.IsValid()) + if (visibleTarget.IsValid() + && Util::DistanceToNoZ(bot->GetPos(), visibleTarget.GetPos()) > _ConVarHolder->CVarBotWeaponLongRangeDist->GetFloat() + && !_IsCurrentBotTaskOfType(typeid(BotTaskSniperSnipe))) { - if (Util::DistanceToNoZ(bot->GetPos(), visibleTarget.GetPos()) > _ConVarHolder->CVarBotWeaponLongRangeDist->GetFloat()) - { - if (!_IsBotSniping) - { - _IsBotSniping = true; - _SetBotTask(new BotTaskSniperSnipe(bot)); - } - } - else - { - _IsBotSniping = false; - } + _SetBotTask(new BotTaskSniperSnipe(bot)); } -} - -void BotBrainSniper::_OnSpawn() -{ - _IsBotSniping = false; } \ No newline at end of file diff --git a/Pongbot/Bot/Brain/BotBrainSniper.h b/Pongbot/Bot/Brain/BotBrainSniper.h index 2d87aee..5bb4aac 100644 --- a/Pongbot/Bot/Brain/BotBrainSniper.h +++ b/Pongbot/Bot/Brain/BotBrainSniper.h @@ -4,11 +4,8 @@ class BotBrainSniper : public BotBrain { public: - BotBrainSniper(Bot* bot) : BotBrain(bot), _IsBotSniping(false) {} + BotBrainSniper(Bot* bot) : BotBrain(bot) {} private: - bool _IsBotSniping; - virtual void _OnThink(); - virtual void _OnSpawn(); }; \ No newline at end of file diff --git a/Pongbot/Bot/Brain/BotBrainSpy.cpp b/Pongbot/Bot/Brain/BotBrainSpy.cpp index 5ffff1f..bcf1559 100644 --- a/Pongbot/Bot/Brain/BotBrainSpy.cpp +++ b/Pongbot/Bot/Brain/BotBrainSpy.cpp @@ -2,7 +2,9 @@ #include "BotBrainSpy.h" void BotBrainSpy::_OnThink() -{} +{ + +} void BotBrainSpy::_OnSpawn() { diff --git a/makefile b/makefile index f513755..180cc1e 100644 --- a/makefile +++ b/makefile @@ -25,7 +25,8 @@ DEPS = $(OBJECTS:.o=.d) COMPILE_FLAGS = -Wall -Wextra -fpermissive -w -DPOSIX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp \ -Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca \ -Dstrcmpi=strcasecmp -DCOMPILER_GCC -Wall -Wno-non-virtual-dtor -Wno-overloaded-virtual \ - -Werror -fPIC -fno-exceptions -fno-rtti -msse -m32 -fno-strict-aliasing -D_LINUX -shared -ggdb -D_DEBUG + -Werror -fPIC -fno-exceptions -msse -m32 -fno-strict-aliasing -D_LINUX -shared -ggdb -D_DEBUG + # -fno-rtti INCLUDES = -I $(MLIBS) -I $(MLIBS)/hlsdk $(addprefix -I,$(shell find $(MLIBS)/hlsdk/public -type d -print)) -I $(MLIBS)/hlsdk/engine \ -I $(MLIBS)/hlsdk/mathlib -I $(MLIBS)/hlsdk/vstdlib -I $(MLIBS)/hlsdk/game -I $(MLIBS)/hlsdk/game/tier1 -I $(MLIBS)/hlsdk/game/tier0 \ -I $(MLIBS)/hlsdk/tier0 -I $(MLIBS)/hlsdk/tier1 -I $(MLIBS)/hlsdk/game/server -I $(MLIBS)/hlsdk/game/shared -I $(MLIBS)/metamod -I $(MLIBS)/metamod/sourcehook -I Pongbot