2010-12-31 12:20:54 +00:00
|
|
|
/*--
|
|
|
|
Pump
|
2011-10-11 22:32:46 +00:00
|
|
|
Author: Maikel, ST-DDT
|
2010-12-31 12:20:54 +00:00
|
|
|
|
|
|
|
Pumps liquids using drain and source pipes.
|
|
|
|
--*/
|
|
|
|
|
2012-02-18 21:50:18 +00:00
|
|
|
#include Library_Ownable
|
2010-12-31 12:20:54 +00:00
|
|
|
#include Library_PowerConsumer
|
|
|
|
|
|
|
|
|
|
|
|
// This object is a liquid pump, thus pipes can be connected.
|
|
|
|
public func IsLiquidPump() { return true; }
|
|
|
|
|
2012-04-16 15:31:38 +00:00
|
|
|
public func Construction(object creator)
|
2010-12-31 12:20:54 +00:00
|
|
|
{
|
|
|
|
SetAction("Wait");
|
2012-04-16 15:31:38 +00:00
|
|
|
if (!creator) return;
|
|
|
|
var dir = creator->~GetConstructionDirection();
|
|
|
|
if (dir)
|
|
|
|
SetDir(dir);
|
|
|
|
return _inherited(creator, ...);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected func Initialize()
|
|
|
|
{
|
2012-02-18 21:50:18 +00:00
|
|
|
MakePowerConsumer(100);
|
2012-03-10 19:45:18 +00:00
|
|
|
turned_on = true;
|
2010-12-31 12:20:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-10 19:45:18 +00:00
|
|
|
/*-- Interaction --*/
|
|
|
|
|
|
|
|
local turned_on;
|
|
|
|
|
|
|
|
public func IsInteractable() { return GetCon() >= 100; }
|
|
|
|
|
|
|
|
public func GetInteractionMetaInfo(object clonk)
|
|
|
|
{
|
|
|
|
if (turned_on)
|
|
|
|
return { Description = "$MsgTurnOff$", IconName = nil, IconID = nil };
|
|
|
|
return { Description = "$MsgTurnOn$", IconName = nil, IconID = nil };
|
|
|
|
}
|
|
|
|
|
|
|
|
// On interaction the pump can be turned on or off.
|
|
|
|
public func Interact(object clonk)
|
|
|
|
{
|
|
|
|
if (turned_on)
|
|
|
|
{
|
|
|
|
turned_on = false;
|
|
|
|
SetAction("Wait");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
turned_on = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-31 12:20:54 +00:00
|
|
|
/*-- Pipe connection --*/
|
|
|
|
|
|
|
|
local source_pipe;
|
|
|
|
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; }
|
|
|
|
|
2012-02-18 21:50:18 +00:00
|
|
|
func QueryWaivePowerRequest()
|
|
|
|
{
|
|
|
|
// don't need power if not pumping anyway
|
|
|
|
if(GetAction() == "Wait")
|
|
|
|
return 50;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
func OnNotEnoughPower()
|
|
|
|
{
|
|
|
|
if(GetAction() == "Pump")
|
|
|
|
SetAction("Wait");
|
|
|
|
return _inherited(...);
|
|
|
|
}
|
|
|
|
|
|
|
|
func OnEnoughPower()
|
|
|
|
{
|
|
|
|
OnWaitStart();
|
|
|
|
return _inherited(...);
|
|
|
|
}
|
|
|
|
|
2010-12-31 12:20:54 +00:00
|
|
|
protected func OnPumpStart()
|
|
|
|
{
|
|
|
|
if (!ReadyToPump())
|
|
|
|
SetAction("Wait");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected func OnWaitStart()
|
|
|
|
{
|
2012-04-16 15:31:38 +00:00
|
|
|
if (GetCon() < 100) return;
|
|
|
|
|
2010-12-31 12:20:54 +00:00
|
|
|
if (ReadyToPump())
|
|
|
|
SetAction("Pump");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-11 22:32:46 +00:00
|
|
|
local aMaterials=["", 0]; //contained liquids
|
2012-03-10 17:23:48 +00:00
|
|
|
local pumpable_materials; // materials that can be pumped
|
2011-10-11 22:32:46 +00:00
|
|
|
|
2010-12-31 12:20:54 +00:00
|
|
|
protected func Pumping()
|
|
|
|
{
|
2012-03-10 19:45:18 +00:00
|
|
|
// Only if turned on.
|
|
|
|
if (!turned_on)
|
|
|
|
return SetAction("Wait");
|
2010-12-31 12:20:54 +00:00
|
|
|
// Pump liquids.
|
|
|
|
if (!source_pipe)
|
|
|
|
return SetAction("Wait");
|
2011-10-11 22:32:46 +00:00
|
|
|
//IsEmpty?
|
|
|
|
if ((aMaterials[1] == 0) || (aMaterials[0] == ""))
|
|
|
|
{
|
|
|
|
//Get new Materials
|
2012-03-10 17:23:48 +00:00
|
|
|
aMaterials = source_pipe->GetLiquid(pumpable_materials, 5, this, true);
|
2011-10-11 22:32:46 +00:00
|
|
|
//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];
|
|
|
|
}
|
|
|
|
//maybe add the possebility to empty pump (invaild mats?)
|
|
|
|
return;
|
2010-12-31 12:20:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns whether the pump can pump some liquid.
|
|
|
|
private func ReadyToPump()
|
|
|
|
{
|
2012-02-18 21:50:18 +00:00
|
|
|
// no power?
|
|
|
|
if(!CurrentlyHasPower())
|
|
|
|
return false;
|
2010-12-31 12:20:54 +00:00
|
|
|
// If there is no source pipe, return false.
|
|
|
|
if (!source_pipe)
|
|
|
|
return false;
|
|
|
|
// If there is nothing to pump at the source return false.
|
|
|
|
var source = source_pipe->GetConnectedObject(this);
|
|
|
|
if (!source)
|
|
|
|
return false;
|
|
|
|
if (!source->GBackLiquid())
|
|
|
|
return false;
|
|
|
|
// TODO: Account for pumping into buildings.
|
|
|
|
// Pumping is okay.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-10 17:23:48 +00:00
|
|
|
/**
|
|
|
|
Set name or wildcard string of materials this pump can pump
|
|
|
|
@param to_val: Material that can be pumped. 0 or "*" for any material.
|
|
|
|
*/
|
|
|
|
public func SetPumpableMaterials(string to_val)
|
|
|
|
{
|
|
|
|
pumpable_materials = to_val;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-31 12:20:54 +00:00
|
|
|
local Name = "$Name$";
|
2012-04-15 11:13:14 +00:00
|
|
|
local Description = "$Description$";
|
2012-04-28 14:17:38 +00:00
|
|
|
local BlastIncinerate = 50;
|
2010-12-31 12:20:54 +00:00
|
|
|
local ActMap = {
|
|
|
|
Pump = {
|
|
|
|
Prototype = Action,
|
|
|
|
Name = "Pump",
|
|
|
|
Procedure = DFA_NONE,
|
|
|
|
Length = 20,
|
|
|
|
Delay = 3,
|
2012-04-16 15:31:38 +00:00
|
|
|
Directions = 2,
|
|
|
|
FlipDir = 1,
|
2010-12-31 12:20:54 +00:00
|
|
|
X = 0,
|
|
|
|
Y = 0,
|
|
|
|
Wdt = 28,
|
|
|
|
Hgt = 32,
|
|
|
|
NextAction = "Pump",
|
|
|
|
StartCall = "OnPumpStart",
|
2011-10-11 22:32:46 +00:00
|
|
|
PhaseCall = "Pumping"
|
2010-12-31 12:20:54 +00:00
|
|
|
},
|
|
|
|
Wait = {
|
|
|
|
Prototype = Action,
|
|
|
|
Name = "Wait",
|
|
|
|
Procedure = DFA_NONE,
|
|
|
|
Length = 1,
|
|
|
|
Delay = 50,
|
2012-04-16 15:31:38 +00:00
|
|
|
Directions = 2,
|
|
|
|
FlipDir = 1,
|
2010-12-31 12:20:54 +00:00
|
|
|
X = 0,
|
|
|
|
Y = 0,
|
|
|
|
Wdt = 28,
|
|
|
|
Hgt = 32,
|
|
|
|
NextAction = "Wait",
|
2011-10-11 22:32:46 +00:00
|
|
|
StartCall = "OnWaitStart"
|
|
|
|
}
|
2011-01-02 21:43:54 +00:00
|
|
|
};
|