Remove cs-related commented-out code

This commit is contained in:
mittorn 2017-01-09 22:35:08 +00:00
parent 70af6c8e9e
commit d7008be97d
20 changed files with 64 additions and 3180 deletions

View File

@ -221,11 +221,6 @@ void CCSBot::BotTouch(CBaseEntity *other)
// TODO: Need to account for reaction time, etc.
if (other->IsPlayer())
{
#if 0
// if we are defusing a bomb, don't move
if (IsDefusingBomb())
return;
#endif
CBasePlayer *player = static_cast<CBasePlayer *>(other);
// get priority of other player
@ -292,14 +287,7 @@ void CCSBot::BotTouch(CBaseEntity *other)
bool CCSBot::IsBusy() const
{
if (IsAttacking() ||
#if 0
IsBuying() ||
IsDefusingBomb() ||
GetTask() == PLANT_BOMB ||
GetTask() == RESCUE_HOSTAGES ||
#endif
IsSniping())
if (IsAttacking() || IsSniping())
{
return true;
}
@ -462,68 +450,6 @@ bool CCSBot::IsDoingScenario() const
return !UTIL_HumansOnTeam(m_iTeam, true);
}
// Return true if we noticed the bomb on the ground or on the radar (for T's only)
#if 0
bool CCSBot::NoticeLooseBomb() const
{
CCSBotManager *ctrl = TheCSBots();
if (ctrl->GetScenario() != CCSBotManager::SCENARIO_DEFUSE_BOMB)
return false;
CBaseEntity *bomb = ctrl->GetLooseBomb();
if (bomb != NULL)
{
// T's can always see bomb on their radar
return true;
}
return false;
}
// Return true if can see the bomb lying on the ground
bool CCSBot::CanSeeLooseBomb() const
{
CCSBotManager *ctrl = TheCSBots();
if (ctrl->GetScenario() != CCSBotManager::SCENARIO_DEFUSE_BOMB)
return false;
CBaseEntity *bomb = ctrl->GetLooseBomb();
if (bomb != NULL)
{
if (IsVisible(&bomb->pev->origin, CHECK_FOV))
return true;
}
return false;
}
// Return true if can see the planted bomb
bool CCSBot::CanSeePlantedBomb() const
{
CCSBotManager *ctrl = TheCSBots();
if (ctrl->GetScenario() != CCSBotManager::SCENARIO_DEFUSE_BOMB)
return false;
if (!GetGameState()->IsBombPlanted())
return false;
const Vector *bombPos = GetGameState()->GetBombPosition();
if (bombPos != NULL && IsVisible((Vector*)bombPos, CHECK_FOV))
return true;
return false;
}
#endif
// Return last enemy that hurt us
CBasePlayer *CCSBot::GetAttacker() const
@ -597,13 +523,6 @@ void CCSBot::SetHidingSpotCheckTimestamp(HidingSpot *spot)
m_checkedHidingSpot[ leastRecent ].timestamp = gpGlobals->time;
}
}
#if 0
// Periodic check of hostage count in case we lost some
void CCSBot::UpdateHostageEscortCount()
{
}
#endif
// Return true if we are outnumbered by enemies
bool CCSBot::IsOutnumbered() const
@ -861,12 +780,3 @@ const Vector *FindNearbyRetreatSpot(CCSBot *me, float maxRange)
int which = RANDOM_LONG(0, collector.m_count - 1);
return collector.m_spot[ which ];
}
// Return euclidean distance to farthest escorted hostage.
// Return -1 if no hostage is following us.
#if 0
float CCSBot::GetRangeToFarthestEscortedHostage() const
{
return 0;
}
#endif

View File

@ -83,58 +83,6 @@ void BotHelpMeme::Interpret(CCSBot *sender, CCSBot *receiver) const
// receiver->RespondToHelpRequest(sender, m_place, maxHelpRange);
}
// A teammate reported information about a bombsite
#if 0
void BotBombsiteStatusMeme::Interpret(CCSBot *sender, CCSBot *receiver) const
{
// remember this bombsite's status
if (m_status == CLEAR)
receiver->GetGameState()->ClearBombsite(m_zoneIndex);
else
receiver->GetGameState()->MarkBombsiteAsPlanted(m_zoneIndex);
// if we were heading to the just-cleared bombsite, pick another one to search
// if our target bombsite wasn't cleared, will will continue going to it,
// because GetNextBombsiteToSearch() will return the same zone (since its not cleared)
// if the bomb was planted, we will head to that bombsite
if (receiver->GetTask() == CCSBot::FIND_TICKING_BOMB)
{
receiver->Idle();
receiver->GetChatter()->Affirmative();
}
}
// A teammate reported information about the bomb
void BotBombStatusMeme::Interpret(CCSBot *sender, CCSBot *receiver) const
{
// update our gamestate based on teammate's report
switch (m_state)
{
case CSGameState::MOVING:
{
receiver->GetGameState()->UpdateBomber(&m_pos);
// if we are hunting and see no enemies, respond
if (!receiver->IsRogue() && receiver->IsHunting() && receiver->GetNearbyEnemyCount() == 0)
// receiver->RespondToHelpRequest(sender, TheNavAreaGrid.GetPlace(&m_pos));
break;
}
case CSGameState::LOOSE:
{
receiver->GetGameState()->UpdateLooseBomb(&m_pos);
if (receiver->GetTask() == CCSBot::GUARD_BOMB_ZONE)
{
receiver->Idle();
receiver->GetChatter()->Affirmative();
}
break;
}
}
}
#endif
// A teammate has asked that we follow him
void BotFollowMeme::Interpret(CCSBot *sender, CCSBot *receiver) const
@ -194,49 +142,12 @@ void BotDefendHereMeme::Interpret(CCSBot *sender, CCSBot *receiver) const
receiver->GetChatter()->Say("Affirmative");
}
// A teammate has asked where the bomb is planted
#if 0
void BotWhereBombMeme::Interpret(CCSBot *sender, CCSBot *receiver) const
{
int zone = receiver->GetGameState()->GetPlantedBombsite();
if (zone != CSGameState::UNKNOWN)
receiver->GetChatter()->FoundPlantedBomb(zone);
}
#endif
// A teammate has asked us to report in
void BotRequestReportMeme::Interpret(CCSBot *sender, CCSBot *receiver) const
{
receiver->GetChatter()->ReportingIn();
}
#if 0
// A teammate told us all the hostages are gone
void BotAllHostagesGoneMeme::Interpret(CCSBot *sender, CCSBot *receiver) const
{
// receiver->GetGameState()->AllHostagesGone();
// acknowledge
receiver->GetChatter()->Say("Affirmative");
}
// A teammate told us a CT is talking to a hostage
void BotHostageBeingTakenMeme::Interpret(CCSBot *sender, CCSBot *receiver) const
{
// receiver->GetGameState()->HostageWasTaken();
// if we're busy, ignore
if (receiver->IsBusy())
return;
receiver->Idle();
// acknowledge
receiver->GetChatter()->Say("Affirmative");
}
#endif
BotSpeakable::BotSpeakable()
{
@ -936,15 +847,6 @@ bool BotStatement::IsObsolete() const
return true;
}
#if 0
// If we're wanting to say "I lost him" but we've spotted another enemy,
// we no longer need to report losing someone.
if (GetOwner()->GetChatter()->SeesAtLeastOneEnemy() && m_type == REPORT_ENEMY_LOST)
{
return true;
}
#endif
// check if statement lifetime has expired
return (gpGlobals->time > m_expireTime);
}
@ -1618,13 +1520,7 @@ BotStatement *BotChatterInterface::GetActiveStatement()
bool BotChatterInterface::ShouldSpeak() const
{
// don't talk to non-existent friends
//if (m_me->GetFriendsRemaining() == 0)
//return false;
// if everyone is together, no need to tell them what's going on
//if (m_me->GetNearbyFriendCount() == m_me->GetFriendsRemaining())
//return false;
/// speak?
return true;
}
@ -1695,54 +1591,7 @@ void BotChatterInterface::ReportingIn()
// where are we
Place place = m_me->GetPlace();
SayWhere(say, place);
#if 0
// what are we doing
switch (m_me->GetTask())
{
case CCSBot::PLANT_BOMB:
{
m_me->GetChatter()->GoingToPlantTheBomb(UNDEFINED_PLACE);
break;
}
case CCSBot::DEFUSE_BOMB:
{
m_me->GetChatter()->Say("DefusingBomb");
break;
}
case CCSBot::GUARD_LOOSE_BOMB:
{
if (ctrl->GetLooseBomb())
{
say->AppendPhrase(TheBotPhrases->GetPhrase("GuardingLooseBomb"));
say->AttachMeme(new BotBombStatusMeme(CSGameState::LOOSE, ctrl->GetLooseBomb()->pev->origin));
}
break;
}
case CCSBot::GUARD_HOSTAGES:
{
m_me->GetChatter()->GuardingHostages(UNDEFINED_PLACE, !m_me->IsAtHidingSpot());
break;
}
case CCSBot::GUARD_HOSTAGE_RESCUE_ZONE:
{
m_me->GetChatter()->GuardingHostageEscapeZone(!m_me->IsAtHidingSpot());
break;
}
case CCSBot::COLLECT_HOSTAGES:
{
break;
}
case CCSBot::RESCUE_HOSTAGES:
{
m_me->GetChatter()->EscortingHostages();
break;
}
case CCSBot::GUARD_VIP_ESCAPE_ZONE:
{
break;
}
}
#endif
// what do we see
if (m_me->IsAttacking())
{
@ -1897,189 +1746,7 @@ void BotChatterInterface::Negative()
say->AppendPhrase(TheBotPhrases->GetPhrase("Negative"));
AddStatement(say);
}
#if 0
void BotChatterInterface::GoingToPlantTheBomb(Place place)
{
if (TheCSBots()->IsRoundOver())
return;
const float minInterval = 10.0f; // 20.0f
if (m_planInterval.IsLessThen(minInterval))
return;
m_planInterval.Reset();
BotStatement *say = new BotStatement(this, REPORT_CRITICAL_EVENT, 10.0f);
say->AppendPhrase(TheBotPhrases->GetPhrase("GoingToPlantBomb"));
say->SetPlace(place);
say->AttachMeme(new BotFollowMeme());
AddStatement(say);
}
void BotChatterInterface::PlantingTheBomb(Place place)
{
if (TheCSBots()->IsRoundOver())
return;
BotStatement *say = new BotStatement(this, REPORT_CRITICAL_EVENT, 10.0f);
say->AppendPhrase(TheBotPhrases->GetPhrase("PlantingBomb"));
say->SetPlace(place);
say->AttachMeme(new BotDefendHereMeme(m_me->pev->origin));
AddStatement(say);
}
void BotChatterInterface::TheyPickedUpTheBomb()
{
if (TheCSBots()->IsRoundOver())
return;
// if we already know the bomb is not loose, this is old news
if (!m_me->GetGameState()->IsBombLoose())
return;
// update our gamestate - use our own position for now
m_me->GetGameState()->UpdateBomber(&m_me->pev->origin);
// tell our teammates
BotStatement *say = new BotStatement(this, REPORT_INFORMATION, 10.0f);
say->AppendPhrase(TheBotPhrases->GetPhrase("TheyPickedUpTheBomb"));
say->AttachMeme(new BotBombStatusMeme(CSGameState::MOVING, m_me->pev->origin));
AddStatement(say);
}
void BotChatterInterface::SpottedBomber(CBasePlayer *bomber)
{
if (m_me->GetGameState()->IsBombMoving())
{
// if we knew where the bomber was, this is old news
const Vector *bomberPos = m_me->GetGameState()->GetBombPosition();
const float closeRangeSq = 1000.0f * 1000.0f;
if (bomberPos != NULL && (bomber->pev->origin - *bomberPos).LengthSquared() < closeRangeSq)
return;
}
// update our gamestate
m_me->GetGameState()->UpdateBomber(&bomber->pev->origin);
// tell our teammates
BotStatement *say = new BotStatement(this, REPORT_INFORMATION, 10.0f);
// where is the bomber
Place place = TheNavAreaGrid.GetPlace(&bomber->pev->origin);
SayWhere(say, place);
say->AppendPhrase(TheBotPhrases->GetPhrase("SpottedBomber"));
say->SetSubject(bomber->entindex());
//say->AttachMeme(new BotHelpMeme(place));
say->AttachMeme(new BotBombStatusMeme(CSGameState::MOVING, bomber->pev->origin));
AddStatement(say);
}
void BotChatterInterface::SpottedLooseBomb(CBaseEntity *bomb)
{
if (TheCSBots()->IsRoundOver())
return;
// if we already know the bomb is loose, this is old news
if (m_me->GetGameState()->IsBombLoose())
return;
// update our gamestate
m_me->GetGameState()->UpdateLooseBomb(&bomb->pev->origin);
if (m_spottedLooseBombTimer.IsElapsed())
{
// throttle frequency
m_spottedLooseBombTimer.Start(10.0f);
// tell our teammates
BotStatement *say = new BotStatement(this, REPORT_INFORMATION, 10.0f);
// where is the bomb
Place place = TheNavAreaGrid.GetPlace(&bomb->pev->origin);
SayWhere(say, place);
say->AppendPhrase(TheBotPhrases->GetPhrase("SpottedLooseBomb"));
if (TheCSBots()->GetLooseBomb())
say->AttachMeme(new BotBombStatusMeme(CSGameState::LOOSE, bomb->pev->origin));
AddStatement(say);
}
}
NOXREF void BotChatterInterface::GuardingLooseBomb(CBaseEntity *bomb)
{
if (TheCSBots()->IsRoundOver() || !bomb)
return;
const float minInterval = 20.0f;
if (m_planInterval.IsLessThen(minInterval))
return;
m_planInterval.Reset();
// update our gamestate
m_me->GetGameState()->UpdateLooseBomb(&bomb->pev->origin);
// tell our teammates
BotStatement *say = new BotStatement(this, REPORT_INFORMATION, 10.0f);
// where is the bomb
Place place = TheNavAreaGrid.GetPlace(&bomb->pev->origin);
SayWhere(say, place);
say->AppendPhrase(TheBotPhrases->GetPhrase("GuardingLooseBomb"));
if (TheCSBots()->GetLooseBomb())
say->AttachMeme(new BotBombStatusMeme(CSGameState::LOOSE, bomb->pev->origin));
AddStatement(say);
}
void BotChatterInterface::RequestBombLocation()
{
// only ask once per round
if (m_requestedBombLocation)
return;
m_requestedBombLocation = true;
// tell our teammates
BotStatement *say = new BotStatement(this, REPORT_REQUEST_INFORMATION, 10.0f);
say->AppendPhrase(TheBotPhrases->GetPhrase("WhereIsTheBomb"));
say->AttachMeme(new BotWhereBombMeme());
AddStatement(say);
}
void BotChatterInterface::BombsiteClear(int zoneIndex)
{
const CCSBotManager::Zone *zone = TheCSBots()->GetZone(zoneIndex);
if (zone == NULL)
return;
BotStatement *say = new BotStatement(this, REPORT_INFORMATION, 10.0f);
SayWhere(say, TheNavAreaGrid.GetPlace(&zone->m_center));
say->AppendPhrase(TheBotPhrases->GetPhrase("BombsiteClear"));
say->AttachMeme(new BotBombsiteStatusMeme(zoneIndex, BotBombsiteStatusMeme::CLEAR));
AddStatement(say);
}
void BotChatterInterface::FoundPlantedBomb(int zoneIndex)
{
const CCSBotManager::Zone *zone = TheCSBots()->GetZone(zoneIndex);
if (zone == NULL)
return;
BotStatement *say = new BotStatement(this, REPORT_INFORMATION, 3.0f);
say->AppendPhrase(TheBotPhrases->GetPhrase("PlantedBombPlace"));
say->SetPlace(TheNavAreaGrid.GetPlace(&zone->m_center));
say->AttachMeme(new BotBombsiteStatusMeme(zoneIndex, BotBombsiteStatusMeme::PLANTED));
AddStatement(say);
}
#endif
void BotChatterInterface::Scared()
{
const float minInterval = 10.0f;
@ -2142,119 +1809,3 @@ void BotChatterInterface::AnnouncePlan(const char *phraseName, Place place)
say->SetStartTime(ctrl->GetRoundStartTime() + RANDOM_FLOAT(2.0, 3.0f));
AddStatement(say);
}
#if 0
void BotChatterInterface::GuardingHostages(Place place, bool isPlan)
{
if (TheCSBots()->IsRoundOver())
return;
const float minInterval = 20.0f;
if (m_planInterval.IsLessThen(minInterval))
return;
m_planInterval.Reset();
if (isPlan)
AnnouncePlan("GoingToGuardHostages", place);
else
Say("GuardingHostages");
}
void BotChatterInterface::GuardingHostageEscapeZone(bool isPlan)
{
if (TheCSBots()->IsRoundOver())
return;
const float minInterval = 20.0f;
if (m_planInterval.IsLessThen(minInterval))
return;
m_planInterval.Reset();
if (isPlan)
AnnouncePlan("GoingToGuardHostageEscapeZone", UNDEFINED_PLACE);
else
Say("GuardingHostageEscapeZone");
}
void BotChatterInterface::HostagesBeingTaken()
{
if (TheCSBots()->IsRoundOver())
return;
BotStatement *say = new BotStatement(this, REPORT_INFORMATION, 3.0f);
say->AppendPhrase(TheBotPhrases->GetPhrase("HostagesBeingTaken"));
say->AttachMeme(new BotHostageBeingTakenMeme());
AddStatement(say);
}
void BotChatterInterface::HostagesTaken()
{
if (TheCSBots()->IsRoundOver())
return;
BotStatement *say = new BotStatement(this, REPORT_INFORMATION, 3.0f);
say->AppendPhrase(TheBotPhrases->GetPhrase("HostagesTaken"));
AddStatement(say);
}
void BotChatterInterface::TalkingToHostages()
{
;
}
void BotChatterInterface::EscortingHostages()
{
if (TheCSBots()->IsRoundOver())
return;
if (m_escortingHostageTimer.IsElapsed())
{
// throttle frequency
m_escortingHostageTimer.Start(10.0f);
BotStatement *say = new BotStatement(this, REPORT_MY_PLAN, 5.0f);
say->AppendPhrase(TheBotPhrases->GetPhrase("EscortingHostages"));
AddStatement(say);
}
}
NOXREF void BotChatterInterface::HostageDown()
{
if (TheCSBots()->IsRoundOver())
return;
BotStatement *say = new BotStatement(this, REPORT_INFORMATION, 3.0f);
say->AppendPhrase(TheBotPhrases->GetPhrase("HostageDown"));
AddStatement(say);
}
void BotChatterInterface::Encourage(const char *phraseName, float repeatInterval, float lifetime)
{
if (m_encourageTimer.IsElapsed())
{
Say(phraseName, lifetime);
m_encourageTimer.Start(repeatInterval);
}
}
void BotChatterInterface::KilledFriend()
{
BotStatement *say = new BotStatement(this, REPORT_KILLED_FRIEND, 2.0f);
say->AppendPhrase(TheBotPhrases->GetPhrase("KilledFriend"));
// give them time to react
say->SetStartTime(gpGlobals->time + RANDOM_FLOAT(0.5f, 1.0f));
AddStatement(say);
}
void BotChatterInterface::FriendlyFire()
{
BotStatement *say = new BotStatement(this, REPORT_FRIENDLY_FIRE, 1.0f);
say->AppendPhrase(TheBotPhrases->GetPhrase("FriendlyFire"));
// give them time to react
say->SetStartTime(gpGlobals->time + RANDOM_FLOAT(0.3f, 0.5f));
AddStatement(say);
}
#endif

