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

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 5 Rev 29
Line 1... Line 1...
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // 2 // Copyright (C) Wizardry and Steamworks 2014 - License: CC BY 2.0 //
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 GNU/GPLv3 10 // you are free to use, change, and commercialize it under the CC BY 2.0
11 // license which can be found at: http://www.gnu.org/licenses/gpl.html 11 // license which can be found at: https://creativecommons.org/licenses/by/2.0
12 // 12 //
13 /////////////////////////////////////////////////////////////////////////// 13 ///////////////////////////////////////////////////////////////////////////
Line 14... Line 14...
14   14  
15 /////////////////////////////////////////////////////////////////////////// 15 ///////////////////////////////////////////////////////////////////////////
16 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // 16 // Copyright (C) 2014 Wizardry and Steamworks - License: CC BY 2.0 //
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: GNU GPLv3 // 28 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 //
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: GNU GPLv3 // 43 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 //
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: GNU GPLv3 // 74 // Copyright (C) 2014 Wizardry and Steamworks - License: CC BY 2.0 //
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: GNU GPLv3 // 94 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 //
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: GNU GPLv3 // 114 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 //
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: GNU GPLv3 // 129 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 //
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: GNU GPLv3 // 147 // Copyright (C) 2011 Wizardry and Steamworks - License: CC BY 2.0 //
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: GNU GPLv3 // 158 // Copyright (C) 2011 Wizardry and Steamworks - License: CC BY 2.0 //
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: GNU GPLv3 // 171 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
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: GNU GPLv3 // 195 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
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 = "";