Beispiel #1
0
        // hide any location with maxArmor <= 0 && structure <= 1
        // for vehicles and troopers
        private static bool ShouldHide(MechLabLocationWidget widget)
        {
            var def = widget.chassisLocationDef;

            return(PrecisionUtils.SmallerOrEqualsTo(def.MaxArmor, 0) &&
                   PrecisionUtils.SmallerOrEqualsTo(def.InternalStructure, 1));
        }
Beispiel #2
0
    private static float CalculateWeight(float unmodified, float factor, float?precision = null)
    {
        var modified        = unmodified * factor;
        var modifiedRounded = PrecisionUtils.RoundUp(modified, precision ?? OverrideTonnageFeature.settings.TonnageStandardPrecision);

        return(modifiedRounded);
    }
Beispiel #3
0
        internal static int GetJumpHeat(this StatCollection statCollection, float ratio)
        {
            var jumpMaxHeat = statCollection.JumpHeat().Get();
            var jumpHeat    = ratio * jumpMaxHeat;

            jumpHeat = Mathf.Max(jumpHeat, EngineFeature.settings.MinimJumpHeat);
            return(PrecisionUtils.RoundUpToInt(jumpHeat));
        }
Beispiel #4
0
 private static float RoundRunMovementPoints(float value)
 {
     if (EngineFeature.settings.CBTWalkAndRunMPRounding)
     {
         return(PrecisionUtils.RoundUpToInt(value));
     }
     return(value);
 }
Beispiel #5
0
            static string DistanceToSummary(float meter)
            {
                var meters          = PrecisionUtils.RoundDownToInt(meter);
                var hexWidth        = MechStatisticsRules.Combat.MoveConstants.ExperimentalGridDistance;
                var hexes           = PrecisionUtils.RoundDownToInt(meters / hexWidth);
                var translatedValue = Strings.T("{0}m / {1} hex", meters, hexes);

                return(translatedValue);
            }
Beispiel #6
0
        internal static void SetStatValues(float fraction, ref float currentValue, ref float maxValue)
        {
            var minValue = 1f;

            maxValue     = 10f;
            currentValue = fraction * (maxValue - minValue) + minValue;
            currentValue = PrecisionUtils.RoundDownToInt(currentValue);
            currentValue = Mathf.Max(currentValue, minValue);
            currentValue = Mathf.Min(currentValue, maxValue);
        }
