Unofficialcrusaderpatch: Laddermen AI use.

Created on 16 Jan 2020  路  25Comments  路  Source: Sh0wdown/UnofficialCrusaderPatch

Hey guys

In my testing I unintentionally found out something that could potentially be useful and potentially fixed.

The AI IS capable of using laddermen properly if two conditions are met. The first makes sense, the second I have to believe was unintentional on Firefly's part.

1st) The walls the laddermen go up to MUST either be attached to the keep itself, or have a staircase attached which allows access to the Lord.
-This is because of pathfinding, plain and simple, the enemy must see a path to the enemy lord.
-The keep is seen as one way down off a wall and the stairs are obviously another.
-A gatehouse DOES NOT count as a pathway for the AI. So if your AIV's have a keep surrounded by walls that are only accessable by gatehouses, the AI will not send its MainATT Units nor its AttUnit2's to climb ladders, they will instead just try to bash the walls down.

2nd) Stupidly, if the AI who is attacking, like The Snake, HAS HIS OWN KEEP ENCLOSED, then he will not send his MainATTUnits nor his AttUnit2's to climb ladders, they will instead just try to bash the walls down.

In order to make The Snake use his units properly his own keep can't be enclosed, and all the AI's he is attacking must have staircases or attachment to the keep in order to send his units to climb them.

For someone like me, who created all my own AIV's I will be going back and putting staircases on all my castles for balance reasons now. So that AI's I create using laddermen actually use them.

One neat trick is to use the double drawbridge enclosed glitch (the one where you place two drawbridges facing each other, with access from the sides making the game think the keep is not enclosed, but when the drawbridges lift the keep gets enclosed) to design The Snake's castle's so that he can use laddermen.

The only other way AI units will climb a ladder is if units like Attunitengage are nearby and the enemy they see(they are in aggressive stance) is up a ladder on the wall or a tower.
OR
Units in the attackunitmain/attackunit2 finish breaking down a wall(usually because multiple units are hitting the same piece of wall) they also are in aggresive stance at this time and may choose to attack an enemy up a ladder on the wall.
OR
Units filling moats are out of moat to fill, also go into aggresive stance and may climb a ladder to attack units on the wall.

It would wonderful if you guys who know more about coding could find where this is and potentially correct it so that the attacking AI doesn't have to have an "open" keep in order to use laddermen properly.

AIV Castles bug

Most helpful comment

image
vs
image

Notice how in the second pic the enclosed symbol is on the minimap vs the first pic where the enclosed symbol is not there. This is the enclosed drawbridge glitch.

You can also do it with one drawbridge like so, it just looks dumber to me,
image

All 25 comments

Thanks for the in-dept analysis, the 2nd point is new to me. I know the 1st point is the same for the siege tower, do you know if this problem is also present for the siege tower?

And do you have a picture of the double drawbridge enclosed glitch? I can't wrap my head around your explanation.

This is phenomenal. The double drawbridge means drawbridges facing each other sideway, so the they are the only thing in between keep and outside world. I wonder if this also works with only one drawbridge sideways as a accessable drawbridge through the middle tile.
Also, what if there are units that cannot climb ladders in the main attack force: there are only specific units that can potentially climb ladders in the first place, as spearman, maceman and such, while swordsman for example should not be capable of climbing any ladder.

It crossed my mind to test siege towers as well. I just didn't have the time to last night, I'm gonna guess and say they are probably the same, but I'll test that aswell.

Also yes, only E.Archers, Spearmen, Macemen, Pikemen can climb ladders. If you have swordsmen as the AttMain they will bash the walls as normal.

And I will get a pic of the drawbridge glitch when I get home tonight for you if your not aware of it.

image
vs
image

Notice how in the second pic the enclosed symbol is on the minimap vs the first pic where the enclosed symbol is not there. This is the enclosed drawbridge glitch.

You can also do it with one drawbridge like so, it just looks dumber to me,
image

Regarding units not climbing laddermen, I have found the code part where it gets determined whether units should climb the laddermen or not, however, it is far more complex than I thought. Of course I could always force units to climb laddermen if they are available, but that made the melee units just not attack the walls at all and wait for laddermen to get in position at a distance.

Something is wrong with re-evaluating whether the AI has laddermen ready at walls or not, but I am close to solving this issue.

