summaryrefslogtreecommitdiffstats
path: root/Items.c4d/Tubekit.c4d/Script.c
blob: 25df4dbb5dd96fc7a33e3f099f5c09367c2f7276 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#strict 2

static const TK7I_Tube = TU7I;

func Find_TubeTarget()
{
	return [C4FO_Func, "IsTubeTarget"];
}

func Activate(object caller)
{
	var line = FindObject2(Find_Tube(this)), lineEnd;
	if(line)
	{
		lineEnd = line->GetLineEnd(this);
	}
	var targets = FindObjects(Find_AtRect(0, -9, 1, 18), Find_TubeTarget());
	if(GetLength(targets) > 1)
	{
		caller->~CreateSelectionMenu("ConnectTarget", targets, GetID(), "$SelectTarget$", this);
	}
	else if(GetLength(targets) == 1)
	{
		ConnectTarget(0, targets[0]);
	}
	else
	{
		PlayerMessage(GetController(caller), "$TxtNoNewLine$", this);
	}
	return true;
}

func ConnectTarget(id id, object target)
{
	var line = FindObject2(Find_Line(TK7I_Tube, this)), lineEnd;
	if(line)
	{
		lineEnd = line->GetLineEnd(this);
		if(lineEnd == target)
		{
			PlayerMessage(GetController(Contained()), "$TxtLineRemoval$", Contained(), GetName(line));
			RemoveObject(line);
			return true;
		}
	}
	else
	{
		line = CreateObject(TK7I_Tube);
		CreateObject(TK7I_Tube)->Complement(line);
	}
	
	if(line->GetActionTarget(0) == lineEnd)
	{
		line->SetActionTargets(lineEnd || this, target);
	}
	else
	{
		line->SetActionTargets(target, lineEnd || this);
	}
	
	PlayerMessage(GetController(Contained()), "$TxtConnect$", Contained(), GetName(line), GetName(target));
	if(lineEnd)
	{
		RemoveObject();
	}
	return true;
}

func AcceptsObject(object obj)
{
	return true;
}

func ReceiveObject(object obj, bool noReturn)
{
	obj->Enter(this);
	Exit(obj);
	if(Contained())
	{
		Put(Contained(), obj);
	}
	return true;
}

func IsAnvilProduct() { return true; }