fix(pathfinding): added circular path detection and bail for wallhug#4603
fix(pathfinding): added circular path detection and bail for wallhug#4603cerwym wants to merge 1 commit intodkfans:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the wallhug pathfinding logic to detect circular movement patterns (loops) using a short position history, replacing the previous “90-degree retry” wallhug state handling.
Changes:
- Add an 8-sample position history + counters to
struct Navigationfor loop detection. - Introduce
update_position_history()andcheck_for_circular_path()helpers inariadne_wallhug.c. - Replace the old wallhug retry/state logic with a “circular loop detected → flip wallhug side” bailout.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/ariadne_wallhug.c |
Adds position-history tracking and loop detection; swaps out previous retry-based wallhug logic for loop-based bailout. |
src/ariadne.h |
Extends struct Navigation with loop-detection state (history buffer + indices/counters). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Position history for circle detection | ||
| struct Coord3d position_history[8]; | ||
| unsigned char history_index; | ||
| unsigned char loop_counter; |
There was a problem hiding this comment.
Adding fields to struct Navigation changes sizeof(struct CreatureControl) and therefore sizeof(struct Game) (since game_legacy.h embeds cctrl_data[]). The save loader (load_game_chunks) rejects saves when hdr.len != sizeof(struct Game), so this will make existing savegames incompatible. If preserving save compatibility matters, the save chunk needs a version bump and backward-compatible load path (or this needs to be explicitly documented as a breaking change).
| unsigned char loop_counter; |
There was a problem hiding this comment.
Working on prevention of save game breaks
|
Put back in draft while working on avoiding save break |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
src/ariadne_wallhug.c:134
- The doc comment says this function detects a "circular path", but the current implementation only checks whether the creature is within a fixed distance of any previous sample and increments a counter. That logic can also trigger for backtracking, small jitter, or being stationary, which isn't necessarily a circle. Either tighten the detection to match the comment (eg, detect repeated cycles with sufficient displacement), or update the comment to accurately describe the heuristic being used.
/// @brief Checks if the creature is moving in a circular path.
/// @param creatng The creature to check.
/// @return True if a circular path is detected, false otherwise.
static TbBool check_for_circular_path(struct Thing *creatng)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Adds history and removes old 90 degree wallhug state logic with proper circular loop check