# HG changeset patch
# User Daniel@TK-DTK.kawo1.rwth-aachen.de
# Date 1318372366 -7200
# Node ID b417333789ecb71c6e57f56026c970c899287b49
# Parent  5a349a12e3308d3cf707a3742d97af43c1ce9748
Liquid Pipe System Update

diff -r 5a349a12e330 -r b417333789ec planet/Objects.ocd/Items.ocd/Tools.ocd/Barrel.ocd/BarrelTex.ocd/MB_oil.png
Binary file planet/Objects.ocd/Items.ocd/Tools.ocd/Barrel.ocd/BarrelTex.ocd/MB_oil.png has changed
diff -r 5a349a12e330 -r b417333789ec planet/Objects.ocd/Items.ocd/Tools.ocd/Barrel.ocd/MetalBarrel.ocd/Script.c
--- a/planet/Objects.ocd/Items.ocd/Tools.ocd/Barrel.ocd/MetalBarrel.ocd/Script.c	Tue Oct 11 18:59:58 2011 +0200
+++ b/planet/Objects.ocd/Items.ocd/Tools.ocd/Barrel.ocd/MetalBarrel.ocd/Script.c	Wed Oct 12 00:32:46 2011 +0200
@@ -1,6 +1,6 @@
 /*--
 	Metal Barrel
-	Author: Ringwaul
+	Author: Ringwaul, ST-DDT
 
 	A sturdier barrel that can transport lava or acid.
 --*/
