nice pic of euler's identity, rendered with impressionistic dots
[feisty_meow.git] / huffware / huffotronic_scripts / logic_system_main_v1.8.txt
1 
2 // logic system master script
3 // copyright john jamison, imagilearning?
4 // created by xyz
5 // modified by fred huffhines / chris koeritz.
6 //
7 //
8
9 // defaults...
10 vector TEXT_COLOR = <0.6, 0.84, 0.8>;  // label color.
11 float RADARTIME = 10.0;  // how frequently radar fires.
12 float RANGE = 50.0;  // range of the sensor sweeps.
13 integer MAX_AVATAR_AWOLS = 5;
14     // number of times the avatar is allowed to be missed by sensor.
15     // we have seen some unreliability of sensors, so a single miss is not a definite problem.
16 list RESET = ["Restart", "CANCEL"];  // used in a menu someplace?
17 string Choicetimer = "2";  // how long they get to make their choice?
18
19 // global variables...
20 integer current_awols;
21 key user = NULL_KEY;
22 key lquery = NULL_KEY;
23 list dialog;
24 string CHOICE1;
25 string CHOICE2;
26 string CHOICE3;
27 string CHOICE4;
28 string CHOICE5;
29 string CHOICE6;
30 string CHOICE7;
31 string CHOICE8;
32 string CHOICE1TEXT;
33 string CHOICE2TEXT;
34 string CHOICE3TEXT;
35 string CHOICE4TEXT;
36 string CHOICE5TEXT;
37 string CHOICE6TEXT;
38 string CHOICE7TEXT;
39 string CHOICE8TEXT;
40 integer CHOICE1POINTS;
41 integer CHOICE2POINTS;
42 integer CHOICE3POINTS;
43 integer CHOICE4POINTS;
44 integer CHOICE5POINTS;
45 integer CHOICE6POINTS;
46 integer CHOICE7POINTS;
47 integer CHOICE8POINTS;
48 integer TotalScore;
49 string DIALOG = " ";
50 string CurrentNoteCard;
51 string resettext = " ";
52 list CHOICE;
53 integer line = 0;
54 integer eof = 0;
55 integer CHANNEL;
56
57 initialize()
58 {
59     CHOICE = [ CHOICE1TEXT, CHOICE2TEXT, CHOICE3TEXT, CHOICE4TEXT ];
60     llSetText("[System Ready]", TEXT_COLOR, 1);
61     eof = 0;
62 }
63
64 // leave the current setup and completely restart the script.
65 reboot(string reason)
66 {
67 llSay(0, "restarting now because " + reason);
68     llResetScript();
69 }
70
71 // starts looking for our registered user.
72 start_sensor_sweeps()
73 {
74     llSensorRemove();  // clear any existing sensor.
75 //llSay(0, "sweeping for " + user + " aka " + llKey2Name(user));
76     llSensorRepeat("", user, AGENT, RANGE, 2 * PI, RADARTIME);  // look for our customer.
77 }
78
79 // what this did before made no sense...
80 // but now it serves to reset the device if the avatar wandered off.
81 handle_sensor(integer numDetected)
82 {
83     integer proceed = FALSE;
84     integer i;
85     for (i = 0; i < numDetected; i++) {
86         if (llDetectedKey(i) == user) proceed = TRUE;
87     }
88     if (proceed) return;  // keep running like we were.
89     else reboot("we no longer saw our user here.");  // reboot, since we don't see our user.
90 }
91
92 // processes commands coming from other scripts or other parts of the object.
93 handle_link_message(string str, key id)
94 {
95     if (str == "user") {
96         user = id;
97         llSetText ("System in use by " + llKey2Name (id), TEXT_COLOR, 1);
98         CurrentNoteCard = llGetObjectDesc();
99         CHANNEL = llRound (llFrand (-394304));
100         llListen (CHANNEL, "", NULL_KEY, "");
101         start_sensor_sweeps();
102         lquery = llGetNotecardLine (CurrentNoteCard, line);
103     }
104 }
105
106 // handles notecard data as it is read.
107 process_incoming_data(key query_id, string data)
108 {
109     list split_data = llParseString2List (data, [":"], []);
110     string cmd = llToLower(llList2String(split_data, 0));
111
112 //hmmm: terribly repetitive code here.  clean up, shorten.
113     if (cmd == "choicetimer") {
114         Choicetimer = llList2String (split_data, 1);
115     }
116     if (cmd == "chat") {
117         llSay(0, llList2String (split_data, 1));
118         line++;
119         lquery = llGetNotecardLine (CurrentNoteCard, line);
120     }
121     if (cmd == "whisper") {
122         llWhisper(0, llList2String (split_data, 1));
123         line++;
124         lquery = llGetNotecardLine (CurrentNoteCard, line);
125     }
126     if (cmd == "givenotecard") {
127         llGiveInventory (user, llList2String (split_data, 1));
128         line++;
129         lquery = llGetNotecardLine (CurrentNoteCard, line);
130     }
131     if (cmd == "channelsay") {
132         llSay((integer) llList2String (split_data, 1), llList2String (split_data, 2));
133         line++;
134         lquery = llGetNotecardLine (CurrentNoteCard, line);
135     }
136     if (cmd == "channelshout") {
137         llShout ((integer) llList2String (split_data, 1),
138                  llList2String (split_data, 2));
139         line++;
140         lquery = llGetNotecardLine (CurrentNoteCard, line);
141     }
142     if (cmd == "channelwhisper") {
143         llSay((integer) llList2String (split_data, 1), llList2String (split_data, 2));
144         line++;
145         lquery = llGetNotecardLine (CurrentNoteCard, line);
146     }
147     if (cmd == "resettext") {
148         resettext = llList2String (split_data, 1);
149
150     }
151     if (cmd == "end") {
152 ///        CurrentNoteCard = llGetObjectDesc();
153 ///        line = 0;
154         reboot("notecard said to end processing.");
155     }
156
157     if (cmd == "giveobject") {
158         llGiveInventory (user, llList2String (split_data, 1));
159         line++;
160         lquery = llGetNotecardLine (CurrentNoteCard, line);
161     }
162 ///TALK TO VB AS THIS NEXT PART NEEDS A MEDIA RELAY FOR IT TO WORK
163     if (cmd == "videourl") {
164         if (llList2String (split_data, 3) != "") {
165             llParcelMediaCommandList ([PARCEL_MEDIA_COMMAND_URL,
166                llList2String (split_data, 1) + ":" +
167                llList2String (split_data, 2) + ":" +
168                llList2String (split_data, 3) +
169                llList2String (split_data, 4)]);
170             line++;
171             lquery = llGetNotecardLine (CurrentNoteCard, line);
172         }
173         else {
174             llParcelMediaCommandList ([PARCEL_MEDIA_COMMAND_URL,
175                 llList2String (split_data, 1) + ":" +
176                llList2String (split_data, 2)]);
177             line++;
178             lquery = llGetNotecardLine (CurrentNoteCard, line);
179         }
180         //llSay(-840,llList2String(dat,1));
181         //llSay(-848,llList2String(dat,1));
182     }
183     if (cmd == "mediatexture") {
184         llParcelMediaCommandList ([PARCEL_MEDIA_COMMAND_TEXTURE,
185                                    (key) llList2String (split_data, 1)]);
186         //llSay(-849,llList2String(dat,1));
187         line++;
188         lquery = llGetNotecardLine (CurrentNoteCard, line);
189     }
190     if (cmd == "sleep") {
191         llSleep (llList2Float (split_data, 1));
192         line++;
193         lquery = llGetNotecardLine (CurrentNoteCard, line);
194     }
195     if (cmd == "audiourl") {
196 llSay(0, "got to audio url");
197         if (llList2String (split_data, 3) != "") {
198             llSetParcelMusicURL (llList2String (split_data, 1) + ":" +
199                 llList2String (split_data, 2) + ":" +
200                 llList2String (split_data, 3) + llList2String (split_data, 4));
201             line++;
202             lquery = llGetNotecardLine (CurrentNoteCard, line);
203         }
204
205         else {
206             llSetParcelMusicURL (llList2String (split_data, 1) + ":" +
207                 llList2String (split_data, 2));
208             line++;
209             lquery = llGetNotecardLine (CurrentNoteCard, line);
210         }
211         //llSay(-840,llList2String(dat,1));
212     }
213     //THIS IS OPTION A//
214     if (cmd == "weburl") {
215         llLoadURL (user, llList2String (split_data, 1),
216                    llList2String (split_data, 2) + llList2String (split_data,
217                                                             3) +
218                    llList2String (split_data, 4));
219
220         line++;
221         lquery = llGetNotecardLine (CurrentNoteCard, line);
222     }
223
224
225     if (cmd == "dialog") {
226         DIALOG = llList2String (split_data, 1);
227         line++;
228         lquery = llGetNotecardLine (CurrentNoteCard, line);
229     }
230     if (cmd == "choice1") {
231         CHOICE1TEXT = llList2String (split_data, 1);
232         CHOICE1 = llList2String (split_data, 2);
233         dialog = dialog +[llList2String (split_data, 1)];
234
235         line++;
236         lquery = llGetNotecardLine (CurrentNoteCard, line);
237
238     }
239     if (cmd == "choice2") {
240         CHOICE2TEXT = llList2String (split_data, 1);
241         CHOICE2 = llList2String (split_data, 2);
242         dialog = dialog +[llList2String (split_data, 1)];
243         line++;
244         lquery = llGetNotecardLine (CurrentNoteCard, line);
245     }
246     if (cmd == "choice3") {
247         CHOICE3TEXT = llList2String (split_data, 1);
248         CHOICE3 = llList2String (split_data, 2);
249         dialog = dialog +[llList2String (split_data, 1)];
250         line++;
251         lquery = llGetNotecardLine (CurrentNoteCard, line);
252     }
253     if (cmd == "choice4") {
254         CHOICE4TEXT = llList2String (split_data, 1);
255         CHOICE4 = llList2String (split_data, 2);
256
257         dialog = dialog +[llList2String (split_data, 1)];
258         line++;
259         lquery = llGetNotecardLine (CurrentNoteCard, line);
260     }
261     if (cmd == "choice5") {
262         CHOICE5TEXT = llList2String (split_data, 1);
263         CHOICE5 = llList2String (split_data, 2);
264         dialog = dialog +[llList2String (split_data, 1)];
265
266         line++;
267         lquery = llGetNotecardLine (CurrentNoteCard, line);
268
269     }
270     if (cmd == "choice6") {
271         CHOICE6TEXT = llList2String (split_data, 1);
272         CHOICE6 = llList2String (split_data, 2);
273         dialog = dialog +[llList2String (split_data, 1)];
274
275         line++;
276         lquery = llGetNotecardLine (CurrentNoteCard, line);
277
278     }
279
280     if (cmd == "choice7") {
281         CHOICE7TEXT = llList2String (split_data, 1);
282         CHOICE7 = llList2String (split_data, 2);
283         dialog = dialog +[llList2String (split_data, 1)];
284
285         line++;
286         lquery = llGetNotecardLine (CurrentNoteCard, line);
287
288     }
289
290     if (cmd == "choice8") {
291         CHOICE8TEXT = llList2String (split_data, 1);
292         CHOICE8 = llList2String (split_data, 2);
293         dialog = dialog +[llList2String (split_data, 1)];
294
295         line++;
296         lquery = llGetNotecardLine (CurrentNoteCard, line);
297
298     }
299
300     if (cmd == "choice1points") {
301         CHOICE1POINTS = (integer) llList2String (split_data, 1);
302         line++;
303         lquery = llGetNotecardLine (CurrentNoteCard, line);
304
305     }
306
307     if (cmd == "choice2points") {
308         CHOICE2POINTS = (integer) llList2String (split_data, 1);
309         line++;
310         lquery = llGetNotecardLine (CurrentNoteCard, line);
311     }
312     if (cmd == "choice3points") {
313         CHOICE3POINTS = (integer) llList2String (split_data, 1);
314         line++;
315         lquery = llGetNotecardLine (CurrentNoteCard, line);
316     }
317     if (cmd == "choice4points") {
318         CHOICE4POINTS = (integer) llList2String (split_data, 1);
319         line++;
320         lquery = llGetNotecardLine (CurrentNoteCard, line);
321     }
322     if (cmd == "choice5points") {
323         CHOICE5POINTS = (integer) llList2String (split_data, 1);
324         line++;
325         lquery = llGetNotecardLine (CurrentNoteCard, line);
326     }
327     if (cmd == "choice6points") {
328         CHOICE6POINTS = (integer) llList2String (split_data, 1);
329         line++;
330         lquery = llGetNotecardLine (CurrentNoteCard, line);
331     }
332     if (cmd == "choice7points") {
333         CHOICE7POINTS = (integer) llList2String (split_data, 1);
334         line++;
335         lquery = llGetNotecardLine (CurrentNoteCard, line);
336     }
337     if (cmd == "choice8points") {
338         CHOICE8POINTS = (integer) llList2String (split_data, 1);
339         line++;
340         lquery = llGetNotecardLine (CurrentNoteCard, line);
341     }
342     if (cmd == "email") {
343         llEmail (llList2String (split_data, 1),
344                  llKey2Name (user) + " Scored " + (string) TotalScore +
345                  " On " + llGetObjectDesc (),
346                  llKey2Name (user) + " Scored " + (string) TotalScore +
347                  " On " + llGetObjectDesc () + "Score As Of " +
348                  CurrentNoteCard);
349
350         line++;
351         lquery = llGetNotecardLine (CurrentNoteCard, line);
352     }
353     if (cmd == "imuser") {
354         llInstantMessage (user, llList2String (split_data, 1));
355     }
356
357     if (cmd == "im") {
358         llInstantMessage (llList2String (split_data, 1), llList2String (split_data, 2));
359     }
360     if (cmd == "deadusertime") {
361         RADARTIME = (integer) llList2String (split_data, 1);
362     }
363
364     if (cmd == "deadrange") {
365         RANGE = (integer) llList2String (split_data, 1);
366         start_sensor_sweeps();
367     }
368
369     if (cmd == "finalscore") {
370         llSay (0,
371                "You Scored " + (string) TotalScore + "/" +
372                llList2String (split_data, 1));
373     }
374     if (cmd == "playsounduuid") {
375         llPreloadSound (llList2String (split_data, 1));
376         llPlaySound (llList2String (split_data, 1),
377                      (integer) llList2String (split_data, 2));
378     }
379
380     if (cmd == "debug") {
381         llSay (2147483647,
382                "System Debug Info follows " + "/n " +
383                (string) "key user = " + (string) user +
384                (string) " key lquery = " + (string) lquery +
385                (string) " integer DEADTIME = " + (string) RADARTIME +
386                "string CHOICE1 = " + CHOICE1 + "string CHOICE2 = " +
387                CHOICE2 + "string CHOICE3 = " + CHOICE3 +
388                "string CHOICE4 = " + CHOICE4 + "string CHOICE1TEXT = " +
389                CHOICE1TEXT + "string CHOICE2TEXT = " + CHOICE2TEXT +
390                "string CHOICE3TEXT= " + CHOICE3TEXT +
391                "string CHOICE4TEXT= " + CHOICE4TEXT +
392                "integer CHOICE1POINTS" + (string) CHOICE1POINTS +
393                "integer CHOICE2POINTS" + (string) CHOICE2POINTS +
394                "integer CHOICE3POINTS" + (string) CHOICE3POINTS +
395                "integer CHOICE4POINTS" + (string) CHOICE4POINTS +
396                "integer Choicetimer = " + (string) Choicetimer +
397                "integer TotalScore =" + (string) TotalScore +
398                "string DIOALOGE = " + DIALOG +
399                "string CurrentNoteCard = " + CurrentNoteCard +
400                "string resettext = " + resettext +
401                "list RESET = [Restart,CANCEL]" + "list CHOICE = " +
402                (string) CHOICE + "integer line = " + (string) line);
403
404     }
405
406     if (data == EOF) {
407         if (eof != 2 | eof == 1) {
408             eof = 2;
409             llSetTimerEvent ((float) Choicetimer);
410         }
411     } else {
412         line++;
413         lquery = llGetNotecardLine (CurrentNoteCard, line);
414     }
415 }
416
417 // process what the device hears spoken nearby.
418 hear_voices(integer channel, string name, key id, string message)
419 {
420 //hmmm: bunkum.  do this as a list.
421     if (message == CHOICE1TEXT) {
422         CurrentNoteCard = CHOICE1;
423         dialog =[];
424         eof = 0;
425         line = 0;
426         TotalScore = TotalScore + CHOICE1POINTS;
427         lquery = llGetNotecardLine (CurrentNoteCard, line);
428     }
429     if (message == CHOICE2TEXT) {
430         CurrentNoteCard = CHOICE2;
431         dialog =[];
432         eof = 0;
433         line = 0;
434         TotalScore = TotalScore + CHOICE2POINTS;
435         lquery = llGetNotecardLine (CurrentNoteCard, line);
436     }
437     if (message == CHOICE3TEXT) {
438         CurrentNoteCard = CHOICE3;
439         dialog =[];
440         eof = 0;
441         line = 0;
442         TotalScore = TotalScore + CHOICE3POINTS;
443         lquery = llGetNotecardLine (CurrentNoteCard, line);
444     }
445     if (message == CHOICE4TEXT) {
446         CurrentNoteCard = CHOICE4;
447         dialog =[];
448         eof = 0;
449         line = 0;
450         TotalScore = TotalScore + CHOICE4POINTS;
451         lquery = llGetNotecardLine (CurrentNoteCard, line);
452     }
453     if (message == CHOICE5TEXT) {
454         CurrentNoteCard = CHOICE5;
455         dialog =[];
456         eof = 0;
457         line = 0;
458         TotalScore = TotalScore + CHOICE5POINTS;
459         lquery = llGetNotecardLine (CurrentNoteCard, line);
460     }
461     if (message == CHOICE6TEXT) {
462         CurrentNoteCard = CHOICE6;
463         dialog =[];
464         eof = 0;
465         line = 0;
466         TotalScore = TotalScore + CHOICE6POINTS;
467         lquery = llGetNotecardLine (CurrentNoteCard, line);
468     }
469     if (message == CHOICE7TEXT) {
470         CurrentNoteCard = CHOICE7;
471         dialog =[];
472         eof = 0;
473         line = 0;
474         TotalScore = TotalScore + CHOICE7POINTS;
475         lquery = llGetNotecardLine (CurrentNoteCard, line);
476     }
477     if (message == CHOICE8TEXT) {
478         CurrentNoteCard = CHOICE8;
479         dialog =[];
480         eof = 0;
481         line = 0;
482         TotalScore = TotalScore + CHOICE8POINTS;
483         lquery = llGetNotecardLine (CurrentNoteCard, line);
484     }
485     if (message == "Restart") {
486         eof = 0;
487         line = 0;
488         lquery = llGetNotecardLine (CurrentNoteCard, line);
489     }
490 }
491
492 //////////////
493
494 // ensure stops running if kept in updater object.
495 default
496 {
497     state_entry() { if (llSubStringIndex(llGetObjectName(),  "huffotronic") < 0) state real_default; }
498     on_rez(integer parm) { state rerun; }
499 }
500 state rerun { state_entry() { state default; } }
501
502 // main state engine.
503 state real_default
504 {
505     state_entry () {
506         initialize();
507     }
508
509     on_rez (integer i) {
510         reboot("object just rezzed.");
511     }
512
513     no_sensor () {
514         current_awols++;
515 //llSay(0, "sensor missed avatar.");
516         if (current_awols > MAX_AVATAR_AWOLS) {
517             reboot("avatar was missed by sensor sweep too many times.");
518         }
519     }
520
521     sensor (integer numDetected) {
522         current_awols = 0;
523 //llSay(0, "sensor saw avatar.");
524         handle_sensor(numDetected);
525     }
526
527     link_message (integer sender_num, integer num, string str, key id) {
528         handle_link_message(str, id);
529     }
530
531     touch_start (integer total_number) {
532         integer i;
533         for (i = 0; i < total_number; i++) {
534             if (llDetectedKey(i) == user) {
535                 llDialog (user, resettext, RESET, CHANNEL);
536                 return;
537             }
538         }
539     }
540
541     listen (integer channel, string name, key id, string message) {
542         hear_voices(channel, name, id, message);
543     }
544
545     dataserver (key query_id, string data) {
546         process_incoming_data(query_id, data);
547     }
548
549     collision_start(integer total_number)
550     {
551         if (user == NULL_KEY) {
552 //llSay(0, "sending startup link message.");
553             handle_link_message("user", llDetectedKey(0));
554         }
555     }
556
557     timer () {
558         llDialog (user, DIALOG, dialog, CHANNEL);
559         llSetTimerEvent (0);
560     }
561 }