]> de.git.xonotic.org Git - voretournament/voretournament.git/blobdiff - data/qcsrc/server/bot/havocbot/havocbot.qc
Fix bug with bots not selecting the Grabber gun. This was caused by an improper weapo...
[voretournament/voretournament.git] / data / qcsrc / server / bot / havocbot / havocbot.qc
index 122871914265e35b102f71eaa52bd0f942af3731..95c4e95dac28d0bdf125e0b4ee9bca7ad8b618db 100644 (file)
@@ -14,6 +14,11 @@ void havocbot_ai()
        if(bot_execute_commands())
                return;
 
+       // execute the vore AI for bots
+       Vore_AI();
+       if(self.stat_eaten)
+               return; // an eaten bot has nothing to do outside of the vore AI
+
        if (bot_strategytoken == self)
        if (!bot_strategytoken_taken)
        {
@@ -79,8 +84,6 @@ void havocbot_ai()
        if(self.deadflag != DEAD_NO)
                return;
 
-       Vore_AI();
-
        havocbot_chooseenemy();
        if (self.bot_chooseweapontime < time )
        {
@@ -148,6 +151,31 @@ void havocbot_ai()
                bot_aimdir(v, -1);
        }
        havocbot_movetogoal();
+
+       // if the bot is not attacking, consider reloading weapons
+       if not(self.aistatus & AI_STATUS_ATTACKING)
+       {
+               float i;
+               entity e;
+
+               // we are currently holding a weapon that's not fully loaded, reload it
+               if(skill >= 2) // bots can only reload the held weapon on purpose past this skill
+               if(self.clip_load < self.clip_size)
+                       self.impulse = 20; // "press" the reload button, not sure if this is done right
+
+               // if we're not reloading a weapon, switch to any weapon in our invnetory that's not fully loaded to reload it next
+               // the code above executes next frame, starting the reloading then
+               if(skill >= 5) // bots can only look for unloaded weapons past this skill
+               if(self.clip_load >= 0) // only if we're not reloading a weapon already
+               {
+                       for(i = WEP_FIRST; i <= WEP_LAST; ++i)
+                       {
+                               e = get_weaponinfo(i);
+                               if ((e.spawnflags & WEP_FLAG_RELOADABLE) && self.weapon_load[i] < cvar(strcat("g_balance_", e.netname, "_reload_ammo")))
+                                       self.switchweapon = i;
+                       }
+               }
+       }
 };
 
 void havocbot_keyboard_movement(vector destorg)
@@ -883,6 +911,31 @@ void havocbot_chooseenemy()
        self.havocbot_stickenemy = TRUE;
 };
 
+float havocbot_chooseweapon_checkreload(float new_weapon)
+{
+       // bots under this skill cannot find unloaded weapons to reload idly when not in combat,
+       // so skip this for them, or they'll never get to reload their weapons at all.
+       // this also allows bots under this skill to be more stupid, and reload more often during combat :)
+       if(skill < 5)
+               return FALSE;
+
+       // if this weapon is scheduled for reloading, don't switch to it during combat
+       if (self.weapon_load[new_weapon] < 0)
+       {
+               local float i, other_weapon_available;
+               for(i = WEP_FIRST; i <= WEP_LAST; ++i)
+               {
+                       // if we are out of ammo for all other weapons, it's an emergency to switch to anything else
+                       if (weapon_action(i, WR_CHECKAMMO1) + weapon_action(i, WR_CHECKAMMO2))
+                               other_weapon_available = TRUE;
+               }
+               if(other_weapon_available)
+                       return TRUE;
+       }
+
+       return FALSE;
+}
+
 void havocbot_chooseweapon()
 {
        local float i;
@@ -894,7 +947,7 @@ void havocbot_chooseweapon()
        {
                // If no weapon was chosen get the first available weapon
                if(self.weapon==0)
-               for(i=WEP_GRABBER + 1; i < WEP_COUNT ; ++i)
+               for(i = WEP_FIRST; i <= WEP_COUNT ; ++i)
                {
                        if(client_hasweapon(self, i, TRUE, FALSE))
                        {
@@ -948,7 +1001,7 @@ void havocbot_chooseweapon()
                        for(i=0; i < WEP_COUNT && bot_weapons_far[i] != -1 ; ++i){
                                w = bot_weapons_far[i];
                                if ( client_hasweapon(self, w, TRUE, FALSE) ){
-                                       if ( self.weapon == w && combo)
+                                       if ( self.weapon == w && combo || havocbot_chooseweapon_checkreload(w))
                                                continue;
                                        self.switchweapon = w;
                                        return;
@@ -961,7 +1014,7 @@ void havocbot_chooseweapon()
                        for(i=0; i < WEP_COUNT && bot_weapons_mid[i] != -1 ; ++i){
                                w = bot_weapons_mid[i];
                                if ( client_hasweapon(self, w, TRUE, FALSE) ){
-                                       if ( self.weapon == w && combo)
+                                       if ( self.weapon == w && combo || havocbot_chooseweapon_checkreload(w))
                                                continue;
                                        self.switchweapon = w;
                                        return;
@@ -973,7 +1026,7 @@ void havocbot_chooseweapon()
                for(i=0; i < WEP_COUNT && bot_weapons_close[i] != -1 ; ++i){
                        w = bot_weapons_close[i];
                        if ( client_hasweapon(self, w, TRUE, FALSE) ){
-                               if ( self.weapon == w && combo)
+                               if ( self.weapon == w && combo || havocbot_chooseweapon_checkreload(w))
                                        continue;
                                self.switchweapon = w;
                                return;