]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/scripting.qc
Merge branch 'master' into Mario/wepent_experimental
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / scripting.qc
index 6b3ab1e4b05d2de7a41bbdbbc54244356c4f7318..252708a1189f0401c7af68b0ff4ff047759e1950 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <common/state.qh>
 #include <common/physics/player.qh>
+#include <common/wepent.qh>
 
 #include "bot.qh"
 
@@ -568,11 +569,22 @@ float bot_cmd_select_weapon(entity this)
        if(id < WEP_FIRST || id > WEP_LAST)
                return CMD_STATUS_ERROR;
 
-       .entity weaponentity = weaponentities[0]; // TODO: unhardcode
+       bool success = false;
 
-       if(client_hasweapon(this, Weapons_from(id), weaponentity, true, false))
-               this.(weaponentity).m_switchweapon = Weapons_from(id);
-       else
+       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+       {
+               .entity weaponentity = weaponentities[slot];
+               if(this.(weaponentity).m_weapon == WEP_Null && slot != 0)
+                       continue;
+
+               if(client_hasweapon(this, Weapons_from(id), weaponentity, true, false))
+               {
+                       success = true;
+                       this.(weaponentity).m_switchweapon = Weapons_from(id);
+               }
+       }
+
+       if(!success)
                return CMD_STATUS_ERROR;
 
        return CMD_STATUS_FINISHED;
@@ -1108,7 +1120,6 @@ void bot_setcurrentcommand(entity this)
        if(!this.bot_cmd_current)
        {
                this.bot_cmd_current = new_pure(bot_cmd);
-               this.bot_cmd_current.is_bot_cmd = true;
        }
 
        bot_cmd = this.bot_cmd_current;
@@ -1163,16 +1174,17 @@ float bot_execute_commands_once(entity this)
        // Find command
        bot_setcurrentcommand(this);
 
-       // if we have no bot command, better return
-       // old logic kept pressing previously pressed keys, but that has problems
-       // (namely, it means you cannot make a bot "normal" ever again)
-       // to keep a bot walking for a while, use the "wait" bot command
-       if(bot_cmd == NULL)
-               return false;
-
        // Ignore all commands except continue when the bot is paused
-       if(this.bot_exec_status & BOT_EXEC_STATUS_PAUSED)
-       if(bot_cmd.bot_cmd_type!=BOT_CMD_CONTINUE)
+       if(!(self.bot_exec_status & BOT_EXEC_STATUS_PAUSED))
+       {
+               // if we have no bot command, better return
+               // old logic kept pressing previously pressed keys, but that has problems
+               // (namely, it means you cannot make a bot "normal" ever again)
+               // to keep a bot walking for a while, use the "wait" bot command
+               if(bot_cmd == world)
+                       return 0;
+       }
+       else if(bot_cmd.bot_cmd_type != BOT_CMD_CONTINUE)
        {
                if(bot_cmd.bot_cmd_type!=BOT_CMD_NULL)
                {