Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeat bullseye coordinates in DECLARE response if player didn't specify format #483

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 15 additions & 15 deletions pkg/composer/declare.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
package composer

import (
"fmt"
"slices"

"github.com/dharmab/skyeye/pkg/brevity"
)

// ComposeDeclareResponse constructs natural language brevity for responding to a DECLARE call.
func (c *Composer) ComposeDeclareResponse(response brevity.DeclareResponse) NaturalLanguageResponse {
func (c *Composer) ComposeDeclareResponse(response brevity.DeclareResponse) (reply NaturalLanguageResponse) {
reply.WriteBoth(c.composeCallsigns(response.Callsign) + ", ")

if response.Sour {
reply := fmt.Sprintf("%s, %s", c.composeCallsigns(response.Callsign), "unable, timber sour. Repeat your request with bullseye or BRAA position included.")
return NaturalLanguageResponse{
Subtitle: reply,
Speech: reply,
}
reply.WriteBoth("unable, timber sour. Repeat your request with bullseye or BRAA position included.")
return
}

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,
if response.Readback != nil {
bullseye := c.composeBullseye(*response.Readback)
reply.WriteResponse(bullseye)
reply.WriteBoth(",")
}
reply.WriteBoth(" " + string(response.Declaration))
return
}

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
}
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
Loading