diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-04 10:38:55 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-04 10:38:55 +0200 |
| commit | 525dd3c3990ee8365e08be59a48df1f51a42b638 (patch) | |
| tree | 3e3170a24e9c0399596b649398ca90be4efb3a26 /move.go | |
| parent | 0a64a4bdb028449bc3852887b1f54f397e40cf90 (diff) | |
Find a ne wpath to resource when blocked
Diffstat (limited to 'move.go')
| -rw-r--r-- | move.go | 46 |
1 files changed, 24 insertions, 22 deletions
@@ -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) } } |