View File

@ -54,19 +54,6 @@ public:
void Transmit(CCSBot *sender) const; // transmit meme to other bots
virtual void Interpret(CCSBot *sender, CCSBot *receiver) const = 0; // cause the given bot to act on this meme
};
#if 0
class BotAllHostagesGoneMeme: public BotMeme
{
public:
virtual void Interpret(CCSBot *sender, CCSBot *receiver) const; // cause the given bot to act on this meme
};
class BotHostageBeingTakenMeme: public BotMeme
{
public:
virtual void Interpret(CCSBot *sender, CCSBot *receiver) const; // cause the given bot to act on this meme
};
#endif
class BotHelpMeme: public BotMeme
{
public:
@ -79,41 +66,6 @@ public:
private:
Place m_place;
};
#if 0
class BotBombsiteStatusMeme: public BotMeme
{
public:
enum StatusType { CLEAR, PLANTED };
BotBombsiteStatusMeme(int zoneIndex, StatusType status)
{
m_zoneIndex = zoneIndex;
m_status = status;
}
virtual void Interpret(CCSBot *sender, CCSBot *receiver) const; // cause the given bot to act on this meme
private:
int m_zoneIndex; // the bombsite
StatusType m_status; // whether it is cleared or the bomb is there (planted)
};
class BotBombStatusMeme: public BotMeme
{
public:
BotBombStatusMeme(CSGameState::BombState state, const Vector &pos)
{
m_state = state;
m_pos = pos;
}
public:
virtual void Interpret(CCSBot *sender, CCSBot *receiver) const; // cause the given bot to act on this meme
private:
CSGameState::BombState m_state;
Vector m_pos;
};
#endif
class BotFollowMeme: public BotMeme
{
public:
@ -133,13 +85,6 @@ private:
Vector m_pos;
};
#if 0
class BotWhereBombMeme: public BotMeme
{
public:
virtual void Interpret(CCSBot *sender, CCSBot *receiver) const; // cause the given bot to act on this meme
};
#endif
class BotRequestReportMeme: public BotMeme
{
@ -501,26 +446,6 @@ public:
void PinnedDown();
void Scared();
void HeardNoise(const Vector *pos);
#if 0
void TheyPickedUpTheBomb();
void GoingToPlantTheBomb(Place place);
void BombsiteClear(int zoneIndex);
void FoundPlantedBomb(int zoneIndex);
void PlantingTheBomb(Place place);
void SpottedBomber(CBasePlayer *bomber);
void SpottedLooseBomb(CBaseEntity *bomb);
NOXREF void GuardingLooseBomb(CBaseEntity *bomb);
void RequestBombLocation();
#define IS_PLAN true
void GuardingHostages(Place place, bool isPlan = false);
void GuardingHostageEscapeZone(bool isPlan = false);
void HostagesBeingTaken();
void HostagesTaken();
void TalkingToHostages();
void EscortingHostages();
NOXREF void HostageDown();
#endif
void CelebrateWin();
void Encourage(const char *phraseName, float repeatInterval = 10.0f, float lifetime = 3.0f); // "encourage" the player to do the scenario

View File

@ -2,35 +2,10 @@
void CCSBot::OnEvent(GameEventType event, CBaseEntity *entity, CBaseEntity *other)
{
#if 0
GetGameState()->OnEvent(event, entity, other);
GetChatter()->OnEvent(event, entity, other);
// Morale adjustments happen even for dead players
/* switch (event)
{
case EVENT_TERRORISTS_WIN:
if (m_iTeam == CT)
{
DecreaseMorale();
}
else
{
IncreaseMorale();
}
break;
case EVENT_CTS_WIN:
if (m_iTeam == CT)
{
IncreaseMorale();
}
else
{
DecreaseMorale();
}
break;
}*/
if (!IsAlive())
return;
@ -42,6 +17,7 @@ void CCSBot::OnEvent(GameEventType event, CBaseEntity *entity, CBaseEntity *othe
{
if (event == EVENT_PLAYER_DIED)
{
#if 0
if (player->m_iTeam == m_iTeam)
{
CBasePlayer *killer = static_cast<CBasePlayer *>(other);
@ -67,11 +43,13 @@ void CCSBot::OnEvent(GameEventType event, CBaseEntity *entity, CBaseEntity *othe
}
}
}
#endif
}
}
switch (event)
{
#if 0
case EVENT_PLAYER_DIED:
{
CBasePlayer *victim = player;
@ -159,75 +137,7 @@ void CCSBot::OnEvent(GameEventType event, CBaseEntity *entity, CBaseEntity *othe
}
return;
}
case EVENT_TERRORISTS_WIN:
if (m_iTeam == TERRORIST)
GetChatter()->CelebrateWin();
return;
case EVENT_CTS_WIN:
if (m_iTeam == CT)
GetChatter()->CelebrateWin();
return;
case EVENT_BOMB_DEFUSED:
if (m_iTeam == CT && TheCSBots()->GetBombTimeLeft() < 2.0)
GetChatter()->Say("BarelyDefused");
return;
case EVENT_BOMB_PICKED_UP:
{
if (m_iTeam == CT && player != NULL)
{
// check if we're close enough to hear it
const float bombPickupHearRangeSq = 1000.0f * 1000.0f;
if ((pev->origin - player->pev->origin).LengthSquared() < bombPickupHearRangeSq)
{
GetChatter()->TheyPickedUpTheBomb();
}
}
return;
}
case EVENT_BOMB_BEEP:
{
// if we don't know where the bomb is, but heard it beep, we've discovered it
if (GetGameState()->IsPlantedBombLocationKnown() == false)
{
// check if we're close enough to hear it
const float bombBeepHearRangeSq = 1000.0f * 1000.0f;
if ((pev->origin - entity->pev->origin).LengthSquared() < bombBeepHearRangeSq)
{
// radio the news to our team
if (m_iTeam == CT && GetGameState()->GetPlantedBombsite() == CSGameState::UNKNOWN)
{
const CCSBotManager::Zone *zone = TheCSBots()->GetZone(&entity->pev->origin);
if (zone != NULL)
GetChatter()->FoundPlantedBomb(zone->m_index);
}
// remember where the bomb is
GetGameState()->UpdatePlantedBomb(&entity->pev->origin);
}
}
return;
}
case EVENT_BOMB_PLANTED:
{
// if we're a CT, forget what we're doing and go after the bomb
if (m_iTeam == CT)
{
Idle();
}
// if we are following someone, stop following
if (IsFollowing())
{
StopFollowing();
Idle();
}
OnEvent(EVENT_BOMB_BEEP, other);
return;
}
case EVENT_BOMB_DEFUSE_ABORTED:
PrintIfWatched("BOMB DEFUSE ABORTED\n");
return;
#endif
case EVENT_WEAPON_FIRED:
case EVENT_WEAPON_FIRED_ON_EMPTY:
case EVENT_WEAPON_RELOADED:
@ -241,7 +151,7 @@ void CCSBot::OnEvent(GameEventType event, CBaseEntity *entity, CBaseEntity *othe
}
// Process radio events from our team
if (player != NULL && player->m_iTeam == m_iTeam && event > EVENT_START_RADIO_1 && event < EVENT_END_RADIO)
if (player != NULL && event > EVENT_START_RADIO_1 && event < EVENT_END_RADIO)
{
// TODO: Distinguish between radio commands and responses
if (event != EVENT_RADIO_AFFIRMATIVE && event != EVENT_RADIO_NEGATIVE && event != EVENT_RADIO_REPORTING_IN)
@ -257,28 +167,6 @@ void CCSBot::OnEvent(GameEventType event, CBaseEntity *entity, CBaseEntity *othe
if (player == NULL)
return;
if (!IsRogue() && event == EVENT_HOSTAGE_CALLED_FOR_HELP && m_iTeam == CT && IsHunting())
{
if ((entity->pev->origin - pev->origin).IsLengthGreaterThan(1000.0f))
return;
Vector v = entity->Center();
if (IsVisible(&v))
{
m_task = COLLECT_HOSTAGES;
m_taskEntity = NULL;
Run();
m_goalEntity = entity;
MoveTo(&entity->pev->origin, (RouteType)(m_hostageEscortCount == 0));
PrintIfWatched("I'm fetching a hostage that called out to me\n");
return;
}
}
// don't pay attention to noise that friends make
if (!IsEnemy(player))
return;
@ -290,26 +178,6 @@ void CCSBot::OnEvent(GameEventType event, CBaseEntity *entity, CBaseEntity *othe
if (IsGameEventAudible(event, entity, other, &range, &priority, &isHostile) == false)
return;
if (event == EVENT_HOSTAGE_USED)
{
if (m_iTeam == CT)
return;
if ((entity->pev->origin - pev->origin).IsLengthGreaterThan(range))
return;
GetChatter()->HostagesBeingTaken();
if (!GetGameState()->GetNearestVisibleFreeHostage() && m_task != GUARD_HOSTAGE_RESCUE_ZONE && GuardRandomZone())
{
m_task = GUARD_HOSTAGE_RESCUE_ZONE;
m_taskEntity = NULL;
SetDisposition(OPPORTUNITY_FIRE);
PrintIfWatched("Trying to beat them to an escape zone!\n");
}
}
// check if noise is close enough for us to hear
const Vector *newNoisePosition = &player->pev->origin;
float newNoiseDist = (pev->origin - *newNoisePosition).Length();
@ -384,5 +252,4 @@ void CCSBot::OnEvent(GameEventType event, CBaseEntity *entity, CBaseEntity *othe
m_noiseTimestamp = gpGlobals->time;
}
#endif
}

View File

@ -221,10 +221,6 @@ void CCSBot::ResetValues()
m_lastRadioSentTimestamp = 0.0f;
m_radioSubject = NULL;
m_voiceFeedbackEndTimestamp = 0.0f;
#if 0
m_hostageEscortCount = 0;
m_hostageEscortCountTimestamp = 0.0f;
#endif
m_noisePosition = Vector(0, 0, 0);
m_noiseTimestamp = 0.0f;
m_noiseCheckTimestamp = 0.0f;

View File

@ -40,13 +40,6 @@ CCSBotManager::CCSBotManager()
TheBotProfiles->FindVoiceBankIndex("BotChatter.db");
const char *filename;
#if 0
if (IS_CAREER_MATCH())
{
filename = "MissionPacks/BotPackList.db";
}
else
#endif
{
filename = "BotPackList.db";
}
@ -190,28 +183,6 @@ void CCSBotManager::StartFrame()
bool CCSBotManager::IsWeaponUseable(CBasePlayerItem *item) const
{
if (item == NULL)
{
return false;
}
// if (item->m_iId == WEAPON_C4)
// return true;
// int weaponClass = WeaponIDToWeaponClass(item->m_iId);
#if 0
if ((!AllowShotguns() && weaponClass == WEAPONCLASS_SHOTGUN)
|| (!AllowMachineGuns() && weaponClass == WEAPONCLASS_MACHINEGUN)
|| (!AllowRifles() && weaponClass == WEAPONCLASS_RIFLE)
|| (!AllowSnipers() && weaponClass == WEAPONCLASS_SNIPERRIFLE)
|| (!AllowSubMachineGuns() && weaponClass == WEAPONCLASS_SUBMACHINEGUN)
|| (!AllowTacticalShield() && item->m_iId == WEAPON_SHIELDGUN)
|| (!AllowPistols() && weaponClass == WEAPONCLASS_PISTOL)
|| (!AllowGrenades() && weaponClass == WEAPONCLASS_GRENADE))
{
return false;
}
#endif
return true;
}
@ -219,19 +190,6 @@ bool CCSBotManager::IsWeaponUseable(CBasePlayerItem *item) const
bool CCSBotManager::IsOnDefense(CBasePlayer *player) const
{
#if 0
switch (GetScenario())
{
case SCENARIO_DEFUSE_BOMB:
return (player->m_iTeam == CT);
case SCENARIO_RESCUE_HOSTAGES:
return (player->m_iTeam == TERRORIST);
case SCENARIO_ESCORT_VIP:
return (player->m_iTeam == TERRORIST);
}
#endif
return false;
}
@ -804,7 +762,7 @@ bool CCSBotManager::BotAddCommand(BotProfileTeamType team, bool isFromConsole)
{
// in career, ignore humans
bool ignoreHumans = false;
#warning "Will crash in non-deathmatch"
CHalfLifeMultiplay *mp = (CHalfLifeMultiplay*)g_pGameRules;
//if (mp != NULL && mp->IsCareer())
@ -843,7 +801,7 @@ void CCSBotManager::MaintainBotQuota()
{
if (m_isLearningMap)
return;
#warning "will crash in non-deathmatch"
CHalfLifeMultiplay *mp = (CHalfLifeMultiplay *) g_pGameRules;
int totalHumansInGame = UTIL_HumansInGame();
int humanPlayersInGame = UTIL_HumansInGame(IGNORE_SPECTATORS);
@ -882,74 +840,10 @@ void CCSBotManager::MaintainBotQuota()
}
else if (desiredBotCount < botsInGame)
{
// kick a bot to maintain quota
// first remove any unassigned bots
//if (UTIL_KickBotFromTeam(0))
// return;
#if 0
//TeamName kickTeam;
// remove from the team that has more players
if (mp->m_iNumTerrorist > mp->m_iNumCT)
{
kickTeam = TERRORIST;
}
else if (mp->m_iNumTerrorist < mp->m_iNumCT)
{
kickTeam = CT;
}
// remove from the team that's winning
else if (mp->m_iNumTerroristWins > mp->m_iNumCTWins)
{
kickTeam = TERRORIST;
}
else if (mp->m_iNumCTWins > mp->m_iNumTerroristWins)
{
kickTeam = CT;
}
else
{
// teams and scores are equal, pick a team at random
kickTeam = (RANDOM_LONG(0, 1) == 0) ? CT : TERRORIST;
}
// attempt to kick a bot from the given team
if (UTIL_KickBotFromTeam(kickTeam))
return;
// if there were no bots on the team, kick a bot from the other team
if (kickTeam == TERRORIST)
UTIL_KickBotFromTeam(CT);
else
UTIL_KickBotFromTeam(TERRORIST);
#endif
UTIL_KickBot();
}
else
{
#if 0
if (mp != NULL && !mp->IsCareer())
return;
bool humansAreCTs = (Q_strcmp(humans_join_team.string, "CT") == 0);
if (humansAreCTs)
{
if (mp->m_iNumCT <= 6)
return;
UTIL_KickBotFromTeam(CT);
}
else
{
if (mp->m_iNumTerrorist <= 6)
return;
UTIL_KickBotFromTeam(TERRORIST);
}
CVAR_SET_FLOAT("bot_quota", cv_bot_quota.value - 1.0f);
#endif
}
}
@ -1147,45 +1041,6 @@ void CCSBotManager::ValidateMapData()
bool CCSBotManager::AddBot(const BotProfile *profile, BotProfileTeamType team)
{
// if (!g_bEnableCSBot)
// return false;
#if 0
CHalfLifeMultiplay *mp = (CHalfLifeMultiplay *)g_pGameRules;
int nTeamSlot = UNASSIGNED;
if (team == BOT_TEAM_ANY)
{
// if team not specified, check cv_bot_join_team cvar for preference
if (!Q_stricmp(cv_bot_join_team.string, "T"))
nTeamSlot = TERRORIST;
else if (!Q_stricmp(cv_bot_join_team.string, "CT"))
nTeamSlot = CT;
}
else if (team == BOT_TEAM_CT)
nTeamSlot = CT;
else if (team == BOT_TEAM_T)
nTeamSlot = TERRORIST;
if (nTeamSlot == UNASSIGNED)
{
nTeamSlot = SelectDefaultTeam();
}
if (nTeamSlot == UNASSIGNED || mp->TeamFull(nTeamSlot))
{
CONSOLE_ECHO("Could not add bot to the game: Team is full\n");
return false;
}
if (mp->TeamStacked(nTeamSlot, UNASSIGNED))
{
CONSOLE_ECHO("Could not add bot to the game: Team is stacked (to disable this check, set mp_limitteams and mp_autoteambalance to zero and restart the round).\n");
return false;
}
#endif
CCSBot *pBot = CreateBot<CCSBot>(profile);
if (pBot == NULL)
{
@ -1196,32 +1051,9 @@ bool CCSBotManager::AddBot(const BotProfile *profile, BotProfileTeamType team)
//int nJoinedTeam;
ClientPutInServer(pBot->edict());
SET_CLIENT_KEY_VALUE(pBot->entindex(), GET_INFO_BUFFER(pBot->edict()), "*bot", "1");
#if 0
pBot->m_iMenu = Menu_ChooseTeam;
pBot->m_iJoiningState = PICKINGTEAM;
if (HandleMenu_ChooseTeam(pBot, nTeamSlot))
{
int skin = profile->GetSkin();
if (!skin)
skin = 6;// MODEL_GIGN?
HandleMenu_ChooseAppearance(pBot, skin);
if (IS_DEDICATED_SERVER())
{
UTIL_DPrintf("Added bot %s to server\n", STRING(pBot->pev->netname));
}
return true;
}
SERVER_COMMAND(UTIL_VarArgs("kick \"%s\"\n", STRING(pBot->pev->netname)));
CONSOLE_ECHO("Could not add bot to the game.\n");
#endif
return false;
ALERT( at_console, "Added bot %s to server\n", STRING(pBot->pev->netname));
return true;
}
// Return the zone that contains the given position
@ -1375,31 +1207,6 @@ void CCSBotManager::SetLooseBomb(CBaseEntity *bomb)
bool CCSBotManager::IsImportantPlayer(CBasePlayer *player) const
{
#if 0
switch (GetScenario())
{
case SCENARIO_DEFUSE_BOMB:
{
if (player->m_iTeam == TERRORIST && player->IsBombGuy())
return true;
// TODO: CT's defusing the bomb are important
return false;
}
case SCENARIO_ESCORT_VIP:
{
if (player->m_iTeam == CT && player->m_bIsVIP)
return true;
return false;
}
case SCENARIO_RESCUE_HOSTAGES:
{
// TODO: CT's escorting hostages are important
return false;
}
}
#endif
// everyone is equally important in a deathmatch
return false;
}
@ -1421,36 +1228,6 @@ unsigned int CCSBotManager::GetPlayerPriority(CBasePlayer *player) const
if (!bot)
return 0;
#if 0
// bots doing something important for the current scenario have high priority
switch (GetScenario())
{
case SCENARIO_DEFUSE_BOMB:
{
// the bomb carrier has high priority
if (bot->m_iTeam == TERRORIST && bot->m_bHasC4)
return 1;
break;
}
case SCENARIO_ESCORT_VIP:
{
// the VIP has high priority
if (bot->m_iTeam == CT && bot->m_bIsVIP)
return 1;
break;
}
case SCENARIO_RESCUE_HOSTAGES:
{
// CT's rescuing hostages have high priority
if (bot->m_iTeam == CT && bot->GetHostageEscortCount())
return 1;
break;
}
}
#endif
// everyone else is ranked by their unique ID (which cannot be zero)
return 1 + bot->GetID();
}
@ -1460,22 +1237,14 @@ unsigned int CCSBotManager::GetPlayerPriority(CBasePlayer *player) const
float CCSBotManager::GetRadioMessageTimestamp(GameEventType event, int teamID) const
{
// if (event <= EVENT_START_RADIO_1 || event >= EVENT_END_RADIO)
// return 0.0f;
//int i = (teamID == TERRORIST) ? 0 : 1;
return 0;//m_radioMsgTimestamp[ event - EVENT_START_RADIO_1 ][ i ];
return 0;
}
// Return the interval since the last time this message was sent
float CCSBotManager::GetRadioMessageInterval(GameEventType event, int teamID) const
{
// if (event <= EVENT_START_RADIO_1 || event >= EVENT_END_RADIO)
return 99999999.9f;
// int i = (teamID == TERRORIST) ? 0 : 1;
// return gpGlobals->time - m_radioMsgTimestamp[ event - EVENT_START_RADIO_1 ][ i ];
return 1;
}
// Set the given radio message timestamp.
@ -1483,24 +1252,10 @@ float CCSBotManager::GetRadioMessageInterval(GameEventType event, int teamID) co
void CCSBotManager::SetRadioMessageTimestamp(GameEventType event, int teamID)
{
// if (event <= EVENT_START_RADIO_1 || event >= EVENT_END_RADIO)
return;
// int i = (teamID == TERRORIST) ? 0 : 1;
// m_radioMsgTimestamp[ event - 1 ][ i ] = gpGlobals->time;
}
// Reset all radio message timestamps
void CCSBotManager::ResetRadioMessageTimestamps()
{
#if 0
for (int t = 0; t < ARRAYSIZE(m_radioMsgTimestamp[0]); ++t)
{
for (int m = 0; m < ARRAYSIZE(m_radioMsgTimestamp); ++m)
{
m_radioMsgTimestamp[m][t] = 0.0f;
}
}
#endif
}

View File

@ -24,13 +24,7 @@ void CCSBot::Idle()
SetTask(SEEK_AND_DESTROY);
SetState(&m_idleState);
}
#if 0
void CCSBot::EscapeFromBomb()
{
// SetTask(ESCAPE_FROM_BOMB);
// SetState(&m_escapeFromBombState);
}
#endif
void CCSBot::Follow(CBasePlayer *player)
{
if (player == NULL)
@ -66,13 +60,6 @@ void CCSBot::StopFollowing()
m_allowAutoFollowTime = gpGlobals->time + 10.0f;
}
// Begin process of rescuing hostages
#if 0
void CCSBot::RescueHostages()
{
SetTask(RESCUE_HOSTAGES);
}
#endif
// Use the entity
void CCSBot::UseEntity(CBaseEntity *entity)
@ -335,26 +322,6 @@ bool CCSBot::IsAttacking() const
return m_isAttacking;
}
// Return true if we are escaping from the bomb
#if 0
bool CCSBot::IsEscapingFromBomb() const
{
// if (m_state == static_cast<const BotState *>(&m_escapeFromBombState))
// return true;
return false;
}
// Return true if we are defusing the bomb
bool CCSBot::IsDefusingBomb() const
{
// if (m_state == static_cast<const BotState *>(&m_defuseBombState))
// return true;
return false;
}
#endif
// Return true if we are hiding
bool CCSBot::IsHiding() const
@ -395,16 +362,6 @@ bool CCSBot::IsMovingTo() const
return false;
}
// Return true if we are buying
#if 0
bool CCSBot::IsBuying() const
{
// if (m_state == static_cast<const BotState *>(&m_buyState))
// return true;
return false;
}
#endif
// Move to potentially distant position
@ -415,24 +372,6 @@ void CCSBot::MoveTo(const Vector *pos, RouteType route)
SetState(&m_moveToState);
}
#if 0
void CCSBot::PlantBomb()
{
// SetState(&m_plantBombState);
}
// Bomb has been dropped - go get it
void CCSBot::FetchBomb()
{
// SetState(&m_fetchBombState);
}
void CCSBot::DefuseBomb()
{
// SetState(&m_defuseBombState);
}
#endif
// Investigate recent enemy noise

View File

@ -534,67 +534,7 @@ void CCSBot::Update()
// check encounter spots
UpdatePeripheralVision();
#if 0
// Update gamestate
if (m_bomber != NULL)
GetChatter()->SpottedBomber(GetBomber());
if (CanSeeLooseBomb())
GetChatter()->SpottedLooseBomb(ctrl->GetLooseBomb());
// Scenario interrupts
switch (ctrl->GetScenario())
{
case CCSBotManager::SCENARIO_DEFUSE_BOMB:
{
// flee if the bomb is ready to blow and we aren't defusing it or attacking and we know where the bomb is
// (aggressive players wait until its almost too late)
float gonnaBlowTime = 8.0f - (2.0f * GetProfile()->GetAggression());
// if we have a defuse kit, can wait longer
// if (m_bHasDefuser)
// gonnaBlowTime *= 0.66f;
if (!IsEscapingFromBomb() // we aren't already escaping the bomb
&& ctrl->IsBombPlanted() // is the bomb planted
&& GetGameState()->IsPlantedBombLocationKnown() // we know where the bomb is
&& ctrl->GetBombTimeLeft() < gonnaBlowTime // is the bomb about to explode
&& !IsDefusingBomb() // we aren't defusing the bomb
&& !IsAttacking()) // we aren't in the midst of a firefight
{
EscapeFromBomb();
break;
}
break;
}
case CCSBotManager::SCENARIO_RESCUE_HOSTAGES:
{
#if 0
if (m_iTeam == CT)
{
UpdateHostageEscortCount();
}
else
{
// Terrorists have imperfect information on status of hostages
CSGameState::ValidateStatusType status = GetGameState()->ValidateHostagePositions();
if (status & CSGameState::HOSTAGES_ALL_GONE)
{
GetChatter()->HostagesTaken();
Idle();
}
else if (status & CSGameState::HOSTAGE_GONE)
{
GetGameState()->HostageWasTaken();
Idle();
}
}
break;
#endif
}
}
#endif
// Follow nearby humans if our co-op is high and we have nothing else to do
// If we were just following someone, don't auto-follow again for a short while to
// give us a chance to do something else.
@ -713,38 +653,6 @@ void CCSBot::Update()
ResetStuckMonitor();
ClearMovement();
}
#endif
#if 0
// if we get too far ahead of the hostages we are escorting, wait for them
if (!IsAttacking() && m_inhibitWaitingForHostageTimer.IsElapsed())
{
const float waitForHostageRange = 500.0f;
if (GetTask() == RESCUE_HOSTAGES && GetRangeToFarthestEscortedHostage() > waitForHostageRange)
{
if (!m_isWaitingForHostage)
{
// just started waiting
m_isWaitingForHostage = true;
m_waitForHostageTimer.Start(10.0f);
}
else
{
// we've been waiting
if (m_waitForHostageTimer.IsElapsed())
{
// give up waiting for awhile
m_isWaitingForHostage = false;
m_inhibitWaitingForHostageTimer.Start(3.0f);
}
else
{
// keep waiting
ResetStuckMonitor();
ClearMovement();
}
}
}
}
#endif
// remember our prior safe time status
m_wasSafe = IsSafe();

