internal BaseWeightState(MechDef mechDef)
 {
     Armor     = mechDef.ArmorTonnage();
     Structure = mechDef.Chassis.Tonnage / 10f;
     Chassis   = mechDef.Chassis.Tonnage;
     Engine    = mechDef.GetEngine();
 }
        internal MechDefMovementStatistics(MechDef mechDef)
        {
            this.mechDef = mechDef;

            Engine   = mechDef.GetEngine();
            movement = Engine?.CoreDef.GetMovement(mechDef.Chassis.Tonnage);
            if (movement == null)
            {
                return;
            }

            WalkMovementPoint = movement.WalkMovementPoint;
            MoveMultiplier    = GetMoveMultiplier();
            BaseWalkSpeed     = GetWalkSpeed();
            BaseRunSpeed      = GetRunSpeed();
            WalkSpeed         = BaseWalkSpeed * MoveMultiplier;
            RunSpeed          = BaseRunSpeed * MoveMultiplier;

            JumpCapacity           = GetJumpCapacity();
            BaseJumpDistance       = EngineMovement.ConvertJJMPToGameDistance(JumpCapacity);
            JumpDistanceMultiplier = GetJumpDistanceMultiplier();
            JumpDistance           = BaseJumpDistance * JumpDistanceMultiplier;

            JumpJetCount    = mechDef.Inventory.Count(x => x.ComponentDefType == ComponentType.JumpJet);
            JumpJetMaxCount = GetJumpJetMaxCount();
        }
Exemple #3
0
        public void ValidateMech(MechDef mechDef, Errors errors)
        {
            var engine = mechDef.GetEngine();

            if (engine == null)
            {
                return;
            }

            {
                var count = mechDef.Inventory.Count(c => c.ComponentDefType == ComponentType.JumpJet);
                var max   = engine.CoreDef.GetMovement(mechDef.Chassis.Tonnage).JumpJetCount;

                if (count > max)
                {
                    if (errors.Add(MechValidationType.InvalidJumpjets, $"JUMP JETS: This Mech mounts too many jumpjets ({count} / {max})"))
                    {
                        return;
                    }
                }
            }

            if (Control.settings.MinimumHeatSinksOnMech > 0)
            {
                var externalCount = mechDef.Inventory.Count(c => c.Is <EngineHeatSink>());
                var internalCount = engine.CoreDef.InternalHeatSinks;
                var count         = internalCount + externalCount;

                var min = Control.settings.MinimumHeatSinksOnMech;

                if (count < min)
                {
                    if (errors.Add(MechValidationType.InvalidInventorySlots, $"HEAT SINKS: This Mech has too few heat sinks ({count} / {min})"))
                    {
                        return;
                    }
                }
            }

            if (!Control.settings.AllowMixingHeatSinkTypes)
            {
                var types = new HashSet <string>();

                var inventoryHeatSinkTypes = mechDef.Inventory.Select(r => r.GetComponent <EngineHeatSink>()).Where(hs => hs != null);
                foreach (var hs in inventoryHeatSinkTypes.Union(engine.CoreRef.GetInternalEngineHeatSinkTypes()))
                {
                    types.Add(hs.HSCategory);
                    if (types.Count > 1)
                    {
                        if (errors.Add(MechValidationType.InvalidInventorySlots, "MIXED HEAT SINKS: Heat Sink types cannot be mixed"))
                        {
                            return;
                        }
                        break;
                    }
                }
            }
        }
Exemple #4
0
 internal Weights(MechDef mechDef)
 {
     StandardArmorWeight           = mechDef.StandardArmorTonnage();
     StandardStructureWeight       = mechDef.Chassis.Tonnage / 10f;
     StandardChassisWeightCapacity = mechDef.Chassis.Tonnage;
     Engine             = mechDef.GetEngine();
     Factors            = Engine?.WeightFactors ?? WeightsUtils.GetWeightFactorsFromInventory(mechDef.Inventory);
     ComponentSumWeight = mechDef.Inventory.Sum(mechComponentRef => mechComponentRef.Def.Tonnage) - (Engine?.CoreDef.Def.Tonnage ?? 0);
 }
