public override void LoadCustom(ConfigNode node) { bool targetTracked = false; node.TryGetValue("targetTracked", ref targetTracked); if (targetTracked) { this.targetVessel = SupplyChainController.getVesselTrackingInfo(new Guid(node.GetValue("target"))); } else { if (node.HasValue("target")) { this.targetVessel = null; } else { VesselData targetData = new VesselData(); targetData.Load(node.GetNode("targetData")); this.targetVessel = targetData; } } ConfigNode[] xferNodes = node.GetNodes("Transfer"); foreach (ConfigNode xferNode in xferNodes) { ResourceTransfer xfer = new ResourceTransfer(); string destination = xferNode.GetValue("destination"); xfer.resourceID = PartResourceLibrary.Instance.GetDefinition(xferNode.GetValue("resource")).id; xferNode.TryGetValue("amount", ref xfer.amount); int xferType = 0; xferNode.TryGetValue("type", ref xferType); xfer.type = (TransferType)xferType; if (destination == "origin") { toOrigin.Add(xfer); } else if (destination == "target") { toTarget.Add(xfer); } else { Debug.LogError("[SupplyChain] ResourceTransferAction: Got invalid destination!"); } } calculateRequirements(); }
public override void OnLoad(ConfigNode node) { if (points == null) { points = new List <SupplyPoint>(); } if (links == null) { links = new List <SupplyLink>(); } if (trackedVessels == null) { trackedVessels = new List <VesselData>(); } /* Load all SupplyPoints. */ Debug.Log("[SupplyChain] Loading SupplyPoints..."); ConfigNode[] pointNodes = node.GetNodes("SupplyPoint"); foreach (ConfigNode pointNode in pointNodes) { if (!points.Exists((SupplyPoint p) => { return(p.id.Equals(new Guid(pointNode.GetValue("id")))); })) { String type = pointNode.GetValue("type"); switch (type) { case "orbit": OrbitalSupplyPoint point = new OrbitalSupplyPoint(); point.Load(pointNode); points.Add(point); Debug.Log("[SupplyChain] Loaded SupplyPoint: " + point.name); break; default: Debug.LogError("[SupplyChain] unrecognized supply point type: " + type); break; } } } Debug.Log("[SupplyChain] Loading tracked vessels..."); ConfigNode[] vessNodes = node.GetNodes("TrackedVessel"); foreach (ConfigNode vessNode in vessNodes) { VesselData v = new VesselData(); v.Load(vessNode); trackedVessels.Add(v); } /* Load all SupplyLinks. */ Debug.Log("[SupplyChain] Loading SupplyLinks..."); ConfigNode[] linkNodes = node.GetNodes("SupplyLink"); foreach (ConfigNode linkNode in linkNodes) { if (!links.Exists((SupplyLink l) => { return(l.id.Equals(new Guid(linkNode.GetValue("id")))); })) { SupplyLink link = new SupplyLink(); link.Load(linkNode); links.Add(link); if (link.active) { activeActions.Add(link); } Debug.Log("[SupplyChain] Loaded Supply Link: " + link.location.name + " -> " + link.to.name); } } ConfigNode[] actNodes = node.GetNodes("ActiveAction"); if (actNodes.Count() > 0) { Debug.Log("[SupplyChain] Loading active actions..."); foreach (ConfigNode actNode in actNodes) { string type = actNode.GetValue("type"); if (type == "ResourceTransfer") { ResourceTransferAction act = new ResourceTransferAction(); act.Load(actNode); this.activeActions.Add(act); } } } }