Beispiel #7
0
    public int CompareTo(ArmorLocationState other)
    {
        var cmp = ArmorPointsPriority - other.ArmorPointsPriority;

        if (!PrecisionUtils.Equals(cmp, 0))
        {
            return(cmp > 0 ? 1 : -1);
        }
        return(LocationPriority - other.LocationPriority);
    }
        private static bool ProcessMechArmorStructureRatioForLocation(
            MechDef mechDef,
            ChassisLocations location,
            Dictionary <MechValidationType, List <Text> > errorMessages = null,
            bool applyChanges = false)
        {
            var mechLocationDef    = mechDef.GetLocationLoadoutDef(location);
            var chassisLocationDef = mechDef.Chassis.GetLocationDef(location);

            var armor     = Mathf.Max(mechLocationDef.AssignedArmor, 0);
            var armorRear = Mathf.Max(mechLocationDef.AssignedRearArmor, 0);

            var structure = chassisLocationDef.InternalStructure;

            var ratio = location == ChassisLocations.Head ? 3 : 2;

            var total    = armor + armorRear;
            var totalMax = ratio * structure;

            if (total <= totalMax)
            {
                return(true);
            }

            if (applyChanges)
            {
//                Control.mod.Logger.LogDebug($"structure={structure} location={location} totalMax={totalMax}");
//                Control.mod.Logger.LogDebug($"before AssignedArmor={mechLocationDef.AssignedArmor} AssignedRearArmor={mechLocationDef.AssignedRearArmor}");

                if ((location & ChassisLocations.Torso) != 0)
                {
                    mechLocationDef.AssignedArmor     = PrecisionUtils.RoundUp((totalMax * 2 / 3), 5);
                    mechLocationDef.CurrentArmor      = mechLocationDef.AssignedArmor;
                    mechLocationDef.AssignedRearArmor = PrecisionUtils.RoundDown((totalMax * 1 / 3), 5);
                    mechLocationDef.CurrentRearArmor  = mechLocationDef.AssignedRearArmor;
                }
                else
                {
                    mechLocationDef.AssignedArmor = totalMax;
                    mechLocationDef.CurrentArmor  = mechLocationDef.AssignedArmor;
                }

                Control.mod.Logger.LogDebug($"set AssignedArmor={mechLocationDef.AssignedArmor} AssignedRearArmor={mechLocationDef.AssignedRearArmor} on location={location}");
            }

            //Control.mod.Logger.LogDebug($"{Mech.GetAbbreviatedChassisLocation(location)} armor={armor} armorRear={armorRear} structure={structure}");

            if (errorMessages != null)
            {
                var locationName = Mech.GetLongChassisLocation(location);
                errorMessages[MechValidationType.InvalidHardpoints].Add(new Text($"ARMOR {locationName}: Armor can only be {ratio} times more than structure."));
            }

            return(false);
        }
 public static void Postfix(ref float currentValue)
 {
     try
     {
         currentValue = PrecisionUtils.RoundUp(currentValue, OverrideTonnageFeature.settings.TonnageStandardPrecision);
     }
     catch (Exception e)
     {
         Control.Logger.Error.Log(e);
     }
 }
        private int GetJumpJetMaxCount()
        {
            var raw        = movement.JumpJetCount;
            var multiplier = GetJumpJetMaxCountMultiplier();
            var mutiplied  = raw * multiplier;
            var rounded    = PrecisionUtils.RoundDownToInt(mutiplied);
            var cropped    = Mathf.Min(rounded, mechDef.Chassis.MaxJumpjets);

            //Control.mod.Logger.Log($"raw={raw} multiplier={multiplier} mutiplied={mutiplied} rounded={rounded} cropped={cropped}");
            return(cropped);
        }
 private static MinHandReq CalcHandReq(float capacityOnLocation, float usageOnLocation)
 {
     if (PrecisionUtils.SmallerThan(capacityOnLocation, usageOnLocation))
     {
         return(MinHandReq.Two);
     }
     if (PrecisionUtils.SmallerThan(0, usageOnLocation))
     {
         return(MinHandReq.One);
     }
     return(MinHandReq.None);
 }
 public static void Postfix(MechDef mechDef, ref float currentValue, ref float maxValue)
 {
     try
     {
         currentValue += WeightsHandler.Shared.TonnageChanges(mechDef);
         currentValue  = PrecisionUtils.RoundUp(currentValue, OverrideTonnageFeature.settings.TonnageStandardPrecision);
         maxValue      = mechDef.Chassis.Tonnage;
     }
     catch (Exception e)
     {
         Control.Logger.Error.Log(e);
     }
 }
        private int GetHeatGenerated()
        {
            var defaultValue = mechDef.Inventory
                               .Where(x => x.IsFunctionalORInstalling())
                               .Select(x => x.Def as WeaponDef)
                               .Where(x => x != null)
                               .Sum(x => x.HeatGenerated);

            var stat = statCollection.HeatGenerated();

            stat.CreateWithDefault(defaultValue);
            var value = MechDefStatisticModifier.ModifyStatistic(stat, mechDef);

            return(PrecisionUtils.RoundUpToInt(value));
        }
        private int GetHeatGenerated()
        {
            var defaultValue = mechDef.Inventory
                               .Where(x => x.IsFunctionalORInstalling())
                               .Select(x => x.Def as WeaponDef)
                               .Where(x => x != null)
                               .Sum(x => x.HeatGenerated);

            // TODO HeatDivisor support or not? nah we just don't support COIL, who needs that anyway...

            var stat = statCollection.HeatGenerated();

            stat.CreateWithDefault(defaultValue);
            var value = MechDefStatisticModifier.ModifyStatistic(stat, mechDef);

            return(PrecisionUtils.RoundUpToInt(value));
        }
    internal static void OnArmorAddOrSubtract(MechLabLocationWidget widget, bool isRearArmor, float direction)
    {
        var stepPrecision = ArmorMaximizerFeature.Shared.Settings.StepPrecision.Get() ?? ArmorStructureRatioFeature.ArmorPerStep;
        var stepSize      = ArmorMaximizerFeature.Shared.Settings.StepSize.Get() ?? ArmorStructureRatioFeature.ArmorPerStep;

        var stepDirection = direction < 0 ? -1 : 1;
        var current       = isRearArmor ? widget.currentRearArmor : widget.currentArmor;

        var updated = stepDirection > 0
            ? PrecisionUtils.RoundUp(current + stepSize, stepPrecision)
            : PrecisionUtils.RoundDown(current - stepSize, stepPrecision);

        Control.Logger.Trace?.Log($"HandleArmorUpdate stepDirection={stepDirection} current={current} precision={stepPrecision} isRearArmor={isRearArmor}");
        if (stepDirection > 0)
        {
            var max = isRearArmor ? widget.maxRearArmor : widget.maxArmor;
            updated = Mathf.Min(updated, max);

            var maxTotal     = ArmorStructureRatioFeature.GetMaximumArmorPoints(widget.chassisLocationDef);
            var maxOther     = maxTotal - updated;
            var currentOther = isRearArmor ? widget.currentArmor : widget.currentRearArmor;
            var updatedOther = Mathf.Min(currentOther, maxOther);

            var otherNotChanged = PrecisionUtils.Equals(currentOther, updatedOther);
            if (otherNotChanged || !ArmorLocationLocker.IsLocked(widget.loadout.Location, !isRearArmor))
            {
                widget.SetArmor(isRearArmor, updated);
                widget.SetArmor(!isRearArmor, updatedOther);
            }

            Control.Logger.Trace?.Log($"HandleArmorUpdate updated={updated} maxTotal={maxTotal} maxOther={maxOther} currentOther={currentOther} updatedOther={updatedOther} isRearArmor={updatedOther}");
        }
        else
        {
            updated = Mathf.Max(updated, 0);
            widget.SetArmor(isRearArmor, updated);
            Control.Logger.Trace?.Log($"HandleArmorUpdate updated={updated}");
        }
    }
    internal static void OnRefreshArmor(MechLabLocationWidget widget)
    {
        void RefreshArmorBar(LanceStat lanceStat, bool isRearArmor)
        {
            lanceStat.SetTextColor(UIColor.White, UIColor.White);
            RefreshBarColor(widget, isRearArmor);

            void SetButtonColor(string buttonId, UIColor uiColor)
            {
                var button = lanceStat.transform.Find(buttonId);
                // the plus icon is actually made of two minus icons
                var icons = button.Find("startButtonFill").GetChildren();

                foreach (var icon in icons)
                {
                    var colorRefTracker = icon.GetComponent <UIColorRefTracker>();
                    colorRefTracker.SetUIColor(uiColor);
                }
            }

            const UIColor limitReachedColor = UIColor.MedGray;
            {
                var max        = isRearArmor ? widget.maxRearArmor : widget.maxArmor;
                var current    = isRearArmor ? widget.currentRearArmor : widget.currentArmor;
                var maxReached = PrecisionUtils.SmallerOrEqualsTo(max, current);
                SetButtonColor("bttn_plus", maxReached ? limitReachedColor : UIColor.White);
            }
            {
                var minReached = PrecisionUtils.SmallerOrEqualsTo(isRearArmor ? widget.currentRearArmor : widget.currentArmor, 0);
                SetButtonColor("bttn_minus", minReached ? limitReachedColor : UIColor.White);
            }
        }

        RefreshArmorBar(widget.armorBar, false);
        if (widget.useRearArmor)
        {
            RefreshArmorBar(widget.rearArmorBar, true);
        }
    }
Beispiel #17
0
 private static float RoundBy1(float value)
 {
     return(PrecisionUtils.RoundDown(value, 1));
 }