diff --git a/bot.cpp b/bot.cpp index 282a50d..31eab52 100644 --- a/bot.cpp +++ b/bot.cpp @@ -237,6 +237,8 @@ void BotSpawnInit( bot_t &pBot ) pBot.f_pause_look_time = 0.0; + pBot.f_current_hearing_sensitivity = -1; + memset(&(pBot.current_weapon), 0, sizeof(pBot.current_weapon)); memset(&(pBot.m_rgAmmo), 0, sizeof(pBot.m_rgAmmo)); } @@ -2084,6 +2086,8 @@ void BotThink( bot_t &pBot ) pBot.b_low_health = BotLowHealth(pBot); + BotUpdateHearingSensitivity(pBot); + // does bot need to say a message and time to say a message? if ((pBot.b_bot_say) && (pBot.f_bot_say < gpGlobals->time)) { diff --git a/bot.h b/bot.h index fb0754c..053dd4b 100644 --- a/bot.h +++ b/bot.h @@ -301,6 +301,8 @@ typedef struct float f_reaction_target_time; // time when enemy targeting starts float f_weaponchange_time; + + float f_current_hearing_sensitivity; qboolean b_set_special_shoot_angle; float f_special_shoot_angle; diff --git a/bot_combat.cpp b/bot_combat.cpp index 2b88fc8..b14b4fa 100644 --- a/bot_combat.cpp +++ b/bot_combat.cpp @@ -794,6 +794,31 @@ edict_t *BotFindEnemyNearestToPoint(bot_t &pBot, const Vector &v_point, float ra } +// called on every think frame +void BotUpdateHearingSensitivity(bot_t &pBot) +{ + if (pBot.pBotEnemy != NULL) + { + // have enemy, use best hearing sensitivity for all + pBot.f_current_hearing_sensitivity = skill_settings[BEST_BOT_LEVEL].hearing_sensitivity; + return; + } + + // reduce from best to worst in 3 sec + pBot.f_current_hearing_sensitivity -= (skill_settings[BEST_BOT_LEVEL].hearing_sensitivity - skill_settings[WORST_BOT_LEVEL].hearing_sensitivity) * pBot.f_frame_time / 3; + if (pBot.f_current_hearing_sensitivity < skill_settings[pBot.bot_skill].hearing_sensitivity) + pBot.f_current_hearing_sensitivity = skill_settings[pBot.bot_skill].hearing_sensitivity; +} + +// +float BotGetHearingSensitivity(bot_t &pBot) +{ + if(pBot.f_current_hearing_sensitivity < skill_settings[pBot.bot_skill].hearing_sensitivity) + return skill_settings[pBot.bot_skill].hearing_sensitivity; + return pBot.f_current_hearing_sensitivity; +} + + // edict_t *BotFindVisibleSoundEnemy( bot_t &pBot ) { @@ -820,7 +845,7 @@ edict_t *BotFindVisibleSoundEnemy( bot_t &pBot ) // is sound too far away? (bot cannot hear) float s_distance = (pCurrentSound->m_vecOrigin - pEdict->v.origin).Length(); - if(s_distance > pCurrentSound->m_iVolume * skill_settings[pBot.bot_skill].hearing_sensitivity) + if(s_distance > pCurrentSound->m_iVolume * BotGetHearingSensitivity(pBot)) continue; // more distant than what we got already? diff --git a/bot_func.h b/bot_func.h index 6ccda36..eef59b0 100644 --- a/bot_func.h +++ b/bot_func.h @@ -58,6 +58,7 @@ qboolean BotEdgeLeft( bot_t &pBot, const Vector &v_move_dir ); qboolean BotUpdateTrackSoundGoal( bot_t &pBot ); int BotGetSoundWaypoint( bot_t &pBot, edict_t *pTrackSoundEdict, edict_t ** pNewTrackSoundEdict ); +void BotUpdateHearingSensitivity(bot_t &pBot); void BotRemoveEnemy( bot_t &pBot, qboolean b_keep_tracking ); qboolean BotLowHealth( bot_t &pBot ); diff --git a/bot_skill.h b/bot_skill.h index f7ef9f6..8f696b3 100644 --- a/bot_skill.h +++ b/bot_skill.h @@ -4,6 +4,9 @@ // bot_skill.h // +#define BEST_BOT_LEVEL 0 +#define WORST_BOT_LEVEL 4 + typedef struct { int pause_frequency; // how often (out of 1000 times) the bot will pause, based on bot skill