-
Notifications
You must be signed in to change notification settings - Fork 0
/
=rcomm.lsl
executable file
·261 lines (236 loc) · 7.71 KB
/
=rcomm.lsl
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// =rcomm.lsl
// rezzed-ring communications handler
//
// Open Source 'Stargate' Ring Platform
// Copyright 2008-2009 (C) CB Radek (Sarah Bennert)
// http://xhub.com
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////////////////////
//
// PLEASE READ THE README FILE
//
////////////////////////////////////////////////////////////////////////////////////////////////
integer debug = 0;
integer linkChannel = -1; // this will be changed after init comms with icomm.lsl
integer listenChannel = -3141592;
integer listen_handle = 0;
key ringBase = NULL_KEY;
key ring1 = NULL_KEY;
key ring2 = NULL_KEY;
key ring3 = NULL_KEY;
key ring4 = NULL_KEY;
key ring5 = NULL_KEY;
string newPrim = "";
string currentState = "";
string messageTO;
string messageFROM;
string messageCOMMAND;
string commandList;
integer ringPos;
float ringHeight;
list message_list = [ "" , "" , <0,0,0>];
// internal messages pass through icomm.lsl. use this function to communicate with other scripts
sendMessage(string command, string data)
{
llMessageLinked(LINK_THIS, 0, command, (key)data);
}
// Start ring process
rezRings()
{
// set the ring base texture
llSetPrimitiveParams([PRIM_GLOW, 0, 1.0]);
llTriggerSound("ringSound", 1.0);
// we need to set this 'flag' so we know below in obj_rez that the event was meant for us
newPrim = "ringPrim";
// rez the first ring
llRezObject("ring", // object name
llGetPos() + <0.0,0.0,ringHeight>,
<0.0,0.0,0.0>,
llEuler2Rot(<0,0,0>*DEG_TO_RAD),
ringPos--); // position value sent to new ring object
}
// called by obj_rez if due to a ring creation
// need to store the keys of the rings so we can communicate with them
onRezRings(key id)
{
if (ring1 == NULL_KEY)
{
ring1 = id;
}
else if (ring2 == NULL_KEY)
{
ring2 = id;
}
else if (ring3 == NULL_KEY)
{
ring3 = id;
}
else if (ring4 == NULL_KEY)
{
ring4 = id;
}
else if (ring5 == NULL_KEY)
{
ring5 = id;
}
// when we've identified the key of the ring, we say a quick hello to
// give the ring our key. Otherwise it wouldn't know future messages were from us
llWhisper(listenChannel,
(string)id + ":" +
(string)ringBase + ":" +
"HelloRing");
}
// called when transport is complete. lowering ring back down in reverse sequence.
deRezRings()
{
if (ring5 != NULL_KEY)
llSay(listenChannel, (string)ring5 + ":" + (string)ringBase + ":Die");
if (ring4 != NULL_KEY)
llSay(listenChannel, (string)ring4 + ":" + (string)ringBase + ":Die");
if (ring3 != NULL_KEY)
llSay(listenChannel, (string)ring3 + ":" + (string)ringBase + ":Die");
if (ring2 != NULL_KEY)
llSay(listenChannel, (string)ring2 + ":" + (string)ringBase + ":Die");
if (ring1 != NULL_KEY)
llSay(listenChannel, (string)ring1 + ":" + (string)ringBase + ":Die");
resetRings();
// after the rings are down, tell main to go back to its normal state.
sendMessage("setState", "normal");
// set the ring base texture
llSetPrimitiveParams([PRIM_GLOW, 0, 0.0]);
}
// reset working variables to a default state.
resetRings()
{
ringBase = llGetLinkKey(llGetLinkNumber());
ring1 = NULL_KEY;
ring2 = NULL_KEY;
ring3 = NULL_KEY;
ring4 = NULL_KEY;
ring5 = NULL_KEY;
ringPos = 5;
ringHeight = 0.1;
message_list = [ "" , "" , <0,0,0>];
newPrim = "";
}
// function used to process external ring-to-ringBase communicaions
ProcessMessage(string name, key id, string message)
{
if (debug) llOwnerSay("DEBUG:" + message);
string tempName;
message_list = llParseString2List(message, [":"], [""]);
messageTO = llList2String(message_list, 0);
messageFROM = llList2String(message_list, 1);
messageCOMMAND = llList2String(message_list, 2);
if (messageTO == (string)ringBase)
// only talk to those who know our UUID
{
if (messageCOMMAND == "ringCreated" && ring5 == NULL_KEY)
{
// if we receive a message stating a ring has been created, and the last one
// hasn't been created, keep rezzing.
newPrim = "ringPrim";
llRezObject("ring",
llGetPos() + <0.0,0.0,ringHeight>,
<0.0,0.0,0.0>,
llEuler2Rot(<0,0,0>*DEG_TO_RAD),
ringPos--);
}
else if (messageCOMMAND == "ringPositioned" && ring5 != NULL_KEY)
{
// if the last ring is in position, tell main to transport
sendMessage("commenceTransport", "");
}
}
}
default
{
state_entry()
{
// set the list of internal commands that we will respond to
commandList = llGetScriptName() +
" rezRings" +
" deRezRings" +
" resetRings";
resetRings();
listen_handle = llListen(listenChannel, "", "", "");
}
link_message(integer sender_num, integer num, string command, key data)
{
if (sender_num == llGetLinkNumber())
{
// Broadcast message received from icomm
if (num == -1)
{
if (command == "SEND_LINK_CHANNEL_REQUESTS")
{
sendMessage("LINK_CHANNEL_REQUEST", (key)llGetScriptName());
}
else if (command == llGetScriptName())
{
linkChannel = (integer)((string)data);
}
else if (command == "COMMAND_LIST_QUERY")
{
if (llListFindList(llParseString2List(commandList, [" "], []), [ (string)data]) != -1)
{
llOwnerSay("Script for command '"+ (string)data + "' found. Re-initalizing comm link.");
sendMessage("LINK_CHANNEL_REQUEST", llGetScriptName());
}
}
// mains' current state was broadcasted
else if (command == "curState")
{
currentState = (string)data;
}
}
// Direct message received from icomm
else if (num == linkChannel)
{
if (command == "LIST_COMMANDS")
{
sendMessage("COMMAND_LIST", commandList);
}
else if (command == "rezRings")
{
rezRings();
}
else if (command == "deRezRings" ||
command == "resetRings")
{
deRezRings();
}
}
}
}
listen( integer channel, string name, key id, string message )
{
// only process external communications if our link to icomm is already established.
if (linkChannel != -1 && channel == listenChannel)
{
ProcessMessage(name, id, message);
}
}
object_rez(key id)
{
// need to put key storing code here for clear communications to/from child prims
if (newPrim == "ringPrim")
{
onRezRings(id);
}
newPrim = "";
}
}