pipes: fix attaching, cutting, swapping, messaging, and interface

install-platforms
Maikel de Vries 2018-01-13 11:00:41 +01:00
parent 84ad52251f
commit 3255b02728
8 changed files with 71 additions and 62 deletions

View File

@ -152,23 +152,21 @@ public func GetConnectedPipe()
}
// Do not accept source pipes
public func QueryConnectPipe(object pipe)
public func QueryConnectPipe(object pipe, bool do_msg)
{
if (GetConnectedPipe())
{
pipe->Report("$MsgHasPipe$");
if (do_msg)
pipe->Report("$MsgHasPipe$");
return true;
}
if (pipe->IsSourcePipe())
{
pipe->Report("$MsgPipeProhibited$");
if (do_msg)
pipe->Report("$MsgPipeProhibited$");
return true;
}
else
{
return false;
}
return false;
}
@ -255,10 +253,8 @@ public func OnPipeControl(symbol_or_object, string action, bool alt)
func FindAvailablePipe(object container)
{
for (var pipe in FindObjects(Find_ID(Pipe), Find_Container(container), Find_Or(Find_Func("IsAirPipe"), Find_Func("IsDrainPipe"), Find_Func("IsNeutralPipe"))))
{
if (!this->~QueryConnectPipe(pipe))
if (!this->~QueryConnectPipe(pipe, false))
return pipe;
}
return nil;
}

View File

