Esempio n. 1
0
        protected override float GetAiWeight()
        {
            float  powerLossOfFormation = Mission.Current.GetMissionBehaviour <CasualtyHandler>().GetCasualtyPowerLossOfFormation(this.formation);
            double num = Math.Sqrt((double)powerLossOfFormation / ((double)this.formation.QuerySystem.FormationPower + (double)powerLossOfFormation));

            return(MBMath.ClampFloat(this.formation.Team.QuerySystem.PowerRatioIncludingCasualties, 0.1f, 3f) / MBMath.ClampFloat(this.formation.Team.QuerySystem.OverallPowerRatio, 0.1f, 3f) * (float)num);
        }
Esempio n. 2
0
        public static float CalculateBaseBlowMagnitudeForSwing(
            float angularSpeed,
            float weaponReach,
            float weaponWeight,
            float weaponInertia,
            float weaponCoM,
            float impactPoint,
            float exraLinearSpeed)
        {
            impactPoint = Math.Min(impactPoint, 0.93f);
            float num1 = MBMath.ClampFloat(0.4f / weaponReach, 0.0f, 1f);
            float num2 = 0.0f;

            for (int index = 0; index < 5; ++index)
            {
                float impactPointAsPercent = impactPoint + (float)index / 4f * num1;
                if ((double)impactPointAsPercent < 1.0)
                {
                    float magnitudeForSwing = CombatStatCalculator.CalculateStrikeMagnitudeForSwing(angularSpeed, impactPointAsPercent, weaponWeight, weaponReach, weaponInertia, weaponCoM, exraLinearSpeed);
                    if ((double)num2 < (double)magnitudeForSwing)
                    {
                        num2 = magnitudeForSwing;
                    }
                }
                else
                {
                    break;
                }
            }
            return(num2);
        }
        /// <summary>
        /// Change Weight
        /// </summary>
        /// <param name="weight"></param>
        /// <param name="hero"></param>
        private void ChangeWeight(Hero hero, int stage, float weight = 0.3f)
        {
            if (stage != 0)
            {
                weight = hero.Weight;
            }

            switch (stage)
            {
            case 1:
                weight = MBMath.ClampFloat(weight + 0.01f, 0.3f, 0.7f);
                break;

            case 2:
                weight = MBMath.ClampFloat(weight + 0.01f, 0.3f, 0.95f);
                break;

            case 3:
                weight = 1f;
                break;

            default:
                break;
            }

            hero.Weight = weight;
        }
Esempio n. 4
0
        private void AddWarExhaustion(Kingdom kingdom1, Kingdom kingdom2, float warExhaustionToAdd, WarExhaustionType warExhaustionType, bool addFuzziness = true)
        {
            string key = CreateKey(kingdom1, kingdom2);

            if (key != null)
            {
                float finalWarExhaustionDelta = warExhaustionToAdd;
                if (addFuzziness)
                {
                    finalWarExhaustionDelta *= Fuzziness;
                }
                if (_warExhaustionById.TryGetValue(key, out float currentValue))
                {
                    _warExhaustionById[key] = MBMath.ClampFloat(currentValue += finalWarExhaustionDelta, MinWarExhaustion, MaxWarExhaustion);
                }
                else
                {
                    _warExhaustionById[key] = MBMath.ClampFloat(finalWarExhaustionDelta, MinWarExhaustion, MaxWarExhaustion);
                }

                if (Settings.Instance.EnableWarExhaustionDebugMessages && kingdom1 == Hero.MainHero.MapFaction)
                {
                    string information = string.Format("Added {0} {1} war exhaustion to {2}'s war with {3}", finalWarExhaustionDelta, Enum.GetName(typeof(WarExhaustionType), warExhaustionType), kingdom1.Name, kingdom2.Name);
                    InformationManager.DisplayMessage(new InformationMessage(information, Color.FromUint(4282569842U)));
                }
            }
        }
