/// <summary> /// Create an InventoryPart from an origin ConfigNode, extracting the name, dry cost, and relevant MODULEs /// </summary> /// <param name="originPartConfigNode">The <see cref="ConfigNode"/> to use as the basis of the <see cref="InventoryPart"/>.</param> public InventoryPart(ConfigNode originPartConfigNode) { _name = ConfigNodeUtils.PartNameFromNode(originPartConfigNode); float fuelCost; AvailablePart availablePartForNode = ConfigNodeUtils.AvailablePartFromNode(originPartConfigNode); if (availablePartForNode != null) { float dryMass, fuelMass; ShipConstruction.GetPartCostsAndMass(originPartConfigNode, availablePartForNode, out _dryCost, out fuelCost, out dryMass, out fuelMass); } if (originPartConfigNode.HasNode("MODULE")) { foreach (ConfigNode module in originPartConfigNode.GetNodes("MODULE")) { foreach (string trackedModuleName in ScrapYard.Instance.Settings.TrackedModules) { if (module.GetValue("name").ToUpper().Contains(trackedModuleName)) { savedModules.Add(module); } } } } }
/// <summary> /// Create an InventoryPart from an origin ConfigNode, extracting the name, dry cost, and relevant MODULEs /// </summary> /// <param name="originPartConfigNode">The <see cref="ConfigNode"/> to use as the basis of the <see cref="InventoryPart"/>.</param> public InventoryPart(ConfigNode originPartConfigNode) { //if the ConfigNode given is already an InventoryPart, just load it instead if (originPartConfigNode.name == typeof(InventoryPart).FullName) { State = originPartConfigNode; } else { _name = ConfigNodeUtils.PartNameFromNode(originPartConfigNode); if (ScrapYard.Instance.Settings.PartBlacklist.Contains(Name)) { DoNotStore = true; } AvailablePart availablePartForNode = ConfigNodeUtils.AvailablePartFromNode(originPartConfigNode); if (availablePartForNode != null) { float dryMass, fuelMass, fuelCost; ShipConstruction.GetPartCostsAndMass(originPartConfigNode, availablePartForNode, out _dryCost, out fuelCost, out dryMass, out fuelMass); } if (originPartConfigNode.HasNode("MODULE")) { foreach (ConfigNode module in originPartConfigNode.GetNodes("MODULE")) { string name = module.GetValue("name"); bool isTracker = name.Equals("ModuleSYPartTracker"); _allModules.Add(module); if (isTracker) { TrackerModule = new TrackerModuleWrapper(module); } } } uint id = 0; if (originPartConfigNode.TryGetValue("persistentId", ref id)) { ID = id; } else { Logging.Log($"Could not find a persistent ID for part {_name}", Logging.LogType.ERROR); } } }
private static bool GetPartCost(ConfigNode part, out float total, bool includeFuel = true) { string name = GetPartName(part); float dryCost, fuelCost, mass; total = 0; var aP = GetAvailablePart(name); if (aP == null) { return(false); } //ShipConstruction.GetPartCostsAndMass total = ShipConstruction.GetPartCostsAndMass(part, aP, out dryCost, out fuelCost, out mass, out mass); if (!includeFuel) { total = dryCost; } return(ResearchAndDevelopment.PartTechAvailable(aP)); }
//Parse .craft file and read info private void read_craft_info_from_file() { file_name = Path.GetFileNameWithoutExtension(path); CraftData.file_load_count += 1; //increment count of craft loaded from file ConfigNode data = ConfigNode.Load(path); ConfigNode[] parts = data.GetNodes(); AvailablePart matched_part; name = Translate.this_string(data.GetValue("ship")); description = Translate.this_string(data.GetValue("description")); construction_type = data.GetValue("type"); ksp_version = data.GetValue("version"); if (!(construction_type == "SPH" || construction_type == "VAB")) { construction_type = "Subassembly"; } part_count = parts.Length; stage_count = 0; missing_parts = false; cost_dry = 0; cost_fuel = 0; cost_total = 0; mass_dry = 0; mass_fuel = 0; mass_total = 0; crew_capacity = 0; //interim variables used to collect values from GetPartCostsAndMass (defined outside of loop as a garbage reduction measure) float dry_mass = 0; float fuel_mass = 0; float dry_cost = 0; float fuel_cost = 0; string stage; string part_name; foreach (ConfigNode part in parts) { //Set the number of stages in the craft stage = part.GetValue("istg"); if (!String.IsNullOrEmpty(stage)) { int stage_number = int.Parse(stage); if (stage_number > stage_count) { stage_count = stage_number; } } //locate part in game_parts and read part cost/mass information. part_name = get_part_name(part); part_name_list.AddUnique(part_name); matched_part = cache.fetch_part(part_name); if (matched_part != null) { ShipConstruction.GetPartCostsAndMass(part, matched_part, out dry_cost, out fuel_cost, out dry_mass, out fuel_mass); if (matched_part.partConfig.HasValue("CrewCapacity")) { crew_capacity += int.Parse(matched_part.partConfig.GetValue("CrewCapacity")); } cost_dry += dry_cost; cost_fuel += fuel_cost; mass_dry += dry_mass; mass_fuel += fuel_mass; } else { missing_parts = true; } } stage_count += 1; //this might not be right cost_total = cost_dry + cost_fuel; mass_total = mass_dry + mass_fuel; }