corrade-lsl-templates – Diff between revs 29 and 37

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 29 Rev 37
Line 1... Line 1...
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2014 - License: CC BY 2.0 // 2 // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 //
3 /////////////////////////////////////////////////////////////////////////// 3 ///////////////////////////////////////////////////////////////////////////
4 // 4 //
5 // This is an automatic teleporter, and patrol script for the Corrade 5 // This is an automatic teleporter, and patrol script for the Corrade
6 // Second Life / OpenSim bot. You can find more details about the bot 6 // Second Life / OpenSim bot. You can find more details about the bot
7 // by following the URL: http://was.fm/secondlife/scripted_agents/corrade 7 // by following the URL: http://was.fm/secondlife/scripted_agents/corrade
8 // 8 //
9 // The purpose of this script is to demonstrate patroling with Corrade and 9 // The purpose of this script is to demonstrate patroling with Corrade and
10 // you are free to use, change, and commercialize it under the CC BY 2.0 10 // you are free to use, change, and commercialize it under the GNU/GPLv3
11 // license which can be found at: https://creativecommons.org/licenses/by/2.0 11 // license which can be found at: http://www.gnu.org/licenses/gpl.html
12 // 12 //
13 /////////////////////////////////////////////////////////////////////////// 13 ///////////////////////////////////////////////////////////////////////////
Line 14... Line 14...
14   14  
15 /////////////////////////////////////////////////////////////////////////// 15 ///////////////////////////////////////////////////////////////////////////
16 // Copyright (C) 2014 Wizardry and Steamworks - License: CC BY 2.0 // 16 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
17 /////////////////////////////////////////////////////////////////////////// 17 ///////////////////////////////////////////////////////////////////////////
18 string wasKeyValueGet(string k, string data) { 18 string wasKeyValueGet(string k, string data) {
19 if(llStringLength(data) == 0) return ""; 19 if(llStringLength(data) == 0) return "";
20 if(llStringLength(k) == 0) return ""; 20 if(llStringLength(k) == 0) return "";
Line 23... Line 23...
23 if(i != -1) return llList2String(a, i+1); 23 if(i != -1) return llList2String(a, i+1);
24 return ""; 24 return "";
25 } 25 }
Line 26... Line 26...
26 26
27 /////////////////////////////////////////////////////////////////////////// 27 ///////////////////////////////////////////////////////////////////////////
28 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // 28 // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
29 /////////////////////////////////////////////////////////////////////////// 29 ///////////////////////////////////////////////////////////////////////////
30 string wasKeyValueEncode(list data) { 30 string wasKeyValueEncode(list data) {
31 list k = llList2ListStrided(data, 0, -1, 2); 31 list k = llList2ListStrided(data, 0, -1, 2);
32 list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2); 32 list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2);
Line 38... Line 38...
38 } while(llGetListLength(k) != 0); 38 } while(llGetListLength(k) != 0);
39 return llDumpList2String(data, "&"); 39 return llDumpList2String(data, "&");
40 } 40 }
Line 41... Line 41...
41   41  
42 /////////////////////////////////////////////////////////////////////////// 42 ///////////////////////////////////////////////////////////////////////////
43 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // 43 // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
44 /////////////////////////////////////////////////////////////////////////// 44 ///////////////////////////////////////////////////////////////////////////
45 list wasDualQuicksort(list a, list b) { 45 list wasDualQuicksort(list a, list b) {
Line 46... Line 46...
46 if(llGetListLength(a) <= 1) return a+b; 46 if(llGetListLength(a) <= 1) return a+b;
Line 69... Line 69...
69 } while(llGetListLength(a)); 69 } while(llGetListLength(a));
70 return wasDualQuicksort(less, less_b) + [ pivot_a ] + [ pivot_b ] + wasDualQuicksort(more, more_b); 70 return wasDualQuicksort(less, less_b) + [ pivot_a ] + [ pivot_b ] + wasDualQuicksort(more, more_b);
71 } 71 }
Line 72... Line 72...
72 72
73 /////////////////////////////////////////////////////////////////////////// 73 ///////////////////////////////////////////////////////////////////////////
74 // Copyright (C) 2014 Wizardry and Steamworks - License: CC BY 2.0 // 74 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
75 /////////////////////////////////////////////////////////////////////////// 75 ///////////////////////////////////////////////////////////////////////////
76 // determines whether the segment AB intersects the segment CD 76 // determines whether the segment AB intersects the segment CD
77 integer wasSegmentIntersect(vector A, vector B, vector C, vector D) { 77 integer wasSegmentIntersect(vector A, vector B, vector C, vector D) {
78 vector s1 = <B.x - A.x, B.y - A.y, B.z - A.z>; 78 vector s1 = <B.x - A.x, B.y - A.y, B.z - A.z>;
Line 89... Line 89...
89 return (integer)(s >= 0 && s <= 1 && t >= 0 && t <= 1 && 89 return (integer)(s >= 0 && s <= 1 && t >= 0 && t <= 1 &&
90 A.z + t*(B.z - A.z) == C.z + s*(D.z - C.z)); 90 A.z + t*(B.z - A.z) == C.z + s*(D.z - C.z));
91 } 91 }
Line 92... Line 92...
92 92
93 /////////////////////////////////////////////////////////////////////////// 93 ///////////////////////////////////////////////////////////////////////////
94 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // 94 // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
95 // www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html // 95 // www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html //
96 /////////////////////////////////////////////////////////////////////////// 96 ///////////////////////////////////////////////////////////////////////////
97 integer wasPointInPolygon(vector p, list polygon) { 97 integer wasPointInPolygon(vector p, list polygon) {
98 integer inside = FALSE; 98 integer inside = FALSE;
Line 109... Line 109...
109 } while(i<nvert); 109 } while(i<nvert);
110 return inside; 110 return inside;
111 } 111 }
Line 112... Line 112...
112 112
113 /////////////////////////////////////////////////////////////////////////// 113 ///////////////////////////////////////////////////////////////////////////
114 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // 114 // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
115 // www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html // 115 // www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html //
116 /////////////////////////////////////////////////////////////////////////// 116 ///////////////////////////////////////////////////////////////////////////
117 list wasPointToPolygon(list polygon, vector point) { 117 list wasPointToPolygon(list polygon, vector point) {
118 integer i = llGetListLength(polygon)-1; 118 integer i = llGetListLength(polygon)-1;
Line 124... Line 124...
124 return [llList2Float(l, 0), llList2Vector(l, 1)]; 124 return [llList2Float(l, 0), llList2Vector(l, 1)];
Line 125... Line 125...
125 125
Line 126... Line 126...
126 } 126 }
127 127
128 /////////////////////////////////////////////////////////////////////////// 128 ///////////////////////////////////////////////////////////////////////////
129 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // 129 // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
130 // www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html // 130 // www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html //
131 /////////////////////////////////////////////////////////////////////////// 131 ///////////////////////////////////////////////////////////////////////////
132 vector wasPolygonCentroid(list polygon, vector start, float tollerance, integer power) { 132 vector wasPolygonCentroid(list polygon, vector start, float tollerance, integer power) {
Line 142... Line 142...
142 if(llVecMag(start-next) < tollerance) return next; 142 if(llVecMag(start-next) < tollerance) return next;
143 return wasPolygonCentroid(polygon, next, tollerance, power*power); 143 return wasPolygonCentroid(polygon, next, tollerance, power*power);
144 } 144 }
Line 145... Line 145...
145 145
146 /////////////////////////////////////////////////////////////////////////// 146 ///////////////////////////////////////////////////////////////////////////
147 // Copyright (C) 2011 Wizardry and Steamworks - License: CC BY 2.0 // 147 // Copyright (C) 2011 Wizardry and Steamworks - License: GNU GPLv3 //
148 /////////////////////////////////////////////////////////////////////////// 148 ///////////////////////////////////////////////////////////////////////////
149 vector wasCirclePoint(float radius) { 149 vector wasCirclePoint(float radius) {
150 float x = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2); 150 float x = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2);
151 float y = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2); 151 float y = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2);
152 if(llPow(x,2) + llPow(y,2) <= llPow(radius,2)) 152 if(llPow(x,2) + llPow(y,2) <= llPow(radius,2))
153 return <x, y, 0>; 153 return <x, y, 0>;
154 return wasCirclePoint(radius); 154 return wasCirclePoint(radius);
Line 155... Line 155...
155 } 155 }
156 156
157 /////////////////////////////////////////////////////////////////////////// 157 ///////////////////////////////////////////////////////////////////////////
158 // Copyright (C) 2011 Wizardry and Steamworks - License: CC BY 2.0 // 158 // Copyright (C) 2011 Wizardry and Steamworks - License: GNU GPLv3 //
159 /////////////////////////////////////////////////////////////////////////// 159 ///////////////////////////////////////////////////////////////////////////
160 vector wasPolygonPoint(list polygon) { 160 vector wasPolygonPoint(list polygon) {
161 vector c = wasPolygonCentroid(polygon, llList2Vector(polygon, 0), 0.05, 2); 161 vector c = wasPolygonCentroid(polygon, llList2Vector(polygon, 0), 0.05, 2);
Line 166... Line 166...
166 } while(wasPointInPolygon(d, polygon) == FALSE); 166 } while(wasPointInPolygon(d, polygon) == FALSE);
167 return d; 167 return d;
168 } 168 }
Line 169... Line 169...
169 169
170 /////////////////////////////////////////////////////////////////////////// 170 ///////////////////////////////////////////////////////////////////////////
171 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 171 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
172 /////////////////////////////////////////////////////////////////////////// 172 ///////////////////////////////////////////////////////////////////////////
173 // determines whether the path between the current positon m and the 173 // determines whether the path between the current positon m and the
174 // computed next position d will intersect any two sides of the polygon 174 // computed next position d will intersect any two sides of the polygon
175 vector wasPolygonPath(vector m, list polygon) { 175 vector wasPolygonPath(vector m, list polygon) {
Line 190... Line 190...
190 if(i > 1) return wasPolygonPath(m, polygon); 190 if(i > 1) return wasPolygonPath(m, polygon);
191 return d; 191 return d;
192 } 192 }
Line 193... Line 193...
193   193  
194 /////////////////////////////////////////////////////////////////////////// 194 ///////////////////////////////////////////////////////////////////////////
195 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 195 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
196 /////////////////////////////////////////////////////////////////////////// 196 ///////////////////////////////////////////////////////////////////////////
197 // escapes a string in conformance with RFC1738 197 // escapes a string in conformance with RFC1738
198 string wasURLEscape(string i) { 198 string wasURLEscape(string i) {
199 string o = ""; 199 string o = "";
Line 503... Line 503...
503 llOwnerSay("Corrade is not online, sleeping..."); 503 llOwnerSay("Corrade is not online, sleeping...");
504 llResetScript(); 504 llResetScript();
505 return; 505 return;
506 } 506 }
507 // DEBUG 507 // DEBUG
508 //llOwnerSay("Sending stop..."); -  
509 llInstantMessage(CORRADE, -  
510 wasKeyValueEncode( -  
511 [ -  
512 "command", "autopilot", -  
513 "group", wasURLEscape(GROUP), -  
514 "password", wasURLEscape(PASSWORD), -  
515 "action", "stop", -  
516 "callback", wasURLEscape(callback) -  
517 ] -  
518 ) -  
519 ); -  
520 } -  
521 http_request(key id, string method, string body) { -  
522 llHTTPResponse(id, 200, "OK"); -  
523 if(wasKeyValueGet("command", body) != "autopilot" || -  
524 wasKeyValueGet("success", body) != "True") { -  
525 // DEBUG -  
526 llOwnerSay("Could not get Corrade to stop, restarting script..."); -  
527 llResetScript(); -  
528 } -  
529 // DEBUG -  
530 llOwnerSay("Sending next move..."); 508 llOwnerSay("Sending next move...");
531 // get the next location 509 // get the next location
532 location = wasPolygonPath(location, POLYGON); 510 location = wasPolygonPath(location, POLYGON);
533 vector pos = llGetPos(); 511 vector pos = llGetPos();
534 llInstantMessage(CORRADE, 512 llInstantMessage(CORRADE,
535 wasKeyValueEncode( 513 wasKeyValueEncode(
536 [ 514 [
537 "command", "autopilot", 515 "command", "walkto",
538 "group", wasURLEscape(GROUP), 516 "group", wasURLEscape(GROUP),
539 "password", wasURLEscape(PASSWORD), 517 "password", wasURLEscape(PASSWORD),
540 "position", wasURLEscape( 518 "position", wasURLEscape(
541 (string)(<location.x, location.y, pos.z>) 519 (string)(<location.x, location.y, pos.z>)
542 ), 520 ),
-   521 "vicinity", "1",
543 "action", "start" 522 "duration", "2500"
544 ] 523 ]
545 ) 524 )
546 ); 525 );
547 llSetTimerEvent(1 + llFrand(WAIT)); 526 llSetTimerEvent(1 + llFrand(WAIT));
548 } 527 }