@@ -2,6 +2,7 @@ package engine
22
33import (
44 "github.com/RoboCup-SSL/ssl-game-controller/internal/app/state"
5+ "slices"
56)
67
78type BallPlacementCoordinator struct {
@@ -23,12 +24,14 @@ func (c *BallPlacementCoordinator) process() {
2324 }
2425
2526 remainingDistance := c .remainingPlacementDistance ()
27+ nearestOwnRobotDistance := c .nearestOwnRobotDistance ()
2628
2729 e .Enqueue (createGameEventChange (state .GameEvent_PLACEMENT_FAILED , & state.GameEvent {
2830 Event : & state.GameEvent_PlacementFailed_ {
2931 PlacementFailed : & state.GameEvent_PlacementFailed {
30- ByTeam : e .currentState .Command .ForTeam ,
31- RemainingDistance : & remainingDistance ,
32+ ByTeam : e .currentState .Command .ForTeam ,
33+ RemainingDistance : & remainingDistance ,
34+ NearestOwnBotDistance : & nearestOwnRobotDistance ,
3235 },
3336 },
3437 }))
@@ -42,3 +45,25 @@ func (c *BallPlacementCoordinator) remainingPlacementDistance() float32 {
4245 ballPos := c .gcEngine .trackerStateGc .Ball .Pos .ToVector2 ()
4346 return float32 (placementPos .DistanceTo (ballPos ))
4447}
48+
49+ func (c * BallPlacementCoordinator ) nearestOwnRobotDistance () float32 {
50+ if c .gcEngine .currentState .PlacementPos == nil {
51+ return - 1
52+ }
53+ placementPos := c .gcEngine .currentState .PlacementPos
54+
55+ var distances []float32
56+ for _ , robot := range c .gcEngine .trackerStateGc .Robots {
57+ if * robot .Id .Team == * c .gcEngine .currentState .Command .ForTeam {
58+ distance := float32 (robot .Pos .DistanceTo (placementPos ))
59+ distances = append (distances , distance )
60+ }
61+ }
62+
63+ if len (distances ) == 0 {
64+ return - 1
65+ }
66+
67+ slices .Sort (distances )
68+ return distances [0 ]
69+ }
0 commit comments