]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/t_items.qc
Preliminary support for triggering items (default action is to give the item to the...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / t_items.qc
index 4f6cf459ebc203d20ded5c825e3760b6152d254f..cacc1e4f511e87ba71f3e91dd83889c0194866af 100644 (file)
@@ -393,7 +393,7 @@ bool have_pickup_item(entity this)
                if(autocvar_g_pickup_items == 0)
                        return false;
                if(g_weaponarena)
-                       if(this.weapons || (this.items & IT_AMMO)) // no item or ammo pickups in weaponarena
+                       if(this.weapons || this.itemdef.instanceOfAmmo) // no item or ammo pickups in weaponarena
                                return false;
        }
        return true;
@@ -924,17 +924,20 @@ float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickup
 float weapon_pickupevalfunc(entity player, entity item)
 {
        float c;
+       int rating = item.bot_pickupbasevalue;
 
        // See if I have it already
-       if(!(item.weapons & ~player.weapons))
+       if(player.weapons & item.weapons)
        {
                // If I can pick it up
                if(!item.spawnshieldtime)
                        c = 0;
                else if(player.ammo_cells || player.ammo_shells || player.ammo_plasma || player.ammo_nails || player.ammo_rockets)
                {
+                       if (rating > 0)
+                               rating = BOT_PICKUP_RATING_LOW * 0.5 * (1 + rating / BOT_PICKUP_RATING_HIGH);
                        // Skilled bots will grab more
-                       c = bound(0, skill / 10, 1) * 0.5;
+                       c = 1 + bound(0, skill / 10, 1) * 0.5;
                }
                else
                        c = 0;
@@ -942,8 +945,11 @@ float weapon_pickupevalfunc(entity player, entity item)
        else
                c = 1;
 
+       if (c <= 0)
+               return 0;
+
        // If custom weapon priorities for bots is enabled rate most wanted weapons higher
-       if( bot_custom_weapon && c )
+       if(bot_custom_weapon)
        {
                int best_ratio = 0;
                int missing = 0;
@@ -982,35 +988,31 @@ float weapon_pickupevalfunc(entity player, entity item)
                }
 
                if (missing < 3 && best_ratio)
-                       return (BOT_PICKUP_RATING_HIGH - ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * best_ratio )) * c;
+                       c = c - best_ratio * 0.3;
        }
 
-       return item.bot_pickupbasevalue * c;
+       return rating * c;
 }
 
 float commodity_pickupevalfunc(entity player, entity item)
 {
-       float c;
-       float need_shells = false, need_nails = false, need_rockets = false, need_cells = false, need_plasma = false, need_fuel = false;
-       c = 0;
+       bool need_shells = false, need_nails = false, need_rockets = false, need_cells = false, need_plasma = false, need_fuel = false;
+       float c = 0;
 
        // Detect needed ammo
        FOREACH(Weapons, it != WEP_Null, {
                if(!(player.weapons & (it.m_wepset)))
                        continue;
 
-               if(it.items & ITEM_Shells.m_itemid)
-                       need_shells = true;
-               else if(it.items & ITEM_Bullets.m_itemid)
-                       need_nails = true;
-               else if(it.items & ITEM_Rockets.m_itemid)
-                       need_rockets = true;
-               else if(it.items & ITEM_Cells.m_itemid)
-                       need_cells = true;
-               else if(it.items & ITEM_Plasma.m_itemid)
-                       need_plasma = true;
-               else if(it.items & ITEM_JetpackFuel.m_itemid)
-                       need_fuel = true;
+               switch(it.ammo_field)
+               {
+                       case ammo_shells:  need_shells  = true; break;
+                       case ammo_nails:   need_nails   = true; break;
+                       case ammo_rockets: need_rockets = true; break;
+                       case ammo_cells:   need_cells   = true; break;
+                       case ammo_plasma:  need_plasma  = true; break;
+                       case ammo_fuel:    need_fuel    = true; break;
+               }
        });
 
        // TODO: figure out if the player even has the weapon this ammo is for?
@@ -1056,6 +1058,12 @@ void Item_Damage(entity this, entity inflictor, entity attacker, float damage, i
                RemoveItem(this);
 }
 
+void item_use(entity this, entity actor, entity trigger)
+{
+       // use the touch function to handle collection
+       gettouch(this)(this, actor);
+}
+
 void _StartItem(entity this, entity def, float defaultrespawntime, float defaultrespawntimejitter)
 {
        string itemname = def.m_name;
@@ -1177,6 +1185,9 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default
                }
                */
 
+               if(this.targetname != "" && (this.spawnflags & 16))
+                       this.use = item_use;
+
                if(autocvar_spawn_debug >= 2)
                {
             // why not flags & fl_item?