aboutsummaryrefslogtreecommitdiff
path: root/gather_order.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2025-07-04 17:55:53 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2025-07-04 23:02:21 +0200
commita5fef758107888853c14a592696b45768ef56df8 (patch)
tree9d1fd0b0abb49ce6814b8868926bf7af83611303 /gather_order.go
parente3f14fc0b375b4b7c2204a669d058ac124b78e92 (diff)
Refactor into packages
Diffstat (limited to 'gather_order.go')
-rw-r--r--gather_order.go19
1 files changed, 10 insertions, 9 deletions
diff --git a/gather_order.go b/gather_order.go
index b4f3c9e..2f5a060 100644
--- a/gather_order.go
+++ b/gather_order.go
@@ -1,6 +1,7 @@
package main
import (
+ "age_of_empires/physics"
"math"
"time"
@@ -22,7 +23,7 @@ func (o *GatherOrder) Update(e *Entity, g *Game) {
o.updateGathererFull(e, g, gatherer)
return
}
- if Distance(e.Position.Value, gatherer.CurrentTarget.Position.Value) <= 100 {
+ if physics.Distance(e.Position.Value, gatherer.CurrentTarget.Position.Value) <= 100 {
o.updateGathering(gatherer, source)
return
}
@@ -56,7 +57,7 @@ func (o *GatherOrder) updateGathererFull(e *Entity, g *Game, gatherer *ResourceG
slog.Info("storage target", slog.String("storage", destination.String()), slog.Int("distance", distance))
if distance > 1 {
slog.Info("moving to storage", slog.String("storage", destination.String()))
- e.StartMove(destination, g.getMoveMap())
+ physics.StartMove(&e.Move,e.Position, destination, g.getMoveMap())
return
}
gatherer.CurrentVolume = 0
@@ -65,21 +66,21 @@ func (o *GatherOrder) updateGathererFull(e *Entity, g *Game, gatherer *ResourceG
}
func (o *GatherOrder) startMoveToSource(e *Entity, gatherer *ResourceGatherer, g *Game) {
- sourceDockings := AdjacentPoints(gatherer.CurrentTarget.Position.Value)
+ sourceDockings := physics.AdjacentPoints(gatherer.CurrentTarget.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
}
- e.StartMove(destination, g.getMoveMap())
+ physics.StartMove(&e.Move,e.Position, destination, g.getMoveMap())
}
-func getAllStorageDockings(g *Game) []Point {
- storageDockings := []Point{}
+func getAllStorageDockings(g *Game) []physics.Point {
+ storageDockings := []physics.Point{}
for _, entity := range g.Entities {
if entity.Position.IsEnabled && entity.ResourceStorage.IsEnabled {
- storageDockings = append(storageDockings, AdjacentPoints(entity.Position.Value)...)
+ storageDockings = append(storageDockings, physics.AdjacentPoints(entity.Position.Value)...)
}
}
return storageDockings
@@ -91,14 +92,14 @@ func Gather(e *Entity, source *Entity, g *Game) Order {
slog.Info("gathering from", slog.String("source", source.Position.Value.String()))
e.Order.Value = &GatherOrder{source: source}
e.ResourceGatherer.Value.CurrentTarget = source
- sourceDockings := AdjacentPoints(source.Position.Value)
+ 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
}
- e.StartMove(destination, g.getMoveMap())
+ physics.StartMove(&e.Move,e.Position, destination, g.getMoveMap())
}
}
return &GatherOrder{source: source}