-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6462f0e
commit ab2a35e
Showing
20 changed files
with
427 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <extension.h> | ||
#include <util/entprops.h> | ||
#include <mods/tf2/teamfortress2mod.h> | ||
#include <mods/tf2/nav/tfnavmesh.h> | ||
#include <mods/tf2/nav/tfnavarea.h> | ||
#include <bot/tf2/tf2bot.h> | ||
#include "tf2bot_mvm_upgrade.h" | ||
#include "tf2bot_mvm_idle.h" | ||
|
||
TaskResult<CTF2Bot> CTF2BotMvMIdleTask::OnTaskStart(CTF2Bot* bot, AITask<CTF2Bot>* pastTask) | ||
{ | ||
return Continue(); | ||
} | ||
|
||
TaskResult<CTF2Bot> CTF2BotMvMIdleTask::OnTaskUpdate(CTF2Bot* bot) | ||
{ | ||
if (entprops->GameRules_GetRoundState() == RoundState_RoundRunning) | ||
{ | ||
// Wave has started! | ||
// TO-DO: Switch to combat task | ||
return Continue(); | ||
} | ||
|
||
// Wave has not started yet | ||
if (entprops->GameRules_GetRoundState() == RoundState_BetweenRounds) | ||
{ | ||
// Should the bot buy upgrades? | ||
if (bot->GetUpgradeManager().ShouldGoToAnUpgradeStation()) | ||
{ | ||
// Buy upgrades | ||
return PauseFor(new CTF2BotMvMUpgradeTask, "Going to use an upgrade station!"); | ||
} | ||
} | ||
|
||
// TO-DO: Move to defensive positions near the robot spawn | ||
// TO-DO: Engineer | ||
// TO-DO: Add ready up logic | ||
|
||
return Continue(); | ||
} | ||
|
||
TaskEventResponseResult<CTF2Bot> CTF2BotMvMIdleTask::OnMoveToFailure(CTF2Bot* bot, CPath* path, IEventListener::MovementFailureType reason) | ||
{ | ||
return TryContinue(); | ||
} | ||
|
||
TaskEventResponseResult<CTF2Bot> CTF2BotMvMIdleTask::OnMoveToSuccess(CTF2Bot* bot, CPath* path) | ||
{ | ||
return TryContinue(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef NAVBOT_TF2BOT_TASK_MVM_IDLE_H_ | ||
#define NAVBOT_TF2BOT_TASK_MVM_IDLE_H_ | ||
#pragma once | ||
|
||
#include <bot/interfaces/path/meshnavigator.h> | ||
|
||
class CTF2Bot; | ||
|
||
class CTF2BotMvMIdleTask : public AITask<CTF2Bot> | ||
{ | ||
public: | ||
TaskResult<CTF2Bot> OnTaskStart(CTF2Bot* bot, AITask<CTF2Bot>* pastTask) override; | ||
TaskResult<CTF2Bot> OnTaskUpdate(CTF2Bot* bot) override; | ||
|
||
TaskEventResponseResult<CTF2Bot> OnMoveToFailure(CTF2Bot* bot, CPath* path, IEventListener::MovementFailureType reason) override; | ||
TaskEventResponseResult<CTF2Bot> OnMoveToSuccess(CTF2Bot* bot, CPath* path) override; | ||
|
||
const char* GetName() const override { return "MvMIdle"; } | ||
private: | ||
CMeshNavigator m_nav; | ||
Vector m_goal; | ||
CountdownTimer m_repathtimer; | ||
}; | ||
|
||
#endif // !NAVBOT_TF2BOT_TASK_MVM_IDLE_H_ |
157 changes: 157 additions & 0 deletions
157
extension/bot/tf2/tasks/scenario/mvm/tf2bot_mvm_upgrade.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
#include <limits> | ||
|
||
#include <extension.h> | ||
#include <bot/tf2/tf2bot.h> | ||
#include <util/helpers.h> | ||
#include <entities/tf2/tf_entities.h> | ||
#include "tf2bot_mvm_upgrade.h" | ||
|
||
#undef min // undef valve mathlib stuff that causes issues with C++ STD lib | ||
#undef max | ||
#undef clamp | ||
|
||
TaskResult<CTF2Bot> CTF2BotMvMUpgradeTask::OnTaskStart(CTF2Bot* bot, AITask<CTF2Bot>* pastTask) | ||
{ | ||
if (!SelectNearestUpgradeStation(bot)) | ||
{ | ||
bot->GetUpgradeManager().OnDoneUpgrading(); // Mark as done | ||
return Done("No upgrade stations available!"); | ||
} | ||
|
||
SetGoalPosition(); | ||
|
||
CTF2BotPathCost cost(bot); | ||
if (!m_nav.ComputePathToPosition(bot, m_goal, cost)) | ||
{ | ||
return Done("Failed to find a path to the upgrade station"); | ||
} | ||
|
||
m_repathtimer.Start(2.0f); | ||
return Continue(); | ||
} | ||
|
||
TaskResult<CTF2Bot> CTF2BotMvMUpgradeTask::OnTaskUpdate(CTF2Bot* bot) | ||
{ | ||
auto& manager = bot->GetUpgradeManager(); | ||
|
||
if (manager.IsDoneForCurrentWave()) | ||
{ | ||
return Done("Done upgrading!"); | ||
} | ||
|
||
if (!bot->IsInUpgradeZone()) | ||
{ | ||
if (m_repathtimer.IsElapsed()) | ||
{ | ||
m_repathtimer.Start(2.0f); | ||
|
||
CTF2BotPathCost cost(bot); | ||
if (!m_nav.ComputePathToPosition(bot, m_goal, cost)) | ||
{ | ||
return Done("Failed to find a path to the upgrade station"); | ||
} | ||
} | ||
|
||
// Path to the upgrade station | ||
m_nav.Update(bot); | ||
} | ||
else | ||
{ | ||
manager.Update(); // bot is inside an upgrade zone, buy upgrades | ||
} | ||
|
||
return Continue(); | ||
} | ||
|
||
TaskEventResponseResult<CTF2Bot> CTF2BotMvMUpgradeTask::OnMoveToFailure(CTF2Bot* bot, CPath* path, IEventListener::MovementFailureType reason) | ||
{ | ||
m_repathtimer.Start(2.0f); | ||
|
||
CTF2BotPathCost cost(bot); | ||
if (!m_nav.ComputePathToPosition(bot, m_goal, cost)) | ||
{ | ||
return TryDone(PRIORITY_HIGH, "Failed to find a path to the upgrade station"); | ||
} | ||
|
||
return TryContinue(PRIORITY_LOW); | ||
} | ||
|
||
TaskEventResponseResult<CTF2Bot> CTF2BotMvMUpgradeTask::OnMoveToSuccess(CTF2Bot* bot, CPath* path) | ||
{ | ||
if (!bot->IsInUpgradeZone()) | ||
{ | ||
return TryDone(PRIORITY_HIGH, "Reached goal but outside upgrade zone."); | ||
} | ||
|
||
return TryContinue(PRIORITY_LOW); | ||
} | ||
|
||
bool CTF2BotMvMUpgradeTask::SelectNearestUpgradeStation(CTF2Bot* me) | ||
{ | ||
std::vector<edict_t*> upgradestations; | ||
upgradestations.reserve(8); | ||
|
||
UtilHelpers::ForEachEntityOfClassname("func_upgradestation", [&upgradestations](int index, edict_t* edict, CBaseEntity* entity) { | ||
if (edict == nullptr) | ||
{ | ||
return true; // return early, but keep looping. Upgrade stations should never have a NULL edict | ||
} | ||
|
||
tfentities::HTFBaseEntity basentity(edict); | ||
|
||
if (basentity.IsDisabled()) | ||
{ | ||
return true; // return early, keep loop | ||
} | ||
|
||
// upgrade station is not disabled, add to the list | ||
upgradestations.push_back(edict); | ||
|
||
return true; // continue looping | ||
}); | ||
|
||
if (upgradestations.empty()) | ||
{ | ||
return false; | ||
} | ||
|
||
Vector origin = me->GetAbsOrigin(); | ||
float best = std::numeric_limits<float>::max(); | ||
edict_t* target = nullptr; | ||
|
||
for (auto upgradeentity : upgradestations) | ||
{ | ||
Vector dest = UtilHelpers::getWorldSpaceCenter(upgradeentity); | ||
float distance = (dest - origin).Length(); | ||
|
||
if (distance < best) | ||
{ | ||
target = upgradeentity; | ||
best = distance; | ||
} | ||
|
||
} | ||
|
||
if (target == nullptr) | ||
{ | ||
return false; | ||
} | ||
|
||
UtilHelpers::SetHandleEntity(m_upgradestation, target); | ||
return true; | ||
} | ||
|
||
void CTF2BotMvMUpgradeTask::SetGoalPosition() | ||
{ | ||
Vector center = UtilHelpers::getWorldSpaceCenter(UtilHelpers::GetEdictFromCBaseHandle(m_upgradestation)); | ||
auto area = TheNavMesh->GetNearestNavArea(center, 1024.0f, false, false); | ||
|
||
if (area == nullptr) | ||
{ | ||
m_goal = center; | ||
return; | ||
} | ||
|
||
area->GetClosestPointOnArea(center, &m_goal); | ||
m_goal.z = area->GetCenter().z; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef NAVBOT_TF2BOT_TASK_MVM_UPGRADE_H_ | ||
#define NAVBOT_TF2BOT_TASK_MVM_UPGRADE_H_ | ||
#pragma once | ||
|
||
#include <bot/interfaces/path/meshnavigator.h> | ||
#include <basehandle.h> | ||
|
||
class CTF2Bot; | ||
|
||
class CTF2BotMvMUpgradeTask : public AITask<CTF2Bot> | ||
{ | ||
public: | ||
TaskResult<CTF2Bot> OnTaskStart(CTF2Bot* bot, AITask<CTF2Bot>* pastTask) override; | ||
TaskResult<CTF2Bot> OnTaskUpdate(CTF2Bot* bot) override; | ||
|
||
TaskEventResponseResult<CTF2Bot> OnMoveToFailure(CTF2Bot* bot, CPath* path, IEventListener::MovementFailureType reason) override; | ||
TaskEventResponseResult<CTF2Bot> OnMoveToSuccess(CTF2Bot* bot, CPath* path) override; | ||
|
||
const char* GetName() const override { return "MvMUpgrade"; } | ||
private: | ||
CMeshNavigator m_nav; | ||
Vector m_goal; | ||
CountdownTimer m_repathtimer; | ||
CBaseHandle m_upgradestation; | ||
|
||
bool SelectNearestUpgradeStation(CTF2Bot* me); | ||
void SetGoalPosition(); | ||
}; | ||
|
||
#endif // !NAVBOT_TF2BOT_TASK_MVM_UPGRADE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.