Esempio n. 1
0
        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
        }
Esempio n. 2
0
        public static TankVolume FromResource(PartResource res)
        {
            var tank      = new TankVolume();
            var tank_type = SwitchableTankType.FindTankType(res.resourceName);

            if (tank_type == null)
            {
                return(null);
            }
            tank.TankType        = tank_type.name;
            tank.CurrentResource = res.resourceName;
            tank.Volume          = (float)(res.maxAmount / tank_type.Resources[res.resourceName].UnitsPerLiter / 1000 / tank_type.UsefulVolumeRatio);
            tank.InitialAmount   = (float)(res.amount / res.maxAmount);
            return(tank);
        }
Esempio n. 3
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);
        }