@@ -16,14 +16,16 @@
 protected func Initialize()
 {
 	iVolume = 0;
-	debug=0;
+	debug = 0;
 }
 
 private func Hit()
 {
 	Sound("Clonk.ogg");
-	if(iVolume >= 1) {
-		if(GBackLiquid(0,7) && GetMaterial(0,7) != szLiquid) return 0;
+	if (iVolume >= 1)
+	{
+		if (GBackLiquid(0, 7) && GetMaterial(0, 7) != szLiquid)
+			return 0;
 		EmptyBarrel(GetR());
 		Sound("Splash1");
 	}
@@ -32,27 +34,34 @@
 private func FillWithLiquid()
 {
 	var mat = GetMaterial();
-
-	if(mat == Material("Water"))
+	
+	if (mat == Material("Water"))
 	{
 		FillBarrel(MaterialName(mat));
 		SetMeshMaterial("MB_Water");
 		return 1;
 	}
-
-	if(mat == Material("Acid"))
+	
+	if (mat == Material("Acid"))
 	{
 		FillBarrel(MaterialName(mat));
 		SetMeshMaterial("MB_Acid");
 		return 1;
 	}
-
-	if(mat == Material("Lava") || mat == Material("DuroLava"))
+	
+	if (mat == Material("Lava") || mat == Material("DuroLava"))
 	{
 		FillBarrel(MaterialName(mat));
 		SetMeshMaterial("MB_Lava");
 		return 1;
 	}
+	
+	if (mat == Material("Oil"))
+	{
+		FillBarrel(MaterialName(mat));
+		SetMeshMaterial("MB_Oil");
+		return 1;
+	}
 }
 
 private func OriginalTex()
@@ -60,6 +69,25 @@
 	SetMeshMaterial("MetalBarrel");
 }
 
+public func IsBarrelForMaterial(string sznMaterial)
+{
+	if ((iVolume > 0) && (WildcardMatch(szLiquid,sznMaterial)))
+		return true;
+	if (WildcardMatch("Water", sznMaterial))
+		return true;
+	if (WildcardMatch("Acid", sznMaterial))
+		return true;
+	if (WildcardMatch("Lava", sznMaterial))
+		return true;
+	if (WildcardMatch("DuroLava", sznMaterial))
+		return true;
+	if (WildcardMatch("Oil", sznMaterial))
+		return true;
+	//if (GetMaterialVal("Density","Material",Material(szMaterial)))
+	//	return true;
+	return false;
+}
+
 local Collectible = 1;
 local Name = "$Name$";
 local Description = "$Description$";
diff -r 5a349a12e330 -r b417333789ec planet/Objects.ocd/Items.ocd/Tools.ocd/Barrel.ocd/Script.c
--- a/planet/Objects.ocd/Items.ocd/Tools.ocd/Barrel.ocd/Script.c	Tue Oct 11 18:59:58 2011 +0200
+++ b/planet/Objects.ocd/Items.ocd/Tools.ocd/Barrel.ocd/Script.c	Wed Oct 12 00:32:46 2011 +0200
@@ -1,6 +1,6 @@
 /*--
 	Wooden Barrel
-	Author: Ringwaul
+	Author: Ringwaul, ST-DDT
 
 	The barrel is used to transport liquids
 --*/
@@ -10,21 +10,32 @@
 
 local debug;
 
-public func GetCarryMode(clonk) { return CARRY_BothHands; }
-public func GetCarryTransform(clonk) { return Trans_Translate(-1000,-800,0); }
-public func GetCarryPhase() { return 900; }
+public func GetCarryMode(clonk)
+{
+	return CARRY_BothHands;
+}
+public func GetCarryTransform(clonk)
+{
+	return Trans_Translate(-1000, -800, 0);
+}
+public func GetCarryPhase()
+{
+	return 900;
+}
 
 protected func Initialize()
 {
 	iVolume = 0;
-	debug=0;
+	debug = 0;
 }
 
 private func Hit()
 {
 	Sound("WoodHit");
-	if(iVolume >= 1) {
-		if(GBackLiquid(0,3) && GetMaterial(0,3) != szLiquid) return 0;
+	if (iVolume >= 1)
+	{
+		if (GBackLiquid(0, 3) && GetMaterial(0, 3) != szLiquid)
+			return 0;
 		EmptyBarrel(GetR());
 		Sound("Splash1");
 	}
@@ -34,31 +45,34 @@
 {
 	//Fills Barrel with specified liquid from if submerged
 	var iSource = 3;
-
-	if(GBackLiquid(0,iSource))
+	
+	if (GBackLiquid(0, iSource))
 	{
 		FillWithLiquid();
 	}
-
-	if(iVolume == 0) {
+	
+	if (iVolume == 0)
+	{
 		SetGraphics();
-		szLiquid=nil;
+		szLiquid = nil;
 	}
-
+	
 	//Value. Base value is 10.
-	if(iVolume == 0)	SetProperty("Value", 10);
+	if (iVolume == 0)
+		SetProperty("Value", 10);
 	//if(szLiquid == Oil)	SetProperty("Value", 10 + (iVolume / 15)); //No oil in current build
-
+	
 	//Debug/Testing Purposes
-	if(debug == 1) Message("Volume:|%d|Liquid:|%s", iVolume, szLiquid);
+	if (debug == 1)
+		Message("Volume:|%d|Liquid:|%s", iVolume, szLiquid);
 }
 
 //over-ridden with metal barrel
 private func FillWithLiquid()
 {
 	var mat = GetMaterial();
-
-	if(mat == Material("Water"))
+	
+	if (mat == Material("Water"))
 	{
 		FillBarrel(MaterialName(mat));
 		SetMeshMaterial("Barrel_Water");
@@ -67,13 +81,14 @@
 
 private func FillBarrel(string szMat)
 {
-	var iCapacity = 300;
+	var iCapacity = BarrelMaxFillLevel();
 	var intake = 3;
 	
-	if(iVolume >= 1 && szMat != szLiquid) return 0;
-	while(iVolume != iCapacity && GetMaterial(0,intake) == Material(szMat))
+	if (iVolume >= 1 && szMat != szLiquid)
+		return 0;
+	while (iVolume != iCapacity && GetMaterial(0, intake) == Material(szMat))
 	{
-		ExtractLiquid(0,intake);
+		ExtractLiquid(0, intake);
 		iVolume = ++iVolume;
 	}
 	szLiquid = szMat;
@@ -81,9 +96,11 @@
 
 private func EmptyBarrel(int iAngle, int iStrength)
 {
-	if(!iAngle) iAngle = 0;
-	if(!iStrength) iStrength = 30;
-	CastPXS(szLiquid, iVolume,iStrength,0,0,iAngle,30);
+	if (!iAngle)
+		iAngle = 0;
+	if (!iStrength)
+		iStrength = 30;
+	CastPXS(szLiquid, iVolume, iStrength, 0, 0, iAngle, 30);
 	iVolume = 0;
 	OriginalTex();
 }
@@ -96,21 +113,107 @@
 
 public func ControlUse(object clonk, int iX, int iY)
 {
-	var AimAngle=Angle(0,0, iX, iY);
-	if(iVolume >= 1)
+	var AimAngle = Angle(0, 0, iX, iY);
+	if (iVolume >= 1)
 	{
-		EmptyBarrel(AimAngle,50);
-		if( iX > 1) Contained()->SetDir(1);
-		if( iX < -1 ) Contained()->SetDir(0);
+		EmptyBarrel(AimAngle, 50);
+		if (iX > 1)
+			Contained()->SetDir(1);
+		if (iX < -1)
+			Contained()->SetDir(0);
 	}
 	return 1;
 }
 
-public func IsToolProduct() { return 1; }
+public func IsToolProduct()
+{
+	return 1;
+}
 
-func Definition(def) {
-	SetProperty("PictureTransformation",Trans_Mul(Trans_Translate(0,1000,0), Trans_Rotate(-40,1,0,0), Trans_Rotate(20,0,0,1)), def);
+public func Definition(proplist def)
+{
+	SetProperty("PictureTransformation", Trans_Mul(Trans_Translate(0, 1000, 0), Trans_Rotate(-40, 1, 0, 0), Trans_Rotate(20, 0, 0, 1)), def);
 }
+
+
+
+public func BarrelMaxFillLevel()
+{
+	return 300;
+}
+
+public func GetFillLevel()
+{
+	return iVolume;
+}
+
+public func IsBarrel()
+{
+	return true;
+}
+
+public func BarrelIsEmpty()
+{
+	return iVolume == 0;
+}
+
+public func BarrelIsFull()
+{
+	return iVolume == BarrelMaxFillLevel();
+}
+
+//returns the contained liquid
+public func GetBarrelMaterial()
+{
+	if (iVolume == 0)
+		return "";
+	return szLiquid;
+}
+
+public func IsBarrelForMaterial(string sznMaterial)
+{
+	return WildcardMatch("Water",sznMaterial);
+}
+
+/**
+Extract liquid from barrel
+@param sznMaterial: Material to extract; Wildcardsupport
+@param inMaxAmount: Max Amount of Material being extracted 
+@param pnTarget: Object which extracts the liquid
+@return [irMaterial,irAmount]
+	-irMaterial: Material being extracted
+	-irAmount: Amount being extracted
+*/
+public func GetLiquid(string sznMaterial, int inMaxAmount, object pnTarget)
+{
+	//Wrong material?
+	if (!WildcardMatch(szLiquid, sznMaterial))
+		inMaxAmount = 0;
+	inMaxAmount = Min(inMaxAmount, iVolume);
+	iVolume -= inMaxAmount;
+	return [szLiquid, inMaxAmount];
+}
+
+/** 
+Insert liquid to barrel
+	@param sznMaterial: Material to insert
+	@param inMaxAmount: Max Amount of Material being inserted 
+	@param pnSource: Object which inserts the liquid
+	@return inAmount: The inserted amount
+*/
+public func PutLiquid(string sznMaterial, int inMaxAmount, object pnSource)
+{
+	//Wrong material?
+	if (sznMaterial != szLiquid)
+		if (iVolume>0)
+			return 0;
+		else if (IsBarrelForMaterial(sznMaterial))
+			szLiquid=sznMaterial;
+	inMaxAmount = BoundBy(BarrelMaxFillLevel() - iVolume, 0, inMaxAmount);
+	iVolume += inMaxAmount;
+	return inMaxAmount;
+}
+
 local Collectible = 1;
 local Name = "$Name$";
 local Description = "$Description$";
diff -r 5a349a12e330 -r b417333789ec planet/Objects.ocd/Items.ocd/Tools.ocd/Pipe.ocd/PipeLine.ocd/Script.c
--- a/planet/Objects.ocd/Items.ocd/Tools.ocd/Pipe.ocd/PipeLine.ocd/Script.c	Tue Oct 11 18:59:58 2011 +0200
+++ b/planet/Objects.ocd/Items.ocd/Tools.ocd/Pipe.ocd/PipeLine.ocd/Script.c	Wed Oct 12 00:32:46 2011 +0200
@@ -1,11 +1,13 @@
 /*-- Pipe line --*/
 
+//Author: ST-DDT
+
 protected func Initialize()
 {
 	SetAction("Connect");
 	SetVertexXY(0, GetX(), GetY());
 	SetVertexXY(1, GetX(), GetY());
-	SetProperty("LineColors", [RGB(80,80,120), RGB(80,80,120)]);
+	SetProperty("LineColors", [RGB(80, 80, 120), RGB(80, 80, 120)]);
 	return;
 }
 
@@ -34,7 +36,7 @@
 protected func LineBreak(bool no_msg)
 {
 	Sound("LineBreak");
-	if (!no_msg) 
+	if (!no_msg)
 		BreakMessage();
 	return;
 }
@@ -42,21 +44,68 @@
 private func BreakMessage()
 {
 	var line_end = GetActionTarget(0);
-	if (line_end->GetID() != Pipe) 
+	if (line_end->GetID() != Pipe)
 		line_end = GetActionTarget(1);
-
+	
 	line_end->Message("$TxtPipeBroke$");
 	return;
 }
 
 local ActMap = {
-	Connect = {
-		Prototype = Action,
-		Name = "Connect",
-		Procedure = DFA_CONNECT,
-		NextAction = "Connect",
-	},
+	Connect: {
+		Prototype: Action,
+		Name: "Connect",
+		Procedure: DFA_CONNECT,
+		NextAction: "Connect"
+	}
 };
 
+/**
+Extract liquid from barrel
+@param sznMaterial: Material to extract; Wildcardsupport
+@param inMaxAmount: Max Amount of Material being extracted 
+@param pnTarget: Object which extracts the liquid
+@return [irMaterial,irAmount]
+	-irMaterial: Material being extracted
+	-irAmount: Amount being extracted
+*/
+public func GetLiquid(string sznMaterial, int inMaxAmount, object pnTarget, bool bWildcard)
+{
+	var pConnected = GetConnectedObject(pnTarget);
+	if (!pConnected)
+		return ["", 0];
+	var aMat = pConnected->~LiquidOutput(sznMaterial, inMaxAmount, pnTarget, this, bWildcard);
+	//Bad script? Not needed.
+	if (GetType(aMat) != C4V_Array)
+		return [-1, 0];
+	//Verify data
+	if ((aMat[0] == "") || (GetLength(aMat) == 1))
+		aMat[1] = 0;
+	//Nothing is nothing
+	if (aMat[1] <= 0)
+	{
+		aMat[0] = "";
+		aMat[1] = 0;
+	} //Bad script end
+	return aMat;
+}
+ 
+/** 
+Insert liquid to barrel
+	@param sznMaterial: Material to insert
+	@param inMaxAmount: Max Amount of Material being inserted 
+	@param pnSource: Object which inserts the liquid
+	@return inAmount: The inserted amount
+*/
+public func PutLiquid(string sznMaterial, int inMaxAmount, object pnSource)
+{
+	var pConnected = GetConnectedObject(pnSource);
+	if (!pConnected)
+		return 0;
+	if (sznMaterial == "")
+		return 0;
+	return BoundBy(pConnected->~LiquidInput(sznMaterial, inMaxAmount, pnSource, this), 0, inMaxAmount);
+}
+
 local Name = "$Name$";
 		
diff -r 5a349a12e330 -r b417333789ec planet/Objects.ocd/Items.ocd/Tools.ocd/Pipe.ocd/Script.c
--- a/planet/Objects.ocd/Items.ocd/Tools.ocd/Pipe.ocd/Script.c	Tue Oct 11 18:59:58 2011 +0200
+++ b/planet/Objects.ocd/Items.ocd/Tools.ocd/Pipe.ocd/Script.c	Wed Oct 12 00:32:46 2011 +0200
@@ -1,11 +1,16 @@
 /*-- Pipe --*/
 
+//Author: ST-DDT
+
 protected func Hit()
 {
 	Sound("RockHit*");
 }
 
-public func IsToolProduct() { return 1; }
+public func IsToolProduct()
+{
+	return 1;
+}
 
 /*-- Line connection --*/
 
@@ -14,12 +19,12 @@
 {
 	// Is this already connected to a liquid pump?
 	if (FindObject(Find_PipeLine()))
-		return false;	
+		return false;
 	// Only use if clonk is walking.
 	if (!clonk->IsWalking())
 		return true;
 	// Clonk should stand still.
-	clonk->SetComDir(COMD_Stop);	
+	clonk->SetComDir(COMD_Stop);
 	// Is there an object which accepts power lines?
 	var liquid_pump = FindObject(Find_AtPoint(), Find_Func("IsLiquidPump"));
 	// No liquid pump, display message.
@@ -63,6 +68,58 @@
 	return [C4FO_Func, "IsConnectedTo", obj];
 }
 
+/**
+Extract liquid from this
+@param sznMaterial: Material to extract
+@param inMaxAmount: Max Amount of Material being extracted 
+@param pnPump: Object which extracts the liquid
+@param pnPipe: Pipe which extracts the liquid (connected to pnPump)
+@param bnWildcard: Usefull to extract random liquids; use '*' for sznMaterial for all Materials
+@return [irMaterial,irAmount]
+	-irMaterial: Material being extracted
+	-irAmount: Amount being extracted
+*/
+public func LiquidOutput(string sznMaterial, int inMaxAmount, object pnPump, object pnPipe, bool bnWildcard)
+{
+	var itMaterial;
+	//Search liquid to pump
+	if (bnWildcard)
+	{
+		itMaterial = GetMaterial();
+		//nothing?
+		if (itMaterial == -1)
+			return ["", 0];
+		//no liquid?
+		if (GetMaterialVal("Density", "Material", itMaterial) != 25)
+			return ["", 0];
+		//wrong liquid?
+		if (!WildcardMatch(MaterialName(itMaterial),sznMaterial))
+			return ["", 0];
+		sznMaterial = MaterialName(itMaterial);
+	}
+	else
+		itMaterial = Material(sznMaterial);
+	if (GetMaterial() != itMaterial)
+		return ["", 0];
+	var itFound = ExtractMaterialAmount(0, 0, itMaterial, 5);
+	return [sznMaterial, itFound];
+}
+
+/** 
+Insert liquid to this
+	@param sznMaterial: Material to insert
+	@param inMaxAmount: Max Amount of Material being inserted 
+	@param pnPump: Object which inserts the liquid
+	@param pnPipe: Pipe which inserts the liquid (connected to pnPump)
+	@return irAmount: The inserted amount
+*/
+public func LiquidInput(string sznMaterial, int inMaxAmount, object pnPump, object pnPipe)
+{
+	var i=Max(0,inMaxAmount),itMaterial=Material(sznMaterial);
+	while (i--) InsertMaterial(itMaterial);
+	return inMaxAmount;
+}
+
 local Name = "$Name$";
 local Description = "$Description$";
 local Collectible = 1;
diff -r 5a349a12e330 -r b417333789ec planet/Objects.ocd/Libraries.ocd/BarrelFiller.ocd/DefCore.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/planet/Objects.ocd/Libraries.ocd/BarrelFiller.ocd/DefCore.txt	Wed Oct 12 00:32:46 2011 +0200
@@ -0,0 +1,4 @@
+[DefCore]
+id=Libary_BarrelFiller
+Version=5,2,0,1
+Category=C4D_StaticBack
diff -r 5a349a12e330 -r b417333789ec planet/Objects.ocd/Libraries.ocd/BarrelFiller.ocd/Graphics.png
Binary file planet/Objects.ocd/Libraries.ocd/BarrelFiller.ocd/Graphics.png has changed
diff -r 5a349a12e330 -r b417333789ec planet/Objects.ocd/Libraries.ocd/BarrelFiller.ocd/Script.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/planet/Objects.ocd/Libraries.ocd/BarrelFiller.ocd/Script.c	Wed Oct 12 00:32:46 2011 +0200
@@ -0,0 +1,73 @@
+/* --- BarrelFiller --- */
+
+/*
+Author: ST-DDT
+Import this to allow the structures to 
+-fill liquids which has been pumped into the building into barrels 
+-extract liquids from barrels and pump it somewhere else
+*/
+ 
+/**
+Extract liquid from this
+@param sznMaterial: Material to extract
+@param inMaxAmount: Max Amount of Material being extracted 
+@param pnPump: Object which extracts the liquid
+@param pnPipe: Pipe which extracts the liquid (connected to pnPump)
+@param bnWildcard: Usefull to extract random liquids; use '*' for sznMaterial for all Materials
+@return [irMaterial,irAmount]
+	-irMaterial: Material being extracted
+	-irAmount: Amount being extracted
+*/
+public func LiquidOutput(string sznMaterial, int inMaxAmount, object pnPump, object pnPipe, bool bnWildcard)
+{
+	//Search liquid to pump
+	if (bnWildcard)
+	{
+		var ptBarrel = FindObject(Find_Container(this), Find_Func("IsBarrel"), Find_Func("IsBarrelForMaterial", sznMaterial), Find_Not(Find_Func("BarrelIsEmpty")));
+		var sztMaterial="";
+		if (ptBarrel)
+			sztMaterial = ptBarrel->GetBarrelMaterial();
+		//Nothing to pump
+		if (sztMaterial == "")
+			return ["", 0];
+		sznMaterial = sztMaterial;
+	}
+	var itFound = 0;
+	for (var ptBarrel in FindObjects(Find_Container(this), Find_Func("IsBarrel"), Find_Func("IsBarrelForMaterial", sznMaterial), Find_Not(Find_Func("BarrelIsEmpty")))) 
+	{
+		var atFound = ptBarrel->GetLiquid(sznMaterial, inMaxAmount - itFound, this);
+		//Crazy stuff happend?
+		itFound += BoundBy(atFound[1], 0, inMaxAmount - itFound);
+		if (itFound == inMaxAmount)
+			break;
+	}
+	return [sznMaterial, itFound];
+}
+
+/** 
+Insert liquid to this
+	@param sznMaterial: Material to insert
+	@param inMaxAmount: Max Amount of Material being inserted 
+	@param pnPump: Object which inserts the liquid
+	@param pnPipe: Pipe which inserts the liquid (connected to pnPump)
+	@return irAmount: The inserted amount
+*/
+public func LiquidInput(string sznMaterial, int inMaxAmount, object pnPump, object pnPipe)
+{
+	var itAmount = inMaxAmount;
+	//Fill liquids into already existing barrels
+	for (var ptBarrel in FindObjects(Find_Container(this), Find_Func("IsBarrel"), Find_Func("IsContainerForMaterial", sznMaterial), Find_Not(Find_Func("BarrelIsEmpty")), Find_Not(Find_Func("BarrelIsFull")))) 
+	{
+		itAmount -= BoundBy(ptBarrel->PutLiquid(sznMaterial, itAmount, this), 0, itAmount);
+		if (!itAmount)
+			return inMaxAmount;
+	}
+	//Fill liquids into empty barrels
+	for (var ptBarrel in FindObjects(Find_Container(this), Find_Func("IsBarrel"), Find_Func("IsContainerForMaterial", sznMaterial), Find_Func("BarrelIsEmpty"))) 
+	{
+		itAmount -= BoundBy(ptBarrel->PutLiquid(sznMaterial, itAmount, this), 0, itAmount);
+		if (!itAmount)
+			return inMaxAmount;
+	}
+	return inMaxAmount - itAmount;
+}
diff -r 5a349a12e330 -r b417333789ec planet/Objects.ocd/Libraries.ocd/Tank.ocd/DefCore.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/planet/Objects.ocd/Libraries.ocd/Tank.ocd/DefCore.txt	Wed Oct 12 00:32:46 2011 +0200
@@ -0,0 +1,4 @@
+[DefCore]
+id=Libary_Tank
+Version=5,2,0,1
+Category=C4D_StaticBack
diff -r 5a349a12e330 -r b417333789ec planet/Objects.ocd/Libraries.ocd/Tank.ocd/Graphics.png
Binary file planet/Objects.ocd/Libraries.ocd/Tank.ocd/Graphics.png has changed
diff -r 5a349a12e330 -r b417333789ec planet/Objects.ocd/Libraries.ocd/Tank.ocd/Script.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/planet/Objects.ocd/Libraries.ocd/Tank.ocd/Script.c	Wed Oct 12 00:32:46 2011 +0200
@@ -0,0 +1,61 @@
+/* --- Tank --- */
+
+/*
+Author: ST-DDT
+Import this to allow the structures to 
+-fill liquids which has been pumped into the building into the internal contained 
+-extract liquids from internal contained and pump it somewhere else
+*/
+
+local szLiquid;
+local iLiquidAmount;
+
+public func MaxFillLevel()
+{
+	return 5000;
+}
+
+/**
+Extract liquid from this
+@param sznMaterial: Material to extract
+@param inMaxAmount: Max Amount of Material being extracted 
+@param pnPump: Object which extracts the liquid
+@param pnPipe: Pipe which extracts the liquid (connected to pnPump)
+@param bnWildcard: Usefull to extract random liquids; use '*' for sznMaterial for all Materials
+@return [irMaterial,irAmount]
+	-irMaterial: Material being extracted
+	-irAmount: Amount being extracted
+*/
+public func LiquidOutput(string sznMaterial, int inMaxAmount, object pnPump, object pnPipe, bool bnWildcard)
+{
+	//Search liquid to pump
+	if (bnWildcard)
+	{
+		if (WildcardMatch(szLiquid, sznMaterial))
+			sznMaterial = szLiquid;
+	}
+	//Wrong material?
+	if (szLiquid != sznMaterial)
+		return ["", 0];
+	inMaxAmount = Min(inMaxAmount, iLiquidAmount);
+	iLiquidAmount -= inMaxAmount;
+	return [szLiquid, inMaxAmount];
+}
+
+/** 
+Insert liquid to this
+	@param sznMaterial: Material to insert
+	@param inMaxAmount: Max Amount of Material being inserted 
+	@param pnPump: Object which inserts the liquid
+	@param pnPipe: Pipe which inserts the liquid (connected to pnPump)
+	@return irAmount: The inserted amount
+*/
+public func LiquidInput(string sznMaterial, int inMaxAmount, object pnPump, object pnPipe)
+{
+	//wrong material?
+	if (szLiquid != sznMaterial)
+		return 0;
+	inMaxAmount = Min(MaxFillLevel() - iLiquidAmount, inMaxAmount);
+	iLiquidAmount += inMaxAmount;
+	return inMaxAmount;
+}
diff -r 5a349a12e330 -r b417333789ec planet/Objects.ocd/Structures.ocd/Pump.ocd/Script.c
--- a/planet/Objects.ocd/Structures.ocd/Pump.ocd/Script.c	Tue Oct 11 18:59:58 2011 +0200
+++ b/planet/Objects.ocd/Structures.ocd/Pump.ocd/Script.c	Wed Oct 12 00:32:46 2011 +0200
@@ -1,6 +1,6 @@
 /*--
 	Pump
-	Author: Maikel
+	Author: Maikel, ST-DDT
 	
 	Pumps liquids using drain and source pipes.
 --*/
@@ -9,7 +9,10 @@
 
 
 // This object is a liquid pump, thus pipes can be connected.
-public func IsLiquidPump() { return true; }
+public func IsLiquidPump()
+{
+	return true;
+}
 
 protected func Initialize()
 {
@@ -23,10 +26,22 @@
 local drain_pipe;
 
 // Set-Getters for source and drain pipe.
-public func SetSource(object pipe) { source_pipe = pipe; }
-public func GetSource() { return source_pipe; }
-public func SetDrain(object pipe) { drain_pipe = pipe; }
-public func GetDrain() { return drain_pipe; }
+public func SetSource(object pipe)
+{
+	source_pipe = pipe;
+}
+public func GetSource()
+{
+	return source_pipe;
+}
+public func SetDrain(object pipe)
+{
+	drain_pipe = pipe;
+}
+public func GetDrain()
+{
+	return drain_pipe;
+}
 
 protected func OnPumpStart()
 {
@@ -42,6 +57,8 @@
 	return;
 }
 
+local aMaterials=["", 0]; //contained liquids
+
 protected func Pumping()
 {
 	// Only proceed if there is enough power available.
@@ -50,7 +67,28 @@
 	// Pump liquids.
 	if (!source_pipe)
 		return SetAction("Wait");
-	var source = source_pipe->GetConnectedObject(this);
+	//IsEmpty?
+	if ((aMaterials[1] == 0) || (aMaterials[0] == ""))
+	{
+		//Get new Materials
+		aMaterials = source_pipe->GetLiquid("*", 5, this, true);
+		//No Material to pump?
+		if ((aMaterials[0] == "") || (aMaterials[1] == 0))
+			return;
+	}
+	if (drain_pipe)
+		aMaterials[1] -= BoundBy(drain_pipe->PutLiquid(aMaterials[0], aMaterials[1], this), 0, aMaterials[1]);
+	else
+	{
+		var i = Max(0, aMaterials[1]), itMaterial = Material(aMaterials[0]);
+		while (i--)
+			InsertMaterial(itMaterial);
+		aMaterials = ["", 0];
+	}
+	return;
+	//maybe add the possebility to empty pump (invaild mats?)
+	
+	/*var source = source_pipe->GetConnectedObject(this);
 	// Extract liquid at source location.
 	// TODO: Maybe bubble a little.
 	var mat = source->ExtractLiquid();
@@ -65,7 +103,7 @@
 		return InsertMaterial(mat);
 	// TODO: Account for pumping into buildings.
 	drain->InsertMaterial(mat);		
-	return;
+	return;*/
 }
 
 // Returns whether the pump can pump some liquid.
@@ -87,31 +125,31 @@
 
 local Name = "$Name$";
 local ActMap = {
-	Pump = {
-		Prototype = Action,
-		Name = "Pump",
-		Procedure = DFA_NONE,
-		Length = 20,
-		Delay = 3,
-		X = 0,
-		Y = 0,
-		Wdt = 28,
-		Hgt = 32,
-		NextAction = "Pump",
-		StartCall = "OnPumpStart",
-		PhaseCall = "Pumping",
+	Pump: {
+		Prototype: Action,
+		Name: "Pump",
+		Procedure: DFA_NONE,
+		Length: 20,
+		Delay: 3,
+		X: 0,
+		Y: 0,
+		Wdt: 28,
+		Hgt: 32,
+		NextAction: "Pump",
+		StartCall: "OnPumpStart",
+		PhaseCall: "Pumping"
 	},
-	Wait = {
-		Prototype = Action,
-		Name = "Wait",
-		Procedure = DFA_NONE,
-		Length = 1,
-		Delay = 50,
-		X = 0,
-		Y = 0,
-		Wdt = 28,
-		Hgt = 32,
-		NextAction = "Wait",
-		StartCall = "OnWaitStart",
-	},
+	Wait: {
+		Prototype: Action,
+		Name: "Wait",
+		Procedure: DFA_NONE,
+		Length: 1,
+		Delay: 50,
+		X: 0,
+		Y: 0,
+		Wdt: 28,
+		Hgt: 32,
+		NextAction: "Wait",
+		StartCall: "OnWaitStart"
+	}
 };