Esempio n. 5
0
        public static int GetModifiedRelation(this Hero hero, Hero otherHero)
        {
            ExplainedNumber relationBetweenHeroes = new ExplainedNumber(CharacterRelationManager.GetHeroRelation(hero, otherHero), null, null);

            deGetPersonalityEffects(Campaign.Current.Models.DiplomacyModel is DefaultDiplomacyModel defaultDiplomacyModel ? defaultDiplomacyModel : new DefaultDiplomacyModel(), ref relationBetweenHeroes, hero, otherHero);
            return(MBMath.Round(MBMath.ClampFloat(relationBetweenHeroes.ResultNumber + (RelativesHelper.BloodRelatives(hero, otherHero) ? 30f : 0f), -100f, 100f)));
        }
        public void SetTimersOfVictoryReactionsForRetreating(BattleSideEnum side)
        {
            this._reactionsStarted = true;
            this.SelectVictoryCondition(side);
            List <Agent> list      = this.Mission.Agents.Where <Agent>((Func <Agent, bool>)(agent => agent.IsHuman && agent.IsAIControlled && agent.Team.Side == side)).ToList <Agent>();
            int          num1      = (int)((double)list.Count * 0.5);
            List <Agent> agentList = new List <Agent>();

            for (int index = 0; index < list.Count && agentList.Count != num1; ++index)
            {
                int num2 = list.Count - index - (num1 - agentList.Count);
                if ((double)MBRandom.RandomFloat <= 0.5 + 0.5 * (double)MBMath.ClampFloat((float)(num1 - num2) / (float)num1, 0.0f, 1f))
                {
                    agentList.Add(list[index]);
                }
            }
            foreach (Agent agent in agentList)
            {
                MatrixFrame frame  = agent.Frame;
                Vec2        asVec2 = frame.origin.AsVec2;
                Vec3        f      = frame.rotation.f;
                agent.SetTargetPositionAndDirectionSynched(ref asVec2, ref f);
                this.SetTimersOfVictoryReactions(agent, 1f, 8f);
            }
        }
Esempio n. 7
0
        private void CheckMorales()
        {
            if ((double)this._nextTimeToCheckForMorales < 0.0)
            {
                this._nextTimeToCheckForMorales = this.Mission.Time + 1f;
            }
            if ((double)this.Mission.Time < (double)this._nextTimeToCheckForMorales)
            {
                return;
            }
            ++this._nextTimeToCheckForMorales;
            float moraleGain;

            if (!this.GetMoraleGain(out moraleGain))
            {
                return;
            }
            this._morale += moraleGain;
            this._morale  = MBMath.ClampFloat(this._morale, -1f, 1f);
            GameNetwork.BeginBroadcastModuleEvent();
            GameNetwork.WriteMessage((GameNetworkMessage) new FlagDominationMoraleChangeMessage(this.MoraleRounded));
            GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.None);
            this._gameModeFlagDominationClient?.OnMoraleChanged(this.MoraleRounded);
            MPPerkObject.RaiseEventForAllPeers(MPPerkCondition.PerkEventFlags.MoraleChange);
        }
Esempio n. 8
0
            static protected float CalculateAILevel(Agent agent, int relevantSkillLevel)
            {
                float difficultyModifier = GetCombatAIDifficultyMultiplier();

                //float difficultyModifier = 1.0f; // v enhanced battle test je difficulty very easy
                return(MBMath.ClampFloat((float)relevantSkillLevel / 250f * difficultyModifier, 0f, 1f));
            }
        internal override float GetTacticWeight()
        {
            float  num1 = this.team.QuerySystem.PowerRatioIncludingCasualties / this.team.QuerySystem.OverallPowerRatio;
            double num2 = (double)MBMath.LinearExtrapolation(0.0f, Math.Max(this.team.QuerySystem.InfantryRatio, Math.Max(this.team.QuerySystem.RangedRatio, this.team.QuerySystem.CavalryRatio)), MBMath.ClampFloat(num1, 0.0f, 2.66f) / 2f);
            float  num3 = this.team.QuerySystem.EnemyTeams.Average <TeamQuerySystem>((Func <TeamQuerySystem, float>)(et => et.CavalryRatio)) + this.team.QuerySystem.EnemyTeams.Average <TeamQuerySystem>((Func <TeamQuerySystem, float>)(et => et.RangedCavalryRatio));
            double num4 = (double)num3 != 0.0 ? (double)MBMath.Lerp(0.8f, 1.2f, MBMath.ClampFloat((this.team.QuerySystem.CavalryRatio + this.team.QuerySystem.RangedCavalryRatio) / num3, 0.0f, 2f) / 2f) : 1.20000004768372;

            return((float)(num2 * num4) * (float)Math.Min(1.0, Math.Sqrt((double)this.team.QuerySystem.OverallPowerRatio)));
        }
