Nov 18, 2010

Fear Working

Well, I didn't know it wasn't working until I decided to test it.

At first everything seemed to be okay; I cast Fear on a goblin and it fled.

Then I chased it to see what happens if it can't get away from me. But before I got it cornered, it attacked me, even though it had an escape route. This started an hours-long search for a bug.

Layer by layer I got deeper. Finally, I found the line, which caused this unwanted behavior - and it wasn't really a bug as such. It was in a function, which checked if a place in map was pathfindable for the pathfinding map. Here's a simplified version of the function:
bool isPathFindable(x, y) {
  if(creatureIsNextToPlayer(x, y)) return false;
  // switch-case for checking if the spot
  // has a wall or such.
What this means is if there is a creature standing next to the player, the position is marked as -1 (notPathFindable) instead of 1 (steps from the player). I think Ashie added this to make creatures find an alternate route if the player is, for instance, in a tunnel behind another creature. I even remember the conversation now.

The pathfinding map is updated only when the player's position changes, and that's why Fear seemed to work initially. The line is now commented out, however, and Fear is as it should.

message("The %s is no longer afraid.");
was giving "The (null) is no longer afraid." messages when Fear ended.

Fun times in the roguelike land.

No comments:

Post a Comment