From c7afed1aeb836cd60e2b2f51f75da2a68282358a Mon Sep 17 00:00:00 2001 From: Maikel de Vries Date: Fri, 23 Dec 2016 18:08:50 +0100 Subject: [PATCH] allow pumping liquids from container (foundry and steam engine) --- .../Resources.ocd/Concrete.ocd/Script.c | 12 +++-- .../Pipe.ocd/PipeLine.ocd/Graphics.png | Bin 141 -> 0 bytes .../LiquidControl.ocd/Liquid.ocd/Script.c | 19 ++++--- .../LiquidContainer.ocd/Script.c | 19 +++++++ .../LiquidControl.ocd/LiquidTank.ocd/Script.c | 3 +- .../Structures.ocd/Foundry.ocd/Script.c | 49 +++++++++++++----- .../Foundry.ocd/StringTblDE.txt | 6 ++- .../Foundry.ocd/StringTblUS.txt | 6 ++- .../Structures.ocd/Pump.ocd/Script.c | 19 +++++-- .../Structures.ocd/SteamEngine.ocd/Script.c | 45 ++++++++++++---- .../SteamEngine.ocd/StringTblDE.txt | 6 ++- .../SteamEngine.ocd/StringTblUS.txt | 6 ++- 12 files changed, 142 insertions(+), 48 deletions(-) delete mode 100644 planet/Objects.ocd/Items.ocd/Tools.ocd/Pipe.ocd/PipeLine.ocd/Graphics.png diff --git a/planet/Objects.ocd/Items.ocd/Resources.ocd/Concrete.ocd/Script.c b/planet/Objects.ocd/Items.ocd/Resources.ocd/Concrete.ocd/Script.c index b3a57b52e..7ed439afe 100644 --- a/planet/Objects.ocd/Items.ocd/Resources.ocd/Concrete.ocd/Script.c +++ b/planet/Objects.ocd/Items.ocd/Resources.ocd/Concrete.ocd/Script.c @@ -10,9 +10,11 @@ public func GetLiquidType() { return "Concrete"; } +public func GetLiquidMaterial() { return "Granite"; } + public func Disperse(int angle, int strength) { - DisperseMaterial("Rock", GetLiquidAmount(), strength, angle); + DisperseMaterial(GetLiquidMaterial(), GetLiquidAmount(), strength, angle); _inherited(angle, strength, ...); } @@ -25,9 +27,9 @@ public func Construction(object creator) { var res = _inherited(creator, ...); // If the concrete is created by the foundry we can safely assume it has been produced - // and set the stack count to 100. - if (creator->~IsProducer()) - SetStackCount(100); + // and set the stack count to 100. The only exceptions are CreateContents script calls. + if (creator && creator->~IsProducer()) + SetStackCount(200); return res; } @@ -35,4 +37,4 @@ public func Construction(object creator) local Name = "$Name$"; local Description = "$Description$"; -local Components = {Rock = 1, Water = 100}; \ No newline at end of file +local Components = {Rock = 2, Water = 100}; \ No newline at end of file diff --git a/planet/Objects.ocd/Items.ocd/Tools.ocd/Pipe.ocd/PipeLine.ocd/Graphics.png b/planet/Objects.ocd/Items.ocd/Tools.ocd/Pipe.ocd/PipeLine.ocd/Graphics.png deleted file mode 100644 index 753695654c8a1413f2e2a51b20165116a5b0ec82..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 141 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1|;Q0k92}K#X;^)4C~IxyaaOClDyqr82*Fc zg1yTp14TFsJR*x37`TN&n2}-D90{Nxdx@v7EBj3@R(=__hQk{gfkM2VE{-7_*OL=~ Z0LW!!V2t~$Wd&q0c)I$ztaD0e0st2;AF%)c diff --git a/planet/Objects.ocd/Libraries.ocd/LiquidControl.ocd/Liquid.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/LiquidControl.ocd/Liquid.ocd/Script.c index 2f2228bda..814fc7bc6 100644 --- a/planet/Objects.ocd/Libraries.ocd/LiquidControl.ocd/Liquid.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/LiquidControl.ocd/Liquid.ocd/Script.c @@ -9,10 +9,9 @@ */ #include Library_Stackable - -static const FX_LIQUID_Dispersion = "IntLiquidDispersion"; -func IsLiquid() { return true;} + +func IsLiquid() { return true; } func InitialStackCount(){ return 1; } func MaxStackCount() { @@ -46,6 +45,13 @@ func GetLiquidType() return "undefined"; } +// The material maybe different from the type, for example concrete differs from its material granite. +public func GetLiquidMaterial() +{ + // Default to the liquid type. + return this->GetLiquidType(); +} + func GetLiquidAmount() { return GetStackCount(); @@ -61,20 +67,19 @@ func Departure(object container) func TriggerDispersion() { - var fx = GetEffect(FX_LIQUID_Dispersion, this); + var fx = GetEffect("IntLiquidDispersion", this); if (!fx) { - AddEffect(FX_LIQUID_Dispersion, this, 1, 1, this); + AddEffect("IntLiquidDispersion", this, 1, 1, this); } } func FxIntLiquidDispersionTimer(object target, proplist fx, int timer) { - if (!(target->Contained())) + if (!target->Contained()) { target->Disperse(); } - return FX_Execute_Kill; } diff --git a/planet/Objects.ocd/Libraries.ocd/LiquidControl.ocd/LiquidContainer.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/LiquidControl.ocd/LiquidContainer.ocd/Script.c index 843d4fb4b..6e9e99941 100644 --- a/planet/Objects.ocd/Libraries.ocd/LiquidControl.ocd/LiquidContainer.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/LiquidControl.ocd/LiquidContainer.ocd/Script.c @@ -54,6 +54,25 @@ func GetLiquidContents() // // Interfaces for interaction with other objects + +// Returns whether this container has the requested liquid and returns that liquid. +// If liquid_name == nil it returns the first liquid found. +public func HasLiquid(string liquid_name) +{ + for (var liquid in GetLiquidContents()) + { + if (liquid_name != nil) + { + if (liquid_name == liquid->GetLiquidType()) + return liquid; + } + else + return liquid; + } + return nil; +} + + /** Extracts liquid from the container. @param liquid_name: Material to extract; Wildcardsupport diff --git a/planet/Objects.ocd/Libraries.ocd/LiquidControl.ocd/LiquidTank.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/LiquidControl.ocd/LiquidTank.ocd/Script.c index 86d5695a2..608ee95a9 100644 --- a/planet/Objects.ocd/Libraries.ocd/LiquidControl.ocd/LiquidTank.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/LiquidControl.ocd/LiquidTank.ocd/Script.c @@ -47,7 +47,7 @@ public func Construction() _inherited(...); } -public func IsLiquidTank() { return true;} +public func IsLiquidTank() { return true; } /* ---------- Menu Entries ---------- */ @@ -202,6 +202,7 @@ public func DoCutPipe(object pipe) public func DoSwapSourceDrain(object source, object drain) { + // TODO: Check if swapping is even allowed. SetDrainPipe(source); SetSourcePipe(drain); source->SetDrainPipe(); diff --git a/planet/Objects.ocd/Structures.ocd/Foundry.ocd/Script.c b/planet/Objects.ocd/Structures.ocd/Foundry.ocd/Script.c index 747b28e72..45a918e15 100644 --- a/planet/Objects.ocd/Structures.ocd/Foundry.ocd/Script.c +++ b/planet/Objects.ocd/Structures.ocd/Foundry.ocd/Script.c @@ -73,7 +73,6 @@ func Collection() public func FxSmeltingTimer(object target, proplist effect, int time) { - //Message(Format("Smelting %d",timer)); // Fire in the furnace. CreateParticle("Fire", -10 * GetCalcDir() + RandomX(-1, 1), 20 + RandomX(-1, 1), PV_Random(-1, 1), PV_Random(-1, 1), PV_Random(3, 10), Particles_Fire(), 2); @@ -125,37 +124,61 @@ public func OnProductEjection(object product) /*-- Pipeline --*/ -func IsLiquidContainerForMaterial(string liquid) +public func IsLiquidContainerForMaterial(string liquid) { return WildcardMatch("Oil", liquid) || WildcardMatch("Water", liquid) || WildcardMatch("Concrete", liquid); } -func QueryConnectPipe(object pipe) +// The foundry may have one drain and one source. +public func QueryConnectPipe(object pipe) { - if (GetNeutralPipe()) + if (GetDrainPipe() && GetSourcePipe()) { pipe->Report("$MsgHasPipes$"); return true; } - - if (pipe->IsDrainPipe() || pipe->IsNeutralPipe()) + else if (GetSourcePipe() && pipe->IsSourcePipe()) { - return false; + pipe->Report("$MsgSourcePipeProhibited$"); + return true; } - else + else if (GetDrainPipe() && pipe->IsDrainPipe()) + { + pipe->Report("$MsgDrainPipeProhibited$"); + return true; + } + else if (pipe->IsAirPipe()) { pipe->Report("$MsgPipeProhibited$"); return true; } + return false; } -func OnPipeConnect(object pipe, string specific_pipe_state) +// Set to source or drain pipe. +public func OnPipeConnect(object pipe, string specific_pipe_state) { - SetNeutralPipe(pipe); + if (PIPE_STATE_Source == specific_pipe_state) + { + SetSourcePipe(pipe); + pipe->SetSourcePipe(); + } + else if (PIPE_STATE_Drain == specific_pipe_state) + { + SetDrainPipe(pipe); + pipe->SetDrainPipe(); + } + else + { + if (!GetDrainPipe()) + OnPipeConnect(pipe, PIPE_STATE_Drain); + else if (!GetSourcePipe()) + OnPipeConnect(pipe, PIPE_STATE_Source); + } pipe->Report("$MsgConnectedPipe$"); } -func GetLiquidContainerMaxFillLevel() +public func GetLiquidContainerMaxFillLevel() { return 300; } @@ -163,7 +186,6 @@ func GetLiquidContainerMaxFillLevel() /*-- Properties --*/ - local ActMap = { Default = { Prototype = Action, @@ -179,8 +201,9 @@ local ActMap = { }; func Definition(def) { - SetProperty("PictureTransformation", Trans_Mul(Trans_Translate(2000,0,7000),Trans_Rotate(-20,1,0,0),Trans_Rotate(30,0,1,0)), def); + def.PictureTransformation = Trans_Mul(Trans_Translate(2000,0,7000),Trans_Rotate(-20,1,0,0),Trans_Rotate(30,0,1,0)); } + local Name = "$Name$"; local Description = "$Description$"; local ContainBlast = true; diff --git a/planet/Objects.ocd/Structures.ocd/Foundry.ocd/StringTblDE.txt b/planet/Objects.ocd/Structures.ocd/Foundry.ocd/StringTblDE.txt index ed5a8cdc0..7a504994a 100644 --- a/planet/Objects.ocd/Structures.ocd/Foundry.ocd/StringTblDE.txt +++ b/planet/Objects.ocd/Structures.ocd/Foundry.ocd/StringTblDE.txt @@ -2,5 +2,7 @@ Name=Hochofen Description=Im Hochofen können Erze zu Barren geschmolzen werden. Dafür wird ein Brennstoff benötigt. MsgConnectedPipe=Rohr angeschlossen. -MsgPipeProhibited=Zuflussrohre können nicht an den Hochofen angeschlossen werden. -MsgHasPipes=Der Hochofen hat schon ein Rohr. \ No newline at end of file +MsgPipeProhibited=Dieses Rohr kann nicht an den Hochofen angeschlossen werden. +MsgHasPipes=Der Hochofen hat schon ein Zu- und Abflussrohr. +MsgSourcePipeProhibited=Zuflussrohre können nicht an den Hochofen angeschlossen werden. +MsgDrainPipeProhibited=Abflussrohre können nicht an den Hochofen angeschlossen werden. \ No newline at end of file diff --git a/planet/Objects.ocd/Structures.ocd/Foundry.ocd/StringTblUS.txt b/planet/Objects.ocd/Structures.ocd/Foundry.ocd/StringTblUS.txt index 832e92156..508271e3f 100644 --- a/planet/Objects.ocd/Structures.ocd/Foundry.ocd/StringTblUS.txt +++ b/planet/Objects.ocd/Structures.ocd/Foundry.ocd/StringTblUS.txt @@ -2,5 +2,7 @@ Name=Foundry Description=In the foundry, ore can be smelted into ingots. Fuel, such as coal, is necessary for this. MsgConnectedPipe=Connected pipe. -MsgPipeProhibited=Source pipes cannot be connected to the foundry. -MsgHasPipes=The foundry already has a pipe. \ No newline at end of file +MsgPipeProhibited=This pipe cannot be connected to the foundry. +MsgHasPipes=Foundry already has a source and a drain pipe. +MsgSourcePipeProhibited=Unable to connect source pipe to the foundry. +MsgDrainPipeProhibited=Unable to connect drain pipe to the foundry. \ No newline at end of file diff --git a/planet/Objects.ocd/Structures.ocd/Pump.ocd/Script.c b/planet/Objects.ocd/Structures.ocd/Pump.ocd/Script.c index a9831c767..601a521ed 100644 --- a/planet/Objects.ocd/Structures.ocd/Pump.ocd/Script.c +++ b/planet/Objects.ocd/Structures.ocd/Pump.ocd/Script.c @@ -162,8 +162,8 @@ private func SetInfoMessage(string msg) UpdateInteractionMenus(this.GetPumpControlMenuEntries); } -/*-- Pipe control --*/ +/*-- Pipe control --*/ func QueryConnectPipe(object pipe) { @@ -234,7 +234,6 @@ func OnPipeConnect(object pipe, string specific_pipe_state) } } - func OnPipeDisconnect(object pipe) { _inherited(pipe); @@ -409,6 +408,8 @@ func InsertMaterialAtDrain(object drain_obj, string material_name, int amount) { // convert to actual material, and insert remaining var material_index = Material(material_name); + if (material_index == -1 && material_name != nil) + material_index = Material(GetDefinition(material_name)->GetLiquidMaterial()); if (material_index != -1) { while (amount > 0 && drain_obj->InsertMaterial(material_index, drain_obj.ApertureOffsetX, drain_obj.ApertureOffsetY)) @@ -595,10 +596,17 @@ private func PumpHeight2Power(int pump_height) private func GetLiquidSourceMaterial() { // Get the source object and check whether there is liquid. - // TODO: If the source is a liquid container check which material will be supplied. var source_obj = GetSourceObject(); if (!source_obj) return; + // The source is a liquid container: check which material will be supplied. + if (source_obj->~IsLiquidContainer()) + { + var liquid = source_obj->HasLiquid(); + if (liquid) + return liquid->GetLiquidType(); + return; + } var is_liquid = source_obj->GBackLiquid(source_obj.ApertureOffsetX, source_obj.ApertureOffsetY); var liquid = MaterialName(source_obj->GetMaterial(source_obj.ApertureOffsetX, source_obj.ApertureOffsetY)); if (!is_liquid) @@ -616,7 +624,10 @@ private func GetLiquidDrainOk(string liquid) var drain_obj = GetDrainObject(); if (drain_obj->~HasAperture()) { - if (!drain_obj->CanInsertMaterial(Material(liquid), drain_obj.ApertureOffsetX, drain_obj.ApertureOffsetY)) + var material_index = Material(liquid); + if (material_index == -1 && liquid != nil) + material_index = Material(GetDefinition(liquid)->GetLiquidMaterial()); + if (!drain_obj->CanInsertMaterial(material_index, drain_obj.ApertureOffsetX, drain_obj.ApertureOffsetY)) { drain_obj->~CycleApertureOffset(this); // try different offsets, so we can resume pumping after clog because 1px of earth was dropped on the source pipe return false; diff --git a/planet/Objects.ocd/Structures.ocd/SteamEngine.ocd/Script.c b/planet/Objects.ocd/Structures.ocd/SteamEngine.ocd/Script.c index 3b7188308..ca03b6364 100644 --- a/planet/Objects.ocd/Structures.ocd/SteamEngine.ocd/Script.c +++ b/planet/Objects.ocd/Structures.ocd/SteamEngine.ocd/Script.c @@ -187,41 +187,66 @@ func Smoking() } -func IsLiquidContainerForMaterial(string liquid) +public func IsLiquidContainerForMaterial(string liquid) { return WildcardMatch("Oil", liquid); } -func GetLiquidContainerMaxFillLevel() +public func GetLiquidContainerMaxFillLevel() { return 300; } -func QueryConnectPipe(object pipe) +// The foundry may have one drain and one source. +public func QueryConnectPipe(object pipe) { - if (GetNeutralPipe()) + if (GetDrainPipe() && GetSourcePipe()) { pipe->Report("$MsgHasPipes$"); return true; } - - if (pipe->IsDrainPipe() || pipe->IsNeutralPipe()) + else if (GetSourcePipe() && pipe->IsSourcePipe()) { - return false; + pipe->Report("$MsgSourcePipeProhibited$"); + return true; } - else + else if (GetDrainPipe() && pipe->IsDrainPipe()) + { + pipe->Report("$MsgDrainPipeProhibited$"); + return true; + } + else if (pipe->IsAirPipe()) { pipe->Report("$MsgPipeProhibited$"); return true; } + return false; } -func OnPipeConnect(object pipe, string specific_pipe_state) +// Set to source or drain pipe. +public func OnPipeConnect(object pipe, string specific_pipe_state) { - SetNeutralPipe(pipe); + if (PIPE_STATE_Source == specific_pipe_state) + { + SetSourcePipe(pipe); + pipe->SetSourcePipe(); + } + else if (PIPE_STATE_Drain == specific_pipe_state) + { + SetDrainPipe(pipe); + pipe->SetDrainPipe(); + } + else + { + if (!GetDrainPipe()) + OnPipeConnect(pipe, PIPE_STATE_Drain); + else if (!GetSourcePipe()) + OnPipeConnect(pipe, PIPE_STATE_Source); + } pipe->Report("$MsgConnectedPipe$"); } + /*-- Properties --*/ local ActMap = { diff --git a/planet/Objects.ocd/Structures.ocd/SteamEngine.ocd/StringTblDE.txt b/planet/Objects.ocd/Structures.ocd/SteamEngine.ocd/StringTblDE.txt index 560269997..0e1fcb397 100644 --- a/planet/Objects.ocd/Structures.ocd/SteamEngine.ocd/StringTblDE.txt +++ b/planet/Objects.ocd/Structures.ocd/SteamEngine.ocd/StringTblDE.txt @@ -2,5 +2,7 @@ Name=Dampfmaschine Description=Die Dampfmaschine erzeugt Strom aus Brennstoffen wie Kohle, Holz oder Öl. MsgConnectedPipe=Rohr angeschlossen. -MsgPipeProhibited=Zuflussrohre können nicht an die Dampfmaschine angeschlossen werden. -MsgHasPipes=Die Dampfmaschine hat schon ein Rohr. \ No newline at end of file +MsgPipeProhibited=Dieses Rohr kann nicht an die Dampfmaschine angeschlossen werden. +MsgHasPipes=Die Dampfmaschine hat schon ein Zu- und Abflussrohr. +MsgSourcePipeProhibited=Zuflussrohre können nicht an die Dampfmaschine angeschlossen werden. +MsgDrainPipeProhibited=Abflussrohre können nicht an die Dampfmaschine angeschlossen werden. \ No newline at end of file diff --git a/planet/Objects.ocd/Structures.ocd/SteamEngine.ocd/StringTblUS.txt b/planet/Objects.ocd/Structures.ocd/SteamEngine.ocd/StringTblUS.txt index 7da5e4914..8c371b81a 100644 --- a/planet/Objects.ocd/Structures.ocd/SteamEngine.ocd/StringTblUS.txt +++ b/planet/Objects.ocd/Structures.ocd/SteamEngine.ocd/StringTblUS.txt @@ -2,5 +2,7 @@ Name=Steam engine Description=The steam engine generates electricity from fuel, such as coal, wood or oil. MsgConnectedPipe=Connected pipe. -MsgPipeProhibited=Source pipes cannot be connected to the steam engine. -MsgHasPipes=The steam engine already has a pipe. \ No newline at end of file +MsgPipeProhibited=This pipe cannot be connected to the steam engine. +MsgHasPipes=Steam engine already has a source and a drain pipe. +MsgSourcePipeProhibited=Unable to connect source pipe to the steam engine. +MsgDrainPipeProhibited=Unable to connect drain pipe to the steam engine. \ No newline at end of file