View File

@ -437,29 +437,7 @@ void CCSBot::EquipBestWeapon(bool mustEquip)
CCSBotManager *ctrl = TheCSBots();
CBasePlayerWeapon *primary = static_cast<CBasePlayerWeapon *>(m_rgpPlayerItems[ 2 ]);
#if 0
if (primary != NULL)
{
WeaponClassType weaponClass = WeaponIDToWeaponClass(primary->m_iId);
if ((ctrl->AllowShotguns() && weaponClass == WEAPONCLASS_SHOTGUN)
|| (ctrl->AllowMachineGuns() && weaponClass == WEAPONCLASS_MACHINEGUN)
|| (ctrl->AllowRifles() && weaponClass == WEAPONCLASS_RIFLE)
|| (ctrl->AllowSnipers() && weaponClass == WEAPONCLASS_SNIPERRIFLE)
|| (ctrl->AllowSubMachineGuns() && weaponClass == WEAPONCLASS_SUBMACHINEGUN)
|| (ctrl->AllowTacticalShield() && primary->m_iId == WEAPON_SHIELDGUN))
{
if (DoEquip(primary))
return;
}
}
if (ctrl->AllowPistols())
{
if (DoEquip(static_cast<CBasePlayerWeapon *>(m_rgpPlayerItems[ 1 ])))
return;
}
#endif
/// TODO: hl
// always have a knife
EquipKnife();
}
@ -702,13 +680,10 @@ void CCSBot::ReloadCheck()
// don't bother to reload if there are no enemies left
if (GetEnemiesRemaining() == 0)
return;
#if 0
if (IsDefusingBomb() || IsActiveWeaponReloading())
return;
#else
if (IsActiveWeaponReloading())
return;
#endif
if (IsActiveWeaponClipEmpty())
{
#if 0

View File

@ -4,29 +4,7 @@ CSGameState::CSGameState(CCSBot *owner)
{
m_owner = owner;
m_isRoundOver = false;
// m_bombState = MOVING;
#if 0
m_lastSawBomber.Invalidate();
m_lastSawLooseBomb.Invalidate();
#endif
m_validateInterval.Invalidate();
// m_isPlantedBombPosKnown = false;
// m_plantedBombsite = UNKNOWN;
// m_bombsiteCount = 0;
// m_bombsiteSearchIndex = 0;
#if 0
for (int i = 0; i < MAX_HOSTAGES; ++i)
{
HostageInfo *info = &m_hostage[i];
info->hostage = NULL;
info->knownPos = Vector(0, 0, 0);
info->isValid = false;
info->isAlive = false;
info->isFree = true;
}
#endif
}
// Reset at round start
@ -37,71 +15,14 @@ void CSGameState::Reset()
CCSBotManager *ctrl = TheCSBots();
m_isRoundOver = false;
#if 0
// bomb
m_bombState = MOVING;
m_lastSawBomber.Invalidate();
m_lastSawLooseBomb.Invalidate();
m_bombsiteCount = ctrl->GetZoneCount();
m_isPlantedBombPosKnown = false;
m_plantedBombsite = UNKNOWN;
for (i = 0; i < m_bombsiteCount; ++i)
{
m_isBombsiteClear[i] = false;
m_bombsiteSearchOrder[i] = i;
}
// shuffle the bombsite search order
// allows T's to plant at random site, and CT's to search in a random order
// NOTE: VS6 std::random_shuffle() doesn't work well with an array of two elements (most maps)
for (i = 0; i < m_bombsiteCount; ++i)
{
int swap = m_bombsiteSearchOrder[i];
int rnd = RANDOM_LONG(i, m_bombsiteCount - 1);
m_bombsiteSearchOrder[i] = m_bombsiteSearchOrder[rnd];
m_bombsiteSearchOrder[rnd] = swap;
}
m_bombsiteSearchIndex = 0;
InitializeHostageInfo();
#endif
}
// Update game state based on events we have received
void CSGameState::OnEvent(GameEventType event, CBaseEntity *entity, CBaseEntity *other)
{
#if 0
switch (event)
{
case EVENT_BOMB_PLANTED:
SetBombState(PLANTED);
if (m_owner->m_iTeam == TERRORIST && other != NULL)
{
UpdatePlantedBomb(&other->pev->origin);
}
break;
case EVENT_BOMB_DEFUSED:
SetBombState(DEFUSED);
break;
case EVENT_BOMB_EXPLODED:
SetBombState(EXPLODED);
break;
case EVENT_ALL_HOSTAGES_RESCUED:
m_allHostagesRescued = true;
break;
case EVENT_TERRORISTS_WIN:
case EVENT_CTS_WIN:
case EVENT_ROUND_DRAW:
m_isRoundOver = true;
break;
default:
break;
}
#endif
}
// True if round has been won or lost (but not yet reset)
@ -110,587 +31,3 @@ bool CSGameState::IsRoundOver() const
{
return m_isRoundOver;
}
#if 0
void CSGameState::SetBombState(BombState state)
{
// if state changed, reset "last seen" timestamps
if (m_bombState != state)
{
m_bombState = state;
}
}
void CSGameState::UpdateLooseBomb(const Vector *pos)
{
m_looseBombPos = *pos;
m_lastSawLooseBomb.Reset();
// we saw the loose bomb, update our state
SetBombState(LOOSE);
}
float CSGameState::TimeSinceLastSawLooseBomb() const
{
return m_lastSawLooseBomb.GetElapsedTime();
}
bool CSGameState::IsLooseBombLocationKnown() const
{
if (m_bombState != LOOSE)
return false;
return (m_lastSawLooseBomb.HasStarted()) ? true : false;
}
void CSGameState::UpdateBomber(const Vector *pos)
{
m_bomberPos = *pos;
m_lastSawBomber.Reset();
// we saw the bomber, update our state
SetBombState(MOVING);
}
float CSGameState::TimeSinceLastSawBomber() const
{
return m_lastSawBomber.GetElapsedTime();
}
bool CSGameState::IsPlantedBombLocationKnown() const
{
// if (m_bombState != PLANTED)
// return false;
return false;//m_isPlantedBombPosKnown;
}
// Return the zone index of the planted bombsite, or UNKNOWN
int CSGameState::GetPlantedBombsite() const
{
//if (m_bombState != PLANTED)
return UNKNOWN;
//return m_plantedBombsite;
}
// Return true if we are currently in the bombsite where the bomb is planted
bool CSGameState::IsAtPlantedBombsite() const
{
#if 0
if (m_bombState != PLANTED)
return false;
CCSBotManager *ctrl = TheCSBots();
const CCSBotManager::Zone *zone = ctrl->GetClosestZone(&m_owner->pev->origin);
if (zone != NULL)
{
return (m_plantedBombsite == zone->m_index);
}
#endif
return false;
}
// Return the zone index of the next bombsite to search
int CSGameState::GetNextBombsiteToSearch()
{
// if (m_bombsiteCount <= 0)
return 0;
#if 0
int i;
// return next non-cleared bombsite index
for (i = m_bombsiteSearchIndex; i < m_bombsiteCount; ++i)
{
int z = m_bombsiteSearchOrder[i];
if (!m_isBombsiteClear[z])
{
m_bombsiteSearchIndex = i;
return z;
}
}
// all the bombsites are clear, someone must have been mistaken - start search over
for (i = 0; i < m_bombsiteCount; ++i)
{
m_isBombsiteClear[i] = false;
}
m_bombsiteSearchIndex = 0;
return GetNextBombsiteToSearch();
#endif
}
// Returns position of bomb in its various states (moving, loose, planted),
// or NULL if we don't know where the bomb is
const Vector *CSGameState::GetBombPosition() const
{
#if 0
switch (m_bombState)
{
case MOVING:
{
if (!m_lastSawBomber.HasStarted())
return NULL;
return &m_bomberPos;
}
case LOOSE:
{
if (IsLooseBombLocationKnown())
return &m_looseBombPos;
return NULL;
}
case PLANTED:
{
if (IsPlantedBombLocationKnown())
return &m_plantedBombPos;
return NULL;
}
}
#endif
return NULL;
}
// We see the planted bomb at 'pos'
void CSGameState::UpdatePlantedBomb(const Vector *pos)
{
#if 0
CCSBotManager *ctrl = TheCSBots();
const CCSBotManager::Zone *zone = ctrl->GetClosestZone(pos);
if (zone == NULL)
{
CONSOLE_ECHO("ERROR: Bomb planted outside of a zone!\n");
m_plantedBombsite = UNKNOWN;
}
else
{
m_plantedBombsite = zone->m_index;
}
m_plantedBombPos = *pos;
m_isPlantedBombPosKnown = true;
SetBombState(PLANTED);
#endif
}
// Someone told us where the bomb is planted
void CSGameState::MarkBombsiteAsPlanted(int zoneIndex)
{
#if 0
m_plantedBombsite = zoneIndex;
SetBombState(PLANTED);
#endif
}
// Someone told us a bombsite is clear
void CSGameState::ClearBombsite(int zoneIndex)
{
#if 0
if (zoneIndex >= 0 && zoneIndex < m_bombsiteCount)
m_isBombsiteClear[zoneIndex] = true;
#endif
}
bool CSGameState::IsBombsiteClear(int zoneIndex) const
{
#if 0
if (zoneIndex >= 0 && zoneIndex < m_bombsiteCount)
return m_isBombsiteClear[zoneIndex];
#endif
return false;
}
#endif
#if 0
void CSGameState::InitializeHostageInfo()
{
m_hostageCount = 0;
m_allHostagesRescued = 0;
m_haveSomeHostagesBeenTaken = 0;
CBaseEntity *hostage = NULL;
while ((hostage = UTIL_FindEntityByClassname(hostage, "hostage_entity")) != NULL)
{
if (m_hostageCount >= MAX_HOSTAGES)
break;
if (hostage->pev->takedamage != DAMAGE_YES)
continue;
m_hostage[m_hostageCount].hostage = static_cast<CHostage *>(hostage);
m_hostage[m_hostageCount].knownPos = hostage->pev->origin;
m_hostage[m_hostageCount].isValid = true;
m_hostage[m_hostageCount].isAlive = true;
m_hostage[m_hostageCount].isFree = true;
++m_hostageCount;
}
}
#endif
// Return the closest free and live hostage
// If we are a CT this information is perfect.
// Otherwise, this is based on our individual memory of the game state.
// If NULL is returned, we don't think there are any hostages left, or we dont know where they are.
// NOTE: a T can remember a hostage who has died. knowPos will be filled in, but NULL will be
// returned, since CHostages get deleted when they die.
#if 0
CHostage *CSGameState::GetNearestFreeHostage(Vector *knowPos) const
{
if (m_owner == NULL)
return NULL;
CNavArea *startArea = m_owner->GetLastKnownArea();
if (startArea == NULL)
return NULL;
CHostage *close = NULL;
const Vector *closePos = NULL;
float closeDistance = 9999999999.9f;
for (int i = 0; i < m_hostageCount; ++i)
{
CHostage *hostage = m_hostage[i].hostage;
const Vector *hostagePos = NULL;
if (m_owner->m_iTeam == CT)
{
// we know exactly where the hostages are, and if they are alive
if (!m_hostage[i].hostage || !m_hostage[i].hostage->IsValid())
continue;
if (m_hostage[i].hostage->IsFollowingSomeone())
continue;
hostagePos = &hostage->pev->origin;
}
else
{
// use our memory of where we think the hostages are
if (m_hostage[i].isValid == false)
continue;
hostagePos = &m_hostage[i].knownPos;
}
CNavArea *hostageArea = TheNavAreaGrid.GetNearestNavArea(hostagePos);
if (hostageArea != NULL)
{
ShortestPathCost pc;
float travelDistance = NavAreaTravelDistance(startArea, hostageArea, pc);
if (travelDistance >= 0.0f && travelDistance < closeDistance)
{
closePos = hostagePos;
closeDistance = travelDistance;
close = hostage;
}
}
}
// return where we think the hostage is
if (knowPos != NULL && closePos != NULL)
{
knowPos = const_cast<Vector *>(closePos);
}
return close;
}
#endif
// Return the location of a "free" hostage, or NULL if we dont know of any
#if 0
const Vector *CSGameState::GetRandomFreeHostagePosition()
{
// TODO: use static?
const Vector *freePos[MAX_HOSTAGES];
int freeCount = 0;
if (m_owner == NULL)
return NULL;
for (int i = 0; i < m_hostageCount; ++i)
{
const HostageInfo *info = &m_hostage[i];
const Vector *hostagePos = NULL;
if (m_owner->m_iTeam == CT)
{
// we know exactly where the hostages are, and if they are alive
if (!info->hostage || !info->hostage->IsAlive())
continue;
// escorted hostages are not "free"
if (info->hostage->IsFollowingSomeone())
continue;
freePos[ freeCount++ ] = &info->hostage->pev->origin;
}
else
{
// use our memory of where we think the hostages are
if (info->isValid == false)
continue;
freePos[ freeCount++ ] = &info->knownPos;
}
}
if (freeCount)
{
return freePos[RANDOM_LONG(0, freeCount - 1)];
}
return NULL;
}
#endif
// If we can see any of the positions where we think a hostage is, validate it
// Return status of any changes (a hostage died or was moved)
#if 0
CSGameState::ValidateStatusType CSGameState::ValidateHostagePositions()
{
// limit how often we validate
if (!m_validateInterval.IsElapsed())
return NO_CHANGE;
const float validateInterval = 0.5f;
m_validateInterval.Start(validateInterval);
// check the status of hostages
int status = NO_CHANGE;
int i;
int startValidCount = 0;
for (i = 0; i < m_hostageCount; ++i)
{
if (m_hostage[i].isValid)
++startValidCount;
}
for (i = 0; i < m_hostageCount; ++i)
{
HostageInfo *info = &m_hostage[i];
if (!info->hostage)
continue;
// if we can see a hostage, update our knowledge of it
if (m_owner->IsVisible(&info->hostage->pev->origin, CHECK_FOV))
{
if (info->hostage->pev->takedamage == DAMAGE_YES)
{
// live hostage
// if hostage is being escorted by a CT, we don't "see" it, we see the CT
if (info->hostage->IsFollowingSomeone())
{
info->isValid = false;
}
else
{
info->knownPos = info->hostage->pev->origin;
info->isValid = true;
}
}
else
{
// dead hostage
// if we thought it was alive, this is news to us
if (info->isAlive)
status |= HOSTAGE_DIED;
info->isAlive = false;
info->isValid = false;
}
continue;
}
// if we dont know where this hostage is, nothing to validate
if (!info->isValid)
continue;
// can't directly see this hostage
// check line of sight to where we think this hostage is, to see if we noticed that is has moved
if (m_owner->IsVisible(&info->knownPos, CHECK_FOV))
{
// we can see where we thought the hostage was - verify it is still there and alive
if (info->hostage->pev->takedamage != DAMAGE_YES)
{
// since we have line of sight to an invalid hostage, it must be dead
// discovered that hostage has been killed
status |= HOSTAGE_DIED;
info->isAlive = false;
info->isValid = false;
continue;
}
if (info->hostage->IsFollowingSomeone())
{
// discovered the hostage has been taken
status |= HOSTAGE_GONE;
info->isValid = false;
continue;
}
const float tolerance = 50.0f;
if ((info->hostage->pev->origin - info->knownPos).IsLengthGreaterThan(tolerance))
{
// discovered that hostage has been moved
status |= HOSTAGE_GONE;
info->isValid = false;
continue;
}
}
}
int endValidCount = 0;
for (i = 0; i < m_hostageCount; ++i)
{
if (m_hostage[i].isValid)
++endValidCount;
}
if (endValidCount == 0 && startValidCount > 0)
{
// we discovered all the hostages are gone
status &= ~HOSTAGE_GONE;
status |= HOSTAGES_ALL_GONE;
}
return (ValidateStatusType) status;
}
// Return the nearest visible free hostage
// Since we can actually see any hostage we return, we know its actual position
CHostage *CSGameState::GetNearestVisibleFreeHostage() const
{
CHostage *close = NULL;
float closeRangeSq = 999999999.9f;
float rangeSq;
Vector pos;
for (int i = 0; i < m_hostageCount; ++i)
{
const HostageInfo *info = &m_hostage[i];
if (!info->hostage)
continue;
// if the hostage is dead or rescued, its not free
if (info->hostage->pev->takedamage != DAMAGE_YES)
continue;
// if this hostage is following someone, its not free
if (info->hostage->IsFollowingSomeone())
continue;
// TODO: Use travel distance here
pos = info->hostage->pev->origin + Vector(0, 0, HumanHeight * 0.75f);
rangeSq = (pos - m_owner->pev->origin).LengthSquared();
if (rangeSq < closeRangeSq)
{
if (!m_owner->IsVisible(&pos))
continue;
close = info->hostage;
closeRangeSq = rangeSq;
}
}
return close;
}
// Return true if there are no free hostages
bool CSGameState::AreAllHostagesBeingRescued() const
{
// if the hostages have all been rescued, they are not being rescued any longer
if (m_allHostagesRescued)
return false;
bool isAllDead = true;
for (int i = 0; i < m_hostageCount; ++i)
{
const HostageInfo *info = &m_hostage[i];
if (m_owner->m_iTeam == CT)
{
// CT's have perfect knowledge via their radar
if (info->hostage != NULL && info->hostage->IsValid())
{
if (!info->hostage->IsFollowingSomeone())
return false;
isAllDead = false;
}
}
else
{
if (info->isValid && info->isAlive)
return false;
if (info->isAlive)
isAllDead = false;
}
}
// if all of the remaining hostages are dead, they arent being rescued
if (isAllDead)
return false;
return true;
}
// All hostages have been rescued or are dead
bool CSGameState::AreAllHostagesGone() const
{
if (m_allHostagesRescued)
return true;
// do we know that all the hostages are dead
for (int i = 0; i < m_hostageCount; ++i)
{
const HostageInfo *info = &m_hostage[i];
if (m_owner->m_iTeam == CT)
{
// CT's have perfect knowledge via their radar
if (info->hostage->IsAlive())// == DAMAGE_YES)
return false;
}
else
{
if (info->isValid && info->isAlive)
return false;
}
}
return true;
}
// Someone told us all the hostages are gone
void CSGameState::AllHostagesGone()
{
for (int i = 0; i < m_hostageCount; ++i)
m_hostage[i].isValid = false;
}
#endif

