dd18ac3cc5887f416660eb09682674f62d36cd2e
[feisty_meow.git] / huffware / huffotronic_scripts / minnow_v10.6.txt
1 
2 // huffware script: minnow, modifications by fred huffhines.
3 //
4 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
5 // do not use it in objects without fully realizing you are implicitly accepting that license.
6 //
7 // original attributions:
8 //   Fixit Galatea generic boat script
9 //   This script uses the basic direction keys for boat operation and requires
10 //   the final prim to be oriented at rotation <0, 0, 0>.
11
12 //****************************************************************************
13 //****************************************************************************
14 //****************************************************************************
15 //* The following items can be edited in this script. See the comment for each
16 //* item to see how it work when it is changed.
17 //****************************************************************************
18
19 //* When the forward key is pressed and the mouse button is pressed at the
20 //* same time, this speed is used. This number should be between 0.0 and 30.0,
21 //* with higher numbers giving faster performance.
22 float fastspeed = 16.0;
23
24 //* When the forward key is pressed and the mouse button is NOT pressed, this
25 //* speed is used. This number should be between 0.0 and whatever the
26 //* fastspeed value was set at, with higher numbers giving faster performance.
27 float slowspeed = 8.0;
28
29 //* This is the reverse speed. It shouldn't be too fast, but can be between
30 //* 0.0 and 30.0.
31 float backspeed = 2.0;
32
33 //* This is the vehicle 'hover' height, or how far it sits out of the water.
34 //* Adjust this as necessary for your boat.
35 float floatheight = 0.44;
36
37 //* If the boat is to ramp up speed slowly, set the following value to '1'.
38 //* Otherwise, the board will instantly reach full speed when the forward
39 //* key is pressed.
40 integer fastforward = 0;  // NOT IMPLEMENTED YET
41
42 //* Turning speed, a small turning speed is best
43 float turnspeed = 1.5;
44
45 //* If the boat 'angles' into turns, set the following value to '1'.
46 //* Otherwise, the boat will do flat turns.
47 integer angledturn = 1;   // NOT IMPLEMENTED YET
48
49 //* Height offset of seat
50 //vector seatheight = <.2, 0, 0.35>;
51
52 vector camera_lives_at = <-7, 0, 3>;
53     // where the camera is poised when the avatar is seated.
54
55 vector camera_looks_at = <4, 0, 1>;
56
57 //****************************************************************************
58 //****************************************************************************
59 //****************************************************************************
60
61 // Initialize the vehicle as a boat
62 vehicle_init()
63 {
64     llSetVehicleType(VEHICLE_TYPE_BOAT);
65
66     // least for forward-back, most friction for up-down
67     llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <10, 1, 3>);
68
69     // uniform angular friction (setting it as a scalar rather than a vector)
70     llSetVehicleFloatParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, 0.1);
71
72     // linear motor wins after about five seconds, decays after about a minute
73     llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0, 0, 0>);
74     llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.1);
75     llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 0.05);
76
77     // agular motor wins after four seconds, decays in same amount of time
78     llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <0, 0, 0>);
79     llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.1);
80     llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.2);
81
82     // hover 
83     llSetVehicleFloatParam(VEHICLE_HOVER_HEIGHT, floatheight);
84     llSetVehicleFloatParam(VEHICLE_HOVER_EFFICIENCY, 0.2);
85     llSetVehicleFloatParam(VEHICLE_HOVER_TIMESCALE, 0.4);
86     llSetVehicleFloatParam(VEHICLE_BUOYANCY, 1.0);
87
88     // Slight linear deflection with timescale of 1 seconds
89     llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.1);
90     llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 1);
91
92     // Slight angular deflection 
93     llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.1);
94     llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 6);
95
96     // somewhat bounscy vertical attractor 
97     llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.5);
98     llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 1);
99
100     // weak negative damped banking
101     llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, 1.0);
102     llSetVehicleFloatParam(VEHICLE_BANKING_MIX, 1.0);
103     llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 0.1);
104
105     // default rotation of local frame
106     llSetVehicleRotationParam(VEHICLE_REFERENCE_FRAME,
107         llEuler2Rot(<0, 0, 0>));
108
109     // remove these flags.
110 //disabled due to opensim problems running this call.
111 //    llRemoveVehicleFlags(VEHICLE_FLAG_HOVER_TERRAIN_ONLY 
112 //                         | VEHICLE_FLAG_LIMIT_ROLL_ONLY
113 //                         | VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT);
114
115     // set these flags 
116 //    llSetVehicleFlags(VEHICLE_FLAG_NO_DEFLECTION_UP 
117 //                      | VEHICLE_FLAG_HOVER_WATER_ONLY 
118 //                      | VEHICLE_FLAG_HOVER_UP_ONLY 
119 //                      | VEHICLE_FLAG_LIMIT_MOTOR_UP);
120 }
121
122 // Setup everything
123 all_setup()
124 {
125     // Display version number
126     llWhisper(0, "running script " + llGetScriptName());
127     llSetStatus(STATUS_PHYSICS, FALSE);
128
129     // Set sit direction (forward) and sight location slightly up and behind
130 //    llSitTarget(seatheight, llEuler2Rot(<0, 0, 0>));
131     llSetCameraAtOffset(camera_looks_at);
132     llSetCameraEyeOffset(camera_lives_at);
133     llSetSitText("Pilot");
134
135     // Initialize vehicle states
136     vehicle_init();
137
138     // Set up listener callback function
139     llListen(0, "", llGetOwner(), "");
140 }
141
142 //////////////
143 // huffware script: auto-retire, by fred huffhines, version 2.5.
144 // distributed under BSD-like license.
145 //   !!  keep in mind that this code must be *copied* into another
146 //   !!  script that you wish to add auto-retirement capability to.
147 // when a script has auto_retire in it, it can be dropped into an
148 // object and the most recent version of the script will destroy
149 // all older versions.
150 //
151 // the version numbers are embedded into the script names themselves.
152 // the notation for versions uses a letter 'v', followed by two numbers
153 // in the form "major.minor".
154 // major and minor versions are implicitly considered as a floating point
155 // number that increases with each newer version of the script.  thus,
156 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
157 // and "hazmap v3.2" is a more recent version.
158 //
159 // example usage of the auto-retirement script:
160 //     default {
161 //         state_entry() {
162 //            auto_retire();  // make sure newest addition is only version of script.
163 //        }
164 //     }
165 // this script is partly based on the self-upgrading scripts from markov brodsky
166 // and jippen faddoul.
167 //////////////
168 auto_retire() {
169     string self = llGetScriptName();  // the name of this script.
170     list split = compute_basename_and_version(self);
171     if (llGetListLength(split) != 2) return;  // nothing to do for this script.
172     string basename = llList2String(split, 0);  // script name with no version attached.
173     string version_string = llList2String(split, 1);  // the version found.
174     integer posn;
175     // find any scripts that match the basename.  they are variants of this script.
176     for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
177 //log_it("invpo=" + (string)posn);
178         string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
179         if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
180             // found a basic match at least.
181             list inv_split = compute_basename_and_version(curr_script);
182             if (llGetListLength(inv_split) == 2) {
183                 // see if this script is more ancient.
184                 string inv_version_string = llList2String(inv_split, 1);  // the version found.
185                 // must make sure that the retiring script is completely the identical basename;
186                 // just matching in the front doesn't make it a relative.
187                 if ( (llList2String(inv_split, 0) == basename)
188                     && ((float)inv_version_string < (float)version_string) ) {
189                     // remove script with same name from inventory that has inferior version.
190                     llRemoveInventory(curr_script);
191                 }
192             }
193         }
194     }
195 }
196 //
197 // separates the base script name and version number.  used by auto_retire.
198 list compute_basename_and_version(string to_chop_up)
199 {
200     // minimum script name is 2 characters plus a version.
201     integer space_v_posn;
202     // find the last useful space and 'v' combo.
203     for (space_v_posn = llStringLength(to_chop_up) - 3;
204         (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
205         space_v_posn--) {
206         // look for space and v but do nothing else.
207 //log_it("pos=" + (string)space_v_posn);
208     }
209     if (space_v_posn < 2) return [];  // no space found.
210 //log_it("space v@" + (string)space_v_posn);
211     // now we zoom through the stuff after our beloved v character and find any evil
212     // space characters, which are most likely from SL having found a duplicate item
213     // name and not so helpfully renamed it for us.
214     integer indy;
215     for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
216 //log_it("indy=" + (string)space_v_posn);
217         if (llGetSubString(to_chop_up, indy, indy) == " ") {
218             // found one; zap it.  since we're going backwards we don't need to
219             // adjust the loop at all.
220             to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
221 //log_it("saw case of previously redundant item, aieee.  flattened: " + to_chop_up);
222         }
223     }
224     string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
225     // ditch the space character for our numerical check.
226     string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
227     // strip out a 'v' if there is one.
228     if (llGetSubString(chop_suffix, 0, 0) == "v")
229         chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
230     // if valid floating point number and greater than zero, that works for our version.
231     string basename = to_chop_up;  // script name with no version attached.
232     if ((float)chop_suffix > 0.0) {
233         // this is a big success right here.
234         basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
235         return [ basename, chop_suffix ];
236     }
237     // seems like we found nothing useful.
238     return [];
239 }
240 //
241 //////////////
242
243 // State (default) event handlers
244 default
245 {
246     state_entry() { if (llSubStringIndex(llGetObjectName(),  "huffotronic") < 0) state real_default; }
247     on_rez(integer parm) { state rerun; }
248 }
249 state rerun { state_entry() { state default; } }
250
251 state real_default
252 {
253     state_entry()
254     {
255         auto_retire();
256         all_setup();
257     }
258
259     on_rez(integer start_param)
260     {
261         llSetStatus(STATUS_PHYSICS, FALSE);
262     }
263
264      run_time_permissions(integer permissions)
265     {
266         // Get user permissions
267         if ((permissions & PERMISSION_TAKE_CONTROLS) ==
268             PERMISSION_TAKE_CONTROLS)
269         {
270             llTakeControls(CONTROL_ML_LBUTTON | CONTROL_FWD |
271                 CONTROL_BACK | CONTROL_LEFT | CONTROL_RIGHT |
272                 CONTROL_ROT_LEFT | CONTROL_ROT_RIGHT, TRUE, FALSE);
273         }
274     }
275
276     changed(integer change)
277     {
278         if (change & CHANGED_LINK)
279         {
280             key agent = llAvatarOnSitTarget();
281             if (agent)
282             {
283                 if (agent != llGetOwner())
284                 {
285                     llSay(0, "This boat isn't yours, but you can buy a copy!");
286                     llUnSit(agent);
287                 }
288                 else
289                 {
290                     llRequestPermissions(agent, PERMISSION_TAKE_CONTROLS);
291                     llSetStatus(STATUS_PHYSICS, TRUE);
292                 }
293             }
294             else
295             {
296                 llReleaseControls();
297                 llSetStatus(STATUS_PHYSICS, FALSE);
298             }
299         }
300     }
301
302     control(key name, integer levels, integer edges) 
303     {
304         float side = 0.0;
305         float forw = 0.0;
306         float move = 0.0;
307         float turn;
308
309         if (levels & CONTROL_ML_LBUTTON)
310         {
311             move = fastspeed;
312             turn = 1.5 * turnspeed;
313 //            forw = 2 * PI / 3;
314         }
315         else if (levels & CONTROL_FWD)
316         {
317             move = slowspeed;
318             turn = 1.0 * turnspeed;
319 //            forw = PI / 2;
320         }
321         else if (levels & CONTROL_BACK)
322         {
323             move = -backspeed;
324 //            forw = -PI / 3;
325 //            turn = -1.0 * turnspeed;
326         }
327
328         if (levels & (CONTROL_LEFT | CONTROL_ROT_LEFT))
329         {
330             if (move == fastspeed)
331             {
332                 side = turnspeed;
333 //                forw = PI;
334             }
335             else if (move != 0)
336             {
337                 side = turnspeed;
338 //                forw = PI / 3;
339             }
340             else
341             {
342                 side = .67 * turnspeed;
343 //                forw = PI / 4;
344                 move = 0.1;
345             }
346         }
347         else if (levels & (CONTROL_RIGHT | CONTROL_ROT_RIGHT))
348         {
349             if (move == fastspeed)
350             {
351                 side = -turnspeed;
352 //                forw = PI;
353             }
354             else if (move != 0)
355             {
356                 side = -turnspeed;
357 //                forw = PI / 3;
358             }
359             else
360             {
361                 side = -.67 * turnspeed;
362 //                forw = PI / 4;
363                 move = 0.1;
364             }
365         }
366
367         if (move == 0)
368         {
369             llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0, 0, 0>);
370         }
371         else
372         {
373             llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION,
374                   <move, 0, 0>);
375             llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION,
376                 <-side / 5, 0, side>);
377         }
378     }
379
380     listen(integer channel, string name, key id, string message)
381     {
382         list params = llParseString2List(message, [" "], [":"]);
383         string cmd = llList2String(params, 0);
384         integer enable = llList2Integer(params, 1);
385
386         // Commands
387         ;
388     }
389
390     touch_start(integer total_number)
391     {
392         key id = llDetectedOwner(total_number - 1);
393        // llGiveInventory(id, "Info card");
394     }
395 }