Esempio n. 10
0
 private void ApplyAIWithholdDecision(bool decisionIsWithhold)
 {
     if (!decisionIsWithhold || WithholdCost is null)
     {
         return;
     }
     LeavingClan.Kingdom.RulingClan.Influence = MBMath.ClampFloat(LeavingClan.Kingdom.RulingClan.Influence - WithholdCost.InfluenceCost, 0f, float.MaxValue);
     LeavingClan.Kingdom.Ruler.Gold           = MBMath.ClampInt(LeavingClan.Kingdom.Ruler.Gold - WithholdCost.GoldCost, 0, int.MaxValue);
 }
Esempio n. 11
0
        public static float GetBattleSizeFactor(int battleSize, float normalizationFactor)
        {
            float num = -1f;

            if (battleSize > 0)
            {
                num = (float)(0.0399999991059303 + 0.0799999982118607 * Math.Pow((double)battleSize, 0.400000005960464)) * normalizationFactor;
            }
            return(MBMath.ClampFloat(num, 0.15f, 1f));
        }
Esempio n. 12
0
        private void InitializeMorale()
        {
            float num  = 35f;
            int   num2 = MBRandom.RandomInt(30);
            float num3 = num + num2;

            num3   = MissionGameModels.Current.BattleMoraleModel.GetEffectiveInitialMorale(Agent, num3);
            num3   = MBMath.ClampFloat(num3, 15f, 100f);
            Morale = num3;
        }
Esempio n. 13
0
        private void RemoveDailyWarExhaustion(Tuple <Kingdom, Kingdom> kingdoms)
        {
            string key = CreateKey(kingdoms);

            if (key != null && _warExhaustionById.TryGetValue(key, out float currentValue))
            {
                float warExhaustionToRemove = Settings.Instance.WarExhaustionDecayPerDay;
                _warExhaustionById[key] = MBMath.ClampFloat(currentValue -= warExhaustionToRemove, MinWarExhaustion, MaxWarExhaustion);
            }
        }
        private void InitializeMorale()
        {
            Helpers.Say("Vampire initialize morale");
            float num  = 35f;
            int   num2 = MBRandom.RandomInt(30);
            float num3 = num + (float)num2;

            num3        = MissionGameModels.Current.BattleMoraleModel.GetEffectiveInitialMorale(this.Agent, num3);
            num3        = MBMath.ClampFloat(num3, 15f, 100f);
            base.Morale = num3;
        }
        public void FormFromCircumference(float circumference)
        {
            int   countWithOverride = this.GetUnitCountWithOverride();
            int   maximumDepth      = this.GetMaximumDepth(countWithOverride);
            float num1     = (float)(6.28318548202515 * ((double)this.Distance + (double)this.UnitDiameter) / ((double)this.Interval + (double)this.UnitDiameter));
            int   num2     = MBMath.Round((float)(maximumDepth * (maximumDepth - 1) / 2) * num1);
            float minValue = (float)Math.Max(0, Math.Min(MBMath.Round((float)((countWithOverride + num2) / maximumDepth)), countWithOverride) - 1) * (this.Interval + this.UnitDiameter);
            float maxValue = (float)Math.Max(0, countWithOverride - 1) * (this.Interval + this.UnitDiameter);

            circumference = MBMath.ClampFloat(circumference, minValue, maxValue);
            this.Width    = circumference + this.UnitDiameter;
        }
