]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/scripting.qc
Purge hardcoded slot 0 weapon entity use from most of the bot AI
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / scripting.qc
index e111b2ab4f043f5174b270b5090f6190a3dfb5c1..6b3ab1e4b05d2de7a41bbdbbc54244356c4f7318 100644 (file)
@@ -230,17 +230,10 @@ void bot_commands_init()
 // Returns first bot with matching name
 entity find_bot_by_name(string name)
 {
-       entity bot;
-
-       bot = findchainflags(flags, FL_CLIENT);
-       while (bot)
+       FOREACH_CLIENT(IS_BOT_CLIENT(it) && it.netname == name,
        {
-               if(IS_BOT_CLIENT(bot))
-               if(bot.netname==name)
-                       return bot;
-
-               bot = bot.chain;
-       }
+               return it;
+       });
 
        return NULL;
 }
@@ -575,8 +568,10 @@ float bot_cmd_select_weapon(entity this)
        if(id < WEP_FIRST || id > WEP_LAST)
                return CMD_STATUS_ERROR;
 
-       if(client_hasweapon(this, Weapons_from(id), true, false))
-               PS(this).m_switchweapon = Weapons_from(id);
+       .entity weaponentity = weaponentities[0]; // TODO: unhardcode
+
+       if(client_hasweapon(this, Weapons_from(id), weaponentity, true, false))
+               this.(weaponentity).m_switchweapon = Weapons_from(id);
        else
                return CMD_STATUS_ERROR;
 
@@ -594,16 +589,12 @@ const int CMD_CONDITION_false_BLOCK = 8;
 float bot_cmd_eval(entity this, string expr)
 {
        // Search for numbers
-       if(strstrofs("0123456789", substring(expr, 0, 1), 0) >= 0)
-       {
+       if(IS_DIGIT(substring(expr, 0, 1)))
                return stof(expr);
-       }
 
        // Search for cvars
        if(substring(expr, 0, 5)=="cvar.")
-       {
                return cvar(substring(expr, 5, strlen(expr)));
-       }
 
        // Search for fields
        switch(expr)
@@ -1065,7 +1056,7 @@ float bot_cmd_debug_assert_canfire(entity this)
                if(f)
                {
                        this.colormod = '0 8 8';
-                       LOG_INFO("Bot ", this.netname, " using ", this.weaponname, " wants to fire, inhibited by weaponentity state\n");
+                       LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " wants to fire, inhibited by weaponentity state\n");
                }
        }
        else if(ATTACK_FINISHED(this, slot) > time)
@@ -1073,15 +1064,15 @@ float bot_cmd_debug_assert_canfire(entity this)
                if(f)
                {
                        this.colormod = '8 0 8';
-                       LOG_INFO("Bot ", this.netname, " using ", this.weaponname, " wants to fire, inhibited by ATTACK_FINISHED (", ftos(ATTACK_FINISHED(this, slot) - time), " seconds left)\n");
+                       LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " wants to fire, inhibited by ATTACK_FINISHED (", ftos(ATTACK_FINISHED(this, slot) - time), " seconds left)\n");
                }
        }
-       else if(this.tuba_note)
+       else if(this.(weaponentity).tuba_note)
        {
                if(f)
                {
                        this.colormod = '8 0 0';
-                       LOG_INFO("Bot ", this.netname, " using ", this.weaponname, " wants to fire, bot still has an active tuba note\n");
+                       LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " wants to fire, bot still has an active tuba note\n");
                }
        }
        else
@@ -1089,7 +1080,7 @@ float bot_cmd_debug_assert_canfire(entity this)
                if(!f)
                {
                        this.colormod = '8 8 0';
-                       LOG_INFO("Bot ", this.netname, " using ", this.weaponname, " thinks it has fired, but apparently did not; ATTACK_FINISHED says ", ftos(ATTACK_FINISHED(this, slot) - time), " seconds left\n");
+                       LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " thinks it has fired, but apparently did not; ATTACK_FINISHED says ", ftos(ATTACK_FINISHED(this, slot) - time), " seconds left\n");
                }
        }