diff options
author | Julien Dessaux | 2025-02-15 01:22:36 +0100 |
---|---|---|
committer | Julien Dessaux | 2025-02-15 01:22:36 +0100 |
commit | 66466e161fff1bd2b8c2ea42249947ccc19c39fe (patch) | |
tree | 67f0e7fe70a3993764c43aa77fa6707a4137ae67 /golang/pkg/agent | |
parent | [golang] implement automation loop and add contract accepting (diff) | |
download | spacetraders-66466e161fff1bd2b8c2ea42249947ccc19c39fe.tar.gz spacetraders-66466e161fff1bd2b8c2ea42249947ccc19c39fe.tar.bz2 spacetraders-66466e161fff1bd2b8c2ea42249947ccc19c39fe.zip |
[golang] implement systems and waypoints lookups
Diffstat (limited to '')
-rw-r--r-- | golang/pkg/agent/contracting.go | 2 | ||||
-rw-r--r-- | golang/pkg/agent/run.go | 6 | ||||
-rw-r--r-- | golang/pkg/agent/visit.go | 24 |
3 files changed, 32 insertions, 0 deletions
diff --git a/golang/pkg/agent/contracting.go b/golang/pkg/agent/contracting.go index 44d7753..0f07170 100644 --- a/golang/pkg/agent/contracting.go +++ b/golang/pkg/agent/contracting.go @@ -26,6 +26,7 @@ func (a *agent) autoContracting(ship *model.Ship) { } } } + a.sendShipError(fmt.Errorf("failed to run contracts: negotiating new contracts is not implemented yet"), ship) // TODO //for { // negotiate @@ -37,6 +38,7 @@ func (a *agent) runContract(contract *model.Contract, ship *model.Ship) error { if err := a.client.Accept(contract, a.db); err != nil { return fmt.Errorf("failed to run contract: %w", err) } + //slog.Info("running contract", "contract", contract, "ship", ship.Symbol) switch contract.Type { // TODO //case "PROCUREMENT": diff --git a/golang/pkg/agent/run.go b/golang/pkg/agent/run.go index bc5254e..1d70be8 100644 --- a/golang/pkg/agent/run.go +++ b/golang/pkg/agent/run.go @@ -23,6 +23,7 @@ type State int const ( start_running_contracts_with_the_command_ship = iota + visit_all_shipyards ) func Run( @@ -54,6 +55,11 @@ func Run( agent.wg.Add(1) go agent.autoContracting(&agent.ships[0]) state++ + case visit_all_shipyards: + if err := agent.visitAllShipyards(&agent.ships[1]); err != nil { + agent.sendShipError(fmt.Errorf("agent runner returned an error on state %d: %w", state, err), &agent.ships[1]) + } + state++ return default: agent.sendShipError(fmt.Errorf("agent runner reach an unknown state: %d", state), nil) diff --git a/golang/pkg/agent/visit.go b/golang/pkg/agent/visit.go new file mode 100644 index 0000000..019a6e5 --- /dev/null +++ b/golang/pkg/agent/visit.go @@ -0,0 +1,24 @@ +package agent + +import ( + "fmt" + "log/slog" + + "git.adyxax.org/adyxax/spacetraders/golang/pkg/model" +) + +func (a *agent) visitAllShipyards(ship *model.Ship) error { + system, err := a.client.GetSystem(ship.Nav.SystemSymbol, a.db) + if err != nil { + return fmt.Errorf("failed to visit all shipyards: %w", err) + } + waypoints, err := a.client.ListWaypointsInSystem(system, a.db) + if err != nil { + return fmt.Errorf("failed to visit all shipyards: %w", err) + } + //slog.Info("get system", "system", system.Waypoints, "err", err) + //waypoint, err := a.client.GetWaypoint("X1-RR14-J88", a.db) + slog.Info("get waypoint", "waypoint", waypoints[0]) + + return fmt.Errorf("failed to visit all shipyards: not implemented yet") +} |