2016-02-09 05:27:42 +00:00
|
|
|
/* --- Tank ---
|
2011-10-11 22:32:46 +00:00
|
|
|
|
2016-02-09 05:27:42 +00:00
|
|
|
A structure that can contain liquids. Connecting pipes to the
|
|
|
|
structure can be allowed, but this has to be implemented by the
|
|
|
|
object.
|
|
|
|
This is controlled with the callbacks
|
|
|
|
- QueryConnectPipe
|
|
|
|
- OnPipeConnect
|
|
|
|
- OnPipeDisconnect
|
|
|
|
in that structure.
|
|
|
|
|
|
|
|
Author: Marky
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include Library_LiquidContainer
|
2016-02-03 05:58:41 +00:00
|
|
|
|
2011-10-11 22:32:46 +00:00
|
|
|
|
2016-02-03 05:58:41 +00:00
|
|
|
static const LIBRARY_TANK_Menu_Action_Add_Drain = "adddrain";
|
|
|
|
static const LIBRARY_TANK_Menu_Action_Add_Source = "addsource";
|
2016-02-05 21:52:34 +00:00
|
|
|
static const LIBRARY_TANK_Menu_Action_Add_Neutral = "addneutral";
|
2016-02-03 05:58:41 +00:00
|
|
|
static const LIBRARY_TANK_Menu_Action_Cut_Drain = "cutdrain";
|
|
|
|
static const LIBRARY_TANK_Menu_Action_Cut_Source = "cutsource";
|
2016-02-05 21:52:34 +00:00
|
|
|
static const LIBRARY_TANK_Menu_Action_Cut_Neutral = "cutneutral";
|
2016-02-03 05:58:41 +00:00
|
|
|
static const LIBRARY_TANK_Menu_Action_Description = "description";
|
|
|
|
|
|
|
|
|
|
|
|
local lib_tank; // proplist for local variables
|
|
|
|
|
2016-02-05 21:52:34 +00:00
|
|
|
/* ---------- Callbacks ---------- */
|
|
|
|
|
2016-02-03 05:58:41 +00:00
|
|
|
func Construction()
|
2011-10-11 22:32:46 +00:00
|
|
|
{
|
2016-02-03 05:58:41 +00:00
|
|
|
lib_tank = {
|
|
|
|
drain_pipe = nil,
|
|
|
|
source_pipe = nil,
|
2016-02-05 21:52:34 +00:00
|
|
|
neutral_pipe = nil,
|
2016-02-03 05:58:41 +00:00
|
|
|
custom_entry =
|
|
|
|
{
|
|
|
|
Right = "100%", Bottom = "2em",
|
|
|
|
BackgroundColor = {Std = 0, OnHover = 0x50ff0000},
|
|
|
|
image = {Right = "2em"},
|
|
|
|
text = {Left = "2em"}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
_inherited(...);
|
2011-10-11 22:32:46 +00:00
|
|
|
}
|
|
|
|
|
2016-02-04 17:25:19 +00:00
|
|
|
func IsLiquidTank(){ return true;}
|
|
|
|
|
2016-02-05 21:52:34 +00:00
|
|
|
/* ---------- Menu Entries ---------- */
|
|
|
|
|
2016-02-03 05:58:41 +00:00
|
|
|
public func GetInteractionMenus(object clonk)
|
2011-10-11 22:32:46 +00:00
|
|
|
{
|
2016-02-03 05:58:41 +00:00
|
|
|
var menus = _inherited() ?? [];
|
|
|
|
|
|
|
|
if (CanConnectPipe())
|
2011-10-11 22:32:46 +00:00
|
|
|
{
|
2016-02-03 05:58:41 +00:00
|
|
|
var pipe_menu =
|
|
|
|
{
|
|
|
|
title = "$MenuPipeControl$",
|
|
|
|
entries_callback = this.GetPipeControlMenuEntries,
|
|
|
|
callback = "OnPipeControl",
|
|
|
|
callback_hover = "OnPipeControlHover",
|
|
|
|
callback_target = this,
|
|
|
|
BackgroundColor = RGB(0, 50, 50),
|
|
|
|
Priority = 30
|
|
|
|
};
|
|
|
|
PushBack(menus, pipe_menu);
|
2011-10-11 22:32:46 +00:00
|
|
|
}
|
2016-02-03 05:58:41 +00:00
|
|
|
return menus;
|
|
|
|
}
|
|
|
|
|
|
|
|
public func GetPipeControlMenuEntries(object clonk)
|
|
|
|
{
|
|
|
|
var menu_entries = [];
|
|
|
|
|
|
|
|
// Add info message about pipe control.
|
|
|
|
PushBack(menu_entries, {symbol = this, extra_data = LIBRARY_TANK_Menu_Action_Description,
|
|
|
|
custom =
|
|
|
|
{
|
|
|
|
Prototype = lib_tank.custom_entry,
|
|
|
|
Bottom = "1.2em",
|
|
|
|
Priority = -1,
|
|
|
|
BackgroundColor = RGB(25, 100, 100),
|
2016-02-05 21:52:34 +00:00
|
|
|
text = {Prototype = lib_tank.custom_entry.text, Text = "$MenuPipeControl$"},
|
2016-02-03 05:58:41 +00:00
|
|
|
image = {Prototype = lib_tank.custom_entry.image, Symbol = Pipe}
|
|
|
|
}});
|
|
|
|
|
2016-02-05 21:52:34 +00:00
|
|
|
var source_pipe = FindAvailablePipe(clonk, Find_Func("IsSourcePipe"));
|
|
|
|
var drain_pipe = FindAvailablePipe(clonk, Find_Func("IsDrainPipe"));
|
|
|
|
var neutral_pipe = FindAvailablePipe(clonk, Find_Func("IsNeutralPipe"));
|
2016-02-03 05:58:41 +00:00
|
|
|
|
|
|
|
if (GetSourcePipe())
|
2016-02-04 21:18:40 +00:00
|
|
|
PushBack(menu_entries, GetTankMenuEntry(Icon_Cancel, "$MsgCutSource$", 1, LIBRARY_TANK_Menu_Action_Cut_Source));
|
|
|
|
else if (source_pipe)
|
|
|
|
PushBack(menu_entries, GetTankMenuEntry(source_pipe, "$MsgConnectSource$", 1, LIBRARY_TANK_Menu_Action_Add_Source));
|
2016-02-05 21:52:34 +00:00
|
|
|
|
2016-02-03 05:58:41 +00:00
|
|
|
if (GetDrainPipe())
|
2016-02-04 21:18:40 +00:00
|
|
|
PushBack(menu_entries, GetTankMenuEntry(Icon_Cancel, "$MsgCutDrain$", 2, LIBRARY_TANK_Menu_Action_Cut_Drain));
|
|
|
|
else if (drain_pipe)
|
|
|
|
PushBack(menu_entries, GetTankMenuEntry(drain_pipe, "$MsgConnectDrain$", 2, LIBRARY_TANK_Menu_Action_Add_Drain));
|
2016-02-03 05:58:41 +00:00
|
|
|
|
2016-02-05 21:52:34 +00:00
|
|
|
if (GetNeutralPipe())
|
|
|
|
PushBack(menu_entries, GetTankMenuEntry(Icon_Cancel, "$MsgCutNeutral$", 3, LIBRARY_TANK_Menu_Action_Cut_Neutral));
|
|
|
|
else if (neutral_pipe)
|
|
|
|
PushBack(menu_entries, GetTankMenuEntry(neutral_pipe, "$MsgConnectNeutral$", 3, LIBRARY_TANK_Menu_Action_Add_Neutral));
|
|
|
|
|
2016-02-03 05:58:41 +00:00
|
|
|
return menu_entries;
|
2013-12-22 22:47:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-03 05:58:41 +00:00
|
|
|
func GetTankMenuEntry(symbol, string text, int priority, extra_data)
|
|
|
|
{
|
|
|
|
return {symbol = symbol, extra_data = extra_data,
|
|
|
|
custom =
|
|
|
|
{
|
|
|
|
Prototype = lib_tank.custom_entry,
|
|
|
|
Priority = priority,
|
|
|
|
text = {Prototype = lib_tank.custom_entry.text, Text = text},
|
|
|
|
image = {Prototype = lib_tank.custom_entry.image, Symbol = symbol}
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public func OnPipeControlHover(id symbol, string action, desc_menu_target, menu_id)
|
|
|
|
{
|
|
|
|
var text = "";
|
|
|
|
if (action == LIBRARY_TANK_Menu_Action_Add_Drain) text = "$DescConnectDrain$";
|
|
|
|
else if (action == LIBRARY_TANK_Menu_Action_Cut_Drain) text = "$DescCutDrain$";
|
|
|
|
else if (action == LIBRARY_TANK_Menu_Action_Add_Source) text = "$DescConnectSource$";
|
|
|
|
else if (action == LIBRARY_TANK_Menu_Action_Cut_Source) text = "$DescCutSource$";
|
2016-06-11 18:57:06 +00:00
|
|
|
else if (action == LIBRARY_TANK_Menu_Action_Add_Neutral) text = "$DescConnectNeutral$";
|
|
|
|
else if (action == LIBRARY_TANK_Menu_Action_Cut_Neutral) text = "$DescCutNeutral$";
|
2016-02-03 05:58:41 +00:00
|
|
|
else if (action == LIBRARY_TANK_Menu_Action_Description) text = this.Description;
|
|
|
|
GuiUpdateText(text, menu_id, 1, desc_menu_target);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public func OnPipeControl(symbol_or_object, string action, bool alt)
|
|
|
|
{
|
|
|
|
if (action == LIBRARY_TANK_Menu_Action_Add_Source)
|
2016-02-04 21:18:40 +00:00
|
|
|
this->DoConnectPipe(symbol_or_object, PIPE_STATE_Source);
|
2016-02-03 05:58:41 +00:00
|
|
|
else if (action == LIBRARY_TANK_Menu_Action_Cut_Source)
|
2016-02-04 21:18:40 +00:00
|
|
|
this->DoCutPipe(GetSourcePipe());
|
2016-02-03 05:58:41 +00:00
|
|
|
else if (action == LIBRARY_TANK_Menu_Action_Add_Drain)
|
2016-02-04 21:18:40 +00:00
|
|
|
this->DoConnectPipe(symbol_or_object, PIPE_STATE_Drain);
|
2016-02-03 05:58:41 +00:00
|
|
|
else if (action == LIBRARY_TANK_Menu_Action_Cut_Drain)
|
2016-02-04 21:18:40 +00:00
|
|
|
this->DoCutPipe(GetDrainPipe());
|
2016-02-05 21:52:34 +00:00
|
|
|
else if (action == LIBRARY_TANK_Menu_Action_Add_Neutral)
|
|
|
|
this->DoConnectPipe(symbol_or_object, PIPE_STATE_Neutral);
|
|
|
|
else if (action == LIBRARY_TANK_Menu_Action_Cut_Neutral)
|
|
|
|
this->DoCutPipe(GetNeutralPipe());
|
2016-02-03 05:58:41 +00:00
|
|
|
|
|
|
|
UpdateInteractionMenus(this.GetPipeControlMenuEntries);
|
|
|
|
}
|
|
|
|
|
2016-02-05 21:52:34 +00:00
|
|
|
|
|
|
|
/* ---------- Handle connections ---------- */
|
|
|
|
|
|
|
|
func GetDrainPipe(){ return lib_tank.drain_pipe;}
|
|
|
|
func GetSourcePipe(){ return lib_tank.source_pipe;}
|
|
|
|
func GetNeutralPipe(){ return lib_tank.neutral_pipe;}
|
|
|
|
|
|
|
|
func SetDrainPipe(object drain_pipe)
|
|
|
|
{
|
|
|
|
lib_tank.drain_pipe = drain_pipe;
|
|
|
|
return lib_tank.drain_pipe;
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetSourcePipe(object source_pipe)
|
|
|
|
{
|
|
|
|
lib_tank.source_pipe = source_pipe;
|
|
|
|
return lib_tank.source_pipe;
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetNeutralPipe(object neutral_pipe)
|
2016-02-03 05:58:41 +00:00
|
|
|
{
|
2016-02-05 21:52:34 +00:00
|
|
|
lib_tank.neutral_pipe = neutral_pipe;
|
|
|
|
return lib_tank.neutral_pipe;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ---------- Menu callbacks ---------- */
|
|
|
|
|
|
|
|
func DoConnectPipe(object pipe, string specific_pipe_state)
|
|
|
|
{
|
|
|
|
pipe->ConnectPipeTo(this, specific_pipe_state);
|
2016-02-03 05:58:41 +00:00
|
|
|
}
|
|
|
|
|
2016-02-06 22:12:26 +00:00
|
|
|
func DoCutPipe(object pipe)
|
2016-02-03 05:58:41 +00:00
|
|
|
{
|
2016-02-06 22:12:26 +00:00
|
|
|
if (pipe)
|
2016-02-03 05:58:41 +00:00
|
|
|
{
|
2016-02-06 22:12:26 +00:00
|
|
|
pipe->CutLineConnection(this);
|
2016-02-05 21:52:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func FindAvailablePipe(object container, find_state)
|
|
|
|
{
|
|
|
|
for (var pipe in FindObjects(Find_ID(Pipe), Find_Container(container), find_state))
|
|
|
|
{
|
|
|
|
if (!this->~QueryConnectPipe(pipe))
|
|
|
|
return pipe;
|
2016-02-03 05:58:41 +00:00
|
|
|
}
|
2016-02-05 21:52:34 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------- Pipe callbacks ---------- */
|
|
|
|
|
|
|
|
func CanConnectPipe(){ return true;}
|
|
|
|
|
2016-02-06 22:12:26 +00:00
|
|
|
func OnPipeDisconnect(object pipe)
|
2016-02-05 21:52:34 +00:00
|
|
|
{
|
|
|
|
// pipe objects have to be reset!
|
2016-02-06 22:12:26 +00:00
|
|
|
if (pipe == GetDrainPipe()) SetDrainPipe();
|
|
|
|
if (pipe == GetSourcePipe()) SetSourcePipe();
|
|
|
|
if (pipe == GetNeutralPipe()) SetNeutralPipe();
|
2013-12-22 22:47:40 +00:00
|
|
|
}
|