View File

@ -44,63 +44,14 @@ public:
void Reset();
void OnEvent(GameEventType event, CBaseEntity *entity, CBaseEntity *other); // Event handling
bool IsRoundOver() const; // true if round has been won or lost (but not yet reset)
#if 0
// bomb defuse scenario
enum BombState
{
MOVING, // being carried by a Terrorist
LOOSE, // loose on the ground somewhere
PLANTED, // planted and ticking
DEFUSED, // the bomb has been defused
EXPLODED, // the bomb has exploded
};
bool IsBombMoving() const { return (m_bombState == MOVING); }
bool IsBombLoose() const { return (m_bombState == LOOSE); }
bool IsBombPlanted() const { return (m_bombState == PLANTED); }
bool IsBombDefused() const { return (m_bombState == DEFUSED); }
bool IsBombExploded() const { return (m_bombState == EXPLODED); }
void UpdateLooseBomb(const Vector *pos); // we see the loose bomb
float TimeSinceLastSawLooseBomb() const; // how long has is been since we saw the loose bomb
bool IsLooseBombLocationKnown() const; // do we know where the loose bomb is
void UpdateBomber(const Vector *pos); // we see the bomber
float TimeSinceLastSawBomber() const; // how long has is been since we saw the bomber
void UpdatePlantedBomb(const Vector *pos); // we see the planted bomb
bool IsPlantedBombLocationKnown() const; // do we know where the bomb was planted
void MarkBombsiteAsPlanted(int zoneIndex); // mark bombsite as the location of the planted bomb
enum { UNKNOWN = -1 };
int GetPlantedBombsite() const; // return the zone index of the planted bombsite, or UNKNOWN
bool IsAtPlantedBombsite() const; // return true if we are currently in the bombsite where the bomb is planted
int GetNextBombsiteToSearch(); // return the zone index of the next bombsite to search
bool IsBombsiteClear(int zoneIndex) const; // return true if given bombsite has been cleared
void ClearBombsite(int zoneIndex); // mark bombsite as clear
const Vector *GetBombPosition() const; // return where we think the bomb is, or NULL if we don't know
#endif
// hostage rescue scenario
//enum ValidateStatusType:unsigned char //C++11 feature
private:
CCSBot *m_owner; // who owns this gamestate
bool m_isRoundOver; // true if round is over, but no yet reset
#if 0
// bomb defuse scenario
void SetBombState(BombState state);
BombState GetBombState() { return m_bombState; }
BombState m_bombState; // what we think the bomb is doing
IntervalTimer m_lastSawBomber;
Vector m_bomberPos;
IntervalTimer m_lastSawLooseBomb;
Vector m_looseBombPos;
#endif
CountdownTimer m_validateInterval;
};

