Example #1
0
        public override int FindNumberOfTroopsToTakeFromGarrison(MobileParty mobileParty, Settlement settlement, float defaultIdealGarrisonStrengthPerWalledCenter = 0f)
        {
            MobileParty garrisonParty = settlement.Town.GarrisonParty;

            if (garrisonParty != null)
            {
                float totalStrength = garrisonParty.Party.TotalStrength;
                float num           = (defaultIdealGarrisonStrengthPerWalledCenter > 0.1f) ? defaultIdealGarrisonStrengthPerWalledCenter : FactionHelper.FindIdealGarrisonStrengthPerWalledCenter(mobileParty.MapFaction as Kingdom, settlement.OwnerClan);
                float num2          = FactionHelper.OwnerClanEconomyEffectOnGarrisonSizeConstant(settlement.OwnerClan);
                num *= num2;
                num *= (settlement.IsTown ? 2f : 1f);
                float num3 = (float)mobileParty.Party.PartySizeLimit * mobileParty.PaymentRatio;
                int   numberOfAllMembers = mobileParty.Party.NumberOfAllMembers;
                float num4 = num3 / (float)numberOfAllMembers;
                float num5 = (float)Math.Min(11.0, (double)num4 * Math.Sqrt((double)num4)) - 1f;
                float num6 = (float)Math.Pow((double)(totalStrength / num), 1.5);
                float num7 = (mobileParty.LeaderHero.Clan.Leader == mobileParty.LeaderHero) ? 2f : 1f;
                int   num8 = MBRandom.RoundRandomized(num5 * num6 * num7);
                int   num9 = 25;
                num9 *= (settlement.IsTown ? 2 : 1);
                if (num8 > garrisonParty.Party.MemberRoster.TotalRegulars - num9)
                {
                    num8 = garrisonParty.Party.MemberRoster.TotalRegulars - num9;
                }
                return(num8);
            }
            return(0);
        }
        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);
        }