@ -205,9 +205,10 @@ public func SetAirPipe()
/* ---------- Pipe Connection ---------- */
func ConnectPipeTo(object target, string specific_pipe_state, bool block_cutting)
public func ConnectPipeTo(object target, string specific_pipe_state, bool block_cutting)
{
if (!target || target->~QueryConnectPipe(this)) return false;
if (!target || target->~QueryConnectPipe(this, true))
return false;
AddLineConnectionTo(target, block_cutting);
target->OnPipeConnect(this, specific_pipe_state);
Sound("Objects::Connect");
@ -243,7 +244,7 @@ public func GetConnectedLine()
@par target the target object
*/
func AddLineConnectionTo(object target, bool block_cutting)
public func AddLineConnectionTo(object target, bool block_cutting)
{
var line = GetConnectedLine();
if (line)
@ -276,7 +277,7 @@ func AddLineConnectionTo(object target, bool block_cutting)
@par target the target object
*/
func CutLineConnection(object target)
public func CutLineConnection(object target)
{
var line = GetConnectedLine();
if (!line) return;
@ -316,7 +317,7 @@ public func QueryCutLineConnection(object target)
@par target the target object.
@return object the line that was created
*/
func CreateLine(object target, bool block_cutting)
public func CreateLine(object target, bool block_cutting)
{
// Create and connect pipe line.
pipe_line = CreateObject(PipeLine, 0, 0, NO_OWNER);
@ -333,7 +334,7 @@ protected func ControlUse(object clonk, int x, int y)
var target = FindObject(Find_AtPoint(), Find_Func("CanConnectPipe"));
if (target)
{
ConnectPipeTo(target);
ConnectPipeTo(target, GetPipeState());
}
return true;
}
@ -343,7 +344,7 @@ protected func ControlUse(object clonk, int x, int y)
Displays a message at top-level container of this object.
@par message the message
*/
func Report(string message)
public func Report(string message)
{
var reporter = this;
var next = Contained();

View File

@ -99,34 +99,34 @@ public func GetPipeControlMenuEntries(object clonk)
if (GetSourcePipe())
{
if (!GetSourcePipe()->QueryCutLineConnection(this))
PushBack(menu_entries, GetTankMenuEntry(Icon_Cancel, "$MsgCutSource$", 1, LIBRARY_TANK_Menu_Action_Cut_Source));
PushBack(menu_entries, GetTankMenuEntry(Icon_Cancel, "$MsgCutSource$", 1, LIBRARY_TANK_Menu_Action_Cut_Source, RGB(102, 136, 34)));
}
else if (source_pipe)
PushBack(menu_entries, GetTankMenuEntry(source_pipe, "$MsgConnectSource$", 1, LIBRARY_TANK_Menu_Action_Add_Source));
PushBack(menu_entries, GetTankMenuEntry(source_pipe, "$MsgConnectSource$", 1, LIBRARY_TANK_Menu_Action_Add_Source, RGB(102, 136, 34)));
if (GetDrainPipe())
{
if (!GetDrainPipe()->QueryCutLineConnection(this))
PushBack(menu_entries, GetTankMenuEntry(Icon_Cancel, "$MsgCutDrain$", 2, LIBRARY_TANK_Menu_Action_Cut_Drain));
PushBack(menu_entries, GetTankMenuEntry(Icon_Cancel, "$MsgCutDrain$", 2, LIBRARY_TANK_Menu_Action_Cut_Drain, RGB(238, 102, 0)));
}
else if (drain_pipe)
PushBack(menu_entries, GetTankMenuEntry(drain_pipe, "$MsgConnectDrain$", 2, LIBRARY_TANK_Menu_Action_Add_Drain));
PushBack(menu_entries, GetTankMenuEntry(drain_pipe, "$MsgConnectDrain$", 2, LIBRARY_TANK_Menu_Action_Add_Drain, RGB(238, 102, 0)));
if (GetNeutralPipe())
{
if (!GetNeutralPipe()->QueryCutLineConnection(this))
PushBack(menu_entries, GetTankMenuEntry(Icon_Cancel, "$MsgCutNeutral$", 3, LIBRARY_TANK_Menu_Action_Cut_Neutral));
PushBack(menu_entries, GetTankMenuEntry(Icon_Cancel, "$MsgCutNeutral$", 3, LIBRARY_TANK_Menu_Action_Cut_Neutral, RGB(80, 80, 120)));
}
else if (neutral_pipe)
PushBack(menu_entries, GetTankMenuEntry(neutral_pipe, "$MsgConnectNeutral$", 3, LIBRARY_TANK_Menu_Action_Add_Neutral));
PushBack(menu_entries, GetTankMenuEntry(neutral_pipe, "$MsgConnectNeutral$", 3, LIBRARY_TANK_Menu_Action_Add_Neutral, RGB(80, 80, 120)));
if (GetSourcePipe() && GetDrainPipe())
PushBack(menu_entries, GetTankMenuEntry(Icon_Swap, "$MsgSwapSourceDrain$", 4, LIBRARY_TANK_Menu_Action_Swap_SourceDrain));
if (IsAllowedSwapSourceDrain())
PushBack(menu_entries, GetTankMenuEntry(Icon_Swap, "$MsgSwapSourceDrain$", 4, LIBRARY_TANK_Menu_Action_Swap_SourceDrain, nil));
return menu_entries;
}
public func GetTankMenuEntry(symbol, string text, int priority, extra_data)
public func GetTankMenuEntry(symbol, string text, int priority, extra_data, int clr)
{
return {symbol = symbol, extra_data = extra_data,
custom =
@ -134,7 +134,7 @@ public func GetTankMenuEntry(symbol, string text, int priority, extra_data)
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}
image = {Prototype = lib_tank.custom_entry.image, Symbol = symbol, BackgroundColor = clr},
}};
}
@ -213,22 +213,38 @@ public func DoCutPipe(object pipe)
}
}
public func IsAllowedSwapSourceDrain()
{
if (!GetSourcePipe() || !GetDrainPipe())
return false;
var source_line = GetSourcePipe()->GetConnectedLine();
var drain_line = GetDrainPipe()->GetConnectedLine();
if (source_line && drain_line)
{
var source = source_line->GetConnectedObject(this);
var drain = drain_line->GetConnectedObject(this);
// Allow swapping if both ends are pipes.
if (source->GetID() == Pipe && drain->GetID() == Pipe)
return true;
}
// TODO: Also allow swapping if non pipe objects are on the other end and accept the drain or source.
return false;
}
public func DoSwapSourceDrain(object source, object drain)
{
// TODO: Check if swapping is even allowed.
SetDrainPipe(source);
SetSourcePipe(drain);
source->SetDrainPipe();
drain->SetSourcePipe();
// TODO: Also change the state of the objects on the other end of the pipe.
}
public func FindAvailablePipe(object container, find_state)
{
for (var pipe in FindObjects(Find_ID(Pipe), Find_Container(container), find_state))
{
if (!this->~QueryConnectPipe(pipe))
if (!this->~QueryConnectPipe(pipe, false))
return pipe;
}
return nil;
}

View File

