76465b72a316281bcec3aa84f91cbc7ee58422df
[feisty_meow.git] / huffware / huffotronic_scripts / child_jaunter_v85.2.txt
1 
2 // huffware script: child jaunter, by fred huffhines,  released under GPL license.
3 //
4 // this is the sub-jaunter implementation, for children of a root jaunter.  this script
5 // handles reconnaissance and one-way trips.
6 //
7 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
8 // do not use it in objects without fully realizing you are implicitly accepting that license.
9 //
10
11 //////////////
12
13 // configurable constants...
14
15 string TEXT_COLOR = "<0.5, 0.7, 0.95>";
16     // set float text color to a nice color.
17
18 integer DEBUGGING = FALSE;
19     // set to true to get debugging noises.
20
21 // requires jaunting library API.
22 //////////////
23 // do not redefine these constants.
24 integer JAUNT_HUFFWARE_ID = 10008;
25     // the unique id within the huffware system for the jaunt script to
26     // accept commands on.  this is used in llMessageLinked as the num parameter.
27 string HUFFWARE_PARM_SEPARATOR = "{~~~}";
28     // this pattern is an uncommon thing to see in text, so we use it to separate
29     // our commands in link messages.
30 string HUFFWARE_ITEM_SEPARATOR = "{|||}";
31     // used to separate lists of items from each other when stored inside a parameter.
32     // this allows lists to be passed as single string parameters if needed.
33 integer REPLY_DISTANCE = 100008;  // offset added to service's huffware id in reply IDs.
34 //////////////
35 // commands available via the jaunting library:
36 string FULL_STOP_COMMAND = "#fullstop#";
37     // command used to bring object to a halt.
38 string JAUNT_LIST_COMMAND = "#jauntlist#";
39     // like regular jaunt, but expects a string in jaunt notecard format with vectors.
40     // the second parameter, if any, should be 1 for forwards traversal and 0 for backwards.
41 //
42 //////////////
43
44 // the API for this library script to be used in other scripts.
45 //////////////
46 // do not redefine these constants.
47 integer JAUNT_REZOLATOR_HUFFWARE_ID = 10025;
48     // the unique id within the huffware system for this script's commands.
49     // it's used in llMessageLinked as the num parameter.
50 //////////////
51 // commands available from the library:
52 string RESET_REZOLATOR = "#reset";
53     // tells the script to stop any previous efforts to rez children.
54 //string REZ_CHILD_NOW = "#rezkd#";
55     // requests this script to create a new child object.  this requires several
56     // parameters to succeed: 1) object to rez, 2) conveyance mode for the rezzed object
57     // to implement, 3) the chat channel to listen for and speak to new child on,
58     // 4) the destination name for where the child should go, 5) a count of the full
59     // set of known destinations, 6) the target where the jaunt should arrive at.
60 string REPORT_CHILD_REZZED = "#reziam";
61     // requests that this class report to the root jaunter that a child has rezzed and
62     // is ready for service.  there are no required parameters.
63 string REZOLATOR_CHILD_SUPPORT = "#rzsup";
64     // used by child jaunters to request that the rezolator handle things for them.
65 string REZOLATOR_CHILD_RETURNED = "#rezdon";
66     // used by the child jaunter to tell the rezolator that it has jumped to wherever it
67     // was supposed to and is ready to report to the parent, if needed.  the first parameter
68     // required for the rezolator is whether the jump was successful (1) or not (0), and
69     // the second parameter should be the last safe position that the jaunter was at when
70     // it was possibly closest to the target.
71 //////////////
72 // events generated by the library:
73 //string REZOLATOR_EVENT_REZZED_CHILD = "#donekd";
74     // an event generated for a previous rez child request.  this lets the caller know that
75     // the child has been created and told what to do.  the single parameter is where the
76     // jaunter has been rezzed.
77 string REZOLATOR_EVENT_GOT_INSTRUCTIONS = "#rzsta";
78     // the root jaunter has given a child instructions on where to go.  this info includes
79     // the name of the destination, the pathway to get there, and the conveyance mode.
80 //string REZOLATOR_EVENT_RECON_FINISHED = "#rzcnfn";
81     // an event generated when the recon process has concluded.  this includes parms:
82     // number of good destinations.
83 //
84 //////////////
85
86 // important constants used internally...  these should not be changed willy nilly.
87
88 ////////////// jaunt base API
89
90 // the following constants define how the script should behave (i.e., its conveyance mode).
91 // TWO_WAY_TRIP: the script jaunts using the current target vectors to get somewhere
92 //   and then takes the same pathway back, but in reverse order.
93 // AUTOREZ_JAUNTER: the script rezzes the first regular object in its inventory next to
94 //   the root telehub.  that object is loaded with the destination notecard and this script.
95 //   the rezzed object can then be used for the next few minutes to jaunt to the selected
96 //   destination.  the temporary object will use the ONE_WAY_TRIP mode.
97 // ONE_WAY_TRIP: the object containing this script will take the user to a particular
98 //   destination, but the object does not survive the trip.  it self-destructs after
99 //   reaching the destination.  this mode is used in conjunction with the AUTOREZ_JAUNTER
100 //   mode and should generally never be used on its own.
101 // RECONNAISSANCE_TRIP: a survey run to test out a particular path to get to a
102 //   destination.
103 integer TWO_WAY_TRIP = 1;
104 integer AUTOREZ_JAUNTER = 2;
105 integer ONE_WAY_TRIP = 3;
106 integer RECONNAISSANCE_TRIP = 4;
107
108 // values used to represent different stages of verification.
109 integer VERIFY_UNTESTED = -3;  // don't know destinations tate yet.
110 integer VERIFY_SAFE = -4;  // the destination last tested safe.
111 integer VERIFY_UNSAFE_SO_FAR = -5;  // this cannot be done with simple jaunt.
112 integer VERIFY_UNSAFE_DECIDED = -6;  // this means the destination seems intractable.
113
114 integer MAXIMUM_PRIV_CHAN = 90000;
115     // the largest amount we will ever subtract from the tricky parms in order to
116     // tell the sub-jaunter which channel to listen on.
117
118 string VECTOR_SEPARATOR = "|";
119     // how we separate components of vectors from each other.
120 string DB_SEPARATOR = "``";  // separating items in lists.
121
122 ////////////// end jaunt base API
123
124 integer MAX_DEST_NAME = 24;  // the longest name that we store.
125
126 float NORMAL_TIMER_PERIOD = 1.0;  // our normal timer rate.
127
128 float POSITION_CHECKING_INTERVAL = 0.11;
129     // how frequently the waiting for arrival state will check where we are.
130
131 integer MAXIMUM_SLACKNESS = 108;
132     // how many timer hits we'll allow before reverting to the default state.
133
134 integer FREE_MEM_REQUIRED = 3200;
135     // we need at least this much memory before adding new targets.
136
137 //////////////
138
139 // global variables.
140
141 integer startup_parm;  // recorded at rez time.  used for deciding what to do.
142
143 integer conveyance_mode;  // when we are given our instructions, we will know what type of jump to use.
144
145 // jaunter target configuration...
146 string global_name;  // the name for our destination.
147 integer global_verification_state;  // the verification state of the last destination we asked for.
148 string global_pathway;  // similar, but the last pathway we heard.
149
150 // jaunt trip variables...
151 vector eventual_destination;  // where we're headed, if we're headed anywhere.
152 integer slackness_counter;  // snoozes had while waiting for destination.
153 list full_journey;  // the full pathway we expect to jaunt on.
154 integer jaunt_responses_awaited;  // number of pending jumps in progress.
155 integer got_close_enough;  // did we arrive at right place?
156 vector last_safe_position;  // where did we actually reach?
157
158 // asks the jaunting library to take us to the target using a list of waypoints.
159 request_jaunt(list journey, integer forwards)
160 {
161     // ask for a jump.
162     jaunt_responses_awaited++;
163     llMessageLinked(LINK_THIS, JAUNT_HUFFWARE_ID, JAUNT_LIST_COMMAND,
164         wrap_item_list(journey) + HUFFWARE_PARM_SEPARATOR + (string)forwards);
165     // stops the jaunter in its tracks.
166     llMessageLinked(LINK_THIS, JAUNT_HUFFWARE_ID, FULL_STOP_COMMAND, ""); 
167 }
168
169 // this function returns TRUE if we are close enough to the "destination".
170 integer close_enough(vector destination)
171 {
172     float PROXIMITY_REQUIRED = 0.1;
173         // how close we must be to the target location to call it done.
174         // matches current jaunting library proximity.
175     return (llVecDist(llGetPos(), destination) <= PROXIMITY_REQUIRED);
176 }
177
178 // sets up the initial state.
179 initialize_child()
180 {
181     llSetTimerEvent(0.0);  // cancel any existing timers.
182     // load up an arrival sound if any exist.
183     if (llGetInventoryNumber(INVENTORY_SOUND))
184         llPreloadSound(llGetInventoryName(INVENTORY_SOUND, 0));
185     if (DEBUGGING) log_it("child init startparm=" + (string)startup_parm);
186
187 //voodoo.
188     llSleep(0.5);
189     
190     if (startup_parm != 0) {
191         // tell the rezolator to start listening for commands.
192         llMessageLinked(LINK_THIS, JAUNT_REZOLATOR_HUFFWARE_ID, REZOLATOR_CHILD_SUPPORT,
193             wrap_parameters([startup_parm]));
194         // let our parent know we're here.
195         llMessageLinked(LINK_THIS, JAUNT_REZOLATOR_HUFFWARE_ID, REPORT_CHILD_REZZED, "");
196     }
197     // set up some of the object properties...
198     llSetSitText("Jaunt");  // change to the proper text for our mode.
199 }
200
201 // shows our next target for jaunting above the object.
202 text_label_for_destination()
203 {
204     string msg = "↣ " + global_name;
205     llSetText(msg, (vector)TEXT_COLOR, 1.0);
206 }
207
208 // signal that we are where we were going.
209 proclaim_arrival()
210 {
211     if (conveyance_mode == ONE_WAY_TRIP) {
212         // sing a little song, if there's a sound to use.
213         if (llGetInventoryNumber(INVENTORY_SOUND))
214             llTriggerSound(llGetInventoryName(INVENTORY_SOUND, 0), 1.0);
215     }
216 }
217
218 string verification_name(integer enumtype)
219 {
220     if (enumtype == VERIFY_SAFE) return "ok";
221     else if (enumtype == VERIFY_UNSAFE_SO_FAR) return "uhh";
222     else if (enumtype == VERIFY_UNSAFE_DECIDED) return "far";
223     // catch-all, including untested.
224     return "?";
225 }
226
227 // returns true if the slackness counter awaiting things has elapsed.
228 integer check_for_timeout()
229 {
230     if (slackness_counter++ > MAXIMUM_SLACKNESS) {
231         // go back to the main state.  we took too long.
232         log_it("timed out!");
233         llUnSit(llAvatarOnSitTarget());  // don't hang onto the avatar for this error.
234         llSetTimerEvent(0.0);
235         return TRUE;
236     }
237     return FALSE;
238 }
239
240 //////////////
241
242 // returns the value of a boolean variable definition.
243 integer parse_bool_def(string def)
244 { return !(llGetSubString(def, find_substring(def, "=") + 1, -1) == "0"); }
245
246 // processes link messages received from support libraries.
247 integer handle_link_message(integer which, integer num, string msg, string id)
248 {
249     // is it a jaunting library response?
250     if (num == JAUNT_HUFFWARE_ID + REPLY_DISTANCE) {
251         jaunt_responses_awaited--;  // one less response being awaited.
252         if (jaunt_responses_awaited < 0) {
253             log_it("error: responses awaited < 0");
254             jaunt_responses_awaited = 0;
255         }
256         return FALSE;
257     }
258     
259     // is it an event from the rezolator script?
260     if (num == JAUNT_REZOLATOR_HUFFWARE_ID + REPLY_DISTANCE) {
261         list parms = llParseString2List(id, [HUFFWARE_PARM_SEPARATOR], []);
262         if (msg == REZOLATOR_EVENT_GOT_INSTRUCTIONS) {
263             global_name = llList2String(parms, 0);
264             full_journey = [ llGetPos() ] + llParseString2List(llList2String(parms, 1), [VECTOR_SEPARATOR], []);
265             eventual_destination = (vector)llList2String(full_journey, llGetListLength(full_journey) - 1);
266             conveyance_mode = llList2Integer(parms, 2);
267             if (DEBUGGING)
268                 log_it("got instructions: name=" + global_name + " dest=" + (string)eventual_destination);
269             text_label_for_destination();
270             if (conveyance_mode == RECONNAISSANCE_TRIP) {
271                 return TRUE;
272             }
273         }
274         return FALSE;
275     }
276
277     return FALSE;
278 }
279
280 // processes a destination set to handle special cases, like for offset jaunting.
281 list prechewed_destinations(string dests)
282 {
283
284 //document this!!!
285 // as in, we support the offset format!
286
287     // look for our special start character for offsets.
288     if (is_prefix(dests, "o"))
289         // if this is an offset version, then chop whatever word they used starting with 'o'
290         // and compute the destination based on current position.
291         return [ (vector)llDeleteSubString(dests, 0, find_substring(dests, "<") - 1) + llGetPos() ];
292     else
293         // normal jaunt to absolute coordinates.
294         return llParseString2List(dests, [VECTOR_SEPARATOR], []);
295 }
296
297 //////////////
298 // from hufflets...
299
300 integer debug_num = 0;
301
302 // a debugging output method.  can be disabled entirely in one place.
303 log_it(string to_say)
304 {
305     debug_num++;
306     // tell this to the owner.    
307     llOwnerSay(llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
308     // say this on open chat, but use an unusual channel.
309 //    llSay(108, (string)debug_num + "- " + to_say);
310 }
311
312 ///////////////
313
314 // returns TRUE if the value in "to_check" specifies a legal x or y value in a sim.
315 integer valid_sim_value(float to_check)
316 {
317     if (to_check < 0.0) return FALSE;
318     if (to_check >= 257.0) return FALSE;
319     return TRUE;
320 }
321
322 // returns TRUE if the "to_check" vector is a location outside of the current sim.
323 integer outside_of_sim(vector to_check)
324 {
325     return !valid_sim_value(to_check.x) || !valid_sim_value(to_check.y);
326 }
327
328 // returns text for a floating point number, but includes only
329 // two digits after the decimal point.
330 string float_chop(float to_show)
331 {
332     integer mant = llAbs(llRound(to_show * 100.0) / 100);
333     string neg_sign;
334     if (to_show < 0.0) neg_sign = "-";
335     string dec_s = (string)((llRound(to_show * 100.0) - mant * 100) / 100.0);
336     dec_s = llGetSubString(llGetSubString(dec_s, find_substring(dec_s, ".") + 1, -1), 0, 2);
337     // strip off all trailing zeros.
338     while (llGetSubString(dec_s, -1, -1) == "0")
339         dec_s = llDeleteSubString(dec_s, -1, -1);
340     string to_return = neg_sign + (string)mant;
341     if (llStringLength(dec_s)) to_return += "." + dec_s;
342     return to_return;
343 }
344
345 // returns a prettier form for vector text, with chopped floats.
346 string vector_chop(vector to_show)
347 {
348     return "<" + float_chop(to_show.x) + ","
349         + float_chop(to_show.y) + ","
350         + float_chop(to_show.z) + ">";
351 }
352
353 // joins a list of parameters using the parameter sentinel for the library.
354 string wrap_parameters(list to_flatten)
355 { return llDumpList2String(to_flatten, HUFFWARE_PARM_SEPARATOR); }
356 //
357 // joins a list of sub-items using the item sentinel for the library.
358 string wrap_item_list(list to_wrap)
359 { return llDumpList2String(to_wrap, HUFFWARE_ITEM_SEPARATOR); }
360
361 // returns a number at most "maximum" and at least "minimum".
362 // if "allow_negative" is TRUE, then the return may be positive or negative.
363 float randomize_within_range(float minimum, float maximum, integer allow_negative)
364 {
365     if (minimum > maximum) {
366         // flip the two if they are reversed.
367         float temp = minimum; minimum = maximum; maximum = temp;
368     }
369     float to_return = minimum + llFrand(maximum - minimum);
370     if (allow_negative) {
371         if (llFrand(1.0) < 0.5) to_return *= -1.0;
372     }
373     return to_return;
374 }
375
376 // returns a random vector where x,y,z will be between "minimums" and "maximums"
377 // x,y,z components.  if "allow_negative" is true, then any component will
378 // randomly be negative or positive.
379 vector random_bound_vector(vector minimums, vector maximums, integer allow_negative)
380 {
381     return <randomize_within_range(minimums.x, maximums.x, allow_negative),
382         randomize_within_range(minimums.y, maximums.y, allow_negative),
383         randomize_within_range(minimums.z, maximums.z, allow_negative)>;
384 }
385
386 // returns a vector whose components are between minimum and maximum.
387 // if allow_negative is true, then they can be either positive or negative.
388 vector random_vector(float minimum, float maximum, integer allow_negative)
389 {
390     return random_bound_vector(<minimum, minimum, minimum>,
391         <maximum, maximum, maximum>, allow_negative);
392 }
393
394 // returns the portion of the list between start and end, but only if they are
395 // valid compared with the list length.  an attempt to use negative start or
396 // end values also returns a blank list.
397 list chop_list(list to_chop, integer start, integer end)
398 {
399     integer last_len = llGetListLength(to_chop) - 1;
400     if ( (start < 0) || (end < 0) || (start > last_len) || (end > last_len) ) return [];
401     return llList2List(to_chop, start, end);
402 }
403
404 // returns the index of the first occurrence of "pattern" inside
405 // the "full_string".  if it is not found, then a negative number is returned.
406 integer find_substring(string full_string, string pattern)
407 {
408     string full_lower = llToLower(full_string);
409     return llSubStringIndex(full_lower, pattern);
410 }
411
412 // returns TRUE if the "prefix" string is the first part of "compare_with".
413 integer is_prefix(string compare_with, string prefix)
414 { return find_substring(compare_with, prefix) == 0; }
415
416 //////////////
417 // huffware script: auto-retire, by fred huffhines, version 2.8.
418 // distributed under BSD-like license.
419 //   !!  keep in mind that this code must be *copied* into another
420 //   !!  script that you wish to add auto-retirement capability to.
421 // when a script has auto_retire in it, it can be dropped into an
422 // object and the most recent version of the script will destroy
423 // all older versions.
424 //
425 // the version numbers are embedded into the script names themselves.
426 // the notation for versions uses a letter 'v', followed by two numbers
427 // in the form "major.minor".
428 // major and minor versions are implicitly considered as a floating point
429 // number that increases with each newer version of the script.  thus,
430 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
431 // and "hazmap v3.2" is a more recent version.
432 //
433 // example usage of the auto-retirement script:
434 //     default {
435 //         state_entry() {
436 //            auto_retire();  // make sure newest addition is only version of script.
437 //        }
438 //     }
439 // this script is partly based on the self-upgrading scripts from markov brodsky
440 // and jippen faddoul.
441 //////////////
442 auto_retire() {
443     string self = llGetScriptName();  // the name of this script.
444     list split = compute_basename_and_version(self);
445     if (llGetListLength(split) != 2) return;  // nothing to do for this script.
446     string basename = llList2String(split, 0);  // script name with no version attached.
447     string version_string = llList2String(split, 1);  // the version found.
448     integer posn;
449     // find any scripts that match the basename.  they are variants of this script.
450     for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
451         string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
452         if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
453             // found a basic match at least.
454             list inv_split = compute_basename_and_version(curr_script);
455             if (llGetListLength(inv_split) == 2) {
456                 // see if this script is more ancient.
457                 string inv_version_string = llList2String(inv_split, 1);  // the version found.
458                 // must make sure that the retiring script is completely the identical basename;
459                 // just matching in the front doesn't make it a relative.
460                 if ( (llList2String(inv_split, 0) == basename)
461                     && ((float)inv_version_string < (float)version_string) ) {
462                     // remove script with same name from inventory that has inferior version.
463                     llRemoveInventory(curr_script);
464                 }
465             }
466         }
467     }
468 }
469 //
470 // separates the base script name and version number.  used by auto_retire.
471 list compute_basename_and_version(string to_chop_up)
472 {
473     // minimum script name is 2 characters plus a version.
474     integer space_v_posn;
475     // find the last useful space and 'v' combo.
476     for (space_v_posn = llStringLength(to_chop_up) - 3;
477         (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
478         space_v_posn--) {
479         // look for space and v but do nothing else.
480     }
481     if (space_v_posn < 2) return [];  // no space found.
482     // now we zoom through the stuff after our beloved v character and find any evil
483     // space characters, which are most likely from SL having found a duplicate item
484     // name and not so helpfully renamed it for us.
485     integer indy;
486     for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
487         if (llGetSubString(to_chop_up, indy, indy) == " ") {
488             // found one; zap it.  since we're going backwards we don't need to
489             // adjust the loop at all.
490             to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
491         }
492     }
493     string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
494     // ditch the space character for our numerical check.
495     string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
496     // strip out a 'v' if there is one.
497     if (llGetSubString(chop_suffix, 0, 0) == "v")
498         chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
499     // if valid floating point number and greater than zero, that works for our version.
500     string basename = to_chop_up;  // script name with no version attached.
501     if ((float)chop_suffix > 0.0) {
502         // this is a big success right here.
503         basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
504         return [ basename, chop_suffix ];
505     }
506     // seems like we found nothing useful.
507     return [];
508 }
509 //
510 //////////////
511
512 //////////////
513
514 // default state scrounges for information in a notecard and looks for landmarks in
515 // inventory to add as destinations.
516 default
517 {
518     state_entry() { if (llSubStringIndex(llGetObjectName(),  "huffotronic") < 0) state real_default; }
519     on_rez(integer parm) {
520         startup_parm = parm; 
521         if (DEBUGGING) log_it("default onrez " + (string)startup_parm);
522         state rerun;
523     }
524 }
525 state rerun { state_entry() { state default; } }
526
527 state real_default
528 {
529     state_entry() {
530         auto_retire();
531         if (DEBUGGING) log_it("=> real_default state, mem=" + (string)llGetFreeMemory());
532         initialize_child();
533         state normal_runtime;
534     }
535     
536     on_rez(integer parm) {
537         startup_parm = parm; 
538         if (DEBUGGING) log_it("default onrez " + (string)startup_parm);
539         state default;
540     }
541 }
542
543 // the normal state is pretty calm; the jaunter just sits there waiting for
544 // an avatar who needs it to do something.
545 state normal_runtime
546 {
547     state_entry() {
548         if (DEBUGGING) log_it("=> normal state, mem=" + (string)llGetFreeMemory());
549         jaunt_responses_awaited = 0;  // nothing pending right now.
550         got_close_enough = FALSE;  // have not even tried going there yet.
551     }
552
553     on_rez(integer parm) {
554         startup_parm = parm;
555         if (DEBUGGING) log_it("default onrez " + (string)startup_parm);
556         state default;
557     }
558
559     touch_end(integer total_number) {
560         // if we got to here, we may need to check the safety of the target and show the
561         // map if the conditions are right.
562         if (outside_of_sim(eventual_destination)) {
563             // bring up the map; maybe we can't get there from here.  definitely out of sim.
564             llMapDestination(llGetRegionName(), eventual_destination, ZERO_VECTOR);
565             proclaim_arrival();
566         }
567     }
568
569     changed(integer change) {
570         if (!(change & CHANGED_LINK)) return;  // don't care then.
571 //no, bad, ack.  if the jaunter has multiple parts and they sit on non-root prim, this breaks our ability to react to sit events properly.        if (llAvatarOnSitTarget() == NULL_KEY) return;  // there is no one sitting now.
572         if (outside_of_sim(eventual_destination)) {
573             llWhisper(0, "This type of jaunter needs to be clicked rather than sat upon.  Please left-click it (or right-click it and select 'touch').");
574             llUnSit(llAvatarOnSitTarget());
575             return;
576         }
577         state jaunting_now;  // sweet, we're off.
578     }
579
580     // process the response from the APIs we use.
581     link_message(integer which, integer num, string msg, key id) {
582         if (handle_link_message(which, num, msg, id)) state jaunting_now;
583     }
584     
585 }
586
587 // once someone is trying to jump to a target, this state processes the request.
588 state jaunting_now
589 {
590     state_entry() {
591         if (DEBUGGING) log_it("=> jauntnow state, posn=" + vector_chop(llGetPos()));
592         slackness_counter = 0;
593         // most jaunters go to at least the first location...
594         request_jaunt(full_journey, TRUE);
595         eventual_destination = (vector)llList2String(full_journey, llGetListLength(full_journey) - 1);
596         llSetTimerEvent(POSITION_CHECKING_INTERVAL);
597     }
598
599     on_rez(integer parm)
600     {
601         startup_parm = parm;
602         if (DEBUGGING) log_it("default onrez " + (string)startup_parm);
603         state default;
604     }
605
606     timer() {
607         if (jaunt_responses_awaited) {
608             // we are not quite there yet.
609             if (check_for_timeout()) state normal_runtime;  // oops.
610             return;  // not time yet.
611         }
612         // we got to where we were going, maybe.  unseat the avatar, leaving her
613         // at the destination.
614         llUnSit(llAvatarOnSitTarget());
615         state arrived_at_target;
616     }
617
618     // process the response from the jaunting library.
619     link_message(integer which, integer num, string msg, key id)
620     { handle_link_message(which, num, msg, id); }
621 }
622
623 // this state is activated when the first jaunt is complete.
624 state arrived_at_target
625 {
626     state_entry() {
627         if (DEBUGGING) log_it("=> arriv targ state, posn=" + vector_chop(llGetPos()));
628         // we are close enough; get back to work.
629         jaunt_responses_awaited = 0;  // nothing pending right now.
630         if (conveyance_mode != RECONNAISSANCE_TRIP) {
631             llWhisper(0, "↣ " + global_name);
632         } else {
633             if (DEBUGGING) {
634                 string close = "yep";
635                 if (!close_enough(eventual_destination)) close = "nope";
636                 log_it("close enough here? " + close + ", want to get to "
637                     + (string)eventual_destination);
638             }
639             got_close_enough = close_enough(eventual_destination);
640             last_safe_position = llGetPos();
641         }
642
643         // we've gotten where we were going.
644         proclaim_arrival();
645
646 //hmmm: nice mod to make the one way trip actually flip its target list and allow a return.
647
648         // reverse direction and head back without rider.
649         eventual_destination = (vector)llList2String(full_journey, 0);
650         request_jaunt(full_journey, FALSE);
651         llSetTimerEvent(POSITION_CHECKING_INTERVAL);
652         slackness_counter = 0;
653         if (DEBUGGING) log_it("now trying to jaunt home, responses awaited=" + (string)jaunt_responses_awaited);
654     }
655
656     on_rez(integer parm) {
657         startup_parm = parm; 
658         if (DEBUGGING) log_it("default onrez " + (string)startup_parm);
659         state default;
660     }
661
662     timer() {
663         if (jaunt_responses_awaited) {
664             // we are not quite there yet.
665             if (check_for_timeout()) state normal_runtime;  // oops.
666             return;  // not time yet.
667         }
668         if (DEBUGGING) log_it("==> telling parent we got back, now at posn: " + (string)llGetPos());
669         llMessageLinked(LINK_THIS, JAUNT_REZOLATOR_HUFFWARE_ID, REZOLATOR_CHILD_RETURNED,
670             wrap_parameters([got_close_enough, 
671                 llDumpList2String(llDeleteSubList(full_journey, 0, 0) + [ last_safe_position ],
672                     VECTOR_SEPARATOR)]));
673         state normal_runtime;
674     }
675     
676     // process the response from the jaunting library.
677     link_message(integer which, integer num, string msg, key id)
678     { handle_link_message(which, num, msg, id); } 
679 }