Esempio n. 16
0
        private static GoldCost DetermineGoldCostForFormingNonAggressionPact(Kingdom kingdom, Kingdom otherKingdom, bool forcePlayerCharacterCosts = false)
        {
            Hero giver = forcePlayerCharacterCosts ? Hero.MainHero : kingdom.Leader;

            float otherKingdomWarLoad = GetKingdomWarLoad(otherKingdom) + 1;

            int baseGoldCost   = 500;
            int goldCostFactor = 100;
            int goldCost       = (int)((MBMath.ClampFloat((1 / otherKingdomWarLoad), 0f, 1f) * GetKingdomScalingFactor(kingdom) * goldCostFactor) + baseGoldCost);

            return(new GoldCost(giver, otherKingdom.Leader, goldCost));
        }
        public static float GetFormAllianceScore(Kingdom kingdom, Kingdom otherKingdom)
        {
            float totalScore    = 0;
            float totalStrength = 0;

            float[] kingdomStrengths = Kingdom.All.Select(curKingdom => curKingdom.TotalStrength).OrderBy(a => a).ToArray();

            int   halfIndex = kingdomStrengths.Count() / 2;
            float medianStrength;

            if ((kingdomStrengths.Length % 2) == 0)
            {
                medianStrength = (kingdomStrengths.ElementAt(halfIndex) + kingdomStrengths.ElementAt(halfIndex - 1)) / 2;
            }
            else
            {
                medianStrength = kingdomStrengths.ElementAt(halfIndex);
            }

            // weak faction bonus
            float averageStrength = totalStrength / Kingdom.All.Count;

            if (kingdom.TotalStrength <= medianStrength)
            {
                totalScore += (int)AllianceScore.BelowMedianStrength;
            }

            // common enemies
            IEnumerable <Kingdom> commonEnemies = FactionManager.GetEnemyKingdoms(kingdom).Intersect(FactionManager.GetEnemyKingdoms(otherKingdom));

            totalScore += commonEnemies.Count() * (int)AllianceScore.HasCommonEnemy;

            // bordering or inside territory modifier
            if (kingdom.IsInsideTeritoryOf(otherKingdom))
            {
                float traitScore = 0;
                traitScore -= (int)AllianceScore.SharesBorder * kingdom.Leader.GetHeroTraits().Calculating;
                traitScore += (int)AllianceScore.SharesBorder * kingdom.Leader.GetHeroTraits().Mercy;

                totalScore += traitScore;
            }

            // existing alliances
            totalScore -= (int)AllianceScore.ExistingAlliance * Kingdom.All.Except(new[] { kingdom, otherKingdom }).Where(curKingdom => FactionManager.IsAlliedWithFaction(kingdom, curKingdom)).Count();

            // relation modifier
            float relationModifier = MBMath.ClampFloat((float)Math.Log((kingdom.Leader.GetRelation(otherKingdom.Leader) + 100f) / 100f, 1.5), -1, 1);

            totalScore += (int)AllianceScore.Relationship * relationModifier;

            return(totalScore);
        }
Esempio n. 18
0
        internal static float DetermineInfluenceCostForFormingAlliance(Kingdom kingdom, Kingdom otherKingdom, bool isPlayerRequested = false)
        {
            const float baseInfluenceCost = 100f;

            if (isPlayerRequested)
            {
                return(MBMath.ClampFloat((float)Math.Pow(AllianceScoringModel.FormAllianceScoreThreshold / Math.Max(AllianceScoringModel.GetFormAllianceScore(kingdom, otherKingdom), 1f), 4), 1f, 256f) * baseInfluenceCost);
            }
            else
            {
                return(baseInfluenceCost);
            }
        }
Esempio n. 19
0
        internal override float GetTacticWeight()
        {
            if (this.team.Formations.All <Formation>((Func <Formation, bool>)(f => !f.QuerySystem.IsRangedFormation)))
            {
                return(0.0f);
            }
            double num1 = (double)this.team.QuerySystem.RangedRatio * (double)this.team.QuerySystem.MemberCount / ((double)this.team.QuerySystem.MemberCount - (double)(this.team.QuerySystem.RangedCavalryRatio * (float)this.team.QuerySystem.MemberCount));
            float  num2 = this.team.QuerySystem.RangedRatio + this.team.QuerySystem.RangedCavalryRatio;
            float  num3 = this.team.QuerySystem.EnemyRangedRatio + this.team.QuerySystem.EnemyRangedCavalryRatio;
            double num4 = (double)MBMath.ClampFloat((double)num3 > 0.0 ? num2 / num3 : 2f, 0.5f, 2f);

            return((float)(num1 * num4) * (float)Math.Sqrt((double)this.team.QuerySystem.OverallPowerRatio));
        }
        private static void FormFromCircumference(TaleWorlds.MountAndBlade.CircularFormation circularFormation, float circumference,
                                                  int countWithOverride, int maximumDepth, float distance, float interval, float unitDiameter)
        {
            float num1     = (float)(6.28318548202515 * (distance + (double)unitDiameter) / (interval + (double)unitDiameter));
            int   num2     = MBMath.Round(maximumDepth * (maximumDepth - 1) / 2 * num1);
            float minValue =
                Math.Max(0, Math.Min(MBMath.Round((countWithOverride + num2) / maximumDepth), countWithOverride)) *
                (interval + unitDiameter);
            float maxValue = Math.Max(0, countWithOverride - 1) * (interval + unitDiameter);

            circumference           = MBMath.ClampFloat(circumference, minValue, maxValue);
            circularFormation.Width = circumference + unitDiameter;
        }
