예제 #1
0
        public override void OnLoad(ConfigNode node)
        {
            if (!compatible)
            {
                return;
            }

            UI_FloatRange f = (UI_FloatRange)(Fields["utilization"].uiControlEditor);

            f.minValue  = minUtilization;
            f.maxValue  = maxUtilization;
            utilization = Mathf.Clamp(utilization, minUtilization, maxUtilization);

            if (MFSSettings.tankDefinitions == null)
            {
                MFSSettings.Initialize();
            }

            // Load the volume. If totalVolume is specified, use that to calc the volume
            // otherwise scale up the provided volume. No KSPField support for doubles
            if (node.HasValue("totalVolume") && double.TryParse(node.GetValue("totalVolume"), out totalVolume))
            {
                ChangeTotalVolume(totalVolume);
            }
            else if (node.HasValue("volume") && double.TryParse(node.GetValue("volume"), out volume))
            {
                totalVolume = volume * 100d / utilization;
            }
            if (isDatabaseLoad)
            {
                MFSSettings.SaveOverrideList(part, node.GetNodes("TANK"));
                ParseBaseMass(node);
                ParseBaseCost(node);
                ParseInsulationFactor(node);
                typesAvailable = node.GetValues("typeAvailable");
                RecordManagedResources();
            }
            else if (isEditorOrFlight)
            {
                // The amounts initialized flag is there so that the tank type loading doesn't
                // try to set up any resources. They'll get loaded directly from the save.
                UpdateTankType(false);
                // Destroy any resources still hanging around from the LOADING phase
                for (int i = part.Resources.Count - 1; i >= 0; --i)
                {
                    PartResource partResource = part.Resources[i];
                    if (!tankList.Contains(partResource.resourceName))
                    {
                        continue;
                    }
                    part.Resources.Remove(partResource.info.id);
                    part.SimulationResources.Remove(partResource.info.id);
                }
                RaiseResourceListChanged();
                // Setup the mass
                massDirty = true;
                CalculateMass();
            }
            OnLoadRF(node);
        }
