Exemplo n.º 1
0
 public override void OnStart(StartState state)
 {
     if (state != StartState.Editor)
     {
         Events["registerVessel"].active = !SupplyChainController.isVesselTracked(vessel);
     }
 }
Exemplo n.º 2
0
        public void createNewSupplyPoint()
        {
            foreach (SupplyPoint point in SupplyChainController.instance.points)
            {
                if (point.isVesselAtPoint(vessel))
                {
                    return;
                }
            }

            Debug.Log("[SupplyPoint] Creating new supply point.");
            // Create a new flight point here.
            if (vessel.situation == Vessel.Situations.ORBITING &&
                vessel.orbit.eccentricity > 0 && vessel.orbit.eccentricity < 1)
            {
                flightStartPoint = new OrbitalSupplyPoint(vessel);
                SupplyChainController.registerNewSupplyPoint(flightStartPoint);
            }
            else
            {
                // Can't create a new flight point; unstable situation.
                Debug.LogError("[SupplyPoint] Cannot create new supply point: in unstable orbit!");
                return;
            }
        }
Exemplo n.º 3
0
        public void beginFlightTracking()
        {
            updateResourceCapacity();
            updateResourceAmounts();

            Debug.Log("[SupplyChain] Entering rest of BeginFlightTracking");

            flightStartPoint = null;
            foreach (SupplyPoint point in SupplyChainController.instance.points)
            {
                Debug.Log("[SupplyPoint] Inspecting point: " + point.name);
                if (point.isVesselAtPoint(vessel))
                {
                    Debug.Log("[SupplyChain] Found matching supply point: " + point.name);
                    flightStartPoint = point;
                    break;
                }
            }

            if (flightStartPoint == null)
            {
                Debug.Log("[SupplyPoint] Creating new supply point.");
                // Create a new flight point here.
                if (vessel.situation == Vessel.Situations.ORBITING &&
                    vessel.orbit.eccentricity > 0 && vessel.orbit.eccentricity < 1)
                {
                    flightStartPoint = new OrbitalSupplyPoint(vessel);
                    SupplyChainController.registerNewSupplyPoint(flightStartPoint);
                }
                else
                {
                    // Can't create a new flight point; unstable situation.
                    Debug.LogError("[SupplyPoint] Cannot create new supply point: in unstable orbit!");
                    return;
                }
            }

            Debug.Log("[SupplyPoint] Setting up resources.");

            flightStartingResources = new Dictionary <int, double>();
            foreach (int r in vesselResourceAmounts.Keys)
            {
                Debug.Log("[SupplyChain] Tracking resource: " + PartResourceLibrary.Instance.GetDefinition(r).name + " (have" + Convert.ToString(vesselResourceAmounts[r]) + ")");
                flightStartingResources.Add(r, vesselResourceAmounts[r]);
            }
            flightStartingMET  = vessel.missionTime;
            flightStartingMass = vessel.totalMass;
            Debug.Log("[SupplyPoint] Vessel mass: " + Convert.ToString(vessel.totalMass));
            currentlyTrackingFlight = true;

            Debug.Log("[SupplyPoint] Changing event states.");

            Events["endFlightTracking"].guiActive   = true;
            Events["endFlightTracking"].active      = true;
            Events["beginFlightTracking"].guiActive = false;
            Events["beginFlightTracking"].active    = false;
        }
Exemplo n.º 4
0
        public void registerVessel()
        {
            if (!SupplyChainController.isVesselTracked(vessel))
            {
                VesselData nvd = new VesselData(vessel);
                SupplyChainController.registerNewTrackedVessel(nvd);
            }

            Events["registerVessel"].active = false;
        }
Exemplo n.º 5
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.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
        public override void LoadCustom(ConfigNode node)
        {
            id = new Guid(node.GetValue("id"));
            to = SupplyChainController.getPointByGuid(new Guid(node.GetValue("to")));
            node.TryGetValue("maxMass", ref maxMass);

            /* Load resources. */
            ConfigNode[] required = node.GetNodes("RequiredResource");
            resourcesRequired = new Dictionary <int, double>();
            foreach (ConfigNode rscNode in required)
            {
                String name   = rscNode.GetValue("name");
                double amount = Convert.ToDouble(rscNode.GetValue("amount"));
                resourcesRequired.Add(PartResourceLibrary.Instance.GetDefinition(name).id, amount);
            }

            this.linkVessel.links.Add(this);
        }
Exemplo n.º 8
0
        public override void OnAwake()
        {
            instance = this;

            points         = new List <SupplyPoint>();
            links          = new List <SupplyLink>();
            trackedVessels = new List <VesselData>();
            activeActions  = new List <SupplyChainAction>();
            vesselsAtPoint = new Dictionary <SupplyPoint, List <Vessel> >();

            lastUpdated = Planetarium.GetUniversalTime();

            GameEvents.onFlightReady.Add(doPeriodicUpdate);
            GameEvents.OnFlightGlobalsReady.Add((bool data) => { doPeriodicUpdate(); });
            GameEvents.onTimeWarpRateChanged.Add(doPeriodicUpdate);

            SupplyBaseWindow.initAllWindows();
        }
        private void loadCommonData(ConfigNode node)
        {
            location = SupplyChainController.getPointByGuid(new Guid(node.GetValue("location")));
            node.TryGetValue("freestanding", ref this.freestanding);
            node.TryGetValue("timeRequired", ref timeRequired);

            node.TryGetValue("active", ref active);
            if (this.active)
            {
                node.TryGetValue("timeAtComplete", ref timeComplete);
            }

            /* Load linked vessel. */
            Guid linkVesselID = new Guid(node.GetValue("linkVessel"));

            foreach (VesselData vd in SupplyChainController.instance.trackedVessels)
            {
                if (vd.trackingID.Equals(linkVesselID))
                {
                    this.linkVessel = vd;
                    break;
                }
            }
        }
Exemplo n.º 10
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;
        }