Oil-burning steam engine

The steam engine can burn oil as fuel now. Added test to power system unit test. Still needs support for actually getting oil into the engine.
Fixed a bug in LiquidContainer that would return no liquid if the entire contents are removed. Added unit test for said bug.
Fixed overspilling of connected liquid containers. Pump no longer counts as a liquid container/tank, so that it still spills liquid if no drain is connected.
liquid_container
Mark 2016-02-07 19:14:57 +01:00
parent b6476330d4
commit 3e71b81e5f
5 changed files with 104 additions and 13 deletions

View File

@ -127,10 +127,11 @@ func RemoveLiquid(string liquid_name, int amount, object destination)
//Wrong material?
if (!WildcardMatch(GetLiquidType(), liquid_name))
amount = 0;
return [GetLiquidType(), 0];
amount = Min(amount, GetLiquidFillLevel());
ChangeLiquidFillLevel(-amount);
return [GetLiquidType(), amount];
return [liquid_name, amount];
}
/**

View File

@ -31,6 +31,8 @@ local max_clog_count = 5; // note that even when max_clog_count is reached, the
/** This object is a liquid pump, thus pipes can be connected. */
public func IsLiquidPump() { return true; }
public func IsLiquidContainer() { return false; }
public func IsLiquidTank() { return false; }
// The pump is rather complex for players. If anything happened, tell it to the player via the interaction menu.
local last_status_message;
@ -361,15 +363,17 @@ func InsertMaterialAtDrain(object drain_obj, string material_name, int amount)
// insert material into containers, if possible
if (drain_obj->~IsLiquidContainer())
{
amount -= drain_obj->PutLiquid(, amount, this);
amount -= drain_obj->PutLiquid(material_name, amount, this);
}
// convert to actual material, and insert remaining
var material_index = Material(material_name);
if (material_index != -1)
else
{
while (--amount >= 0)
drain_obj->InsertMaterial(material_index, drain_obj.ApertureOffsetX, drain_obj.ApertureOffsetY);
// convert to actual material, and insert remaining
var material_index = Material(material_name);
if (material_index != -1)
{
while (--amount >= 0)
drain_obj->InsertMaterial(material_index, drain_obj.ApertureOffsetX, drain_obj.ApertureOffsetY);
}
}
return amount <= 0;

View File

@ -138,10 +138,26 @@ func RefillFuel(bool cancel)
// Check if there is still enough fuel available.
if (fuel_amount <= 0)
{
var fuel_extracted;
// Search for new fuel among the contents.
var fuel = GetFuelContents();
if (!fuel)
{
// Extract the fuel amount from stored liquids
var fuel_stored = 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();
}
if (!fuel_extracted)
{
// Set action to idle and unregister this producer as available from the network.
if (cancel)
@ -152,10 +168,8 @@ func RefillFuel(bool cancel)
}
return false;
}
// Extract the fuel amount from the new piece of fuel.
var extracted = fuel->~GetFuelAmount(true);
fuel_amount += extracted * 18;
if (!fuel->~OnFuelRemoved(extracted)) fuel->RemoveObject();
fuel_amount += fuel_extracted * 18;
}
}
@ -183,6 +197,19 @@ func GetFuelValue(string liquid, int amount)
return 0;
}
func IsLiquidContainerForMaterial(string liquid)
{
return WildcardMatch("Oil", liquid);
}
func GetLiquidContainerMaxFillLevel()
{
return 300; // can store one barrel - this should be enough, so that the pump does not fill too much oil into the engine
}
/*-- Properties --*/
local ActMap = {

View File

@ -414,6 +414,15 @@ global func Test8_Execute()
test = (container->GetLiquidFillLevel() == 0);
Log("- Container is empty after removing amount 'nil': %v", test);
container->SetLiquidContainer("Lava", 100);
returned = container->RemoveLiquid(nil, nil, nil);
test = (returned[0] == "Lava");
Log("- Container returns the contained material when extracting material and amount 'nil': %v", test);
test = returned[1] == 100; passed &= test;
Log("- Container returns the contained amount when extracting material and amount 'nil': %v", test);
test = (container->GetLiquidFillLevel() == 0);
Log("- Container is empty after removing amount material and amount 'nil': %v", test);
container->RemoveObject();
return passed;

View File

@ -1131,6 +1131,56 @@ global func Test20_OnFinished()
return;
}
// Test for steam engine fueled by oil field and pump.
global func Test21_OnStart(int plr)
{
// Oil field
DrawMaterialQuad("Oil", 144, 168, 208 + 1, 168, 208 + 1, 304, 144, 304, true);
// Power source: one steam engine.
var engine = CreateObjectAbove(SteamEngine, 70, 160, plr);
engine.fuel_amount = 100; // give some fuel so that the pump can start working
// Power consumer: one pump.
var pump = CreateObjectAbove(Pump, 124, 160, plr);
var source = CreateObjectAbove(Pipe, 176, 292, plr);
source->ConnectPipeTo(pump, PIPE_STATE_Source);
var drain = CreateObjectAbove(Pipe, 100, 160, plr);
drain->ConnectPipeTo(pump, PIPE_STATE_Drain);
drain->ConnectPipeTo(engine);
// Power consumer: armory.
var armory = CreateObjectAbove(Armory, 280, 160, plr);
armory->CreateContents(Firestone, 10);
armory->CreateContents(Metal, 10);
armory->AddToQueue(IronBomb, 10);
// Power connection: flagpole.
CreateObjectAbove(Flagpole, 304, 140, plr);
// Log what the test is about.
Log("A steam engine fueled by an oil field via pump.");
return true;
}
global func Test21_Completed()
{
// One wood is being burned as fuel by the steam engine.
if (ObjectCount(Find_ID(IronBomb)) >= 10)
return true;
return false;
}
global func Test21_OnFinished()
{
// Restore water
RestoreWaterLevels();
// Remove steam engine, armory, pump.
RemoveAll(Find_Or(Find_ID(SteamEngine), Find_ID(Armory), Find_ID(Pipe), Find_ID(Pump)));
return;
}
/*-- Helper Functions --*/
global func SetWindFixed(int strength)