예제 #2
0
        public override void OnLoad(ConfigNode node)
        {
            if (!compatible)
            {
                return;
            }

            // Make sure this isn't an upgrade node because if we got here during an upgrade application
            // then RaiseResourceListChanged will throw an error when it hits SendEvent()

            if (node.name == "CURRENTUPGRADE")
            {
                // If there's ever a need for special upgrade handling, put that code here.
            }
            else
            {
                InitUtilization();
                if (MFSSettings.tankDefinitions == null)
                {
                    MFSSettings.Initialize();
                }
                InitVolume(node);

                ConfigNode[] unmanagedResourceNodes = node.GetNodes("UNMANAGED_RESOURCE");
                //Debug.Log("[ModuleFuelTanks.OnLoad()] " + unmanagedResourceNodes.Count() + " UNMANAGED_RESOURCE nodes found");
                for (int i = unmanagedResourceNodes.Count() - 1; i >= 0; --i)
                {
                    string name      = "";
                    double amount    = 0;
                    double maxAmount = 0;
                    // we're going to be strict and demand all of these be present
                    if (!unmanagedResourceNodes[i].HasValue("name") || !unmanagedResourceNodes[i].HasValue("amount") || !unmanagedResourceNodes[i].HasValue("maxAmount"))
                    {
                        Debug.Log("[ModuleFuelTanks.OnLoad()] was missing either name, amount or maxAmount for UNMANAGED_RESOURCE: " + name);
                        continue;
                    }
                    name = unmanagedResourceNodes[i].GetValue("name");
                    if (PartResourceLibrary.Instance.GetDefinition(name) == null)
                    {
                        Debug.Log("[ModuleFuelTanks.OnLoad()] could not find resource by the name of " + name);
                        continue;
                    }
                    double.TryParse(unmanagedResourceNodes[i].GetValue("amount"), out amount);
                    double.TryParse(unmanagedResourceNodes[i].GetValue("maxAmount"), out maxAmount);
                    amount    = Math.Max(amount, 0d);
                    maxAmount = Math.Max(amount, maxAmount);
                    if (!unmanagedResources.ContainsKey(name))
                    {
                        if (maxAmount > 0)
                        {
                            unmanagedResources.Add(name, new UnmanagedResource(name, amount, maxAmount));
                            Debug.Log("[ModuleFuelTanks.OnLoad()] added new UnmanagedResource " + name + " with " + amount + "/" + maxAmount);
                            if (!part.Resources.Contains(name))
                            {
                                ConfigNode resNode = new ConfigNode("RESOURCE");
                                resNode.AddValue("name", name);
                                resNode.AddValue("amount", amount);
                                resNode.AddValue("maxAmount", maxAmount);
                                part.AddResource(resNode);
                            }
                        }
                        else
                        {
                            Debug.Log("[ModuleFuelTanks.OnLoad()] did not add new UnmanagedResource; maxAmount = 0");
                        }
                    }
                    else
                    {
                        if (maxAmount > 0)
                        {
                            unmanagedResources[name].amount    += amount;
                            unmanagedResources[name].maxAmount += maxAmount;
                            //Debug.Log("[ModuleFuelTanks.OnLoad()] modified UnmanagedResource: " + name + "; amount = " + amount + " / maxAmount = " + maxAmount);

                            // this should be safe; if we're here then we previously would have added this resource if missing.
                            part.Resources[name].amount    = Math.Max(part.Resources[name].amount, unmanagedResources[name].amount);
                            part.Resources[name].maxAmount = Math.Max(part.Resources[name].maxAmount, unmanagedResources[name].maxAmount);
                        }
                        else
                        {
                            Debug.Log("[ModuleFuelTanks.OnLoad()] did not add new UnmanagedResource; maxAmount = 0");
                        }
                    }
                }

                if (isDatabaseLoad)
                {
                    MFSSettings.SaveOverrideList(part, node.GetNodes("TANK"));
                    ParseBaseMass(node);
                    ParseBaseCost(node);
                    ParseInsulationFactor(node);
                    typesAvailable = node.GetValues("typeAvailable");
                    RecordManagedResources();
                }
                else if (isEditorOrFlight)
                {
                    // The amounts initialized flag is there so that the tank type loading doesn't
                    // try to set up any resources. They'll get loaded directly from the save.
                    UpdateTankType(false);

                    CleanResources();

                    // Destroy any resources still hanging around from the LOADING phase
                    for (int i = part.Resources.Count - 1; i >= 0; --i)
                    {
                        PartResource partResource = part.Resources[i];
                        if (!tankList.Contains(partResource.resourceName) && !unmanagedResources.ContainsKey(partResource.resourceName))
                        {
                            part.Resources.Remove(partResource.info.id);
                            part.SimulationResources.Remove(partResource.info.id);
                        }
                    }
                    RaiseResourceListChanged();

                    // Setup the mass
                    massDirty = true;
                    CalculateMass();
                }
            }
        }
