예제 #1
0
    /// <summary>
    ///   Calculates the maximum speed a process can run at in a biome
    ///   based on the environmental compounds.
    /// </summary>
    private static ProcessSpeedInformation CalculateProcessMaximumSpeed(TweakedProcess process,
                                                                        BiomeConditions biome)
    {
        var result = new ProcessSpeedInformation(process.Process);

        float speedFactor = 1.0f;

        // Environmental inputs need to be processed first
        foreach (var entry in process.Process.Inputs)
        {
            if (!entry.Key.IsEnvironmental)
            {
                continue;
            }

            // Environmental compound that can limit the rate

            var input = new ProcessSpeedInformation.EnvironmentalInput(entry.Key, entry.Value);

            var availableInEnvironment = GetDissolvedInBiome(entry.Key, biome);

            input.AvailableAmount = availableInEnvironment;

            // More than needed environment value boosts the effectiveness
            input.AvailableRate = availableInEnvironment / entry.Value;

            speedFactor *= input.AvailableRate;

            result.EnvironmentInputs[entry.Key] = input;
        }

        speedFactor *= process.Rate;

        // So that the speedfactor is available here
        foreach (var entry in process.Process.Inputs)
        {
            if (entry.Key.IsEnvironmental)
            {
                continue;
            }

            // Normal, cloud input

            var input = new ProcessSpeedInformation.CompoundAmount(entry.Key, entry.Value * speedFactor);

            result.OtherInputs.Add(entry.Key, input);
        }

        foreach (var entry in process.Process.Outputs)
        {
            var output = new ProcessSpeedInformation.CompoundAmount(entry.Key,
                                                                    entry.Value * speedFactor);

            result.Outputs[entry.Key] = output;
        }

        result.SpeedFactor = speedFactor;

        return(result);
    }
예제 #2
0
    /// <summary>
    ///   Calculates the maximum speed a process can run at in a biome
    ///   based on the environmental compounds.
    /// </summary>
    private static ProcessSpeedInformation CalculateProcessMaximumSpeed(TweakedProcess process,
                                                                        BiomeConditions biome)
    {
        var result = new ProcessSpeedInformation(process.Process);

        float speedFactor = 1.0f;

        // Environmental inputs need to be processed first
        foreach (var entry in process.Process.Inputs)
        {
            if (!entry.Key.IsEnvironmental)
            {
                continue;
            }

            // Environmental compound that can limit the rate

            var availableInEnvironment = GetDissolvedInBiome(entry.Key, biome);

            var availableRate = availableInEnvironment / entry.Value;

            result.AvailableAmounts[entry.Key] = availableInEnvironment;

            // More than needed environment value boosts the effectiveness
            result.AvailableRates[entry.Key] = availableRate;

            speedFactor *= availableRate;

            result.WritableInputs[entry.Key] = entry.Value;
        }

        speedFactor *= process.Rate;

        // Note that we don't consider storage constraints here so we don't use spaceConstraintModifier calculations

        // So that the speed factor is available here
        foreach (var entry in process.Process.Inputs)
        {
            if (entry.Key.IsEnvironmental)
            {
                continue;
            }

            // Normal, cloud input

            result.WritableInputs.Add(entry.Key, entry.Value * speedFactor);
        }

        foreach (var entry in process.Process.Outputs)
        {
            var amount = entry.Value * speedFactor;

            result.WritableOutputs[entry.Key] = amount;

            if (amount <= 0)
            {
                result.WritableLimitingCompounds.Add(entry.Key);
            }
        }

        result.CurrentSpeed = speedFactor;

        return(result);
    }