void VesselRecovered(ProtoVessel pv, bool b) { // note: this is called multiple times when a vessel is recovered // for each crew member foreach (ProtoCrewMember c in pv.GetVesselCrew()) { // avoid creating kerbal data in db again, // as this function may be called multiple times if (!DB.ContainsKerbal(c.name)) { continue; } // set roster status of eva dead kerbals if (DB.Kerbal(c.name).eva_dead) { c.rosterStatus = ProtoCrewMember.RosterStatus.Dead; } // reset kerbal data of recovered kerbals DB.RecoverKerbal(c.name); } // purge the caches ResourceCache.Purge(pv); Cache.PurgeVesselCaches(pv); }
void VesselDestroyed(Vessel v) { // rescan the damn kerbals // - vessel crew is empty at destruction time // - we can't even use the flightglobal roster, because sometimes it isn't updated yet at this point HashSet <string> kerbals_alive = new HashSet <string>(); HashSet <string> kerbals_dead = new HashSet <string>(); foreach (Vessel ov in FlightGlobals.Vessels) { foreach (ProtoCrewMember c in Lib.CrewList(ov)) { kerbals_alive.Add(c.name); } } foreach (string key in DB.Kerbals().Keys) { if (!kerbals_alive.Contains(key)) { kerbals_dead.Add(key); } } foreach (string n in kerbals_dead) { // we don't know if the kerbal really is dead, or if it is just not currently assigned to a mission DB.KillKerbal(n, false); } // purge the caches ResourceCache.Purge(v); // works with loaded and unloaded vessels //Drive.Purge(v); // works with loaded and unloaded vessels Cache.PurgeVesselCaches(v); // works with loaded and unloaded vessels }
void FromEVA(GameEvents.FromToAction <Part, Part> data) { // contract configurator calls this event with both parts being the same when it adds a passenger if (data.from == data.to) { return; } String prop_name = Lib.EvaPropellantName(); // for each resource in the eva kerbal for (int i = 0; i < data.from.Resources.Count; ++i) { // get the resource PartResource res = data.from.Resources[i]; // add leftovers to the vessel data.to.RequestResource(res.resourceName, -res.amount); } // merge drives data Drive.Transfer(data.from.vessel, data.to.vessel, true); // forget EVA vessel data Cache.PurgeVesselCaches(data.from.vessel); //Drive.Purge(data.from.vessel); // update boarded vessel this.OnVesselModified(data.to.vessel); // execute script data.to.vessel.KerbalismData().computer.Execute(data.to.vessel, ScriptType.eva_in); }
private void OnVesselModified(Vessel vessel) { foreach (var emitter in vessel.FindPartModulesImplementing <Emitter>()) { emitter.Recalculate(); } Cache.PurgeVesselCaches(vessel); //vessel.KerbalismData().UpdateOnVesselModified(); }
void VesselTerminated(ProtoVessel pv) { // forget all kerbals data foreach (ProtoCrewMember c in pv.GetVesselCrew()) { DB.KillKerbal(c.name, true); } // purge the caches ResourceCache.Purge(pv); Cache.PurgeVesselCaches(pv); //Drive.Purge(pv); }
void VesselTerminated(ProtoVessel pv) { // forget all kerbals data foreach (ProtoCrewMember c in pv.GetVesselCrew()) { DB.KillKerbal(c.name, true); } // purge the caches ResourceCache.Purge(pv); Cache.PurgeVesselCaches(pv); // delete data on unloaded vessels only (this is handled trough OnPartWillDie for loaded vessels) if (pv.vesselRef != null && !pv.vesselRef.loaded) { Drive.DeleteDrivesData(pv.vesselRef); } }
void VesselDock(GameEvents.FromToAction <Part, Part> e) { Cache.PurgeVesselCaches(e.from.vessel); // Update docked to vessel this.OnVesselModified(e.to.vessel); }
void FromEVA(GameEvents.FromToAction <Part, Part> data) { // contract configurator calls this event with both parts being the same when it adds a passenger if (data.from == data.to) { return; } // for each resource in the eva kerbal for (int i = 0; i < data.from.Resources.Count; ++i) { // get the resource PartResource res = data.from.Resources[i]; // add leftovers to the vessel data.to.RequestResource(res.resourceName, -res.amount); } #if !KSP15_16 && !KSP17 && !KSP18 && !KSP110 string evaPropName = Lib.EvaPropellantName(); if (evaPropName != "EVA Propellant") { KerbalEVA kerbalEVA = data.from.FindModuleImplementing <KerbalEVA>(); List <ProtoPartResourceSnapshot> propContainers = new List <ProtoPartResourceSnapshot>(); if (kerbalEVA.ModuleInventoryPartReference != null) { foreach (StoredPart storedPart in kerbalEVA.ModuleInventoryPartReference.storedParts.Values) { ProtoPartResourceSnapshot propContainer = storedPart.snapshot.resources.Find(p => p.resourceName == evaPropName); if (propContainer != null && propContainer.amount > 0.0) { propContainers.Add(propContainer); } } } if (propContainers.Count > 0) { // get vessel resources handler ResourceInfo evaPropOnVessel = ResourceCache.GetResource(data.to.vessel, evaPropName); double storageAvailable = evaPropOnVessel.Capacity - evaPropOnVessel.Amount; foreach (ProtoPartResourceSnapshot propContainer in propContainers) { double stored = Math.Min(propContainer.amount, storageAvailable); storageAvailable -= stored; evaPropOnVessel.Produce(stored, ResourceBroker.Generic); propContainer.amount = Math.Max(propContainer.amount - stored, 0.0); if (storageAvailable <= 0.0) { break; } } // Explaination : // - The ProtoCrewMember has already been removed from the EVA part and added to the vessel part // - It's inventory has already been saved // - The stock ModuleInventoryPart.RefillEVAPropellantOnBoarding() method has already been called // So to set the correct amount of EVA prop, we : // - Harmony patch ModuleInventoryPart.RefillEVAPropellantOnBoarding() so it doesn't refill anything // - Grab the ProtoCrewMember on the vessel part // - Call the SaveInventory() method again, with the modified amount on the inventory StoredPart data.to.protoModuleCrew[data.to.protoModuleCrew.Count - 1].SaveInventory(kerbalEVA.ModuleInventoryPartReference); } } #endif // merge drives data Drive.Transfer(data.from.vessel, data.to.vessel, true); // forget EVA vessel data Cache.PurgeVesselCaches(data.from.vessel); //Drive.Purge(data.from.vessel); // update boarded vessel this.OnVesselModified(data.to.vessel); // execute script data.to.vessel.KerbalismData().computer.Execute(data.to.vessel, ScriptType.eva_in); }