Producers handle fuel and liquid with liquid objects

liquid_container
Mark 2016-02-27 15:04:37 +01:00
parent a524e7db2c
commit 7561779d8c
3 changed files with 31 additions and 12 deletions

View File

@ -307,3 +307,12 @@ func CreateLiquid(string liquid_name, int amount)
item.volume = amount;
return item;
}
/**
Gets the amount of fuel that a specific type of liquid is worth.
*/
func GetFuelValue(string liquid, int amount)
{
if (liquid == "Oil") return amount;
return 0;
}

View File

@ -583,11 +583,28 @@ public func CheckFuel(id product, bool remove)
{
// Remove the fuel needed.
fuel_amount = 0;
var fuel_needed = FuelNeed(product);
for (var fuel in FindObjects(Find_Container(this), Find_Func("IsFuel")))
{
fuel_amount += fuel->~GetFuelAmount(false);
fuel->RemoveObject();
if (fuel_amount >= FuelNeed(product))
var fuel_extracted = 0;
var max_extracted = fuel_needed - fuel_amount;
if (fuel->~IsLiquidContainer())
{
// Extract the fuel amount from stored liquids
var fuel_stored = fuel->RemoveLiquid(nil, max_extracted);
fuel_extracted = Library_Liquid->GetFuelValue(fuel_stored[0], fuel_stored[1]);
}
else
{
fuel_extracted = Min(max_extracted, fuel->~GetFuelAmount(true));
if (fuel_extracted > 0)
{
if (!fuel->~OnFuelRemoved(fuel_extracted)) fuel->RemoveObject();
}
}
fuel_amount += fuel_extracted;
if (fuel_amount >= fuel_needed)
break;
}
}

View File

@ -167,7 +167,7 @@ func RefillFuel()
{
// Extract the fuel amount from stored liquids
var fuel_stored = fuel->RemoveLiquid(nil, max_extracted);
fuel_extracted = GetFuelValue(fuel_stored[0], fuel_stored[1]);
fuel_extracted = Library_Liquid->GetFuelValue(fuel_stored[0], fuel_stored[1]);
}
else
{
@ -205,7 +205,7 @@ func Smoking()
func PutLiquid(string liquid_name, int amount, object source)
{
// Convert to fuel on insertion
var fuel_value = GetFuelValue(liquid_name, amount);
var fuel_value = Library_Liquid->GetFuelValue(liquid_name, amount);
if (_inherited("Fuel", fuel_value, source) != 0)
{
return amount; // return the requested amount, so that the correct value is deducted from the source
@ -216,13 +216,6 @@ func PutLiquid(string liquid_name, int amount, object source)
}
}
func GetFuelValue(string liquid, int amount)
{
if (liquid == "Oil") return amount;
return 0;
}
func IsLiquidContainerForMaterial(string liquid)
{
return WildcardMatch("Fuel", liquid);