public static InterestedVessel Load(ConfigNode node)
 {
     if (node.HasValue("VesselGuid"))
     {
         Guid id = new Guid(node.GetValue("VesselGuid"));
         if (FlightGlobals.fetch)
         {
             Vessel vsl = FlightGlobals.FindVessel(id);
             if (vsl != null)
             {
                 if (vsl.protoVessel != null)
                 {
                     ProtoVessel      protovsl         = vsl.protoVessel;
                     InterestedVessel interestedVessel = new InterestedVessel(vsl, protovsl);
                     node.TryGetValue("timeLastRefresh", ref interestedVessel.TimeLastRefresh);
                     ConfigNode[] cacheResourcesNodes = node.GetNodes("CACHERESOURCE");
                     for (int crI = 0; crI < cacheResourcesNodes.Length; crI++)
                     {
                         CacheResources.CacheResource cacheResource = CacheResources.CacheResource.Load(cacheResourcesNodes[crI], protovsl);
                         if (cacheResource != null)
                         {
                             interestedVessel.CachedResources.Add(cacheResource);
                         }
                     }
                     return(interestedVessel);
                 }
             }
         }
     }
     return(null);
 }
 public DeepFreezer(ConfigNode node, InterestedVessel vessel, ProtoPartModuleSnapshot modulesnapshot, ProtoPartSnapshot partsnapshot)
 {
     if (node == null)
     {
         Debug.Log("[UnloadedResources]: SolarPanel - Call to constructor failed. node is null.");
         return;
     }
     if (vessel == null)
     {
         Debug.Log("[UnloadedResources]: SolarPanel - Call to constructor failed. vessel is null.");
         return;
     }
     if (modulesnapshot == null)
     {
         Debug.Log("[UnloadedResources]: SolarPanel - Call to constructor failed. modulesnapshot is null.");
         return;
     }
     if (partsnapshot == null)
     {
         Debug.Log("[UnloadedResources]: SolarPanel - Call to constructor failed. partsnapshot is null.");
         return;
     }
     this.vessel     = vessel;
     this.PartModule = modulesnapshot;
     this.ProtoPart  = partsnapshot;
 }
예제 #3
0
 /// <summary>
 /// Other mods need to call this to start processing a ProtoVessel.
 /// Will write this into an API in future version.
 /// </summary>
 /// <param name="vessel"></param>
 public void AddInterestedVessel(ProtoVessel vessel)
 {
     if (!InterestedVessels.Contains(vessel))
     {
         InterestedVessel iVessel = new InterestedVessel(vessel.vesselRef, vessel);
         InterestedVessels.Add(vessel, iVessel);
         CacheResources.CreatecachedVesselResources(vessel);
     }
 }
예제 #4
0
 /// <summary>
 /// Updates the Vessel ResourceCache Overflow
 /// </summary>
 /// <param name="vessel"></param>
 private void UpdateResourceCacheOverflows(InterestedVessel vessel)
 {
     //if (vessel.vessel.loaded)
     //{
     //    vessel.ClearCaches();
     //}
     //else
     //{
     vessel.UpdateCaches();
     //}
 }
