public int CompareTo(ArmorLocationState other) { var cmp = ArmorPointsPriority - other.ArmorPointsPriority; if (!PrecisionUtils.Equals(cmp, 0)) { return(cmp > 0 ? 1 : -1); } return(LocationPriority - other.LocationPriority); }
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}"); } }