A request on Ameranth's and Elric's Epic Encounters Nexus site reminded me of some old wounds I still suffer:

Several times I tried to teach NPCs in recognizing items blocking their path and in removing them, both in combat and, not least, during their peace routines.
While it's mostly just 'fair' that the Evil gets trapped by the Good, I felt quite pity about those innocent NPCs that got locked in by dark-minded players, to be utterly dependent on their caprice. I tried to help them but, as I admit, I always failed.

This time, though, I seem to be on the right track and got a prototype working, both in combat and in peace, which made NPCs successfully free theirselves from their 'prisons' or remove items that stood between them and me.
They aren't 100% accurate (and never will be) and sometimes there are some weird side-effects (like throwing items through walls or against another NPC's head), not exactly knowing which item is the one to move and where to throw it, but they managed to deliver quite well under different circumstances (blocking items close to themselves, close to the target or somewhere in between).

I had three test situations:

1) I placed items around Mayor Cecil's chair, where he uses to sit half the day, and watched if he would be able to reach his chair, starting from the cupboard near the stairs:

He walked to the barricades I had built, took the candle holder, throw it against his wife's head (no more than 1 damage, by the way) and walked close to his chair. And since I had placed two additional chairs to block the path twice, he took one chair, threw it away (well, once he threw his own chair right into the next room) and had a seat as though nothing had happened. I walled him in again, while he was relaxing, but he delivered as well.

2) There's a small hut in my testlevel, with two crates unfortunately blocking the entrance (the previous owner left it this way). I placed my player character inside the hut and then called several NPCs to come to me. They moved to the walls, walked around to the entrance, removed one crate, opened the door (thanks to the engine) and got in.

3) I started a fight in Morris's kitchen, some guards came in, I walked right out the door and placed two barrels at the door. Once a similar obstacle as a dragon, this time they just threw one barrel out of their way and attacked me.

I'm quite confident that there are still flaws or situations they can't handle or need some time for, doing stupid things. But I think I can already show it to you guys, so you can do some tests with it.

I've scripted two effects to see where the character wants to move to but fails in doing so (and to see which part of the script is being executed). The blue light shows the original target of the character when the movement fails. The red light shows an approximate position the character wants to move to when the movement fails. When you see the red light the character will try to move items close to his own position or close to the red light position.

Some comments on the script:

The main problems of doing this are:

1) We don't know the possible (but blocked) paths to the target.
2) We don't know where the blocking items are.
3) We don't know which items to regard (and can't or shouldn't check for every possible item template).
4) The scripting isn't really built for this specific problem. There is no OnMovementFailed EVENT, it's only a INTERRUPT event. But we necessarily need this. Recording every item the player moves or drops is not viable. Always checking for possible items that are in the way doesn't work either (we don't know the path and which items block it). Just checking for items the character is facing would be absolutely unreliable.
So we have to add the OnMovementFailed lines to every reaction that contains movement (not much work for combat, but a lot of work for all NPCs of Main!).

So my idea was to move the character as close to the target as possible first. Since characters don't move at all when all paths are blocked, we don't know where we have to search for items. So I calculate a position half on the way to the target (slightly randomized, in case there's a wall or something) and let the character move there. If the movement fails the character will check for items he is facing (close to himself or close to the temporary target position) and move them, otherwise he will check for an even closer position and try to move there. He will ignore all items with weight less than 1000 and more than 40000 (I haven't checked all item weights yet, maybe there are a few that can block the path and are lighter than 1000/heavier than 40000). Maybe there will be conflicts with immobile items. In this case I will have to add more conditions. There could also be a problem with situations in which a character's movement fails for other reasons than items (don't know if this case exists).
But all in all I'm quite happy about how it works already.

Now, I hope it works for you and would be glad about your feedback!


My mods for DOS 1 EE: FasterAnimations - QuietDay - Samaritan