]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/havocbot/roles.qc
Merge branch 'master' into Lyberta/PrintMove
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / havocbot / roles.qc
index 54129e25d2d5bcf40b9a8ed88cd2d0a28a9c330a..2aa11b52ca45c3df0e2df3e0c807f1be346c1f01 100644 (file)
@@ -2,6 +2,8 @@
 
 #include <server/defs.qh>
 #include <server/miscfunctions.qh>
+#include <server/items.qh>
+#include <server/resources.qh>
 #include "havocbot.qh"
 
 #include "../cvars.qh"
@@ -9,6 +11,8 @@
 #include "../bot.qh"
 #include "../navigation.qh"
 
+.float bot_ratingscale;
+.float bot_ratingscale_time;
 .float max_armorvalue;
 .float havocbot_role_timeout;
 
@@ -48,12 +52,12 @@ bool havocbot_goalrating_item_can_be_left_to_teammate(entity this, entity player
 {
        if (item.health && player.health <= this.health) {return true;}
        if (item.armorvalue && player.armorvalue <= this.armorvalue) {return true;}
-       if (item.weapons && !(player.weapons & item.weapons)) {return true;}
-       if (item.ammo_shells && player.ammo_shells <= this.ammo_shells) {return true;}
-       if (item.ammo_nails && player.ammo_nails <= this.ammo_nails) {return true;}
-       if (item.ammo_rockets && player.ammo_rockets <= this.ammo_rockets) {return true;}
-       if (item.ammo_cells && player.ammo_cells <= this.ammo_cells) {return true;}
-       if (item.ammo_plasma && player.ammo_plasma <= this.ammo_plasma) {return true;}
+       if (STAT(WEAPONS, item) && !(STAT(WEAPONS, player) & STAT(WEAPONS, item))) {return true;}
+       if (item.ammo_shells && GetResourceAmount(player, RESOURCE_SHELLS) <= GetResourceAmount(this, RESOURCE_SHELLS)) {return true;}
+       if (item.ammo_nails && GetResourceAmount(player, RESOURCE_BULLETS) <= GetResourceAmount(this, RESOURCE_BULLETS)) {return true;}
+       if (item.ammo_rockets && GetResourceAmount(player, RESOURCE_ROCKETS) <= GetResourceAmount(this, RESOURCE_ROCKETS)) {return true;}
+       if (item.ammo_cells && GetResourceAmount(player, RESOURCE_CELLS) <= GetResourceAmount(this, RESOURCE_CELLS)) {return true;}
+       if (item.ammo_plasma && GetResourceAmount(player, RESOURCE_PLASMA) <= GetResourceAmount(this, RESOURCE_PLASMA)) {return true;}
        if (item.itemdef.instanceOfPowerup) {return true;}
 
        return false;
@@ -113,6 +117,13 @@ void havocbot_goalrating_items(entity this, float ratingscale, vector org, float
 
        IL_EACH(g_items, it.bot_pickup,
        {
+               // ignore if bot already rated this item with a higher ratingscale
+               // NOTE: this code assumes each bot rates items in a different frame
+               if(it.bot_ratingscale_time == time && ratingscale < it.bot_ratingscale)
+                       continue;
+               it.bot_ratingscale_time = time;
+               it.bot_ratingscale = ratingscale;
+
                if(!it.solid)
                {
                        if(!autocvar_bot_ai_timeitems)
@@ -140,7 +151,7 @@ void havocbot_goalrating_items(entity this, float ratingscale, vector org, float
                        continue;
 
                // Check if the item can be picked up safely
-               if(it.classname == "droppedweapon")
+               if(Item_IsLoot(it))
                {
                        if(!IS_ONGROUND(it))
                                continue;
@@ -163,9 +174,8 @@ void havocbot_goalrating_items(entity this, float ratingscale, vector org, float
 
                if(!havocbot_goalrating_item_pickable_check_players(this, org, it, o))
                        continue;
-               
-               rating = it.bot_pickupevalfunc(this, it);
 
+               rating = it.bot_pickupevalfunc(this, it);
                if(rating > 0)
                        navigation_routerating(this, it, rating * ratingscale, 2000);
        });
@@ -188,6 +198,8 @@ void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org
                // TODO: Merge this logic with the bot_shouldattack function
                if(vdist(it.origin - org, <, 100) || vdist(it.origin - org, >, sradius))
                        continue;
+               if(vdist(vec2(it.velocity), >, autocvar_sv_maxspeed * 2))
+                       continue;
 
                // rate only visible enemies
                /*