示例#1
0
        public override void OnFixedUpdate()
        {
            float global_rate_multipliers = 1;

            crew_capacity_ratio     = ((float)part.protoModuleCrew.Count) / ((float)part.CrewCapacity);
            global_rate_multipliers = global_rate_multipliers * crew_capacity_ratio;

            if (ResearchAndDevelopment.Instance != null)
            {
                if (!double.IsNaN(science_awaiting_addition) && !double.IsInfinity(science_awaiting_addition) && science_awaiting_addition > 0)
                {
                    ResearchAndDevelopment.Instance.Science = ResearchAndDevelopment.Instance.Science + (float)science_awaiting_addition;
                    ScreenMessages.PostScreenMessage(science_awaiting_addition.ToString("0") + " science has been added to the R&D centre.", 2.5f, ScreenMessageStyle.UPPER_CENTER);
                    science_awaiting_addition = 0;
                }
            }

            if (IsEnabled)
            {
                if (active_mode == 0)   // Research
                {
                    double electrical_power_provided = consumeFNResource(GameConstants.basePowerConsumption * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES);
                    electrical_power_ratio  = (float)(electrical_power_provided / TimeWarp.fixedDeltaTime / GameConstants.basePowerConsumption);
                    global_rate_multipliers = global_rate_multipliers * electrical_power_ratio;
                    float stupidity = 0;
                    foreach (ProtoCrewMember proto_crew_member in part.protoModuleCrew)
                    {
                        stupidity += proto_crew_member.stupidity;
                    }
                    stupidity = 1.5f - stupidity / 2.0f;
                    float altitude_multiplier = (float)(vessel.altitude / (vessel.mainBody.Radius));
                    altitude_multiplier = Math.Max(altitude_multiplier, 1);
                    science_rate_f      = (float)(GameConstants.baseScienceRate * PluginHelper.getScienceMultiplier(vessel.mainBody.flightGlobalsIndex, vessel.LandedOrSplashed) / 86400.0f * global_rate_multipliers * stupidity / (Mathf.Sqrt(altitude_multiplier)));
                    if (ResearchAndDevelopment.Instance != null)
                    {
                        if (!double.IsNaN(science_rate_f) && !double.IsInfinity(science_rate_f))
                        {
                            ResearchAndDevelopment.Instance.Science = ResearchAndDevelopment.Instance.Science + science_rate_f * TimeWarp.fixedDeltaTime;
                        }
                    }
                }
                else if (active_mode == 1)     // Fuel Reprocessing
                {
                    double electrical_power_provided = consumeFNResource(GameConstants.basePowerConsumption * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES);
                    electrical_power_ratio  = (float)(electrical_power_provided / TimeWarp.fixedDeltaTime / GameConstants.basePowerConsumption);
                    global_rate_multipliers = global_rate_multipliers * electrical_power_ratio;
                    reprocessor.performReprocessingFrame(global_rate_multipliers);
                    if (reprocessor.getActinidesRemovedPerHour() > 0)
                    {
                        reprocessing_rate_f = (float)(reprocessor.getRemainingAmountToReprocess() / reprocessor.getActinidesRemovedPerHour());
                    }
                    else
                    {
                        IsEnabled = false;
                    }
                }
                else if (active_mode == 2)     //Antimatter
                {
                    double electrical_power_provided = consumeFNResource(GameConstants.baseAMFPowerConsumption * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES);
                    electrical_power_ratio  = (float)(electrical_power_provided / TimeWarp.fixedDeltaTime / GameConstants.baseAMFPowerConsumption);
                    global_rate_multipliers = crew_capacity_ratio * electrical_power_ratio;
                    anti_factory.produceAntimatterFrame(global_rate_multipliers);
                    antimatter_rate_f = (float)anti_factory.getAntimatterProductionRate();
                }
                else if (active_mode == 3)
                {
                    IsEnabled = false;
                }
                else if (active_mode == 4)     // Centrifuge
                {
                    if (vessel.Splashed)
                    {
                        float electrical_power_provided = consumeFNResource(GameConstants.baseCentriPowerConsumption * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES);
                        electrical_power_ratio  = (float)(electrical_power_provided / TimeWarp.fixedDeltaTime / GameConstants.baseCentriPowerConsumption);
                        global_rate_multipliers = global_rate_multipliers * electrical_power_ratio;
                        float deut_produced = (float)(global_rate_multipliers * GameConstants.deuterium_timescale * GameConstants.deuterium_abudance * 1000.0f);
                        deut_rate_f = -ORSHelper.fixedRequestResource(part, "Deuterium", -deut_produced * TimeWarp.fixedDeltaTime) / TimeWarp.fixedDeltaTime;
                    }
                    else
                    {
                        ScreenMessages.PostScreenMessage("You must be splashed down to perform this activity.", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                        IsEnabled = false;
                    }
                }

                if (electrical_power_ratio <= 0)
                {
                    deut_rate_f         = 0;
                    electrolysis_rate_f = 0;
                    science_rate_f      = 0;
                    antimatter_rate_f   = 0;
                    reprocessing_rate_f = 0;
                }

                last_active_time = (float)Planetarium.GetUniversalTime();
            }
            else
            {
            }
        }
示例#2
0
 public override void OnFixedUpdate()
 {
     if (IsEnabled)
     {
         if (active_mode == 0)   // Fuel Reprocessing
         {
             double electrical_power_provided = consumeFNResource(GameConstants.basePowerConsumption * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES);
             electrical_power_ratio = (float)(electrical_power_provided / TimeWarp.fixedDeltaTime / GameConstants.basePowerConsumption);
             reprocessor.performReprocessingFrame(electrical_power_ratio);
             if (reprocessor.getActinidesRemovedPerHour() > 0)
             {
                 reprocessing_rate_d = reprocessor.getRemainingAmountToReprocess() / reprocessor.getActinidesRemovedPerHour();
             }
             else
             {
                 ScreenMessages.PostScreenMessage("Unable to Reprocess Nuclear Fuel", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                 IsEnabled = false;
             }
         }
         else if (active_mode == 1)     // Aluminium Electrolysis
         {
             double electrical_power_provided = consumeFNResource((GameConstants.baseELCPowerConsumption) * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES);
             electrical_power_ratio = (float)(electrical_power_provided / TimeWarp.fixedDeltaTime / GameConstants.baseELCPowerConsumption);
             double density_alumina   = PartResourceLibrary.Instance.GetDefinition("Alumina").density;
             double aluminium_density = PartResourceLibrary.Instance.GetDefinition(PluginHelper.aluminium_resource_name).density;
             double oxygen_density    = PartResourceLibrary.Instance.GetDefinition(PluginHelper.oxygen_resource_name).density;
             electrolysis_rate_d = electrical_power_provided / GameConstants.aluminiumElectrolysisEnergyPerTon / TimeWarp.fixedDeltaTime;
             double alumina_consumption_rate = part.RequestResource("Alumina", electrolysis_rate_d * TimeWarp.fixedDeltaTime / density_alumina) / TimeWarp.fixedDeltaTime * density_alumina;
             double mass_rate = alumina_consumption_rate;
             electrolysis_rate_d  = part.RequestResource(PluginHelper.aluminium_resource_name, -mass_rate * TimeWarp.fixedDeltaTime / aluminium_density) * aluminium_density;
             electrolysis_rate_d += part.RequestResource(PluginHelper.oxygen_resource_name, -GameConstants.aluminiumElectrolysisMassRatio * mass_rate * TimeWarp.fixedDeltaTime / oxygen_density) * oxygen_density;
             electrolysis_rate_d  = electrolysis_rate_d / TimeWarp.fixedDeltaTime;
         }
         else if (active_mode == 2)     // Sabatier ISRU
         {
             if (FlightGlobals.getStaticPressure(vessel.transform.position) * ORSAtmosphericResourceHandler.getAtmosphericResourceContentByDisplayName(vessel.mainBody.flightGlobalsIndex, "Carbon Dioxide") >= 0.01)
             {
                 double electrical_power_provided = consumeFNResource((GameConstants.baseELCPowerConsumption) * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES);
                 electrical_power_ratio = (float)(electrical_power_provided / TimeWarp.fixedDeltaTime / GameConstants.baseELCPowerConsumption);
                 electrolysis_rate_d    = electrical_power_provided / GameConstants.electrolysisEnergyPerTon * vessel.atmDensity / TimeWarp.fixedDeltaTime;
                 double hydrogen_rate = electrolysis_rate_d / (1 + GameConstants.electrolysisMassRatio);
                 double oxygen_rate   = hydrogen_rate * GameConstants.electrolysisMassRatio;
                 double density_h     = PartResourceLibrary.Instance.GetDefinition(PluginHelper.hydrogen_resource_name).density;
                 double density_o     = PartResourceLibrary.Instance.GetDefinition(PluginHelper.oxygen_resource_name).density;
                 double density_ch4   = PartResourceLibrary.Instance.GetDefinition(PluginHelper.methane_resource_name).density;
                 double h2_rate       = part.RequestResource(PluginHelper.hydrogen_resource_name, hydrogen_rate * TimeWarp.fixedDeltaTime / density_h / 2);
                 if (h2_rate > 0)
                 {
                     double o_rate       = part.RequestResource(PluginHelper.oxygen_resource_name, -oxygen_rate * TimeWarp.fixedDeltaTime / density_o);
                     double methane_rate = electrolysis_rate_d / 4.5;
                     methane_rate_d = -part.RequestResource(PluginHelper.methane_resource_name, -methane_rate * TimeWarp.fixedDeltaTime / density_ch4) * density_ch4 / TimeWarp.fixedDeltaTime;
                 }
             }
             else
             {
                 ScreenMessages.PostScreenMessage("Ambient C02 insufficient.", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                 IsEnabled = false;
             }
         }
         else if (active_mode == 3)     // Water Electrolysis
         {
             double density_h   = PartResourceLibrary.Instance.GetDefinition(PluginHelper.hydrogen_resource_name).density;
             double density_o   = PartResourceLibrary.Instance.GetDefinition(PluginHelper.oxygen_resource_name).density;
             double density_h2o = PartResourceLibrary.Instance.GetDefinition(PluginHelper.water_resource_name).density;
             double electrical_power_provided = consumeFNResource((GameConstants.baseELCPowerConsumption) * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES);
             electrical_power_ratio = (float)(electrical_power_provided / TimeWarp.fixedDeltaTime / GameConstants.baseELCPowerConsumption);
             electrolysis_rate_d    = electrical_power_provided / GameConstants.electrolysisEnergyPerTon / TimeWarp.fixedDeltaTime;
             double water_consumption_rate = part.RequestResource(PluginHelper.water_resource_name, electrolysis_rate_d * TimeWarp.fixedDeltaTime / density_h2o) / TimeWarp.fixedDeltaTime * density_h2o;
             double hydrogen_rate          = water_consumption_rate / (1 + GameConstants.electrolysisMassRatio);
             double oxygen_rate            = hydrogen_rate * GameConstants.electrolysisMassRatio;
             electrolysis_rate_d  = part.RequestResource(PluginHelper.hydrogen_resource_name, -hydrogen_rate * TimeWarp.fixedDeltaTime / density_h);
             electrolysis_rate_d += part.RequestResource(PluginHelper.oxygen_resource_name, -oxygen_rate * TimeWarp.fixedDeltaTime / density_o);
             electrolysis_rate_d  = electrolysis_rate_d / TimeWarp.fixedDeltaTime * density_h;
         }
         else if (active_mode == 4)     // Anthraquinone Process
         {
             double density_h2o  = PartResourceLibrary.Instance.GetDefinition(PluginHelper.water_resource_name).density;
             double density_h2o2 = PartResourceLibrary.Instance.GetDefinition(PluginHelper.hydrogen_peroxide_resource_name).density;
             double electrical_power_provided = consumeFNResource((GameConstants.baseAnthraquiononePowerConsumption) * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES);
             electrical_power_ratio = (float)(electrical_power_provided / TimeWarp.fixedDeltaTime / GameConstants.baseAnthraquiononePowerConsumption);
             anthra_rate_d          = electrical_power_provided / GameConstants.anthraquinoneEnergyPerTon / TimeWarp.fixedDeltaTime;
             double water_consumption_rate = part.RequestResource(PluginHelper.water_resource_name, anthra_rate_d * TimeWarp.fixedDeltaTime / density_h2o) / TimeWarp.fixedDeltaTime * density_h2o;
             anthra_rate_d = -part.RequestResource(PluginHelper.hydrogen_peroxide_resource_name, -water_consumption_rate * TimeWarp.fixedDeltaTime / density_h2o2) * density_h2o2 / TimeWarp.fixedDeltaTime;
             if (water_consumption_rate <= 0 && electrical_power_ratio > 0)
             {
                 ScreenMessages.PostScreenMessage("Water is required to perform the Anthraquinone Process.", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                 IsEnabled = false;
             }
         }
         else if (active_mode == 5)     // Monoprop Production
         {
             double density_h2o2              = PartResourceLibrary.Instance.GetDefinition(PluginHelper.hydrogen_peroxide_resource_name).density;
             double density_ammonia           = PartResourceLibrary.Instance.GetDefinition(PluginHelper.ammonia_resource_name).density;
             double electrical_power_provided = consumeFNResource((GameConstants.basePechineyUgineKuhlmannPowerConsumption) * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES);
             electrical_power_ratio = (float)(electrical_power_provided / TimeWarp.fixedDeltaTime / GameConstants.basePechineyUgineKuhlmannPowerConsumption);
             monoprop_rate_d        = electrical_power_provided / GameConstants.pechineyUgineKuhlmannEnergyPerTon / TimeWarp.fixedDeltaTime;
             double ammonia_consumption_rate = part.RequestResource(PluginHelper.ammonia_resource_name, 0.5 * monoprop_rate_d * (1 - GameConstants.pechineyUgineKuhlmannMassRatio) * TimeWarp.fixedDeltaTime / density_ammonia) * density_ammonia / TimeWarp.fixedDeltaTime;
             double h202_consumption_rate    = part.RequestResource(PluginHelper.hydrogen_peroxide_resource_name, 0.5 * monoprop_rate_d * GameConstants.pechineyUgineKuhlmannMassRatio * TimeWarp.fixedDeltaTime / density_h2o2) * density_h2o2 / TimeWarp.fixedDeltaTime;
             if (ammonia_consumption_rate > 0 && h202_consumption_rate > 0)
             {
                 double mono_prop_produciton_rate = ammonia_consumption_rate + h202_consumption_rate;
                 double density_monoprop          = PartResourceLibrary.Instance.GetDefinition("MonoPropellant").density;
                 monoprop_rate_d = -ORSHelper.fixedRequestResource(part, "MonoPropellant", -mono_prop_produciton_rate * TimeWarp.fixedDeltaTime / density_monoprop) * density_monoprop / TimeWarp.fixedDeltaTime;
             }
             else
             {
                 if (electrical_power_ratio > 0)
                 {
                     monoprop_rate_d = 0;
                     ScreenMessages.PostScreenMessage("Ammonia and Hydrogen Peroxide are required to produce Monopropellant.", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                     IsEnabled = false;
                 }
             }
         }
         else if (active_mode == 6)
         {
             double density_ammonia           = PartResourceLibrary.Instance.GetDefinition(PluginHelper.ammonia_resource_name).density;
             double density_uf4               = PartResourceLibrary.Instance.GetDefinition("UF4").density;
             double density_un                = PartResourceLibrary.Instance.GetDefinition("UraniumNitride").density;
             double electrical_power_provided = consumeFNResource((GameConstants.baseUraniumAmmonolysisConsumption) * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES);
             electrical_power_ratio = (float)(electrical_power_provided / TimeWarp.fixedDeltaTime / GameConstants.baseUraniumAmmonolysisConsumption);
             double lpersec       = GameConstants.baseUraniumAmmonolysisRate * electrical_power_ratio;
             double uf4persec     = lpersec * 1.24597 / density_uf4;
             double unpersec      = lpersec / density_un;
             double ammoniapersec = lpersec * 0.901 / density_ammonia;
             double uf4_rate      = ORSHelper.fixedRequestResource(part, "UF4", uf4persec * TimeWarp.fixedDeltaTime);
             double ammonia_rate  = ORSHelper.fixedRequestResource(part, PluginHelper.ammonia_resource_name, uf4persec * TimeWarp.fixedDeltaTime);
             if (uf4_rate > 0 && ammonia_rate > 0)
             {
                 uranium_nitride_rate_d = -ORSHelper.fixedRequestResource(part, "UraniumNitride", -uf4_rate * density_uf4 / 1.24597 / density_un) / TimeWarp.fixedDeltaTime * density_un;
             }
             else
             {
                 if (electrical_power_ratio > 0)
                 {
                     uranium_nitride_rate_d = 0;
                     ScreenMessages.PostScreenMessage("Uranium Tetraflouride and Ammonia are required to produce Uranium Nitride.", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                     IsEnabled = false;
                 }
             }
         }
     }
     else
     {
     }
 }