public override void OnStart(StartState state) { if (state != StartState.Editor) { Events["registerVessel"].active = !SupplyChainController.isVesselTracked(vessel); } }
public void registerVessel() { if (!SupplyChainController.isVesselTracked(vessel)) { VesselData nvd = new VesselData(vessel); SupplyChainController.registerNewTrackedVessel(nvd); } Events["registerVessel"].active = false; }
public override void SaveCustom(ConfigNode node) { node.AddValue("type", "ResourceTransfer"); /* Save target vessel ID first. * The target VesselData might not be registered with SupplyChainController, * so check for that. */ if (targetVessel == null || targetVessel.vessel == null) { node.AddValue("targetTracked", false); node.AddValue("target", "none"); } else { if (SupplyChainController.isVesselTracked(targetVessel.vessel)) { node.AddValue("targetTracked", true); node.AddValue("target", targetVessel.trackingID.ToString()); } else { node.AddValue("targetTracked", false); ConfigNode tgtNode = node.AddNode("targetData"); targetVessel.Save(tgtNode); } } /* Save the actual transfer data next. */ foreach (ResourceTransfer xfer in this.toOrigin) { ConfigNode xferNode = node.AddNode("Transfer"); xferNode.AddValue("destination", "origin"); xferNode.AddValue("resource", PartResourceLibrary.Instance.GetDefinition(xfer.resourceID).name); xferNode.AddValue("amount", xfer.amount); xferNode.AddValue("type", (int)xfer.type); } foreach (ResourceTransfer xfer in this.toTarget) { ConfigNode xferNode = node.AddNode("Transfer"); xferNode.AddValue("destination", "target"); xferNode.AddValue("resource", PartResourceLibrary.Instance.GetDefinition(xfer.resourceID).name); xferNode.AddValue("amount", xfer.amount); xferNode.AddValue("type", (int)xfer.type); } }
public void endFlightTracking() { if (!currentlyTrackingFlight) { Debug.LogError("[SupplyChain] Attempted to end flight tracking without starting!"); return; } updateResourceAmounts(); // are we in a stable non-escape orbit? if (vessel.situation == Vessel.Situations.ORBITING && vessel.orbit.eccentricity > 0 && vessel.orbit.eccentricity < 1) { SupplyPoint to = null; foreach (SupplyPoint point in SupplyChainController.instance.points) { if (point.isVesselAtPoint(vessel)) { Debug.Log("[SupplyChain] Found existing supply point."); to = point; break; } } if (to == null) { Debug.Log("[SupplyChain] Creating new supply point."); to = new OrbitalSupplyPoint(vessel); SupplyChainController.registerNewSupplyPoint(to); } if (!SupplyChainController.isVesselTracked(vessel)) { VesselData nv = new VesselData(vessel); SupplyChainController.registerNewTrackedVessel(nv); } VesselData vd = SupplyChainController.getVesselTrackingInfo(vessel); SupplyLink result = new SupplyLink(vd, flightStartPoint, to); result.timeRequired = (vessel.missionTime - flightStartingMET); result.maxMass = flightStartingMass; Debug.Log("[SupplyChain] Creating new supply link."); Debug.Log("[SupplyChain] From: " + result.location.name); Debug.Log("[SupplyChain] To: " + result.to.name); Debug.Log("[SupplyChain] Total Elapsed MET: " + Convert.ToString(result.timeRequired)); Debug.Log("[SupplyChain] Maximum mass: " + Convert.ToString(result.maxMass)); foreach (int rsc in flightStartingResources.Keys) { if (vesselResourceAmounts[rsc] < flightStartingResources[rsc]) { result.resourcesRequired.Add(rsc, flightStartingResources[rsc] - vesselResourceAmounts[rsc]); Debug.Log("[SupplyChain] Detected resource deficit: " + Convert.ToString(flightStartingResources[rsc] - vesselResourceAmounts[rsc]) + " of " + PartResourceLibrary.Instance.GetDefinition(rsc).name); } } SupplyChainController.registerNewSupplyLink(result); } else { Debug.Log("Canceled flight tracking: not in stable orbit."); } currentlyTrackingFlight = false; Events["endFlightTracking"].guiActive = false; Events["endFlightTracking"].active = false; Events["beginFlightTracking"].guiActive = true; Events["beginFlightTracking"].active = true; }