normalized perms on all files, to avoid relying on any stored executable bits in...
[feisty_meow.git] / huffware / huffotronic_scripts / turbo_lifter_v5.8.txt
1 
2 // huffware script: turbo lifter, by fred huffhines
3
4 // constants you may want to adjust...
5
6 float minimum_height = 0.5;
7     // the lowest that the lifter will move -- relative to ground height.
8
9 float maximum_height = 1007.5;
10     // the highest that the platform will move in absolute height (not relative to ground!).
11
12 // the rationale for having the minimum be based on ground height and the maximum be based
13 // on absolute heights is that it is often the case that one wants to have the elevator meet
14 // people at the ground, and then take them high up in the clouds.  given that main usage
15 // pattern, we've found it way more convenient to reckon the base against ground but leave
16 // the top absolute so we can match sky houses et al.
17     
18 float movement_per_cycle = 100.0;
19     // how much change in height occurs per timer hit.
20
21 integer SLEEP_DURATION = 28;
22     // how long the elevator pauses at the stations.
23   
24 integer PAUSE_DURATION = 14;
25     // the delay added when a user clicks on the elevator.
26
27 integer COUNTDOWN_INTERVAL = 8;
28    // the frequency of the countdown message about departure.
29
30 integer WHISPER_COUNTDOWN = FALSE;
31     // if TRUE, the elevator will count down its departure schedule.
32
33 //////////////
34
35 // requires: jaunting library v14.0 or higher.
36 //////////////
37 integer JAUNT_HUFFWARE_ID = 10008;
38     // the unique id within the huffware system for the jaunt script to
39     // accept commands on.  this is used in llMessageLinked as the num parameter.
40 string HUFFWARE_PARM_SEPARATOR = "{~~~}";
41     // this pattern is an uncommon thing to see in text, so we use it to separate
42     // our commands in link messages.
43 string HUFFWARE_ITEM_SEPARATOR = "{|||}";
44     // used to separate lists of items from each other when stored inside a parameter.
45     // this allows lists to be passed as single string parameters if needed.
46 integer REPLY_DISTANCE = 100008;  // offset added to service's huffware id in reply IDs.
47 //////////////
48 string JAUNT_COMMAND = "#jaunt#";
49     // command used to tell jaunt script to move object.
50 //////////////
51
52 //////////////
53
54 // global variables and their default values...
55
56 integer going_up = FALSE;
57     // remembers which direction the platform is moving.
58
59 integer next_movement;
60     // when the lift should next move.  delayed for stations and
61     // when user chooses to delay take-off.
62
63 //////////////
64
65 float height_above_ground()
66 {
67     vector position = llGetPos();
68     vector size = llGetAgentSize(llGetOwner()); 
69     return position.z - llGround(<0.0,0.0,0.0>) - size.z;
70 }
71
72 jaunt_to_target(vector target)
73 {
74     llMessageLinked(LINK_THIS, JAUNT_HUFFWARE_ID, JAUNT_COMMAND, (string)target);
75 }
76
77 //////////////
78 // huffware script: auto-retire, by fred huffhines, version 2.5.
79 // distributed under BSD-like license.
80 //   !!  keep in mind that this code must be *copied* into another
81 //   !!  script that you wish to add auto-retirement capability to.
82 // when a script has auto_retire in it, it can be dropped into an
83 // object and the most recent version of the script will destroy
84 // all older versions.
85 //
86 // the version numbers are embedded into the script names themselves.
87 // the notation for versions uses a letter 'v', followed by two numbers
88 // in the form "major.minor".
89 // major and minor versions are implicitly considered as a floating point
90 // number that increases with each newer version of the script.  thus,
91 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
92 // and "hazmap v3.2" is a more recent version.
93 //
94 // example usage of the auto-retirement script:
95 //     default {
96 //         state_entry() {
97 //            auto_retire();  // make sure newest addition is only version of script.
98 //        }
99 //     }
100 // this script is partly based on the self-upgrading scripts from markov brodsky
101 // and jippen faddoul.
102 //////////////
103 auto_retire() {
104     string self = llGetScriptName();  // the name of this script.
105     list split = compute_basename_and_version(self);
106     if (llGetListLength(split) != 2) return;  // nothing to do for this script.
107     string basename = llList2String(split, 0);  // script name with no version attached.
108     string version_string = llList2String(split, 1);  // the version found.
109     integer posn;
110     // find any scripts that match the basename.  they are variants of this script.
111     for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
112 //log_it("invpo=" + (string)posn);
113         string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
114         if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
115             // found a basic match at least.
116             list inv_split = compute_basename_and_version(curr_script);
117             if (llGetListLength(inv_split) == 2) {
118                 // see if this script is more ancient.
119                 string inv_version_string = llList2String(inv_split, 1);  // the version found.
120                 // must make sure that the retiring script is completely the identical basename;
121                 // just matching in the front doesn't make it a relative.
122                 if ( (llList2String(inv_split, 0) == basename)
123                     && ((float)inv_version_string < (float)version_string) ) {
124                     // remove script with same name from inventory that has inferior version.
125                     llRemoveInventory(curr_script);
126                 }
127             }
128         }
129     }
130 }
131 //
132 // separates the base script name and version number.  used by auto_retire.
133 list compute_basename_and_version(string to_chop_up)
134 {
135     // minimum script name is 2 characters plus a version.
136     integer space_v_posn;
137     // find the last useful space and 'v' combo.
138     for (space_v_posn = llStringLength(to_chop_up) - 3;
139         (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
140         space_v_posn--) {
141         // look for space and v but do nothing else.
142 //log_it("pos=" + (string)space_v_posn);
143     }
144     if (space_v_posn < 2) return [];  // no space found.
145 //log_it("space v@" + (string)space_v_posn);
146     // now we zoom through the stuff after our beloved v character and find any evil
147     // space characters, which are most likely from SL having found a duplicate item
148     // name and not so helpfully renamed it for us.
149     integer indy;
150     for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
151 //log_it("indy=" + (string)space_v_posn);
152         if (llGetSubString(to_chop_up, indy, indy) == " ") {
153             // found one; zap it.  since we're going backwards we don't need to
154             // adjust the loop at all.
155             to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
156 //log_it("saw case of previously redundant item, aieee.  flattened: " + to_chop_up);
157         }
158     }
159     string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
160     // ditch the space character for our numerical check.
161     string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
162     // strip out a 'v' if there is one.
163     if (llGetSubString(chop_suffix, 0, 0) == "v")
164         chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
165     // if valid floating point number and greater than zero, that works for our version.
166     string basename = to_chop_up;  // script name with no version attached.
167     if ((float)chop_suffix > 0.0) {
168         // this is a big success right here.
169         basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
170         return [ basename, chop_suffix ];
171     }
172     // seems like we found nothing useful.
173     return [];
174 }
175 //
176 //////////////
177
178
179 default
180 {
181     state_entry() { if (llSubStringIndex(llGetObjectName(),  "huffotronic") < 0) state real_default; }
182     on_rez(integer parm) { state rerun; }
183 }
184 state rerun { state_entry() { state default; } }
185
186 state real_default
187 {
188     state_entry()
189     {
190         auto_retire();
191         // initialize the next movement so elevator doesn't just zoom off.
192         next_movement = llGetUnixTime() + (integer)SLEEP_DURATION;
193         // we move at one second intervals due to our use of unix time,
194         // which has a resolution of seconds.
195         llSetTimerEvent(4.0);
196     }
197     
198 //need commands, like start, or call to come down.
199 // need elevator system that would call it.
200 //  if elevator style deal, needs to not delay so silly like.
201 //    when jaunting, go go go.
202     
203     timer()
204     {
205         integer time_now = llGetUnixTime();
206         // make sure it's time to do something.
207         if (time_now < next_movement) {
208             integer time_left = next_movement - time_now;
209             if ( (time_left <= 2) || !(time_left % COUNTDOWN_INTERVAL) ) {
210                 if (WHISPER_COUNTDOWN) {
211 //hmmm: abstract pluralizer out as separate function.
212                     string plural = "s";
213                     if (time_left == 1) plural = "";
214                     llWhisper(0, "Time remaining before departure: "
215                         + (string)time_left + " second" + plural + ".");
216                 }
217             }
218             return;  // not time to move yet.
219         }
220         // set the next movement time to be without any delay, until we know better.
221         next_movement = llGetUnixTime();
222         // compute where we should jump to next.        
223         vector next_location = llGetPos();
224         // add in the appropriate amount to our height.
225         if (going_up) next_location += <0.0, 0.0, movement_per_cycle>;
226         else next_location -= <0.0, 0.0, movement_per_cycle>;
227         // check whether we've hit one of our extremes.
228         if (next_location.z >= maximum_height) {
229             going_up = FALSE;  // start going down.
230             next_movement = llGetUnixTime() + (integer)SLEEP_DURATION;
231             next_location.z = maximum_height;
232         } else if (next_location.z <= minimum_height + llGround(<0.0,0.0,0.0>)) {
233             going_up = TRUE;  // begin going up.
234             next_movement = llGetUnixTime() + (integer)SLEEP_DURATION;
235             next_location.z = minimum_height + llGround(<0.0,0.0,0.0>);
236         }
237         // now actually go to where we decided.
238         jaunt_to_target(next_location);
239     }
240
241     touch_start(integer total_number)
242     {
243         next_movement += (integer)PAUSE_DURATION;
244         llWhisper(0, "Your click delays departure by " + (string)PAUSE_DURATION + " seconds.");
245     }
246 }
247