예제 #1
0
            public override float GetScoreOfClanToLeaveKingdom(Clan clan, Kingdom kingdom)
            {
                var numClanHeroes = clan.CommanderHeroes.Count;

                if ((kingdom.RulingClan == clan) ||
                    (numClanHeroes == 0))
                {
                    return(-1E+08f);
                }

                // Start with a basis of 0.
                var valueProposition = 0.0f;

                if (!clan.IsMinorFaction)
                {
                    // Apply a penalty for losing the possibility of getting slices of pie in the kingdom.
                    // This also reflects on the kingdom's success at war as a reflection of how likely it is
                    // the pie will increase or decrease.
                    var warMult = GetWarMultForClan(clan, kingdom);
                    var existingHeroesInKingdom      = GetNumberOfHeroesInKingdom(kingdom);
                    var hypotheticalValuePerClanHero = GetValueOfKingdomFortifications(kingdom) / (existingHeroesInKingdom + numClanHeroes);
                    valueProposition -= hypotheticalValuePerClanHero * (float)Math.Sqrt(numClanHeroes) * 0.300000011920929f * warMult;
                }

                // Apply a penalty ~ the number of towns and honor of the lord.
                var reliabilityConstant = HeroHelper.CalculateReliabilityConstant(clan.Leader);
                var townMult            = 40000f + clan.Fortifications.Count * 20000f;

                valueProposition -= townMult * reliabilityConstant;

                // Apply a penalty ~ the strength of the clan and honor of the lord.
                var clanStrength = GetClanStrength(clan, numClanHeroes);

                valueProposition -= clanStrength * reliabilityConstant;

                // Apply a penalty ~ how recently the clan has swapped kingdoms.
                const float maxDaysForPenalty    = 365;
                var         timeRemainingPenalty = (maxDaysForPenalty - Math.Min(maxDaysForPenalty, (float)(CampaignTime.Now - clan.LastFactionChangeTime).ToDays)) / maxDaysForPenalty;
                var         kingdomSwapPenalty   = 100000f * reliabilityConstant * timeRemainingPenalty;

                valueProposition -= kingdomSwapPenalty;

                // Increase the value for happier relations.
                var relationMult = GetRelationMult(clan, kingdom);

                valueProposition *= relationMult;

                // Increase the value for the same culture.
                var sameCultureMult = GetSameCultureMult(clan, kingdom);

                valueProposition *= sameCultureMult;

                // Add the expected change in settlement value.
                var expectedChangeInSettlementValue = clan.CalculateSettlementValue() - clan.CalculateSettlementValue(clan.Kingdom);

                valueProposition += expectedChangeInSettlementValue;

                return(valueProposition);
            }
예제 #2
0
            public override float GetScoreOfKingdomToGetClan(Kingdom kingdom, Clan clan)
            {
                var numClanHeroes           = clan.CommanderHeroes.Count;
                var existingHeroesInKingdom = GetNumberOfHeroesInKingdom(kingdom);

                if ((numClanHeroes == 0) ||
                    (existingHeroesInKingdom == 0))
                {
                    return(-1E+08f);
                }

                // Start with a basis of 0.
                var valueProposition = 0.0f;

                // Add value for the settlements the clan will bring to the kingdom, and the adjusted clan strength.
                // Adjusted clan strength is the clan strength ~ how badly the kingdom needs allies.
                var clanStrength        = GetClanStrength(clan, numClanHeroes);
                var powerRatioToEnemies = FactionHelper.GetPowerRatioToEnemies(kingdom);
                var howBadlyDoesThisKingdomNeedSupport = 1f / Clamp(powerRatioToEnemies > 1 ? (float)Math.Sqrt(powerRatioToEnemies) : powerRatioToEnemies, 0.1f, 2.5f);
                var adjustedClanStrength = clanStrength * howBadlyDoesThisKingdomNeedSupport;

                valueProposition += clan.CalculateSettlementValue(kingdom) * 0.1f + adjustedClanStrength;

                // Increase the value for happier relations.
                var relationMult = Clamp(1.0f + 0.0199999995529652f * FactionManager.GetRelationBetweenClans(kingdom.RulingClan, clan), 0.33f, 2f);

                valueProposition *= relationMult;

                // Increase the value for the same culture.
                var sameCultureMult = (float)(1.0 + (kingdom.Culture == clan.Culture ? 1.0 : 0.0));

                valueProposition *= sameCultureMult;

                // Increase the value if the lord is known to be honorable.
                var reliabilityConstant = HeroHelper.CalculateReliabilityConstant(clan.Leader);

                valueProposition *= reliabilityConstant;

                return(valueProposition);
            }