Pathfinding, Doors, Queues, and Items
Hey Folks! Bit of a slog today, as I continue working through some annoying bugs in the pathfinding, queue, and other systems.
I was able to figure out why AI prematurely triggered interactions while walking towards them. Basically, the code to calculate range to target in tiles was incorrectly converting units, causing most distances to be 0. In other words, the AI almost always thought it was close enough. Once I fixed that calc error, the AI would correctly wait until it arrived at a destination before triggering its interaction or UI.
And for a while, I thought that was it. I moved on to a minor issue with pathfinding that caused AI to always spiral down and out before setting off to a target, which turned out to be a typo in the code. And while in there, I noticed a place where the pathfinder should bail if the current interaction is null.
I also finally figured out why my animations were sometimes not playing. Seemingly at random, the AI would get stuck playing walk or use animations when doing anything other than standing idle. And as it turns out, this was a bug in the animation state machine. It was waiting for an "idle" signal to exit "use" and "walk" states, which doesn't happen if the AI goes straight from "use" to "walk" or vice versa. Changing the conditional tests there was pretty easy, and now AI looked much better, doing appropriate animations for each action.
Finally, I also noticed a bug in hull patching that occurred when the AI automatically retrieved a hull patch kit before moving on to repair a hole. The range info on that interaction was wrong, so AI was repairing from across the ship. Again, small typo was easy enough to fix. Just hard to find.
I thought I was in good shape after that, but I started noticing more bugs as I tested these. As it turned out, my AI was unable to continue certain actions after passing through a door.
The pathfinder code inserts an "open door" action into the queue when the AI's next step would intersect a door, and that seems to work as expected. But as soon as that is done, the AI resumes walking as if the target is right at the doorway. Things are a bit better if the AI was on its way to interact with an item. It just pauses, recalculates pathfinding, and continues on. The pause isn't great, but it works.
But if the AI was just walking to a tile, such as when the player tells it to go there, the AI gives up in the doorway after opening it. The walk command is still in the queue, but it's like the command's target tile moved to the door. I can see in the code that the target is right, so this is starting to look like another pathfinding bug. I.e. the pathfinder had its goal changed somewhere in there, and never got reset to the ultimate goal.
I thought I was being clever by recalculating pathfinding any time the command queue's head changed (i.e. when a new action was added, or any action was removed), but no change. I'll have to dig into this a bit more to see why.
Overall, I guess today wasn't a bad day. A lot of tricky, annoying bugs got solved. But it sure would be nice to be back into working on fun-factor instead of bugs!