Need More Info Wrong information with regards to the actual support of kingdom policies

Users who are viewing this thread

Version number
1.0.3
Branch
Main
Modded/unmodded
Yes, I used mods.

Underuse2307

Summary:The percentage bar does not reflect the number of clans that support the policy
How to Reproduce: A quick look at the game source with dnspy confirms this
Have you used cheats and if so which:No
Scene Name (if related):
Media (Screenshots & Video):
Computer Specs:
OS:
GPU:
GPU Driver Version:
CPU:
RAM:
Motherboard:
Storage Device (HDD/SSD):
 
Hi,

Here is the decompiled source for the KingdomElection method Setup() that determines the likelihood for each decision outcome that is displayed in the UI:

private void Setup() { MBList<DecisionOutcome> initialCandidates = _decision.DetermineInitialCandidates().ToMBList(); _possibleOutcomes = _decision.NarrowDownCandidates(initialCandidates, 3); _supporters = _decision.DetermineSupporters().ToList(); _chooser = _decision.DetermineChooser(); _decision.DetermineSponsors(_possibleOutcomes); _hasPlayerVoted = false; IsCancelled = false; foreach (DecisionOutcome possibleOutcome in _possibleOutcomes) { possibleOutcome.InitialSupport = DetermineInitialSupport(possibleOutcome); } float num = _possibleOutcomes.Sum((DecisionOutcome x) => x.InitialSupport); foreach (DecisionOutcome possibleOutcome2 in _possibleOutcomes) { possibleOutcome2.Likelihood = ((num == 0f) ? 0f : (possibleOutcome2.InitialSupport / num)); } }

As you can see it loops through the decision outcomes (usually 2 for the relevant ones) and sums up the clan support weights. Then it looks at the percentage of those numbers for each outcome and sets it as the likelihood that is displayed in the UI.

The problem is, that's not actually how the voting plays out. A clan either supports a proposal or it doesn't, and whatever points may have been opposed when the clan actually supported the proposal mean nothing. What the percentage should display is the percentage of clans in the kingdom that actually support the proposal. In my mod called Kingdom Politics Expanded I have patched this issue with the following Harmony patch.

using HarmonyLib; using System.Collections.Generic; using TaleWorlds.CampaignSystem.Election; using TaleWorlds.Library; namespace KingdomPoliticsExpanded.Patches.KingdomElectionPatches { [HarmonyPatch(typeof(KingdomElection), "Setup")] internal class Setup { private static void Postfix(KingdomElection __instance) { MBList<DecisionOutcome> possibleOutcomes = (MBList<DecisionOutcome>)AccessTools.Field(__instance.GetType(), "_possibleOutcomes").GetValue(__instance); List<Supporter> supporters = (List<Supporter>)AccessTools.Field(__instance.GetType(), "_supporters").GetValue(__instance); KingdomDecision decision = (KingdomDecision)AccessTools.Field(__instance.GetType(), "_decision").GetValue(__instance); if (possibleOutcomes == null || supporters == null || decision == null || possibleOutcomes.Count < 1 || supporters.Count < 1) { return; } Dictionary<DecisionOutcome, float> clanSupport = new Dictionary<DecisionOutcome, float>(); foreach (Supporter s in supporters) { float highest = float.MinValue; DecisionOutcome highestOutcome = null; foreach (DecisionOutcome possibleOutcome in possibleOutcomes) { if (!clanSupport.ContainsKey(possibleOutcome)) { clanSupport.Add(possibleOutcome, 0); } float thisSupport = decision.DetermineSupport(s.Clan, possibleOutcome); if (thisSupport > highest) { highest = thisSupport; highestOutcome = possibleOutcome; } } clanSupport[highestOutcome] += 1f; } foreach (DecisionOutcome possibleOutcome2 in possibleOutcomes) { AccessTools.Property(possibleOutcome2.GetType(), "Likelihood").SetValue(possibleOutcome2, clanSupport[possibleOutcome2] / supporters.Count); } } } }
 
cY7C9nB.png


oewhfiA.png
 
Back
Top Bottom