예제 #3
0
        public override void OnLoad(ConfigNode node)
        {
            if (!compatible)
            {
                return;
            }

            UI_FloatRange f = (UI_FloatRange)(Fields["utilization"].uiControlEditor);

            f.minValue  = minUtilization;
            f.maxValue  = maxUtilization;
            utilization = Mathf.Clamp(utilization, minUtilization, maxUtilization);

            if (MFSSettings.tankDefinitions == null)
            {
                MFSSettings.Initialize();
            }

            // Load the volume. If totalVolume is specified, use that to calc the volume
            // otherwise scale up the provided volume. No KSPField support for doubles
            if (node.HasValue("totalVolume") && double.TryParse(node.GetValue("totalVolume"), out totalVolume))
            {
                ChangeTotalVolume(totalVolume);
            }
            else if (node.HasValue("volume") && double.TryParse(node.GetValue("volume"), out volume))
            {
                totalVolume = volume * 100d / utilization;
            }

            ConfigNode[] unmanagedResourceNodes = node.GetNodes("UNMANAGED_RESOURCE");
            Debug.Log("[ModuleFuelTanks.OnLoad()] " + unmanagedResourceNodes.Count() + " UNMANAGED_RESOURCE nodes found");
            for (int i = unmanagedResourceNodes.Count() - 1; i >= 0; --i)
            {
                string name;
                double amount    = 0;
                double maxAmount = 0;
                // we're going to be strict and demand all of these be present
                if (!unmanagedResourceNodes[i].HasValue("name") || !unmanagedResourceNodes[i].HasValue("amount") || !unmanagedResourceNodes[i].HasValue("maxAmount"))
                {
                    Debug.Log("[ModuleFuelTanks.OnLoad()] was missing either name, amount or maxAmount");
                    continue;
                }
                name = unmanagedResourceNodes[i].GetValue("name");
                if (PartResourceLibrary.Instance.GetDefinition(name) == null)
                {
                    Debug.Log("[ModuleFuelTanks.OnLoad()] could not find resource by the name of " + name);
                    continue;
                }
                double.TryParse(unmanagedResourceNodes[i].GetValue("amount"), out amount);
                double.TryParse(unmanagedResourceNodes[i].GetValue("maxAmount"), out maxAmount);
                maxAmount = Math.Max(amount, maxAmount);
                if (maxAmount > 0 && !unmanagedResources.ContainsKey(name))
                {
                    unmanagedResources.Add(name, new UnmanagedResource(name, amount, maxAmount));
                    Debug.Log("[ModuleFuelTanks.OnLoad()] added new UnmanagedResource " + name + " with " + amount + "/" + maxAmount);
                }
                else
                {
                    Debug.Log("[ModuleFuelTanks.OnLoad()] did not add new UnmanagedResource; maxAmount = 0");
                }
            }

            if (isDatabaseLoad)
            {
                MFSSettings.SaveOverrideList(part, node.GetNodes("TANK"));
                ParseBaseMass(node);
                ParseBaseCost(node);
                ParseInsulationFactor(node);
                typesAvailable = node.GetValues("typeAvailable");
                RecordManagedResources();
            }
            else if (isEditorOrFlight)
            {
                // The amounts initialized flag is there so that the tank type loading doesn't
                // try to set up any resources. They'll get loaded directly from the save.
                UpdateTankType(false);
                CleanResources();

                // Destroy any resources still hanging around from the LOADING phase
                for (int i = part.Resources.Count - 1; i >= 0; --i)
                {
                    PartResource partResource = part.Resources[i];
                    if (!tankList.Contains(partResource.resourceName) || unmanagedResources.ContainsKey(partResource.resourceName))
                    {
                        continue;
                    }
                    part.Resources.Remove(partResource.info.id);
                    part.SimulationResources.Remove(partResource.info.id);
                }
                RaiseResourceListChanged();
                // Setup the mass
                massDirty = true;
                CalculateMass();
            }
            OnLoadRF(node);
        }
예제 #4
0
        public override void OnLoad(ConfigNode node)
        {
            if (!compatible)
            {
                return;
            }

            if (MFSSettings.tankDefinitions == null)
            {
                MFSSettings.Initialize();
            }

            // Load the volume. If totalVolume is specified, use that to calc the volume
            // otherwise scale up the provided volume. No KSPField support for doubles
            if (node.HasValue("totalVolume") && double.TryParse(node.GetValue("totalVolume"), out totalVolume))
            {
                ChangeTotalVolume(totalVolume);
            }
            else if (node.HasValue("volume") && double.TryParse(node.GetValue("volume"), out volume))
            {
                totalVolume = volume * 100d / utilization;
            }
            using (PartMessageService.Instance.Ignore(this, null, typeof(PartResourcesChanged))) {
                if (isDatabaseLoad)
                {
                    MFSSettings.SaveOverrideList(part, node.GetNodes("TANK"));
                    ParseBaseMass(node);
                    ParseBaseCost(node);
                    typesAvailable = node.GetValues("typeAvailable");
                    RecordManagedResources();
                }
                else if (isEditorOrFlight)
                {
                    // The amounts initialized flag is there so that the tank type loading doesn't
                    // try to set up any resources. They'll get loaded directly from the save.
                    UpdateTankType(false);
                    // Destroy any resources still hanging around from the LOADING phase
                    for (int i = part.Resources.Count - 1; i >= 0; --i)
                    {
                        PartResource partResource = part.Resources[i];
                        if (!tankList.Contains(partResource.resourceName))
                        {
                            continue;
                        }
                        part.Resources.list.RemoveAt(i);
                        DestroyImmediate(partResource);
                    }
                    RaiseResourceListChanged();
                    // Setup the mass
                    part.mass = mass;
                    MassChanged(mass);
                    // compute massDelta based on prefab, if available.
                    if ((object)(part.partInfo) != null)
                    {
                        if ((object)(part.partInfo.partPrefab) != null)
                        {
                            massDelta = part.mass - part.partInfo.partPrefab.mass;
                        }
                    }
                }
            }
        }