diff options
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | gather_order.go | 8 | ||||
| -rw-r--r-- | main.go | 4 | ||||
| -rw-r--r-- | spawn.go | 9 |
4 files changed, 13 insertions, 9 deletions
@@ -4,7 +4,6 @@ ## TODO -- time must come from engine, not now - see the current action (debug?) - spawner: show queue - keyboard config diff --git a/gather_order.go b/gather_order.go index 10cbcaf..eec9b99 100644 --- a/gather_order.go +++ b/gather_order.go @@ -1,10 +1,11 @@ package main import ( - "age_of_empires/physics" "math" "time" + "age_of_empires/physics" + "golang.org/x/exp/slog" ) @@ -23,7 +24,7 @@ func (o *GatherOrder) Update(e *Entity, g *Game) { return } if physics.Distance(e.Position.Value, gatherer.CurrentTarget.Position.Value) <= 100 { - o.updateGathering(gatherer, &gatherer.CurrentTarget.ResourceSource.Value) + o.updateGathering(g.Now(), gatherer, &gatherer.CurrentTarget.ResourceSource.Value) return } if !e.Move.Value.IsActive { @@ -31,8 +32,7 @@ func (o *GatherOrder) Update(e *Entity, g *Game) { } } -func (*GatherOrder) updateGathering(gatherer *ResourceGatherer, source *ResourceSource) { - now := time.Now() +func (*GatherOrder) updateGathering(now time.Time, gatherer *ResourceGatherer, source *ResourceSource) { if gatherer.CurrentVolume >= gatherer.MaxCapacity || gatherer.LastPickupTime.Add(200*time.Millisecond).After(now) { return } @@ -39,6 +39,10 @@ type Game struct { UnitBuilder EntityBuilder } +func (g Game) Now() time.Time { + return time.Now() +} + // TODO: This could be a maintained index func (g *Game) getMoveMap() physics.MoveMap { blocked := map[physics.Point]bool{} @@ -1,10 +1,11 @@ package main import ( - "age_of_empires/ecs" - "age_of_empires/physics" "log/slog" "time" + + "age_of_empires/ecs" + "age_of_empires/physics" ) type spawnRequest struct { @@ -31,14 +32,14 @@ func (spawn *Spawn) AddRequest(g *Game) { return } g.ResourceAmount -= spawn.UnitResourceCost - spawn.Requests = append(spawn.Requests, spawnRequest{start: time.Now()}) + spawn.Requests = append(spawn.Requests, spawnRequest{start: g.Now()}) } func UpdateSpawn(g *Game, spawn *ecs.Component[Spawn], position ecs.Component[physics.Point]) { if !spawn.IsEnabled || !position.IsEnabled { return } - now := time.Now() + now := g.Now() if len(spawn.Value.Requests) == 0 || now.Sub(spawn.Value.Requests[0].start) < time.Duration(spawn.Value.UnitSpawnDuration) { return } |
