Skip to content

Commit

Permalink
Repeat bullseye coordinates in DECLARE response if player didn't spec…
Browse files Browse the repository at this point in the history
…ify format
  • Loading branch information
dharmab committed Jan 3, 2025
1 parent c488e5f commit d3922ad
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 39 deletions.
6 changes: 6 additions & 0 deletions pkg/brevity/declare.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type DeclareRequest struct {
Sour bool
// IsBRAA indicates if the contact is provided using Bullseye (false) or BRAA (true).
IsBRAA bool
// IsAmbiguous indicates if the requestor did not explicitly state if they
// were providing Bullseye or BRAA coordinates.
IsAmbiguous bool
// Bullseye of the contact, if provided using Bullseye.
Bullseye Bullseye
// Bearing of the contact, if provided using BRAA.
Expand Down Expand Up @@ -89,6 +92,9 @@ type DeclareResponse struct {
// because the friendly aircraft did not provide coordinates for the
// contact.
Sour bool
// If readback is not nil, the controller should read back the coordinate
// in the response.
Readback *Bullseye
// Declaration of the contact.
Declaration Declaration
// Group that was identified, if a specific one was identifiable.
Expand Down
25 changes: 16 additions & 9 deletions pkg/composer/declare.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@ func (c *Composer) ComposeDeclareResponse(response brevity.DeclareResponse) Natu
}
}

var reply NaturalLanguageResponse

reply.WriteBoth(c.composeCallsigns(response.Callsign) + ", ")

if response.Readback != nil {
bullseye := c.composeBullseye(*response.Readback)
reply.WriteResponse(bullseye)
reply.WriteBoth(", ")
}

if slices.Contains([]brevity.Declaration{brevity.Furball, brevity.Unable, brevity.Clean}, response.Declaration) {
reply := fmt.Sprintf("%s, %s.", c.composeCallsigns(response.Callsign), response.Declaration)
return NaturalLanguageResponse{
Subtitle: reply,
Speech: reply,
}
reply.WriteBoth(" " + string(response.Declaration))
return reply
}

info := c.composeCoreInformationFormat(response.Group)
return NaturalLanguageResponse{
Subtitle: fmt.Sprintf("%s, %s", c.composeCallsigns(response.Callsign), info.Subtitle),
Speech: fmt.Sprintf("%s, %s", c.composeCallsigns(response.Callsign), info.Speech),
}
reply.WriteResponse(info)

return reply
}
4 changes: 4 additions & 0 deletions pkg/controller/declare.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ func (c *Controller) HandleDeclare(ctx context.Context, request *brevity.Declare
}
}

if request.IsAmbiguous {
response.Readback = &request.Bullseye
}

