private void handleUnloadCrew(Vessel ves, bool savereturn) { foreach (Part p in ves.parts) { if (p.CrewCapacity > 0 && p.protoModuleCrew.Count > 0) { for (int i = p.protoModuleCrew.Count - 1; i >= 0; i--) { unloadCrew(p.protoModuleCrew[i], p, savereturn); } } } ves.DespawnCrew(); }
public static void RemoveAllCrew(this Vessel vessel) { foreach (var part in vessel.Parts) { foreach (var crew in part.protoModuleCrew) { vessel.RemoveCrew(crew); } } foreach (var crew in vessel.GetVesselCrew()) { vessel.RemoveCrew(crew); } vessel.DespawnCrew(); }
private void KillVessel(Vessel killVessel) { if (killVessel != null) { //TODO: Deselect the vessel in the tracking station if we are about to kill it. DarkLog.Debug("Killing vessel: " + killVessel.id.ToString()); killVessel.DespawnCrew(); //Add it to the delay kill list to make sure it dies. //With KSP, If it doesn't work first time, keeping doing it until it does. if (!delayKillVessels.Contains(killVessel)) { delayKillVessels.Add(killVessel); } lastKillVesselDestroy[killVessel.id.ToString()] = UnityEngine.Time.realtimeSinceStartup; try { if (killVessel.parts != null) { try { for (int partID = killVessel.parts.Count - 1; partID >= 0; partID--) { Part killPart = killVessel.parts[partID]; killPart.explosionPotential = 0f; killPart.Die(); } } catch (Exception partException) { DarkLog.Debug("Error killing parts: " + partException); } } killVessel.Die(); } catch (Exception killException) { DarkLog.Debug("Error destroying vessel: " + killException); } } }
private void KillVessel(Vessel killVessel) { if (killVessel != null) { //TODO: Deselect the vessel in the tracking station if we are about to kill it. DarkLog.Debug("Killing vessel: " + killVessel.id.ToString()); killVessel.DespawnCrew(); //Add it to the delay kill list to make sure it dies. //With KSP, If it doesn't work first time, keeping doing it until it does. if (!delayKillVessels.Contains(killVessel)) { delayKillVessels.Add(killVessel); } lastKillVesselDestroy[killVessel.id.ToString()] = UnityEngine.Time.realtimeSinceStartup; try { killVessel.Die(); } catch (Exception killException) { DarkLog.Debug("Error destroying vessel: " + killException); } } }
public static void respawnCrew(Vessel fromV, Vessel toV) { fromV.DespawnCrew(); toV.DespawnCrew(); toV.StartCoroutine(CallbackUtil.DelayedCallback(1, FlightGlobals.ActiveVessel.SpawnCrew)); }
//store vessel void store_vessel(Vessel vsl, bool perform_checks = true) { StoredVessel stored_vessel = new StoredVessel(); if(perform_checks) //for normal operation { //check momentary states if(!can_store(vsl)) return; //check if the vessel can be stored, if unknown, try to store bool storable; if(!probed_ids.TryGetValue(vsl.id, out storable)) { stored_vessel = try_store(vsl); storable = stored_vessel != null; probed_ids.Add(vsl.id, storable); } if(!storable) return; } else //for storing packed constructs upon hangar launch { stored_vessel = new StoredVessel(vsl); stored_vessels.ForceAdd(stored_vessel); } //get vessel crew on board List<ProtoCrewMember> _crew = new List<ProtoCrewMember>(stored_vessel.crew); CrewTransfer.delCrew(vsl, _crew); vsl.DespawnCrew(); //first of, add crew to the hangar if there's a place CrewTransfer.addCrew(part, _crew); //then add to other vessel parts if needed CrewTransfer.addCrew(vessel, _crew); //recalculate volume and mass change_part_params(stored_vessel.metric); //switch to hangar vessel before storing if(FlightGlobals.ActiveVessel.id == vsl.id) FlightGlobals.ForceSetActiveVessel(vessel); //destroy vessel vsl.Die(); ScreenMessager.showMessage("Vessel has been docked inside the hangar", 3); }
/// <summary> /// Process a vessel that triggered the hangar. /// </summary> /// <param name="vsl">Vessel</param> void process_vessel(Vessel vsl) { //check if this vessel was encountered before; //if so, reset the timer and return MemoryTimer timer; if(probed_vessels.TryGetValue(vsl.id, out timer)) { timer.Reset(); return; } //if the vessel is new, check momentary states if(!hangar_is_ready(vsl)) return; //if the state is OK, try to store the vessel StoredVessel stored_vessel = try_store_vessel(vsl); //if failed, remember it if(stored_vessel == null) { timer = new MemoryTimer(); timer.EndAction += () => { if(probed_vessels.ContainsKey(vsl.id)) probed_vessels.Remove(vsl.id); }; probed_vessels.Add(vsl.id, timer); StartCoroutine(timer); return; } //deactivate the hangar Deactivate(); //calculate velocity change to conserve momentum deltaV = (vsl.orbit.vel-vessel.orbit.vel).xzy*stored_vessel.mass/vessel.GetTotalMass(); change_velocity = true; //get vessel crew on board var _crew = new List<ProtoCrewMember>(stored_vessel.crew); CrewTransfer.delCrew(vsl, _crew); vsl.DespawnCrew(); //first of, add crew to the hangar if there's a place CrewTransfer.addCrew(part, _crew); //then add to other vessel parts if needed CrewTransfer.addCrew(vessel, _crew); //switch to hangar vessel before storing if(FlightGlobals.ActiveVessel.id == vsl.id) FlightGlobals.ForceSetActiveVessel(vessel); //destroy vessel vsl.Die(); ScreenMessager.showMessage("\"{0}\" has been docked inside the hangar", stored_vessel.name); }
private void KillVessel(Vessel killVessel) { if (killVessel != null) { //TODO: Deselect the vessel in the tracking station if we are about to kill it. DarkLog.Debug("Killing vessel: " + killVessel.id.ToString()); killVessel.DespawnCrew(); //Add it to the delay kill list to make sure it dies. //With KSP, If it doesn't work first time, keeping doing it until it does. if (!delayKillVessels.Contains(killVessel)) { delayKillVessels.Add(killVessel); } lastKillVesselDestroy[killVessel.id.ToString()] = UnityEngine.Time.realtimeSinceStartup; if (killVessel.loaded) { try { killVessel.Unload(); } catch (Exception unloadException) { DarkLog.Debug("Error unloading vessel: " + unloadException); } } foreach (ProtoPartSnapshot pps in killVessel.protoVessel.protoPartSnapshots) { foreach (ProtoCrewMember pcm in pps.protoModuleCrew) { DarkLog.Debug("Unassigning " + pcm.name + " from " + killVessel.id.ToString()); pcm.rosterStatus = ProtoCrewMember.RosterStatus.Available; pcm.seatIdx = -1; } pps.protoModuleCrew.Clear(); } try { killVessel.Die(); } catch (Exception killException) { DarkLog.Debug("Error destroying vessel: " + killException); } } }