Merge: Changes from merge conflict

liquid_container
Mark 2016-03-25 17:20:54 +01:00
parent dd7bf3e89e
commit c0245be627
2 changed files with 110 additions and 30 deletions

View File

@ -1,20 +1,11 @@
/*-- Pipe line
/**
Pipe line
Author: ST-DDT, Marky
--*/
local Name = "$Name$";
@author ST-DDT, Marky
*/
local pipe_kit;
local ActMap = {
Connect = {
Prototype = Action,
Name = "Connect",
Procedure = DFA_CONNECT,
NextAction = "Connect"
}
};
private func Initialize()
{
@ -30,33 +21,33 @@ public func SetNeutral()
SetProperty("LineColors", [RGB(80, 80, 120), RGB(80, 80, 120)]);
}
// Reddish colour
// Reddish colour.
public func SetDrain()
{
SetProperty("LineColors", [RGB(110, 80, 80), RGB(110, 80, 80)]);
}
// Greenish colour
// Greenish colour.
public func SetSource()
{
SetProperty("LineColors", [RGB(80, 110, 80), RGB(80, 110, 80)]);
}
/** Returns true if this object is a functioning pipe. */
// Returns true if this object is a functioning pipe.
public func IsPipeLine()
{
return GetAction() == "Connect";
}
/** Returns whether this pipe is connected to an object.
Returns only actually connected objects if the parameter 'strict' is true */
// Returns whether this pipe is connected to an object.
// Returns only actually connected objects if the parameter 'strict' is true.
public func IsConnectedTo(object obj, bool strict)
{
return GetActionTarget(0) == obj || GetActionTarget(1) == obj || (!strict && pipe_kit == obj);
}
/** Returns the object which is connected to obj through this pipe. */
// Returns the object which is connected to obj through this pipe.
public func GetConnectedObject(object obj)
{
if (GetActionTarget(0) == obj)
@ -66,7 +57,7 @@ public func GetConnectedObject(object obj)
return;
}
/** Switches connection from one object to another. */
// Switches connection from one object to another.
public func SwitchConnection(object connected_to, object obj)
{
var target0 = GetActionTarget(0), target1 = GetActionTarget(1);
@ -77,7 +68,7 @@ public func SwitchConnection(object connected_to, object obj)
SetActionTargets(target0, target1);
}
/** Saves the pipe object that created this line. */
// Saves the pipe object that created this line.
public func SetPipeKit(object obj)
{
pipe_kit = obj;
@ -96,7 +87,7 @@ public func GetPipeKit()
}
private func LineBreak(bool no_msg)
private func OnLineBreak(bool no_msg)
{
Sound("Objects::LineSnap");
if (!no_msg)
@ -112,6 +103,32 @@ private func LineBreak(bool no_msg)
return;
}
private func OnLineChange()
{
// Notify action targets about line change.
var act1 = GetActionTarget(0);
var act2 = GetActionTarget(1);
if (act1) act1->~OnPipeLengthChange(this);
if (act2) act2->~OnPipeLengthChange(this);
// Break line if it is too long.
if (GetPipeLength() > this.PipeMaxLength)
{
OnLineBreak();
RemoveObject();
}
return;
}
// Returns the length between all the vertices.
public func GetPipeLength()
{
var current_length = 0;
for (var index = 0; index < GetVertexNum() - 1; index++)
current_length += Distance(GetVertex(index, VTX_X), GetVertex(index, VTX_Y), GetVertex(index + 1, VTX_X), GetVertex(index + 1, VTX_Y));
return current_length;
}
private func Destruction()
{
var line_end = GetPipeKit();
@ -131,4 +148,19 @@ public func SaveScenarioObject(props)
if (!inherited(props, ...)) return false;
SaveScenarioObjectAction(props);
return true;
}
}
/*-- Properties --*/
local Name = "$Name$";
local PipeMaxLength = 1200;
local ActMap = {
Connect = {
Prototype = Action,
Name = "Connect",
Procedure = DFA_CONNECT,
NextAction = "Connect"
}
};

View File

@ -1,4 +1,5 @@
/*-- Pipe
/**
Pipe
Author: ST-DDT, Marky
@ -24,17 +25,12 @@
- The user may want to connect a drain pipe before connecting a source pipe
- The user may want to connect a neutral pipe
=> separate functions are necessary
--*/
*/
static const PIPE_STATE_Neutral = nil;
static const PIPE_STATE_Source = "Source";
static const PIPE_STATE_Drain = "Drain";
local Name = "$Name$";
local Description = "$Description$";
local Collectible = 1;
local PipeState = nil;
local ApertureOffsetX = 0;
local ApertureOffsetY = 3;
@ -55,6 +51,50 @@ private func Destruction()
public func IsToolProduct() { return true;}
public func OnPipeLineRemoval()
{
OnPipeLengthChange();
return;
}
public func OnPipeLengthChange()
{
// Update usage bar for a possible carrier (the clonk).
var carrier = Contained();
if (carrier)
carrier->~OnInventoryChange();
return;
}
// Display the line length bar over the pipe icon.
public func GetInventoryIconOverlay()
{
var pipe = FindObject(Find_ID(PipeLine), Find_Func("IsConnectedTo", this));
if (!pipe)
return;
var percentage = 100 * pipe->GetPipeLength() / pipe.PipeMaxLength;
var red = percentage * 255 / 100;
var green = 255 - red;
// Overlay a usage bar.
var overlay =
{
Bottom = "0.75em",
Margin = ["0.1em", "0.25em"],
BackgroundColor = RGB(0, 0, 0),
margin =
{
Margin = "0.05em",
bar =
{
BackgroundColor = RGB(red, green, 0),
Right = Format("%d%%", percentage),
}
}
};
return overlay;
}
public func CanBeStackedWith(object other)
{
// Do not stack source/drain/unused pipes
@ -275,3 +315,11 @@ func Report(string message)
reporter->Message(message, ...);
}
/*-- Properties --*/
local Name = "$Name$";
local Description = "$Description$";
local Collectible = 1;
local PipeState = nil;