As far as I know, the problem is lies on two different parts:

  1. One is the pathfinding as Xebenkeck mentions: if there is no way to the keep, the units don't climb.

  2. Even if there is a path, the laddermen as part of the main force, attack the wall in the same time the melee units attack the wall. And while the main force is busy attacking the wall, they do not accept the path over the ladders, whereas if the walls are torn down, they immediately go for the lord. So really inconsistent behavior.

@LordHansCapon nice work, but here is the real issue:
pathfinding in Stronghold Crusader.
There are many wierd bugs related to that topic. I ll just list a few, maybe you came across those, when fixing the laddermen issue:

  • workers are forced on entrences, that rotate clockwise around buildings, if their original entrance is obscured. This is specifically an issue, if an entrance is not connected to the 'outside world'.
    -> it can happen, that for example the stockpile has one space next to it, which is optherwise not accessable. Then workers who want to access that stockpile dont work, as if the stockpile was empty, as the stockpile registers that as the default location to get goods from.
    proposal for solving that: force entrances to look for pathfidning to ressources on initial setup by checking all 'connected' buildings and the building itself for pathfiding. Each building here would have to be handled individually. Also when moats/walls are build next to a building, they should always update their entrance, and not only if a whole side is covered with wall, which makes the building turn btw, and the entrance gets moved to the complete opposite side of that wall. That makes the roof go diagonal from then on. -> so there is already some algorthm in place, which could be used for that purpose and modified.
    -> this is a huge change i guess, but it would solve most lag issues and most issues in general in the game related to pathfinding with workers, that get stuck.

  • pathfinding gets only updated if an obtacle is hit or the destination is reached. That makes workers get stuck or even disappear. Which is frustrating. Sometimes they even get stuck on low stairs, in front of gates that are open and stuff like that, and stay there until they get killed or some gate gets closed/opened to update their pathing.
    -> this should be fixable by giving workers either an update timer which checks for changed pathways every once in a while (could be heavy on the CPU side) or we could actually make some kind of path mapping system, where we would then map all paths that get taken currently, and if one gets updated, we would also update all paths that correlate with that path in the region that caused the update. I guess this is to difficult to implement? Or if it wasnt, it would take some work.

Now to the pathfinding and decision making of AI's:
The main issue for me is, that they just walk around walls and obstacles even if they would be faster destroying them.
-> to fix that, we would have to give Obstacles a different value than 'nonpathable' for units, as giving them some kind of HP value, which then can be used to solve the pathfinding equation.
We would solve the equation by simply checking if the destruction of set opstacles that obscures the way to the target destination would be faster than walking, and wollah, we just set the soldiers automatically into destruction mode and target that obstacle. They already have some kind of way to tell where the weakest point in an enemies castle is, in the case that there is no open pathway, which we could use here in the same way.

  • Next problem: If the enemies use gatehouses, units seem to not recognize open gates as 'nonpathable' objects, and aim to walk through them. This causes units to just walk around, and turning every time they reach a gate that gets closed before they can reach it.
    -> instead there should be 2 behaviours: 1. for assassins: they should see gates as climbable objects, that they should just aim to climb right away, when it gets closed. (some assassins are already handled seperatly, i just wish they wouldnt turn around when a gate gets closed and another pathway is still open.)
  • For normal soldiers, they should see gates as 'always closed' if they are not controlled by themselfs. So that they then evaluate them by their HP as destructable objects for pathfinding.

This is probably too difficult to work into assembler?
But i can keep my hopes :D
If you need any algorithmic help for these things or more inside knowledge about the pathfinding and its current expected behabviour, you can always ask me here or add me on discord to ask me directly. Discord: Krarilotus#6749

I find pathfinding exceptionally hard to modify, especially at the level you want. I think it is way too complex to make these changes in assembly.

But it is possible to setup a timer and update units and workers pathfinding regularly. Though I guess it would be a bit heavier on the CPU that's for sure.

@J-T-de That is exactly how the AI works. Can be easily seen in code aswell, as most of the stuff regarding pathfinding during siege is written pretty simply. However, its not the keep they are looking for as I found, its the King, if you wall in the king and leave your keep "exposed" while they have laddermen, they won't climb the laddermen as they have no path to the lord.

-The path-finding to the king/lord make sense. Why would a CPU tell its units to climb a wall where there is possibly no other way down, or doesn't directly lead to the lord. This one isn't as important to fix its the other issue.