Esempio n. 21
0
 private void TickCameraZoom(float dt)
 {
     if (!((NativeObject)this._camera != (NativeObject)null))
     {
         return;
     }
     this.SetCamFovHorizontal(MBMath.ClampFloat(this._camera.HorizontalFov + this._curZoomSpeed, 0.1f, 2f));
     if ((double)dt <= 0.0)
     {
         return;
     }
     this._curZoomSpeed = MBMath.Lerp(this._curZoomSpeed, 0.0f, MBMath.ClampFloat(dt * 25.9f, 0.0f, 1f), 1E-05f);
 }
Esempio n. 22
0
 protected override void OnTickAsAI(float dt)
 {
     if (Morale < 20f)
     {
         canCrumble = crumbleTimer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission));
         if (canCrumble)
         {
             float damageTaken = 0.01f / Morale;
             damageTaken = MBMath.ClampFloat(damageTaken, 0, 1);
             Agent.ApplyDamage(damageTaken);
             crumbleTimer.Reset(MBCommon.GetTime(MBCommon.TimeType.Mission));
             //Helpers.Say(Agent.Name + " took " + damageTaken + " crumbling damage from low binding");
         }
     }
 }
 protected override void OnTickAsAI(float dt)
 {
     if (base.Morale < 20f)
     {
         canCrumble = crumbleTimer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission));
         if (canCrumble)
         {
             float damageTaken = 0.01f / base.Morale;
             damageTaken        = MBMath.ClampFloat(damageTaken, 0, 1);
             this.Agent.Health -= damageTaken;
             crumbleTimer.Reset(MBCommon.GetTime(MBCommon.TimeType.Mission));
             Helpers.Say(this.Agent.Name + " took " + damageTaken + " damage from low morale.");
         }
     }
 }
Esempio n. 24
0
        protected internal override void OnTick(float dt)
        {
            if ((double)dt == 0.0)
            {
                return;
            }
            MatrixFrame globalFrame = this.GameEntity.GetGlobalFrame();
            MetaMesh    metaMesh    = this.GameEntity.GetMetaMesh(0);

            if ((NativeObject)metaMesh == (NativeObject)null)
            {
                return;
            }
            Vec3 vec3_1 = globalFrame.origin - this._prevFlagMeshFrame;

            vec3_1.x /= dt;
            vec3_1.y /= dt;
            vec3_1.z /= dt;
            Vec3 vec3_2 = new Vec3(20f, z: -10f) * 0.1f - vec3_1;

            if ((double)vec3_2.LengthSquared < 9.99999993922529E-09)
            {
                return;
            }
            Vec3 local = globalFrame.rotation.TransformToLocal(vec3_2);

            local.z = 0.0f;
            double num1  = (double)local.Normalize();
            float  theta = (float)Math.Atan2((double)local.y, (double)local.x);

            this.SmoothTheta(ref theta, dt);
            Vec3        scaleVector = metaMesh.Frame.rotation.GetScaleVector();
            MatrixFrame identity    = MatrixFrame.Identity;

            identity.Scale(scaleVector);
            identity.rotation.RotateAboutUp(theta);
            this._prevTheta = theta;
            float num2 = this._prevSkew + Math.Min((float)Math.Acos((double)Vec3.DotProduct(vec3_2, globalFrame.rotation.u) / (double)vec3_2.Length) - this._prevSkew, 150f * dt) * 0.05f;

            this._prevSkew = num2;
            float num3 = MBMath.ClampFloat(vec3_2.Length, 1f / 1000f, 10000f);

            this._time             += (float)((double)dt * (double)num3 * 0.5);
            metaMesh.Frame          = identity;
            metaMesh.VectorUserData = new Vec3((float)Math.Cos((double)num2), 1f - (float)Math.Sin((double)num2), w: this._time);
            this._prevFlagMeshFrame = globalFrame.origin;
        }
