refactor: clang-tidy source a little

build: remove -fPIC option
This commit is contained in:
dmitry 2021-09-16 16:09:51 +03:00
commit f051fe2b99
No known key found for this signature in database
GPG key ID: 8297CE728B7A7E37
13 changed files with 88 additions and 94 deletions

@ -1 +1 @@
Subproject commit 544851dd2f24a2fd4d11633167c773d98383ba29 Subproject commit 26c617d0a0cd18238a62f6e829da9161b7d56bd0

View file

@ -152,7 +152,7 @@ public:
void testLine (const Vector &start, const Vector &end, int ignoreFlags, edict_t *ignoreEntity, TraceResult *ptr); void testLine (const Vector &start, const Vector &end, int ignoreFlags, edict_t *ignoreEntity, TraceResult *ptr);
// trace line with channel, but allows us to store last traceline bot has fired, saving us some cpu cycles // trace line with channel, but allows us to store last traceline bot has fired, saving us some cpu cycles
bool testLineChannel (TraceChannel channel, const Vector &start, const Vector &end, int ignoreFlags, edict_t *ignoreEntity, TraceResult *ptr); bool testLineChannel (TraceChannel channel, const Vector &start, const Vector &end, int ignoreFlags, edict_t *ignoreEntity, TraceResult &result);
// test line // test line
void testHull (const Vector &start, const Vector &end, int ignoreFlags, int hullNumber, edict_t *ignoreEntity, TraceResult *ptr); void testHull (const Vector &start, const Vector &end, int ignoreFlags, int hullNumber, edict_t *ignoreEntity, TraceResult *ptr);
@ -170,7 +170,7 @@ public:
const char *getMapName (); const char *getMapName ();
// get the "any" entity origin // get the "any" entity origin
Vector getEntityWorldOrigin (edict_t *ent); Vector getEntityOrigin (edict_t *ent);
// registers a server command // registers a server command
void registerEngineCommand (const char *command, void func ()); void registerEngineCommand (const char *command, void func ());
@ -574,7 +574,7 @@ public:
public: public:
template <typename T> T read () { template <typename T> T read () {
T result; T result {};
auto size = sizeof (T); auto size = sizeof (T);
if (m_cursor + size > m_buffer.length ()) { if (m_cursor + size > m_buffer.length ()) {

View file

@ -1137,8 +1137,8 @@ public:
} }
// get the bot last trace result // get the bot last trace result
TraceResult *getLastTraceResult (TraceChannel channel) { TraceResult &getLastTraceResult (TraceChannel channel) {
return &m_lastTrace[channel]; return m_lastTrace[channel];
} }
// prints debug message // prints debug message
@ -1171,6 +1171,18 @@ extern ConVar cv_quota;
extern ConVar cv_difficulty; extern ConVar cv_difficulty;
extern ConVar cv_attack_monsters; extern ConVar cv_attack_monsters;
extern ConVar cv_pickup_custom_items; extern ConVar cv_pickup_custom_items;
extern ConVar cv_economics_rounds;
extern ConVar cv_shoots_thru_walls;
extern ConVar cv_debug;
extern ConVar cv_debug_goal;
extern ConVar mp_freezetime;
extern ConVar mp_roundtime;
extern ConVar mp_timelimit;
extern ConVar mp_limitteams;
extern ConVar mp_autoteambalance;
extern ConVar mp_footsteps;
extern ConVar mp_startmoney;
// execute client command helper // execute client command helper
template <typename ...Args> void Bot::issueCommand (const char *fmt, Args &&...args) { template <typename ...Args> void Bot::issueCommand (const char *fmt, Args &&...args) {

View file

@ -329,7 +329,7 @@ void Bot::avoidGrenades () {
if (m_preventFlashing < game.time () && m_personality == Personality::Rusher && m_difficulty == Difficulty::Expert && strcmp (model, "flashbang.mdl") == 0) { if (m_preventFlashing < game.time () && m_personality == Personality::Rusher && m_difficulty == Difficulty::Expert && strcmp (model, "flashbang.mdl") == 0) {
// don't look at flash bang // don't look at flash bang
if (!(m_states & Sense::SeeingEnemy)) { if (!(m_states & Sense::SeeingEnemy)) {
pev->v_angle.y = cr::normalizeAngles ((game.getEntityWorldOrigin (pent) - getEyesPos ()).angles ().y + 180.0f); pev->v_angle.y = cr::normalizeAngles ((game.getEntityOrigin (pent) - getEyesPos ()).angles ().y + 180.0f);
m_canChooseAimDirection = false; m_canChooseAimDirection = false;
m_preventFlashing = game.time () + rg.get (1.0f, 2.0f); m_preventFlashing = game.time () + rg.get (1.0f, 2.0f);
@ -402,7 +402,7 @@ void Bot::checkBreakablesAround () {
if (!game.isShootableBreakable (breakable)) { if (!game.isShootableBreakable (breakable)) {
continue; continue;
} }
const auto &origin = game.getEntityWorldOrigin (breakable); const auto &origin = game.getEntityOrigin (breakable);
const auto lengthToObstacle = (origin - pev->origin).lengthSq (); const auto lengthToObstacle = (origin - pev->origin).lengthSq ();
// too far, skip it // too far, skip it
@ -437,7 +437,7 @@ edict_t *Bot::lookupBreakable () {
// check if this isn't a triggered (bomb) breakable and if it takes damage. if true, shoot the crap! // check if this isn't a triggered (bomb) breakable and if it takes damage. if true, shoot the crap!
if (game.isShootableBreakable (ent)) { if (game.isShootableBreakable (ent)) {
m_breakableOrigin = game.getEntityWorldOrigin (ent); m_breakableOrigin = game.getEntityOrigin (ent);
return ent; return ent;
} }
} }
@ -447,7 +447,7 @@ edict_t *Bot::lookupBreakable () {
auto ent = tr.pHit; auto ent = tr.pHit;
if (game.isShootableBreakable (ent)) { if (game.isShootableBreakable (ent)) {
m_breakableOrigin = game.getEntityWorldOrigin (ent); m_breakableOrigin = game.getEntityOrigin (ent);
return ent; return ent;
} }
} }
@ -501,7 +501,7 @@ void Bot::updatePickups () {
if (ent->v.effects & EF_NODRAW) { if (ent->v.effects & EF_NODRAW) {
continue; continue;
} }
const Vector &origin = game.getEntityWorldOrigin (ent); const Vector &origin = game.getEntityOrigin (ent);
// too far from us ? // too far from us ?
if ((pev->origin - origin).lengthSq () > radius) { if ((pev->origin - origin).lengthSq () > radius) {
@ -536,7 +536,7 @@ void Bot::updatePickups () {
bool allowPickup = false; // assume can't use it until known otherwise bool allowPickup = false; // assume can't use it until known otherwise
// get the entity origin // get the entity origin
const auto &origin = game.getEntityWorldOrigin (ent); const auto &origin = game.getEntityOrigin (ent);
if ((ent->v.effects & EF_NODRAW) || ent == m_itemIgnore || cr::abs (origin.z - pev->origin.z) > 96.0f) { if ((ent->v.effects & EF_NODRAW) || ent == m_itemIgnore || cr::abs (origin.z - pev->origin.z) > 96.0f) {
continue; // someone owns this weapon or it hasn't respawned yet continue; // someone owns this weapon or it hasn't respawned yet
@ -734,7 +734,6 @@ void Bot::updatePickups () {
} }
else if (pickupType == Pickup::PlantedC4) { else if (pickupType == Pickup::PlantedC4) {
if (util.isAlive (m_enemy)) { if (util.isAlive (m_enemy)) {
allowPickup = false;
return; return;
} }
@ -743,9 +742,6 @@ void Bot::updatePickups () {
// then start escape from bomb immediate // then start escape from bomb immediate
startTask (Task::EscapeFromBomb, TaskPri::EscapeFromBomb, kInvalidNodeIndex, 0.0f, true); startTask (Task::EscapeFromBomb, TaskPri::EscapeFromBomb, kInvalidNodeIndex, 0.0f, true);
// and no pickup
allowPickup = false;
return; return;
} }
@ -931,8 +927,8 @@ void Bot::instantChatter (int type) {
return; return;
} }
auto playbackSound = conf.pickRandomFromChatterBank (type); const auto &playbackSound = conf.pickRandomFromChatterBank (type);
auto painSound = conf.pickRandomFromChatterBank (Chatter::DiePain); const auto &painSound = conf.pickRandomFromChatterBank (Chatter::DiePain);
if (m_notKilled) { if (m_notKilled) {
showChaterIcon (true); showChaterIcon (true);
@ -1001,8 +997,6 @@ void Bot::pushChatterMessage (int message) {
void Bot::checkMsgQueue () { void Bot::checkMsgQueue () {
// this function checks and executes pending messages // this function checks and executes pending messages
extern ConVar mp_freezetime;
// no new message? // no new message?
if (m_msgQueue.empty ()) { if (m_msgQueue.empty ()) {
return; return;
@ -1294,7 +1288,7 @@ void Bot::buyStuff () {
} }
int count = 0, weaponCount = 0; int count = 0, weaponCount = 0;
int choices[kNumWeapons]; int choices[kNumWeapons] {};
// select the priority tab for this personality // select the priority tab for this personality
const int *pref = conf.getWeaponPrefs (m_personality) + kNumWeapons; const int *pref = conf.getWeaponPrefs (m_personality) + kNumWeapons;
@ -1896,7 +1890,7 @@ void Bot::filterTasks () {
filter[Task::PickupItem].desire = 50.0f; // always pickup button filter[Task::PickupItem].desire = 50.0f; // always pickup button
} }
else { else {
float distance = (500.0f - (game.getEntityWorldOrigin (m_pickupItem) - pev->origin).length ()) * 0.2f; float distance = (500.0f - (game.getEntityOrigin (m_pickupItem) - pev->origin).length ()) * 0.2f;
if (distance > 50.0f) { if (distance > 50.0f) {
distance = 50.0f; distance = 50.0f;
@ -4448,7 +4442,7 @@ void Bot::pickupItem_ () {
return; return;
} }
const Vector &dest = game.getEntityWorldOrigin (m_pickupItem); const Vector &dest = game.getEntityOrigin (m_pickupItem);
m_destOrigin = dest; m_destOrigin = dest;
m_entity = dest; m_entity = dest;
@ -4948,7 +4942,7 @@ void Bot::showDebugOverlay () {
return; return;
} }
static float timeDebugUpdate = 0.0f; static float timeDebugUpdate = 0.0f;
static int index, goal, taskID; static int index = kInvalidNodeIndex, goal = kInvalidNodeIndex, taskID = 0;
static HashMap <int32, String> tasks; static HashMap <int32, String> tasks;
static HashMap <int32, String> personalities; static HashMap <int32, String> personalities;
@ -5526,7 +5520,7 @@ bool Bot::canSkipNextTrace (TraceChannel channel) {
// for optmization purposes skip every second traceline fired, this doesn't affect ai // for optmization purposes skip every second traceline fired, this doesn't affect ai
// behaviour too much, but saves alot of cpu cycles. // behaviour too much, but saves alot of cpu cycles.
constexpr auto kSkipTrace = 3; constexpr auto kSkipTrace = 4;
// check if we're have to skip // check if we're have to skip
if ((++m_traceSkip[channel] % kSkipTrace) == 0) { if ((++m_traceSkip[channel] % kSkipTrace) == 0) {
@ -5743,7 +5737,6 @@ void Bot::updateHearing () {
} }
} }
} }
extern ConVar cv_shoots_thru_walls;
// check if heard enemy can be seen // check if heard enemy can be seen
if (checkBodyParts (player)) { if (checkBodyParts (player)) {

View file

@ -156,7 +156,7 @@ bool Bot::checkBodyParts (edict_t *target) {
else { else {
spot.z = target->v.origin.z - standFeet; spot.z = target->v.origin.z - standFeet;
} }
game.testLineChannel (TraceChannel::Enemy, eyes, spot, TraceIgnore::Everything, self, &result); game.testLineChannel (TraceChannel::Enemy, eyes, spot, TraceIgnore::Everything, self, result);
if (result.flFraction >= 1.0f) { if (result.flFraction >= 1.0f) {
m_enemyParts |= Visibility::Other; m_enemyParts |= Visibility::Other;
@ -171,7 +171,7 @@ bool Bot::checkBodyParts (edict_t *target) {
Vector perp (-dir.y, dir.x, 0.0f); Vector perp (-dir.y, dir.x, 0.0f);
spot = target->v.origin + Vector (perp.x * edgeOffset, perp.y * edgeOffset, 0); spot = target->v.origin + Vector (perp.x * edgeOffset, perp.y * edgeOffset, 0);
game.testLineChannel (TraceChannel::Enemy, eyes, spot, TraceIgnore::Everything, self, &result); game.testLineChannel (TraceChannel::Enemy, eyes, spot, TraceIgnore::Everything, self, result);
if (result.flFraction >= 1.0f) { if (result.flFraction >= 1.0f) {
m_enemyParts |= Visibility::Other; m_enemyParts |= Visibility::Other;
@ -181,7 +181,7 @@ bool Bot::checkBodyParts (edict_t *target) {
} }
spot = target->v.origin - Vector (perp.x * edgeOffset, perp.y * edgeOffset, 0); spot = target->v.origin - Vector (perp.x * edgeOffset, perp.y * edgeOffset, 0);
game.testLineChannel (TraceChannel::Enemy, eyes, spot, TraceIgnore::Everything, self, &result); game.testLineChannel (TraceChannel::Enemy, eyes, spot, TraceIgnore::Everything, self, result);
if (result.flFraction >= 1.0f) { if (result.flFraction >= 1.0f) {
m_enemyParts |= Visibility::Other; m_enemyParts |= Visibility::Other;
@ -326,8 +326,8 @@ bool Bot::lookupEnemies () {
newEnemy = shieldEnemy; newEnemy = shieldEnemy;
} }
} }
if (util.isPlayer (newEnemy) || (cv_attack_monsters.bool_ () && util.isMonster (newEnemy))) { if (newEnemy != nullptr && (util.isPlayer (newEnemy) || (cv_attack_monsters.bool_ () && util.isMonster (newEnemy)))) {
bots.setCanPause (true); bots.setCanPause (true);
m_aimFlags |= AimFlags::Enemy; m_aimFlags |= AimFlags::Enemy;
@ -924,7 +924,7 @@ void Bot::fireWeapons () {
} }
// use knife if near and good difficulty (l33t dude!) // use knife if near and good difficulty (l33t dude!)
if (cv_stab_close_enemies.bool_ () && m_difficulty >= Difficulty::Hard && m_healthValue > 80.0f && !game.isNullEntity (enemy) && m_healthValue >= enemy->v.health && distance < 100.0f && !isOnLadder () && !isGroupOfEnemies (pev->origin)) { if (cv_stab_close_enemies.bool_ () && m_difficulty >= Difficulty::Normal && m_healthValue > 80.0f && !game.isNullEntity (enemy) && m_healthValue >= enemy->v.health && distance < 100.0f && !isOnLadder () && !isGroupOfEnemies (pev->origin)) {
selectWeapons (distance, selectIndex, selectId, choosenWeapon); selectWeapons (distance, selectIndex, selectId, choosenWeapon);
return; return;
} }

View file

@ -335,7 +335,7 @@ void BotConfig::loadChatterConfig () {
for (auto &sound : sounds) { for (auto &sound : sounds) {
sound.trim ().trim ("\""); sound.trim ().trim ("\"");
float duration = game.getWaveLen (sound.chars ()); auto duration = game.getWaveLen (sound.chars ());
if (duration > 0.0f) { if (duration > 0.0f) {
m_chatter[event.code].emplace (cr::move (sound), event.repeat, duration); m_chatter[event.code].emplace (cr::move (sound), event.repeat, duration);
@ -582,7 +582,7 @@ void BotConfig::loadDifficultyConfig () {
logger.error ("Error in difficulty config file syntax... Please correct all errors."); logger.error ("Error in difficulty config file syntax... Please correct all errors.");
continue; continue;
} }
auto key = items[0].trim (); const auto &key = items[0].trim ();
// get our keys // get our keys
if (key == "Noob") { if (key == "Noob") {

View file

@ -349,7 +349,7 @@ int BotControl::cmdNode () {
} }
} }
if (commands.has (strValue (cmd))) { if (commands.has (strValue (cmd))) {
auto item = commands[strValue (cmd)]; const auto &item = commands[strValue (cmd)];
// graph have only bad format return status // graph have only bad format return status
int status = (this->*item.handler) (); int status = (this->*item.handler) ();
@ -405,8 +405,6 @@ int BotControl::cmdNodeOn () {
} }
if (graph.hasEditFlag (GraphEdit::On)) { if (graph.hasEditFlag (GraphEdit::On)) {
extern ConVar mp_roundtime, mp_freezetime, mp_timelimit;
mp_roundtime.set (9); mp_roundtime.set (9);
mp_freezetime.set (0); mp_freezetime.set (0);
mp_timelimit.set (0); mp_timelimit.set (0);
@ -914,7 +912,6 @@ int BotControl::menuFeatures (int item) {
break; break;
case 4: case 4:
extern ConVar cv_debug;
cv_debug.set (cv_debug.int_ () ^ 1); cv_debug.set (cv_debug.int_ () ^ 1);
showMenu (Menu::Features); showMenu (Menu::Features);
@ -1067,8 +1064,6 @@ int BotControl::menuTeamSelect (int item) {
closeMenu (); // reset menu display closeMenu (); // reset menu display
if (item < 3) { if (item < 3) {
extern ConVar mp_limitteams, mp_autoteambalance;
// turn off cvars if specified team // turn off cvars if specified team
mp_limitteams.set (0); mp_limitteams.set (0);
mp_autoteambalance.set (0); mp_autoteambalance.set (0);

View file

@ -212,7 +212,7 @@ void Game::testLine (const Vector &start, const Vector &end, int ignoreFlags, ed
engfuncs.pfnTraceLine (start, end, engineFlags, ignoreEntity, ptr); engfuncs.pfnTraceLine (start, end, engineFlags, ignoreEntity, ptr);
} }
bool Game::testLineChannel (TraceChannel channel, const Vector &start, const Vector &end, int ignoreFlags, edict_t *ignoreEntity, TraceResult *ptr) { bool Game::testLineChannel (TraceChannel channel, const Vector &start, const Vector &end, int ignoreFlags, edict_t *ignoreEntity, TraceResult &result) {
// this function traces a line dot by dot, starting from vecStart in the direction of vecEnd, // this function traces a line dot by dot, starting from vecStart in the direction of vecEnd,
// ignoring or not monsters (depending on the value of IGNORE_MONSTERS, true or false), and stops // ignoring or not monsters (depending on the value of IGNORE_MONSTERS, true or false), and stops
// at the first obstacle encountered, returning the results of the trace in the TraceResult structure // at the first obstacle encountered, returning the results of the trace in the TraceResult structure
@ -225,17 +225,17 @@ bool Game::testLineChannel (TraceChannel channel, const Vector &start, const Vec
// check if bot is firing trace line // check if bot is firing trace line
if (bot && bot->canSkipNextTrace (channel)) { if (bot && bot->canSkipNextTrace (channel)) {
ptr = bot->getLastTraceResult (channel); // set the result from bot stored one result = bot->getLastTraceResult (channel); // set the result from bot stored one
// current call is skipped // current call is skipped
return true; return true;
} }
else { else {
testLine (start, end, ignoreFlags, ignoreEntity, ptr); testLine (start, end, ignoreFlags, ignoreEntity, &result);
// if we're still reaching here, save the last trace result // if we're still reaching here, save the last trace result
if (bot) { if (bot) {
bot->setLastTraceResult (channel, ptr); bot->setLastTraceResult (channel, &result);
} }
} }
return false; return false;
@ -326,7 +326,13 @@ float Game::getWaveLen (const char *fileName) {
logger.error ("Wave File %s - has zero length!", filePath); logger.error ("Wave File %s - has zero length!", filePath);
return 0.0f; return 0.0f;
} }
return 1.0f * weh.read32 (header.dataChunkLength) / (weh.read16 (header.bitsPerSample) / 8) / weh.read16 (header.numChannels) / weh.read32 (header.sampleRate);
auto length = static_cast <float> (weh.read32 (header.dataChunkLength));
auto bps = static_cast <float> (weh.read16 (header.bitsPerSample)) / 8;
auto channels = static_cast <float> (weh.read16 (header.numChannels));
auto rate = static_cast <float> (weh.read32 (header.sampleRate));
return length / bps / channels / rate;
} }
bool Game::isDedicated () { bool Game::isDedicated () {
@ -364,7 +370,7 @@ const char *Game::getMapName () {
return strings.format ("%s", globals->mapname.chars ()); return strings.format ("%s", globals->mapname.chars ());
} }
Vector Game::getEntityWorldOrigin (edict_t *ent) { Vector Game::getEntityOrigin (edict_t *ent) {
// this expanded function returns the vector origin of a bounded entity, assuming that any // this expanded function returns the vector origin of a bounded entity, assuming that any
// entity that has a bounding box has its center at the center of the bounding box itself. // entity that has a bounding box has its center at the center of the bounding box itself.

View file

@ -1133,15 +1133,15 @@ void BotGraph::calculatePathRadius (int index) {
TraceResult tr {}; TraceResult tr {};
bool wayBlocked = false; bool wayBlocked = false;
for (float scanDistance = 32.0f; scanDistance < 128.0f; scanDistance += 16.0f) { for (int32 scanDistance = 32; scanDistance < 128; scanDistance += 16) {
start = path.origin; start = path.origin;
direction = Vector (0.0f, 0.0f, 0.0f).forward () * scanDistance; direction = Vector (0.0f, 0.0f, 0.0f).forward () * scanDistance;
direction = direction.angles (); direction = direction.angles ();
path.radius = scanDistance; path.radius = static_cast <float> (scanDistance);
for (float circleRadius = 0.0f; circleRadius < 360.0f; circleRadius += 20.0f) { for (int32 circleRadius = 0; circleRadius < 360; circleRadius += 20) {
const auto &forward = direction.forward (); const auto &forward = direction.forward ();
auto radiusStart = start + forward * scanDistance; auto radiusStart = start + forward * scanDistance;
@ -1195,7 +1195,7 @@ void BotGraph::calculatePathRadius (int index) {
break; break;
} }
direction.y = cr::normalizeAngles (direction.y + circleRadius); direction.y = cr::normalizeAngles (direction.y + static_cast <float> (circleRadius));
} }
if (wayBlocked) { if (wayBlocked) {
@ -1445,7 +1445,6 @@ void BotGraph::initNarrowPlaces () {
if (accumWeight > 1) { if (accumWeight > 1) {
path.flags |= NodeFlag::Narrow; path.flags |= NodeFlag::Narrow;
} }
accumWeight = 0;
} }
m_narrowChecked = true; m_narrowChecked = true;
} }
@ -1793,7 +1792,6 @@ bool BotGraph::loadGraphData () {
ctrl.msg ("Warning: Graph data is probably not for this map. Please check bots behaviour."); ctrl.msg ("Warning: Graph data is probably not for this map. Please check bots behaviour.");
} }
} }
extern ConVar cv_debug_goal;
cv_debug_goal.set (kInvalidNodeIndex); cv_debug_goal.set (kInvalidNodeIndex);
return true; return true;
@ -2683,7 +2681,7 @@ void BotGraph::addBasic () {
Vector up, down, front, back; Vector up, down, front, back;
const Vector &diff = ((ladderLeft - ladderRight) ^ Vector (0.0f, 0.0f, 0.0f)).normalize () * 15.0f; const Vector &diff = ((ladderLeft - ladderRight) ^ Vector (0.0f, 0.0f, 0.0f)).normalize () * 15.0f;
front = back = game.getEntityWorldOrigin (ent); front = back = game.getEntityOrigin (ent);
front = front + diff; // front front = front + diff; // front
back = back - diff; // back back = back - diff; // back
@ -2723,7 +2721,7 @@ void BotGraph::addBasic () {
auto autoCreateForEntity = [] (int type, const char *entity) { auto autoCreateForEntity = [] (int type, const char *entity) {
game.searchEntities ("classname", entity, [&] (edict_t *ent) { game.searchEntities ("classname", entity, [&] (edict_t *ent) {
const Vector &pos = game.getEntityWorldOrigin (ent); const Vector &pos = game.getEntityOrigin (ent);
if (graph.getNearestNoBuckets (pos, 50.0f) == kInvalidNodeIndex) { if (graph.getNearestNoBuckets (pos, 50.0f) == kInvalidNodeIndex) {
graph.add (type, pos); graph.add (type, pos);
@ -2813,7 +2811,7 @@ void BotGraph::setBombOrigin (bool reset, const Vector &pos) {
game.searchEntities ("classname", "grenade", [&] (edict_t *ent) { game.searchEntities ("classname", "grenade", [&] (edict_t *ent) {
if (util.isModel (ent, bombModel)) { if (util.isModel (ent, bombModel)) {
m_bombOrigin = game.getEntityWorldOrigin (ent); m_bombOrigin = game.getEntityOrigin (ent);
wasFound = true; wasFound = true;
return EntitySearchResult::Break; return EntitySearchResult::Break;

View file

@ -120,7 +120,7 @@ void BotManager::touchKillerEntity (Bot *bot) {
m_killerEntity->v.dmg_inflictor = bot->ent (); m_killerEntity->v.dmg_inflictor = bot->ent ();
m_killerEntity->v.dmg = (bot->pev->health + bot->pev->armorvalue) * 4.0f; m_killerEntity->v.dmg = (bot->pev->health + bot->pev->armorvalue) * 4.0f;
KeyValueData kv; KeyValueData kv {};
kv.szClassName = const_cast <char *> (prop.classname.chars ()); kv.szClassName = const_cast <char *> (prop.classname.chars ());
kv.szKeyName = "damagetype"; kv.szKeyName = "damagetype";
kv.szValue = const_cast <char *> (strings.format ("%d", cr::bit (4))); kv.szValue = const_cast <char *> (strings.format ("%d", cr::bit (4)));
@ -297,7 +297,7 @@ void BotManager::addbot (StringRef name, StringRef difficulty, StringRef persona
// this function is same as the function above, but accept as parameters string instead of integers // this function is same as the function above, but accept as parameters string instead of integers
BotRequest request {}; BotRequest request {};
StringRef any = "*"; static StringRef any = "*";
request.name = (name.empty () || name == any) ? StringRef ("\0") : name; request.name = (name.empty () || name == any) ? StringRef ("\0") : name;
request.difficulty = (difficulty.empty () || difficulty == any) ? -1 : difficulty.int_ (); request.difficulty = (difficulty.empty () || difficulty == any) ? -1 : difficulty.int_ ();
@ -306,7 +306,7 @@ void BotManager::addbot (StringRef name, StringRef difficulty, StringRef persona
request.personality = (personality.empty () || personality == any) ? -1 : personality.int_ (); request.personality = (personality.empty () || personality == any) ? -1 : personality.int_ ();
request.manual = manual; request.manual = manual;
m_addRequests.emplaceLast (cr::move (request)); addbot (request.name, request.difficulty, request.personality, request.team, request.skin, request.manual);
} }
void BotManager::maintainQuota () { void BotManager::maintainQuota () {
@ -394,8 +394,7 @@ void BotManager::maintainQuota () {
createRandom (); createRandom ();
} }
else if (desiredBotCount < botsInGame) { else if (desiredBotCount < botsInGame) {
auto tp = countTeamPlayers (); const auto &tp = countTeamPlayers ();
bool isKicked = false; bool isKicked = false;
if (tp.first > tp.second) { if (tp.first > tp.second) {
@ -754,7 +753,7 @@ float BotManager::getConnectTime (StringRef name, float original) {
// this function get's fake bot player time. // this function get's fake bot player time.
for (const auto &bot : m_bots) { for (const auto &bot : m_bots) {
if (name == bot->pev->netname.chars ()) { if (name.startsWith (bot->pev->netname.chars ())) {
return bot->getConnectionTime (); return bot->getConnectionTime ();
} }
} }
@ -823,8 +822,6 @@ void BotManager::updateTeamEconomics (int team, bool setTrue) {
// that have not enough money to buy primary (with economics), and if this result higher 80%, player is can't // that have not enough money to buy primary (with economics), and if this result higher 80%, player is can't
// buy primary weapons. // buy primary weapons.
extern ConVar cv_economics_rounds;
if (setTrue || !cv_economics_rounds.bool_ ()) { if (setTrue || !cv_economics_rounds.bool_ ()) {
m_economicsGood[team] = true; m_economicsGood[team] = true;
return; // don't check economics while economics disable return; // don't check economics while economics disable
@ -877,8 +874,6 @@ void BotManager::updateBotDifficulties () {
} }
void BotManager::balanceBotDifficulties () { void BotManager::balanceBotDifficulties () {
extern ConVar cv_whose_your_daddy;
// with nightmare difficulty, there is no balance // with nightmare difficulty, there is no balance
if (cv_whose_your_daddy.bool_ ()) { if (cv_whose_your_daddy.bool_ ()) {
return; return;
@ -918,7 +913,6 @@ Bot::Bot (edict_t *bot, int difficulty, int personality, int team, int skin) {
// we're not initializing all the variables in bot class, so do an ugly thing... memset this // we're not initializing all the variables in bot class, so do an ugly thing... memset this
plat.bzero (this, sizeof (*this)); plat.bzero (this, sizeof (*this));
int clientIndex = game.indexOfEntity (bot); int clientIndex = game.indexOfEntity (bot);
pev = &bot->v; pev = &bot->v;
@ -1496,7 +1490,7 @@ void Bot::updateTeamJoin () {
} }
if (m_wantedTeam != 1 && m_wantedTeam != 2) { if (m_wantedTeam != 1 && m_wantedTeam != 2) {
auto players = bots.countTeamPlayers (); const auto &players = bots.countTeamPlayers ();
// balance the team upon creation, we can't use game auto select (5) from now, as we use enforced skins belows // balance the team upon creation, we can't use game auto select (5) from now, as we use enforced skins belows
// due to we don't know the team bot selected, and TeamInfo messages still shows us we're spectators.. // due to we don't know the team bot selected, and TeamInfo messages still shows us we're spectators..

View file

@ -41,8 +41,6 @@ void MessageDispatcher::netMsgTextMsg () {
bots.updateTeamEconomics (Team::CT, true); bots.updateTeamEconomics (Team::CT, true);
bots.updateTeamEconomics (Team::Terrorist, true); bots.updateTeamEconomics (Team::Terrorist, true);
extern ConVar mp_startmoney;
// set balance for all players // set balance for all players
bots.forEach ([] (Bot *bot) { bots.forEach ([] (Bot *bot) {
bot->m_moneyAmount = mp_startmoney.int_ (); bot->m_moneyAmount = mp_startmoney.int_ ();

View file

@ -23,7 +23,7 @@ int Bot::findBestGoal () {
game.searchEntities ("classname", "weaponbox", [&] (edict_t *ent) { game.searchEntities ("classname", "weaponbox", [&] (edict_t *ent) {
if (util.isModel (ent, "backpack.mdl")) { if (util.isModel (ent, "backpack.mdl")) {
result = graph.getNearest (game.getEntityWorldOrigin (ent)); result = graph.getNearest (game.getEntityOrigin (ent));
if (graph.exists (result)) { if (graph.exists (result)) {
return EntitySearchResult::Break; return EntitySearchResult::Break;
@ -429,7 +429,7 @@ void Bot::checkTerrain (float movedDistance, const Vector &dirNormal) {
// collision check allowed if not flying through the air // collision check allowed if not flying through the air
if (isOnFloor () || isOnLadder () || isInWater ()) { if (isOnFloor () || isOnLadder () || isInWater ()) {
int state[kMaxCollideMoves * 2 + 1]; int state[kMaxCollideMoves * 2 + 1] {};
int i = 0; int i = 0;
Vector src {}, dst {}; Vector src {}, dst {};
@ -714,7 +714,7 @@ bool Bot::updateNavigation () {
if (!game.isNullEntity (tr.pHit) && game.isNullEntity (m_liftEntity) && strncmp (tr.pHit->v.classname.chars (), "func_door", 9) == 0) { if (!game.isNullEntity (tr.pHit) && game.isNullEntity (m_liftEntity) && strncmp (tr.pHit->v.classname.chars (), "func_door", 9) == 0) {
// if the door is near enough... // if the door is near enough...
if ((game.getEntityWorldOrigin (tr.pHit) - pev->origin).lengthSq () < 2500.0f) { if ((game.getEntityOrigin (tr.pHit) - pev->origin).lengthSq () < 2500.0f) {
ignoreCollision (); // don't consider being stuck ignoreCollision (); // don't consider being stuck
if (rg.chance (50)) { if (rg.chance (50)) {
@ -1814,8 +1814,8 @@ int Bot::findDefendNode (const Vector &origin) {
} }
TraceResult tr {}; TraceResult tr {};
int nodeIndex[kMaxNodeLinks]; int nodeIndex[kMaxNodeLinks] {};
int minDistance[kMaxNodeLinks]; int minDistance[kMaxNodeLinks] {};
for (int i = 0; i < kMaxNodeLinks; ++i) { for (int i = 0; i < kMaxNodeLinks; ++i) {
nodeIndex[i] = kInvalidNodeIndex; nodeIndex[i] = kInvalidNodeIndex;
@ -1927,8 +1927,8 @@ int Bot::findCoverNode (float maxDistance) {
IntArray enemies; IntArray enemies;
int nodeIndex[kMaxNodeLinks]; int nodeIndex[kMaxNodeLinks] {};
int minDistance[kMaxNodeLinks]; int minDistance[kMaxNodeLinks] {};
for (int i = 0; i < kMaxNodeLinks; ++i) { for (int i = 0; i < kMaxNodeLinks; ++i) {
nodeIndex[i] = kInvalidNodeIndex; nodeIndex[i] = kInvalidNodeIndex;
@ -1997,7 +1997,7 @@ int Bot::findCoverNode (float maxDistance) {
minDistance[i] += practice; minDistance[i] += practice;
} }
} }
bool sorting; bool sorting = false;
// sort resulting nodes for nearest distance // sort resulting nodes for nearest distance
do { do {
@ -2240,7 +2240,7 @@ bool Bot::cantMoveForward (const Vector &normal, TraceResult *tr) {
}; };
// trace from the bot's eyes straight forward... // trace from the bot's eyes straight forward...
traceResult = game.testLineChannel (TraceChannel::Body, src, forward, TraceIgnore::Monsters, ent (), tr); traceResult = game.testLineChannel (TraceChannel::Body, src, forward, TraceIgnore::Monsters, ent (), *tr);
// check if the trace hit something... // check if the trace hit something...
if (tr->flFraction < 1.0f) { if (tr->flFraction < 1.0f) {
@ -2255,7 +2255,7 @@ bool Bot::cantMoveForward (const Vector &normal, TraceResult *tr) {
src = getEyesPos () + Vector (0.0f, 0.0f, -16.0f) - right * -16.0f; src = getEyesPos () + Vector (0.0f, 0.0f, -16.0f) - right * -16.0f;
forward = getEyesPos () + Vector (0.0f, 0.0f, -16.0f) + right * 16.0f + normal * 24.0f; forward = getEyesPos () + Vector (0.0f, 0.0f, -16.0f) + right * 16.0f + normal * 24.0f;
traceResult = game.testLineChannel (TraceChannel::Body, src, forward, TraceIgnore::Monsters, ent (), tr); traceResult = game.testLineChannel (TraceChannel::Body, src, forward, TraceIgnore::Monsters, ent (), *tr);
// check if the trace hit something... // check if the trace hit something...
if (checkDoor (tr)) { if (checkDoor (tr)) {
@ -2267,7 +2267,7 @@ bool Bot::cantMoveForward (const Vector &normal, TraceResult *tr) {
src = getEyesPos () + Vector (0.0f, 0.0f, -16.0f) + right * 16.0f; src = getEyesPos () + Vector (0.0f, 0.0f, -16.0f) + right * 16.0f;
forward = getEyesPos () + Vector (0.0f, 0.0f, -16.0f) - right * -16.0f + normal * 24.0f; forward = getEyesPos () + Vector (0.0f, 0.0f, -16.0f) - right * -16.0f + normal * 24.0f;
traceResult = game.testLineChannel (TraceChannel::Body, src, forward, TraceIgnore::Monsters, ent (), tr); traceResult = game.testLineChannel (TraceChannel::Body, src, forward, TraceIgnore::Monsters, ent (), *tr);
// check if the trace hit something... // check if the trace hit something...
if (checkDoor (tr)) { if (checkDoor (tr)) {
@ -2279,7 +2279,7 @@ bool Bot::cantMoveForward (const Vector &normal, TraceResult *tr) {
src = pev->origin + Vector (0.0f, 0.0f, -19.0f + 19.0f); src = pev->origin + Vector (0.0f, 0.0f, -19.0f + 19.0f);
forward = src + Vector (0.0f, 0.0f, 10.0f) + normal * 24.0f; forward = src + Vector (0.0f, 0.0f, 10.0f) + normal * 24.0f;
traceResult = game.testLineChannel (TraceChannel::Body, src, forward, TraceIgnore::Monsters, ent (), tr); traceResult = game.testLineChannel (TraceChannel::Body, src, forward, TraceIgnore::Monsters, ent (), *tr);
// check if the trace hit something... // check if the trace hit something...
if (checkDoor (tr)) { if (checkDoor (tr)) {
@ -2288,7 +2288,7 @@ bool Bot::cantMoveForward (const Vector &normal, TraceResult *tr) {
src = pev->origin; src = pev->origin;
forward = src + normal * 24.0f; forward = src + normal * 24.0f;
traceResult = game.testLineChannel (TraceChannel::Body, src, forward, TraceIgnore::Monsters, ent (), tr); traceResult = game.testLineChannel (TraceChannel::Body, src, forward, TraceIgnore::Monsters, ent (), *tr);
// check if the trace hit something... // check if the trace hit something...
if (checkDoor (tr)) { if (checkDoor (tr)) {
@ -2301,7 +2301,7 @@ bool Bot::cantMoveForward (const Vector &normal, TraceResult *tr) {
forward = pev->origin + Vector (0.0f, 0.0f, -17.0f) + right * 16.0f + normal * 24.0f; forward = pev->origin + Vector (0.0f, 0.0f, -17.0f) + right * 16.0f + normal * 24.0f;
// trace from the bot's waist straight forward... // trace from the bot's waist straight forward...
traceResult = game.testLineChannel (TraceChannel::Body, src, forward, TraceIgnore::Monsters, ent (), tr); traceResult = game.testLineChannel (TraceChannel::Body, src, forward, TraceIgnore::Monsters, ent (), *tr);
// check if the trace hit something... // check if the trace hit something...
if (checkDoor (tr)) { if (checkDoor (tr)) {
@ -2312,7 +2312,7 @@ bool Bot::cantMoveForward (const Vector &normal, TraceResult *tr) {
src = pev->origin + Vector (0.0f, 0.0f, -24.0f) + right * 16.0f; src = pev->origin + Vector (0.0f, 0.0f, -24.0f) + right * 16.0f;
forward = pev->origin + Vector (0.0f, 0.0f, -24.0f) - right * -16.0f + normal * 24.0f; forward = pev->origin + Vector (0.0f, 0.0f, -24.0f) - right * -16.0f + normal * 24.0f;
traceResult = game.testLineChannel (TraceChannel::Body, src, forward, TraceIgnore::Monsters, ent (), tr); traceResult = game.testLineChannel (TraceChannel::Body, src, forward, TraceIgnore::Monsters, ent (), *tr);
// check if the trace hit something... // check if the trace hit something...
if (checkDoor (tr)) { if (checkDoor (tr)) {
@ -2759,9 +2759,9 @@ int Bot::findCampingDirection () {
m_currentNodeIndex = changePointIndex (findNearestNode ()); m_currentNodeIndex = changePointIndex (findNearestNode ());
} }
int count = 0, indices[3]; int count = 0, indices[3] {};
float distTab[3]; float distTab[3] {};
uint16 visibility[3]; uint16 visibility[3] {};
int currentNode = m_currentNodeIndex; int currentNode = m_currentNodeIndex;
@ -2978,7 +2978,7 @@ int Bot::getNearestToPlantedBomb () {
// search the bomb on the map // search the bomb on the map
game.searchEntities ("classname", "grenade", [&result, &bombModel] (edict_t *ent) { game.searchEntities ("classname", "grenade", [&result, &bombModel] (edict_t *ent) {
if (util.isModel (ent, bombModel)) { if (util.isModel (ent, bombModel)) {
result = graph.getNearest (game.getEntityWorldOrigin (ent)); result = graph.getNearest (game.getEntityOrigin (ent));
if (graph.exists (result)) { if (graph.exists (result)) {
return EntitySearchResult::Break; return EntitySearchResult::Break;
@ -3045,7 +3045,7 @@ edict_t *Bot::lookupButton (const char *target) {
// find the nearest button which can open our target // find the nearest button which can open our target
game.searchEntities ("target", target, [&] (edict_t *ent) { game.searchEntities ("target", target, [&] (edict_t *ent) {
const Vector &pos = game.getEntityWorldOrigin (ent); const Vector &pos = game.getEntityOrigin (ent);
// check if this place safe // check if this place safe
if (!isDeadlyMove (pos)) { if (!isDeadlyMove (pos)) {

View file

@ -370,12 +370,12 @@ bool BotSupport::findNearestPlayer (void **pvHolder, edict_t *to, float searchDi
} }
void BotSupport::listenNoise (edict_t *ent, StringRef sample, float volume) { void BotSupport::listenNoise (edict_t *ent, StringRef sample, float volume) {
// this function called by the sound hooking code (in emit_sound) enters the played sound into the array associated with the entity // this function called by the sound hooking code (in emit_sound) enters the played sound into the array associated with the entity
if (game.isNullEntity (ent) || sample.empty ()) { if (game.isNullEntity (ent) || sample.empty ()) {
return; return;
} }
const Vector &origin = game.getEntityWorldOrigin (ent); const auto &origin = game.getEntityOrigin (ent);
// something wrong with sound... // something wrong with sound...
if (origin.empty ()) { if (origin.empty ()) {
@ -496,8 +496,6 @@ void BotSupport::simulateNoise (int playerIndex) {
} }
} }
else { else {
extern ConVar mp_footsteps;
if (mp_footsteps.bool_ ()) { if (mp_footsteps.bool_ ()) {
// moves fast enough? // moves fast enough?
noise.dist = 1280.0f * (client.ent->v.velocity.length2d () / 260.0f); noise.dist = 1280.0f * (client.ent->v.velocity.length2d () / 260.0f);
@ -688,7 +686,7 @@ bool BotSupport::isObjectInsidePlane (FrustumPlane &plane, const Vector &center,
} }
bool BotSupport::isModel (const edict_t *ent, StringRef model) { bool BotSupport::isModel (const edict_t *ent, StringRef model) {
return model == ent->v.model.chars (9); return model.startsWith (ent->v.model.chars (9));
} }
int32 BotSupport::sendTo (int socket, const void *message, size_t length, int flags, const sockaddr *dest, int destLength) { int32 BotSupport::sendTo (int socket, const void *message, size_t length, int flags, const sockaddr *dest, int destLength) {