Best Way to Make All Other Factions Hostile

Started by SickBoyWi, January 15, 2020, 01:16:21 PM

Previous topic - Next topic

SickBoyWi

I'm working on a mod using alien races (though that may or may not matter here), and I want all non player factions to be hostile to the player. I added a postfix to the Faction TryMakeInitialRelationsWith method, and it looks like this:

        private static void Faction_TryMakeInitialRelationsWith_PostFix(Faction __instance, Faction other)
        {
            Faction playerFaction = __instance;

            if (playerFaction.IsPlayer && !other.IsPlayer && (playerFaction.def.defName.Equals("RH_TET_Beastmen_BrayPlayerFaction")
                || playerFaction.def.defName.Equals("RH_TET_Beastmen_BeastmenPlayerFaction")))
            {
                int goodWillAmount = playerFaction.GoodwillWith(other);

                if (goodWillAmount > -100)
                {
                    // TODO make random, between 80 and 100?
                    int newGoodWillAmount = -100;
                   
                    other.RelationWith(playerFaction).goodwill = newGoodWillAmount;
                    other.RelationWith(playerFaction).kind = FactionRelationKind.Hostile;
                }
            }
        }


I've tried other things, like making this call in the postfix instead of setting values randomly:
playerFaction.TryAffectGoodwillWith(other, newGoodWillAmount, false, false);

That call throws an error because Faction.OfPlayer tosses an error due to the player faction not being set up yet.

The issue with my method is that when a raid happens from a faction that my postfix code has forced to be hostile, player pawns and 'enemy' pawns completely ignore each other. The enemy pawns look and act like enemies in every other way, but they walk right by/around player pawns, and go smash up the buildings and such. They pawns don't attack each other.

Any ideas are very welcome.

SickBoyWi

I found a fix that works. I needed to only have this happen for a specific player faction, not all of them. Here's the solution in case it helps anyone else. I added a prefix for the Faction TryMakeInitialRelationsWith function, removing the postfix I mentioned before.

        private static void Faction_TryMakeInitialRelationsWith_PreFix(Faction __instance, Faction other)
        {
            Faction playerFaction = __instance;

            if (playerFaction.IsPlayer && !other.IsPlayer && (playerFaction.def.defName.Equals("RH_TET_Beastmen_BrayPlayerFaction")
                || playerFaction.def.defName.Equals("RH_TET_Beastmen_BeastmenPlayerFaction")))
            {
                other.def.startingGoodwill = new IntRange(-100, -100);
            }
        }