View File

@ -242,6 +242,37 @@ bool UTIL_KickBotFromTeam(TeamName kickTeam)
return false;
}
*/
bool UTIL_KickBot()
{
int i;
// try to kick a dead bot first
for (i = 1; i <= gpGlobals->maxClients; ++i)
{
CBasePlayer *player = static_cast<CBasePlayer *>(UTIL_PlayerByIndex(i));
if (player == NULL)
continue;
if (FNullEnt(player->pev))
continue;
const char *name = STRING(player->pev->netname);
if (FStrEq(name, ""))
continue;
if (!player->IsBot())
continue;
// its a bot on the right team - kick it
SERVER_COMMAND(UTIL_VarArgs("kick \"%s\"\n", STRING(player->pev->netname)));
return true;
}
return false;
}
bool UTIL_IsTeamAllBots(int team)
{
int botCount = 0;

View File

@ -213,7 +213,7 @@ bool UTIL_IsNameTaken(const char *name, bool ignoreHumans = false);
int UTIL_ClientsInGame();
int UTIL_ActivePlayersInGame();
int UTIL_BotsInGame();
//bool UTIL_KickBotFromTeam(TeamName kickTeam);
bool UTIL_KickBot( void );
bool UTIL_IsTeamAllBots(int team);
CBasePlayer *UTIL_GetClosestPlayer(const Vector *pos, float *distance = NULL);
CBasePlayer *UTIL_GetClosestPlayer(const Vector *pos, int team, float *distance = NULL);

View File

@ -30,11 +30,6 @@ void AttackState::OnEnter(CCSBot *me)
m_shieldToggleTimestamp = gpGlobals->time + RANDOM_FLOAT(2.0f, 10.0f);
m_shieldForceOpen = false;
#if 0
// if we encountered someone while escaping, grab our weapon and fight!
if (me->IsEscapingFromBomb())
me->EquipBestWeapon();
#endif
if (me->IsUsingKnife())
{
// can't crouch and hold with a knife
@ -134,20 +129,6 @@ void AttackState::OnUpdate(CCSBot *me)
me->ResetStuckMonitor();
me->StopRapidFire();
CBasePlayerWeapon *weapon = me->GetActiveWeapon();
#if 0
if (weapon != NULL)
{
if (weapon->m_iId == WEAPON_C4 ||
weapon->m_iId == WEAPON_HEGRENADE ||
weapon->m_iId == WEAPON_FLASHBANG ||
weapon->m_iId == WEAPON_SMOKEGRENADE)
{
me->EquipBestWeapon();
}
}
#endif
CBasePlayer *enemy = me->GetEnemy();
if (enemy == NULL)
{
@ -249,41 +230,6 @@ void AttackState::OnUpdate(CCSBot *me)
return;
}
#if 0
// Simple shield usage
if (me->HasShield())
{
if (me->IsEnemyVisible() && !m_shieldForceOpen)
{
if (!me->IsRecognizedEnemyReloading() && !me->IsReloading() && me->IsPlayerLookingAtMe(enemy))
{
// close up - enemy is pointing his gun at us
if (!me->IsProtectedByShield())
me->SecondaryAttack();
}
else
{
// enemy looking away or reloading his weapon - open up and shoot him
if (me->IsProtectedByShield())
me->SecondaryAttack();
}
}
else
{
// can't see enemy, open up
if (me->IsProtectedByShield())
me->SecondaryAttack();
}
if (gpGlobals->time > m_shieldToggleTimestamp)
{
m_shieldToggleTimestamp = gpGlobals->time + RANDOM_FLOAT(0.5, 2.0f);
// toggle shield force open
m_shieldForceOpen = !m_shieldForceOpen;
}
}
#endif
// check if our weapon range is bad and we should switch to pistol
if (me->IsUsingSniperRifle())

View File

@ -83,19 +83,7 @@ void FollowState::OnUpdate(CCSBot *me)
me->Idle();
return;
}
#if 0
// if we are carrying the bomb and at a bombsite, plant
if (me->IsCarryingBomb() && me->IsAtBombsite())
{
// plant it
me->SetTask(CCSBot::PLANT_BOMB);
me->PlantBomb();
// radio to the team
me->GetChatter()->PlantingTheBomb(me->GetPlace());
return;
}
#endif
// look around
me->UpdateLookAround();
@ -247,7 +235,7 @@ void FollowState::OnUpdate(CCSBot *me)
}
}
if (me->ComputePath(target, NULL, FASTEST_ROUTE) == NULL)
if (me->ComputePath(target, NULL, FASTEST_ROUTE) == 0 )
me->PrintIfWatched("Pathfind to leader failed.\n");
// throttle how often we repath