-The one that doesn't make any sense is why their own keep(the attacker's) must be enclosed. If you have found a solution to that, then that alone makes the AI way better.

-I guess the other issue that would help is if you can get units to realize a closed gate is a pathway to the lord if you are on top of the wall because when they get onto the gatehouse they will take over it.

To be honest, I have never seen AI units climb walls, like ever. Not in vanilla, and not in UCP. Is it even working by default? Once I set some stuff in assembly, the units started to climb walls and all worked well, but I bet my head on it that I did not see AI units climb before.

@J-T-de That is exactly how the AI works. Can be easily seen in code aswell, as most of the stuff regarding pathfinding during siege is written pretty simply. However, its not the keep they are looking for as I found, its the King, if you wall in the king and leave your keep "exposed" while they have laddermen, they won't climb the laddermen as they have no path to the lord.

Yeah, it makes sense that the are looking for the lord...

To be honest, I have never seen AI units climb walls, like ever. Not in vanilla, and not in UCP. Is it even working by default? Once I set some stuff in assembly, the units started to climb walls and all worked well, but I bet my head on it that I did not see AI units climb before.

Well, only the snake uses laddermen, and if Xebenkeck is right with his new insight, i.e. "as soon as the keep is enclosed, no more using ladders", then there is a really low probability that one witnesses this.

Once I experimented with giving the pig siege towers. If I remember correctly, the maceman immediately used the siege tower if they had a path to the lord. Even though the keep of the pig was enclosed and the macemen were already attacking the walls (and damn, maceman yoloing on top of walls was mad!).

Alright, I have taken control over snake and demolished his gates and walls right before he was attacking, and I can confirm that if the Snake's keep is enclosed, then he will NOT use laddermen. So you were right, I am looking into it as why would this ever happen.

@Xebenkeck @J-T-de @Krarilotus I have found the issue and the solution regarding laddermen not climbing ladders when AI is enclosed. I will be adding it as a fix in my fork of UCP.

image

Fixed thanks to @LordHansCapon

I'll actually reopen this, as there might be more things that can be solved.

@ByBurton Yes, gatehouses SHOULD count as a pathway for the AI. Interestingly enough, the pathfinding DOES use gatehouses, but the function which determines whether there is a reason to climb the ladders does not. Now that I found the function which determines that, I may be able to add gatehouses checks.

image

@LordHansCapon That would be epic. I always loved laddermen. And spearmen are my all time favourite unit (the only unit that can kick ladders down). It would also enable an AI I made that focuses on laddermen, spearmen and archers.

@ByBurton Wow, Richard is in trouble.

this is epic :D

Should we make another issue for the pathfinding with open gates?
I feel like its seperate topic :)

so we will probably not be able to fix the issue, that AI's always take open pathways?
But could we fix the issue, that AI sees Gatehouses of enemies that are currently open but not under their control as a pathway into the enemy castle?

I ll pin a video demonstrating this issue here soon. One of the AI's in the last AI Contest i hosted abuses this issue alot, which makes its defense broken, while having not a single tower.

Awesome work.

The Snake and other created AI lords will be so much more potent now.

So for someone like me who doesn't know how to change the .exe, or add lines of code, I just have to wait for a official release witht his change for this to work for me right?

@ByBurton @LordHansCapon How to download a new patch ? Thank you!

@Lolasik011 Once @Sh0wdown creates a new release, you can download it, or you could just build the project yourself. Or maybe I could upload it somewhere and share the link. Because I can not upload it here, it is too big to share it.

@LordHansCapon Google drive ...

Working laddermen, finally after nearly 2 decades?! :O Noiice!

But could we fix the issue, that AI sees Gatehouses of enemies that are currently open but not under their control as a pathway into the enemy castle?

@Krarilotus Oh yeah... and this issue becomes even larger when moat/drawbridges are involved... you know, non-digging units run around half of the castle towards a drawbridge, drawbridge closes up, units stand there brainlessly until they're dead, drawbridge opens, more units start running towards it...

Can be closed with new release

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Ninjaa17 picture Ninjaa17  路  3Comments

PitchNeeded picture PitchNeeded  路  4Comments

Monsterfisch picture Monsterfisch  路  3Comments

Heroesflorian picture Heroesflorian  路  3Comments

Heroesflorian picture Heroesflorian  路  4Comments