ExLP.ExLaunchPad.getBuildCost C# (CSharp) Method

getBuildCost() public method

public getBuildCost ( ConfigNode nodes ) : double>.Dictionary
nodes System.ConfigNode
return double>.Dictionary
        public Dictionary<string, double> getBuildCost(ConfigNode[] nodes)
        {
            float mass = 0.0f;
            Dictionary<string, double> resources = new Dictionary<string, double>();
            Dictionary<string, double> hull_resources = new Dictionary<string, double>();
            Dictionary<string, bool> missing_parts = new Dictionary<string, bool>();

            foreach (ConfigNode node in nodes) {
            string part_name = node.GetValue("part");
            part_name = part_name.Remove(part_name.LastIndexOf("_"));
            AvailablePart ap = PartLoader.getPartInfoByName(part_name);
            if (ap == null) {
                missing_parts[part_name] = true;
                continue;
            }
            Part p = ap.partPrefab;
            mass += p.mass;
            foreach (PartResource r in p.Resources) {
                if (r.resourceName == "IntakeAir" || r.resourceName == "KIntakeAir") {
                    // Ignore intake Air
                    continue;
                }

                Dictionary<string, double> res_dict = resources;

                PartResourceDefinition res_def;
                res_def = PartResourceLibrary.Instance.GetDefinition(r.resourceName);
                if (res_def.resourceTransferMode == ResourceTransferMode.NONE
                    || res_def.resourceFlowMode == ResourceFlowMode.NO_FLOW) {
                    res_dict = hull_resources;
                }

                if (!res_dict.ContainsKey(r.resourceName)) {
                    res_dict[r.resourceName] = 0.0;
                }
                res_dict[r.resourceName] += r.maxAmount;
            }
            }
            if (missing_parts.Count > 0) {
            MissingPopup(missing_parts);
            return null;
            }

            // RocketParts for the hull is a separate entity to RocketParts in
            // storage containers
            PartResourceDefinition rp_def;
            rp_def = PartResourceLibrary.Instance.GetDefinition("RocketParts");
            uis.hullRocketParts = mass / rp_def.density;

            // If non pumpable resources are used, convert to RocketParts
            foreach (KeyValuePair<string, double> pair in hull_resources) {
            PartResourceDefinition res_def;
            res_def = PartResourceLibrary.Instance.GetDefinition(pair.Key);
            double hull_mass = pair.Value * res_def.density;
            double hull_parts = hull_mass / rp_def.density;
            uis.hullRocketParts += hull_parts;
            }

            // If there is JetFuel (ie LF only tanks as well as LFO tanks - eg a SpacePlane) then split off the Surplus LF as "JetFuel"
            if (resources.ContainsKey("Oxidizer") && resources.ContainsKey("LiquidFuel")) {
            double jetFuel = 0.0;
            // The LiquidFuel:Oxidizer ratio is 9:11. Try to minimize rounding effects.
            jetFuel = (11 * resources["LiquidFuel"] - 9 * resources["Oxidizer"]) / 11;
            if (jetFuel < 0.01)	{
                // Forget it. not getting far on that. Any discrepency this
                // small will be due to precision losses.
                jetFuel = 0.0;
            }
            resources["LiquidFuel"] -= jetFuel;
            resources["JetFuel"] = jetFuel;
            }

            return resources;
        }