From 16f4c631d6478a969c9f8f021ed55597e3148061 Mon Sep 17 00:00:00 2001 From: Mircea Kitsune Date: Sat, 12 Feb 2011 00:28:01 +0200 Subject: [PATCH] Improve that last code. When not attacking, a bot will switch to all weapons that are not fully loaded, and attempt to reload them, to keep them ready. --- qcsrc/server/bot/havocbot/havocbot.qc | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/qcsrc/server/bot/havocbot/havocbot.qc b/qcsrc/server/bot/havocbot/havocbot.qc index 17a64f5f4..7d1ef3a08 100644 --- a/qcsrc/server/bot/havocbot/havocbot.qc +++ b/qcsrc/server/bot/havocbot/havocbot.qc @@ -146,11 +146,30 @@ void havocbot_ai() } havocbot_movetogoal(); - // if the bot is not attacking anyone and holding a weapon that's not fully loaded, - // now it's a good time to try reloading it + // if the bot is not attacking, go through all weapons that aren't fully loaded and reload them to keep them ready if not(self.aistatus & AI_STATUS_ATTACKING) - if(self.clip_load < self.clip_size) - self.impulse = 20; + { + float i; + entity e; + + // we are currently holding a weapon that's not fully loaded, reload it + if(self.clip_load < self.clip_size && self.weapon) + { + self.impulse = 20; // "press" the reload button, not sure if this is done right + self.clip_load = -1; + } + + // if we're not reloading a weapon, switch to any weapon in our invnetory that's not fully loaded to reload it next + if(self.clip_load >= 0) + { + for(i = WEP_FIRST; i <= WEP_LAST ; ++i) + { + e = get_weaponinfo(i); + if(self.weapon_load[i] < cvar(strcat("g_balance_", e.netname, "_reload_ammo"))) + self.switchweapon = i; + } + } + } }; void havocbot_keyboard_movement(vector destorg) -- 2.39.2