bot: transfer c4 to humans (if any) when ignore_objectives is on

This commit is contained in:
jeefo 2024-05-22 13:33:26 +03:00
commit 778d14b755
No known key found for this signature in database
GPG key ID: D696786B81B667C8
3 changed files with 64 additions and 4 deletions

View file

@ -502,6 +502,7 @@ private:
void updatePredictedIndex (); void updatePredictedIndex ();
void refreshCreatureStatus (char *infobuffer); void refreshCreatureStatus (char *infobuffer);
void updateRightRef (); void updateRightRef ();
void donateC4ToHuman ();
void completeTask (); void completeTask ();
void executeTasks (); void executeTasks ();

View file

@ -2898,6 +2898,9 @@ void Bot::update () {
m_hasC4 = !!(pev->weapons & cr::bit (Weapon::C4)); m_hasC4 = !!(pev->weapons & cr::bit (Weapon::C4));
if (m_hasC4 && (cv_ignore_objectives || cv_jasonmode)) { if (m_hasC4 && (cv_ignore_objectives || cv_jasonmode)) {
if (cv_ignore_objectives) {
donateC4ToHuman ();
}
m_hasC4 = false; m_hasC4 = false;
} }
} }
@ -4136,3 +4139,59 @@ bool Bot::isCreature () {
return m_isOnInfectedTeam || m_modelMask == kModelMaskZombie || m_modelMask == kModelMaskChicken; return m_isOnInfectedTeam || m_modelMask == kModelMaskZombie || m_modelMask == kModelMaskChicken;
} }
void Bot::donateC4ToHuman () {
edict_t *recepient = nullptr;
if (!m_hasC4) {
return;
}
const float radiusSq = cr::sqrf (1024.0f);
for (const auto &client : util.getClients ()) {
if (!(client.flags & ClientFlags::Used) || !(client.flags & ClientFlags::Alive) || client.team != m_team || client.ent == ent ()) {
continue;
}
if (client.origin.distanceSq (pev->origin) < radiusSq) {
recepient = client.ent;
break;
}
}
if (game.isNullEntity (recepient)) {
return;
}
m_itemCheckTime = game.time () + 2.0f;
// select the bomb
if (m_currentWeapon != Weapon::C4) {
selectWeaponById (Weapon::C4);
}
dropCurrentWeapon ();
// bomb on the ground entity
edict_t *bomb = nullptr;
// search world for just dropped bomb
game.searchEntities ("classname", "weaponbox", [&] (edict_t *ent) {
if (util.isModel (ent, "backpack.mdl")) {
bomb = ent;
if (!game.isNullEntity (bomb)) {
return EntitySearchResult::Break;
}
}
return EntitySearchResult::Continue;
});
// got c4 backpack
if (!game.isNullEntity (bomb)) {
bomb->v.flags |= FL_ONGROUND;
// make recepient frient "pickup" it
MDLL_Touch (bomb, recepient);
}
}

View file

@ -843,7 +843,7 @@ void BotManager::setWeaponMode (int selection) {
selection--; selection--;
constexpr int kStd[7][kNumWeapons] = { constexpr int kStdMaps[7][kNumWeapons] = {
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // Knife only {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // Knife only
{-1, -1, -1, 2, 2, 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // Pistols only {-1, -1, -1, 2, 2, 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // Pistols only
{-1, -1, -1, -1, -1, -1, -1, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // Shotgun only {-1, -1, -1, -1, -1, -1, -1, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // Shotgun only
@ -853,7 +853,7 @@ void BotManager::setWeaponMode (int selection) {
{-1, -1, -1, 2, 2, 0, 1, 2, 2, 2, 1, 2, 0, 2, 0, 0, 1, 0, 1, 1, 2, 2, 0, 1, 2, 1} // Standard {-1, -1, -1, 2, 2, 0, 1, 2, 2, 2, 1, 2, 0, 2, 0, 0, 1, 0, 1, 1, 2, 2, 0, 1, 2, 1} // Standard
}; };
constexpr int kAs[7][kNumWeapons] = { constexpr int kAsMaps[7][kNumWeapons] = {
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // Knife only {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // Knife only
{-1, -1, -1, 2, 2, 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // Pistols only {-1, -1, -1, 2, 2, 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // Pistols only
{-1, -1, -1, -1, -1, -1, -1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // Shotgun only {-1, -1, -1, -1, -1, -1, -1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // Shotgun only
@ -869,8 +869,8 @@ void BotManager::setWeaponMode (int selection) {
// set the correct weapon mode // set the correct weapon mode
for (int i = 0; i < kNumWeapons; ++i) { for (int i = 0; i < kNumWeapons; ++i) {
tab[i].teamStandard = kStd[selection][i]; tab[i].teamStandard = kStdMaps[selection][i];
tab[i].teamAS = kAs[selection][i]; tab[i].teamAS = kAsMaps[selection][i];
} }
cv_jasonmode.set (selection == 0 ? 1 : 0); cv_jasonmode.set (selection == 0 ? 1 : 0);