View File

@ -44,48 +44,12 @@ void HideState::OnEnter(CCSBot *me)
void HideState::OnUpdate(CCSBot *me)
{
CCSBotManager *ctrl = TheCSBots();
// wait until finished reloading to leave hide state
if (!me->IsActiveWeaponReloading())
{
if (gpGlobals->time - me->GetStateTimestamp() > m_duration)
{
#if 0
if (me->GetTask() == CCSBot::GUARD_LOOSE_BOMB)
{
// if we're guarding the loose bomb, continue to guard it but pick a new spot
me->Hide(ctrl->GetLooseBombArea());
return;
}
else if (me->GetTask() == CCSBot::GUARD_BOMB_ZONE)
{
// if we're guarding a bombsite, continue to guard it but pick a new spot
const CCSBotManager::Zone *zone = ctrl->GetClosestZone(&me->pev->origin);
if (zone != NULL)
{
CNavArea *area = ctrl->GetRandomAreaInZone(zone);
if (area != NULL)
{
me->Hide(area);
return;
}
}
}
else if (me->GetTask() == CCSBot::GUARD_HOSTAGE_RESCUE_ZONE)
{
// if we're guarding a rescue zone, continue to guard this or another rescue zone
if (me->GuardRandomZone())
{
me->SetTask(CCSBot::GUARD_HOSTAGE_RESCUE_ZONE);
me->PrintIfWatched("Continuing to guard hostage rescue zones\n");
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
me->GetChatter()->GuardingHostageEscapeZone(IS_PLAN);
return;
}
}
#endif
me->Idle();
return;
}
@ -113,116 +77,6 @@ void HideState::OnUpdate(CCSBot *me)
}
}
// if we see a nearby buddy in combat, join him
// TODO: Perhaps tie in to TakeDamage(), so it works for human players, too
#if 0
// Scenario logic
switch (ctrl->GetScenario())
{
case CCSBotManager::SCENARIO_DEFUSE_BOMB:
{
if (me->m_iTeam == CT)
{
// if we are just holding position (due to a radio order) and the bomb has just planted, go defuse it
if (me->GetTask() == CCSBot::HOLD_POSITION &&
ctrl->IsBombPlanted() &&
ctrl->GetBombPlantTimestamp() > me->GetStateTimestamp())
{
me->Idle();
return;
}
// if we are guarding the defuser and he dies/gives up, stop hiding (to choose another defuser)
if (me->GetTask() == CCSBot::GUARD_BOMB_DEFUSER && ctrl->GetBombDefuser() == NULL)
{
me->Idle();
return;
}
// if we are guarding the loose bomb and it is picked up, stop hiding
if (me->GetTask() == CCSBot::GUARD_LOOSE_BOMB && ctrl->GetLooseBomb() == NULL)
{
me->GetChatter()->TheyPickedUpTheBomb();
me->Idle();
return;
}
// if we are guarding a bombsite and the bomb is dropped and we hear about it, stop guarding
if (me->GetTask() == CCSBot::GUARD_BOMB_ZONE && me->GetGameState()->IsLooseBombLocationKnown())
{
me->Idle();
return;
}
// if we are guarding (bombsite, initial encounter, etc) and the bomb is planted, go defuse it
if (me->IsDoingScenario() && me->GetTask() == CCSBot::GUARD_BOMB_ZONE && ctrl->IsBombPlanted())
{
me->Idle();
return;
}
}
// TERRORIST
else
{
// if we are near the ticking bomb and someone starts defusing it, attack!
if (ctrl->GetBombDefuser())
{
Vector toDefuser = ctrl->GetBombDefuser()->pev->origin;
const float hearDefuseRange = 2000.0f;
if ((toDefuser - me->pev->origin).IsLengthLessThan(hearDefuseRange))
{
// if we are nearby, attack, otherwise move to the bomb (which will cause us to attack when we see defuser)
if (me->CanSeePlantedBomb())
{
me->Attack(ctrl->GetBombDefuser());
}
else
{
me->MoveTo(&toDefuser, FASTEST_ROUTE);
me->InhibitLookAround(10.0f);
}
return;
}
}
}
break;
}
case CCSBotManager::SCENARIO_RESCUE_HOSTAGES:
{
// if we're guarding the hostages and they all die or are taken, do something else
if (me->GetTask() == CCSBot::GUARD_HOSTAGES)
{
if (me->GetGameState()->AreAllHostagesBeingRescued() || me->GetGameState()->AreAllHostagesGone())
{
me->Idle();
return;
}
}
else if (me->GetTask() == CCSBot::GUARD_HOSTAGE_RESCUE_ZONE)
{
// if we stumble across a hostage, guard it
CHostage *hostage = me->GetGameState()->GetNearestVisibleFreeHostage();
if (hostage != NULL)
{
// we see a free hostage, guard it
CNavArea *area = TheNavAreaGrid.GetNearestNavArea(&hostage->pev->origin);
if (area != NULL)
{
me->SetTask(CCSBot::GUARD_HOSTAGES);
me->Hide(area);
me->PrintIfWatched("I'm guarding hostages I found\n");
// don't chatter here - he'll tell us when he's in his hiding spot
return;
}
}
}
}
}
#endif
bool isSettledInSniper = (me->IsSniper() && m_isAtSpot) ? true : false;
// only investigate noises if we are initiating attacks, and we aren't a "settled in" sniper
@ -282,43 +136,6 @@ void HideState::OnUpdate(CCSBot *me)
me->Idle();
return;
}
#if 0
// encourage the human player
if (!me->IsDoingScenario())
{
if (me->m_iTeam == CT)
{
if (me->GetTask() == CCSBot::GUARD_BOMB_ZONE && me->IsAtHidingSpot() && ctrl->IsBombPlanted())
{
if (me->GetNearbyEnemyCount() == 0)
{
const float someTime = 30.0f;
const float littleTime = 11.0;
if (ctrl->GetBombTimeLeft() > someTime)
me->GetChatter()->Encourage("BombsiteSecure", RANDOM_FLOAT(10.0f, 15.0f));
else if (ctrl->GetBombTimeLeft() > littleTime)
me->GetChatter()->Encourage("WaitingForHumanToDefuseBomb", RANDOM_FLOAT(5.0f, 8.0f));
else
me->GetChatter()->Encourage("WaitingForHumanToDefuseBombPanic", RANDOM_FLOAT(3.0f, 4.0f));
}
}
if (me->GetTask() == CCSBot::GUARD_HOSTAGES && me->IsAtHidingSpot())
{
if (me->GetNearbyEnemyCount() == 0)
{
CHostage *hostage = me->GetGameState()->GetNearestVisibleFreeHostage();
if (hostage != NULL)
{
me->GetChatter()->Encourage("WaitingForHumanToRescueHostages", RANDOM_FLOAT(10.0f, 15.0f));
}
}
}
}
}
#endif
}
else
{
@ -433,8 +250,4 @@ void HideState::OnExit(CCSBot *me)
me->ResetStuckMonitor();
me->ClearLookAt();
me->ClearApproachPoints();
// if we have a shield, put it away
// if (me->HasShield() && me->IsProtectedByShield())
// me->SecondaryAttack();
}

View File

