Skip to content

Commit

Permalink
escape feature for bots (#1012)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaqtincha authored Sep 17, 2024
1 parent 3f628ea commit 9b7b169
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
7 changes: 7 additions & 0 deletions regamedll/dlls/bot/cs_bot_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,13 @@ void CCSBotManager::ValidateMapData()
found = true;
isLegacy = false;
}
else if (FClassnameIs(pEntity->pev, "func_escapezone"))
{
m_gameScenario = SCENARIO_ESCAPE;
found = true;
isLegacy = false;
}


if (found)
{
Expand Down
3 changes: 2 additions & 1 deletion regamedll/dlls/bot/cs_bot_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class CCSBotManager: public CBotManager
SCENARIO_DEATHMATCH,
SCENARIO_DEFUSE_BOMB,
SCENARIO_RESCUE_HOSTAGES,
SCENARIO_ESCORT_VIP
SCENARIO_ESCORT_VIP,
SCENARIO_ESCAPE
};

GameScenarioType GetScenario() const
Expand Down
87 changes: 87 additions & 0 deletions regamedll/dlls/bot/states/cs_bot_idle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,93 @@ void IdleState::OnUpdate(CCSBot *me)
}
break;
}
case CCSBotManager::SCENARIO_ESCAPE:
{
if (me->m_iTeam == TERRORIST)
{
// if early in round, pick a random zone, otherwise pick closest zone
const float earlyTime = 20.0f;
const CCSBotManager::Zone *zone = nullptr;

if (TheCSBots()->GetElapsedRoundTime() < earlyTime)
{
// pick random zone
zone = TheCSBots()->GetRandomZone();
}
else
{
// pick closest zone
zone = TheCSBots()->GetClosestZone(me->GetLastKnownArea(), PathCost(me));
}

if (zone)
{
// pick a random spot within the escape zone
const Vector *pos = TheCSBots()->GetRandomPositionInZone(zone);
if (pos)
{
// move to escape zone
// me->SetTask(CCSBot::VIP_ESCAPE);
me->Run();
me->MoveTo(pos);
return;
}
}
}
// CT
else
{
if (me->IsSniper())
{
if (RANDOM_FLOAT(0, 100) <= defenseSniperCampChance)
{
// snipe escape zone(s)
const CCSBotManager::Zone *zone = TheCSBots()->GetRandomZone();
if (zone)
{
CNavArea *area = TheCSBots()->GetRandomAreaInZone(zone);
if (area)
{
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() || TheCSBots()->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 = TheCSBots()->GetRandomZone();
if (zone)
{
CNavArea *area = TheCSBots()->GetRandomAreaInZone(zone);
if (area)
{
// 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;
}
}
}
}
}
// deathmatch
default:
{
Expand Down

1 comment on commit 9b7b169

@MysticDeathProject
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Krasava ❤️

Please sign in to comment.