/*************************************************************************************************************************/ public void main_vessel_changed(string save_file) { #if DEBUG // if (Debug_Level_1_Active) Log.PushStackInfo("FMRS_Core.main_vessel_changed", "enter main_vessel_changed(string save_file) " + save_file); if (Debug_Active) { Log.Info("switching main vessel"); } #endif ProtoVessel temp_proto; Game loadgame = GamePersistence.LoadGame(save_file, HighLogic.SaveFolder + "/FMRS", false, false); if (loadgame != null && loadgame.compatible && loadgame.flightState != null) { temp_proto = loadgame.flightState.protoVessels.Find(p => p.vesselID == _SAVE_Main_Vessel); if (temp_proto != null) { if (Vessels_dropped.ContainsKey(temp_proto.vesselID)) { delete_dropped_vessel(temp_proto.vesselID); } Vessels_dropped.Add(temp_proto.vesselID, quicksave_file_name); Vessels_dropped_names.Add(temp_proto.vesselID, temp_proto.vesselName); Vessels.Add(temp_proto.vesselID); } #if DEBUG else if (Debug_Active) { Log.Info("main vessel not found"); } #endif if (Vessels_dropped.ContainsKey(FlightGlobals.ActiveVessel.id)) { delete_dropped_vessel(FlightGlobals.ActiveVessel.id); } _SAVE_Main_Vessel = FlightGlobals.ActiveVessel.id; } #if DEBUG else if (Debug_Active) { Log.Info("unable to load savefile"); } // if (Debug_Level_1_Active) Log.PopStackInfo("leaving main_vessel_changed(string save_file)"); #endif }
/*************************************************************************************************************************/ void vessel_off_rails(Vessel vessel) { Log.PushStackInfo("FMRS_Core.vessel_off_rails", "enter vessel_off_rails(Vessel vessel) {0}", vessel.id); Log.dbg("Vessel will be off rails: {0}", vessel.vesselName); if (_SAVE_Switched_To_Dropped) { Vessel temp_vessel; temp_vessel = FlightGlobals.Vessels.Find(v => v.id == vessel.id); if (temp_vessel != null) { if (temp_vessel.loaded) { if (Vessels_dropped.ContainsKey(vessel.id)) { if (Vessels_dropped[vessel.id] == _SAVE_Switched_To_Savefile) { if (!loaded_vessels.Contains(vessel.id)) { Log.dbg("Vessel will be off rails: adding to loaded_vessels"); loaded_vessels.Add(vessel.id); } } } } } if (vessel.id == FlightGlobals.ActiveVessel.id) { List <Vessel> temp_vessel_list = new List <Vessel>(); temp_vessel_list = FlightGlobals.Vessels.FindAll(v => Vessels_dropped.ContainsKey(v.id) && v.loaded); foreach (Vessel v in temp_vessel_list) { if (Vessels_dropped[v.id] == _SAVE_Switched_To_Savefile) { if (!loaded_vessels.Contains(v.id)) { Log.detail("Vessel will be off rails: adding to loaded_vessels"); loaded_vessels.Add(v.id); } } } } Log.dbg("loaded_vessels: {0}", loaded_vessels.Count); } Log.PopStackInfo("leave vessel_off_rails(Vessel vessel)"); }
/*************************************************************************************************************************/ void vessel_on_rails(Vessel vessel) { List <ProtoCrewMember> member_list = new List <ProtoCrewMember>(); Log.PushStackInfo("FMRS_Core.vessel_on_rails", "enter vessel_on_rails(Vessel vessel) {0}", vessel.id); Log.detail("Vessel will be on rails: {0}", vessel.vesselName); if (Vessels_dropped.ContainsKey(vessel.id) && !_SAVE_Switched_To_Dropped) { Log.dbg("this vessel is listed in dropped dict"); foreach (ProtoPartSnapshot part_snapshot in vessel.protoVessel.protoPartSnapshots) { foreach (ProtoCrewMember member in part_snapshot.protoModuleCrew) { member_list.Add(member); } foreach (ProtoCrewMember member in member_list) { Log.dbg("remove crew member {0}", member.name); part_snapshot.RemoveCrew(member); } member_list.Clear(); } } if (_SAVE_Switched_To_Dropped) { if (loaded_vessels.Contains(vessel.id) && vessel.id != FlightGlobals.ActiveVessel.id && !vessel.Landed && !vessel.Splashed) { Log.detail("loaded_vessels: removing {0}", vessel.id); loaded_vessels.Remove(vessel.id); Log.detail("vessel {0} removed from loaded_vessels", vessel.name); } if (vessel.id == _SAVE_Main_Vessel) { if (ThrottleReplay != null) { vessel.OnFlyByWire -= new FlightInputCallback(ThrottleReplay.flybywire); ThrottleReplay.EndReplay(); } } } Log.PopStackInfo("leave vessel_on_rails(Vessel vessel)"); }
/*************************************************************************************************************************/ public void vessel_change_handler(Vessel change_vessel) { Log.dbg(" #### FMRS: changed to {0}", FlightGlobals.ActiveVessel.vesselName); if (!_SAVE_Switched_To_Dropped) { if (last_staging_event < Planetarium.GetUniversalTime() + 10 && last_staging_event != 0) { if (FlightGlobals.ActiveVessel.id != _SAVE_Main_Vessel && Vessels_dropped.ContainsKey(FlightGlobals.ActiveVessel.id)) { Vessel temp_vessel = FlightGlobals.Vessels.Find(v => v.id == _SAVE_Main_Vessel); if (temp_vessel != null) { if (Vessels_dropped.ContainsKey(_SAVE_Main_Vessel)) { Vessels_dropped.Remove(_SAVE_Main_Vessel); } if (Vessel_State.ContainsKey(_SAVE_Main_Vessel)) { Vessel_State.Remove(_SAVE_Main_Vessel); } if (Vessels_dropped_names.ContainsKey(_SAVE_Main_Vessel)) { Vessels_dropped_names.Remove(_SAVE_Main_Vessel); } if (Vessel_State.ContainsKey(_SAVE_Main_Vessel)) { Vessel_State.Remove(_SAVE_Main_Vessel); } Vessels_dropped.Add(_SAVE_Main_Vessel, Vessels_dropped[FlightGlobals.ActiveVessel.id]); Vessel_State.Add(_SAVE_Main_Vessel, vesselstate.FLY); Vessels_dropped_names.Add(_SAVE_Main_Vessel, temp_vessel.vesselName); foreach (ProtoCrewMember crew_member in temp_vessel.protoVessel.GetVesselCrew()) { Kerbal_dropped.Add(crew_member.name, _SAVE_Main_Vessel); } if (Vessels_dropped.ContainsKey(FlightGlobals.ActiveVessel.id)) { Vessels_dropped.Remove(FlightGlobals.ActiveVessel.id); } if (Vessels_dropped_names.ContainsKey(FlightGlobals.ActiveVessel.id)) { Vessels_dropped_names.Remove(FlightGlobals.ActiveVessel.id); } if (Vessel_State.ContainsKey(FlightGlobals.ActiveVessel.id)) { Vessel_State.Remove(FlightGlobals.ActiveVessel.id); } if (Kerbal_dropped.ContainsValue(FlightGlobals.ActiveVessel.id)) { List <string> kerbals = new List <string>(); foreach (KeyValuePair <string, Guid> kerbal in Kerbal_dropped) { if (kerbal.Value == FlightGlobals.ActiveVessel.id) { kerbals.Add(kerbal.Key); } } foreach (string kerbal in kerbals) { Kerbal_dropped.Remove(kerbal); } } _SAVE_Main_Vessel = FlightGlobals.ActiveVessel.id; } } } else { if (!Vessels_dropped.ContainsKey(change_vessel.id)) { close_FMRS(); } } } else { if (!Vessels_dropped.ContainsKey(FlightGlobals.ActiveVessel.id)) { foreach (Part p in FlightGlobals.ActiveVessel.Parts) { foreach (PartModule pm in p.Modules) { if (pm.moduleName == "FMRS_PM") { Guid temp_guid = new Guid("00000000-0000-0000-0000-000000000000"); try { temp_guid = new Guid((pm as FMRS_PM).parent_vessel); } catch (Exception) { } if (Vessels_dropped.ContainsKey(temp_guid)) { if (Vessels_dropped[temp_guid] == _SAVE_Switched_To_Savefile) { anz_id = temp_guid; } } } } break; } } } }
/*************************************************************************************************************************/ public bool search_for_new_vessels(string save_file_name) { bool new_vessel_found = false, controllable = false; Log.PushStackInfo("FMRS_Core.search_for_new_vessels(string)", "entering search_for_new_vessels(string save_file_name) {0}", save_file_name); foreach (Vessel temp_vessel in FlightGlobals.Vessels) { controllable = false; //Check if the stage was claimed by another mod or by this mod string controllingMod = RecoveryControllerWrapper.ControllingMod(temp_vessel); bool FMRSIsControllingMod = false; if (controllingMod != null) { Log.info("RecoveryControllerWrapper.ControllingMod for vessel: {0} : {1}", temp_vessel.name, controllingMod); FMRSIsControllingMod = string.Equals(controllingMod, "FMRS", StringComparison.OrdinalIgnoreCase); } if (controllingMod == null || string.Equals(controllingMod, "auto", StringComparison.OrdinalIgnoreCase) || FMRSIsControllingMod) { if (!Vessels.Contains(temp_vessel.id)) { if (FMRSIsControllingMod || ( ((temp_vessel.isCommandable && temp_vessel.IsControllable) || (_SETTING_Control_Uncontrollable && controllingMod == null)) && temp_vessel.vesselType != VesselType.EVA && temp_vessel.vesselType != VesselType.Flag && temp_vessel.vesselType != VesselType.SpaceObject && temp_vessel.vesselType != VesselType.Unknown ) ) { controllable = true; } else { foreach (ProtoPartSnapshot proto_part in temp_vessel.protoVessel.protoPartSnapshots) { List <ProtoPartModuleSnapshot> proto_modules = proto_part.modules; ProtoPartModuleSnapshot module = null; if (proto_modules != null && (_SETTING_Parachutes && ((controllingMod != null && string.Equals(controllingMod, "FMRS", StringComparison.OrdinalIgnoreCase)) || !_SETTING_Defer_Parachutes_to_StageRecovery || !stageRecoveryInstalled) ) ) { // module = proto_part.modules.Find(p => p.moduleName == "RealChuteModule" || p.moduleName == "ModuleParachute" || p.moduleName == "ModuleKrKerbalParachute" || p.moduleName == "RealChuteFAR"); if (module != null) { controllable = true; } } if (proto_part.protoCrewNames.Count > 0) { controllable = true; } } } foreach (Part p in temp_vessel.Parts) { foreach (PartModule pm in p.Modules) { if (pm.moduleName == "FMRS_PM") { if ((pm as FMRS_PM).parent_vessel != "00000000-0000-0000-0000-000000000000") { controllable = false; break; } } } break; } if (controllable) { Log.dbg("{0} Found and will be added to the dicts", temp_vessel.vesselName); Vessels_dropped.Add(temp_vessel.id, save_file_name); Vessels_dropped_names.Add(temp_vessel.id, temp_vessel.vesselName); Vessel_State.Add(temp_vessel.id, vesselstate.FLY); foreach (Part p in temp_vessel.Parts) { foreach (PartModule pm in p.Modules) { if (pm.moduleName == "FMRS_PM") { pm.StartCoroutine("setid"); } } } foreach (ProtoPartSnapshot part_snapshot in temp_vessel.protoVessel.protoPartSnapshots) { foreach (ProtoCrewMember member in part_snapshot.protoModuleCrew) { if (!Kerbal_dropped.ContainsKey(member.name)) { Kerbal_dropped.Add(member.name, temp_vessel.id); } } } new_vessel_found = true; } Vessels.Add(temp_vessel.id); } } } Log.PopStackInfo("leaving search_for_new_vessels(string save_file_name)"); return(new_vessel_found); }
/*************************************************************************************************************************/ public void flight_scene_update_routine() { Log.PushStackInfo("FMRS_Core.flight_scene_update_routine", "entering flight_scene_update_routine()"); Instance = this; if (_SETTING_Enabled) { if (timer_start_delay_active) { if ((Timer_Start_Delay + Time_Trigger_Start_Delay) <= Planetarium.GetUniversalTime()) { if (!_SAVE_Switched_To_Dropped) { write_recovered_values_to_save(); } else { List <Guid> temp_guid_list = new List <Guid>(); foreach (Guid id in loaded_vessels) { if (FlightGlobals.Vessels.Find(v => v.id == id) == null) { temp_guid_list.Add(id); } } foreach (Guid id in temp_guid_list) { Log.dbg("loaded_vessels: removing " + id.ToString()); loaded_vessels.Remove(id); } Log.dbg("loaded_vessels: " + loaded_vessels.Count.ToString()); } timer_start_delay_active = false; } } if (timer_staging_active) { if (timer_cuto_active && _SETTING_Auto_Cut_Off) { //if ((Time_Trigger_Cuto + 0.1) <= Planetarium.GetUniversalTime()) //if (_SETTING_Auto_Cut_Off) { Log.dbg("auto thrust cut off"); foreach (Vessel temp_vessel in FlightGlobals.Vessels) { if (!Vessels.Contains(temp_vessel.id)) { temp_vessel.ctrlState.mainThrottle = 0; } } timer_cuto_active = false; } } if ((Time_Trigger_Staging + Timer_Stage_Delay) <= Planetarium.GetUniversalTime()) { Log.dbg("Has Staged Delayed"); last_staging_event = Planetarium.GetUniversalTime(); timer_staging_active = false; quicksave_file_name = FILES.GAMESAVE_NAME + FlightGlobals.ActiveVessel.currentStage.ToString(); if (Vessels_dropped.ContainsValue(quicksave_file_name) || (separated_vessel && !staged_vessel)) { int nr_save_file = 0; foreach (KeyValuePair <Guid, string> temp_keyvalues in Vessels_dropped) { if (temp_keyvalues.Value.Contains("separated_")) { if (nr_save_file <= Convert.ToInt16(temp_keyvalues.Value.Substring(20))) { nr_save_file = Convert.ToInt16(temp_keyvalues.Value.Substring(20)) + 1; } } } quicksave_file_name = FILES.GAMESAVE_NAME + "separated_" + nr_save_file; } separated_vessel = false; staged_vessel = false; if (search_for_new_vessels(quicksave_file_name)) { // GamePersistence.SaveGame(quicksave_file_name, HighLogic.SaveFolder + "/FMRS", SaveMode.OVERWRITE); FMRS_SAVE_Util.Instance.SaveGame("FMRS_Core.flight_scene_update_routine", quicksave_file_name, HighLogic.SaveFolder + "/FMRS", SaveMode.OVERWRITE); if (_SAVE_Main_Vessel != FlightGlobals.ActiveVessel.id && !_SAVE_Switched_To_Dropped) { main_vessel_changed(quicksave_file_name); } set_save_value(save_cat.SAVEFILE, quicksave_file_name, Planetarium.GetUniversalTime().ToString()); write_save_values_to_file(); } } } if (n_launchpad_preflight && !FlightGlobals.ActiveVessel.Landed) { EventReport dummy_event = null; Log.dbg("non launchpad launch"); n_launchpad_preflight = false; launch_routine(dummy_event); } } Log.PopStackInfo("leaving flight_scene_update_routine"); }
/*************************************************************************************************************************/ void vessel_off_rails(Vessel vessel) { #if DEBUG // if (Debug_Level_1_Active) Log.PushStackInfo("FMRS_Core.vessel_off_rails", "enter vessel_off_rails(Vessel vessel) " + vessel.id.ToString()); if (Debug_Active) { Log.Info("Vessel will be off rails: " + vessel.vesselName); } #endif if (_SAVE_Switched_To_Dropped) { Vessel temp_vessel; temp_vessel = FlightGlobals.Vessels.Find(v => v.id == vessel.id); if (temp_vessel != null) { if (temp_vessel.loaded) { if (Vessels_dropped.ContainsKey(vessel.id)) { if (Vessels_dropped[vessel.id] == _SAVE_Switched_To_Savefile) { if (!loaded_vessels.Contains(vessel.id)) { #if DEBUG if (Debug_Active) { Log.Info("Vessel will be off rails: adding to loaded_vessels"); } #endif loaded_vessels.Add(vessel.id); } } } } } if (vessel.id == FlightGlobals.ActiveVessel.id) { List <Vessel> temp_vessel_list = new List <Vessel>(); temp_vessel_list = FlightGlobals.Vessels.FindAll(v => Vessels_dropped.ContainsKey(v.id) && v.loaded); foreach (Vessel v in temp_vessel_list) { if (Vessels_dropped[v.id] == _SAVE_Switched_To_Savefile) { if (!loaded_vessels.Contains(v.id)) { #if DEBUG if (Debug_Active) { Log.Info("Vessel will be off rails: adding to loaded_vessels"); } #endif loaded_vessels.Add(v.id); } } } } #if DEBUG if (Debug_Active) { Log.Info("loaded_vessels: " + loaded_vessels.Count.ToString()); } #endif } #if DEBUG // if (Debug_Level_1_Active) Log.PopStackInfo("leave vessel_off_rails(Vessel vessel)"); #endif }
/*************************************************************************************************************************/ void vessel_on_rails(Vessel vessel) { List <ProtoCrewMember> member_list = new List <ProtoCrewMember>(); #if DEBUG // if (Debug_Level_1_Active) Log.PushStackInfo("FMRS_Core.vessel_on_rails", "enter vessel_on_rails(Vessel vessel) " + vessel.id.ToString()); if (Debug_Active) { Log.Info("Vessel will be on rails: " + vessel.vesselName); } #endif if (Vessels_dropped.ContainsKey(vessel.id) && !_SAVE_Switched_To_Dropped) { #if DEBUG if (Debug_Active) { Log.Info("this vessel is listed in dropped dict"); } #endif foreach (ProtoPartSnapshot part_snapshot in vessel.protoVessel.protoPartSnapshots) { foreach (ProtoCrewMember member in part_snapshot.protoModuleCrew) { member_list.Add(member); } foreach (ProtoCrewMember member in member_list) { #if DEBUG if (Debug_Active) { Log.Info("remove crew member " + member.name); } #endif part_snapshot.RemoveCrew(member); } member_list.Clear(); } } if (_SAVE_Switched_To_Dropped) { if (loaded_vessels.Contains(vessel.id) && vessel.id != FlightGlobals.ActiveVessel.id && !vessel.Landed && !vessel.Splashed) { #if DEBUG if (Debug_Active) { Log.Info("loaded_vessels: removing " + vessel.id.ToString()); } #endif loaded_vessels.Remove(vessel.id); #if DEBUG if (Debug_Active) { Log.Info("vessel " + vessel.name + " removed from loaded_vessels"); } #endif } if (vessel.id == _SAVE_Main_Vessel) { if (ThrottleReplay != null) { vessel.OnFlyByWire -= new FlightInputCallback(ThrottleReplay.flybywire); ThrottleReplay.EndReplay(); } } } #if DEBUG // if (Debug_Level_1_Active) Log.PopStackInfo("leave vessel_on_rails(Vessel vessel)"); #endif }
/*************************************************************************************************************************/ public bool search_for_new_vessels(string save_file_name) { bool new_vessel_found = false, controllable = false; #if DEBUG // if (Debug_Level_1_Active) Log.PushStackInfo("FMRS_Core.search_for_new_vessels(string)", "entering search_for_new_vessels(string save_file_name) " + save_file_name); #endif foreach (Vessel temp_vessel in FlightGlobals.Vessels) { controllable = false; if (!Vessels.Contains(temp_vessel.id)) { if (temp_vessel.isCommandable && temp_vessel.IsControllable && temp_vessel.vesselType != VesselType.EVA && temp_vessel.vesselType != VesselType.Flag && temp_vessel.vesselType != VesselType.SpaceObject && temp_vessel.vesselType != VesselType.Unknown) { controllable = true; } else { foreach (ProtoPartSnapshot proto_part in temp_vessel.protoVessel.protoPartSnapshots) { List <ProtoPartModuleSnapshot> proto_modules = proto_part.modules; ProtoPartModuleSnapshot module = null; if (proto_modules != null && (_SETTING_Parachutes && (!_SETTING_Defer_Parachutes_to_StageRecovery || !stageRecoveryInstalled))) { // module = proto_part.modules.Find(p => p.moduleName == "RealChuteModule" || p.moduleName == "ModuleParachute" || p.moduleName == "ModuleKrKerbalParachute" || p.moduleName == "RealChuteFAR"); if (module != null) { controllable = true; } } if (proto_part.protoCrewNames.Count > 0) { controllable = true; } } } foreach (Part p in temp_vessel.Parts) { foreach (PartModule pm in p.Modules) { if (pm.moduleName == "FMRS_PM") { if ((pm as FMRS_PM).parent_vessel != "00000000-0000-0000-0000-000000000000") { controllable = false; break; } } } break; } if (controllable) { #if DEBUG if (Debug_Active) { Log.Info("" + temp_vessel.vesselName + " Found and will be added to the dicts"); } #endif Vessels_dropped.Add(temp_vessel.id, save_file_name); Vessels_dropped_names.Add(temp_vessel.id, temp_vessel.vesselName); Vessel_State.Add(temp_vessel.id, vesselstate.FLY); foreach (Part p in temp_vessel.Parts) { foreach (PartModule pm in p.Modules) { if (pm.moduleName == "FMRS_PM") { pm.StartCoroutine("setid"); } } } foreach (ProtoPartSnapshot part_snapshot in temp_vessel.protoVessel.protoPartSnapshots) { foreach (ProtoCrewMember member in part_snapshot.protoModuleCrew) { if (!Kerbal_dropped.ContainsKey(member.name)) { Kerbal_dropped.Add(member.name, temp_vessel.id); } } } new_vessel_found = true; } Vessels.Add(temp_vessel.id); } } #if DEBUG // if (Debug_Level_1_Active) Log.PopStackInfo("leaving search_for_new_vessels(string save_file_name)"); #endif return(new_vessel_found); }