home *** CD-ROM | disk | FTP | other *** search
- #
- # CC_Mirror.cog
- #
- # Generic Mirror control Script
- #
- # 03/17/98 DGS Created
- # 03/21/98 DGS Added the keyframe control to make the thing accurate.
- # 04/17/98 DGS Added the buffering system (Jean Jacques Perrey)
- #
- # (C) 1998 Lucas Learning Limited All Rights Reserved
- # ========================================================================================
-
- symbols
- message blocked
- message arrived
- message startup
- message timer
- message entered
- message activated
- message pulse
-
-
- ## ========================= Things
- thing mirror_o
-
- ## ========================= Cogs
- cog laser_c
-
- ## ========================= Surface
- surface left_s
- surface right_s
-
- surface ang_one_s nolink
- surface ang_ten_s nolink
- surface ang_hund_s nolink
- surface ang_LR_s nolink
- surface dummy0_s nolink
- surface dummy1_s nolink
- surface dummy2_s nolink
-
- surface vec_one_s nolink
- surface vec_ten_s nolink
- surface vec_hund_s nolink
-
-
- sound rot_snd=MCH02Mirror.WAV local
- sound compute_snd=CMP04Calc.WAV local
- sound act_snd=SWT00DrSwtch.WAV local
- ## ========================== Key Angle integers
- int key2_ang
- int key3_ang
- int key4_ang
- int key5_ang
-
- int laser_i=0 local
- int l_color=1 local
- flex l_radius=0.005 local
- flex Mirrorang=0 local
- int selection=0 local
- int zang=0 local
- int add_ang=0 local
- int vec_ang=0 local
- int dest_ang=0 local
- int disp_ang=0 local
- int active=0 local
- int pulsemode=0 local
- int pulsecount=0 local
- int buffer=0 local
- int set=0 local
- int playit=0 local
- int arrive_flag=0 local
- int mirror_id=0
- end
-
- # ========================================================================================
-
- code
- startup:
- setwallcel(dummy0_s,10);
- setwallcel(dummy1_s,10);
- setwallcel(dummy2_s,10);
-
- call cue_angle;
- //pulsemode = 2;
- //setpulse(0.25);
-
- return;
-
- activated:
- print("activated");
- // Acitvated routine controls the rotation of the mirror.
- print("Buffer: ");
- printint(buffer);
- selection = getsenderref();
- call rotate_mirror;
- return;
-
- rotate_mirror:
- // This rouitne is called buy both activated and by the timer, and is used to actually setup rotation of the mirror.
- // Another routine called "rotation" is used for common setup stuff.
- print("Buffer: ");
- printint(buffer);
-
- if (active == 0) // if the mirror is currently not rotating
- {
- if ((selection == left_s) || (selection == right_s)) //if it was a switch that was activated
- {
- if (global9 == 1) //if the laser's turned on
- {
- sendmessage(laser_c,user0); // Tell the laser cog to turn off
- settimer(2);
- setwallcel(left_s,1);
- setwallcel(right_s,1);
- }
- else // else the laser must be off.
- {
- if (selection == left_s)
- {
- if (( mirrorang + 5) < 81) // if the mirror's not gonna go past 80
- {
- if (sounder >0) {stopsound(sounder,0.2); sounder = -1;}
-
- print("rotate left");
- rotatepivot(mirror_o,1,-1);
- garbage = playsoundthing(rot_snd,mirror_o,1.0,-1,-1,0);
- setwallcel(left_s,1);
- garbage = playsoundpos(act_snd,getsurfacecenter(left_s),0.5,-1,-1,0);
- setwallcel(right_s,0);
- add_ang = 1;
- dest_ang = mirrorang + 5;
- arrive_flag = 0;
- call rotation;
- }
- else
- {
- buffer = 0;
- dwPlayCammySpeech(16025, "M4ca022.wav", 10, 0); //That's as far as it goes in that dir
- }
- }
- if (selection == right_s)
- {
- if (( mirrorang - 5) > -81) //if the mirror's no gonna go pas -80
- {
- if (sounder >0) {stopsound(sounder,0.2); sounder = -1;}
-
- print("rotate right");
- rotatepivot(mirror_o,1, 1);
- garbage = playsoundthing(rot_snd,mirror_o,1.0,-1,-1,0);
- setwallcel(right_s,1);
- garbage = playsoundpos(act_snd,getsurfacecenter(left_s),0.5,-1,-1,0);
- setwallcel(left_s,0);
- add_ang = -1;
- dest_ang = mirrorang - 5;
- arrive_flag = 0;
- call rotation;
- }
- else
- {
- buffer = 0;
- dwPlayCammySpeech(16025, "M4ca022.wav", 10, 0); //That's as far as it goes in that dir
- }
- }
- }
- }
- }
- else //the mirror is moving
- {
- /////// BUFFER STUF
- if (selection == left_s)
- {
- buffer = buffer + 1;
- }
- if (selection == right_s)
- {
- buffer = buffer - 1;
- }
- }
- return;
-
- rotation:
- // This routine handles stuff common to both rotating left and right.
- if (playit == 0)
- {
- dwPlayCammySpeech(16022, "M4ca020.wav", 10, 0); //I can hear the mirrror turning up there.
- playit = 1;
- }
- active = 1;
- vec_ang = 0;
- pulsemode = 1;
- setpulse(0.09);
- return;
-
- timer:
- // Used to set a delay between the mirror turning off and rotation of the mirror.
- call rotate_mirror;
- return;
-
-
- pulse:
- // Controls cycling of the numbers.
- if (pulsemode == 1)
- {
- mirrorang = mirrorang + add_ang;
- call displayang;
- if (mirrorang == dest_ang)
- {
- setpulse(0);
- vec_ang = 1;
- arrive_flag = arrive_flag + 1;
- call check_buffer;
- }
- }
- else if (pulsemode == 2)
- {
- pulsecount = 0;
- pulsemode = 3;
- }
- if (pulsemode == 3)
- {
- // Random angle mode, "Calculating..."
- //set = ((rand()*9));
- //set = (set * 10) + (rand()*9);
- zang = (rand()*999);
- call disp_ref_ang;
- pulsecount = pulsecount + 1;
- if (pulsecount == 13) // If it's calculated long enough
- {
- pulsemode = 0;
- call displayang; // show the real angle.
- if (sounder >0) {stopsound(sounder,0.1); sounder = -1;}
- setpulse(0);
- }
- }
- return;
-
- arrived:
- //call displayang;
- active = 0;
- setwallcel(left_s,0);
- setwallcel(right_s,0);
- // The following lines control "snapping" the mirrors to the correct angle when they reach their desitination.
- // This is because rotatepivot is not accurate enough for the needed angles.
- if (dest_ang == 0)
- {
- print("Reset angle at key 0");
- jumptoframe(mirror_o,0,getthingsector(mirror_o));
- }
- else if ((dest_ang == key2_ang) && (key2_ang != 0) )
- {
- print("Reset angle at key 2");
- jumptoframe(mirror_o,2,getthingsector(mirror_o));
- }
- else if ((dest_ang == key3_ang) && (key3_ang != 0) )
- {
- print("Reset angle at key 3");
- jumptoframe(mirror_o,3,getthingsector(mirror_o));
- }
- else if ((dest_ang == key4_ang) && (key4_ang != 0) )
- {
- print("Reset angle at key 4");
- jumptoframe(mirror_o,4,getthingsector(mirror_o));
- }
- else if ((dest_ang == key5_ang) && (key5_ang != 0) )
- {
- print("Reset angle at key 5");
- jumptoframe(mirror_o,5,getthingsector(mirror_o));
- }
- call cue_angle;
- arrive_flag = arrive_flag + 1;
- call check_buffer;
- return;
-
- check_buffer:
- if (arrive_flag == 2)
- {
- // ============================== Buffer stuff
- if ( buffer > 0 ) //If there's Left commands in the buffer
- {
- selection = left_s;
- buffer = buffer - 1;
- call rotate_mirror;
- }
- else if ( buffer < 0 ) // If there's Right commands in the buffer
- {
- selection = right_s;
- buffer = buffer + 1;
- call rotate_mirror;
- }
- else //Else there's nothing left for it to do.
- {
- // Start up the randomizer
- pulsemode = 2;
- setpulse(0.025);
- sounder = playsoundthing(compute_snd,mirror_o,1.0,-1,-1,0);
- }
- }
- return;
-
- cue_angle:
- // This routine is used to set the correct global variable to the proper value.
- // Since this cog is used in many locations in the level, this routine is needed
- // to set the correct global variable.
- if (mirror_id == 0) global0 = mirrorang;
- else if (mirror_id == 1) global1 = mirrorang;
- else if (mirror_id == 2) global2 = mirrorang;
- else if (mirror_id == 3) global3 = mirrorang;
- else if (mirror_id == 4) global4 = mirrorang;
- else if (mirror_id == 5) global5 = mirrorang;
- else if (mirror_id == 6) global6 = mirrorang;
- else if (mirror_id == 7) global7 = mirrorang;
- else if (mirror_id == 8) global8 = mirrorang;
-
- //print("G0:");
- //printint(global0);
- //print("G1:");
- //printint(global1);
- //print("G2:");
- //printint(global2);
- //print("G3:");
- //printint(global3);
- //print("G4:");
- //printint(global4);
- //print("G5:");
- //printint(global5);
- //print("G6:");
- //printint(global6);
- //print("G7:");
- //printint(global7);
- //print("G8:");
- //printint(global8);
- //print("G9:");
- //printint(global9);
-
- return;
-
-
-
- displayang:
- // This routine handles the display of angles.
- if (mirrorang < 0) //if the mirror is rotated in the negitive
- {
- disp_ang = 0-mirrorang; // Reverse the display number
- setwallcel(ang_lr_s,1); // Set the left/right indicator to right
- }
- else
- {
- disp_ang = mirrorang; //use the correct diaply number
- setwallcel(ang_lr_s,2); // set the left/right indicator to left
- }
- if (mirrorang == 0) setwallcel(ang_lr_s,0); // If the mirror's at 0 set the left right indicator to nothing.
-
- // Set the angle of mirror
- SetWallCel(ang_one_s, disp_ang % 10);
- SetWallCel(ang_ten_s, (disp_ang / 10) % 10);
- SetWallCel(ang_hund_s, (disp_ang / 100) % 10);
-
-
- // set the angle of relfection
- if (vec_ang == 0)
- {
- zang = 0;
- SetWallCel(vec_one_s, 10);
- SetWallCel(vec_ten_s, 10);
- SetWallCel(vec_hund_s, 10);
- }
- else
- {
- zang = disp_ang * 2;
- call disp_ref_ang;
- }
- return;
- disp_ref_ang:
- // Subroutine that displays the reflection angle.
- SetWallCel(vec_one_s, Zang % 10);
- SetWallCel(vec_ten_s, (Zang / 10) % 10);
- SetWallCel(vec_hund_s, (Zang / 100) % 10);
- return;
-
- end
-
-