forked from Mirrors/openclonk
Added property LineMaxDistance to let a line break when connected objects are too far apart.
parent
400e8719bb
commit
4557d1638e
|
@ -101,7 +101,7 @@
|
|||
<row id="CONNECT">
|
||||
<col>CONNECT</col>
|
||||
<col>Line connections</col>
|
||||
<col>Only <emlink href="definition/lineconnect.html">line objects</emlink>. Connects <emlink href="script/fn/SetAction.html">target object 1</emlink> and <emlink href="script/fn/SetAction.html">target object 2</emlink>.</col>
|
||||
<col>Only <emlink href="definition/lineconnect.html">line objects</emlink>. Connects <emlink href="script/fn/SetAction.html">target object 1</emlink> and <emlink href="script/fn/SetAction.html">target object 2</emlink>. If property LineMaxDistance is a nonzero integer, the line breaks when the target objects are further apart than the given distance.</col>
|
||||
<col>CNAT_None</col>
|
||||
</row>
|
||||
<row id="PULL">
|
||||
|
|
|
@ -3952,84 +3952,88 @@ void C4Object::ExecAction()
|
|||
break;
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
case DFA_CONNECT:
|
||||
|
||||
bool fBroke;
|
||||
fBroke=false;
|
||||
int32_t iConnectX, iConnectY;
|
||||
|
||||
// Line destruction check: Target missing or incomplete
|
||||
if (!Action.Target || (Action.Target->Con<FullCon)) fBroke=true;
|
||||
if (!Action.Target2 || (Action.Target2->Con<FullCon)) fBroke=true;
|
||||
if (fBroke)
|
||||
{
|
||||
Call(PSF_LineBreak,&C4AulParSet(C4VBool(true)));
|
||||
AssignRemoval();
|
||||
return;
|
||||
}
|
||||
bool fBroke=false;
|
||||
|
||||
// Movement by Target
|
||||
if (Action.Target)
|
||||
{
|
||||
// Line destruction check: Target missing or incomplete
|
||||
if (!Action.Target || (Action.Target->Con<FullCon)) fBroke=true;
|
||||
if (!Action.Target2 || (Action.Target2->Con<FullCon)) fBroke=true;
|
||||
if (fBroke)
|
||||
{
|
||||
Call(PSF_LineBreak,&C4AulParSet(C4VBool(true)));
|
||||
AssignRemoval();
|
||||
return;
|
||||
}
|
||||
|
||||
// Movement by Target
|
||||
// Connect to attach vertex
|
||||
C4Value lineAttachV;
|
||||
C4Value lineAttachV; C4ValueArray *lineAttach;
|
||||
Action.Target->GetProperty(P_LineAttach, &lineAttachV);
|
||||
C4ValueArray *lineAttach = lineAttachV.getArray();
|
||||
iConnectX = Action.Target->GetX();
|
||||
iConnectY = Action.Target->GetY();
|
||||
lineAttach = lineAttachV.getArray();
|
||||
int32_t iConnectX1, iConnectY1;
|
||||
iConnectX1 = Action.Target->GetX();
|
||||
iConnectY1 = Action.Target->GetY();
|
||||
if (lineAttach)
|
||||
{
|
||||
iConnectX += lineAttach->GetItem(0).getInt();
|
||||
iConnectY += lineAttach->GetItem(1).getInt();
|
||||
iConnectX1 += lineAttach->GetItem(0).getInt();
|
||||
iConnectY1 += lineAttach->GetItem(1).getInt();
|
||||
}
|
||||
if ((iConnectX!=Shape.VtxX[0]) || (iConnectY!=Shape.VtxY[0]))
|
||||
if ((iConnectX1!=Shape.VtxX[0]) || (iConnectY1!=Shape.VtxY[0]))
|
||||
{
|
||||
// Regular wrapping line
|
||||
if (Def->LineIntersect == 0)
|
||||
if (!Shape.LineConnect(iConnectX,iConnectY,0,+1,
|
||||
Shape.VtxX[0],Shape.VtxY[0])) fBroke=true;
|
||||
if (!Shape.LineConnect(iConnectX1,iConnectY1,0,+1,
|
||||
Shape.VtxX[0],Shape.VtxY[0])) fBroke=true;
|
||||
// No-intersection line
|
||||
if (Def->LineIntersect == 1)
|
||||
{ Shape.VtxX[0]=iConnectX; Shape.VtxY[0]=iConnectY; }
|
||||
{ Shape.VtxX[0]=iConnectX1; Shape.VtxY[0]=iConnectY1; }
|
||||
}
|
||||
}
|
||||
// Movement by Target2
|
||||
if (Action.Target2)
|
||||
{
|
||||
|
||||
// Movement by Target2
|
||||
// Connect to attach vertex
|
||||
C4Value lineAttachV;
|
||||
Action.Target2->GetProperty(P_LineAttach, &lineAttachV);
|
||||
C4ValueArray *lineAttach = lineAttachV.getArray();
|
||||
iConnectX = Action.Target2->GetX();
|
||||
iConnectY = Action.Target2->GetY();
|
||||
lineAttach = lineAttachV.getArray();
|
||||
int32_t iConnectX2, iConnectY2;
|
||||
iConnectX2 = Action.Target2->GetX();
|
||||
iConnectY2 = Action.Target2->GetY();
|
||||
if (lineAttach)
|
||||
{
|
||||
iConnectX += lineAttach->GetItem(0).getInt();
|
||||
iConnectY += lineAttach->GetItem(1).getInt();
|
||||
iConnectX2 += lineAttach->GetItem(0).getInt();
|
||||
iConnectY2 += lineAttach->GetItem(1).getInt();
|
||||
}
|
||||
if ((iConnectX!=Shape.VtxX[Shape.VtxNum-1]) || (iConnectY!=Shape.VtxY[Shape.VtxNum-1]))
|
||||
if ((iConnectX2!=Shape.VtxX[Shape.VtxNum-1]) || (iConnectY2!=Shape.VtxY[Shape.VtxNum-1]))
|
||||
{
|
||||
// Regular wrapping line
|
||||
if (Def->LineIntersect == 0)
|
||||
if (!Shape.LineConnect(iConnectX,iConnectY,Shape.VtxNum-1,-1,
|
||||
Shape.VtxX[Shape.VtxNum-1],Shape.VtxY[Shape.VtxNum-1])) fBroke=true;
|
||||
if (!Shape.LineConnect(iConnectX2,iConnectY2,Shape.VtxNum-1,-1,
|
||||
Shape.VtxX[Shape.VtxNum-1],Shape.VtxY[Shape.VtxNum-1])) fBroke=true;
|
||||
// No-intersection line
|
||||
if (Def->LineIntersect == 1)
|
||||
{ Shape.VtxX[Shape.VtxNum-1]=iConnectX; Shape.VtxY[Shape.VtxNum-1]=iConnectY; }
|
||||
{ Shape.VtxX[Shape.VtxNum-1]=iConnectX2; Shape.VtxY[Shape.VtxNum-1]=iConnectY2; }
|
||||
}
|
||||
|
||||
// Check max length
|
||||
int32_t max_dist;
|
||||
max_dist = GetPropertyInt(P_LineMaxDistance);
|
||||
if (max_dist)
|
||||
{
|
||||
int32_t dist_x = iConnectX2 - iConnectX1, dist_y = iConnectY2 - iConnectY1;
|
||||
int64_t dist_x2 = int64_t(dist_x)*dist_x, dist_y2 = int64_t(dist_y)*dist_y, max_dist2 = int64_t(max_dist)*max_dist;
|
||||
if (dist_x2+dist_y2 > max_dist2) fBroke = true;
|
||||
}
|
||||
|
||||
// Line fBroke
|
||||
if (fBroke)
|
||||
{
|
||||
Call(PSF_LineBreak,0);
|
||||
AssignRemoval();
|
||||
return;
|
||||
}
|
||||
|
||||
// Reduce line segments
|
||||
if (!::Game.iTick35)
|
||||
ReduceLineSegments(Shape, !::Game.iTick2);
|
||||
}
|
||||
|
||||
// Line fBroke
|
||||
if (fBroke)
|
||||
{
|
||||
Call(PSF_LineBreak,0);
|
||||
AssignRemoval();
|
||||
return;
|
||||
}
|
||||
|
||||
// Reduce line segments
|
||||
if (!::Game.iTick35)
|
||||
ReduceLineSegments(Shape, !::Game.iTick2);
|
||||
|
||||
break;
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
default:
|
||||
|
|
|
@ -130,6 +130,7 @@ C4StringTable::C4StringTable()
|
|||
P[P_Parallaxity] = "Parallaxity";
|
||||
P[P_LineColors] = "LineColors";
|
||||
P[P_LineAttach] = "LineAttach";
|
||||
P[P_LineMaxDistance] = "LineMaxDistance";
|
||||
P[P_MouseDrag] = "MouseDrag";
|
||||
P[P_MouseDragImage] = "MouseDragImage";
|
||||
P[P_PictureTransformation] = "PictureTransformation";
|
||||
|
|
|
@ -300,6 +300,7 @@ enum C4PropertyName
|
|||
P_Parallaxity,
|
||||
P_LineColors,
|
||||
P_LineAttach,
|
||||
P_LineMaxDistance,
|
||||
P_PictureTransformation,
|
||||
P_MeshTransformation,
|
||||
P_Procedure,
|
||||
|
|
Loading…
Reference in New Issue