// implement recycler mechanics public void FixedUpdate() { // do nothing in the editor if (HighLogic.LoadedSceneIsEditor) return; // do nothing until tech tree is ready if (!Lib.TechReady()) return; if (use_efficiency) { // deduce quality from technological level if necessary if (efficiency <= double.Epsilon) efficiency = Scrubber.DeduceEfficiency(); } if (is_enabled) { // get vessel info from the cache vessel_info vi = Cache.VesselInfo(vessel); // do nothing if vessel is invalid if (!vi.is_valid) return; // get elapsed time double elapsed_s = Kerbalism.elapsed_s * vi.time_dilation; // get resource cache vessel_resources resources = ResourceCache.Get(vessel); // recycle EC+waste+filter into resource resource_recipe recipe = new resource_recipe(resource_recipe.scrubber_priority); recipe.Input(waste_name, waste_rate * elapsed_s); recipe.Input("ElectricCharge", ec_rate * elapsed_s); if (filter_name.Length > 0 && filter_rate > double.Epsilon) { recipe.Input(filter_name, filter_rate * elapsed_s); } recipe.Output(resource_name, waste_rate * waste_ratio * efficiency * elapsed_s); resources.Transform(recipe); // set status Status = "Running"; } else { Status = "Off"; } // add efficiency to status if (use_efficiency) Status += Lib.BuildString(" (Efficiency: ", (efficiency * 100.0).ToString("F0"), "%)"); }
public static oxygen_data analyze_oxygen(List<Part> parts, environment_data env, crew_data crew) { // store data oxygen_data oxygen = new oxygen_data(); // get scrubber efficiency oxygen.scrubber_efficiency = Scrubber.DeduceEfficiency(); // calculate oxygen consumed oxygen.consumed = !env.breathable ? (double)crew.count * Settings.OxygenPerSecond : 0.0; // deduce co2 produced by the crew per-second double simulated_co2 = oxygen.consumed; // scan the parts foreach(Part p in parts) { // accumulate food storage oxygen.storage += Lib.GetResourceAmount(p, "Oxygen"); // for each module foreach(PartModule m in p.Modules) { // scrubber if (m.moduleName == "Scrubber") { Scrubber mm = (Scrubber)m; // do nothing inside breathable atmosphere if (mm.is_enabled && !env.breathable) { double co2_scrubbed = Math.Min(simulated_co2, mm.co2_rate); if (co2_scrubbed > double.Epsilon) { oxygen.scrubber_cost += mm.ec_rate * (co2_scrubbed / mm.co2_rate); oxygen.recycled += co2_scrubbed * oxygen.scrubber_efficiency; simulated_co2 -= co2_scrubbed; } } } } } // calculate life expectancy oxygen.life_expectancy = !env.breathable ? oxygen.storage / Math.Max(oxygen.consumed - oxygen.recycled, 0.0) : double.NaN; // return data return oxygen; }