Esempio n. 25
0
        private float GetTacticalPositionScore(TacticalPosition tacticalPosition)
        {
            if (!this.CheckAndDetermineFormation(ref this._mainInfantry, (Func <Formation, bool>)(f => f.QuerySystem.IsInfantryFormation)) || !this.CheckAndDetermineFormation(ref this._archers, (Func <Formation, bool>)(f => f.QuerySystem.IsRangedFormation)))
            {
                return(0.0f);
            }
            double    num1          = (double)MBMath.Lerp(1f, 1.5f, MBMath.ClampFloat(tacticalPosition.Slope, 0.0f, 60f) / 60f);
            Formation formation     = this.team.Formations.Where <Formation>((Func <Formation, bool>)(f => f.QuerySystem.IsRangedFormation)).MaxBy <Formation, int>((Func <Formation, int>)(f => f.CountOfUnits));
            float     num2          = Math.Max(formation.arrangement.Depth, formation.arrangement.Width);
            float     num3          = MBMath.ClampFloat(tacticalPosition.Width / num2, 0.7f, 1f);
            float     num4          = tacticalPosition.IsInsurmountable ? 1.5f : 1f;
            float     cavalryFactor = this.GetCavalryFactor(tacticalPosition);
            float     num5          = MBMath.Lerp(0.7f, 1f, (float)((150.0 - (double)MBMath.ClampFloat(this._mainInfantry.QuerySystem.AveragePosition.Distance(tacticalPosition.Position.AsVec2), 50f, 150f)) / 100.0));
            double    num6          = (double)num3;

            return((float)(num1 * num6) * num4 * cavalryFactor * num5);
        }
 protected internal override void OnEditorVariableChanged(string variableName)
 {
     base.OnEditorVariableChanged(variableName);
     if (variableName == "minRadius")
     {
         this.minRadius = MBMath.ClampFloat(this.minRadius, 0.1f, this.maxRadius);
     }
     if (variableName == "maxRadius")
     {
         this.maxRadius = MBMath.ClampFloat(this.maxRadius, this.minRadius, float.MaxValue);
     }
     if (!(variableName == "hideAllProbes"))
     {
         return;
     }
     MapAtmosphereProbe.hideAllProbesStatic = this.hideAllProbes;
 }
Esempio n. 27
0
        public override Agent.UsageDirection GetBlockDirection(Mission mission)
        {
            Agent mainAgent = mission.MainAgent;
            float num1      = float.MinValue;

            Agent.UsageDirection usageDirection = Agent.UsageDirection.AttackDown;
            foreach (Agent agent in (IEnumerable <Agent>)mission.Agents)
            {
                if (agent.IsHuman)
                {
                    switch (agent.GetCurrentActionStage(1))
                    {
                    case Agent.ActionStage.AttackReady:
                    case Agent.ActionStage.AttackQuickReady:
                    case Agent.ActionStage.AttackRelease:
                        if (agent.IsEnemyOf(mainAgent))
                        {
                            Vec3   v1   = agent.Position - mainAgent.Position;
                            float  num2 = v1.Normalize();
                            double num3 = (double)MBMath.ClampFloat(Vec3.DotProduct(v1, mainAgent.LookDirection) + 0.8f, 0.0f, 1f);
                            float  num4 = MBMath.ClampFloat((float)(1.0 / ((double)num2 + 0.5)), 0.0f, 1f);
                            float  num5 = MBMath.ClampFloat((float)(-(double)Vec3.DotProduct(v1, agent.LookDirection) + 0.5), 0.0f, 1f);
                            double num6 = (double)num4;
                            float  num7 = (float)(num3 * num6) * num5;
                            if ((double)num7 > (double)num1)
                            {
                                num1           = num7;
                                usageDirection = agent.GetCurrentActionDirection(1);
                                if (usageDirection == Agent.UsageDirection.None)
                                {
                                    usageDirection = Agent.UsageDirection.AttackDown;
                                    continue;
                                }
                                continue;
                            }
                            continue;
                        }
                        continue;

                    default:
                        continue;
                    }
                }
            }
            return(usageDirection);
        }
