From 525dd3c3990ee8365e08be59a48df1f51a42b638 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Fri, 4 Jul 2025 10:38:55 +0200 Subject: Find a ne wpath to resource when blocked --- move.go | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'move.go') diff --git a/move.go b/move.go index aae83ed..da73c27 100644 --- a/move.go +++ b/move.go @@ -173,32 +173,34 @@ func (e *Entity) moveToward(destination Point) { } func (e *Entity) UpdateMove(moveMap MoveMap) { - if e.Move.IsEnabled && e.Position.IsEnabled { - position := e.Position.Value - if !e.Move.Value.IsActive { - return - } - next := e.Move.Value.Path[0] - if Distance(position, next) < MOVE_SPEED { - e.Position.Value = next - remainingPath := e.Move.Value.Path[1:] - if next == e.Move.Value.Destination { + if !e.Move.IsEnabled || !e.Position.IsEnabled { + return + } + position := e.Position.Value + if !e.Move.Value.IsActive { + return + } + next := e.Move.Value.Path[0] + if Distance(position, next) < MOVE_SPEED { + e.Position.Value = next + remainingPath := e.Move.Value.Path[1:] + if next == e.Move.Value.Destination { + e.Move.Value.IsActive = false + slog.Info("move finished", slog.String("destination", e.Move.Value.Destination.String())) + } else if remainingPath.isValid(moveMap) { + e.Move.Value.Path = remainingPath + } else { + // Here maybe the destination has to change + path, ok := SearchPath(next, e.Move.Value.Destination, moveMap) + if !ok { + slog.Info("no path found", slog.String("destination", e.Move.Value.Destination.String())) e.Move.Value.IsActive = false - slog.Info("move finished", slog.String("destination", e.Move.Value.Destination.String())) - } else if remainingPath.isValid(moveMap) { - e.Move.Value.Path = remainingPath } else { - path, ok := SearchPath(next, e.Move.Value.Destination, moveMap) - if !ok { - slog.Info("no path found", slog.String("destination", e.Move.Value.Destination.String())) - e.Move.Value.IsActive = false - } else { - e.Move.Value.Path = path[1:] - } + e.Move.Value.Path = path[1:] } - } else { - e.moveToward(next) } + } else { + e.moveToward(next) } } -- cgit v1.3