UnofficialCrusaderPatch / UnofficialCrusaderPatch2

Unofficial balancing patch installer for Stronghold Crusader 1
MIT License
430 stars 59 forks source link

AI tearing down economy when using drawbridges #209

Open Monsterfisch opened 5 years ago

Monsterfisch commented 5 years ago

bump for the comment right here as the thread itself was super crowded https://github.com/Sh0wdown/UnofficialCrusaderPatch/issues/5#issuecomment-436734763

This happens especially when the AI is using drawbridges: Every time they are opened, the AI treats the drawbridge as moat and thinks that all the outer buildings are not accessible and deletes them. This only happens if there is no other exit and if there is moat left and right from the bridge. Best example frederick 1.aiv is effected by the bug while frederick 4.aiv isn't. When there are 2 drawbridges it usually doesn't happen because they don't open at the exact same moment (for example fredrick 2.aiv).

generally, I think this is pretty crucial as it cripples a lot of aivs like nizar frederik wolf etc. additional info the bug also happens when there is no mat next to the drawbridge aside from what is mentioned in the original comment. Overall this issue seems to hook into tearing down buildings when unreachable meaning if the gate is closed over a certain period of time while having no second exit it classifies every building outside the castle (the moat underneath the drawbridge counts towards enclosing the keep (which it "shouldn't"~~) making it so the AI thinks there is no access to the outer areas.

alt text

One reason in particular why it may only happen irregulary probably has to do with the fact that the drawbridgeanimation opens slower than than the actual portcullis and therefor makes the ai thinks that the area outside is still inaccessible while the drawbridge opens and the gate is already open since the time difference is not very large it is possible that due to the random/tick based checks? of the checking if accessible feature just tend to line up at some point.

So my guess/suggestion here would be to speed up the animation of the drawbridge or slow down the animation for the normal gate so they are open and closed at the same exact time, to try and fix it.

A different solution could be to pause the "tearing down when enclosed" feature during the time a gate of the castle are closed (i assume it already does it like that) and have it be paused a few more seconds after the gates are opened so that is includes the time drawbridges need to be fully opened.

PitchNeeded commented 5 years ago

Another drawbridge issue:

In one of Udwin's AI battle videos I noticed that an archer of Frederick kept standing on the drawbridge during a siege by Emir. This meant that the drawbridge didn't close and so Emir's Arabian swordsmen could cross the drawbridge and attack the gate.

Heroesflorian commented 5 years ago

In one of Udwin's AI battle videos I noticed that an archer of Frederick kept standing on the drawbridge during a siege by Emir. This meant that the drawbridge didn't close and so Emir's Arabian swordsmen could cross the drawbridge and attack the gate.

Regarding that, I also had some AI battles in the past where units didn't just stand on a drawbridge with closed gate temporarily, but actually got stuck on drawbridges. In particular, units can get stuck on one of the corner tiles of the drawbridge, as those are accessible/traversable when the drawbridge is open - but they are inaccessible (like rocks) when the drawbridge is closed. So if units happen to enter one of the corner tiles right then the drawbridge starts lifting (switching corner accessibility state), they are trapped there (and usually stay there "forever" / until they die afterwards, even when the drawbridge opens and closed again later).

I actually wouldn't be surprised if the state switch of those corner tiles between accessible and inaccessible was also the reason for (or at least related to) the "demolish all pseudo-unreachable buildings" bug.

Heroesflorian commented 5 years ago

Re the "unclosable drawbridges with units stuck on them"-issue...

image

... I proudly present to you the true, one and only evil chicken!

Monsterfisch commented 5 years ago

probably a good idea to make a new post for the locked drawbridge issue you know to keep it organized;)

Heroesflorian commented 5 years ago

Yep... https://github.com/Sh0wdown/UnofficialCrusaderPatch/issues/212

@Monsterfisch / @Sh0wdown Also, I wonder if the "Connect" and "Path Linkage" views could be useful in order to narrow down the why and how of the bug that this issue here is about (i.e. AI deleting all buildings outside)? Outside the editor, they cannot be toggled, but when having them active when leaving the editor, they will remain active even in a started or loaded game until toggled off in the editor. Oh, and in case you wonder how this is toggled at all, just press "Alt + D" in the map editor to switch between those two and the normal view. In case you wonder what the heck those views actually display... one shows tiles with colors and numbers corresponding to the pathfinding-connected area they belong to, and the other one shows borders, and thus indicates how units can pass from one map tile to another straight/diagonally adjacent tile.

Overall this issue seems to hook into tearing down buildings when unreachable meaning if the gate is closed over a certain period of time while having no second exit

And btw, I just had the bug occur once more in a match where the drawbridge had been closed only for a couple seconds (minimum close duration with patch) as a single hostile unit had passed by just at the edge of the gate's "detection" range. And also in the past I have seen the bug appear frequently even for shortly closed gates/drawbridge, so I really doubt the duration for which the gate/drawbridge is closed does matter.


Some examples of the Connect / Path Linkage views: image image image Inaccessible tiles will not have a number/color on it and will display the regular tile content instead. Also, as you can see, for whatever reason "swamp with pitch" tiles are displayed regularly as well, even when accessible, and single-tile walkable areas do receive colors and numbers, but show no white overlay with borders.

Monsterfisch commented 5 years ago

The issue is not the amount of time a gate is closed but how quickly the gate itself and the drawbridge animate as the drawbridge takes longer than the portcullis itself. My guess here why the Bug doesn't always happen is the "randomness" that comes in play when the checks for "testing if enclosed" occur, i have to assume that they are not synchronized with the gate open/closing. When the bug happens my personal guess is that the checks happen between the gate being open (which stops enables the checks again, I would assume) and the drawbridge still lowering therefore creating the situation where the gate is open but the path to the other side is still closed off tricking the ai into thinking its locked in.

You can clearly observe the difference of the opening up of the path, being delayed for the drawbridge here gamespeed is 45 so shows that there is plenty of time for the checks to occur in the time passing alt text

GRhin commented 4 years ago

Is this issue resolved by "Deactivate demolishing for money" sub-option "If enclosed"?

Monsterfisch commented 4 years ago

I don't remember it being fixed with that option turned on but I can give it another test to make sure