diff options
Diffstat (limited to 'order.go')
| -rw-r--r-- | order.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/order.go b/order.go new file mode 100644 index 0000000..13c1b09 --- /dev/null +++ b/order.go @@ -0,0 +1,44 @@ +package main + +import "golang.org/x/exp/slog" + +type Order interface { + Update(e *Entity, g *Game) +} + +type PatrolOrder struct { + origin Point + destination Point +} + +func (o *PatrolOrder) Update(e *Entity, g *Game) { + if e.Position.IsEnabled && e.Move.IsEnabled && e.Order.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 (e *Entity) UpdateOrder(g *Game) { + if e.Order.IsEnabled { + if e.Order.Value != nil { + e.Order.Value.Update(e, g) + } + } +} + +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("patroling 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} +} |