@ -138,26 +138,26 @@ public func GetLiquidContainerMaxFillLevel(liquid_name)
}
// The foundry may have one drain and one source.
public func QueryConnectPipe(object pipe)
public func QueryConnectPipe(object pipe, bool do_msg)
{
if (GetDrainPipe() && GetSourcePipe())
{
pipe->Report("$MsgHasPipes$");
if (do_msg) pipe->Report("$MsgHasPipes$");
return true;
}
else if (GetSourcePipe() && pipe->IsSourcePipe())
{
pipe->Report("$MsgSourcePipeProhibited$");
if (do_msg) pipe->Report("$MsgSourcePipeProhibited$");
return true;
}
else if (GetDrainPipe() && pipe->IsDrainPipe())
{
pipe->Report("$MsgDrainPipeProhibited$");
if (do_msg) pipe->Report("$MsgDrainPipeProhibited$");
return true;
}
else if (pipe->IsAirPipe())
{
pipe->Report("$MsgPipeProhibited$");
if (do_msg) pipe->Report("$MsgPipeProhibited$");
return true;
}
return false;

View File

@ -182,26 +182,26 @@ private func SetInfoMessage(string msg)
/*-- Pipe control --*/
public func QueryConnectPipe(object pipe)
public func QueryConnectPipe(object pipe, bool do_msg)
{
if (GetDrainPipe() && GetSourcePipe())
{
pipe->Report("$MsgHasPipes$");
if (do_msg) pipe->Report("$MsgHasPipes$");
return true;
}
else if (pipe->IsSourcePipe() && GetSourcePipe())
{
pipe->Report("$MsgSourcePipeProhibited$");
if (do_msg) pipe->Report("$MsgSourcePipeProhibited$");
return true;
}
else if (pipe->IsDrainPipe() && GetDrainPipe())
{
pipe->Report("$MsgDrainPipeProhibited$");
if (do_msg) pipe->Report("$MsgDrainPipeProhibited$");
return true;
}
else if (pipe->IsAirPipe() && GetDrainPipe())
{
pipe->Report("$MsgAirPipeProhibited$");
if (do_msg) pipe->Report("$MsgAirPipeProhibited$");
return true;
}
return false;
@ -254,10 +254,8 @@ public func OnPipeConnect(object pipe, string specific_pipe_state)
public func OnPipeDisconnect(object pipe)
{
_inherited(pipe, ...);
if (!pipe->IsAirPipe())
pipe->SetNeutralPipe();
else // Stop pumping to prevent errors from Pumping()
// Stop pumping to prevent errors from Pumping() function.
if (pipe->IsAirPipe())
CheckState();
}

View File

@ -198,26 +198,26 @@ public func GetLiquidContainerMaxFillLevel(liquid_name)
}
// The foundry may have one drain and one source.
public func QueryConnectPipe(object pipe)
public func QueryConnectPipe(object pipe, bool do_msg)
{
if (GetDrainPipe() && GetSourcePipe())
{
pipe->Report("$MsgHasPipes$");
if (do_msg) pipe->Report("$MsgHasPipes$");
return true;
}
else if (GetSourcePipe() && pipe->IsSourcePipe())
{
pipe->Report("$MsgSourcePipeProhibited$");
if (do_msg) pipe->Report("$MsgSourcePipeProhibited$");
return true;
}
else if (GetDrainPipe() && pipe->IsDrainPipe())
{
pipe->Report("$MsgDrainPipeProhibited$");
if (do_msg) pipe->Report("$MsgDrainPipeProhibited$");
return true;
}
else if (pipe->IsAirPipe())
{
pipe->Report("$MsgPipeProhibited$");
if (do_msg) pipe->Report("$MsgPipeProhibited$");
return true;
}
return false;

View File

@ -71,16 +71,18 @@ public func GetLiquidContainerMaxFillLevel(liquid_name)
}
// The locomotive may only have a drain pipe.
public func QueryConnectPipe(object pipe)
public func QueryConnectPipe(object pipe, bool do_msg)
{
if (pipe->IsDrainPipe() && GetDrainPipe())
{
pipe->Report("$MsgHasDrainPipe$");
if (do_msg)
pipe->Report("$MsgHasDrainPipe$");
return true;
}
else if (pipe->IsSourcePipe() || pipe->IsAirPipe())
if (pipe->IsSourcePipe() || pipe->IsAirPipe())
{
pipe->Report("$MsgPipeProhibited$");
if (do_msg)
pipe->Report("$MsgPipeProhibited$");
return true;
}
return false;

View File

@ -22,17 +22,13 @@ public func IsLiquidContainerForMaterial(string liquid)
return WildcardMatch("Oil", liquid);
}
public func QueryConnectPipe(object pipe)
public func QueryConnectPipe(object pipe, bool do_msg)
{
if (pipe->IsDrainPipe() || pipe->IsNeutralPipe())
{
return false;
}
else
{
if (do_msg)
pipe->Report("$MsgPipeProhibited$");
return true;
}
return true;
}
public func OnPipeConnect(object pipe, string specific_pipe_state)