forked from Mirrors/openclonk
cable reel: fix connecting, max cable length, ensure straight cables
parent
a28b3b9ca1
commit
c629661af2
|
@ -42,14 +42,52 @@ public func GetConnectedObject(object obj)
|
|||
}
|
||||
|
||||
|
||||
/*-- Cable Changes --*/
|
||||
|
||||
public func Destruction()
|
||||
{
|
||||
if (GetActionTarget(0)) GetActionTarget(0)->~OnCableLineRemoval();
|
||||
if (GetActionTarget(1)) GetActionTarget(1)->~OnCableLineRemoval();
|
||||
return;
|
||||
}
|
||||
|
||||
public func OnLineChange()
|
||||
{
|
||||
// Notify action targets about line change.
|
||||
var act1 = GetActionTarget(0);
|
||||
var act2 = GetActionTarget(1);
|
||||
if (act1) act1->~OnCableLengthChange(this);
|
||||
if (act2) act2->~OnCableLengthChange(this);
|
||||
// Break line if it is too long or if it is bend.
|
||||
if (GetVertexNum() > 2 || GetCableLength() > this.CableMaxLength)
|
||||
{
|
||||
OnLineBreak();
|
||||
RemoveObject();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Returns the length between all the vertices.
|
||||
public func GetCableLength()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/*-- Breaking --*/
|
||||
|
||||
public func OnLineBreak(bool no_msg)
|
||||
{
|
||||
Sound("Objects::Connect");
|
||||
Sound("Objects::LineSnap");
|
||||
var act1 = GetActionTarget(0);
|
||||
var act2 = GetActionTarget(1);
|
||||
|
||||
if (!no_msg)
|
||||
BreakMessage();
|
||||
|
||||
SetAction("Idle");
|
||||
if (act1)
|
||||
{
|
||||
|
@ -61,19 +99,18 @@ public func OnLineBreak(bool no_msg)
|
|||
act2->~CableDeactivation(activations);
|
||||
act2->~RemoveCableConnection(this);
|
||||
}
|
||||
if (!no_msg)
|
||||
BreakMessage();
|
||||
}
|
||||
|
||||
public func BreakMessage()
|
||||
{
|
||||
var line_end = GetActionTarget(0);
|
||||
if (!line_end || line_end->GetID() != CableLorryReel)
|
||||
|
||||
if (!line_end || line_end->GetID() != CableReel)
|
||||
line_end = GetActionTarget(1);
|
||||
if (line_end && line_end->Contained())
|
||||
line_end = line_end->Contained();
|
||||
if (line_end)
|
||||
line_end->Message("$TxtLinebroke$");
|
||||
line_end->Message("$MsgCableBroke$");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -132,3 +169,4 @@ local ActMap = {
|
|||
};
|
||||
|
||||
local Name = "$Name$";
|
||||
local CableMaxLength = 500;
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
TxtLinebroke=Seil gerissen
|
||||
Name=Seilbahnseil
|
||||
MsgCableBroke=Seil gerissen
|
||||
Name=Seilbahnseil
|
|
@ -1,2 +1,2 @@
|
|||
TxtLinebroke=Line broke
|
||||
Name=Cable line
|
||||
MsgCableBroke=Cable broke
|
||||
Name=Cable
|
|
@ -1,5 +1,5 @@
|
|||
[DefCore]
|
||||
id=CableLorryReel
|
||||
id=CableReel
|
||||
Version=8,0
|
||||
Category=C4D_Object
|
||||
Width=8
|
||||
|
|
|
@ -5,13 +5,19 @@
|
|||
@author Clonkonaut
|
||||
*/
|
||||
|
||||
protected func Hit()
|
||||
|
||||
#include Library_Stackable
|
||||
|
||||
|
||||
public func Hit()
|
||||
{
|
||||
Sound("Hits::Materials::Rock::RockHit?");
|
||||
}
|
||||
|
||||
public func IsToolProduct() { return true; }
|
||||
|
||||
public func MaxStackCount() { return 4; }
|
||||
|
||||
|
||||
/*-- Line connection --*/
|
||||
|
||||
|
@ -27,41 +33,59 @@ protected func ControlUse(object clonk, int x, int y)
|
|||
// There already is a cable
|
||||
if (line)
|
||||
{
|
||||
// Find other connected crossing.
|
||||
var other_obj = nil;
|
||||
if (line->GetActionTarget(0) == this)
|
||||
other_obj = line->GetActionTarget(1);
|
||||
else if(line->GetActionTarget(1) == this)
|
||||
other_obj = line->GetActionTarget(0);
|
||||
else
|
||||
return FatalError("Cable reel: line not connected to reel while trying to connect crossings.");
|
||||
// Cable is already connected to obj -> remove cable.
|
||||
if (obj == line->GetActionTarget(0) || obj == line->GetActionTarget(1))
|
||||
{
|
||||
// Cable is already connected to obj -> remove line.
|
||||
line->RemoveObject();
|
||||
OnCableLengthChange();
|
||||
Sound("Objects::Connect");
|
||||
clonk->Message("$TxtLineRemoval$");
|
||||
clonk->Message("$TxtCableRemoval$");
|
||||
return true;
|
||||
}
|
||||
// Check if this connection does not already exist.
|
||||
else if (AreDirectlyConnectedCrossings(obj, other_obj))
|
||||
{
|
||||
clonk->Message("$TxtDoubleCable$");
|
||||
}
|
||||
// Create new connection.
|
||||
else
|
||||
{
|
||||
// Connect existing power line to obj.
|
||||
if (line->GetActionTarget(0) == this)
|
||||
line->SetActionTargets(obj, line->GetActionTarget(1));
|
||||
else if(line->GetActionTarget(1) == this)
|
||||
line->SetActionTargets(line->GetActionTarget(0), obj);
|
||||
else
|
||||
return;
|
||||
line->SetActionTargets(obj, other_obj);
|
||||
Sound("Objects::Connect");
|
||||
obj->AddCableConnection(line);
|
||||
OnCableLengthChange();
|
||||
clonk->Message("$TxtConnect$", obj->GetName());
|
||||
//RemoveObject();
|
||||
DoStackCount(-1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else // A new cable needs to be created.
|
||||
// A new cable needs to be created.
|
||||
else
|
||||
{
|
||||
line = CreateObjectAbove(CableLine, 0, 0, NO_OWNER);
|
||||
line->SetActionTargets(this, obj);
|
||||
OnCableLengthChange();
|
||||
Sound("Objects::Connect");
|
||||
clonk->Message("$TxtConnect$", obj->GetName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Finds all power lines connected to obj (can be nil in local calls).
|
||||
// Returns whether c1 and c2 are already directly connected by a cable.
|
||||
private func AreDirectlyConnectedCrossings(object c1, object c2)
|
||||
{
|
||||
return !!FindObject(Find_Func("IsConnectedTo", c1), Find_Func("IsConnectedTo", c2));
|
||||
}
|
||||
|
||||
// Finds all cables connected to obj (can be nil in local calls).
|
||||
private func Find_CableLine(object obj)
|
||||
{
|
||||
if (!obj)
|
||||
|
@ -70,6 +94,52 @@ private func Find_CableLine(object obj)
|
|||
}
|
||||
|
||||
|
||||
/*-- Inventory --*/
|
||||
|
||||
public func OnCableLineRemoval()
|
||||
{
|
||||
OnCableLengthChange();
|
||||
return;
|
||||
}
|
||||
|
||||
public func OnCableLengthChange()
|
||||
{
|
||||
// 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 line = FindObject(Find_CableLine());
|
||||
if (!line) return;
|
||||
|
||||
var percentage = 100 * line->GetCableLength() / line.CableMaxLength;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/*-- Properties --*/
|
||||
|
||||
local Name = "$Name$";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
TxtConnectLine=Leitung verbinden
|
||||
TxtNoNewLine=Hier kann keine neue Leitung verlegt werden.
|
||||
TxtLineRemoval=Stromleitung abgenommen.
|
||||
TxtConnect=Stromleitung verbunden|mit %s
|
||||
Name=Kabelspule
|
||||
Description=Drücke [Benutzen] vor einem Gebäude und ein weiteres Mal vor einem anderen Gebäude, um diese beiden mit einem Stromkabel zu verbinden.
|
||||
Description=Drücke [Benutzen] vor einer Seilbahnstation und ein weiteres Mal vor einer anderer Seilbahnstation, um diese beiden mit einem Seil zu verbinden. Die Stationen können nur mit einem geraden Seil verbunden werden.
|
||||
TxtNoNewLine=Hier kann kein neues Seil aufgehängt werden.
|
||||
TxtCableRemoval=Seil abnehmen.
|
||||
TxtDoubleCable=Stationen sind schon verbunden.
|
||||
TxtConnect=Seil verbunden|mit %s
|
|
@ -1,6 +1,6 @@
|
|||
TxtConnectLine=Connect line
|
||||
TxtNoNewLine=Cannot create a new line here.
|
||||
TxtLineRemoval=Power line disconnected.
|
||||
TxtConnect=Power line connected|to %s
|
||||
Name=Cable reel
|
||||
Description=Press [Use] in front of a structure and another time in front of another structure to connect both with a power line.
|
||||
Description=Press [Use] in front of a cable station and another time in front of another cable station to connect both with a cable. The cable stations may only be connected with a straight cable.
|
||||
TxtNoNewLine=Cannot create a new cable here.
|
||||
TxtCableRemoval=Cable disconnected.
|
||||
TxtDoubleCable=Stations are already connected.
|
||||
TxtConnect=Cable connected|to %s
|
|
@ -160,7 +160,7 @@ func InitializeObjects()
|
|||
var Metal001 = ToolsWorkshop001->CreateContents(Metal);
|
||||
Metal001->SetPosition(76, 369);
|
||||
|
||||
var CableLorryReel001 = CreateObjectAbove(CableLorryReel, 163, 386);
|
||||
CableLorryReel001->Unstick(7);
|
||||
var CableReel001 = CreateObjectAbove(CableReel, 163, 386);
|
||||
CableReel001->Unstick(7);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ protected func Initialize()
|
|||
chest->CreateContents(Dynamite, 4);
|
||||
chest->CreateContents(Shovel, 2);
|
||||
chest->CreateContents(Hammer, 2);
|
||||
chest->CreateContents(CableLorryReel, 2);
|
||||
chest->CreateContents(CableReel, 2);
|
||||
|
||||
// Tool workshop on the little mountain.
|
||||
var tools = CreateObjectAbove(ToolsWorkshop, 540, 260);
|
||||
|
|
Loading…
Reference in New Issue