Esempio n. 1
0
 public ProductionTable(ModelObject owner) : base(owner)
 {
     if (owner is ProjectPage)
     {
         modules = new ModuleFillerParameters(this);
     }
 }
Esempio n. 2
0
        public void CalculateParameters(Recipe recipe, Entity entity, Goods fuel, Item module, IInputSettingsProvider settingsProvider, ModuleFillerParameters moduleFiller)
        {
            warningFlags = 0;
            if (entity == null)
            {
                warningFlags        |= WarningFlags.EntityNotSpecified;
                recipeTime           = recipe.time;
                productionMultiplier = 1f;
            }
            else
            {
                recipeTime           = recipe.time / entity.craftingSpeed;
                productionMultiplier = 1f * (1f + entity.productivity);
                var energyUsage = entity.power * entity.energy.effectivity;

                if (recipe.flags.HasFlags(RecipeFlags.ScaleProductionWithPower) && fuel != Database.voidEnergy)
                {
                    warningFlags |= WarningFlags.FuelWithTemperatureNotLinked;
                }

                // Special case for fuel
                if (fuel != null)
                {
                    var fluid    = fuel.fluid;
                    var energy   = entity.energy;
                    var usesHeat = fluid != null && energy.usesHeat;
                    if (usesHeat)
                    {
                        if (!settingsProvider.GetTemperature(fluid, out var minTemp, out var maxTemp))
                        {
                            fuelUsagePerSecondPerBuilding = 0;
                        }
                        else
                        {
                            // TODO research this case;
                            if (minTemp != maxTemp)
                            {
                                warningFlags |= WarningFlags.TemperatureRangeForFuelNotImplemented;
                            }
                            if (minTemp > energy.maxTemperature)
                            {
                                minTemp       = energy.maxTemperature;
                                warningFlags |= WarningFlags.FuelTemperatureExceedsMaximum;
                            }

                            var heatCap = fluid.heatCapacity;
                            var energyPerUnitOfFluid = (minTemp - energy.minTemperature) * heatCap;
                            if (energyPerUnitOfFluid <= 0f)
                            {
                                fuelUsagePerSecondPerBuilding = float.NaN;
                                warningFlags |= WarningFlags.FuelTemperatureLessThanMinimum;
                            }
                            var maxEnergyProduction = energy.fluidLimit * energyPerUnitOfFluid;
                            if (maxEnergyProduction < energyUsage || energyUsage <= 0) // limited by fluid limit
                            {
                                if (energyUsage <= 0)
                                {
                                    recipeTime *= energyUsage / maxEnergyProduction;
                                }
                                energyUsage = maxEnergyProduction * entity.energy.effectivity;
                                fuelUsagePerSecondPerBuilding = energy.fluidLimit;
                            }
                            else // limited by energy usage
                            {
                                fuelUsagePerSecondPerBuilding = energyUsage / energyPerUnitOfFluid;
                            }
                        }
                    }
                    else
                    {
                        fuelUsagePerSecondPerBuilding = energyUsage / fuel.fuelValue;
                    }

                    if (recipe.flags.HasFlags(RecipeFlags.ScaleProductionWithPower) && energyUsage > 0f)
                    {
                        recipeTime    = 1f / energyUsage;
                        warningFlags &= ~WarningFlags.FuelWithTemperatureNotLinked;
                    }
                }