]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Improve that last code. When not attacking, a bot will switch to all weapons that...
authorMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Fri, 11 Feb 2011 22:28:01 +0000 (00:28 +0200)
committerMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Fri, 11 Feb 2011 22:28:01 +0000 (00:28 +0200)
qcsrc/server/bot/havocbot/havocbot.qc

index 17a64f5f42fae0fb54a035111679052ed47f7a3a..7d1ef3a08f4bd82a7071045ddbf54c5c0f8f39f9 100644 (file)
@@ -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)