From 703394e150e49224c2d8e3f7a733f43cbbf080c7 Mon Sep 17 00:00:00 2001 From: terencehill Date: Fri, 21 Dec 2018 19:17:08 +0100 Subject: [PATCH] Fix #2177 "Bot code causes division by zero" --- qcsrc/server/bot/default/aim.qc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/qcsrc/server/bot/default/aim.qc b/qcsrc/server/bot/default/aim.qc index 7af3fab05..1f570eaf5 100644 --- a/qcsrc/server/bot/default/aim.qc +++ b/qcsrc/server/bot/default/aim.qc @@ -170,14 +170,15 @@ void bot_lagfunc(entity this, float t, float f1, float f2, entity e1, vector v1, this.bot_canfire = 1; } +// this function should be called after bot_aim so the aim is reset the next frame void bot_aim_reset(entity this) { + this.bot_mouseaim = this.v_angle; + this.bot_olddesiredang = this.v_angle; this.bot_aimdir_executed = true; this.bot_badaimtime = 0; this.bot_aimthinktime = time; this.bot_prevaimtime = time; - this.bot_mouseaim = this.v_angle; - this.bot_olddesiredang = this.v_angle; this.bot_1st_order_aimfilter = '0 0 0'; this.bot_2nd_order_aimfilter = '0 0 0'; this.bot_3th_order_aimfilter = '0 0 0'; @@ -198,6 +199,10 @@ void bot_aimdir(entity this, vector v, float maxfiredeviation) this.v_angle_y = this.v_angle.y - floor(this.v_angle.y / 360) * 360; this.v_angle_z = 0; + // make work bot_aim_reset even if called before this function + if (this.bot_prevaimtime == time) + return; + // invalid aim dir (can happen when bot overlaps target) if(!v) return; -- 2.39.2