From 9eaca5a27b6e291ae7fe827b74792166fe0f42b1 Mon Sep 17 00:00:00 2001 From: jeefo Date: Fri, 31 May 2019 11:34:32 +0300 Subject: [PATCH] Minor refactoring. --- include/corelib.h | 40 ++++++++------ include/globals.h | 10 ++-- include/yapb.h | 2 +- source/basecode.cpp | 126 +++++++++++++++++++++---------------------- source/chatlib.cpp | 14 ++--- source/combat.cpp | 18 +++---- source/engine.cpp | 2 +- source/globals.cpp | 10 ++-- source/interface.cpp | 75 +++++++++++++------------- source/manager.cpp | 18 +++---- source/navigate.cpp | 8 +-- source/waypoint.cpp | 4 +- 12 files changed, 165 insertions(+), 162 deletions(-) diff --git a/include/corelib.h b/include/corelib.h index f8448f8..99527c4 100644 --- a/include/corelib.h +++ b/include/corelib.h @@ -359,6 +359,10 @@ public: inline float getFloat (float low, float high) { return static_cast (random () * (static_cast (high) - static_cast (low)) / (m_divider - 1) + static_cast (low)); } + + template inline bool chance (const U max, const U maxChance = 100) { + return getInt (0, maxChance) < max; + } }; class SimpleColor final : private NonCopyable { @@ -590,11 +594,13 @@ public: } }; -class Library { +class Library final : private NonCopyable { private: void *m_ptr; public: + explicit Library (void) : m_ptr (nullptr) { } + Library (const char *filename) : m_ptr (nullptr) { if (!filename) { return; @@ -603,6 +609,20 @@ public: } virtual ~Library (void) { + unload (); + } + +public: + inline void *load (const char *filename) noexcept { +#ifdef PLATFORM_WIN32 + m_ptr = LoadLibrary (filename); +#else + m_ptr = dlopen (filename, RTLD_NOW); +#endif + return m_ptr; + } + + inline void unload (void) noexcept { if (!isValid ()) { return; } @@ -613,16 +633,6 @@ public: #endif } -public: - inline void *load (const char *filename) { -#ifdef PLATFORM_WIN32 - m_ptr = LoadLibrary (filename); -#else - m_ptr = dlopen (filename, RTLD_NOW); -#endif - return m_ptr; - } - template R resolve (const char *function) { if (!isValid ()) { return nullptr; @@ -650,7 +660,7 @@ public: B second; public: - Pair (const A &a, const B &b) : first (a), second (b) { + Pair (const A &a, const B &b) : first (cr::move (a)), second (cr::move (b)) { } public: @@ -865,9 +875,7 @@ public: T *buffer = new T[m_length]; if (m_data != nullptr) { - for (size_t i = 0; i < m_length; i++) { - transfer (buffer, m_data); - } + transfer (buffer, m_data); delete[] m_data; } m_data = move (buffer); @@ -1829,5 +1837,3 @@ using StringArray = cr::classes::Array ; using IntArray = cr::classes::Array ; }} - - diff --git a/include/globals.h b/include/globals.h index d4825a6..c65899e 100644 --- a/include/globals.h +++ b/include/globals.h @@ -46,10 +46,10 @@ extern int g_lastRadio[MAX_TEAM_COUNT]; extern int g_storeAddbotVars[4]; extern int *g_weaponPrefs[]; -extern Array g_chatFactory; -extern Array> g_chatterFactory; -extern Array g_botNames; -extern Array g_replyFactory; +extern Array g_chatFactory; +extern Array > g_chatterFactory; +extern Array g_botNames; +extern Array g_replyFactory; extern WeaponSelect g_weaponSelect[NUM_WEAPONS + 1]; extern WeaponProperty g_weaponDefs[MAX_WEAPONS + 1]; @@ -61,7 +61,7 @@ extern Task g_taskFilters[TASK_MAX]; extern Experience *g_experienceData; extern edict_t *g_hostEntity; -extern Library *g_gameLib; +extern Library g_gameLib; extern gamefuncs_t g_functionTable; diff --git a/include/yapb.h b/include/yapb.h index 1f24449..6674f82 100644 --- a/include/yapb.h +++ b/include/yapb.h @@ -1037,7 +1037,7 @@ private: Vector isBombAudible (void); const Vector &getEnemyBodyOffset (void); - Vector getBodyOffserError (float distance); + Vector getBodyOffsetError (float distance); float getEnemyBodyOffsetCorrection (float distance); void processTeamCommands (void); diff --git a/source/basecode.cpp b/source/basecode.cpp index ff7767d..5685abd 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -157,7 +157,7 @@ void Bot::checkGrenadesThrow (void) { else if (grenadeToThrow == WEAPON_SMOKE) { cancelProb = 5; } - if (rng.getInt (0, 100) < cancelProb) { + if (rng.chance (cancelProb)) { clearThrowStates (m_states); return; } @@ -377,7 +377,7 @@ void Bot::avoidGrenades (void) { if (m_viewDistance > distance) { m_viewDistance = distance; - if (rng.getInt (0, 100) < 45) { + if (rng.chance (45)) { pushChatterMessage (CHATTER_BEHIND_SMOKE); } } @@ -690,7 +690,7 @@ void Bot::processPickups (void) { m_itemIgnore = ent; allowPickup = false; - if (!m_defendHostage && m_difficulty > 2 && rng.getInt (0, 100) < 30 && m_timeCamping + 15.0f < engine.timebase ()) { + if (!m_defendHostage && m_difficulty > 2 && rng.chance (30) && m_timeCamping + 15.0f < engine.timebase ()) { int index = getDefendPoint (origin); startTask (TASK_CAMP, TASKPRI_CAMP, INVALID_WAYPOINT_INDEX, engine.timebase () + rng.getFloat (30.0f, 60.0f), true); // push camp task on to stack @@ -732,7 +732,7 @@ void Bot::processPickups (void) { else { m_campButtons &= ~IN_DUCK; } - if (rng.getInt (0, 100) < 90) { + if (rng.chance (90)) { pushChatterMessage (CHATTER_DEFENDING_BOMBSITE); } } @@ -770,7 +770,7 @@ void Bot::processPickups (void) { return; } - if (rng.getInt (0, 100) < 70) { + if (rng.chance (70)) { pushChatterMessage (CHATTER_FOUND_BOMB_PLACE); } @@ -797,7 +797,7 @@ void Bot::processPickups (void) { m_campButtons &= ~IN_DUCK; } - if (rng.getInt (0, 100) < 90) { + if (rng.chance (85)) { pushChatterMessage (CHATTER_DEFENDING_BOMBSITE); } } @@ -806,7 +806,7 @@ void Bot::processPickups (void) { m_itemIgnore = ent; allowPickup = false; - if (!m_defendedBomb && m_difficulty > 2 && rng.getInt (0, 100) < 75 && pev->health < 80) { + if (!m_defendedBomb && m_difficulty > 2 && rng.chance (75) && pev->health < 80) { int index = getDefendPoint (origin); startTask (TASK_CAMP, TASKPRI_CAMP, INVALID_WAYPOINT_INDEX, engine.timebase () + rng.getFloat (30.0f, 70.0f), true); // push camp task on to stack @@ -1136,7 +1136,7 @@ void Bot::checkMsgQueue (void) { if (m_radioSelect == RADIO_REPORTING_IN) { switch (taskId ()) { case TASK_NORMAL: - if (task ()->data != INVALID_WAYPOINT_INDEX && rng.getInt (0, 100) < 70) { + if (task ()->data != INVALID_WAYPOINT_INDEX && rng.chance (70)) { Path &path = waypoints[task ()->data]; if (path.flags & FLAG_GOAL) { @@ -1150,26 +1150,26 @@ void Bot::checkMsgQueue (void) { else if (path.flags & FLAG_RESCUE) { instantChatter (CHATTER_RESCUING_HOSTAGES); } - else if ((path.flags & FLAG_CAMP) && rng.getInt (0, 100) > 15) { + else if ((path.flags & FLAG_CAMP) && rng.chance (75)) { instantChatter (CHATTER_GOING_TO_CAMP); } else { instantChatter (CHATTER_HEARD_NOISE); } } - else if (rng.getInt (0, 100) < 30) { + else if (rng.chance (30)) { instantChatter (CHATTER_REPORTING_IN); } break; case TASK_MOVETOPOSITION: - if (rng.getInt (0, 100) < 20) { + if (rng.chance (2)) { instantChatter (CHATTER_GOING_TO_CAMP); } break; case TASK_CAMP: - if (rng.getInt (0, 100) < 40) { + if (rng.chance (40)) { if (g_bombPlanted && m_team == TEAM_TERRORIST) { instantChatter (CHATTER_GUARDING_DROPPED_BOMB); } @@ -1200,7 +1200,7 @@ void Bot::checkMsgQueue (void) { break; default: - if (rng.getInt (0, 100) < 50) { + if (rng.chance (50)) { instantChatter (CHATTER_NOTHING); } break; @@ -1388,7 +1388,7 @@ int Bot::pickBestWeapon (int *vec, int count, int moneySave) { auto weapon = &g_weaponSelect[vec[i]]; // if wea have enough money for weapon buy it - if (weapon->price + moneySave < m_moneyAmount + rng.getInt (50, 200) && rng.getInt (0, 100) < chance) { + if (weapon->price + moneySave < m_moneyAmount + rng.getInt (50, 200) && rng.chance (chance)) { return vec[i]; } } @@ -1682,19 +1682,19 @@ void Bot::buyStuff (void) { break; case BUYSTATE_GRENADES: // if bot has still some money, choose if bot should buy a grenade or not - if (rng.getInt (1, 100) < g_grenadeBuyPrecent[0] && m_moneyAmount >= 400 && !isWeaponRestricted (WEAPON_EXPLOSIVE)) { + if (rng.chance (g_grenadeBuyPrecent[0]) && m_moneyAmount >= 400 && !isWeaponRestricted (WEAPON_EXPLOSIVE)) { // buy a he grenade engine.execBotCmd (ent (), "buyequip"); engine.execBotCmd (ent (), "menuselect 4"); } - if (rng.getInt (1, 100) < g_grenadeBuyPrecent[1] && m_moneyAmount >= 300 && teamEcoValid && !isWeaponRestricted (WEAPON_FLASHBANG)) { + if (rng.chance (g_grenadeBuyPrecent[1]) && m_moneyAmount >= 300 && teamEcoValid && !isWeaponRestricted (WEAPON_FLASHBANG)) { // buy a concussion grenade, i.e., 'flashbang' engine.execBotCmd (ent (), "buyequip"); engine.execBotCmd (ent (), "menuselect 3"); } - if (rng.getInt (1, 100) < g_grenadeBuyPrecent[2] && m_moneyAmount >= 400 && teamEcoValid && !isWeaponRestricted (WEAPON_SMOKE)) { + if (rng.chance (g_grenadeBuyPrecent[2]) && m_moneyAmount >= 400 && teamEcoValid && !isWeaponRestricted (WEAPON_SMOKE)) { // buy a smoke grenade engine.execBotCmd (ent (), "buyequip"); engine.execBotCmd (ent (), "menuselect 5"); @@ -1702,7 +1702,7 @@ void Bot::buyStuff (void) { break; case BUYSTATE_DEFUSER: // if bot is CT and we're on a bomb map, randomly buy the defuse kit - if ((g_mapFlags & MAP_DE) && m_team == TEAM_COUNTER && rng.getInt (1, 100) < 80 && m_moneyAmount > 200 && !isWeaponRestricted (WEAPON_DEFUSER)) { + if ((g_mapFlags & MAP_DE) && m_team == TEAM_COUNTER && rng.chance (80) && m_moneyAmount > 200 && !isWeaponRestricted (WEAPON_DEFUSER)) { if (isOldGame) { engine.execBotCmd (ent (), "buyequip;menuselect 6"); } @@ -1713,7 +1713,7 @@ void Bot::buyStuff (void) { break; case BUYSTATE_NIGHTVISION: - if (m_moneyAmount > 2500 && !m_hasNVG && rng.getInt (1, 100) < 30) { + if (m_moneyAmount > 2500 && !m_hasNVG && rng.chance (30)) { float skyColor = illum.getSkyColor (); float lightLevel = waypoints.getLightLevel (m_currentWaypointIndex); @@ -1860,21 +1860,21 @@ void Bot::setConditions (void) { m_agressionLevel = 1.0f; } - if (rng.getInt (1, 100) < 10) { + if (rng.chance (10)) { pushChatMessage (CHAT_KILLING); } - if (rng.getInt (1, 100) < 10) { + if (rng.chance (10)) { pushRadioMessage (RADIO_ENEMY_DOWN); } - else if (rng.getInt (1, 100) < 60) { + else if (rng.chance (60)) { if ((m_lastVictim->v.weapons & (1 << WEAPON_AWP)) || (m_lastVictim->v.weapons & (1 << WEAPON_SCOUT)) || (m_lastVictim->v.weapons & (1 << WEAPON_G3SG1)) || (m_lastVictim->v.weapons & (1 << WEAPON_SG550))) { pushChatterMessage (CHATTER_SNIPER_KILLED); } else { switch (numEnemiesNear (pev->origin, 99999.0f)) { case 0: - if (rng.getInt (0, 100) < 50) { + if (rng.chance (50)) { pushChatterMessage (CHATTER_NO_ENEMIES_LEFT); } else { @@ -1947,7 +1947,7 @@ void Bot::setConditions (void) { } // check for grenades depending on difficulty - if (rng.getInt (0, 100) < cr::max (25, m_difficulty * 25)) { + if (rng.chance (cr::max (25, m_difficulty * 25))) { checkGrenadesThrow (); } @@ -2175,7 +2175,7 @@ void Bot::startTask (TaskID id, float desire, int data, float time, bool resume) } // this is best place to handle some voice commands report team some info - if (rng.getInt (0, 100) < 95) { + if (rng.chance (90)) { if (tid == TASK_BLINDED) { instantChatter (CHATTER_BLINDED); } @@ -2184,7 +2184,7 @@ void Bot::startTask (TaskID id, float desire, int data, float time, bool resume) } } - if (rng.getInt (0, 100) < 80 && tid == TASK_CAMP) { + if (rng.chance (80) && tid == TASK_CAMP) { if ((g_mapFlags & MAP_DE) && g_bombPlanted) { pushChatterMessage (CHATTER_GUARDING_DROPPED_BOMB); } @@ -2200,7 +2200,7 @@ void Bot::startTask (TaskID id, float desire, int data, float time, bool resume) m_chosenGoalIndex = task ()->data; } - if (rng.getInt (0, 100) < 80 && tid == TASK_CAMP && m_team == TEAM_TERRORIST && m_inVIPZone) { + if (rng.chance (75) && tid == TASK_CAMP && m_team == TEAM_TERRORIST && m_inVIPZone) { pushChatterMessage (CHATTER_GOING_TO_GUARD_VIP_SAFETY); } } @@ -2331,7 +2331,7 @@ void Bot::checkRadioQueue (void) { case CHATTER_COVER_ME: // check if line of sight to object is not blocked (i.e. visible) if ((seesEntity (m_radioEntity->v.origin)) || (m_radioOrder == RADIO_STICK_TOGETHER_TEAM)) { - if (engine.isNullEntity (m_targetEntity) && engine.isNullEntity (m_enemy) && rng.getInt (0, 100) < (m_personality == PERSONALITY_CAREFUL ? 80 : 20)) { + if (engine.isNullEntity (m_targetEntity) && engine.isNullEntity (m_enemy) && rng.chance (m_personality == PERSONALITY_CAREFUL ? 80 : 20)) { int numFollowers = 0; // Check if no more followers are allowed @@ -2378,11 +2378,11 @@ void Bot::checkRadioQueue (void) { } } } - else if (m_radioOrder != CHATTER_GOING_TO_PLANT_BOMB && rng.getInt (0, 100) < 15) { + else if (m_radioOrder != CHATTER_GOING_TO_PLANT_BOMB && rng.chance (15)) { pushRadioMessage (RADIO_NEGATIVE); } } - else if (m_radioOrder != CHATTER_GOING_TO_PLANT_BOMB && rng.getInt (0, 100) < 25) { + else if (m_radioOrder != CHATTER_GOING_TO_PLANT_BOMB && rng.chance (25)) { pushRadioMessage (RADIO_NEGATIVE); } } @@ -2415,7 +2415,7 @@ void Bot::checkRadioQueue (void) { m_fearLevel = 0.0f; } - if (rng.getInt (0, 100) < 45 && yb_communication_type.integer () == 2) { + if (rng.chance (45) && yb_communication_type.integer () == 2) { pushChatterMessage (CHATTER_ON_MY_WAY); } else if (m_radioOrder == RADIO_NEED_BACKUP && yb_communication_type.integer () != 2) { @@ -2423,7 +2423,7 @@ void Bot::checkRadioQueue (void) { } tryHeadTowardRadioMessage (); } - else if (rng.getInt (0, 100) < 25) { + else if (rng.chance (25)) { pushRadioMessage (RADIO_NEGATIVE); } } @@ -2439,29 +2439,29 @@ void Bot::checkRadioQueue (void) { case RADIO_NEED_BACKUP: case CHATTER_SCARED_EMOTE: case CHATTER_PINNED_DOWN: - if (((engine.isNullEntity (m_enemy) && seesEntity (m_radioEntity->v.origin)) || distance < 2048.0f || !m_moveToC4) && rng.getInt (0, 100) > 50 && m_seeEnemyTime + 4.0f < engine.timebase ()) { + if (((engine.isNullEntity (m_enemy) && seesEntity (m_radioEntity->v.origin)) || distance < 2048.0f || !m_moveToC4) && rng.chance (50) && m_seeEnemyTime + 4.0f < engine.timebase ()) { m_fearLevel -= 0.1f; if (m_fearLevel < 0.0f) { m_fearLevel = 0.0f; } - if (rng.getInt (0, 100) < 45 && yb_communication_type.integer () == 2) { + if (rng.chance (45) && yb_communication_type.integer () == 2) { pushChatterMessage (CHATTER_ON_MY_WAY); } - else if (m_radioOrder == RADIO_NEED_BACKUP && yb_communication_type.integer () != 2 && rng.getInt (0, 100) < 50) { + else if (m_radioOrder == RADIO_NEED_BACKUP && yb_communication_type.integer () != 2 && rng.chance (50)) { pushRadioMessage (RADIO_AFFIRMATIVE); } tryHeadTowardRadioMessage (); } - else if (rng.getInt (0, 100) < 30 && m_radioOrder == RADIO_NEED_BACKUP) { + else if (rng.chance (30) && m_radioOrder == RADIO_NEED_BACKUP) { pushRadioMessage (RADIO_NEGATIVE); } break; case RADIO_GO_GO_GO: if (m_radioEntity == m_targetEntity) { - if (rng.getInt (0, 100) < 45 && yb_communication_type.integer () == 2) { + if (rng.chance (45) && yb_communication_type.integer () == 2) { pushRadioMessage (RADIO_AFFIRMATIVE); } else if (m_radioOrder == RADIO_NEED_BACKUP && yb_communication_type.integer () != 2) { @@ -2502,7 +2502,7 @@ void Bot::checkRadioQueue (void) { pushRadioMessage (RADIO_AFFIRMATIVE); resetDoubleJump (); } - else if (rng.getInt (0, 100) < 35) { + else if (rng.chance (35)) { pushRadioMessage (RADIO_NEGATIVE); } break; @@ -2517,7 +2517,7 @@ void Bot::checkRadioQueue (void) { m_targetEntity = nullptr; startTask (TASK_ESCAPEFROMBOMB, TASKPRI_ESCAPEFROMBOMB, INVALID_WAYPOINT_INDEX, 0.0f, true); } - else if (rng.getInt (0, 100) < 35) { + else if (rng.chance (35)) { pushRadioMessage (RADIO_NEGATIVE); } break; @@ -2537,7 +2537,7 @@ void Bot::checkRadioQueue (void) { break; case RADIO_STORM_THE_FRONT: - if (((engine.isNullEntity (m_enemy) && seesEntity (m_radioEntity->v.origin)) || distance < 1024.0f) && rng.getInt (0, 100) > 50) { + if (((engine.isNullEntity (m_enemy) && seesEntity (m_radioEntity->v.origin)) || distance < 1024.0f) && rng.chance (50)) { pushRadioMessage (RADIO_AFFIRMATIVE); // don't pause/camp anymore @@ -2620,7 +2620,7 @@ void Bot::checkRadioQueue (void) { break; case RADIO_REPORT_TEAM: - if (rng.getInt (0, 100) < 30) { + if (rng.chance (30)) { pushRadioMessage ((numEnemiesNear (pev->origin, 400.0f) == 0 && yb_communication_type.integer () != 2) ? RADIO_SECTOR_CLEAR : RADIO_REPORTING_IN); } break; @@ -2729,7 +2729,7 @@ void Bot::tryHeadTowardRadioMessage (void) { if (taskID == TASK_MOVETOPOSITION || m_headedTime + 15.0f < engine.timebase () || !isAlive (m_radioEntity) || m_hasC4) return; - if ((isFakeClient (m_radioEntity) && rng.getInt (0, 100) < 25 && m_personality == PERSONALITY_NORMAL) || !(m_radioEntity->v.flags & FL_FAKECLIENT)) { + if ((isFakeClient (m_radioEntity) && rng.chance (25) && m_personality == PERSONALITY_NORMAL) || !(m_radioEntity->v.flags & FL_FAKECLIENT)) { if (taskID == TASK_PAUSE || taskID == TASK_CAMP) { task ()->time = engine.timebase (); } @@ -3005,7 +3005,7 @@ void Bot::frame (void) { // bot chatting turned on? if (!m_notKilled && yb_chat.boolean () && m_lastChatTime + 10.0 < engine.timebase () && g_lastChatTime + 5.0f < engine.timebase () && !isReplyingToChat ()) { // say a text every now and then - if (rng.getInt (1, 1500) < 50) { + if (rng.chance (50)) { m_lastChatTime = engine.timebase (); g_lastChatTime = engine.timebase (); @@ -3073,7 +3073,7 @@ void Bot::normal_ (void) { // bots rushing with knife, when have no enemy (thanks for idea to nicebot project) if (m_currentWeapon == WEAPON_KNIFE && (engine.isNullEntity (m_lastEnemy) || !isAlive (m_lastEnemy)) && engine.isNullEntity (m_enemy) && m_knifeAttackTime < engine.timebase () && !hasShield () && numFriendsNear (pev->origin, 96.0f) == 0) { - if (rng.getInt (0, 100) < 40) { + if (rng.chance (40)) { pev->button |= IN_ATTACK; } else { @@ -3096,7 +3096,7 @@ void Bot::normal_ (void) { if (processNavigation ()) { // if we're reached the goal, and there is not enemies, notify the team - if (!g_bombPlanted && m_currentWaypointIndex != INVALID_WAYPOINT_INDEX && (m_currentPath->flags & FLAG_GOAL) && rng.getInt (0, 100) < 15 && numEnemiesNear (pev->origin, 650.0f) == 0) { + if (!g_bombPlanted && m_currentWaypointIndex != INVALID_WAYPOINT_INDEX && (m_currentPath->flags & FLAG_GOAL) && rng.chance (15) && numEnemiesNear (pev->origin, 650.0f) == 0) { pushRadioMessage (RADIO_SECTOR_CLEAR); } @@ -3104,7 +3104,7 @@ void Bot::normal_ (void) { m_prevGoalIndex = INVALID_WAYPOINT_INDEX; // spray logo sometimes if allowed to do so - if (m_timeLogoSpray < engine.timebase () && yb_spraypaints.boolean () && rng.getInt (1, 100) < 60 && m_moveSpeed > getShiftSpeed () && engine.isNullEntity (m_pickupItem)) { + if (m_timeLogoSpray < engine.timebase () && yb_spraypaints.boolean () && rng.chance (60) && m_moveSpeed > getShiftSpeed () && engine.isNullEntity (m_pickupItem)) { if (!((g_mapFlags & MAP_DE) && g_bombPlanted && m_team == TEAM_COUNTER)) { startTask (TASK_SPRAY, TASKPRI_SPRAYLOGO, INVALID_WAYPOINT_INDEX, engine.timebase () + 1.0f, false); } @@ -3162,7 +3162,7 @@ void Bot::normal_ (void) { m_campDirection = 0; // tell the world we're camping - if (rng.getInt (0, 100) < 40) { + if (rng.chance (40)) { pushRadioMessage (RADIO_IN_POSITION); } m_moveToGoal = false; @@ -3183,7 +3183,7 @@ void Bot::normal_ (void) { m_hostages.clear (); } } - else if (m_team == TEAM_TERRORIST && rng.getInt (0, 100) < 75) { + else if (m_team == TEAM_TERRORIST && rng.chance (75)) { int index = getDefendPoint (m_currentPath->origin); startTask (TASK_CAMP, TASKPRI_CAMP, INVALID_WAYPOINT_INDEX, engine.timebase () + rng.getFloat (60.0f, 120.0f), true); // push camp task on to stack @@ -3275,7 +3275,7 @@ void Bot::normal_ (void) { } // bot hasn't seen anything in a long time and is asking his teammates to report in - if (yb_communication_type.integer () > 1 && m_seeEnemyTime + rng.getFloat (45.0f, 80.0f) < engine.timebase () && g_lastRadio[m_team] != RADIO_REPORT_TEAM && rng.getInt (0, 100) < 30 && g_timeRoundStart + 20.0f < engine.timebase () && m_askCheckTime < engine.timebase () && numFriendsNear (pev->origin, 1024.0f) == 0) { + if (yb_communication_type.integer () > 1 && m_seeEnemyTime + rng.getFloat (45.0f, 80.0f) < engine.timebase () && g_lastRadio[m_team] != RADIO_REPORT_TEAM && rng.chance (30) && g_timeRoundStart + 20.0f < engine.timebase () && m_askCheckTime < engine.timebase () && numFriendsNear (pev->origin, 1024.0f) == 0) { pushRadioMessage (RADIO_REPORT_TEAM); m_askCheckTime = engine.timebase () + rng.getFloat (45.0f, 80.0f); @@ -3852,7 +3852,7 @@ void Bot::bombDefuse_ (void) { defuseError = true; g_bombPlanted = false; - if (rng.getInt (0, 100) < 50 && m_numFriendsLeft != 0) { + if (m_numFriendsLeft != 0 && rng.chance (50)) { if (timeToBlowUp <= 3.0) { if (yb_communication_type.integer () == 2) { instantChatter (CHATTER_BARELY_DEFUSED); @@ -4583,7 +4583,7 @@ void Bot::pickupItem_ () { // use game dll function to make sure the hostage is correctly 'used' MDLL_Use (m_pickupItem, ent ()); - if (rng.getInt (0, 100) < 80) { + if (rng.chance (80)) { pushChatterMessage (CHATTER_USING_HOSTAGES); } m_hostages.push (m_pickupItem); @@ -4754,7 +4754,7 @@ void Bot::checkSpawnConditions (void) { startTask (TASK_SPRAY, TASKPRI_SPRAYLOGO, INVALID_WAYPOINT_INDEX, engine.timebase () + 1.0f, false); } - if (m_difficulty >= 2 && rng.getInt (0, 100) < (m_personality == PERSONALITY_RUSHER ? 99 : 50) && !m_isReloading && (g_mapFlags & (MAP_CS | MAP_DE | MAP_ES | MAP_AS))) { + if (m_difficulty >= 2 && rng.chance (m_personality == PERSONALITY_RUSHER ? 99 : 50) && !m_isReloading && (g_mapFlags & (MAP_CS | MAP_DE | MAP_ES | MAP_AS))) { if (yb_jasonmode.boolean ()) { selectSecondary (); engine.execBotCmd (ent (), "drop"); @@ -4765,7 +4765,7 @@ void Bot::checkSpawnConditions (void) { } m_checkKnifeSwitch = false; - if (rng.getInt (0, 100) < yb_user_follow_percent.integer () && engine.isNullEntity (m_targetEntity) && !m_isLeader && !m_hasC4 && rng.getInt (0, 100) > 50) { + if (rng.chance (yb_user_follow_percent.integer ()) && engine.isNullEntity (m_targetEntity) && !m_isLeader && !m_hasC4 && rng.chance (50)) { decideFollowUser (); } } @@ -4784,7 +4784,7 @@ void Bot::checkSpawnConditions (void) { case WEAPON_FAMAS: case WEAPON_GLOCK: - if (rng.getInt (0, 100) < 50) { + if (rng.chance (50)) { pev->button |= IN_ATTACK2; } break; @@ -4845,16 +4845,16 @@ void Bot::ai (void) { if ((m_states & STATE_SEEING_ENEMY) && !engine.isNullEntity (m_enemy)) { int hasFriendNearby = numFriendsNear (pev->origin, 512.0f); - if (!hasFriendNearby && rng.getInt (0, 100) < 45 && (m_enemy->v.weapons & (1 << WEAPON_C4))) { + if (!hasFriendNearby && rng.chance (45) && (m_enemy->v.weapons & (1 << WEAPON_C4))) { pushChatterMessage (CHATTER_SPOT_THE_BOMBER); } - else if (!hasFriendNearby && rng.getInt (0, 100) < 45 && m_team == TEAM_TERRORIST && isPlayerVIP (m_enemy)) { + else if (!hasFriendNearby && rng.chance (45) && m_team == TEAM_TERRORIST && isPlayerVIP (m_enemy)) { pushChatterMessage (CHATTER_VIP_SPOTTED); } - else if (!hasFriendNearby && rng.getInt (0, 100) < 50 && engine.getTeam (m_enemy) != m_team && isGroupOfEnemies (m_enemy->v.origin, 2, 384)) { + else if (!hasFriendNearby && rng.chance (50) && engine.getTeam (m_enemy) != m_team && isGroupOfEnemies (m_enemy->v.origin, 2, 384)) { pushChatterMessage (CHATTER_SCARED_EMOTE); } - else if (!hasFriendNearby && rng.getInt (0, 100) < 40 && ((m_enemy->v.weapons & (1 << WEAPON_AWP)) || (m_enemy->v.weapons & (1 << WEAPON_SCOUT)) || (m_enemy->v.weapons & (1 << WEAPON_G3SG1)) || (m_enemy->v.weapons & (1 << WEAPON_SG550)))) { + else if (!hasFriendNearby && rng.chance (40) && ((m_enemy->v.weapons & (1 << WEAPON_AWP)) || (m_enemy->v.weapons & (1 << WEAPON_SCOUT)) || (m_enemy->v.weapons & (1 << WEAPON_G3SG1)) || (m_enemy->v.weapons & (1 << WEAPON_SG550)))) { pushChatterMessage (CHATTER_SNIPER_WARNING); } @@ -5260,7 +5260,7 @@ void Bot::processBlind (int alpha) { m_blindMoveSpeed = -pev->maxspeed; m_blindSidemoveSpeed = 0.0f; - if (rng.getInt (0, 100) > 50) { + if (rng.chance (50)) { m_blindSidemoveSpeed = pev->maxspeed; } else { @@ -5729,7 +5729,7 @@ void Bot::checkSilencer (void) { int prob = (m_personality == PERSONALITY_RUSHER ? 35 : 65); // aggressive bots don't like the silencer - if (rng.getInt (1, 100) < (m_currentWeapon == WEAPON_USP ? prob / 2 : prob)) { + if (rng.chance (m_currentWeapon == WEAPON_USP ? prob / 2 : prob)) { // is the silencer not attached... if (pev->weaponanim > 6) { pev->button |= IN_ATTACK2; // attach the silencer @@ -5844,7 +5844,7 @@ void Bot::processHearing (void) { m_heardSoundTime = engine.timebase (); m_states |= STATE_HEARING_ENEMY; - if (rng.getInt (0, 100) < 15 && engine.isNullEntity (m_enemy) && engine.isNullEntity (m_lastEnemy) && m_seeEnemyTime + 7.0f < engine.timebase ()) { + if (rng.chance (15) && engine.isNullEntity (m_enemy) && engine.isNullEntity (m_lastEnemy) && m_seeEnemyTime + 7.0f < engine.timebase ()) { pushChatterMessage (CHATTER_HEARD_ENEMY); } @@ -5934,9 +5934,9 @@ void Bot::processBuyzoneEntering (int buyState) { bool Bot::isBombDefusing (const Vector &bombOrigin) { // this function finds if somebody currently defusing the bomb. - if (!g_bombPlanted) + if (!g_bombPlanted) { return false; - + } bool defusingInProgress = false; for (int i = 0; i < engine.maxClients (); i++) { diff --git a/source/chatlib.cpp b/source/chatlib.cpp index d4d6f45..d3ec46b 100644 --- a/source/chatlib.cpp +++ b/source/chatlib.cpp @@ -91,7 +91,7 @@ char *humanizeName (char *name) { strncpy (outputName, name, cr::bufsize (outputName)); // copy name to new buffer // drop tag marks, 80 percent of time - if (rng.getInt (1, 100) < 80) { + if (rng.chance (80)) { stripClanTags (outputName); } else { @@ -100,7 +100,7 @@ char *humanizeName (char *name) { // sometimes switch name to lower characters // note: since we're using russian names written in english, we reduce this shit to 6 percent - if (rng.getInt (1, 100) <= 6) { + if (rng.chance (7)) { for (size_t i = 0; i < strlen (outputName); i++) { outputName[i] = static_cast (tolower (static_cast (outputName[i]))); // to lower case } @@ -116,7 +116,7 @@ void addChatErrors (char *buffer) { // sometimes switch text to lowercase // note: since we're using russian chat written in English, we reduce this shit to 4 percent - if (rng.getInt (1, 100) <= 4) { + if (rng.chance (5)) { for (i = 0; i < length; i++) { buffer[i] = static_cast (tolower (static_cast (buffer[i]))); // switch to lowercase } @@ -289,7 +289,7 @@ void Bot::prepareChatMessage (char *text) { } else if (*pattern == 'd') { if (g_gameFlags & GAME_CZERO) { - if (rng.getInt (1, 100) < 30) { + if (rng.chance (30)) { m_tempStrings += "CZ"; } else { @@ -297,7 +297,7 @@ void Bot::prepareChatMessage (char *text) { } } else if ((g_gameFlags & GAME_CSTRIKE16) || (g_gameFlags & GAME_LEGACY)) { - if (rng.getInt (1, 100) < 30) { + if (rng.chance (30)) { m_tempStrings += "CS"; } else { @@ -367,7 +367,7 @@ bool checkForKeywords (char *message, char *reply) { } // didn't find a keyword? 70% of the time use some universal reply - if (rng.getInt (1, 100) < 70 && !g_chatFactory[CHAT_NOKW].empty ()) { + if (rng.chance (70) && !g_chatFactory[CHAT_NOKW].empty ()) { strcpy (reply, g_chatFactory[CHAT_NOKW].random ().chars ()); return true; } @@ -397,7 +397,7 @@ bool Bot::isReplyingToChat (void) { // check is time to chat is good if (m_sayTextBuffer.timeNextChat < engine.timebase ()) { - if (rng.getInt (1, 100) < m_sayTextBuffer.chatProbability + rng.getInt (15, 35) && processChatKeywords (reinterpret_cast (&text))) { + if (rng.chance (m_sayTextBuffer.chatProbability + rng.getInt (15, 35)) && processChatKeywords (reinterpret_cast (&text))) { prepareChatMessage (text); pushMsgQueue (GAME_MSG_SAY_CMD); diff --git a/source/combat.cpp b/source/combat.cpp index 8337a2e..803514e 100644 --- a/source/combat.cpp +++ b/source/combat.cpp @@ -398,7 +398,7 @@ bool Bot::lookupEnemies (void) { return false; } -Vector Bot::getBodyOffserError (float distance) { +Vector Bot::getBodyOffsetError (float distance) { if (engine.isNullEntity (m_enemy)) { return Vector::null (); } @@ -417,7 +417,7 @@ const Vector &Bot::getEnemyBodyOffset (void) { // the purpose of this function, is to make bot aiming not so ideal. it's mutate m_enemyOrigin enemy vector // returned from visibility check function. - auto headOffset = [] (edict_t *e) { + const auto headOffset = [] (edict_t *e) { return e->v.absmin.z + e->v.size.z * 0.81f; }; @@ -449,7 +449,7 @@ const Vector &Bot::getEnemyBodyOffset (void) { // if we only suspect an enemy behind a wall take the worst skill if (!m_visibility && (m_states & STATE_SUSPECT_ENEMY)) { - aimPos += getBodyOffserError (distance); + aimPos += getBodyOffsetError (distance); } else { // now take in account different parts of enemy body @@ -457,7 +457,7 @@ const Vector &Bot::getEnemyBodyOffset (void) { int headshotFreq[5] = { 20, 40, 60, 80, 100 }; // now check is our skill match to aim at head, else aim at enemy body - if ((rng.getInt (1, 100) < headshotFreq[m_difficulty]) || usesPistol ()) { + if (rng.chance (headshotFreq[m_difficulty]) || usesPistol ()) { aimPos.z = headOffset (m_enemy) + getEnemyBodyOffsetCorrection (distance); } else { @@ -480,7 +480,7 @@ const Vector &Bot::getEnemyBodyOffset (void) { // add some error to unskilled bots if (m_difficulty < 3) { - m_enemyOrigin += getBodyOffserError (distance); + m_enemyOrigin += getBodyOffsetError (distance); } return m_enemyOrigin; } @@ -796,7 +796,7 @@ void Bot::selectWeapons (float distance, int index, int id, int choosen) { if (distance < MAX_SPRAY_DISTANCE || m_blindTime > engine.timebase ()) { if (id == WEAPON_KNIFE) { if (distance < 64.0f) { - if (rng.getInt (1, 100) < 30 || hasShield ()) { + if (rng.chance (30) || hasShield ()) { pev->button |= IN_ATTACK; // use primary attack } else { @@ -914,7 +914,7 @@ void Bot::fireWeapons (void) { m_reloadState = RELOAD_PRIMARY; m_reloadCheckTime = engine.timebase (); - if (rng.getInt (0, 100) < cr::abs (m_difficulty * 25 - 100)) { + if (rng.chance (cr::abs (m_difficulty * 25 - 100))) { pushRadioMessage (RADIO_NEED_BACKUP); } } @@ -1080,7 +1080,7 @@ void Bot::attackMovement (void) { } else { if (m_lastFightStyleCheck + 3.0f < engine.timebase ()) { - if (rng.getInt (0, 100) < 50) { + if (rng.chance (50)) { m_fightStyle = FIGHT_STRAFE; } else { @@ -1105,7 +1105,7 @@ void Bot::attackMovement (void) { m_combatStrafeDir = STRAFE_DIR_RIGHT; } - if (rng.getInt (1, 100) < 30) { + if (rng.chance (30)) { m_combatStrafeDir = (m_combatStrafeDir == STRAFE_DIR_LEFT ? STRAFE_DIR_RIGHT : STRAFE_DIR_LEFT); } m_strafeSetTime = engine.timebase () + rng.getFloat (0.5f, 3.0f); diff --git a/source/engine.cpp b/source/engine.cpp index 31c8517..48617f9 100644 --- a/source/engine.cpp +++ b/source/engine.cpp @@ -1070,7 +1070,7 @@ void Engine::processMessages (void *ptr) { notify->clearSearchNodes (); notify->clearTasks (); - if (yb_communication_type.integer () == 2 && rng.getInt (0, 100) < 55 && notify->m_team == TEAM_COUNTER) { + if (yb_communication_type.integer () == 2 && rng.chance (55) && notify->m_team == TEAM_COUNTER) { notify->pushChatterMessage (CHATTER_WHERE_IS_THE_BOMB); } } diff --git a/source/globals.cpp b/source/globals.cpp index 398afb2..874262d 100644 --- a/source/globals.cpp +++ b/source/globals.cpp @@ -40,11 +40,11 @@ int g_highestDamageCT = 1; int g_highestDamageT = 1; int g_highestKills = 1; -Array g_chatFactory; -Array> g_chatterFactory; -Array g_botNames; -Array g_replyFactory; -Library *g_gameLib = nullptr; +Array g_chatFactory; +Array > g_chatterFactory; +Array g_botNames; +Array g_replyFactory; +Library g_gameLib; meta_globals_t *gpMetaGlobals = nullptr; gamedll_funcs_t *gpGamedllFuncs = nullptr; diff --git a/source/interface.cpp b/source/interface.cpp index 5f7ef10..3df78ed 100644 --- a/source/interface.cpp +++ b/source/interface.cpp @@ -2845,7 +2845,7 @@ SHARED_LIBRARAY_EXPORT int GetEntityAPI2 (gamefuncs_t *functionTable, int *) { memset (functionTable, 0, sizeof (gamefuncs_t)); if (!(g_gameFlags & GAME_METAMOD)) { - auto api_GetEntityAPI = g_gameLib->resolve ("GetEntityAPI"); + auto api_GetEntityAPI = g_gameLib.resolve ("GetEntityAPI"); // pass other DLLs engine callbacks to function table... if (api_GetEntityAPI (&g_functionTable, INTERFACE_VERSION) == 0) { @@ -2913,7 +2913,7 @@ SHARED_LIBRARAY_EXPORT int GetNewDLLFunctions (newgamefuncs_t *functionTable, in // pass them too, else the DLL interfacing wouldn't be complete and the game possibly wouldn't // run properly. - auto api_GetNewDLLFunctions = g_gameLib->resolve ("GetNewDLLFunctions"); + auto api_GetNewDLLFunctions = g_gameLib.resolve ("GetNewDLLFunctions"); if (api_GetNewDLLFunctions == nullptr) { return FALSE; @@ -2971,7 +2971,7 @@ SHARED_LIBRARAY_EXPORT int Server_GetBlendingInterface (int version, void **ppin // of the body move, which bones, which hitboxes and how) between the server and the game DLL. // some MODs can be using a different hitbox scheme than the standard one. - auto api_GetBlendingInterface = g_gameLib->resolve ("Server_GetBlendingInterface"); + auto api_GetBlendingInterface = g_gameLib.resolve ("Server_GetBlendingInterface"); if (api_GetBlendingInterface == nullptr) { return FALSE; @@ -3032,11 +3032,11 @@ SHARED_LIBRARAY_EXPORT void Meta_Init (void) { g_gameFlags |= GAME_METAMOD; } -Library *loadCSBinary (void) { +bool loadCSBinary (void) { const char *modname = engine.getModName (); if (!modname) { - return nullptr; + return false; } #if defined(PLATFORM_WIN32) @@ -3047,14 +3047,14 @@ Library *loadCSBinary (void) { const char *libs[] = {"cs.dylib"}; #endif - auto libCheck = [] (Library *lib, const char *modname, const char *dll) { + auto libCheck = [] (const char *modname, const char *dll) { // try to load gamedll - if (!lib->isValid ()) { + if (!g_gameLib.isValid ()) { logEntry (true, LL_FATAL | LL_IGNORE, "Unable to load gamedll \"%s\". Exiting... (gamedir: %s)", dll, modname); return false; } - auto ent = lib->resolve ("trigger_random_unique"); + auto ent = g_gameLib.resolve ("trigger_random_unique"); // detect regamedll by addon entity they provide if (ent != nullptr) { @@ -3077,28 +3077,26 @@ Library *loadCSBinary (void) { g_gameFlags |= (GAME_CZERO | GAME_SUPPORT_BOT_VOICE | GAME_SUPPORT_SVC_PINGS); if (g_gameFlags & GAME_METAMOD) { - return nullptr; + return false; } - auto game = new Library (path); + g_gameLib.load (path); // verify dll is OK - if (!libCheck (game, modname, libs[i])) { - delete game; - return nullptr; + if (!libCheck (modname, libs[i])) { + return false; } - return game; + return true; } else { - auto game = new Library (path); + g_gameLib.load (path); // verify dll is OK - if (!libCheck (game, modname, libs[i])) { - delete game; - return nullptr; + if (!libCheck (modname, libs[i])) { + return false; } // detect if we're running modern game - auto entity = game->resolve ("weapon_famas"); + auto entity = g_gameLib.resolve ("weapon_famas"); // detect xash engine if (g_engfuncs.pfnCVarGetPointer ("build") != nullptr) { @@ -3109,10 +3107,9 @@ Library *loadCSBinary (void) { } if (g_gameFlags & GAME_METAMOD) { - delete game; - return nullptr; + return false; } - return game; + return true; } if (entity != nullptr) { @@ -3123,13 +3120,12 @@ Library *loadCSBinary (void) { } if (g_gameFlags & GAME_METAMOD) { - delete game; - return nullptr; + return false; } - return game; + return true; } } - return nullptr; + return false; } DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t *pGlobals) { @@ -3225,21 +3221,22 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t printDetectedGame (); #else - g_gameLib = loadCSBinary (); { - if (!g_gameLib && !(g_gameFlags & GAME_METAMOD)) { - logEntry (true, LL_FATAL | LL_IGNORE, "Mod that you has started, not supported by this bot (gamedir: %s)", engine.getModName ()); - return; - } - printDetectedGame (); + bool binaryLoaded = loadCSBinary (); - if (g_gameFlags & GAME_METAMOD) { - return; - } + if (!binaryLoaded && !(g_gameFlags & GAME_METAMOD)) { + logEntry (true, LL_FATAL | LL_IGNORE, "Mod that you has started, not supported by this bot (gamedir: %s)", engine.getModName ()); + return; } + printDetectedGame (); + + if (g_gameFlags & GAME_METAMOD) { + return; + } + #endif - auto api_GiveFnptrsToDll = g_gameLib->resolve ("GiveFnptrsToDll"); - + auto api_GiveFnptrsToDll = g_gameLib.resolve ("GiveFnptrsToDll"); + assert (api_GiveFnptrsToDll != nullptr); GetEngineFunctions (functionTable, nullptr); @@ -3255,14 +3252,14 @@ DLL_ENTRYPOINT { // dynamic library detaching ?? if (DLL_DETACHING) { cleanupGarbage (); // free everything that's freeable - delete g_gameLib; // if dynamic link library of mod is load, free it + g_gameLib.unload (); // if dynamic link library of mod is load, free it } DLL_RETENTRY; // the return data type is OS specific too } void helper_LinkEntity (entity_func_t &addr, const char *name, entvars_t *pev) { if (addr == nullptr) { - addr = g_gameLib->resolve (name); + addr = g_gameLib.resolve (name); } if (addr == nullptr) { diff --git a/source/manager.cpp b/source/manager.cpp index a645c8e..be703e5 100644 --- a/source/manager.cpp +++ b/source/manager.cpp @@ -1098,7 +1098,7 @@ void Bot::newRound (void) { switch (m_personality) { case PERSONALITY_NORMAL: - m_pathType = rng.getInt (0, 100) > 50 ? SEARCH_PATH_SAFEST_FASTER : SEARCH_PATH_SAFEST; + m_pathType = rng.chance (50) ? SEARCH_PATH_SAFEST_FASTER : SEARCH_PATH_SAFEST; break; case PERSONALITY_RUSHER: @@ -1274,7 +1274,7 @@ void Bot::newRound (void) { pushMsgQueue (GAME_MSG_PURCHASE); startTask (TASK_NORMAL, TASKPRI_NORMAL, INVALID_WAYPOINT_INDEX, 0.0f, true); - if (rng.getInt (0, 100) < 50) { + if (rng.chance (50)) { pushChatterMessage (CHATTER_NEW_ROUND); } m_thinkInterval = (g_gameFlags & (GAME_LEGACY | GAME_XASH_ENGINE)) ? 0.0f : (1.0f / cr::clamp (yb_think_fps.flt (), 30.0f, 90.0f)) * rng.getFloat (0.95f, 1.05f); @@ -1366,7 +1366,7 @@ void Bot::processTeamJoin (void) { m_notStarted = false; // check for greeting other players, since we connected - if (rng.getInt (0, 100) < 20) { + if (rng.chance (20)) { pushChatMessage (CHAT_WELCOME); } } @@ -1553,7 +1553,7 @@ void BotManager::selectLeaders (int team, bool reset) { // vip bot is the leader bot->m_isLeader = true; - if (rng.getInt (1, 100) < 50) { + if (rng.chance (50)) { bot->pushRadioMessage (RADIO_FOLLOW_ME); bot->m_campButtons = 0; } @@ -1567,7 +1567,7 @@ void BotManager::selectLeaders (int team, bool reset) { if (bot != nullptr && bot->m_notKilled) { bot->m_isLeader = true; - if (rng.getInt (1, 100) < 45) { + if (rng.chance (45)) { bot->pushRadioMessage (RADIO_FOLLOW_ME); } } @@ -1584,7 +1584,7 @@ void BotManager::selectLeaders (int team, bool reset) { bot->m_isLeader = true; // terrorist carrying a bomb needs to have some company - if (rng.getInt (1, 100) < 80) { + if (rng.chance (75)) { if (yb_communication_type.integer () == 2) { bot->pushChatterMessage (CHATTER_GOING_TO_PLANT_BOMB); } @@ -1601,7 +1601,7 @@ void BotManager::selectLeaders (int team, bool reset) { if (auto bot = bots.getHighfragBot (team)) { bot->m_isLeader = true; - if (rng.getInt (1, 100) < 30) { + if (rng.chance (30)) { bot->pushRadioMessage (RADIO_FOLLOW_ME); } } @@ -1614,7 +1614,7 @@ void BotManager::selectLeaders (int team, bool reset) { if (!m_leaderChoosen[team] && bot) { bot->m_isLeader = true; - if (rng.getInt (1, 100) < 30) { + if (rng.chance (30)) { bot->pushRadioMessage (RADIO_FOLLOW_ME); } m_leaderChoosen[team] = true; @@ -1626,7 +1626,7 @@ void BotManager::selectLeaders (int team, bool reset) { if (!m_leaderChoosen[team] && bot) { bot->m_isLeader = true; - if (rng.getInt (1, 100) < (team == TEAM_TERRORIST ? 30 : 40)) { + if (rng.chance (team == TEAM_TERRORIST ? 30 : 40)) { bot->pushRadioMessage (RADIO_FOLLOW_ME); } m_leaderChoosen[team] = true; diff --git a/source/navigate.cpp b/source/navigate.cpp index 27d08a8..1fccf6b 100644 --- a/source/navigate.cpp +++ b/source/navigate.cpp @@ -1052,7 +1052,7 @@ bool Bot::processNavigation (void) { if ((engine.getAbsPos (tr.pHit) - pev->origin).lengthSq () < 2500.0f) { ignoreCollision (); // don't consider being stuck - if (rng.getInt (1, 100) < 50) { + if (rng.chance (50)) { // do not use door directrly under xash, or we will get failed assert in gamedll code if (g_gameFlags & GAME_XASH_ENGINE) { pev->button |= IN_USE; @@ -1189,14 +1189,14 @@ bool Bot::processNavigation (void) { float distance = (bombOrigin - waypoints[taskTarget].origin).length (); if (distance > 512.0f) { - if (rng.getInt (0, 100) < 50 && !waypoints.isVisited (taskTarget)) { + if (rng.chance (50) && !waypoints.isVisited (taskTarget)) { pushRadioMessage (RADIO_SECTOR_CLEAR); } waypoints.setVisited (taskTarget); // doesn't hear so not a good goal } } else { - if (rng.getInt (0, 100) < 50 && !waypoints.isVisited (taskTarget)) { + if (rng.chance (50) && !waypoints.isVisited (taskTarget)) { pushRadioMessage (RADIO_SECTOR_CLEAR); } waypoints.setVisited (taskTarget); // doesn't hear so not a good goal @@ -2301,7 +2301,7 @@ bool Bot::advanceMovement (void) { if (static_cast (kills) == m_baseAgressionLevel) { m_campButtons |= IN_DUCK; } - else if (rng.getInt (1, 100) > m_difficulty * 25) { + else if (rng.chance (m_difficulty * 25)) { m_minSpeed = getShiftSpeed (); } } diff --git a/source/waypoint.cpp b/source/waypoint.cpp index 8df7549..437e033 100644 --- a/source/waypoint.cpp +++ b/source/waypoint.cpp @@ -2840,9 +2840,9 @@ WaypointDownloadError Waypoint::downloadWaypoint (void) { break; case '\n': - if (symbolsInLine == 0) + if (symbolsInLine == 0) { finished = true; - + } symbolsInLine = 0; break;