float metal_for_tank(string tank_name, float volume)
        {
            var type = SwitchableTankType.GetTankType(tank_name);

            return(type != null?type.AddMass(volume) / metal_pump.Resource.density : 0);
        }
示例#2
0
 bool init_tank_type()
 {
     //check if the tank is in use
     if( tank_type != null &&
         current_resource != null &&
         current_resource.amount > 0)
         {
             ScreenMessager.showMessage("Cannot change tank type while tank is in use");
             TankType = tank_type.name;
             return false;
         }
     //setup new tank type
     tank_type = null;
     //if tank type is not provided, use the first one from the library
     if(string.IsNullOrEmpty(TankType))
     { TankType = SwitchableTankType.TankTypeNames[0]; }
     //select tank type from the library
     if(!SwitchableTankType.TankTypes.TryGetValue(TankType, out tank_type))
         ScreenMessager.showMessage(6, "Hangar: No \"{0}\" tank type in the library. Configuration of \"{1}\" is INVALID.",
             TankType, this.Title());
     //switch off the UI
     HangarGUI.EnableField(Fields["CurrentResource"], false);
     Utils.UpdateEditorGUI();
     if(tank_type == null) return false;
     //initialize new tank UI if needed
     init_res_control();
     //initialize current resource
     if(CurrentResource == string.Empty ||
         !tank_type.Resources.ContainsKey(CurrentResource))
         CurrentResource = tank_type.DefaultResource.Name;
     switch_resource();
     return true;
 }