Skip to content

Commit

Permalink
higher hearing sensitivity right after combat
Browse files Browse the repository at this point in the history
  • Loading branch information
jkivilin committed Dec 3, 2011
1 parent 203a51f commit 6ae69d2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
4 changes: 4 additions & 0 deletions bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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))
{
Expand Down
2 changes: 2 additions & 0 deletions bot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 26 additions & 1 deletion bot_combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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?
Expand Down
1 change: 1 addition & 0 deletions bot_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
3 changes: 3 additions & 0 deletions bot_skill.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6ae69d2

Please sign in to comment.