Skip to content

Commit

Permalink
Enable RTTI and add BotBrain::_IsCurrentBotTaskOfType (make sure to d…
Browse files Browse the repository at this point in the history
…o full rebuild
  • Loading branch information
pongo1231 committed Aug 13, 2019
1 parent dc9c673 commit 265067e
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 61 deletions.
19 changes: 8 additions & 11 deletions Pongbot/Bot/Brain/BotBrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand All @@ -162,7 +160,6 @@ void BotBrain::_ResetState()
{
_States = 0;
_IsBotDead = false;
_IsBotInMeleeFight = false;
}

void BotBrain::_AddState(BotState state)
Expand Down
11 changes: 5 additions & 6 deletions Pongbot/Bot/Brain/BotBrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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() {};
};
3 changes: 2 additions & 1 deletion Pongbot/Bot/Brain/BotBrainMed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
18 changes: 3 additions & 15 deletions Pongbot/Bot/Brain/BotBrainPyro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
5 changes: 1 addition & 4 deletions Pongbot/Bot/Brain/BotBrainPyro.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
22 changes: 4 additions & 18 deletions Pongbot/Bot/Brain/BotBrainSniper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
5 changes: 1 addition & 4 deletions Pongbot/Bot/Brain/BotBrainSniper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
4 changes: 3 additions & 1 deletion Pongbot/Bot/Brain/BotBrainSpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include "BotBrainSpy.h"

void BotBrainSpy::_OnThink()
{}
{

}

void BotBrainSpy::_OnSpawn()
{
Expand Down
3 changes: 2 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 265067e

Please sign in to comment.