public static float getDoNotReplenishGarrisonCorrectionMult( MobileParty mobileParty, Settlement settlement) { if (settlement.IsVillage || settlement.OwnerClan.Kingdom != mobileParty.LeaderHero.Clan.Kingdom) { return(1f); } float strengthPerWalledCenter = FactionHelper.FindIdealGarrisonStrengthPerWalledCenter(mobileParty.MapFaction as Kingdom); if (mobileParty.Army != null) { strengthPerWalledCenter *= 0.75f; } if (settlement.IsFortification && settlement.OwnerClan != Clan.PlayerClan) { float num1 = settlement.Town.GarrisonParty != null ? settlement.Town.GarrisonParty.Party.TotalStrength : 0.0f; float num2 = FactionHelper.OwnerClanEconomyEffectOnGarrisonSizeConstant(settlement.OwnerClan); float num3 = FactionHelper.SettlementProsperityEffectOnGarrisonSizeConstant(settlement); float num4 = FactionHelper.SettlementFoodPotentialEffectOnGarrisonSizeConstant(settlement); float num5 = strengthPerWalledCenter * num2 * num3 * num4; if ((double)num1 < (double)num5) { return((float)(1.0 / (1.0 + Math.Pow(1.0 - (double)num1 / (double)num5, 3.0) * 99.0))); } } return(1f); }
public override int FindNumberOfTroopsToLeaveToGarrison(MobileParty mobileParty, Settlement settlement) { if (SettlementGarrisonSetting.Instance.DisablePlayerClanLeaveTroopToGarrison && mobileParty.LeaderHero != null && mobileParty.LeaderHero.Clan == Clan.PlayerClan) { return(0); } MobileParty garrisonParty = settlement.Town.GarrisonParty; float num = 0f; if (garrisonParty != null) { num = garrisonParty.Party.TotalStrength; } float num2 = FactionHelper.FindIdealGarrisonStrengthPerWalledCenter(mobileParty.MapFaction as Kingdom, settlement.OwnerClan); float num3 = FactionHelper.OwnerClanEconomyEffectOnGarrisonSizeConstant(settlement.OwnerClan); float num4 = FactionHelper.SettlementProsperityEffectOnGarrisonSizeConstant(settlement); num2 *= num3; num2 *= num4; if ((settlement.OwnerClan.Leader != Hero.MainHero || (mobileParty.LeaderHero != null && mobileParty.LeaderHero.Clan == Clan.PlayerClan)) && num < num2) { int numberOfRegularMembers = mobileParty.Party.NumberOfRegularMembers; float num5 = 1f + (float)mobileParty.Party.NumberOfWoundedRegularMembers / (float)mobileParty.Party.NumberOfRegularMembers; float num6 = (float)mobileParty.Party.PartySizeLimit * mobileParty.PaymentRatio; float num7 = (float)(Math.Pow((double)Math.Min(2f, (float)numberOfRegularMembers / num6), 1.2000000476837158) * 0.75); float num8 = (1f - num / num2) * (1f - num / num2); if (mobileParty.Army != null) { num8 = Math.Min(num8, 0.5f); } float num9 = 0.5f; if (settlement.OwnerClan == mobileParty.Leader.HeroObject.Clan || settlement.OwnerClan == mobileParty.Party.Owner.MapFaction.Leader.Clan) { num9 = 1f; } float num10 = (mobileParty.Army != null) ? 1.25f : 1f; float num11 = 1f; List <float> list = new List <float>(5); for (int i = 0; i < 5; i++) { list.Add(Campaign.MapDiagonal * Campaign.MapDiagonal); } foreach (Kingdom kingdom in Kingdom.All) { if (kingdom.IsKingdomFaction && mobileParty.MapFaction.IsAtWarWith(kingdom)) { foreach (Settlement settlement2 in kingdom.Settlements) { float num12 = settlement2.Position2D.DistanceSquared(mobileParty.Position2D); for (int j = 0; j < 5; j++) { if (num12 < list[j]) { for (int k = 4; k >= j + 1; k--) { list[k] = list[k - 1]; } list[j] = num12; break; } } } } } float num13 = 0f; for (int l = 0; l < 5; l++) { num13 += (float)Math.Sqrt((double)list[l]); } num13 /= 5f; float num14 = Math.Max(0f, Math.Min(Campaign.MapDiagonal / 15f - Campaign.MapDiagonal / 30f, num13 - Campaign.MapDiagonal / 30f)); float num15 = Campaign.MapDiagonal / 15f - Campaign.MapDiagonal / 30f; float num16 = num14 / num15; float num17 = Math.Min(0.7f, num11 * num7 * num8 * num9 * num10 * num5); return(MBRandom.RoundRandomized((float)numberOfRegularMembers * num17)); } return(0); }