normalized perms on all files, to avoid relying on any stored executable bits in...
[feisty_meow.git] / huffware / huffotronic_scripts / Hour_Hand_v0.5.txt
1 
2 // huffware script: hour hand, modified by fred huffhines.
3 // 
4 // expanded to support time zones by fred huffhines, december 2009.
5 //
6 // noticed this in arcadia asylum's great hobo cuckoo clock.
7 // this script is licensed by Beezle Warburton:
8 //    "I released those 'into the wild' years ago,do what you like,
9 //     I just ask that people don't resell the scripts by themselves."
10 //
11 // fred's changes licensed by:
12 //   this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
13 //   do not use it in objects without fully realizing you are implicitly accepting that license.
14
15 // Optional second hand will be a much simpler script that will be
16 // unrelated to real-time.
17 //
18 // note - to reduce load, this script only calculates once a minute, so
19 // this provides a jump style minute hand, rather than a smoothy rotating one.
20 // This (and rounding) makes the clock's accuracy +/- 1 minute.
21 // It's a prim clock anyways, so digital accuracy is just excessive.
22 //
23 // It would probably be more elegant to use link messages rather than each
24 // hand having it's own script, however, this method allows for less caution
25 // when linking/unlinking parts of the clock.
26
27 // To not mess up timekeeping, please keep chime sounds under 4 seconds long.
28
29 integer time;
30 integer hours;
31 integer minutes;
32
33 float anglehours;
34 float angleminutes;
35
36 integer chime;
37 integer numrings;
38
39 string chimesound = "CuckooClock";
40 float chimevolume = 1.0;
41
42 // this is what might be adjusted.
43 integer LOCAL_TIME_ZONE_OFFSET = -5;  //-5 is EST, -8 is PST.
44
45 // the code used in linked messages for us.
46 integer SECRET_TIME_ZONE_ADJUSTER_ID = -2091823;
47 string TIME_ZONE_ADJUST_COMMAND = "tzadjust";
48
49 default
50 {
51     state_entry() { if (llSubStringIndex(llGetObjectName(),  "huffotronic") < 0) state real_default; }
52     on_rez(integer parm) { state rerun; }
53 }
54 state rerun { state_entry() { state default; } }
55
56 state real_default
57 {
58     state_entry()
59     {
60         // we want to calculate once a minute.
61         llSetTimerEvent(60.0);
62     }
63     timer() {
64         llSetTimerEvent(0);
65         time = (integer)llGetGMTclock(); // seconds since midnight
66         // adjust the hours for the time zone.  this will work for most time zones that
67         // go through daylight saving time, like the pacific zone where SL is rooted.
68         hours = (time / 3600) + LOCAL_TIME_ZONE_OFFSET;
69         // convert from 24 to 12 hour time
70         if (hours > 11) {
71             hours = hours - 12;
72         } else if (hours < 0) {
73             hours = hours + 12;
74         }
75         minutes = (time % 3600) / 60;
76         
77         numrings = (integer)hours;
78         if (numrings == 0) {
79             numrings = 12;
80         }
81         
82         // the extra addition here makes a smooth hour hand
83         // for example, at 6:30, the hour hand should actually
84         // be halfway between 6 and 7 on the clock dial
85         
86         anglehours = - (((float)hours / 12) + (((float)minutes / 720))) * TWO_PI;
87 //incompatible with opensim:        llSetSoundQueueing(TRUE);
88         llRotateTexture(anglehours, ALL_SIDES);
89         if (minutes == 0) {
90             llMessageLinked(-1,numrings,"chime",NULL_KEY);
91             //for (chime = 0; chime < numrings; chime++) {
92             //      llPlaySound(chimesound, chimevolume);
93             //      llSleep(3.0);    
94             //}            
95         }
96         llSetTimerEvent(60.0);
97     }
98     
99     link_message(integer sender, integer num, string msg, key id) {
100         if ( (num != SECRET_TIME_ZONE_ADJUSTER_ID) || (msg != TIME_ZONE_ADJUST_COMMAND) )
101             return;  // not for us.
102         // this should be a time zone for us to use.
103         LOCAL_TIME_ZONE_OFFSET = (integer)((string)id);
104 //llSay(0, "got a new time zone of " + (string)LOCAL_TIME_ZONE_OFFSET );
105         // handle this update as soon as possible.
106         llSetTimerEvent(0.1);
107     }
108 }
109