Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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;
        }