From ad119e88258cf6add42c9570b7a2b7b591fd0b99 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Fri, 6 Oct 2023 09:21:07 +0200 Subject: feat(order): Gather resources --- patrol_order.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 patrol_order.go (limited to 'patrol_order.go') diff --git a/patrol_order.go b/patrol_order.go new file mode 100644 index 0000000..b7201ed --- /dev/null +++ b/patrol_order.go @@ -0,0 +1,32 @@ +package main + +import "golang.org/x/exp/slog" + +type PatrolOrder struct { + origin Point + destination Point +} + +func (o *PatrolOrder) Update(e *Entity, g *Game) { + if e.Position.IsEnabled && e.Move.IsEnabled { + if !e.Move.Value.IsActive { + moveMap := g.getMoveMap() + if e.Position.Value == o.destination { + e.StartMove(o.origin, moveMap) + } else { + e.StartMove(o.destination, moveMap) + } + } + } +} + +func Patrol(e *Entity, destination Point) Order { + if e.Selection.IsEnabled && e.Position.IsEnabled && e.Move.IsEnabled && e.Order.IsEnabled { + if e.Selection.Value.IsSelected { + origin := e.Position.Value + slog.Info("patrolling between", slog.String("origin", origin.String()), slog.String("destination", destination.String())) + e.Order.Value = &PatrolOrder{origin: origin, destination: destination} + } + } + return &PatrolOrder{origin: e.Position.Value, destination: destination} +} -- cgit v1.3