Esempio n. 28
0
        public static Color AddFactorInHSB(
            this Color rgbColor,
            float hueDifference,
            float saturationDifference,
            float brighnessDifference)
        {
            Vec3 vec3 = MBMath.RGBtoHSB(rgbColor);

            vec3.x = (float)(((double)vec3.x + (double)hueDifference * 360.0) % 360.0);
            if ((double)vec3.x < 0.0)
            {
                vec3.x += 360f;
            }
            vec3.y = MBMath.ClampFloat(vec3.y + saturationDifference, 0.0f, 1f);
            vec3.z = MBMath.ClampFloat(vec3.z + brighnessDifference, 0.0f, 1f);
            return(MBMath.HSBtoRGB(vec3.x, vec3.y, vec3.z, rgbColor.Alpha));
        }
Esempio n. 29
0
        public static int DetermineGoldCostForMakingPeace(Kingdom kingdomMakingPeace, Kingdom otherKingdom)
        {
            if (!Settings.Instance.EnableInfluenceCostsForDiplomacyActions)
            {
                return(0);
            }

            float warExhaustionMultiplier = 1f;

            if (Settings.Instance.EnableWarExhaustion)
            {
                float kingdomMakingPeaceWarExhaustion = WarExhaustionManager.Instance.GetWarExhaustion(kingdomMakingPeace, otherKingdom);
                float otherKingdomWarExhaustion       = WarExhaustionManager.Instance.GetWarExhaustion(otherKingdom, kingdomMakingPeace);
                float relativeWarExhaustion           = (kingdomMakingPeaceWarExhaustion + 1f) / (otherKingdomWarExhaustion + 1f) - 1f;;
                warExhaustionMultiplier = MBMath.ClampFloat(relativeWarExhaustion, 0, (((WarExhaustionManager.DefaultMaxWarExhaustion / Settings.Instance.MaxWarExhaustion) / 20) * kingdomMakingPeaceWarExhaustion) - 1f);
            }

            return(Math.Min((int)(GetKingdomTierCount(kingdomMakingPeace) * Settings.Instance.ScalingWarReparationsGoldCostMultiplier * warExhaustionMultiplier), kingdomMakingPeace.Leader.Gold / 2));
        }
Esempio n. 30
0
        private float GetTacticalPositionScore(TacticalPosition tacticalPosition)
        {
            if (!this.CheckAndDetermineFormation(ref this._mainInfantry, (Func <Formation, bool>)(f => f.QuerySystem.IsInfantryFormation)))
            {
                return(0.0f);
            }
            double num1         = (double)MBMath.Lerp(1f, 1.5f, MBMath.ClampFloat(tacticalPosition.Slope, 0.0f, 60f) / 60f);
            int    countOfUnits = this._mainInfantry.CountOfUnits;
            float  num2         = MBMath.Lerp(0.67f, 1.5f, (float)(((double)MBMath.ClampFloat((float)((double)this._mainInfantry.Interval * (double)(countOfUnits - 1) + (double)this._mainInfantry.UnitDiameter * (double)countOfUnits) / tacticalPosition.Width, 0.5f, 3f) - 0.5) / 2.5));
            float  num3         = 1f;

            if (this.CheckAndDetermineFormation(ref this._archers, (Func <Formation, bool>)(f => f.QuerySystem.IsRangedFormation)) && tacticalPosition.LinkedTacticalPositions.Where <TacticalPosition>((Func <TacticalPosition, bool>)(lcp => lcp.TacticalPositionType == TacticalPosition.TacticalPositionTypeEnum.Cliff)).ToList <TacticalPosition>().Any <TacticalPosition>())
            {
                num3 = MBMath.Lerp(1f, 1.5f, (float)(((double)MBMath.ClampFloat(this.team.QuerySystem.RangedRatio, 0.05f, 0.25f) - 0.0500000007450581) * 5.0));
            }
            float  num4 = MBMath.Lerp(0.7f, 1f, (float)((150.0 - (double)MBMath.ClampFloat(this._mainInfantry.QuerySystem.AveragePosition.Distance(tacticalPosition.Position.AsVec2), 50f, 150f)) / 100.0));
            double num5 = (double)num2;

            return((float)(num1 * num5) * num3 * num4);
        }