private void UpdateTankType(bool initializeAmounts = true) { if (oldType == type || type == null) { return; } // Copy the tank list from the tank definitiion TankDefinition def; if (!MFSSettings.tankDefinitions.Contains(type)) { Debug.LogError("Unable to find tank definition for type \"" + type + "\" reverting."); type = oldType; return; } def = MFSSettings.tankDefinitions[type]; if (!def.canHave) { type = oldType; if (oldType != null && oldType != "") // we have an old type { def = MFSSettings.tankDefinitions[type]; if (def.canHave) { return; // go back to old type } } // else find one that does work foreach (TankDefinition newDef in MFSSettings.tankDefinitions) { if (newDef.canHave) { def = newDef; type = newDef.name; break; } } if (type == oldType) // if we didn't find a new one { Debug.LogError("Unable to find a type that is tech-available for part " + part.name); return; } } oldType = type; // Build the new tank list. tankList = new FuelTankList(); for (int i = 0; i < def.tankList.Count; i++) { FuelTank tank = def.tankList[i]; // Pull the override from the list of overrides ConfigNode overNode = MFSSettings.GetOverrideList(part).FirstOrDefault(n => n.GetValue("name") == tank.name); tankList.Add(tank.CreateCopy(this, overNode, initializeAmounts)); } tankList.TechAmounts(); // update for current techs // Destroy any managed resources that are not in the new type. HashSet <string> managed = MFSSettings.managedResources[part.name]; // if this throws, we have some big fish to fry bool needsMesage = false; for (int i = part.Resources.Count - 1; i >= 0; --i) { PartResource partResource = part.Resources[i]; string resname = partResource.resourceName; if (!managed.Contains(resname) || tankList.Contains(resname)) { continue; } part.Resources.Remove(partResource.info.id); needsMesage = true; } if (needsMesage) { RaiseResourceListChanged(); } if (!basemassOverride) { ParseBaseMass(def.basemass); } if (!baseCostOverride) { ParseBaseCost(def.baseCost); } if (!isDatabaseLoad) { // being called in the SpaceCenter scene is assumed to be a database reload //FIXME is this really needed? massDirty = true; } UpdateTankTypeRF(def); UpdateTestFlight(); }
private void UpdateTankType(bool initializeAmounts = true) { if (oldType == type || type == null) { return; } // Copy the tank list from the tank definitiion TankDefinition def; if (!MFSSettings.tankDefinitions.Contains(type)) { Debug.LogError("Unable to find tank definition for type \"" + type + "\" reverting."); type = oldType; return; } def = MFSSettings.tankDefinitions[type]; oldType = type; // Build the new tank list. tankList = new FuelTankList(); for (int i = 0; i < def.tankList.Count; i++) { FuelTank tank = def.tankList[i]; // Pull the override from the list of overrides ConfigNode overNode = overrideListNodes.FirstOrDefault(n => n.GetValue("name") == tank.name); tankList.Add(tank.CreateCopy(this, overNode, initializeAmounts)); } // Destroy any managed resources that are not in the new type. HashSet <string> managed = MFSSettings.managedResources[part.name]; // if this throws, we have some big fish to fry bool needsMesage = false; for (int i = part.Resources.Count - 1; i >= 0; --i) { PartResource partResource = part.Resources[i]; string resname = partResource.resourceName; if (!managed.Contains(resname) || tankList.Contains(resname)) { continue; } part.Resources.list.RemoveAt(i); DestroyImmediate(partResource); needsMesage = true; } if (needsMesage) { RaiseResourceListChanged(); } if (!basemassOverride) { ParseBaseMass(def.basemass); } if (!baseCostOverride) { ParseBaseCost(def.baseCost); } if (isDatabaseLoad) { // being called in the SpaceCenter scene is assumed to be a database reload //FIXME is this really needed? return; } UpdateEngineIgnitor(def); massDirty = true; }