Exemple #1
0
        public static bool registerNewSupplyLink(SupplyLink link)
        {
            SupplyChainController.instance.links.Add(link);

            Debug.Log("[SupplyChain] Added new supply link from " + link.location.name + " -> " + link.to.name);

            return(true); // TODO: maybe check for redundant points?
        }
Exemple #2
0
        public static bool deregisterNewSupplyLink(SupplyLink link)
        {
            Debug.Log("[SupplyChain] Removed supply link from " + link.location.name + " -> " + link.to.name);

            if (SupplyChainController.instance.links.Contains(link))
            {
                return(true);
            }
            return(false);
        }
Exemple #3
0
        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);
                    }
                }
            }
        }
Exemple #4
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;
        }