diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-09 08:58:14 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-09 08:58:14 +0200 |
| commit | 9f30f800443e6496bbba264a375c126cb26b1760 (patch) | |
| tree | bc0da293f552a0ecf7cac356a6747c109ce9eb0c /gather_order.go | |
| parent | 057adf65468e7b6ec544686b80433093a9f9deab (diff) | |
Spawn target for newly spawned units
Diffstat (limited to 'gather_order.go')
| -rw-r--r-- | gather_order.go | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/gather_order.go b/gather_order.go index aee8b37..be98ca4 100644 --- a/gather_order.go +++ b/gather_order.go @@ -85,20 +85,19 @@ func getAllStorageDockings(g *Game) []physics.Point { } func Gather(e *Entity, source *Entity, g *Game) Order { - if e.Selection.IsEnabled && e.Position.IsEnabled && e.Move.IsEnabled && e.ResourceGatherer.IsEnabled && e.Order.IsEnabled { - if e.Selection.Value.IsSelected { - slog.Info("gathering from", slog.String("source", source.Position.Value.String())) - e.Order.Value = &GatherOrder{source: source} - e.ResourceGatherer.Value.CurrentTarget = source - sourceDockings := physics.AdjacentPoints(source.Position.Value) - destination, distance := g.Closest(e.Position.Value, sourceDockings) - if distance == math.MaxInt { - slog.Info("no accessible storage, canceling gather order") - e.Order.Value = nil - return nil - } - physics.StartMove(&e.Move, e.Position, destination, g.getMoveMap()) - } + if !e.Position.IsEnabled || !e.Move.IsEnabled || !e.Order.IsEnabled { + return nil } + slog.Info("gathering from", slog.String("source", source.Position.Value.String())) + e.Order.Value = &GatherOrder{source: source} + e.ResourceGatherer.Value.CurrentTarget = source + sourceDockings := physics.AdjacentPoints(source.Position.Value) + destination, distance := g.Closest(e.Position.Value, sourceDockings) + if distance == math.MaxInt { + slog.Info("no accessible storage, canceling gather order") + e.Order.Value = nil + return nil + } + physics.StartMove(&e.Move, e.Position, destination, g.getMoveMap()) return &GatherOrder{source: source} } |
