protected override void init_from_part()
        {
            //if part has multiple resources, we're in trouble
            if (part.Resources.Count > 1)
            {
                Utils.Message("SwitchableTank module is added to a part with multiple resources!\n" +
                              "This is an error in MM patch.\n" +
                              "SwitchableTank module is disabled.");
                this.EnableModule(false);
                part.Modules.Remove(this);
            }
            var res  = part.Resources[0];
            var tank = TankVolume.FromResource(res);

            if (tank == null)
            {
                Utils.Message("SwitchableTank module is added to a part with unknown resource!\n" +
                              "This is an error in MM patch.\n" +
                              "SwitchableTank module is disabled.");
                this.EnableModule(false);
                part.Modules.Remove(this);
            }
            DoCostPatch     = false;
            DoMassPatch     = true;
            TankType        = tank.TankType;
            CurrentResource = tank.CurrentResource;
            Volume          = tank.Volume;
            InitialAmount   = tank.InitialAmount;
//            this.Log("Initialized from part in flight: TankType {}, CurrentResource {}, Volume {}, InitialAmount {}",
//                     TankType, CurrentResource, Volume, InitialAmount);//debug
        }
Example #2
0
        public static VolumeConfiguration FromResources(IEnumerable <PartResource> resources)
        {
            var volume = new VolumeConfiguration();

            foreach (var res in resources)
            {
                var tank = TankVolume.FromResource(res);
                if (tank == null)
                {
                    return(null);
                }
                volume.Volumes.Add(tank);
            }
            volume.Volume = volume.TotalVolume;
            return(volume);
        }