Discussion General Issue with coding Lords

Users who are viewing this thread

I have encountered an interesting issue while coding lords. I'm not sure if its a bug or not but it definitely worth raising to your attention.

XML:
<Heroes>
  <Hero id="lord_ala_sac_2_1" is_noble="true" spouse="Hero.lord_ala_sac_2_2" faction="Faction.clan_ala_sac" />
  <Hero id="lord_ala_sac_2_2" is_noble="true" alive="false" spouse="Hero.lord_ala_sac_2_1" faction="Faction.clan_ala_sac" />
  <Hero id="lord_ala_sac_2_3" is_noble="true" father="Hero.lord_ala_sac_2_1" mother="Hero.lord_ala_sac_2_2" faction="Faction.clan_ala_sac" />
</Heroes>
If i have the code set up like this so that the spouse is dead, it causes the game to create new heroes (I know it sounds weird but it happens).
(The last three Heroes in the pictures have been added by the game
VSfqEXN.png

rtwrOWz.png
And this causes a reflection error as it for some reason tries to re add the heroes. If I remove the
XML:
Alive="false"
part from the code the error stops affecting the game. I don't know if this is something that you guys are aware of or if its something that needs fixing either way I'm making sure your aware of it.
 
I'm working with OP on this as well. Have setup a logging patch on the vanilla method that was throwing, like so, and the logs follow.

C#:
[HarmonyPatch(typeof(AgingCampaignBehavior), "InitializeHeroesYoungerThanHeroComesOfAge")]
public class AgingCampaignBehaviorInitializeHeroesYoungerThanHeroComesOfAgePatch
{
    public static void Prefix(Dictionary<Hero, int> ____heroesYoungerThanHeroComesOfAge)
    {
        foreach (Hero key in Hero.All)
        {
            if (key.IsAlive)
            {
                int age = (int) key.Age;
                if (age < Campaign.Current.Models.AgeModel.HeroComesOfAge)
                {
                    if (____heroesYoungerThanHeroComesOfAge.ContainsKey(key))
                    {
                        FileLog.Log($"Duplicate - {key.Name}.");
                    }
                    else
                    {
                        FileLog.Log($"Add - {key.Name}.");
                    }
                }
            }
        }
    }
}

With the spouse set to alive, this output:
Add - Maurentios.
Add - Lucala.
Add - Jephalia.
Add - Megarita.
Add - Casyrea.
Add - Colambea.
Add - Helea.
Add - Anea.
Add - Nonesos.
Add - Gordiana.
Add - Callinia.
Add - Synesios.
Add - Rustica.
Add - Comatasa.
Add - Elidilea.
Add - Dorathila.
Add - Luda.
Add - Teta.
Add - Valla.
Add - Vizhduna.
Add - Velina.
Add - Razana.
Add - Azina.
Add - Bushila.
Add - Sanit.
Add - Jalfar.
Add - Zanuwa.
Add - Hajara.
Add - Merag.
Add - Beasag.
Add - Diarbhain.
Add - Gawen.
Add - Yesum.
Add - Mark Hayward.
Add - Volikn Hayward.

When set to dead (alive=false)
Add - Maurentios.
Add - Lucala.
Add - Jephalia.
Add - Megarita.
Add - Casyrea.
Add - Colambea.
Add - Helea.
Add - Anea.
Add - Nonesos.
Add - Gordiana.
Add - Callinia.
Add - Synesios.
Add - Rustica.
Add - Comatasa.
Add - Elidilea.
Add - Dorathila.
Add - Luda.
Add - Teta.
Add - Valla.
Add - Vizhduna.
Add - Velina.
Add - Razana.
Add - Azina.
Add - Bushila.
Add - Sanit.
Add - Jalfar.
Add - Zanuwa.
Add - Hajara.
Add - Irmgard.
Add - Merag.
Add - Beasag.
Add - Diarbhain.
Add - Gawen.
Add - Yesum.
Add - Mark Hayward.
Add - Volikn Hayward.
Duplicate - Delilah.
Duplicate - Astrid.

My amateur code analysis failed to identify any point where these Hero are being added, since they aren't in the family definitions they appear to be dynamically created.

Stumped.
 
Back
Top Bottom