diff --git a/planet/Objects.ocd/Libraries.ocd/LiquidContainer.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/LiquidContainer.ocd/Script.c index 7005cbc95..76c4d478d 100644 --- a/planet/Objects.ocd/Libraries.ocd/LiquidContainer.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/LiquidContainer.ocd/Script.c @@ -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]; } /** diff --git a/planet/Objects.ocd/Structures.ocd/Pump.ocd/Script.c b/planet/Objects.ocd/Structures.ocd/Pump.ocd/Script.c index a11d8ec55..c5d781ba7 100644 --- a/planet/Objects.ocd/Structures.ocd/Pump.ocd/Script.c +++ b/planet/Objects.ocd/Structures.ocd/Pump.ocd/Script.c @@ -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; diff --git a/planet/Objects.ocd/Structures.ocd/SteamEngine.ocd/Script.c b/planet/Objects.ocd/Structures.ocd/SteamEngine.ocd/Script.c index def7067f2..88522aecb 100644 --- a/planet/Objects.ocd/Structures.ocd/SteamEngine.ocd/Script.c +++ b/planet/Objects.ocd/Structures.ocd/SteamEngine.ocd/Script.c @@ -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 = { diff --git a/planet/Tests.ocf/LiquidContainer.ocs/Script.c b/planet/Tests.ocf/LiquidContainer.ocs/Script.c index cf84f8b5b..693921c9a 100644 --- a/planet/Tests.ocf/LiquidContainer.ocs/Script.c +++ b/planet/Tests.ocf/LiquidContainer.ocs/Script.c @@ -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; diff --git a/planet/Tests.ocf/PowerSystem.ocs/Script.c b/planet/Tests.ocf/PowerSystem.ocs/Script.c index 478266eca..7256b4ace 100644 --- a/planet/Tests.ocf/PowerSystem.ocs/Script.c +++ b/planet/Tests.ocf/PowerSystem.ocs/Script.c @@ -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)