-
Notifications
You must be signed in to change notification settings - Fork 2
/
Script.c
161 lines (140 loc) · 4.14 KB
/
Script.c
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*-- Telegrafenstation --*/
#strict
#include BAS5
#include DOOR
local temp1, temp2;
/* Eingangssteuerung */
private func OpeningDoor() { Sound("GateOpen"); }
private func ClosingDoor() { Sound("GateClose"); }
/* Funktionen */
protected func ContextSend(object pClonk)
{
[$SendMsg$|Image=TEL1]
pClonk->ContainedCall("ContainedUp", this());
}
protected func ContainedUp(object pClonk)
{
[$SendMsg$]
CreateMenu(GetID(), pClonk, this(), 0, "$SendMsg$", 2);
var pLine, i = 1;
while(pLine = FindObject(CNNC, 0,0,0,0,0, "Connect", this(), 0, pLine))
AddMenuItem(Format("$TestWire$", i++), Format("TestWire(%d, %d)", ObjectNumber(pClonk), ObjectNumber(GetActionTarget(0,pLine))), WIRE, pClonk, 0, pClonk, "$TestWireDesc$");
if(Ready2Supply())
AddMenuItem("$MnCallSupp$", "CallSupply", TSCS, pClonk, 0, pClonk);
}
protected func ContainedDown()
{
[$CancelSending$]
if(!ActIdle() && !WildcardMatch(GetAction(), "*Door*")) return(SetAction("Idle"));
}
protected func TestWire(int pClonkNo, int pLineNo)
{
temp1 = pClonkNo;
temp2 = pLineNo;
// Nur wenn Energie da ist
SetAction("TestWire");
}
protected func Testing()
{
var pClonk = Object(temp1);
var pLine = Object(temp2);
temp1 = 0;
temp2 = 0;
// Clonk / Leitung weg
if(!pClonk || !pLine) return();
// Alte Funken entfernen
var oldSpark;
if(oldSpark = FindObjectOwner(TGTS, GetOwner(pClonk))) RemoveObject(oldSpark);
// Funken erzeugen
var Spark = CreateObject(TGTS, 27, -21, GetOwner(pClonk));
// Startpunkt ermitteln
var Start = GetActionTarget(0, pLine);
if(GetActionTarget(1, GetActionTarget(1, pLine)) == this()) Start = GetActionTarget(1, pLine);
// Losschicken
Spark->Set(pLine, Start);
}
protected func CallSupply(id dummy, object pClonk)
{
temp1 = pClonk;
// Nur wenn Energie da ist
SetAction("CallSupply");
}
protected func Supply()
{
if(!temp1) return();
var pClonk = temp1;
temp1 = 0;
// Hat der Spieler genug Geld?
if(GetWealth(GetOwner(pClonk)) < 20)
{
PlayerMessage(GetOwner(pClonk), "$MsgNoMoney$", pClonk);
Sound("Error", 1, 0,0, GetOwner(pClonk));
return();
}
// Geld abziehen, bestellen und Geräusch
DoWealth(GetOwner(pClonk), -20);
HomebaseProduce(GetOwner(pClonk));
return(Sound("Uncash", 1, 0,0, GetOwner(pClonk)));
}
// Bereit zum Nachschubliefern
public func Ready2Supply()
{
// Regel aktiviert
var sRule;
if(!(sRule=FindObject(TSCS))) return();
// Bin ich mit einem Randpfosten verbunden?
return(IsConnectedTo(LocalN("pPole1", sRule)) || IsConnectedTo(LocalN("pPole2", sRule)));
}
/* Leitungssteuerung */
public func MaxConnections()
{
if(ObjectCount(CNNC, 0,0,0,0,0, "Connect", this()) >= 2) return(1);
return();
}
public func WireOffset(& x, & y)
{
x = 27;
y = -21;
}
/* Status */
// Verbunden mit...
public func IsConnectedTo(object pTarget, object pIgnore)
{
// Seltsam aber: bin ich das Ziel?
if(pTarget == this()) return(1);
// Alle angeschlossenen Leitungen durchgehen
var pConnect, pEnd;
while(pConnect = FindObject(CNNC, 0,0,0,0,0, "Connect", this(), 0, pConnect))
{
// Endpunkt suchen
pEnd = GetWireEnd(pConnect, pTarget);
// Endpunkt = Ziel?
if(pEnd == pTarget) return(1);
// Endpunkt = ingoriertes Ziel?
if(pEnd == pIgnore) continue;
// Endpunkt sagen, dass er weiter schauen soll und schauen, ob er erfolgreich war
if(pEnd->~IsConnectedTo(pTarget, this())) return(1);
}
// Ich bin scheinbar nicht verbunden
return();
}
private func GetWireEnd(object pConnect, object pTarget)
{
var pEnd, pLine, pLineEnd;
// Ein Ende muss es geben
while(!pEnd)
{
// Leitung speichern
pLine = GetActionTarget(0, pConnect);
// Anderes Ende suchen
pLineEnd = GetActionTarget(0, pLine);
if(pLineEnd == pConnect) pLineEnd = GetActionTarget(1, pLine);
// Objekt dort anschauen
pLineEnd = GetActionTarget(1, pLineEnd);
// Objekt gefunden
pEnd = pLineEnd;
}
return(pEnd);
}
// Telegrafenleitungen sind hier anschließbar
public func IsWireConnectable() { return(1); }