// calculate a cache entry for the vessel static vessel_info Compute(Vessel v) { 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.env_radiation = info.cosmic_radiation + info.belt_radiation + info.storm_radiation; info.breathable = Sim.Breathable(v); foreach(var p in Kerbalism.rules) { Rule r = p.Value; if (r.resource_name.Length > 0) { var vmon = new vmon_cache(); vmon.depletion = r.EstimateLifetime(v); double amount = Lib.GetResourceAmount(v, r.resource_name); double capacity = Lib.GetResourceCapacity(v, r.resource_name); vmon.level = capacity > double.Epsilon ? amount / capacity : 1.0; //< level is 1 with no capacity info.vmon.Add(p.Value.name, vmon); } } return info; }
// 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; }