Example #3
0
        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);
        }
        public override int FindNumberOfTroopsToTakeFromGarrison(
            MobileParty mobileParty,
            Settlement settlement,
            float defaultIdealGarrisonStrengthPerWalledCenter = 0.0f)
        {
            MobileParty garrisonParty = settlement.Town.GarrisonParty;

            if (garrisonParty == null)
            {
                return(0);
            }
            float  totalStrength = garrisonParty.Party.TotalStrength;
            float  num1          = ((double)defaultIdealGarrisonStrengthPerWalledCenter > 0.100000001490116 ? defaultIdealGarrisonStrengthPerWalledCenter : FactionHelper.FindIdealGarrisonStrengthPerWalledCenter(mobileParty.MapFaction as Kingdom, settlement.OwnerClan)) * FactionHelper.OwnerClanEconomyEffectOnGarrisonSizeConstant(settlement.OwnerClan) * (settlement.IsTown ? 2f : 1f);
            float  num2          = (float)mobileParty.Party.PartySizeLimit * mobileParty.PaymentRatio / (float)mobileParty.Party.NumberOfAllMembers;
            double num3          = Math.Min(11.0, (double)num2 * Math.Sqrt((double)num2)) - 1.0;
            float  num4          = (float)Math.Pow((double)totalStrength / (double)num1, 1.5);
            float  num5          = mobileParty.LeaderHero.Clan.Leader == mobileParty.LeaderHero ? 2f : 1f;
            double num6          = (double)num4;
            int    num7          = MBRandom.RoundRandomized((float)(num3 * num6) * num5);
            int    num8          = 25 * (settlement.IsTown ? 2 : 1);

            if (num7 > garrisonParty.Party.MemberRoster.TotalRegulars - num8)
            {
                num7 = garrisonParty.Party.MemberRoster.TotalRegulars - num8;
            }
            return(num7);
        }
        public override int FindNumberOfTroopsToLeaveToGarrison(
            MobileParty mobileParty,
            Settlement settlement)
        {
            MobileParty garrisonParty = settlement.Town.GarrisonParty;
            float       num1          = 0.0f;

            if (garrisonParty != null)
            {
                num1 = garrisonParty.Party.TotalStrength;
            }
            float num2 = FactionHelper.FindIdealGarrisonStrengthPerWalledCenter(mobileParty.MapFaction as Kingdom, settlement.OwnerClan) * FactionHelper.OwnerClanEconomyEffectOnGarrisonSizeConstant(settlement.OwnerClan) * (settlement.IsTown ? 2f : 1f);

            if (settlement.OwnerClan.Leader == Hero.MainHero && (mobileParty.LeaderHero == null || mobileParty.LeaderHero.Clan != Clan.PlayerClan) || (double)num1 >= (double)num2)
            {
                return(0);
            }
            int   ofRegularMembers = mobileParty.Party.NumberOfRegularMembers;
            float num3             = (float)(1.0 + (double)mobileParty.Party.NumberOfWoundedRegularMembers / (double)mobileParty.Party.NumberOfRegularMembers);
            float num4             = (float)mobileParty.Party.PartySizeLimit * mobileParty.PaymentRatio;
            float num5             = (float)(Math.Pow((double)Math.Min(2f, (float)ofRegularMembers / num4), 1.20000004768372) * 0.75);
            float val1             = (float)((1.0 - (double)num1 / (double)num2) * (1.0 - (double)num1 / (double)num2));

            if (mobileParty.Army != null)
            {
                val1 = Math.Min(val1, 0.5f);
            }
            float num6 = 0.5f;

            if (settlement.OwnerClan == mobileParty.Leader.HeroObject.Clan || settlement.OwnerClan == mobileParty.Party.Owner.MapFaction.Leader.Clan)
            {
                num6 = 1f;
            }
            float        num7      = mobileParty.Army != null ? 1.25f : 1f;
            float        num8      = 1f;
            List <float> floatList = new List <float>(5);

            for (int index = 0; index < 5; ++index)
            {
                floatList.Add(Campaign.MapDiagonal * Campaign.MapDiagonal);
            }
            foreach (Kingdom kingdom in Kingdom.All)
            {
                if (kingdom.IsKingdomFaction && mobileParty.MapFaction.IsAtWarWith((IFaction)kingdom))
                {
                    foreach (Settlement settlement1 in kingdom.Settlements)
                    {
                        float num9 = settlement1.Position2D.DistanceSquared(mobileParty.Position2D);
                        for (int index1 = 0; index1 < 5; ++index1)
                        {
                            if ((double)num9 < (double)floatList[index1])
                            {
                                for (int index2 = 4; index2 >= index1 + 1; --index2)
                                {
                                    floatList[index2] = floatList[index2 - 1];
                                }
                                floatList[index1] = num9;
                                break;
                            }
                        }
                    }
                }
            }
            float num10 = 0.0f;

            for (int index = 0; index < 5; ++index)
            {
                num10 += (float)Math.Sqrt((double)floatList[index]);
            }
            float  num11 = num10 / 5f;
            double num12 = (double)Math.Max(0.0f, Math.Min((float)((double)Campaign.MapDiagonal / 15.0 - (double)Campaign.MapDiagonal / 30.0), num11 - Campaign.MapDiagonal / 30f)) / ((double)Campaign.MapDiagonal / 15.0 - (double)Campaign.MapDiagonal / 30.0);
            float  num13 = Math.Min(0.7f, num8 * num5 * val1 * num6 * num7 * num3);

            return(MBRandom.RoundRandomized((float)ofRegularMembers * num13));
        }
        public override int FindNumberOfTroopsToLeaveToGarrison(MobileParty mobileParty, Settlement settlement)
        {
            MobileParty garrisonParty    = settlement.Town.GarrisonParty;
            float       garrisonStrength = 0f;

            if (garrisonParty is not null)
            {
                garrisonStrength = garrisonParty.Party.TotalStrength;
            }
            float num2 = FactionHelper.FindIdealGarrisonStrengthPerWalledCenter(mobileParty.MapFaction as Kingdom, settlement.OwnerClan) * FactionHelper.OwnerClanEconomyEffectOnGarrisonSizeConstant(settlement.OwnerClan) * (settlement.IsTown ? 2f : 1f);
            int   result;

            if ((settlement.OwnerClan.Leader == Hero.MainHero && (mobileParty.LeaderHero == null || mobileParty.LeaderHero.Clan != Clan.PlayerClan)) || (double)garrisonStrength >= (double)num2)
            {
                result = 0;
            }
            else
            {
                int   numberOfRegularMembers = mobileParty.Party.NumberOfRegularMembers;
                float woundedRatio           = (float)(1.0 + (double)mobileParty.Party.NumberOfWoundedRegularMembers / (double)mobileParty.Party.NumberOfRegularMembers);
                float num4  = (float)mobileParty.Party.PartySizeLimit * mobileParty.PaymentRatio;
                float num5  = (float)(Math.Pow((double)Math.Min(2f, (float)numberOfRegularMembers / num4), 1.20000004768372) * 0.75);
                float num6  = (float)((1.0 - (double)garrisonStrength / (double)num2) * (1.0 - (double)garrisonStrength / (double)num2));
                bool  flag3 = mobileParty.Army != null;
                if (flag3)
                {
                    num6 = Math.Min(num6, 0.5f);
                }
                float num7  = 0.5f;
                bool  flag4 = settlement.OwnerClan == mobileParty.Leader.HeroObject.Clan || settlement.OwnerClan == mobileParty.Party.Owner.MapFaction.Leader.Clan;
                if (flag4)
                {
                    num7 = 1f;
                }
                float        num8 = (mobileParty.Army != null) ? 1.25f : 1f;
                float        num9 = 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)
                {
                    bool flag5 = kingdom.IsKingdomFaction && mobileParty.MapFaction.IsAtWarWith(kingdom);
                    if (flag5)
                    {
                        foreach (Settlement settlement2 in kingdom.Settlements)
                        {
                            float num10 = settlement2.Position2D.DistanceSquared(mobileParty.Position2D);
                            for (int j = 0; j < 5; j++)
                            {
                                bool flag6 = (double)num10 < (double)list[j];
                                if (flag6)
                                {
                                    for (int k = 4; k >= j + 1; k--)
                                    {
                                        list[k] = list[k - 1];
                                    }
                                    list[j] = num10;
                                    break;
                                }
                            }
                        }
                    }
                }
                float num11 = 0f;
                for (int l = 0; l < 5; l++)
                {
                    num11 += (float)Math.Sqrt((double)list[l]);
                }
                float  num12 = num11 / 5f;
                double num13 = (double)Math.Max(0f, Math.Min((float)((double)Campaign.MapDiagonal / 15.0 - (double)Campaign.MapDiagonal / 30.0), num12 - Campaign.MapDiagonal / 30f)) / ((double)Campaign.MapDiagonal / 15.0 - (double)Campaign.MapDiagonal / 30.0);
                float  num14 = Math.Min(0.7f, num9 * num5 * num6 * num7 * num8 * woundedRatio);
                result = MBRandom.RoundRandomized((float)numberOfRegularMembers * num14);
            }
            return(result);
        }