add new liquid tank structure (graphics needed)

install-platforms
Maikel de Vries 2018-01-13 11:06:00 +01:00
parent 3255b02728
commit dc541620b5
7 changed files with 248 additions and 1 deletions

View File

@ -0,0 +1,14 @@
[DefCore]
id=LiquidTank
Version=8,0
Category=C4D_Structure
Width=40
Height=72
Offset=-20,-36
Vertices=6
VertexX=-16,16,-18,18,-18,18
VertexY=35,35,0,0,-20,-20
VertexFriction=100,100,50,50,50,50
Mass=800
Exclusive=1
Construction=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

View File

@ -0,0 +1,174 @@
/**
Liquid Tank
Holds liquids of any type and can be opened to create a flood.
@author Maikel
*/
#include Library_Structure
#include Library_Ownable
#include Library_Tank
public func Initialize()
{
return _inherited(...);
}
public func Construction(object creator)
{
return _inherited(creator, ...);
}
public func IsHammerBuildable() { return true; }
/*-- Liquid Control --*/
// Only accept a single liquid at the same time, but accept any liquid type.
public func IsLiquidContainerForMaterial(string liquid)
{
for (var liquid_content in GetLiquidContents())
if (GetLiquidDef(liquid) != GetLiquidDef(liquid_content->GetID()))
return false;
return true;
}
public func GetLiquidContainerMaxFillLevel(liquid_name)
{
return this.LiquidCapacity;
}
// The liquid tank may have one drain and one source.
public func QueryConnectPipe(object pipe, bool do_msg)
{
if (GetDrainPipe() && GetSourcePipe())
{
if (do_msg) pipe->Report("$MsgHasPipes$");
return true;
}
else if (GetSourcePipe() && pipe->IsSourcePipe())
{
if (do_msg) pipe->Report("$MsgSourcePipeProhibited$");
return true;
}
else if (GetDrainPipe() && pipe->IsDrainPipe())
{
if (do_msg) pipe->Report("$MsgDrainPipeProhibited$");
return true;
}
else if (pipe->IsAirPipe())
{
if (do_msg) pipe->Report("$MsgPipeProhibited$");
return true;
}
return false;
}
// Set to source or drain pipe.
public func OnPipeConnect(object pipe, string specific_pipe_state)
{
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$");
}
/*-- Interaction --*/
public func IsInteractable(object clonk)
{
if (GetCon() < 100)
return false;
return !Hostile(GetOwner(), clonk->GetOwner());
}
public func GetInteractionMetaInfo(object clonk)
{
if (GetEffect("FxDisperseLiquid", this))
return { Description = "$MsgCloseTank$", IconName = nil, IconID = Icon_Enter, Selected = false };
return { Description = "$MsgOpenTank$", IconName = nil, IconID = Icon_Exit, Selected = false };
}
public func Interact(object clonk)
{
var fx = GetEffect("FxDisperseLiquid", this);
if (fx)
{
fx->Remove();
return true;
}
CreateEffect(FxDisperseLiquid, 100, 2);
return true;
}
local FxDisperseLiquid = new Effect
{
Construction = func()
{
this.Interval = 2;
return FX_OK;
},
Timer = func()
{
var liquid = Target->Contents();
if (!liquid || !liquid->~IsLiquid())
return FX_OK;
if (liquid->GetLiquidAmount() <= Target.DispersionRate)
{
liquid->Exit();
liquid->SetPosition(Target->GetX(), Target->GetY());
liquid->Disperse(180, 40);
}
else
{
liquid->RemoveLiquid(nil, Target.DispersionRate);
liquid = liquid->GetID()->CreateLiquid(Target.DispersionRate);
liquid->SetPosition(Target->GetX(), Target->GetY());
liquid->Disperse(180, 40);
}
// TODO: Sound.
return FX_OK;
}
};
/*-- Contents Control --*/
public func IsContainer() { return true; }
protected func RejectCollect(id item, object obj)
{
// Accept liquids only.
if (obj->~IsLiquid())
return _inherited(item, obj, ...);
return true;
}
/*-- Properties --*/
local Name = "$Name$";
local Description ="$Description$";
local BlastIncinerate = 100;
local FireproofContainer = true;
local HitPoints = 90;
local Components = {Wood = 3, Metal = 2};
local LiquidCapacity = 10000;
local DispersionRate = 40;

View File

@ -0,0 +1,11 @@
Name=Tank
Description=Hier können Flüssigkeiten gespeichert werden, aber nur eine Art gleichzeitig.
MsgConnectedPipe=Rohr angeschlossen.
MsgPipeProhibited=Dieses Rohr kann nicht an den Tank angeschlossen werden.
MsgHasPipes=Der Tank hat schon ein Zu- und Abflussrohr.
MsgSourcePipeProhibited=Zuflussrohre können nicht an den Tank angeschlossen werden.
MsgDrainPipeProhibited=Abflussrohre können nicht an den Tank angeschlossen werden.
MsgOpenTank=Ventil öffnen
MsgCloseTank=Ventil schließen

View File

@ -0,0 +1,11 @@
Name=Liquid Tank
Description=Liquids can be stored here, but only one type of liquid at the same time.
MsgConnectedPipe=Connected pipe.
MsgPipeProhibited=This pipe cannot be connected to the liquid tank.
MsgHasPipes=Liquid tank already has a source and a drain pipe.
MsgSourcePipeProhibited=Unable to connect source pipe to the liquid tank.
MsgDrainPipeProhibited=Unable to connect drain pipe to the liquid tank.
MsgOpenTank=Open valve
MsgCloseTank=Close valve

View File

@ -378,6 +378,43 @@ global func Test5_OnFinished()
return;
}
global func Test6_OnStart(int plr)
{
var tank = CreateObjectAbove(LiquidTank, 70, 160, plr);
var pump1 = CreateObjectAbove(Pump, 16, 160, plr);
var pump2 = CreateObjectAbove(Pump, 124, 160, plr);
var source = CreateObjectAbove(Pipe, 168, 292, plr);
source->ConnectPipeTo(pump1, PIPE_STATE_Source);
var drain = CreateObjectAbove(Pipe, 240, 100, plr);
drain->ConnectPipeTo(pump1, PIPE_STATE_Drain);
drain->ConnectPipeTo(tank, PIPE_STATE_Drain);
var source = CreateObjectAbove(Pipe, 168, 292, plr);
source->ConnectPipeTo(pump2, PIPE_STATE_Source);
source->ConnectPipeTo(tank, PIPE_STATE_Source);
var drain = CreateObjectAbove(Pipe, 240, 100, plr);
drain->ConnectPipeTo(pump2, PIPE_STATE_Drain);
// Log what the test is about.
Log("Test pumping into and from a liquid tank");
return true;
}
global func Test6_Completed()
{
if (GetMaterial(240, 60) == Material("Water"))
return true;
return false;
}
global func Test6_OnFinished()
{
RemoveAll(Find_Or(Find_ID(LiquidTank), Find_ID(Pump), Find_ID(Pipe)));
RestoreWaterLevels();
return;
}
/*-- Helper Functions --*/

View File

@ -59,7 +59,7 @@ global func GivePlayerPumpingKnowledge(int plr)
{
var knowledge = [
// Stuff needed for pumping.
Pump, Pipe
Pump, Pipe /*,LiquidTank TODO: add when graphics are done*/
];
for (var plan in knowledge)
SetPlrKnowledge(plr, plan);