Ejemplo n.º 1
0
        private float GetAvionicsToolingCost(float diameter, float length)
        {
            var toolingLevel = ToolingDatabase.GetToolingLevel(ToolingType, ControllableMass, diameter, length);
            var toolingCosts = GetPerLevelToolingCosts(diameter, length);

            return(GetToolingCost(toolingLevel, toolingCosts));
        }
Ejemplo n.º 2
0
        public override void PurchaseTooling()
        {
            float d, l;

            GetDimensions(out d, out l);
            ToolingDatabase.UnlockTooling(toolingType, d, l);
        }
Ejemplo n.º 3
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            ToolingDatabase.Load(node.GetNode("Tooling"));

            EnsureDefinitionsLoaded();
        }
Ejemplo n.º 4
0
        public override bool IsUnlocked()
        {
            GetDimensions(out var d, out var l);
            if (d < minDiameter)
            {
                return(true);
            }

            return(ToolingDatabase.GetToolingLevel(ToolingType, d, l) == 2);
        }
Ejemplo n.º 5
0
        private void UnlockInternalTankTooling(float diameter, float length)
        {
            if (_procAvionics.InternalTanksVolume == 0)
            {
                return;
            }

            var internalTankDiameter = GetInternalTankDiameter(diameter, length);

            ToolingDatabase.UnlockTooling(TankToolingType, internalTankDiameter, internalTankDiameter);
        }
Ejemplo n.º 6
0
        private bool IsInternalTankTooled(float diameter, float length)
        {
            if (_procAvionics.InternalTanksVolume == 0)
            {
                return(true);
            }

            var internalTankDiameter = GetInternalTankDiameter(diameter, length);

            return(ToolingDatabase.GetToolingLevel(TankToolingType, internalTankDiameter, internalTankDiameter) == 2);
        }
Ejemplo n.º 7
0
        private float GetCostReductionFactor(float d, float l)
        {
            foreach (string s in CostReducers)
            {
                if (ToolingDatabase.GetToolingLevel(s, d, l) > 0)
                {
                    return(costReductionMult);
                }
            }

            return(1);
        }
Ejemplo n.º 8
0
        public override bool IsUnlocked()
        {
            float d, l;

            GetDimensions(out d, out l);
            if (d < minDiameter)
            {
                return(true);
            }

            return(ToolingDatabase.HasTooling(toolingType, d, l) == ToolingDatabase.ToolingLevel.Full);
        }
Ejemplo n.º 9
0
        public override float GetToolingCost()
        {
            GetDimensions(out var d, out var l);
            float cost = GetLengthToolingCost(d, l);

            if (ToolingDatabase.GetToolingLevel(ToolingType, d, l) == 0)
            {
                var reductionFactor = GetCostReductionFactor(d, l);
                cost += reductionFactor * GetDiameterToolingCost(d);
            }

            return(cost * finalToolingCostMultiplier);
        }
