The Icemark was indeed a changed place

An interesting thing came from fixing the battle code in Doomdark’s Revenge, it highlighted a bug that is in the original code, that I can’t tell if ever caused an outward problem.

It is all to do with loyalty.

Loyalty in DDR is about race. Which race are you loyal to: Giants, Dwarves, Hearstealer, Moonprince… etc. When a lord recruits another lord, they become their liege and the new vassal becomes loyal to the same loyalty race.

When a AI lord moves in to a location, they check the loyalty of any lords present and if there is a difference in loyalty, they may attempt to recruit.

The problem is – if a lord who has vassals is recruited the loyalty of the vassals does not change, but the loyalty of the lord does. The liege of the vassals does not change either. So these lords have a liege of a lord who is not loyal to the same race as them. And they will potentially attempt to follow them or follow the same instructions. Even though they are technically the enemy.

Should the vassals ever find themselves in the same location as their liege, they are no longer the same loyalty so they will attempt to recruit them. In this instance the, the vassals becomes the liege of their liege, but their own liege does not change. Confused yet?

What we have here, is circular lieges.

Example:

Glormeon the Giant’s liege is Imagrorn the Giant, and Imagrorn’s liege is Varagrim. But let’s say Imagrorn is recruited by Carormand the Barbarian, then Imagorn’s liege is now Carormand, and his loyalty is to the Barbarians. But Glormeon’s liege is still Imagrorn, however his loyalty is still to the Giants.

The first problem here is that these two lords now see themselves as enemies or potential recruits. So they could fight or recruit. But also Glormeon will follow orders of Imagrorn even though they are enemies. Which may be tracking him down or following his enemies, or liege… and should Glormeon enter a location with Imagrorn he may attempt to recruit them. If this is successful then Glormeon’s liege would be Imagrorn and Imagrorn’s liege would be Glormeon.

In the original this situation would occur. Which I think really just messes with the AI. But in the remake, I traverse the liege tree to work out who is the overall lord in charge, and if we have a circular liege then the game crashes!

So the question is – how to fix.

So I remove the liege traversal and allow the original messy AI or do I break the liege link as soon as recruitment happens… ie: When Imagrorn is recruited and his liege changes to Carormand, then Glormeon’s new liege becomes Varagrim. Or should Glormeon remain loyal to Imagrorn and change his race loyalty to the Barbarians?

As a bug fix the first seems the quickest and keeps the gameplay the same. The other two options the potentially becomes gameplay rules.

This also doesn’t take in to account that the human player, ultimately The Moonprince, may be the loyalty race of some of these lords.

I am tracking the bug here on the GitHub repos for anyone interested.

Many battles fought again by tongue

Strange day today. Not just because it would have been Mike’s birthday, but because for some reason I found myself fixing a bug in Doomdark’s Revenge. Back in January I had a bug reported to me by Simon Foston, I managed to get some save games from him and just needed to find some time to look at it. Now, it’s taken a little while for me to find that time, but for some reason I looked at it today. It wasn’t a conscious decision, I was just looking through some emails that needed dealing with and noticed Simon’s bug report.
A quick look through the code and with a tip off from Simon’s report, it became apparent that the ghosts of dead lords were continuing to take part in battles. I checked the original code and it looked as if the bug was there too, however, I then found that the isDead check was happening later in the process. Strangely what it means is that battles at a dead lords location are processed as part of a dead characters turn, and not as part of other characters in the location. In my case, I’d missed the later isDead check and therefore the dead lord actually took part in the battle.

 

So, it seemed strange to be working on a bug in Doomdark’s Revenge that included the dearly departed, today of all days. I’m sure Mike had a wry smile..

We must find friends as well as enemies…

A new bug came to light in Doomdark’s Revenge. I had a report of a crash bug that occurs after 138 days, that’s one hundred, one score, and eighteen days since the Moonprince rode forth into the Icemark.

The problem appeared to be that an AI character’s liege was getting set to himself. This causes a problem in the AI logic for a character choosing to follow their liege. The AI goes something like this…

I want to follow my liege, but my liege is dead, so I need to follow my liege’s liege and this character will become my new liege. The code ripples up the liege tree until it finds someone to follow, or bails and decides to hunt down Luxor instead. When the bug occurs it follows the tree and finds a liege who is dead but they are also their own liege, and thus we get stuck in an infinite loop.

Once I found this as the source of the crash, I needed to work out WHY it occurs.

There are only two places where the liege can change, the aforementioned follow liege routine, and being recruited.

I stuck some debug info on both cases and set the game to run on automatic to see if the issue triggered, and it did.

Here is the scenario…

Anvarorn starts with Fangrorn being his liege. Fangrorn’s liege is Shareth. Fangrorn gets recruited by Anvortheon the Barbarian, and thus his loyalty changes to the barbarians, and his new liege becomes Anvortheon. Anvarorn decides to follow his Liege, who is still Fangrorn. When he gets to the same location as him he notices that they are not the same loyalty and thus tries to recruit him. He succeeds. Thus Fangrorn’s liege becomes Anvarorn. So we now have a circular liege issue. This becomes a problem if Fangrorn dies, because in this instance Anvarorn decides to follow his liege, finds that his liege is dead so takes his liege’s liege as his new liege and therefore becomes his own liege!

I went back and checked the original code, and this issue can happen. The only place you would notice it would be on one of the description screens where it would say, Anvarorn’s liege is Anvarorn – or words to that affect. At worst the character would end up following themselves and end up not moving. This is something that has been mentioned as possibly happening in the current version.

When I implemented the liege tree walk, I did just that, I implemented it as a walk up the tree, and because of the circular issue, a dead lord who is their own liege will create a circular loop if they are someone else’s liege. The original code doesn’t do that, it only takes the next liege up the stack and therefore slowly makes its way up the liege tree over a number of nights. Thus no infinite loop.

This would possibly occur with characters following their foe. If their foe is dead it walks the liege tree of the foe to find the next foe.

Fix to follow soon…