logger.Debug().Any("declaration", response.Declaration).Msg("responding to DECLARE request")
c.calls <- NewCall(ctx, response)
}
33 changes: 19 additions & 14 deletions pkg/parser/declare.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ func parseDeclare(callsign string, scanner *bufio.Scanner) (*brevity.DeclareRequ
var bullseye *brevity.Bullseye
var bearing bearings.Bearing
var _range unit.Length
var IsBRAA bool
var isBRAA bool
isAmbiguous := true
for {
if scanner.Text() == "" {
ok := scanner.Scan()
Expand Down Expand Up @@ -50,6 +51,7 @@ func parseDeclare(callsign string, scanner *bufio.Scanner) (*brevity.DeclareRequ
for _, word := range bullseyeWords {
if isSimilar(scanner.Text(), word) {
log.Debug().Str("text", scanner.Text()).Msg("found bullseye token")
isAmbiguous = false
bullseye = parseBullseye(scanner)
if bullseye == nil {
return nil, false
Expand All @@ -66,6 +68,7 @@ func parseDeclare(callsign string, scanner *bufio.Scanner) (*brevity.DeclareRequ
for _, word := range braaWords {
if isSimilar(scanner.Text(), word) {
log.Debug().Str("text", scanner.Text()).Msg("found braa token")
isAmbiguous = false
scanner.Scan()
b, extra, ok := parseBearing(scanner)
if !ok {
Expand All @@ -78,12 +81,12 @@ func parseDeclare(callsign string, scanner *bufio.Scanner) (*brevity.DeclareRequ
return nil, false
}
_range = r
IsBRAA = true
isBRAA = true
break
}
}

if IsBRAA {
if isBRAA {
log.Debug().Float64("bearing", bearing.Degrees()).Float64("range", _range.NauticalMiles()).Msg("parsed bearing and range")
foundCoordinate = true
break
Expand All @@ -102,23 +105,25 @@ func parseDeclare(callsign string, scanner *bufio.Scanner) (*brevity.DeclareRequ
track := parseTrack(scanner)
log.Debug().Stringer("track", track).Msg("parsed track")

if IsBRAA {
if isBRAA {
return &brevity.DeclareRequest{
Callsign: callsign,
Bearing: bearing,
Range: _range,
Altitude: altitude,
Track: track,
IsBRAA: true,
Callsign: callsign,
Bearing: bearing,
Range: _range,
Altitude: altitude,
Track: track,
IsBRAA: true,
IsAmbiguous: false,
}, true
}
if bullseye == nil {
return nil, false
}
return &brevity.DeclareRequest{
Callsign: callsign,
Bullseye: *bullseye,
Altitude: altitude,
Track: track,
Callsign: callsign,
Bullseye: *bullseye,
Altitude: altitude,
Track: track,
IsAmbiguous: isAmbiguous,
}, true
}
42 changes: 26 additions & 16 deletions pkg/parser/declare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ func TestParserDeclare(t *testing.T) {
bearings.NewMagneticBearing(75*unit.Degree),
26*unit.NauticalMile,
),
Altitude: 2000 * unit.Foot,
Track: brevity.UnknownDirection,
IsAmbiguous: true,
Altitude: 2000 * unit.Foot,
Track: brevity.UnknownDirection,
},
},
{
Expand All @@ -33,8 +34,9 @@ func TestParserDeclare(t *testing.T) {
bearings.NewMagneticBearing(75*unit.Degree),
26*unit.NauticalMile,
),
Altitude: 0,
Track: brevity.UnknownDirection,
IsAmbiguous: true,
Altitude: 0,
Track: brevity.UnknownDirection,
},
},
{
Expand All @@ -45,8 +47,9 @@ func TestParserDeclare(t *testing.T) {
bearings.NewMagneticBearing(75*unit.Degree),
26*unit.NauticalMile,
),
Altitude: 2000 * unit.Foot,
Track: brevity.UnknownDirection,
IsAmbiguous: true,
Altitude: 2000 * unit.Foot,
Track: brevity.UnknownDirection,
},
},
{
Expand All @@ -69,8 +72,9 @@ func TestParserDeclare(t *testing.T) {
bearings.NewMagneticBearing(75*unit.Degree),
26*unit.NauticalMile,
),
Altitude: 2000 * unit.Foot,
Track: brevity.UnknownDirection,
IsAmbiguous: true,
Altitude: 2000 * unit.Foot,
Track: brevity.UnknownDirection,
},
},
{
Expand Down Expand Up @@ -129,8 +133,9 @@ func TestParserDeclare(t *testing.T) {
bearings.NewMagneticBearing(52*unit.Degree),
77*unit.NauticalMile,
),
Altitude: 2000 * unit.Foot,
Track: brevity.UnknownDirection,
IsAmbiguous: true,
Altitude: 2000 * unit.Foot,
Track: brevity.UnknownDirection,
},
},
{
Expand Down Expand Up @@ -180,8 +185,9 @@ func TestParserDeclare(t *testing.T) {
{
text: "anyface, Eagle 12, declare",
expected: &brevity.DeclareRequest{
Callsign: "eagle 1 2",
Sour: true,
Callsign: "eagle 1 2",
Sour: true,
IsAmbiguous: true,
},
},
{
Expand All @@ -202,7 +208,8 @@ func TestParserDeclare(t *testing.T) {
bearings.NewMagneticBearing(177*unit.Degree),
29*unit.NauticalMile,
),
Track: brevity.UnknownDirection,
IsAmbiguous: true,
Track: brevity.UnknownDirection,
},
},
{
Expand Down Expand Up @@ -268,7 +275,8 @@ func TestParserDeclare(t *testing.T) {
bearings.NewMagneticBearing(176*unit.Degree),
31*unit.NauticalMile,
),
Track: brevity.UnknownDirection,
IsAmbiguous: true,
Track: brevity.UnknownDirection,
},
},
{
Expand All @@ -279,7 +287,8 @@ func TestParserDeclare(t *testing.T) {
bearings.NewMagneticBearing(177*unit.Degree),
29*unit.NauticalMile,
),
Track: brevity.UnknownDirection,
IsAmbiguous: true,
Track: brevity.UnknownDirection,
},
},
{
Expand All @@ -290,7 +299,8 @@ func TestParserDeclare(t *testing.T) {
bearings.NewMagneticBearing(255*unit.Degree),
45*unit.NauticalMile,
),
Track: brevity.UnknownDirection,
IsAmbiguous: true,
Track: brevity.UnknownDirection,
},
},
}
Expand Down

0 comments on commit d3922ad

Please sign in to comment.