Collect cut pipes to Clonk inventory, if possible

master
Mark 2018-12-25 15:53:51 +01:00
parent f5b1279cce
commit 1c9164b4be
4 changed files with 69 additions and 23 deletions

View File

@ -45,7 +45,9 @@ public func QueryAirNeed(object pump)
{
var wearer = Contained();
if (wearer && IsWorn())
{
return wearer->~GetBreath() < wearer->~GetMaxBreath();
}
return false;
}
@ -103,28 +105,33 @@ func OnPipeDisconnect(object pipe)
var other = air_pipe->GetConnectedObject(this);
if (!other || other->GetID() != Pump)
{
pipe->SetNeutralPipe();
}
pipe->SetDrainPipe();
other->~CheckState();
}
// Called by the interaction menu (OnPipeControl)
public func DoConnectPipe(object pipe, string specific_pipe_state)
public func DoConnectPipe(object pipe, string specific_pipe_state, object clonk)
{
if (!pipe) return;
if (GetConnectedPipe())
DoCutPipe(GetConnectedPipe());
{
DoCutPipe(GetConnectedPipe(), clonk);
}
pipe->ConnectPipeTo(this, PIPE_STATE_Air);
}
// Called by the interaction menu (OnPipeControl)
public func DoCutPipe(object pipe)
public func DoCutPipe(object pipe, object clonk)
{
if (pipe)
if (pipe->~GetPipeKit())
pipe->GetPipeKit()->CutLineConnection(this);
if (pipe && pipe->~GetPipeKit())
{
pipe->GetPipeKit()->CutLineConnection(this, clonk);
}
}
/*-- Usage --*/
@ -132,9 +139,13 @@ public func DoCutPipe(object pipe)
public func ControlUse(object clonk)
{
if (IsWorn())
{
TakeOff();
}
else
{
PutOn(clonk);
}
return true;
}
@ -157,13 +168,17 @@ public func QueryConnectPipe(object pipe, bool do_msg)
if (GetConnectedPipe())
{
if (do_msg)
{
pipe->Report("$MsgHasPipe$");
}
return true;
}
if (pipe->IsSourcePipe())
{
if (do_msg)
{
pipe->Report("$MsgPipeProhibited$");
}
return true;
}
return false;
@ -240,12 +255,16 @@ public func OnPipeControlHover(id symbol, string action, desc_menu_target, menu_
GuiUpdateText(text, menu_id, 1, desc_menu_target);
}
public func OnPipeControl(symbol_or_object, string action, bool alt)
public func OnPipeControl(symbol_or_object, string action, object clonk)
{
if (action == "cutpipe")
this->DoCutPipe(air_pipe);
{
this->DoCutPipe(air_pipe, clonk);
}
else if (action == "connectpipe")
this->DoConnectPipe(symbol_or_object);
{
this->DoConnectPipe(symbol_or_object, nil, clonk);
}
UpdateInteractionMenus(this.GetPipeControlMenuEntries);
}
@ -301,4 +320,4 @@ func Definition(def)
local Name = "$Name$";
local Description = "$Description$";
local Collectible = true;
local Components = {Wood = 1, Metal = 1};
local Components = {Wood = 1, Metal = 1};

View File

@ -277,31 +277,44 @@ public func AddLineConnectionTo(object target, bool block_cutting)
connected to the line.
@par target the target object
@par possible_container a container that should try to collect the pipe.
*/
public func CutLineConnection(object target)
public func CutLineConnection(object target, object possible_container)
{
var line = GetConnectedLine();
if (!line) return;
var allow_pickup = false;
// connected only to the kit and a structure
// Connected only to the kit and a structure
if (line->IsConnectedTo(this, true))
{
target->OnPipeDisconnect(this);
line->RemoveObject();
// Collection by container, should be near enough or else you'd be able to
// retrieve a line where the line kit is down a well, but you simply detach it from the pump...
// Radius is the same as picking up objects via the surrounding
allow_pickup = ObjectDistance(possible_container, this) <= Helper_Surrounding.Radius;
}
// connected to the target and another structure
// Connected to the target and another structure
else if (line->IsConnectedTo(target, true))
{
target->OnPipeDisconnect(this);
Exit(); // the kit was inside the line at this point.
Exit(); // The kit was inside the line at this point.
SetPosition(target->GetX(), target->GetY() + target->GetBottom() - this->GetBottom());
line->SwitchConnection(target, this);
SetPipeLine(line);
// Can be picked up always
allow_pickup = true;
}
else
{
FatalError(Format("An object %v is trying to cut the pipe connection, but only objects %v and %v may request a disconnect", target, line->GetActionTarget(0), line->GetActionTarget(1)));
}
// Pick it up
if (possible_container && allow_pickup)
{
possible_container->Collect(this);
}
}
// Returns whether the cutting pipe is blocked.

View File

@ -160,22 +160,36 @@ public func OnPipeControlHover(symbol_or_object, string action, desc_menu_target
GuiUpdateText(text, menu_id, 1, desc_menu_target);
}
public func OnPipeControl(symbol_or_object, string action, bool alt)
public func OnPipeControl(symbol_or_object, string action, object clonk)
{
if (action == LIBRARY_TANK_Menu_Action_Add_Source)
{
this->DoConnectPipe(symbol_or_object, PIPE_STATE_Source);
}
else if (action == LIBRARY_TANK_Menu_Action_Cut_Source)
this->DoCutPipe(GetSourcePipe());
{
this->DoCutPipe(GetSourcePipe(), clonk);
}
else if (action == LIBRARY_TANK_Menu_Action_Add_Drain)
{
this->DoConnectPipe(symbol_or_object, PIPE_STATE_Drain);
}
else if (action == LIBRARY_TANK_Menu_Action_Cut_Drain)
this->DoCutPipe(GetDrainPipe());
{
this->DoCutPipe(GetDrainPipe(), clonk);
}
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());
{
this->DoCutPipe(GetNeutralPipe(), clonk);
}
else if (action == LIBRARY_TANK_Menu_Action_Swap_SourceDrain)
{
this->DoSwapSourceDrain(GetSourcePipe(), GetDrainPipe());
}
UpdateInteractionMenus(this.GetPipeControlMenuEntries);
}
@ -236,11 +250,11 @@ public func DoConnectPipe(object pipe, string specific_pipe_state)
pipe->ConnectPipeTo(this, specific_pipe_state);
}
public func DoCutPipe(object pipe)
public func DoCutPipe(object pipe, object clonk)
{
if (pipe)
{
pipe->CutLineConnection(this);
pipe->CutLineConnection(this, clonk);
}
}

View File

@ -226,11 +226,11 @@ public func OnPipeControlHover(symbol_or_object, string action, desc_menu_target
return inherited(symbol_or_object, action, desc_menu_target, menu_id, ...);
}
public func OnPipeControl(symbol_or_object, string action, bool alt)
public func OnPipeControl(symbol_or_object, string action, object clonk)
{
if (action == LIBRARY_TANK_Menu_Action_Cut_AirPipe)
{
this->DoCutPipe(GetDrainPipe());
this->DoCutPipe(GetDrainPipe(), clonk);
UpdateInteractionMenus(this.GetPipeControlMenuEntries);
return;
}
@ -240,7 +240,7 @@ public func OnPipeControl(symbol_or_object, string action, bool alt)
UpdateInteractionMenus(this.GetPipeControlMenuEntries);
return;
}
return inherited(symbol_or_object, action, alt, ...);
return inherited(symbol_or_object, action, clonk, ...);
}