Ejemplo n.º 10
0
        private float GetInternalTankToolingCost(float externalDiameter, float length)
        {
            if (_procAvionics.InternalTanksVolume == 0)
            {
                return(0);
            }

            var internalTankDiameter = GetInternalTankDiameter(externalDiameter, length);
            var level         = ToolingDatabase.GetToolingLevel(TankToolingType, internalTankDiameter, internalTankDiameter);
            var perLevelCosts = new[] { GetDiameterToolingCost(internalTankDiameter), GetLengthToolingCost(internalTankDiameter, internalTankDiameter) };
            var costMult      = TankToolingDefinition?.finalToolingCostMultiplier ?? 0f;

            return(GetToolingCost(level, perLevelCosts) * costMult);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Use for purchasing multiple toolings at once. Does it's best to determine the best order to buy them so that the cost would be minimal.
        /// Also deducuts the funds required for purchase.
        /// Has an option for running a simulation to calculate the accurate cost of toolings while the tooling DB and funds are left untouched.
        /// </summary>
        /// <param name="toolingColl">Collection of toolings to purchase.</param>
        /// <param name="isSimulation">Whether to simulate the purchase to get the accurate cost of all toolings.</param>
        /// <returns>Total cost of all the toolings purchased.</returns>
        public static float PurchaseToolingBatch(List <ModuleTooling> toolingColl, bool isSimulation = false)
        {
            ConfigNode toolingBackup = null;

            if (isSimulation)
            {
                toolingBackup = new ConfigNode();
                ToolingDatabase.Save(toolingBackup);
            }

            float totalCost = 0;

            try
            {
                // Currently all cost reducers are applied correctly when the tooling types are first sorted in alphabetical order
                toolingColl.Sort((mt1, mt2) => mt1.ToolingType.CompareTo(mt2.ToolingType));

                //TODO: find the most optimal order to purchase toolings that have diameter and length.
                //      If there are diameters 2.9; 3 and 3.1 only 3 needs to be purchased and others will fit inside the stretch margin.

                toolingColl.ForEach(mt =>
                {
                    if (mt.IsUnlocked())
                    {
                        return;
                    }

                    totalCost += mt.GetToolingCost();
                    mt.PurchaseTooling();
                });

                if (totalCost > 0 && !isSimulation)
                {
                    Funding.Instance.AddFunds(-totalCost, TransactionReasons.RnDPartPurchase);
                }
            }
            finally
            {
                if (isSimulation)
                {
                    ToolingDatabase.Load(toolingBackup);
                }
            }

            return(totalCost);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Checks whether two toolings are considered the same by checking their types and dimensions (if applicable).
        /// Dimension comparison is done with an error margin of 4%.
        /// </summary>
        /// <param name="a">Tooling 1</param>
        /// <param name="b">Tooling 2</param>
        /// <returns>True if toolings match</returns>
        public static bool IsSame(ModuleTooling a, ModuleTooling b)
        {
            if (a.ToolingType != b.ToolingType) return false;

            if (a is ModuleToolingDiamLen || b is ModuleToolingDiamLen)
            {
                var d1 = a as ModuleToolingDiamLen;
                var d2 = b as ModuleToolingDiamLen;
                if (d1 == null || d2 == null) return false;

                d1.GetDimensions(out float diam1, out float len1);
                d2.GetDimensions(out float diam2, out float len2);

                return ToolingDatabase.IsSameSize(diam1, len1, diam2, len2);
            }

            return true;
        }
Ejemplo n.º 13
0
        public override float GetToolingCost()
        {
            float d, l;

            GetDimensions(out d, out l);
            float cost = lengthToolingCost.x * d * d + lengthToolingCost.y * d + lengthToolingCost.z * l + lengthToolingCost.w;

            if (ToolingDatabase.HasTooling(toolingType, d, l) == ToolingDatabase.ToolingLevel.None)
            {
                float mult = 1f;
                foreach (string s in reducers)
                {
                    if (ToolingDatabase.HasTooling(s, d, l) > ToolingDatabase.ToolingLevel.None)
                    {
                        mult = costReductionMult;
                        break;
                    }
                }
                cost += mult * (diameterToolingCost.x * d * d + diameterToolingCost.y * d + diameterToolingCost.z);
            }

            return(cost * finalToolingCostMultiplier);
        }
Ejemplo n.º 14
0
 public override void PurchaseTooling()
 {
     GetDimensions(out var diameter, out var length);
     ToolingDatabase.UnlockTooling(ToolingType, ControllableMass, diameter, length);
     UnlockInternalTankTooling(diameter, length);
 }
Ejemplo n.º 15
0
 private bool IsAvionicsTooled(float diameter, float length) => ToolingDatabase.GetToolingLevel(ToolingType, ControllableMass, diameter, length) == 3;
Ejemplo n.º 16
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            ToolingDatabase.Load(node.GetNode("Tooling"));
        }
Ejemplo n.º 17
0
 public override void PurchaseTooling()
 {
     GetDimensions(out var d, out var l);
     ToolingDatabase.UnlockTooling(ToolingType, d, l);
 }
Ejemplo n.º 18
0
 public override void OnSave(ConfigNode node)
 {
     ToolingDatabase.Save(node.AddNode("Tooling"));
 }