protected override void OnParameterLoad(ConfigNode node) { // Load state flag allowStateReset = Convert.ToBoolean(node.GetValue("allowStateReset")); failWhenUnmet = ConfigNodeUtil.ParseValue <bool?>(node, "failWhenUnmet", (bool?)false).Value; // Load completion times foreach (ConfigNode child in node.GetNodes("VESSEL_STATS")) { Guid id = new Guid(child.GetValue("vessel")); Vessel vessel = FlightGlobals.Vessels.Find(v => v != null && v.id == id); if (vessel != null || HighLogic.LoadedScene == GameScenes.EDITOR) { VesselInfo info = new VesselInfo(id, vessel); info.state = ConfigNodeUtil.ParseValue <ParameterState>(child, "state"); info.strength = ConfigNodeUtil.ParseValue <ParamStrength>(child, "strength"); info.completionTime = ConfigNodeUtil.ParseValue <double>(child, "completionTime", 0.0); vesselInfo[id] = info; } } // Load docked sub-vessels foreach (ConfigNode child in node.GetNodes("DOCKED_SUB_VESSEL")) { uint hash = Convert.ToUInt32(child.GetValue("hash")); ParamStrength strength = ConfigNodeUtil.ParseValue <ParamStrength>(child, "strength"); double completionTime = ConfigNodeUtil.ParseValue <double>(child, "completionTime", 0.0); dockedVesselInfo[hash] = new KeyValuePair <ParamStrength, double>(strength, completionTime); } }
public void Test002() { // Arrange ContactInfo contactInfoModel = new ContactInfo { FirstName = "FirstName", Index = UserInfoIndex.Applicant }; ContactInfo mailingInfoModel = new ContactInfo { FirstName = "FirstName", Index = UserInfoIndex.MailRecipient }; InsuranceInfo insuranceInfoModel = new InsuranceInfo { NameOfInsurer = "InsurerName" }; VesselInfo vesselInfoModel = new VesselInfo { Name = "VesselName" }; _appStateManager.SetClientApplicationContext(new EditContext(contactInfoModel)); _appStateManager.SetClientApplicationContext(new EditContext(mailingInfoModel)); _appStateManager.SetClientApplicationContext(new EditContext(insuranceInfoModel)); _appStateManager.SetClientApplicationContext(new EditContext(vesselInfoModel)); // Act _appStateManager.Clear(); // Assert Assert.Null(_appState.ClientApplicationState.ApplicantContext); Assert.Null(_appState.ClientApplicationState.MailRecipientContext); Assert.True(_appState.ClientApplicationState.VesselInfoContexts.Count < 1); }
public bool UpdateShipSensor(ref VesselInfo info) { if (info == null) { return(false); } if (ShipSensors != null) { var mmsi = info.Mmsi; var Fuels = (from x in ShipSensors where x.Mmsi == mmsi select new { x.FlowIn, x.FlowOut, x.Created }).ToList(); if (Fuels != null && Fuels.Count > 0) { info.Fuel = Fuels.Sum(x => x.FlowIn) - Fuels.Sum(x => x.FlowOut); var fIn = Fuels.Where(x => x.FlowIn > 0).OrderByDescending(x => x.Created).FirstOrDefault(); var fOut = Fuels.Where(x => x.FlowOut > 0).OrderByDescending(x => x.Created).FirstOrDefault(); info.LastFlowIn = fIn.FlowIn; info.LastFlowInDate = fIn.Created; info.LastFlowOut = fOut.FlowOut; info.LastFlowOutDate = fOut.Created; return(true); } } return(false); }
public void Test001() { // Arrange const string vesselName = "Vessel Name"; var vessel = new VesselInfo { Name = vesselName }; // Act var cut = base.RenderComponent <MiuFormStateInitializerFake>( (nameof(MiuFormStateInitializerFake.EditContext), new EditContext(vessel)) ); var instance = cut.Instance; // Assert Assert.NotNull(instance.EditContext); Assert.Equal(vesselName, ((VesselInfo)instance.EditContext.Model).Name); var appState = Services.GetService <AppState>(); Assert.NotNull(appState.ClientApplicationState.VesselInfoContexts); Assert.Single(appState.ClientApplicationState.VesselInfoContexts); Assert.Equal(vesselName, ((VesselInfo)appState.ClientApplicationState.VesselInfoContexts.First().Model).Name); }
protected override void OnLoad(ConfigNode node) { base.OnLoad(node); // Load state flag allowStateReset = Convert.ToBoolean(node.GetValue("allowStateReset")); // Load completion times foreach (ConfigNode child in node.GetNodes("VESSEL_STATS")) { Guid id = new Guid(child.GetValue("vessel")); Vessel vessel = FlightGlobals.Vessels.Find(v => v.id == id); if (vessel != null || HighLogic.LoadedScene == GameScenes.EDITOR) { VesselInfo info = new VesselInfo(id, vessel); info.state = (ParameterState)Enum.Parse(typeof(ParameterState), child.GetValue("state")); info.strength = (ParamStrength)Enum.Parse(typeof(ParamStrength), child.GetValue("strength")); if (state == ParameterState.Complete) { info.completionTime = Convert.ToDouble(child.GetValue("completionTime")); } vesselInfo[id] = info; } } // Load docked sub-vessels foreach (ConfigNode child in node.GetNodes("DOCKED_SUB_VESSEL")) { uint hash = Convert.ToUInt32(child.GetValue("hash")); ParamStrength strength = (ParamStrength)Enum.Parse(typeof(ParamStrength), child.GetValue("strength")); dockedVesselStrength[hash] = strength; } }
IEnumerator <YieldInstruction> CompleteVesselLoad(string key, Guid id) { if (FlightGlobals.Vessels.Count == 0) { yield return(new WaitForEndOfFrame()); } if (!vessels.ContainsKey(key)) { yield break; } VesselInfo vi = vessels[key]; Vessel vessel = FlightGlobals.FindVessel(id); if (vessel == null || vessel.state == Vessel.State.DEAD) { id = Guid.Empty; vessels.Remove(key); } else if (vi.hash == 0 && HighLogic.LoadedScene == GameScenes.FLIGHT) { vi.hash = vessel.GetHashes().FirstOrDefault(); LoggingUtil.LogVerbose(this, "Setting hash for " + id + " on load to: " + vi.hash); } }
protected virtual void OnVesselWasModified(Vessel vessel) { LoggingUtil.LogDebug(this, "OnVesselWasModified: " + vessel.id); vessel.GetHashes().Count(); // Check for a vessel creation after a part joint break if (HighLogic.LoadedScene != GameScenes.FLIGHT || lastBreak == null || vessel == lastBreak) { LoggingUtil.LogVerbose(this, " returning, wrong scene or wrong vessel..."); return; } IEnumerable <uint> otherVesselHashes = lastBreak.GetHashes(); IEnumerable <uint> vesselHashes = vessel.GetHashes(); // OnVesselWasModified gets called twice, on the first call the vessels are still // connected. Check for that case. if (vesselModifiedCallCount++ == 0) { LoggingUtil.LogVerbose(this, " first call check"); // The second call will be for the original vessel. Swap over to check that one. lastBreak = vessel; return; } // Get the keys we will be looking at List <string> vesselKeys = GetAssociatedKeys(vessel).ToList(); List <string> otherVesselKeys = GetAssociatedKeys(lastBreak).ToList(); // Check the lists and see if we need to do a switch foreach (string key in vesselKeys) { // Check if we need to switch over to the newly created vessel VesselInfo vi = vessels[key]; if (otherVesselHashes.Contains(vi.hash)) { LoggingUtil.LogDebug(this, "Moving association for '" + key + "' from " + vi.id + " to " + lastBreak.id); vi.id = lastBreak.id; OnVesselAssociation.Fire(new GameEvents.HostTargetAction <Vessel, string>(lastBreak, key)); } } foreach (string key in otherVesselKeys) { // Check if we need to switch over to the newly created vessel VesselInfo vi = vessels[key]; if (vesselHashes.Contains(vi.hash)) { LoggingUtil.LogDebug(this, "Moving association for '" + key + "' from " + vi.id + " to " + vessel.id); vi.id = vessel.id; OnVesselAssociation.Fire(new GameEvents.HostTargetAction <Vessel, string>(vessel, key)); } } lastBreak = null; }
public static VesselInfo Load(ConfigNode node) { string vesselName = Utilities.GetValue(node, "vesselName", "Unknown"); double lastUpdate = Utilities.GetValue(node, "lastUpdate", 0.0); Vessel.Situations vesselSituation = Utilities.GetValue(node, "vesselSituation", Vessel.Situations.PRELAUNCH); VesselType vesselType = Utilities.GetValue(node, "vesselType", VesselType.Unknown); VesselInfo info = new VesselInfo(vesselName, vesselSituation, vesselType, lastUpdate); info.vesselIsPreLaunch = Utilities.GetValue(node, "vesselIsPreLaunch", true); if (info.vesselIsPreLaunch && !(vesselSituation == Vessel.Situations.PRELAUNCH)) { Logging.LogError("VesselInfo.Load", "Mismatch between VesselSituation and vesselIsPreLaunch, setting to Prelaunch"); info.vesselIsPreLaunch = true; info.vesselSituation = Vessel.Situations.PRELAUNCH; } info.numCrew = Utilities.GetValue(node, "numCrew", 0); info.numFrozenCrew = Utilities.GetValue(node, "numFrozenCrew", 0); info.numOccupiedParts = Utilities.GetValue(node, "numOccupiedParts", 0); info.lastFood = Utilities.GetValue(node, "lastFood", lastUpdate); info.lastWater = Utilities.GetValue(node, "lastWater", lastUpdate); info.lastOxygen = Utilities.GetValue(node, "lastOxygen", lastUpdate); info.lastElectricity = Utilities.GetValue(node, "lastElectricity", lastUpdate); info.remainingFood = Utilities.GetValue(node, "remainingFood", 0.0); info.remainingWater = Utilities.GetValue(node, "remainingWater", 0.0); info.remainingOxygen = Utilities.GetValue(node, "remainingOxygen", 0.0); info.remainingElectricity = Utilities.GetValue(node, "remainingElectricity", 0.0); info.remainingCO2 = Utilities.GetValue(node, "remainingCO2", 0.0); info.remainingWaste = Utilities.GetValue(node, "remainingWaste", 0.0); info.remainingWasteWater = Utilities.GetValue(node, "remainingWasteWater", 0.0); info.maxFood = Utilities.GetValue(node, "maxFood", 0.0); info.maxWater = Utilities.GetValue(node, "maxWater", 0.0); info.maxOxygen = Utilities.GetValue(node, "maxOxygen", 0.0); info.maxElectricity = Utilities.GetValue(node, "maxElectricity", 0.0); info.estimatedElectricityConsumptionRate = Utilities.GetValue(node, "estimatedElectricityConsumptionRate", 0.0); info.hibernating = Utilities.GetValue(node, "hibernating", false); info.recoveryvessel = Utilities.GetValue(node, "recoveryvessel", false); info.windowOpen = Utilities.GetValue(node, "windowOpen", false); return(info); }
public override void OnSave(ConfigNode node) { try { base.OnSave(node); foreach (KeyValuePair <string, VesselInfo> p in vessels) { VesselInfo vi = p.Value; // First find the vessel by id Vessel vessel = FlightGlobals.Vessels.Find(v => v != null && v.id == vi.id); if (HighLogic.LoadedScene == GameScenes.FLIGHT) { // If not found, attempt to find it by hash if (vessel == null) { vessel = FlightGlobals.Vessels.Find(v => v != null && v.GetHashes().Contains(vi.hash)); } // If found, verify the hash else { IEnumerable <uint> hashes = vessel.GetHashes(); if (hashes.Any() && !hashes.Contains(vi.hash)) { LoggingUtil.LogVerbose(this, "Setting hash for " + vi.id + " on save from " + vi.hash + " to " + hashes.FirstOrDefault()); vi.hash = hashes.FirstOrDefault(); } } } if (vessel != null) { ConfigNode child = new ConfigNode("VESSEL"); child.AddValue("key", p.Key); child.AddValue("id", vi.id); child.AddValue("hash", vi.hash); node.AddNode(child); } } } catch (Exception e) { LoggingUtil.LogError(this, "Error saving ContractVesselTracker to persistance file!"); LoggingUtil.LogException(e); ExceptionLogWindow.DisplayFatalException(ExceptionLogWindow.ExceptionSituation.SCENARIO_MODULE_SAVE, e, "ContractVesselTracker"); } }
protected void NewEVA(Vessel parent, Vessel eva) { // Check if there's anything for the parent if (vesselInfo.ContainsKey(parent.id)) { // If there's a completion, transfer that to the EVA VesselInfo vi = vesselInfo[parent.id]; if (vi.state == ParameterState.Complete && vi.strength != ParamStrength.WEAK) { VesselInfo viEVA = new VesselInfo(eva.id, eva); viEVA.completionTime = vi.completionTime; viEVA.state = vi.state; vesselInfo[eva.id] = viEVA; } } }
protected virtual void OnVesselDestroy(Vessel vessel) { LoggingUtil.LogVerbose(this, "OnVesselDestroy " + vessel.id); if (HighLogic.LoadedScene != GameScenes.FLIGHT) { LoggingUtil.LogVerbose(this, " returning, not in flight scene"); return; } // Try to change any associations over if this is due to a docking event foreach (string key in GetAssociatedKeys(vessel).ToList()) { LoggingUtil.LogVerbose(this, " checking key " + key); // Check if we need to switch over to the newly created vessel VesselInfo vi = vessels[key]; Vessel newVessel = FlightGlobals.Vessels.Find(v => { if (v != null && v != vessel) { LoggingUtil.LogVerbose(this, " loading protovessel for " + v.vesselName); // If the vessel is loaded, refresh the protovessel. We do this to support // grappling - when a new vessel is grappled the protovessel information // doesn't get properly updated. if (v.loaded) { v.protoVessel = new ProtoVessel(v); } return(v.GetHashes().Contains(vi.hash)); } return(false); }); if (newVessel != null) { vi.id = newVessel.id; } else { AssociateVessel(key, null); } } }
public static void EnsurePrefabIsVessel(string name, out VesselInfo vi) { byte vesselCompatibility = GetVesselCompatibility(name); if ((vesselCompatibility & 1) != 1) { if ((vesselCompatibility & 0x40) == 0x40) { throw new NonVesselControllableException(name); } throw new NonControllableException(name); } if ((vesselCompatibility & 0x18) == 0) { throw new NonControllableException("The vessel has not been marked for either ai and/or player control. not bothering to spawn it."); } vi = new VesselInfo(vesselCompatibility); }
internal static VesselInfo Load(ConfigNode node) { string vesselName = Utilities.GetNodeValue(node, "vesselName", "Unknown"); double lastUpdate = Utilities.GetNodeValue(node, "lastUpdate", 0.0); VesselInfo info = new VesselInfo(vesselName, lastUpdate); info.numSeats = Utilities.GetNodeValue(node, "numSeats", 0); info.vesselType = Utilities.GetNodeValue(node, "vesselType", VesselType.Unknown); info.numCrew = Utilities.GetNodeValue(node, "numCrew", 0); info.numOccupiedParts = Utilities.GetNodeValue(node, "numOccupiedParts", 0); info.numFrznCrew = Utilities.GetNodeValue(node, "numFrznCrew", 0); info.hibernating = Utilities.GetNodeValue(node, "hibernating", false); info.hasextDoor = Utilities.GetNodeValue(node, "hasextDoor", false); info.storedEC = Utilities.GetNodeValue(node, "storedEC", 0d); info.predictedECOut = Utilities.GetNodeValue(node, "predictedECOut", 0d); return info; }
protected virtual void OnVesselCreate(Vessel vessel) { if (IsIgnoredVesselType(vessel.vesselType) || HighLogic.LoadedScene != GameScenes.FLIGHT) { return; } LoggingUtil.LogVerbose(this, "OnVesselCreate(" + vessel.id + ")"); // Go through the hashes to try to set the parameters for this vessel KeyValuePair <ParamStrength, double>?dockedInfo = null; foreach (uint hash in vessel.GetHashes()) { if (dockedVesselInfo.ContainsKey(hash)) { if (dockedInfo == null) { dockedInfo = dockedVesselInfo[hash]; } else { dockedInfo = dockedVesselInfo[hash].Key > dockedInfo.Value.Key ? dockedVesselInfo[hash] : dockedInfo; } } } // Found one if (dockedInfo != null) { VesselInfo v = new VesselInfo(vessel.id, vessel); v.strength = dockedInfo.Value.Key; v.completionTime = dockedInfo.Value.Value; v.state = ParameterState.Complete; vesselInfo[vessel.id] = v; LoggingUtil.LogVerbose(this, " set state to " + v.state + " and strength to " + v.strength); } else { LoggingUtil.LogVerbose(this, " didn't find docked sub-vessel info"); } CheckVessel(vessel); }
/// <summary> /// Creates a permanent link between the given vessel and key. /// </summary> /// <param name="key">The key to create an association with.</param> /// <param name="vessel">The vessel that will be associated with the key</param> public void AssociateVessel(string key, Vessel vessel) { // Already associated! if (vessel != null && vessels.ContainsKey(key) && vessels[key].id == vessel.id) { return; } else if (vessel == null && !vessels.ContainsKey(key)) { return; } if (vessel != null) { LoggingUtil.LogVerbose(this, "Associating vessel " + vessel.id + " with key '" + key + "'."); } else { LoggingUtil.LogVerbose(this, "Disassociating key '" + key + "'."); } // First remove whatever was there if (vessels.ContainsKey(key)) { Guid oldVesselId = vessels[key].id; Vessel oldVessel = FlightGlobals.Vessels.Find(v => v != null && v.id == oldVesselId); vessels.Remove(key); if (oldVessel != null) { LoggingUtil.LogVerbose(this, "Firing OnVesselDisassociation."); OnVesselDisassociation.Fire(new GameEvents.HostTargetAction <Vessel, string>(oldVessel, key)); } } // Add the new vessel if (vessel != null) { vessels[key] = new VesselInfo(vessel); LoggingUtil.LogVerbose(this, "Firing OnVesselAssociation."); OnVesselAssociation.Fire(new GameEvents.HostTargetAction <Vessel, string>(vessel, key)); } }
protected virtual void OnVesselDestroy(Vessel vessel) { LoggingUtil.LogVerbose(this, "OnVesselDestroy " + vessel.id); // Try to change any associations over if this is due to a docking event foreach (string key in GetAssociatedKeys(vessel).ToList()) { // Check if we need to switch over to the newly created vessel VesselInfo vi = vessels[key]; Vessel newVessel = FlightGlobals.Vessels.Find(v => v != vessel && v.GetHashes().Contains(vi.hash)); if (newVessel != null) { vi.id = newVessel.id; } else { AssociateVessel(key, null); } } }
protected void ReturnEVA(Vessel parent, Vessel eva) { // Check if the EVA is interesting... if (vesselInfo.ContainsKey(eva.id)) { // Initialize parent if (!vesselInfo.ContainsKey(parent.id)) { vesselInfo[parent.id] = new VesselInfo(parent.id, parent); } // Copy to parent vessel VesselInfo vi = vesselInfo[parent.id]; VesselInfo viEVA = vesselInfo[eva.id]; if (viEVA.state == ParameterState.Complete && vi.state != ParameterState.Complete) { vi.state = viEVA.state; vi.strength = viEVA.strength; vi.completionTime = viEVA.completionTime; } } }
protected virtual void OnVesselCreate(Vessel vessel) { if (IsIgnoredVesselType(vessel.vesselType)) { return; } LoggingUtil.LogVerbose(this, "OnVesselCreate(" + vessel.id + ")"); // Go through the hashes to try to set the parameters for this vessel ParamStrength?strength = null; foreach (uint hash in GetVesselHashes(vessel)) { if (dockedVesselStrength.ContainsKey(hash)) { if (strength == null) { strength = dockedVesselStrength[hash]; } else { strength = dockedVesselStrength[hash] > strength ? dockedVesselStrength[hash] : strength; } } } // Found one if (strength != null) { VesselInfo v = new VesselInfo(vessel.id, vessel); v.strength = (ParamStrength)strength; v.state = ParameterState.Complete; vesselInfo[vessel.id] = v; } CheckVessel(vessel); }
public override void OnLoad(ConfigNode node) { try { base.OnLoad(node); foreach (ConfigNode child in node.GetNodes("VESSEL")) { string key = child.GetValue("key"); Guid id = new Guid(child.GetValue("id")); uint hash = ConfigNodeUtil.ParseValue <uint>(child, "hash", 0); StartCoroutine(CompleteVesselLoad(key, id)); vessels[key] = new VesselInfo(id, hash); } } catch (Exception e) { LoggingUtil.LogError(this, "Error loading ContractVesselTracker from persistance file!"); LoggingUtil.LogException(e); ExceptionLogWindow.DisplayFatalException(ExceptionLogWindow.ExceptionSituation.SCENARIO_MODULE_LOAD, e, "ContractVesselTracker"); } }
public override void OnLoad(ConfigNode node) { try { base.OnLoad(node); foreach (ConfigNode child in node.GetNodes("VESSEL")) { string key = child.GetValue("key"); Guid id = new Guid(child.GetValue("id")); uint hash = ConfigNodeUtil.ParseValue <uint>(child, "hash", 0); Vessel vessel = FlightGlobals.Vessels.Find(v => v != null && v.id == id); if (vessel == null || vessel.state == Vessel.State.DEAD) { id = Guid.Empty; } else if (hash == 0 && HighLogic.LoadedScene == GameScenes.FLIGHT) { hash = vessel.GetHashes().FirstOrDefault(); LoggingUtil.LogVerbose(this, "Setting hash for " + id + " on load to: " + hash); } if (id != Guid.Empty) { vessels[key] = new VesselInfo(id, hash); } } } catch (Exception e) { LoggingUtil.LogError(this, "Error loading ContractVesselTracker from persistance file!"); LoggingUtil.LogException(e); ExceptionLogWindow.DisplayFatalException(ExceptionLogWindow.ExceptionSituation.SCENARIO_MODULE_LOAD, e, "ContractVesselTracker"); } }
protected override void OnParameterLoad(ConfigNode node) { // Load state flag allowStateReset = Convert.ToBoolean(node.GetValue("allowStateReset")); // Load completion times foreach (ConfigNode child in node.GetNodes("VESSEL_STATS")) { Guid id = new Guid(child.GetValue("vessel")); Vessel vessel = FlightGlobals.Vessels.Find(v => v != null && v.id == id); if (vessel != null || HighLogic.LoadedScene == GameScenes.EDITOR) { VesselInfo info = new VesselInfo(id, vessel); info.state = ConfigNodeUtil.ParseValue<ParameterState>(child, "state"); info.strength = ConfigNodeUtil.ParseValue<ParamStrength>(child, "strength"); info.completionTime = ConfigNodeUtil.ParseValue<double>(child, "completionTime", 0.0); vesselInfo[id] = info; } } // Load docked sub-vessels foreach (ConfigNode child in node.GetNodes("DOCKED_SUB_VESSEL")) { uint hash = Convert.ToUInt32(child.GetValue("hash")); ParamStrength strength = ConfigNodeUtil.ParseValue<ParamStrength>(child, "strength"); double completionTime = ConfigNodeUtil.ParseValue<double>(child, "completionTime", 0.0); dockedVesselInfo[hash] = new KeyValuePair<ParamStrength,double>(strength, completionTime); } }
protected void NewEVA(Vessel parent, Vessel eva) { // Check if there's anything for the parent if (vesselInfo.ContainsKey(parent.id)) { // If there's a completion, transfer that to the EVA VesselInfo vi = vesselInfo[parent.id]; if (vi.state == ParameterState.Complete && vi.strength != ParamStrength.WEAK) { VesselInfo viEVA = new VesselInfo(eva.id, eva); viEVA.completionTime = vi.completionTime; viEVA.state = vi.state; viEVA.strength = ParamStrength.WEAK; vesselInfo[eva.id] = viEVA; } } }
public override void OnLoad(ConfigNode node) { try { base.OnLoad(node); foreach (ConfigNode child in node.GetNodes("VESSEL")) { string key = child.GetValue("key"); Guid id = new Guid(child.GetValue("id")); uint hash = ConfigNodeUtil.ParseValue<uint>(child, "hash", 0); Vessel vessel = FlightGlobals.Vessels.Find(v => v != null && v.id == id); if (vessel == null || vessel.state == Vessel.State.DEAD) { id = Guid.Empty; } else if (hash == 0 && HighLogic.LoadedScene == GameScenes.FLIGHT) { hash = vessel.GetHashes().FirstOrDefault(); LoggingUtil.LogVerbose(this, "Setting hash for " + id + " on load to: " + hash); } if (id != Guid.Empty) { vessels[key] = new VesselInfo(id, hash); } } } catch (Exception e) { LoggingUtil.LogError(this, "Error loading ContractVesselTracker from persistance file!"); LoggingUtil.LogException(e); ExceptionLogWindow.DisplayFatalException(ExceptionLogWindow.ExceptionSituation.SCENARIO_MODULE_LOAD, e, "ContractVesselTracker"); } }
/// <summary> /// Creates a permanent link between the given vessel and key. /// </summary> /// <param name="key">The key to create an association with.</param> /// <param name="vessel">The vessel that will be associated with the key</param> public void AssociateVessel(string key, Vessel vessel) { // Already associated! if (vessel != null && vessels.ContainsKey(key) && vessels[key].id == vessel.id) { return; } else if (vessel == null && !vessels.ContainsKey(key)) { return; } if (vessel != null) { LoggingUtil.LogVerbose(this, "Associating vessel " + vessel.id + " with key '" + key + "'."); } else { LoggingUtil.LogVerbose(this, "Disassociating key '" + key + "'."); } // First remove whatever was there if (vessels.ContainsKey(key)) { Guid oldVesselId = vessels[key].id; Vessel oldVessel = FlightGlobals.Vessels.Find(v => v != null && v.id == oldVesselId); vessels.Remove(key); if (oldVessel != null) { LoggingUtil.LogVerbose(this, "Firing OnVesselDisassociation."); OnVesselDisassociation.Fire(new GameEvents.HostTargetAction<Vessel, string>(oldVessel, key)); } } // Add the new vessel if (vessel != null) { vessels[key] = new VesselInfo(vessel); LoggingUtil.LogVerbose(this, "Firing OnVesselAssociation."); OnVesselAssociation.Fire(new GameEvents.HostTargetAction<Vessel, string>(vessel, key)); } }
public static VesselInfo Load(ConfigNode node) { string vesselName = Utilities.GetValue(node, "vesselName", "Unknown"); double lastUpdate = Utilities.GetValue(node, "lastUpdate", 0.0); Vessel.Situations vesselSituation = Utilities.GetValue(node, "vesselSituation", Vessel.Situations.PRELAUNCH); VesselType vesselType = Utilities.GetValue(node, "vesselType", VesselType.Unknown); VesselInfo info = new VesselInfo(vesselName, vesselSituation, vesselType, lastUpdate); info.vesselIsPreLaunch = Utilities.GetValue(node, "vesselIsPreLaunch", true); if (info.vesselIsPreLaunch && !(vesselSituation == Vessel.Situations.PRELAUNCH)) { Logging.LogError("VesselInfo.Load", "Mismatch between VesselSituation and vesselIsPreLaunch, setting to Prelaunch"); info.vesselIsPreLaunch = true; info.vesselSituation = Vessel.Situations.PRELAUNCH; } info.numCrew = Utilities.GetValue(node, "numCrew", 0); info.numFrozenCrew = Utilities.GetValue(node, "numFrozenCrew", 0); info.numOccupiedParts = Utilities.GetValue(node, "numOccupiedParts", 0); info.lastFood = Utilities.GetValue(node, "lastFood", lastUpdate); info.lastWater = Utilities.GetValue(node, "lastWater", lastUpdate); info.lastOxygen = Utilities.GetValue(node, "lastOxygen", lastUpdate); info.lastElectricity = Utilities.GetValue(node, "lastElectricity", lastUpdate); info.remainingFood = Utilities.GetValue(node, "remainingFood", 0.0); info.remainingWater = Utilities.GetValue(node, "remainingWater", 0.0); info.remainingOxygen = Utilities.GetValue(node, "remainingOxygen", 0.0); info.remainingElectricity = Utilities.GetValue(node, "remainingElectricity", 0.0); info.remainingCO2 = Utilities.GetValue(node, "remainingCO2", 0.0); info.remainingWaste = Utilities.GetValue(node, "remainingWaste", 0.0); info.remainingWasteWater = Utilities.GetValue(node, "remainingWasteWater", 0.0); info.maxFood = Utilities.GetValue(node, "maxFood", 0.0); info.maxWater = Utilities.GetValue(node, "maxWater", 0.0); info.maxOxygen = Utilities.GetValue(node, "maxOxygen", 0.0); info.maxElectricity = Utilities.GetValue(node, "maxElectricity", 0.0); info.estimatedElectricityConsumptionRate = Utilities.GetValue(node, "estimatedElectricityConsumptionRate", 0.0); info.hibernating = Utilities.GetValue(node, "hibernating", false); info.recoveryvessel = Utilities.GetValue(node, "recoveryvessel", false); return info; }
protected virtual void OnPartAttach(GameEvents.HostTargetAction <Part, Part> e) { if (HighLogic.LoadedScene == GameScenes.EDITOR || e.host.vessel == null || e.target.vessel == null) { return; } // Get the vesselInfo structs VesselInfo v1 = vesselInfo.ContainsKey(e.host.vessel.id) ? vesselInfo[e.host.vessel.id] : null; VesselInfo v2 = vesselInfo.ContainsKey(e.target.vessel.id) ? vesselInfo[e.target.vessel.id] : null; // Handle cases of untracked vessels if (v1 == null && v2 == null) { return; } else if (v1 == null) { VesselInfo v = new VesselInfo(e.host.vessel.id, e.host.vessel); v1 = vesselInfo[e.host.vessel.id] = v; } else if (v2 == null) { VesselInfo v = new VesselInfo(e.target.vessel.id, e.target.vessel); v2 = vesselInfo[e.target.vessel.id] = v; } // Neither is complete, nothing to do if (v1.state != ParameterState.Complete && v2.state != ParameterState.Complete) { return; } // Both are complete else if (v1.state == v2.state) { // Save the subvessel info SaveSubVesselInfo(v1.vessel, v1.strength == ParamStrength.STRONG ? ParamStrength.STRONG : ParamStrength.WEAK); SaveSubVesselInfo(v2.vessel, v2.strength == ParamStrength.STRONG ? ParamStrength.STRONG : ParamStrength.WEAK); // Minimize completion time v1.completionTime = v2.completionTime = Math.Min(v1.completionTime, v2.completionTime); // If the two strengths are different, they both end up medium if (v1.strength != v2.strength) { v1.strength = v2.strength = ParamStrength.MEDIUM; } } // Only one is complete else { // Swap to make v1 the complete one if (v2.state == ParameterState.Complete) { VesselInfo tmp = v2; v2 = v1; v1 = tmp; } // Save the subvessel info for v1 only SaveSubVesselInfo(v1.vessel, v1.strength == ParamStrength.STRONG ? ParamStrength.STRONG : ParamStrength.WEAK); // v1 is complete - transfer parameter state only if strength is not weak if (v1.strength != ParamStrength.WEAK) { // Save sub-vessel info for v2 SaveSubVesselInfo(v2.vessel, ParamStrength.WEAK); v2.completionTime = v1.completionTime; v2.state = v1.state; v1.strength = v2.strength = ParamStrength.MEDIUM; } } }
public override void OnLoad(ConfigNode node) { try { base.OnLoad(node); foreach (ConfigNode child in node.GetNodes("VESSEL")) { string key = child.GetValue("key"); Guid id = new Guid(child.GetValue("id")); uint hash = ConfigNodeUtil.ParseValue<uint>(child, "hash", 0); StartCoroutine(CompleteVesselLoad(key, id)); vessels[key] = new VesselInfo(id, hash); } } catch (Exception e) { LoggingUtil.LogError(this, "Error loading ContractVesselTracker from persistance file!"); LoggingUtil.LogException(e); ExceptionLogWindow.DisplayFatalException(ExceptionLogWindow.ExceptionSituation.SCENARIO_MODULE_LOAD, e, "ContractVesselTracker"); } }
public static void EnsurePrefabIsVessel(string name, Controllable forControllable, out VesselInfo vi) { EnsurePrefabIsVessel(name, out vi); if ((forControllable != null) && forControllable.controlled) { if (forControllable.aiControlled) { if (!vi.supportsAI) { throw new NonAIVesselControllableException(name); } } else if (forControllable.playerControlled && !vi.supportsPlayer) { throw new NonPlayerVesselControllableException(name); } } }
public List <VesselInfo> GetAllShipInArea(List <LatLngLiteral> Area) { var list = new List <VesselInfo>(); try { foreach (var item in ShipPositions.Values) { PointXY loc; VesselInfo data = null; if (item[item.Count - 1] is PositionReportClassAMessage) { var obj = item[item.Count - 1] as PositionReportClassAMessage; if (!ShipDatas.ContainsKey(obj.Mmsi)) { continue; } var shipInfo = ShipDatas[obj.Mmsi].Last() as StaticAndVoyageRelatedDataMessage; loc = new PointXY(obj.Latitude, obj.Longitude); data = new VesselInfo() { Mmsi = obj.Mmsi, Lat = obj.Latitude, Course = obj.CourseOverGround, Dest = shipInfo.Destination, ETA = $"{shipInfo.EtaDay}/{shipInfo.EtaMonth} {shipInfo.EtaHour}:{shipInfo.EtaMinute}", Lng = obj.Longitude, ShipName = shipInfo.ShipName, Speed = obj.SpeedOverGround, Status = obj.NavigationStatus.ToString(), Direction = obj.TrueHeading }; } else if (item[item.Count - 1] is ExtendedClassBCsPositionReportMessage) { var obj = item[item.Count - 1] as ExtendedClassBCsPositionReportMessage; if (!ShipDatas.ContainsKey(obj.Mmsi)) { continue; } var shipInfo = ShipDatas[obj.Mmsi].Last() as StaticAndVoyageRelatedDataMessage; loc = new PointXY(obj.Latitude, obj.Longitude); data = new VesselInfo() { Mmsi = obj.Mmsi, Lat = obj.Latitude, Course = obj.CourseOverGround, Dest = shipInfo.Destination, ETA = $"{shipInfo.EtaDay}/{shipInfo.EtaMonth} {shipInfo.EtaHour}:{shipInfo.EtaMinute}", Lng = obj.Longitude, ShipName = shipInfo.ShipName, Speed = obj.SpeedOverGround, Status = "", Direction = obj.TrueHeading }; } if (data != null) { if (Area == null) { list.Add(data); } else if (GeoFence.PointInPolygon(new LatLngLiteral() { Lat = data.Lat, Lng = data.Lng }, Area)) { list.Add(data); } } } } catch (Exception ex) { Console.WriteLine("get ships error : " + ex.Message); } return(list); }
protected virtual void OnPartAttach(GameEvents.HostTargetAction<Part, Part> e) { if (HighLogic.LoadedScene == GameScenes.EDITOR || e.host.vessel == null || e.target.vessel == null) { return; } // Get the vesselInfo structs VesselInfo v1 = vesselInfo.ContainsKey(e.host.vessel.id) ? vesselInfo[e.host.vessel.id] : null; VesselInfo v2 = vesselInfo.ContainsKey(e.target.vessel.id) ? vesselInfo[e.target.vessel.id] : null; // Handle cases of untracked vessels if (v1 == null && v2 == null) { return; } else if (v1 == null) { VesselInfo v = new VesselInfo(e.host.vessel.id, e.host.vessel); v1 = vesselInfo[e.host.vessel.id] = v; } else if (v2 == null) { VesselInfo v = new VesselInfo(e.target.vessel.id, e.target.vessel); v2 = vesselInfo[e.target.vessel.id] = v; } // Neither is complete, nothing to do if (v1.state != ParameterState.Complete && v2.state != ParameterState.Complete) { return; } // Both are complete else if (v1.state == v2.state) { // Save the subvessel info SaveSubVesselInfo(v1.vessel, v1.strength == ParamStrength.STRONG ? ParamStrength.STRONG : ParamStrength.WEAK, v1.completionTime); SaveSubVesselInfo(v2.vessel, v2.strength == ParamStrength.STRONG ? ParamStrength.STRONG : ParamStrength.WEAK, v2.completionTime); // Minimize completion time v1.completionTime = v2.completionTime = Math.Min(v1.completionTime, v2.completionTime); // If the two strengths are different, they both end up medium if (v1.strength != v2.strength) { v1.strength = v2.strength = ParamStrength.MEDIUM; } } // Only one is complete else { // Swap to make v1 the complete one if (v2.state == ParameterState.Complete) { VesselInfo tmp = v2; v2 = v1; v1 = tmp; } // Save the subvessel info for v1 only SaveSubVesselInfo(v1.vessel, v1.strength == ParamStrength.STRONG ? ParamStrength.STRONG : ParamStrength.WEAK, v1.completionTime); // v1 is complete - transfer parameter state only if strength is not weak if (v1.strength != ParamStrength.WEAK) { // Save sub-vessel info for v2 SaveSubVesselInfo(v2.vessel, ParamStrength.WEAK, v1.completionTime); v2.completionTime = v1.completionTime; v2.state = v1.state; v1.strength = v2.strength = ParamStrength.MEDIUM; } } CheckVessel(e.host.vessel); if (e.host.vessel.id != e.target.vessel.id) { CheckVessel(e.target.vessel); } }
protected virtual void OnVesselCreate(Vessel vessel) { if (IsIgnoredVesselType(vessel.vesselType) || HighLogic.LoadedScene != GameScenes.FLIGHT) { return; } LoggingUtil.LogVerbose(this, "OnVesselCreate(" + vessel.id + ")"); // Go through the hashes to try to set the parameters for this vessel KeyValuePair<ParamStrength, double>? dockedInfo = null; foreach (uint hash in vessel.GetHashes()) { if (dockedVesselInfo.ContainsKey(hash)) { if (dockedInfo == null) { dockedInfo = dockedVesselInfo[hash]; } else { dockedInfo = dockedVesselInfo[hash].Key > dockedInfo.Value.Key ? dockedVesselInfo[hash] : dockedInfo; } } } // Found one if (dockedInfo != null) { VesselInfo v = new VesselInfo(vessel.id, vessel); v.strength = dockedInfo.Value.Key; v.completionTime = dockedInfo.Value.Value; v.state = ParameterState.Complete; vesselInfo[vessel.id] = v; } CheckVessel(vessel); }
public void Awake() { if (GHudmain != null) return; GHudmain = this; UnityEngine.Object.DontDestroyOnLoad(GHudmain); if (!lcd_initialized) { DMcLgLCD.LcdInit(); lcd_initialized = true; } Device bw_dev = new DeviceBW(); Device color_dev = new DeviceQVGA(); if (bw_dev != null && bw_dev.isValid()) { devices.Add(bw_dev); OrbitInfo initialbw = new OrbitInfo(bw_dev, "✈", System.Drawing.Color.Black, System.Drawing.Color.Black); initialbw.Activate(); bw_dev.modules.Add(initialbw); OrbitInfo targetinfo = new OrbitInfo(bw_dev, "+", System.Drawing.Color.Black, System.Drawing.Color.Black); targetinfo.is_target_type_module = true; bw_dev.modules.Add(targetinfo); bw_dev.modules.Add(new OrbitGraph(bw_dev, System.Drawing.Color.Yellow, "✈")); OrbitGraph tgt_orbitgraph = new OrbitGraph(bw_dev, System.Drawing.Color.Yellow, "+"); tgt_orbitgraph.is_target_type_module = true; bw_dev.modules.Add(tgt_orbitgraph); } if (color_dev != null && color_dev.isValid()) { devices.Add(color_dev); VesselInfo initialcolor = new VesselInfo(color_dev); initialcolor.Activate(); color_dev.modules.Add(initialcolor); //color_dev.modules.Add(new OrbitInfo(color_dev, "✈", System.Drawing.Color.FromArgb(0xee, 0xee, 0x00), System.Drawing.Color.FromArgb(0xaa, 0xaa, 0x44))); /* OrbitInfo col_targetinfo = new OrbitInfo(color_dev, "⊹", System.Drawing.Color.LightBlue, System.Drawing.Color.MediumPurple); col_targetinfo.is_target_type_module = true; color_dev.modules.Add(col_targetinfo); */ color_dev.modules.Add(new OrbitGraph(color_dev, System.Drawing.Color.Yellow, "✈")); OrbitGraph tgt_orbitgraph = new OrbitGraph(color_dev, System.Drawing.Color.LightBlue, "+"); tgt_orbitgraph.is_target_type_module = true; color_dev.modules.Add(tgt_orbitgraph); } foreach (Device dev in devices) { dev.ButtonUP += new Device.ButtonHandler(ButtonUp); dev.ButtonDOWN += new Device.ButtonHandler(ButtonDown); dev.ButtonLEFT += new Device.ButtonHandler(ButtonLeft); dev.ButtonRIGHT += new Device.ButtonHandler(ButtonRight); dev.ButtonOK += new Device.ButtonHandler(ButtonOk); dev.ButtonCANCEL += new Device.ButtonHandler(ButtonCancel); dev.ButtonMENU += new Device.ButtonHandler(ButtonMenu); dev.DisplayFrame(); } }