@@ -9,48 +9,48 @@ bool DefenderFSMBase::ballNearbyWithoutThreat(
99 const TbotsProto::BallStealMode& ball_steal_mode,
1010 const TbotsProto::DefenderStealConfig& defender_steal_config)
1111{
12+ if (ball_steal_mode == TbotsProto::BallStealMode::IGNORE )
13+ {
14+ // Do nothing if stealing is disabled
15+ return false ;
16+ }
17+
1218 Point robot_position = robot.position ();
1319 Point ball_position = world_ptr->ball ().position ();
1420
1521 std::optional<Robot> nearest_friendly_to_ball =
1622 world_ptr->friendlyTeam ().getNearestRobot (ball_position);
1723 std::optional<Robot> nearest_enemy_to_ball =
1824 world_ptr->enemyTeam ().getNearestRobot (robot_position);
19- if (ball_steal_mode == TbotsProto::BallStealMode::IGNORE )
20- {
21- // Do nothing if stealing is disabled
22- return false ;
23- }
24- else if (nearest_friendly_to_ball.has_value () &&
25- robot.id () != nearest_friendly_to_ball.value ().id ())
25+
26+ if (nearest_friendly_to_ball.has_value () &&
27+ robot.id () != nearest_friendly_to_ball.value ().id ())
2628 {
2729 // Do nothing if this robot is not the closest to the ball. Resolves issue of
2830 // multiple simultaneous steals
2931 return false ;
3032 }
31- if (nearest_enemy_to_ball.has_value ())
32- {
33- // Get the ball if ball is closer to robot than enemy threat by threshold ratio
34- // and within max range
35- double ball_distance_to_friendly = distance (robot_position, ball_position);
36- double ball_distance_to_enemy =
37- distance (nearest_enemy_to_ball.value ().position (), ball_position);
38-
39- bool ball_is_near_friendly =
40- ball_distance_to_friendly <
41- ball_distance_to_enemy *
42- (1.0 - defender_steal_config.max_get_ball_ratio_threshold ());
43- bool ball_is_within_max_range =
44- ball_distance_to_friendly <= defender_steal_config.max_get_ball_radius_m ();
45- bool ball_is_slow = world_ptr->ball ().velocity ().length () <=
46- defender_steal_config.max_ball_speed_to_get_m_per_s ();
4733
48- return ball_is_near_friendly && ball_is_within_max_range && ball_is_slow;
49- }
50- else
34+ if (!nearest_enemy_to_ball.has_value ())
5135 {
5236 return true ;
5337 }
38+
39+ // Get the ball if ball is closer to robot than enemy threat by threshold ratio
40+ // and within max range
41+ double ball_distance_to_friendly = distance (robot_position, ball_position);
42+ double ball_distance_to_enemy =
43+ distance (nearest_enemy_to_ball.value ().position (), ball_position);
44+
45+ bool ball_is_near_friendly =
46+ ball_distance_to_friendly <
47+ ball_distance_to_enemy * defender_steal_config.max_get_ball_ratio_threshold ();
48+ bool ball_is_within_max_range =
49+ ball_distance_to_friendly <= defender_steal_config.max_get_ball_radius_m ();
50+ bool ball_is_slow = world_ptr->ball ().velocity ().length () <=
51+ defender_steal_config.max_ball_speed_to_get_m_per_s ();
52+
53+ return ball_is_near_friendly && ball_is_within_max_range && ball_is_slow;
5454}
5555
5656void DefenderFSMBase::prepareGetPossession (
0 commit comments