Changing Policy Influence Effects

Users who are viewing this thread

I'm trying to make a mod to change how much influence is given from Council of Commons to be multiplied by a factor of .2 to help out with late-game influence inflation and bring that policy more in line with other influence gains. I've found the relevant section that handles influence change due to policies under Sandbox.GameComponents DefaultClanPoliticsModel class. I inherited from the class with my own sub-module myPolicies to override CalculateInfluenceChange. I also copied the private static TextObjects that are occasionally used through CalculateInfluenceChange.

However, when I try to run the game with my sub-module edits, the game crashes on startup due to NullReferences from the TextObjects. I tried simply replacing the whole Default Model and also inheriting and overriding the override within the default model but it still crashes. Seems like the game is trying to load my sub-module before campaign start and failing to find those TextObject strings. Any ideas on how to fix this?
 
I have no idea if this makes any sense, but I read in some comments about another mod loading before the native modules... I believe the solution was to add the native modules as dependencies so your mod would load only after those.

I know zip about modding this game so take what I say with a grain of salt :wink:
 
Upvote 0
So long as your SubModule.xml has this, you should be okay on a module load order front. Your module depends on Sandbox, and Sandbox depends on Native and SandboxCore, so the dependency tree should shake out to put your module behind all 3 of them.

XML:
<DependedModules>
    <DependedModule Id="Sandbox"/>
</DependedModules>

I got NullReference errors on launch at first when I was trying to launch from commandline with an improperly structured module. So let's rule that out. Your mod structure follows this pattern, yes?

Code:
- Installation Folder
  - Modules
    - MyModule
      - bin
        - Win64_Shipping_Client
          - MyModule.dll
      - SubModule.xml
 
Upvote 0
I'm trying to make a mod to change how much influence is given from Council of Commons to be multiplied by a factor of .2 to help out with late-game influence inflation and bring that policy more in line with other influence gains. I've found the relevant section that handles influence change due to policies under Sandbox.GameComponents DefaultClanPoliticsModel class. I inherited from the class with my own sub-module myPolicies to override CalculateInfluenceChange. I also copied the private static TextObjects that are occasionally used through CalculateInfluenceChange.

However, when I try to run the game with my sub-module edits, the game crashes on startup due to NullReferences from the TextObjects. I tried simply replacing the whole Default Model and also inheriting and overriding the override within the default model but it still crashes. Seems like the game is trying to load my sub-module before campaign start and failing to find those TextObject strings. Any ideas on how to fix this?

I ran into the same problem when I tried to patch the DefaultFoodChangeModel object with Harmony. Basically, the problem is caused by the DefaultClanPoliticsModel's type initializer which throws an exception. Doing the pathcing in OnGameStart instead of OnSubModuleLoad fixed it for me. Either the model object isn't ready yet or the stuff it utilizes when initializing isn't ready. I suspect the latter. If you want to try patching, make sure you only patch once though by checking some static bool or something because a game can be started more than once.

Instead of inheriting a whole model class and basically copy-pasting a method to change a few lines in it, you can modify them with Harmony like this. This code basically makes the "Propose to give this settlement to other clan" decion's influence cost 0 if the settlement belongs to the player.

Code:
[HarmonyPatch(typeof(KingdomSettlementVM))]
[HarmonyPatch("AnnexCost", MethodType.Setter)]
public class KingdomAnexationCostPatch
{
    static void Prefix(KingdomSettlementItemVM ____currentSelectedSettlement, ref int value)
    {
        if (____currentSelectedSettlement != null &&
            ____currentSelectedSettlement.Settlement.OwnerClan == Clan.PlayerClan)
        {
            value = 0;
        }
    }
}

In your case, you can try patching CalculateInfluenceChangeInternal and removing 0.8 * <notable_count> from the result if this policy is enabled. I may post a code for it later.
 
Last edited:
Upvote 0
Back
Top Bottom