Exemple #5
0
        internal static float GetEngineHeatDissipation(MechDef mechDef)
        {
            var engine = mechDef.GetEngine();

            if (engine == null)
            {
                return(EngineFeature.settings.EngineMissingFallbackHeatSinkCapacity);
            }

            return(engine.EngineHeatDissipation);
        }
        internal MechDefHeatEfficiencyStatistics(MechDef mechDef)
        {
            this.mechDef = mechDef;
            Engine       = mechDef.GetEngine();

            DissipationCapacity = (int)GetDissipationCapacity();
            HeatSinkCapacity    = GetHeatSinkCapacity();
            HeatSinking         = (int)((DissipationCapacity + HeatSinkCapacity) * MechStatisticsRules.Combat.Heat.GlobalHeatSinkMultiplier);
            AlphaStrike         = (int)(GetHeatGenerated() * GetWeaponHeatMultiplier());
            JumpHeat            = GetJumpHeat();
            MaxHeat             = GetMaxHeat();
            Overheat            = GetOverheat();
        }
Exemple #7
0
        private static float CalculateEngineTonnageChanges(MechDef mechDef, Weights savings = null)
        {
            var engine = mechDef.GetEngine();

            if (engine == null)
            {
                return(0);
            }

            // TODO only way to get rid of this would be to fake replace using category restrictions
            // then get a prepared mechdef and use that
            // unfortunatly CC does not work on fake mechdefs or inventories in that sense yet
            if (savings != null)
            {
                //var originalTonnage = engine.TotalTonnage;

                if (!Mathf.Approximately(savings.EngineFactor, 1))
                {
                    engine.Weights.EngineFactor = 1;
                }

                if (!Mathf.Approximately(savings.GyroFactor, 1))
                {
                    engine.Weights.GyroFactor = 1;
                }

                var defaultTonnage = engine.TotalTonnage;

                if (!Mathf.Approximately(savings.EngineFactor, 1))
                {
                    engine.Weights.EngineFactor = savings.EngineFactor;
                }

                if (!Mathf.Approximately(savings.GyroFactor, 1))
                {
                    engine.Weights.GyroFactor = savings.GyroFactor;
                }

                var newTonnage = engine.TotalTonnage;

                //Control.mod.Logger.LogDebug($"originalTonnage={originalTonnage} defaultTonnage={defaultTonnage} newTonnage={newTonnage}");

                return(newTonnage - defaultTonnage);
            }

            return(engine.TotalTonnageChanges);
        }
Exemple #8
0
        internal static EngineMovement GetEngineMovement(this MechDef mechDef)
        {
            var engine = mechDef.GetEngine();

            return(engine?.CoreDef.GetMovement(mechDef.Chassis.Tonnage));
        }
        public void ValidateMech(MechDef mechDef, Errors errors)
        {
            var engine = mechDef.GetEngine();

            if (engine == null)
            {
                return;
            }

            {
                var count = mechDef.Inventory.Count(c => c.ComponentDefType == ComponentType.JumpJet);
                var max   = engine.CoreDef.GetMovement(mechDef.Chassis.Tonnage).JumpJetCount;

                if (count > max)
                {
                    if (errors.Add(MechValidationType.InvalidJumpjets, $"JUMP JETS: This Mech mounts too many jumpjets ({count} / {max})"))
                    {
                        return;
                    }
                }
            }

            {
                if (engine.IsMissingHeatSinks(out var min, out var count))
                {
                    if (errors.Add(MechValidationType.InvalidInventorySlots, $"HEAT SINKS: This Mech has too few heat sinks ({count} / {min})"))
                    {
                        return;
                    }
                }
            }

            if (!EngineFeature.settings.AllowMixingHeatSinkTypes)
            {
                var types = new HashSet <string>();

                var inventoryHeatSinkTypes = mechDef.Inventory.Select(r => r.GetComponent <EngineHeatSinkDef>()).Where(hs => hs != null).ToList();
                inventoryHeatSinkTypes.Add(engine.MechHeatSinkDef);
                foreach (var hs in inventoryHeatSinkTypes)
                {
                    types.Add(hs.HSCategory);
                    if (types.Count <= 1)
                    {
                        continue;
                    }

                    if (errors.Add(MechValidationType.InvalidInventorySlots, "HEAT SINKS: Heat Sink types cannot be mixed"))
                    {
                        return;
                    }
                }
            }

            if (EngineFeature.settings.EnforceRulesForAdditionalInternalHeatSinks)
            {
                var count = engine.EngineHeatBlockDef.HeatSinkCount;
                var max   = engine.HeatSinkInternalAdditionalMaxCount;
                if (count > max)
                {
                    if (errors.Add(MechValidationType.InvalidInventorySlots, $"HEAT SINKS: This Mech has too many internal heat sinks ({count} / {max})"))
                    {
                        return;
                    }
                }
            }
        }