예제 #5
0
 /// <summary>
 /// Process the module handlers for a protovessel we are interested in.
 /// </summary>
 /// <param name="vessel"></param>
 private void ProcessInterestedModules(InterestedVessel vessel)
 {
     if (vessel.vessel.loaded) //If vessel is loaded don't process resources.
     {
         return;
     }
     for (int i = 0; i < vessel.ModuleHandlers.Count; i++)
     {
         vessel.ModuleHandlers[i].ProcessHandler();
     }
 }
        /// <summary>
        /// Create or update a InterestedVessels entry's CachedResources for a ProtoVessel.
        /// </summary>
        /// <param name="vessel"></param>
        public static void CreatecachedVesselResources(ProtoVessel vessel)
        {
            if (UnloadedResources.InterestedVessels == null)
            {
                UnloadedResources.InterestedVessels = new DictionaryValueList <ProtoVessel, InterestedVessel>();
            }
            List <CacheResource> cacheresources = new List <CacheResource>();

            for (int i = 0; i < vessel.protoPartSnapshots.Count; i++)
            {
                ProtoPartSnapshot protoPartSnapshot = vessel.protoPartSnapshots[i];
                for (int j = 0; j < protoPartSnapshot.resources.Count; j++)
                {
                    ProtoPartResourceSnapshot protoPartResourceSnapshot = protoPartSnapshot.resources[j];
                    bool found = false;
                    for (int k = 0; k < cacheresources.Count; k++)
                    {
                        if (cacheresources[k].resourceName == protoPartResourceSnapshot.resourceName)
                        {
                            cacheresources[k].amount    += protoPartResourceSnapshot.amount;
                            cacheresources[k].maxAmount += protoPartResourceSnapshot.maxAmount;
                            cacheresources[k].protoPartResourceSnapshot.Add(CacheResource.GetKey(protoPartSnapshot, protoPartResourceSnapshot), protoPartResourceSnapshot);
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        CacheResource newresource = new CacheResource(protoPartSnapshot.craftID, protoPartResourceSnapshot, protoPartResourceSnapshot.resourceName, protoPartResourceSnapshot.amount, protoPartResourceSnapshot.maxAmount);
                        cacheresources.Add(newresource);
                    }
                }
            }
            if (UnloadedResources.InterestedVessels.Contains(vessel))
            {
                UnloadedResources.InterestedVessels[vessel].CachedResources = cacheresources;
            }
            else
            {
                InterestedVessel iVessel = new InterestedVessel(vessel.vesselRef, vessel);
                iVessel.CachedResources = cacheresources;
                UnloadedResources.InterestedVessels.Add(vessel, iVessel);
                UnloadedResources.InterestedVessels[vessel].TimeLastRefresh = Time.time;
            }
        }
예제 #7
0
        private void UpdateInterestedVessels()
        {
            List <Vessel> allVessels = FlightGlobals.Vessels;

            for (int i = 0; i < allVessels.Count; i++)
            {
                if (allVessels[i].loaded)
                {
                    RemoveInterestedVessel(allVessels[i].protoVessel);
                }
                else if (!allVessels[i].loaded && !InterestedVessels.ContainsKey(allVessels[i].protoVessel))
                {
                    if (InterestedVessel.ContainsInterestedModules(allVessels[i].protoVessel))
                    {
                        AddInterestedVessel(allVessels[i].protoVessel);
                    }
                }
            }
        }
예제 #8
0
 public Generator(ConfigNode node, InterestedVessel vessel, ProtoPartModuleSnapshot modulesnapshot, ProtoPartSnapshot partsnapshot)
 {
     this.vessel     = vessel;
     this.PartModule = modulesnapshot;
     node.TryGetValue("generatorIsActive", ref generatorIsActive);
     ConfigNode[] modulenodes = partsnapshot.partInfo.partConfig.GetNodes();
     for (int i = 0; i < modulenodes.Length; i++)
     {
         ConfigNode resNode = new ConfigNode();
         if (modulenodes[i].TryGetNode("OUTPUT_RESOURCE", ref resNode))
         {
             string resName = string.Empty;
             resNode.TryGetValue("name", ref resName);
             if (resName == "ElectricCharge")
             {
                 resNode.TryGetValue("rate", ref rate);
             }
         }
     }
 }
 public override void OnLoad(ConfigNode gameNode)
 {
     base.OnLoad(gameNode);
     if (gameNode.HasNode(configNodeName))
     {
         ConfigNode settingsNode = gameNode.GetNode(configNodeName);
         InterestedVessels.Clear();
         var vesselNodes = settingsNode.GetNodes(InterestedVessel.configNodeName);
         foreach (ConfigNode vesselNode in vesselNodes)
         {
             InterestedVessel interestedVessel = InterestedVessel.Load(vesselNode);
             if (interestedVessel != null)
             {
                 ProtoVessel key = interestedVessel.protovessel;
                 InterestedVessels.Add(key, interestedVessel);
             }
         }
     }
     Utilities.Log("OnLoad: ", gameNode);
 }
예제 #10
0
 public TacGenericConverter(ConfigNode node, InterestedVessel vessel, ProtoPartModuleSnapshot modulesnapshot, ProtoPartSnapshot partsnapshot)
 {
     this.vessel     = vessel;
     this.PartModule = modulesnapshot;
     if (partsnapshot != null && partsnapshot.partPrefab != null)
     {
         for (int i = 0; i < partsnapshot.partPrefab.Modules.Count; i++)
         {
             BaseConverter           converter    = partsnapshot.partPrefab.Modules[i] as BaseConverter;
             Tac.TacGenericConverter tacConverter = partsnapshot.partPrefab.Modules[i] as Tac.TacGenericConverter;
             if (converter != null && tacConverter != null)
             {
                 inputResList    = converter.inputList;
                 outputResList   = converter.outputList;
                 requiredResList = converter.reqList;
             }
         }
     }
     node.TryGetValue("IsActivated", ref converterIsActive);
 }
예제 #11
0
 public ModuleResourceConverter(ConfigNode node, InterestedVessel vessel, ProtoPartModuleSnapshot modulesnapshot, ProtoPartSnapshot partsnapshot)
 {
     this.vessel     = vessel;
     this.PartModule = modulesnapshot;
     node.TryGetValue("IsActivated", ref converterIsActive);
     if (partsnapshot != null && partsnapshot.partPrefab != null)
     {
         for (int i = 0; i < partsnapshot.partPrefab.Modules.Count; i++)
         {
             BaseConverter converter    = partsnapshot.partPrefab.Modules[i] as BaseConverter;
             bool          tacConverter = partsnapshot.partPrefab.Modules[i].ClassID == "Tac.TacGenericConverter".GetHashCode();
             if (converter != null && tacConverter)
             {
                 inputResList    = converter.inputList;
                 outputResList   = converter.outputList;
                 requiredResList = converter.reqList;
             }
         }
     }
     this.moduleType = UnloadedResources.ModuleType.Both;
 }
예제 #12
0
        public SolarPanel(ConfigNode node, InterestedVessel vessel, ProtoPartModuleSnapshot modulesnapshot, ProtoPartSnapshot partsnapshot)
        {
            if (node == null)
            {
                Debug.Log("[UnloadedResources]: SolarPanel - Call to constructor failed. node is null.");
                return;
            }
            if (vessel == null)
            {
                Debug.Log("[UnloadedResources]: SolarPanel - Call to constructor failed. vessel is null.");
                return;
            }
            if (modulesnapshot == null)
            {
                Debug.Log("[UnloadedResources]: SolarPanel - Call to constructor failed. modulesnapshot is null.");
                return;
            }
            if (partsnapshot == null)
            {
                Debug.Log("[UnloadedResources]: SolarPanel - Call to constructor failed. partsnapshot is null.");
                return;
            }
            this.vessel     = vessel;
            this.PartModule = modulesnapshot;

            if (node.HasValue("type"))
            {
                panelType = (ModuleDeployableSolarPanel.PanelType)System.Enum.Parse(typeof(ModuleDeployableSolarPanel.PanelType), node.GetValue("type"));
            }
            node.TryGetValue("chargeRate", ref chargeRate);
            node.TryGetValue("sunAOA", ref this.sunAOA);
            node.TryGetValue("flowRate", ref this.flowRate);
            node.TryGetValue("flowMult", ref this.flowMult);
            node.TryGetValue("efficiencyMult", ref this.efficiencyMult);
            if (node.HasValue("deployState"))
            {
                deployState = (ModuleDeployablePart.DeployState)System.Enum.Parse(typeof(ModuleDeployablePart.DeployState), node.GetValue("deployState"));
            }
            if (deployState != ModuleDeployablePart.DeployState.EXTENDED)
            {
                sunAOA   = 0f;
                flowRate = 0f;
            }
            Part part = PartLoader.getPartInfoByName(partsnapshot.partName).partPrefab;

            if (part == null)
            {
                Debug.Log("[UnloadedResources]: SolarPanel - Unable to Find Part: " + partsnapshot.partName);
                return;
            }
            for (int i = 0; i < part.Modules.Count; ++i)
            {
                if (part.Modules[i].moduleName == "ModuleDeployableSolarPanel" || part.Modules[i].moduleName == "KopernicusSolarPanel")
                {
                    ModuleDeployableSolarPanel panelModule = (ModuleDeployableSolarPanel)part.Modules[i];
                    solarNormal = panelModule.part.FindModelTransform(panelModule.secondaryTransformName).forward;
                    pivotAxis   = panelModule.part.FindModelTransform(panelModule.pivotName).up;
                    sunTracking = panelModule.isTracking && panelModule.trackingMode == ModuleDeployablePart.TrackingMode.SUN;
                    usesCurve   = panelModule.useCurve;
                    tempCurve   = panelModule.temperatureEfficCurve;
                    temperature = (float)partsnapshot.temperature;
                    powerCurve  = panelModule.powerCurve;
                    position    = partsnapshot.position;
                    orientation = partsnapshot.rotation;
                    break;
                }
            }
        }