Skip to content

Instantly share code, notes, and snippets.

@sigsegv-mvm
Last active March 30, 2024 03:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sigsegv-mvm/fd30ba1aac06d7e887402f1abfedcce2 to your computer and use it in GitHub Desktop.
Save sigsegv-mvm/fd30ba1aac06d7e887402f1abfedcce2 to your computer and use it in GitHub Desktop.
TFBot AI logic for using the BASE Jumper item
// Based on ServerLinux 20170616a
//
// SUMMARY: when TFBots have the BASE Jumper equipped, they will press their jump button in the following manner:
//
// If their parachute is not yet deployed, they will start holding down the jump button to deploy it if:
// - their health is at least 50%
// - AND they are not on fire
// - AND they are moving downward
// - AND they are at least 300 HU above the ground
//
// If their parachute is currently deployed, they will continue holding down the jump button until:
// - their health falls below 50%
// - OR they catch on fire
// - OR they reach a height of less than 150 HU above the ground
//
CTFBotUseItem *CTFBot::OpportunisticallyUseWeaponAbilities()
{
// ...
// CTFPlayerShared+0x0340: bool m_bShieldEquipped
// CTFPlayerShared+0x0341: bool m_bParachuteEquipped
if (this->IsPlayerClass(TF_CLASS_DEMOMAN) && this->m_Shared.m_bShieldEquipped) {
// ...
} else if (this->m_Shared.m_bParachuteEquipped) {
bool burning = this->m_Shared.InCond(TF_COND_BURNING);
float health_ratio = ((float)this->GetHealth() / (float)this->GetMaxHealth());
auto l_is_above_ground = [](CTFBot *actor, float min_height){
Vector from = actor->GetAbsOrigin();
Vector to = actor->GetAbsOrigin() - Vector(0.0f, 0.0f, min_height);
return !actor->GetLocomotionInterface()->IsPotentiallyTraversable(from, to, ILocomotion::TRAVERSE_DEFAULT);
};
if (this->m_Shared.InCond(TF_COND_PARACHUTE_DEPLOYED)) {
if (health_ratio >= 0.5f && !burning && !l_is_above_ground(this, 150.0f)) {
this->PressJumpButton();
} else {
// implicit: release jump button
}
} else {
if (health_ratio >= 0.5f && !burning && this->GetAbsVelocity().z < 0.0f && !l_is_above_ground(this, 300.0f)) {
this->PressJumpButton();
} else {
// implicit: release jump button
}
}
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment