bot: done some experiments with think timers
This commit is contained in:
parent
34772be5ca
commit
90dde6690b
4 changed files with 32 additions and 26 deletions
|
|
@ -519,6 +519,7 @@ private:
|
||||||
void findValidNode ();
|
void findValidNode ();
|
||||||
void setPathOrigin ();
|
void setPathOrigin ();
|
||||||
void fireWeapons ();
|
void fireWeapons ();
|
||||||
|
void doFireWeapons ();
|
||||||
void selectWeapons (float distance, int index, int id, int choosen);
|
void selectWeapons (float distance, int index, int id, int choosen);
|
||||||
void focusEnemy ();
|
void focusEnemy ();
|
||||||
void selectBestWeapon ();
|
void selectBestWeapon ();
|
||||||
|
|
@ -727,8 +728,8 @@ public:
|
||||||
Deque <int32_t> m_msgQueue {};
|
Deque <int32_t> m_msgQueue {};
|
||||||
Array <int32_t> m_goalHist {};
|
Array <int32_t> m_goalHist {};
|
||||||
|
|
||||||
FrameDelay m_thinkDelay {};
|
FrameDelay m_thinkTimer {};
|
||||||
FrameDelay m_commandDelay {};
|
FrameDelay m_fullThinkTimer {};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Bot (edict_t *bot, int difficulty, int personality, int team, int skin);
|
Bot (edict_t *bot, int difficulty, int personality, int team, int skin);
|
||||||
|
|
|
||||||
|
|
@ -3007,24 +3007,26 @@ void Bot::checkParachute () {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bot::frame () {
|
void Bot::frame () {
|
||||||
|
if (m_thinkTimer.time < game.time ()) {
|
||||||
|
m_thinkTimer.time = game.time () + m_thinkTimer.interval;
|
||||||
|
|
||||||
|
if (m_aimFlags && AimFlags::Enemy) {
|
||||||
|
focusEnemy ();
|
||||||
|
}
|
||||||
|
doFireWeapons ();
|
||||||
|
updateLookAngles ();
|
||||||
|
|
||||||
pev->flags |= FL_CLIENT | FL_FAKECLIENT; // restore fake client bit, just in case
|
pev->flags |= FL_CLIENT | FL_FAKECLIENT; // restore fake client bit, just in case
|
||||||
|
|
||||||
const auto timestamp = game.time ();
|
if (m_fullThinkTimer.time < game.time ()) {
|
||||||
|
m_fullThinkTimer.time = game.time () + m_fullThinkTimer.interval;
|
||||||
|
|
||||||
if (m_thinkDelay.time <= timestamp) {
|
|
||||||
update ();
|
update ();
|
||||||
|
|
||||||
// delay next execution for thinking
|
|
||||||
m_thinkDelay.time = timestamp + m_thinkDelay.interval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// run bot command on twice speed
|
|
||||||
if (m_commandDelay.time <= timestamp) {
|
|
||||||
runMovement ();
|
runMovement ();
|
||||||
m_commandDelay.time = timestamp + m_commandDelay.interval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_slowFrameTimestamp > timestamp) {
|
if (m_slowFrameTimestamp > game.time ()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3390,11 +3392,7 @@ void Bot::logic () {
|
||||||
executeTasks (); // execute current task
|
executeTasks (); // execute current task
|
||||||
setAimDirection (); // choose aim direction
|
setAimDirection (); // choose aim direction
|
||||||
updateLookAngles (); // and turn to chosen aim direction
|
updateLookAngles (); // and turn to chosen aim direction
|
||||||
|
doFireWeapons (); // do weapon firing
|
||||||
// the bots wants to fire at something?
|
|
||||||
if (m_shootAtDeadTime > game.time () || (m_wantsToFire && !m_isUsingGrenade && m_shootTime <= game.time ())) {
|
|
||||||
fireWeapons (); // if bot didn't fire a bullet try again next frame
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for reloading
|
// check for reloading
|
||||||
if (m_reloadCheckTime <= game.time ()) {
|
if (m_reloadCheckTime <= game.time ()) {
|
||||||
|
|
|
||||||
|
|
@ -1217,6 +1217,14 @@ void Bot::selectWeapons (float distance, int, int id, int choosen) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Bot::doFireWeapons () {
|
||||||
|
// the bots wants to fire at something?
|
||||||
|
|
||||||
|
if (m_shootAtDeadTime > game.time () || (m_wantsToFire && !m_isUsingGrenade && m_shootTime <= game.time ())) {
|
||||||
|
fireWeapons (); // if bot didn't fire a bullet try again next frame
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Bot::fireWeapons () {
|
void Bot::fireWeapons () {
|
||||||
// this function will return true if weapon was fired, false otherwise
|
// this function will return true if weapon was fired, false otherwise
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1732,23 +1732,22 @@ void Bot::newRound () {
|
||||||
pushChatterMessage (Chatter::NewRound);
|
pushChatterMessage (Chatter::NewRound);
|
||||||
}
|
}
|
||||||
auto thinkFps = cr::clamp (cv_think_fps.as <float> (), 30.0f, 90.0f);
|
auto thinkFps = cr::clamp (cv_think_fps.as <float> (), 30.0f, 90.0f);
|
||||||
|
auto thinkInterval = 1.0f / thinkFps;
|
||||||
auto updateInterval = 1.0f / thinkFps;
|
|
||||||
auto commandInterval = 1.0f / 60.0f;
|
|
||||||
|
|
||||||
if (game.is (GameFlags::Xash3D)) {
|
if (game.is (GameFlags::Xash3D)) {
|
||||||
if (thinkFps < 50) {
|
if (thinkFps < 50) {
|
||||||
updateInterval = 1.0f / 50.0f; // xash3d works acceptable at 50fps
|
thinkInterval = 1.0f / 50.0f; // xash3d works acceptable at 50fps
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
auto fullThinkInterval = 1.0f / 10.0f;
|
||||||
|
|
||||||
// legacy games behaves strange, when this enabled, disable for xash3d as well if requested
|
// legacy games behaves strange, when this enabled, disable for xash3d as well if requested
|
||||||
if (bots.isFrameSkipDisabled ()) {
|
if (bots.isFrameSkipDisabled ()) {
|
||||||
updateInterval = 0.0f;
|
thinkInterval = 0.0f;
|
||||||
commandInterval = 0.0f;
|
fullThinkInterval = 0.0f;
|
||||||
}
|
}
|
||||||
m_thinkDelay.interval = updateInterval;
|
m_thinkTimer.interval = thinkInterval;
|
||||||
m_commandDelay.interval = commandInterval;
|
m_fullThinkTimer.interval = fullThinkInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bot::resetPathSearchType () {
|
void Bot::resetPathSearchType () {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue