It appears, that creatures who can't find a path request a path on every turn (like the [clowns] if you seal [the circus]).
Possible solution :
* add a variable named unsigned int i_am_lost into the structure/class of a creature.
* got to the function, that computes a path. I assume it is called whenever a creature requests a path, and the path or parts of it are stored as nodes into the creature. we assume the creature is a pointer named *cr (in oop it might be a method of creature, thougt oop is not effecient in general).
At the beginning :
if(cr->i_am_lost) {cr->i_am_lost--;return;}
....
At the point, there a creature didn't find a path to its destination :
cr->i_am_lost=random(50)+50;
This will set stuck creatures to idle, and prevent the 100 stuck [clowns] from eating up CPU time.
*Now a bit optimization: If a creature needs a path to fight, or for the case it might want to flee, set cr->i_am_lost to zero if :
** It got attacked
** It is a dwarf, and its labour preference was changed
** It is a dwarf, and the player gave a military order
** A door or hatch was unlocked by the player
** A door, hatch drawbridge or floodgate was unlocked by a trigger
* more optimization : Decide, which creatures are Bosses. Forgotten [Fluffy Rabbit], Dr[ake], Mega [Fluffy Rabbit] or the like, are bosses, and the value is set to 10 instead of 50. This will give them a fast reponse time. The [clowns] of the [party catering], if you dig through an [asbestos] vein are no bosses -what makes the deadly is primary their number of 100 or so, and not the individual [clown]. The value should however always be set, as it appears, that a single stuck miner can slow down the game.
Instead of optimizing Dwarf Fortress, it might actually be more important, to fix the abundand crashes. I never actually "finished" a game in dwarf fortress, because it will always reach a point, then a safefile will crash after unpauseing, and of course crash every hour or so anyway. Dr Watson 32 shows, that all crashes are acces of a NULL pointer, so all crashes could be prevented, by checking for NULL Pointers before acessing them. An interesting point is also, that the famous tree bug actually calls a NULL Pointer, what is the Curse of Object-oriented Programming (probably a vitual Method). If someone ever wants to write a stable remake of Dwarf Fortress, I recomment, that you use standart C instead of C++, because it is much easier to prevent such critical errors with pure imperative programming.