+bool havocbot_goalrating_item_can_be_left_to_teammate(entity this, entity player, entity item)
+{
+ if (item.health && player.health <= this.health) {return true;}
+ if (item.armorvalue && player.armorvalue <= this.armorvalue) {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;
+};
+
+bool havocbot_goalrating_item_pickable_check_players(entity this, vector org, entity item, vector item_org)
+{
+ if(!teamplay)
+ return true;
+
+ // actually these variables hold the squared distances in order to optimize code
+ float friend_distance = FLOAT_MAX;
+ float enemy_distance = FLOAT_MAX;
+ float dist;
+
+ FOREACH_CLIENT(IS_PLAYER(it) && it != this && !IS_DEAD(it),
+ {
+ if (it.team == this.team)
+ {
+ if (!IS_REAL_CLIENT(it))
+ continue;
+
+ dist = vlen2(it.origin - item_org);
+ if(dist > friend_distance)
+ continue;
+
+ if(havocbot_goalrating_item_can_be_left_to_teammate(this, it, item))
+ {
+ friend_distance = dist;
+ continue;
+ }
+ }
+ else
+ {
+ // If enemy only track distances
+ // TODO: track only if visible ?
+ dist = vlen2(it.origin - item_org);
+ if(dist < enemy_distance)
+ enemy_distance = dist;
+ }
+ });
+
+ // Rate the item only if no one needs it, or if an enemy is closer to it
+ dist = vlen2(item_org - org);
+ if ((enemy_distance < friend_distance && dist < enemy_distance) ||
+ (friend_distance > autocvar_bot_ai_friends_aware_pickup_radius ** 2) ||
+ (dist < friend_distance && dist < 200 ** 2))
+ return true;
+ return false;
+};
+