private void LoadPartModulesAndFields()
        {
            _roTankPM   = part.Modules.GetModule("ModuleROTank");
            _procPartPM = part.Modules.GetModule("ProceduralPart");
            if (_procPartPM != null)
            {
                BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy;
                _procPartMinVolumeField = _procPartPM.GetType().GetField("volumeMin", flags);
                _procPartCurShapeProp   = _procPartPM.GetType().GetProperty("CurrentShape", flags);
            }

            _rfPM = part.Modules.GetModule <ModuleFuelTanks>();
            var fiTanks = typeof(ModuleFuelTanks).GetField("tankList", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);

            _tankList = (FuelTankList)fiTanks.GetValue(_rfPM);
            _ecTank   = _tankList["ElectricCharge"];

            _seekVolumeMethod = GetSeekVolumeMethod();
        }
        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("Unalbe to find a type that is tech-available for part " + part.name);
                    return;
                }
            }

            oldType = type;

            // Get pressurization
            highlyPressurized = def.highlyPressurized;

            // 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.list.RemoveAt (i);
                DestroyImmediate (partResource);
                needsMesage = true;
            }
            if (needsMesage) {
                RaiseResourceListChanged ();
            }
            if (!basemassOverride) {
                ParseBaseMass (def.basemass);
            }
            if (!baseCostOverride) {
                ParseBaseCost (def.baseCost);
            }

            UpdateTFInterops();

            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;
        }