+void havocbot_goalrating_waypoints(entity this, float ratingscale, vector org, float sradius)
+{
+ // rate waypoints only if there's no alternative goal
+ if(navigation_bestgoal)
+ return;
+
+ float f;
+ float range = 500;
+ sradius = max(range, (0.5 + random() * 0.5) * sradius);
+ while(sradius > 100)
+ {
+ IL_EACH(g_waypoints, vdist(it.origin - org, <, sradius)
+ && vdist(it.origin - org, >, max(100, sradius - range))
+ && !(it.wpflags & WAYPOINTFLAG_TELEPORT),
+ {
+ if(vdist(it.origin - this.wp_goal_prev0.origin, <, range * 1.5))
+ f = 0.1;
+ else if(vdist(it.origin - this.wp_goal_prev1.origin, <, range * 1.5))
+ f = 0.1;
+ else
+ f = 0.5 + random() * 0.5;
+ navigation_routerating(this, it, ratingscale * f, 2000);
+ });
+ if(navigation_bestgoal)
+ break;
+ sradius -= range;
+ }
+};
+
+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 (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;}
+
+ return false;
+};
+
+bool havocbot_goalrating_item_pickable_check_players(entity this, vector org, entity item, vector item_org)
+{
+ if(!teamplay)
+ return true;
+
+ float friend_distance = FLOAT_MAX;
+ float enemy_distance = FLOAT_MAX;
+
+ FOREACH_CLIENT(IS_PLAYER(it) && it != this && !IS_DEAD(it),
+ {
+ if (it.team == this.team)
+ {
+ if (!IS_REAL_CLIENT(it))
+ continue;
+
+ if(vdist(it.origin - item_org, >, friend_distance))
+ continue;
+
+ if(havocbot_goalrating_item_can_be_left_to_teammate(this, it, item))
+ {
+ friend_distance = vlen(it.origin - item_org);
+ continue;
+ }
+ }
+ else
+ {
+ // If enemy only track distances
+ // TODO: track only if visible ?
+ if(vdist(it.origin - item_org, <, enemy_distance))
+ enemy_distance = vlen(it.origin - item_org);
+ }
+ });
+
+ // Rate the item only if no one needs it, or if an enemy is closer to it
+ if ((enemy_distance < friend_distance && vdist(item_org - org, <, enemy_distance)) ||
+ (friend_distance > autocvar_bot_ai_friends_aware_pickup_radius))
+ return true;
+ return false;
+};
+