@ -20,115 +20,6 @@ void HuntState::OnEnter(CCSBot *me)
void HuntState::OnUpdate(CCSBot *me)
{
// if we've been hunting for a long time, drop into Idle for a moment to
// select something else to do
const float huntingTooLongTime = 30.0f;
#if 0
if (gpGlobals->time - me->GetStateTimestamp() > huntingTooLongTime)
{
// stop being a rogue and do the scenario, since there must not be many enemies left to hunt
me->PrintIfWatched("Giving up hunting, and being a rogue\n");
me->SetRogue(false);
me->Idle();
return;
}
#endif
CCSBotManager *ctrl = TheCSBots();
#if 0
// scenario logic
if (ctrl->GetScenario() == CCSBotManager::SCENARIO_DEFUSE_BOMB)
{
if (me->m_iTeam == TERRORIST)
{
// if we have the bomb and it's time to plant, or we happen to be in a bombsite and it seems safe, do it
if (me->IsCarryingBomb())
{
const float safeTime = 3.0f;
if (ctrl->IsTimeToPlantBomb() || (me->IsAtBombsite() && gpGlobals->time - me->GetLastSawEnemyTimestamp() > safeTime))
{
me->Idle();
return;
}
}
// if we notice the bomb lying on the ground, go get it
if (me->NoticeLooseBomb())
{
me->FetchBomb();
return;
}
// if bomb has been planted, and we hear it, move to a hiding spot near the bomb and watch it
const Vector *bombPos = me->GetGameState()->GetBombPosition();
if (!me->IsRogue() && me->GetGameState()->IsBombPlanted() && bombPos != NULL)
{
me->SetTask(CCSBot::GUARD_TICKING_BOMB);
me->Hide(TheNavAreaGrid.GetNavArea(bombPos));
return;
}
}
// CT
else
{
if (!me->IsRogue() && me->CanSeeLooseBomb())
{
// if we are near the loose bomb and can see it, hide nearby and guard it
me->SetTask(CCSBot::GUARD_LOOSE_BOMB);
me->Hide(ctrl->GetLooseBombArea());
me->GetChatter()->AnnouncePlan("GoingToGuardLooseBomb", ctrl->GetLooseBombArea()->GetPlace());
return;
}
else if (ctrl->IsBombPlanted())
{
// rogues will defuse a bomb, but not guard the defuser
if (!me->IsRogue() || !ctrl->GetBombDefuser())
{
// search for the planted bomb to defuse
me->Idle();
return;
}
}
}
}
else if (ctrl->GetScenario() == CCSBotManager::SCENARIO_RESCUE_HOSTAGES)
{
if (me->m_iTeam == TERRORIST)
{
if (me->GetGameState()->AreAllHostagesBeingRescued())
{
// all hostages are being rescued, head them off at the escape zones
if (me->GuardRandomZone())
{
me->SetTask(CCSBot::GUARD_HOSTAGE_RESCUE_ZONE);
me->PrintIfWatched("Trying to beat them to an escape zone!\n");
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
me->GetChatter()->GuardingHostageEscapeZone(IS_PLAN);
return;
}
}
// if safe time is up, and we stumble across a hostage, guard it
if (!me->IsRogue() && !me->IsSafe())
{
CHostage *hostage = me->GetGameState()->GetNearestVisibleFreeHostage();
if (hostage != NULL)
{
CNavArea *area = TheNavAreaGrid.GetNearestNavArea(&hostage->pev->origin);
if (area != NULL)
{
// we see a free hostage, guard it
me->SetTask(CCSBot::GUARD_HOSTAGES);
me->Hide(area);
me->PrintIfWatched("I'm guarding hostages\n");
me->GetChatter()->GuardingHostages(area->GetPlace(), IS_PLAN);
return;
}
}
}
}
}
#endif
// listen for enemy noises
if (me->ShouldInvestigateNoise())
{

View File

@ -53,19 +53,6 @@ void IdleState::OnUpdate(CCSBot *me)
// if round is over, hunt
if (me->GetGameState()->IsRoundOver())
{
#if 0
// if we are escorting hostages, try to get to the rescue zone
if (me->GetHostageEscortCount())
{
const CCSBotManager::Zone *zone = ctrl->GetClosestZone(me->GetLastKnownArea(), PathCost(me, FASTEST_ROUTE));
me->SetTask(CCSBot::RESCUE_HOSTAGES);
me->Run();
me->SetDisposition(CCSBot::SELF_DEFENSE);
me->MoveTo(ctrl->GetRandomPositionInZone(zone), FASTEST_ROUTE);
me->PrintIfWatched("Trying to rescue hostages at the end of the round\n");
return;
}
#endif
me->Hunt();
return;
}
@ -79,677 +66,16 @@ void IdleState::OnUpdate(CCSBot *me)
me->ContinueFollowing();
return;
}
#if 0
// Scenario logic
switch (ctrl->GetScenario())
// deathmatch
// sniping check
if (me->GetFriendsRemaining() && me->IsSniper() && RANDOM_FLOAT(0, 100.0f) < offenseSniperCampChance)
{
case CCSBotManager::SCENARIO_DEFUSE_BOMB:
{
static int inumpo = 0;
inumpo++;
// if this is a bomb game and we have the bomb, go plant it
if (me->m_iTeam == TERRORIST)
{
if (me->GetGameState()->IsBombPlanted())
{
if (me->GetGameState()->GetPlantedBombsite() != CSGameState::UNKNOWN)
{
// T's always know where the bomb is - go defend it
const CCSBotManager::Zone *zone = ctrl->GetZone(me->GetGameState()->GetPlantedBombsite());
me->SetTask(CCSBot::GUARD_TICKING_BOMB);
Place place = TheNavAreaGrid.GetPlace(&zone->m_center);
if (place != UNDEFINED_PLACE)
{
// pick a random hiding spot in this place
const Vector *spot = FindRandomHidingSpot(me, place, me->IsSniper());
if (spot != NULL)
{
me->Hide(spot);
return;
}
}
// hide nearby
me->Hide(TheNavAreaGrid.GetNearestNavArea(&zone->m_center));
return;
}
else
{
// ask our teammates where the bomb is
me->GetChatter()->RequestBombLocation();
// we dont know where the bomb is - we must search the bombsites
int zoneIndex = me->GetGameState()->GetNextBombsiteToSearch();
// move to bombsite - if we reach it, we'll update its cleared status, causing us to select another
const Vector *pos = ctrl->GetRandomPositionInZone(ctrl->GetZone(zoneIndex));
if (pos != NULL)
{
me->SetTask(CCSBot::FIND_TICKING_BOMB);
me->MoveTo(pos);
return;
}
}
}
else if (me->IsCarryingBomb())
{
// if we're at a bomb site, plant the bomb
if (me->IsAtBombsite())
{
// plant it
me->SetTask(CCSBot::PLANT_BOMB);
me->PlantBomb();
// radio to the team
me->GetChatter()->PlantingTheBomb(me->GetPlace());
return;
}
else if (ctrl->IsTimeToPlantBomb())
{
// move to the closest bomb site
const CCSBotManager::Zone *zone = ctrl->GetClosestZone(me->GetLastKnownArea(), PathCost(me));
if (zone != NULL)
{
// pick a random spot within the bomb zone
const Vector *pos = ctrl->GetRandomPositionInZone(zone);
if (pos != NULL)
{
// move to bombsite
me->SetTask(CCSBot::PLANT_BOMB);
me->Run();
me->MoveTo(pos);
return;
}
}
}
}
else
{
// small chance of sniper camping on offense, if we aren't carrying the bomb
if (me->GetFriendsRemaining() && me->IsSniper() && RANDOM_FLOAT(0, 100.0f) < offenseSniperCampChance)
{
me->SetTask(CCSBot::MOVE_TO_SNIPER_SPOT);
me->Hide(me->GetLastKnownArea(), RANDOM_FLOAT(10.0f, 30.0f), sniperHideRange);
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
me->PrintIfWatched("Sniping!\n");
return;
}
// if the bomb is loose (on the ground), go get it
if (me->NoticeLooseBomb())
{
me->FetchBomb();
return;
}
// if bomb has been planted, and we hear it, move to a hiding spot near the bomb and guard it
if (!me->IsRogue() && me->GetGameState()->IsBombPlanted() && me->GetGameState()->GetBombPosition() != NULL)
{
const Vector *bombPos = me->GetGameState()->GetBombPosition();
if (bombPos != NULL)
{
me->SetTask(CCSBot::GUARD_TICKING_BOMB);
me->Hide(TheNavAreaGrid.GetNavArea(bombPos));
return;
}
}
}
}
// CT
else
{
if (me->GetGameState()->IsBombPlanted())
{
// if the bomb has been planted, attempt to defuse it
const Vector *bombPos = me->GetGameState()->GetBombPosition();
if (bombPos != NULL)
{
// if someone is defusing the bomb, guard them
if (ctrl->GetBombDefuser())
{
if (!me->IsRogue())
{
me->SetTask(CCSBot::GUARD_BOMB_DEFUSER);
me->Hide(TheNavAreaGrid.GetNavArea(bombPos));
return;
}
}
else if (me->IsDoingScenario())
{
// move to the bomb and defuse it
me->SetTask(CCSBot::DEFUSE_BOMB);
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
me->MoveTo(bombPos);
return;
}
else
{
// we're not allowed to defuse, guard the bomb zone
me->SetTask(CCSBot::GUARD_BOMB_ZONE);
me->Hide(TheNavAreaGrid.GetNavArea(bombPos));
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
return;
}
}
else if (me->GetGameState()->GetPlantedBombsite() != CSGameState::UNKNOWN)
{
// we know which bombsite, but not exactly where the bomb is, go there
const CCSBotManager::Zone *zone = ctrl->GetZone(me->GetGameState()->GetPlantedBombsite());
if (zone != NULL)
{
if (me->IsDoingScenario())
{
me->SetTask(CCSBot::DEFUSE_BOMB);
me->MoveTo(&zone->m_center);
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
return;
}
else
{
// we're not allowed to defuse, guard the bomb zone
me->SetTask(CCSBot::GUARD_BOMB_ZONE);
me->Hide(TheNavAreaGrid.GetNavArea(&zone->m_center));
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
return;
}
}
}
else
{
// we dont know where the bomb is - we must search the bombsites
// find closest un-cleared bombsite
const CCSBotManager::Zone *zone = NULL;
float travelDistance = 9999999.9f;
for (int z = 0; z < ctrl->GetZoneCount(); ++z)
{
if (ctrl->GetZone(z)->m_areaCount == 0)
continue;
// don't check bombsites that have been cleared
if (me->GetGameState()->IsBombsiteClear(z))
continue;
// just use the first overlapping nav area as a reasonable approximation
ShortestPathCost pathCost = ShortestPathCost();
float dist = NavAreaTravelDistance(me->GetLastKnownArea(), TheNavAreaGrid.GetNearestNavArea(&ctrl->GetZone(z)->m_center), pathCost);
if (/*dist >= 0.0f && */dist < travelDistance)
{
zone = ctrl->GetZone(z);
travelDistance = dist;
}
}
if (zone != NULL)
{
const float farAwayRange = 2000.0f;
if (travelDistance > farAwayRange)
{
zone = NULL;
}
}
// if closest bombsite is "far away", pick one at random
if (zone == NULL)
{
int zoneIndex = me->GetGameState()->GetNextBombsiteToSearch();
zone = ctrl->GetZone(zoneIndex);
}
// move to bombsite - if we reach it, we'll update its cleared status, causing us to select another
if (zone != NULL)
{
const Vector *pos = ctrl->GetRandomPositionInZone(zone);
if (pos != NULL)
{
me->SetTask(CCSBot::FIND_TICKING_BOMB);
me->MoveTo(pos);
return;
}
}
}
assert((0, "A CT bot doesn't know what to do while the bomb is planted!\n"));
}
// if we have a sniper rifle, we like to camp, whether rogue or not
if (me->IsSniper())
{
if (RANDOM_FLOAT(0, 100) <= defenseSniperCampChance)
{
CNavArea *snipingArea = NULL;
// if the bomb is loose, snipe near it
if (me->GetGameState()->IsLooseBombLocationKnown())
{
snipingArea = TheNavAreaGrid.GetNearestNavArea(me->GetGameState()->GetBombPosition());
me->PrintIfWatched("Sniping near loose bomb\n");
}
else
{
// snipe bomb zone(s)
const CCSBotManager::Zone *zone = ctrl->GetRandomZone();
if (zone != NULL)
{
snipingArea = ctrl->GetRandomAreaInZone(zone);
me->PrintIfWatched("Sniping near bombsite\n");
}
}
if (snipingArea != NULL)
{
me->SetTask(CCSBot::MOVE_TO_SNIPER_SPOT);
me->Hide(snipingArea, -1.0f, sniperHideRange);
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
return;
}
}
}
// rogues just hunt, unless they want to snipe
// if the whole team has decided to rush, hunt
// if we know the bomb is dropped, hunt for enemies and the loose bomb
if (me->IsRogue() || ctrl->IsDefenseRushing() || me->GetGameState()->IsLooseBombLocationKnown())
{
me->Hunt();
return;
}
// the lower our morale gets, the more we want to camp the bomb zone(s)
// only decide to camp at the start of the round, or if we haven't seen anything for a long time
if (me->IsSafe() || me->HasNotSeenEnemyForLongTime())
{
float guardBombsiteChance = -34.0f * me->GetMorale();
if (RANDOM_FLOAT(0.0f, 100.0f) < guardBombsiteChance)
{
float guardRange = 500.0f + 100.0f * (me->GetMorale() + 3);
// guard bomb zone(s)
const CCSBotManager::Zone *zone = ctrl->GetRandomZone();
if (zone != NULL)
{
CNavArea *area = ctrl->GetRandomAreaInZone(zone);
if (area != NULL)
{
me->PrintIfWatched("I'm guarding a bombsite\n");
me->GetChatter()->AnnouncePlan("GoingToDefendBombsite", area->GetPlace());
me->SetTask(CCSBot::GUARD_BOMB_ZONE);
me->Hide(area, -1.0, guardRange);
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
return;
}
}
}
}
}
break;
}
case CCSBotManager::SCENARIO_ESCORT_VIP:
{
if (me->m_iTeam == TERRORIST)
{
// if we have a sniper rifle, we like to camp, whether rogue or not
if (me->IsSniper())
{
if (RANDOM_FLOAT(0, 100) <= defenseSniperCampChance)
{
// snipe escape zone(s)
const CCSBotManager::Zone *zone = ctrl->GetRandomZone();
if (zone != NULL)
{
CNavArea *area = ctrl->GetRandomAreaInZone(zone);
if (area != NULL)
{
me->SetTask(CCSBot::MOVE_TO_SNIPER_SPOT);
me->Hide(area, -1.0, sniperHideRange);
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
me->PrintIfWatched("Sniping near escape zone\n");
return;
}
}
}
}
// rogues just hunt, unless they want to snipe
// if the whole team has decided to rush, hunt
if (me->IsRogue() || ctrl->IsDefenseRushing())
break;
// the lower our morale gets, the more we want to camp the escape zone(s)
float guardEscapeZoneChance = -34.0f * me->GetMorale();
if (RANDOM_FLOAT(0.0f, 100.0f) < guardEscapeZoneChance)
{
// guard escape zone(s)
const CCSBotManager::Zone *zone = ctrl->GetRandomZone();
if (zone != NULL)
{
CNavArea *area = ctrl->GetRandomAreaInZone(zone);
if (area != NULL)
{
// guard the escape zone - stay closer if our morale is low
me->SetTask(CCSBot::GUARD_VIP_ESCAPE_ZONE);
me->PrintIfWatched("I'm guarding an escape zone\n");
float escapeGuardRange = 750.0f + 250.0f * (me->GetMorale() + 3);
me->Hide(area, -1.0, escapeGuardRange);
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
return;
}
}
}
}
// CT
else
{
if (me->m_bIsVIP)
{
// if early in round, pick a random zone, otherwise pick closest zone
const float earlyTime = 20.0f;
const CCSBotManager::Zone *zone = NULL;
if (ctrl->GetElapsedRoundTime() < earlyTime)
{
// pick random zone
zone = ctrl->GetRandomZone();
}
else
{
// pick closest zone
zone = ctrl->GetClosestZone(me->GetLastKnownArea(), PathCost(me));
}
if (zone != NULL)
{
// pick a random spot within the escape zone
const Vector *pos = ctrl->GetRandomPositionInZone(zone);
if (pos != NULL)
{
// move to escape zone
me->SetTask(CCSBot::VIP_ESCAPE);
me->Run();
me->MoveTo(pos);
// tell team to follow
const float repeatTime = 30.0f;
if (me->GetFriendsRemaining() && ctrl->GetRadioMessageInterval(EVENT_RADIO_FOLLOW_ME, me->m_iTeam) > repeatTime)
me->SendRadioMessage(EVENT_RADIO_FOLLOW_ME);
return;
}
}
}
else
{
// small chance of sniper camping on offense, if we aren't VIP
if (me->GetFriendsRemaining() && me->IsSniper() && RANDOM_FLOAT(0, 100.0f) < offenseSniperCampChance)
{
me->SetTask(CCSBot::MOVE_TO_SNIPER_SPOT);
me->Hide(me->GetLastKnownArea(), RANDOM_FLOAT(10.0f, 30.0f), sniperHideRange);
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
me->PrintIfWatched("Sniping!\n");
return;
}
}
}
break;
}
case CCSBotManager::SCENARIO_RESCUE_HOSTAGES:
{
if (me->m_iTeam == TERRORIST)
{
bool campHostages;
// if we are in early game, camp the hostages
if (me->IsSafe())
{
campHostages = true;
}
else if (me->GetGameState()->HaveSomeHostagesBeenTaken() || me->GetGameState()->AreAllHostagesBeingRescued())
{
campHostages = false;
}
else
{
// later in the game, camp either hostages or escape zone
const float campZoneChance = 100.0f * (ctrl->GetElapsedRoundTime() - me->GetSafeTime()) / 120.0f;
campHostages = (RANDOM_FLOAT(0, 100) > campZoneChance) ? true : false;
}
// if we have a sniper rifle, we like to camp, whether rogue or not
if (me->IsSniper())
{
if (RANDOM_FLOAT(0, 100) <= defenseSniperCampChance)
{
const Vector *hostagePos = me->GetGameState()->GetRandomFreeHostagePosition();
if (hostagePos != NULL && campHostages)
{
me->SetTask(CCSBot::MOVE_TO_SNIPER_SPOT);
me->PrintIfWatched("Sniping near hostages\n");
me->Hide(TheNavAreaGrid.GetNearestNavArea(hostagePos), -1.0, sniperHideRange);
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
return;
}
else
{
// camp the escape zone(s)
if (me->GuardRandomZone(sniperHideRange))
{
me->SetTask(CCSBot::MOVE_TO_SNIPER_SPOT);
me->PrintIfWatched("Sniping near a rescue zone\n");
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
return;
}
}
}
}
// if safe time is up, and we stumble across a hostage, guard it
if (!me->IsSafe() && !me->IsRogue())
{
CBaseEntity *hostage = me->GetGameState()->GetNearestVisibleFreeHostage();
if (hostage != NULL)
{
// we see a free hostage, guard it
CNavArea *area = TheNavAreaGrid.GetNearestNavArea(&hostage->pev->origin);
if (area != NULL)
{
me->SetTask(CCSBot::GUARD_HOSTAGES);
me->Hide(area);
me->PrintIfWatched("I'm guarding hostages I found\n");
// don't chatter here - he'll tell us when he's in his hiding spot
return;
}
}
}
// decide if we want to hunt, or guard
const float huntChance = 70.0f + 25.0f * me->GetMorale();
// rogues just hunt, unless they want to snipe
// if the whole team has decided to rush, hunt
if (me->GetFriendsRemaining())
{
if (me->IsRogue() || ctrl->IsDefenseRushing() || RANDOM_FLOAT(0, 100) < huntChance)
{
me->Hunt();
return;
}
}
// decide whether to camp the hostages or the escape zones
const Vector *hostagePos = me->GetGameState()->GetRandomFreeHostagePosition();
if (hostagePos != NULL && campHostages)
{
CNavArea *area = TheNavAreaGrid.GetNearestNavArea(hostagePos);
if (area != NULL)
{
// guard the hostages - stay closer to hostages if our morale is low
me->SetTask(CCSBot::GUARD_HOSTAGES);
me->PrintIfWatched("I'm guarding hostages\n");
float hostageGuardRange = 750.0f + 250.0f * (me->GetMorale() + 3);
me->Hide(area, -1.0, hostageGuardRange);
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
if (RANDOM_FLOAT(0, 100) < 50)
me->GetChatter()->GuardingHostages(area->GetPlace(), IS_PLAN);
return;
}
}
// guard rescue zone(s)
if (me->GuardRandomZone())
{
me->SetTask(CCSBot::GUARD_HOSTAGE_RESCUE_ZONE);
me->PrintIfWatched("I'm guarding a rescue zone\n");
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
me->GetChatter()->GuardingHostageEscapeZone(IS_PLAN);
return;
}
}
// CT
else
{
// only decide to do something else if we aren't already rescuing hostages
if (!me->GetHostageEscortCount())
{
// small chance of sniper camping on offense
if (me->GetFriendsRemaining() && me->IsSniper() && RANDOM_FLOAT(0, 100.0f) < offenseSniperCampChance)
{
me->SetTask(CCSBot::MOVE_TO_SNIPER_SPOT);
me->Hide(me->GetLastKnownArea(), RANDOM_FLOAT(10.0f, 30.0f), sniperHideRange);
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
me->PrintIfWatched("Sniping!\n");
return;
}
if (me->GetFriendsRemaining() && !me->GetHostageEscortCount())
{
// rogues just hunt, unless all friends are dead
// if we have friends left, we might go hunting instead of hostage rescuing
const float huntChance = 33.3f;
if (me->IsRogue() || RANDOM_FLOAT(0.0f, 100.0f) < huntChance)
{
me->Hunt();
return;
}
}
}
// look for free hostages - CT's have radar so they know where hostages are at all times
CHostage *hostage = me->GetGameState()->GetNearestFreeHostage();
// if we are not allowed to do the scenario, guard the hostages to clear the area for the human(s)
if (!me->IsDoingScenario())
{
if (hostage != NULL)
{
CNavArea *area = TheNavAreaGrid.GetNearestNavArea(&hostage->pev->origin);
if (area != NULL)
{
me->SetTask(CCSBot::GUARD_HOSTAGES);
me->Hide(area);
me->PrintIfWatched("I'm securing the hostages for a human to rescue\n");
return;
}
}
me->Hunt();
return;
}
bool fetchHostages = false;
bool rescueHostages = false;
const CCSBotManager::Zone *zone = NULL;
me->SetGoalEntity(NULL);
// if we are escorting hostages, determine where to take them
if (me->GetHostageEscortCount())
zone = ctrl->GetClosestZone(me->GetLastKnownArea(), PathCost(me, FASTEST_ROUTE));
// if we are escorting hostages and there are more hostages to rescue,
// determine whether it's faster to rescue the ones we have, or go get the remaining ones
if (hostage != NULL)
{
if (zone != NULL)
{
PathCost pathCost(me, FASTEST_ROUTE);
float toZone = NavAreaTravelDistance(me->GetLastKnownArea(), zone->m_area[0], pathCost);
float toHostage = NavAreaTravelDistance(me->GetLastKnownArea(), TheNavAreaGrid.GetNearestNavArea(&hostage->pev->origin), pathCost);
if (toHostage < 0.0f)
{
rescueHostages = true;
}
else
{
if (toZone < toHostage)
rescueHostages = true;
else
fetchHostages = true;
}
}
else
{
fetchHostages = true;
}
}
else if (zone != NULL)
{
rescueHostages = true;
}
if (fetchHostages)
{
// go get hostages
me->SetTask(CCSBot::COLLECT_HOSTAGES);
me->Run();
me->SetGoalEntity(hostage);
me->ResetWaitForHostagePatience();
// if we already have some hostages, move to the others by the quickest route
RouteType route = (me->GetHostageEscortCount()) ? FASTEST_ROUTE : SAFEST_ROUTE;
me->MoveTo(&hostage->pev->origin, route);
me->PrintIfWatched("I'm collecting hostages\n");
return;
}
if (rescueHostages)
{
me->SetTask(CCSBot::RESCUE_HOSTAGES);
me->Run();
me->SetDisposition(CCSBot::SELF_DEFENSE);
me->MoveTo(ctrl->GetRandomPositionInZone(zone), FASTEST_ROUTE);
me->PrintIfWatched("I'm rescuing hostages\n");
me->GetChatter()->EscortingHostages();
return;
}
}
break;
}
#endif
// deathmatch
//default:
{
// sniping check
if (me->GetFriendsRemaining() && me->IsSniper() && RANDOM_FLOAT(0, 100.0f) < offenseSniperCampChance)
{
me->SetTask(CCSBot::MOVE_TO_SNIPER_SPOT);
me->Hide(me->GetLastKnownArea(), RANDOM_FLOAT(10.0f, 30.0f), sniperHideRange);
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
me->PrintIfWatched("Sniping!\n");
return;
}
//break;
}
//}
me->SetTask(CCSBot::MOVE_TO_SNIPER_SPOT);
me->Hide(me->GetLastKnownArea(), RANDOM_FLOAT(10.0f, 30.0f), sniperHideRange);
me->SetDisposition(CCSBot::OPPORTUNITY_FIRE);
me->PrintIfWatched("Sniping!\n");
return;
}
// if we have nothing special to do, go hunting for enemies
me->Hunt();

View File

@ -18,10 +18,6 @@ void MoveToState::OnEnter(CCSBot *me)
switch (me->GetTask())
{
// maybe also fastest way to healthkits??
#if 0
case CCSBot::FIND_TICKING_BOMB:
case CCSBot::DEFUSE_BOMB:
#endif
case CCSBot::MOVE_TO_LAST_KNOWN_ENEMY_POSITION:
route = FASTEST_ROUTE;
break;
@ -59,225 +55,12 @@ void MoveToState::OnUpdate(CCSBot *me)
// look around
me->UpdateLookAround();
#if 0
// Scenario logic
switch (ctrl->GetScenario())
{
case CCSBotManager::SCENARIO_DEFUSE_BOMB:
{
// if the bomb has been planted, find it
// NOTE: This task is used by both CT and T's to find the bomb
if (me->GetTask() == CCSBot::FIND_TICKING_BOMB)
{
if (!me->GetGameState()->IsBombPlanted())
{
// the bomb is not planted - give up this task
me->Idle();
return;
}
if (me->GetGameState()->GetPlantedBombsite() != CSGameState::UNKNOWN)
{
// we know where the bomb is planted, stop searching
me->Idle();
return;
}
// check off bombsites that we explore or happen to stumble into
for (int z = 0; z < ctrl->GetZoneCount(); ++z)
{
// don't re-check zones
if (me->GetGameState()->IsBombsiteClear(z))
continue;
#if 0
if (ctrl->GetZone(z)->m_extent.Contains(&me->pev->origin))
{
// note this bombsite is clear
me->GetGameState()->ClearBombsite(z);
if (me->m_iTeam == CT)
{
// tell teammates this bombsite is clear
me->GetChatter()->BombsiteClear(z);
}
// find another zone to check
me->Idle();
return;
}
#endif
}
// move to a bombsite
break;
}
else if (me->m_iTeam == CT)
{
if (me->GetGameState()->IsBombPlanted())
{
switch (me->GetTask())
{
case CCSBot::DEFUSE_BOMB:
{
// if we are trying to defuse the bomb, and someone has started defusing, guard them instead
if (me->CanSeePlantedBomb() && ctrl->GetBombDefuser())
{
me->GetChatter()->Say("CoveringFriend");
me->Idle();
return;
}
break;
}
default:
{
// we need to find the bomb
me->Idle();
return;
}
}
}
}
// TERRORIST
else
{
if (me->GetTask() == CCSBot::PLANT_BOMB)
{
if (me->GetFriendsRemaining())
{
// if we are about to plant, radio for cover
if (!m_askedForCover)
{
const float nearPlantSite = 50.0f;
if (me->IsAtBombsite() && me->GetPathDistanceRemaining() < nearPlantSite)
{
// radio to the team
me->GetChatter()->PlantingTheBomb(me->GetPlace());
m_askedForCover = true;
}
// after we have started to move to the bombsite, tell team we're going to plant, and where
// don't do this if we have already radioed that we are starting to plant
if (!m_radioedPlan)
{
const float radioTime = 2.0f;
if (gpGlobals->time - me->GetStateTimestamp() > radioTime)
{
me->GetChatter()->GoingToPlantTheBomb(TheNavAreaGrid.GetPlace(&m_goalPosition));
m_radioedPlan = true;
}
}
}
}
}
}
break;
}
case CCSBotManager::SCENARIO_RESCUE_HOSTAGES:
{
if (me->GetTask() == CCSBot::COLLECT_HOSTAGES)
{
// Since CT's have a radar, they can directly look at the actual hostage state
// check if someone else collected our hostage, or the hostage died or was rescued
CHostage *hostage = static_cast<CHostage *>(me->GetGoalEntity());
if (hostage == NULL || !hostage->IsValid() || hostage->IsFollowingSomeone())
{
me->Idle();
return;
}
// if our hostage has moved, repath
const float repathToleranceSq = 75.0f * 75.0f;
float error = (hostage->pev->origin - m_goalPosition).LengthSquared();
if (error > repathToleranceSq)
{
m_goalPosition = hostage->pev->origin;
me->ComputePath(TheNavAreaGrid.GetNavArea(&m_goalPosition), &m_goalPosition, SAFEST_ROUTE);
}
// TODO: Generalize ladder priorities over other tasks
if (!me->IsUsingLadder())
{
Vector pos = hostage->pev->origin + Vector(0, 0, HumanHeight * 0.75f);
Vector to = pos - me->pev->origin;
// look at the hostage as we approach
const float watchHostageRange = 100.0f;
if (to.IsLengthLessThan(watchHostageRange))
{
me->SetLookAt("Hostage", &pos, PRIORITY_LOW, 0.5f);
// randomly move just a bit to avoid infinite use loops from bad hostage placement
NavRelativeDirType dir = (NavRelativeDirType)RANDOM_LONG(0, 3);
switch (dir)
{
case LEFT: me->StrafeLeft(); break;
case RIGHT: me->StrafeRight(); break;
case FORWARD: me->MoveForward(); break;
case BACKWARD: me->MoveBackward(); break;
}
// check if we are close enough to the hostage to talk to him
const float useRange = PLAYER_USE_RADIUS - 14.0f; // shave off a fudge factor to make sure we're within range
if (to.IsLengthLessThan(useRange))
{
me->UseEntity(me->GetGoalEntity());
return;
}
}
}
}
else if (me->GetTask() == CCSBot::RESCUE_HOSTAGES)
{
// periodically check if we lost all our hostages
if (me->GetHostageEscortCount() == 0)
{
// lost our hostages - go get 'em
me->Idle();
return;
}
}
break;
}
}
#endif
if (me->UpdatePathMovement() != CCSBot::PROGRESSING)
{
// reached destination
switch (me->GetTask())
{
#if 0
case CCSBot::PLANT_BOMB:
{
// if we are at bombsite with the bomb, plant it
if (me->IsAtBombsite() && me->IsCarryingBomb())
{
me->PlantBomb();
return;
}
break;
}
case CCSBot::DEFUSE_BOMB:
{
if (!me->IsActiveWeaponReloading())
{
// if we are near the bomb, defuse it (if we are reloading, don't try to defuse until we finish)
const Vector *bombPos = me->GetGameState()->GetBombPosition();
if (bombPos != NULL)
{
const float defuseRange = 100.0f;
Vector toBomb = *bombPos - me->pev->origin + Vector(0, 0, me->GetFeetZ());
if (toBomb.IsLengthLessThan(defuseRange))
{
me->DefuseBomb();
return;
}
}
}
break;
}
#endif
case CCSBot::MOVE_TO_LAST_KNOWN_ENEMY_POSITION:
{
CBasePlayer *victim = static_cast<CBasePlayer *>(me->GetTaskEntity());

View File

@ -24,17 +24,9 @@ void UseEntityState::OnUpdate(CCSBot *me)
me->SetLookAt("Use entity", &pos, PRIORITY_HIGH);
// if we are looking at the entity, "use" it and exit
/// todo
// if (me->IsLookingAtPosition(&pos))
{
#if 0
if (TheCSBots()->GetScenario() == CCSBotManager::SCENARIO_RESCUE_HOSTAGES
&& me->m_iTeam == CT
&& me->GetTask() == CCSBot::COLLECT_HOSTAGES)
{
// we are collecting a hostage, assume we were successful - the update check will correct us if we weren't
me->IncreaseHostageEscortCount();
}
#endif
me->UseEnvironment();
me->Idle();
}