Refactoring: Steam engine liquid extraction

The steam engine treats barrels the same as itself when it comes to extracting liquids. This removes the need for the callback OnFuelRemoved() in the barrel, as well as the stupid definition call from the barrel to the steam engine.
liquid_container
Mark 2016-02-10 06:21:13 +01:00
parent 514eae0102
commit 7a3be2dd62
2 changed files with 3 additions and 21 deletions

View File

@ -226,24 +226,6 @@ func IsFuel()
return WildcardMatch("Oil", GetLiquidType());
}
// Gets the amount of fuel that is stored in the barrel
func GetFuelAmount(bool partial)
{
if (partial)
{
return SteamEngine->GetFuelValue(GetLiquidType(), GetLiquidFillLevel());
}
return SteamEngine->GetFuelValue(GetLiquidType(), GetLiquidContainerMaxFillLevel());
}
// Callback from the steam engine: if this returns true, then the barrel is not removed
func OnFuelRemoved(int amount)
{
RemoveLiquid(nil, amount);
return true;
}
func GetNameForBarrel(string liquid)
{
if (liquid == nil) return this.Prototype.Name;

View File

@ -144,15 +144,15 @@ func RefillFuel(bool cancel)
// Search for new fuel among the contents.
var fuel = GetFuelContents();
if (!fuel)
if (!fuel || fuel->~IsLiquidContainer())
{
fuel = fuel ?? this;
// Extract the fuel amount from stored liquids
var fuel_stored = RemoveLiquid(nil, nil);
var fuel_stored = fuel->RemoveLiquid(nil, nil);
fuel_extracted = GetFuelValue(fuel_stored[0], fuel_stored[1]);
}
else
{
// Extract the fuel amount from the new piece of fuel.
fuel_extracted = fuel->~GetFuelAmount(true);
if (!fuel->~OnFuelRemoved(fuel_extracted)) fuel->RemoveObject();
}