float getFuelForPartAndFueltype(Part p, int fuelType) { if (p is IFuelSource) { IFuelSource ifs = (IFuelSource)p; if (!ifs.FuelType.Equals(fts.ElementAt(fuelType))) { return(-1); } return(ifs.Fuel); } if (fuelType == RegularFuel) { if (p is FuelTank) { return(((FuelTank)p).fuel); } } else if (fuelType == RCSFuel) { if (p is RCSFuelTank) { return(((RCSFuelTank)p).fuel); } } return(-1); }
public PowerInfo(IInputController inputController, IFuelSource Battery, float InputVolt, float MaxAmpere, float Resistance) { _input = inputController; _battery = Battery; _inputVolt = InputVolt; _maxAmpere = MaxAmpere; _resistance = Resistance; }
List <String> otherFuelParts() { List <String> ret = new List <String> (); foreach (Vessel v in FlightGlobals.Vessels) { foreach (Part p in v.parts) { if (p is IFuelSource) { IFuelSource ifs = (IFuelSource)p; if (!ret.Contains(ifs.FuelType)) { ret.Add(ifs.FuelType); } } } } return(ret); }
bool transferFuel(Part source, Part dest, float amount, int FuelType) { bool wasDeactive = false; if (dest.State == PartStates.DEACTIVATED) { dest.force_activate(); wasDeactive = true; } float fuelBefore = getFuelForPartAndFueltype(source, FuelType); bool deactivated = false; if (source is IFuelSource) { IFuelSource ifs = (IFuelSource)source; if (ifs.FuelType.Equals(fts.ElementAt(FuelType)) && ifs.RequestFuel(amount, fts.ElementAt(FuelType))) { addFuel(dest, amount, FuelType); /* * if (fuelBefore - amount != getFuelForPartAndFueltype(source, FuelType)) { * addFuel(source, fuelBefore - amount, FuelType); * } */ } if (ifs.Fuel <= 0.0) { source.deactivate(); deactivated = true; } } else { if (FuelType == RegularFuel && source is FuelTank) { FuelTank ft = (FuelTank)source; ft.fuel -= amount; addFuel(dest, amount, FuelType); if (ft.fuel <= 0.0) { ft.deactivate(); deactivated = true; } } else if (FuelType == RCSFuel && source is RCSFuelTank) { RCSFuelTank ft = (RCSFuelTank)source; ft.fuel -= amount; addFuel(dest, amount, FuelType); /* * if (fuelBefore - amount != getFuelForPartAndFueltype(source, FuelType)) { * addFuel(source, fuelBefore - amount, FuelType); * } */ if (ft.fuel <= 0.0) { ft.deactivate(); deactivated = true; } } } if (wasDeactive) { source.deactivate(); } return(deactivated); }
public override void OnCraftStructureChanged(ICraftScript craftScript) { this._battery = this.PartScript?.BatteryFuelSource; }
public void UpdateBattery(IFuelSource Battery) { _battery = Battery; }