public static radiation_data analyze_radiation(List<Part> parts, environment_data env, crew_data crew) { // store data radiation_data radiation = new radiation_data(); // scan the parts foreach(Part p in parts) { // accumulate shielding amount and capacity radiation.shielding_amount += Lib.GetResourceAmount(p, "Shielding"); radiation.shielding_capacity += Lib.GetResourceCapacity(p, "Shielding"); } // calculate radiation data double shielding = Radiation.Shielding(radiation.shielding_amount, radiation.shielding_capacity); double belt_strength = Settings.BeltRadiation * Radiation.Dynamo(env.body) * 0.5; //< account for the 'ramp' if (crew.capacity > 0) { radiation.life_expectancy = new double[] { Settings.RadiationFatalThreshold / (Settings.CosmicRadiation * (1.0 - shielding)), Settings.RadiationFatalThreshold / (Settings.StormRadiation * (1.0 - shielding)), Radiation.HasBelt(env.body) ? Settings.RadiationFatalThreshold / (belt_strength * (1.0 - shielding)) : double.NaN }; } else { radiation.life_expectancy = new double[]{double.NaN, double.NaN, double.NaN}; } // return data return radiation; }
void updateConnectedSpaces(Vessel v, vessel_info vi) { // get CLS handler var cls = CLS.get(); // calculate whole-space if (cls == null) { double living_space = QualityOfLife.LivingSpace((uint)vi.crew_count, (uint)vi.crew_capacity); double entertainment = QualityOfLife.Entertainment(v); double shielding = Radiation.Shielding(v); foreach (var c in v.loaded ? v.GetVesselCrew() : v.protoVessel.GetVesselCrew()) { kerbal_data kd = DB.KerbalData(c.name); kd.living_space = living_space; kd.entertainment = entertainment; kd.shielding = shielding; kd.space_name = ""; } } // calculate connected-space // note: avoid problem at scene change else if (cls.Vessel != null && cls.Vessel.Spaces.Count > 0) { // calculate internal spaces foreach (var space in cls.Vessel.Spaces) { double living_space = QualityOfLife.LivingSpace(space); double entertainment = QualityOfLife.Entertainment(v, space); double shielding = Radiation.Shielding(space); foreach (var c in space.Crew) { kerbal_data kd = DB.KerbalData(c.Kerbal.name); kd.living_space = living_space; kd.entertainment = entertainment; kd.shielding = shielding; kd.space_name = space.Name; } } } }
// get vessel info from the cache, or compute a new one and add it to the cache public static vessel_info VesselInfo(Vessel v) { // get the info from the cache, if it exist vessel_info info; if (instance.vessels.TryGetValue(v.id, out info)) return info; // compute vessel info info = new vessel_info(); info.position = Lib.VesselPosition(v); info.sunlight = Sim.RaytraceBody(v, Sim.Sun(), out info.sun_dir, out info.sun_dist); info.temperature = Sim.Temperature(v, info.sunlight); info.cosmic_radiation = Radiation.CosmicRadiation(v); info.belt_radiation = Radiation.BeltRadiation(v); info.storm_radiation = Radiation.StormRadiation(v, info.sunlight); info.radiation = (info.cosmic_radiation + info.belt_radiation + info.storm_radiation) * (1.0 - Radiation.Shielding(v)); // store vessel info in the cache instance.vessels.Add(v.id, info); // return the vessel info return info; }