Пример #1
0
        private void InitializeTechLimits()
        {
            if (HighLogic.CurrentGame == null || HighLogic.CurrentGame.Mode != Game.Modes.CAREER || techLimitsSerialized == null)
            {
                return;
            }

            if (ResearchAndDevelopment.Instance == null)
            {
                needsTechInit = true;
                return;
            }
            needsTechInit = false;

            List <TechLimit> techLimits;

            ObjectSerializer.Deserialize(techLimitsSerialized, out techLimits);

            // ReSharper disable LocalVariableHidesMember
            float diameterMax        = 0;
            float diameterMin        = float.PositiveInfinity;
            float lengthMax          = 0;
            float lengthMin          = float.PositiveInfinity;
            float volumeMax          = 0;
            float volumeMin          = float.PositiveInfinity;
            float aspectMin          = 0;
            float aspectMax          = float.PositiveInfinity;
            bool  allowCurveTweaking = false;

            foreach (TechLimit limit in techLimits)
            {
                if (ResearchAndDevelopment.GetTechnologyState(limit.name) != RDTech.State.Available)
                {
                    continue;
                }

                if (limit.diameterMin < diameterMin)
                {
                    diameterMin = limit.diameterMin;
                }
                if (limit.diameterMax > diameterMax)
                {
                    diameterMax = limit.diameterMax;
                }
                if (limit.lengthMin < lengthMin)
                {
                    lengthMin = limit.lengthMin;
                }
                if (limit.lengthMax > lengthMax)
                {
                    lengthMax = limit.lengthMax;
                }
                if (limit.volumeMin < volumeMin)
                {
                    volumeMin = limit.volumeMin;
                }
                if (limit.volumeMax > volumeMax)
                {
                    volumeMax = limit.volumeMax;
                }
                if (limit.aspectMin < aspectMin)
                {
                    aspectMin = limit.aspectMin;
                }
                if (limit.aspectMax > aspectMax)
                {
                    aspectMax = limit.aspectMax;
                }
                if (limit.allowCurveTweaking)
                {
                    allowCurveTweaking = true;
                }
            }

            // ReSharper disable CompareOfFloatsByEqualityOperator
            if (diameterMax == 0)
            {
                diameterMax = float.PositiveInfinity;
            }
            if (float.IsInfinity(diameterMin))
            {
                diameterMin = 0.01f;
            }
            if (lengthMax == 0)
            {
                lengthMax = float.PositiveInfinity;
            }
            if (float.IsInfinity(lengthMin))
            {
                lengthMin = 0.01f;
            }
            if (volumeMax == 0)
            {
                volumeMax = float.PositiveInfinity;
            }
            if (float.IsInfinity(volumeMin))
            {
                volumeMin = 0.01f;
            }
            if (aspectMax == 0)
            {
                aspectMax = float.PositiveInfinity;
            }
            if (float.IsInfinity(aspectMin))
            {
                aspectMin = 0.01f;
            }
            // ReSharper restore CompareOfFloatsByEqualityOperator

            this.diameterMax        = Mathf.Min(this.diameterMax, diameterMax);
            this.diameterMin        = Mathf.Max(this.diameterMin, diameterMin);
            this.lengthMax          = Mathf.Min(this.lengthMax, lengthMax);
            this.lengthMin          = Mathf.Max(this.lengthMin, lengthMin);
            this.volumeMax          = Mathf.Min(this.volumeMax, volumeMax);
            this.volumeMin          = Mathf.Max(this.volumeMin, volumeMin);
            this.aspectMax          = Mathf.Min(this.aspectMax, aspectMax);
            this.aspectMin          = Mathf.Max(this.aspectMin, aspectMin);
            this.allowCurveTweaking = this.allowCurveTweaking && allowCurveTweaking;
            // ReSharper restore LocalVariableHidesMember

            //Debug.Log(string.Format("TechLimits applied: diameter=({0:G3}, {1:G3}) length=({2:G3}, {3:G3}) volume=({4:G3}, {5:G3}) allowCurveTweaking={6}", diameterMin, diameterMax, lengthMin, lengthMax, volumeMin, volumeMax, allowCurveTweaking));
        }