home *** CD-ROM | disk | FTP | other *** search
/ Classic Fond 52 / ClassicFond52.iso / GAMES / DROIDW.RAR / DWCD.GOB / mission_cog_cc_mirror.cog < prev    next >
Encoding:
Text File  |  1998-11-04  |  9.7 KB  |  381 lines

  1. #
  2. # CC_Mirror.cog
  3. #
  4. # Generic Mirror control Script
  5. #
  6. # 03/17/98 DGS Created
  7. # 03/21/98 DGS Added the keyframe control to make the thing accurate. 
  8. # 04/17/98 DGS Added the buffering system (Jean Jacques Perrey)
  9. #
  10. # (C) 1998 Lucas Learning Limited All Rights Reserved
  11. # ========================================================================================
  12.  
  13. symbols
  14. message           blocked
  15. message           arrived
  16. message            startup            
  17. message          timer
  18. message           entered    
  19. message           activated  
  20. message         pulse 
  21.                
  22.  
  23. ## ========================= Things
  24. thing            mirror_o
  25.  
  26. ## ========================= Cogs
  27. cog                laser_c
  28.  
  29. ## ========================= Surface 
  30. surface            left_s
  31. surface            right_s
  32.  
  33. surface            ang_one_s        nolink
  34. surface            ang_ten_s         nolink
  35. surface            ang_hund_s         nolink
  36. surface            ang_LR_s        nolink
  37. surface            dummy0_s        nolink
  38. surface            dummy1_s        nolink
  39. surface            dummy2_s        nolink
  40.  
  41. surface            vec_one_s         nolink
  42. surface            vec_ten_s         nolink
  43. surface            vec_hund_s          nolink
  44.  
  45.  
  46. sound        rot_snd=MCH02Mirror.WAV        local
  47. sound        compute_snd=CMP04Calc.WAV        local
  48. sound        act_snd=SWT00DrSwtch.WAV   local
  49. ## ========================== Key Angle integers
  50. int                key2_ang    
  51. int                key3_ang
  52. int                key4_ang
  53. int                key5_ang        
  54.  
  55. int                laser_i=0        local
  56. int                l_color=1        local
  57. flex            l_radius=0.005    local
  58. flex            Mirrorang=0        local
  59. int                selection=0        local
  60. int                zang=0            local
  61. int                add_ang=0        local
  62. int                vec_ang=0        local
  63. int                dest_ang=0        local
  64. int                disp_ang=0        local
  65. int                active=0        local
  66. int                pulsemode=0        local
  67. int                pulsecount=0    local
  68. int                buffer=0        local
  69. int                set=0            local
  70. int                playit=0        local
  71. int                arrive_flag=0    local
  72. int                mirror_id=0        
  73. end
  74.  
  75. # ========================================================================================
  76.  
  77. code
  78. startup:
  79.     setwallcel(dummy0_s,10);
  80.     setwallcel(dummy1_s,10);
  81.     setwallcel(dummy2_s,10);
  82.     
  83.     call cue_angle;
  84.     //pulsemode = 2;
  85.     //setpulse(0.25);
  86.     
  87.     return;
  88.  
  89. activated:
  90.     print("activated");
  91.     // Acitvated routine controls the rotation of the mirror. 
  92.     print("Buffer: ");
  93.     printint(buffer);
  94.     selection = getsenderref();
  95.     call rotate_mirror;
  96.     return;
  97.  
  98. rotate_mirror:    
  99.     // This rouitne is called buy both activated and by the timer, and is used to actually setup rotation of the mirror. 
  100.     // Another routine called "rotation" is used for common setup stuff.
  101.     print("Buffer: ");
  102.     printint(buffer);
  103.     
  104.     if (active == 0)        // if the mirror is currently  not rotating
  105.         {
  106.         if ((selection == left_s) || (selection == right_s))  //if it was a switch that was activated
  107.             {
  108.             if (global9 == 1)        //if the laser's turned on
  109.                 {
  110.                 sendmessage(laser_c,user0);    // Tell the laser cog to turn off
  111.                 settimer(2);
  112.                 setwallcel(left_s,1);
  113.                 setwallcel(right_s,1);
  114.                 }
  115.             else                     // else the laser must be off.
  116.                 {
  117.                 if (selection == left_s)
  118.                     {
  119.                     if (( mirrorang + 5) < 81)      // if the mirror's not gonna go past 80
  120.                         {
  121.                         if (sounder >0) {stopsound(sounder,0.2); sounder = -1;}
  122.                         
  123.                         print("rotate left");    
  124.                         rotatepivot(mirror_o,1,-1);
  125.                         garbage = playsoundthing(rot_snd,mirror_o,1.0,-1,-1,0);
  126.                         setwallcel(left_s,1);
  127.                         garbage = playsoundpos(act_snd,getsurfacecenter(left_s),0.5,-1,-1,0);
  128.                         setwallcel(right_s,0);
  129.                         add_ang = 1;
  130.                         dest_ang = mirrorang + 5;
  131.                         arrive_flag = 0;
  132.                         call rotation;
  133.                         }
  134.                     else 
  135.                         {
  136.                         buffer = 0;
  137.                         dwPlayCammySpeech(16025, "M4ca022.wav", 10, 0);        //That's as far as it goes in that dir
  138.                         }
  139.                     }    
  140.                 if (selection == right_s)
  141.                     {
  142.                     if (( mirrorang - 5) > -81)        //if the mirror's no gonna go pas -80
  143.                         {
  144.                         if (sounder >0) {stopsound(sounder,0.2); sounder = -1;}
  145.                         
  146.                         print("rotate right");    
  147.                         rotatepivot(mirror_o,1, 1);
  148.                         garbage = playsoundthing(rot_snd,mirror_o,1.0,-1,-1,0);
  149.                         setwallcel(right_s,1);
  150.                         garbage = playsoundpos(act_snd,getsurfacecenter(left_s),0.5,-1,-1,0);
  151.                         setwallcel(left_s,0);
  152.                         add_ang = -1;
  153.                         dest_ang = mirrorang - 5;
  154.                         arrive_flag = 0;
  155.                         call rotation;
  156.                         }
  157.                     else 
  158.                         {
  159.                         buffer = 0;
  160.                         dwPlayCammySpeech(16025, "M4ca022.wav", 10, 0);        //That's as far as it goes in that dir
  161.                         }
  162.                     }
  163.                 } 
  164.             }
  165.         }
  166.     else //the mirror is moving
  167.         {
  168.         ///////     BUFFER STUF
  169.         if (selection == left_s)
  170.             {
  171.             buffer = buffer + 1;
  172.             }
  173.         if (selection == right_s)
  174.             {
  175.             buffer = buffer - 1;
  176.             }        
  177.         }
  178.         return;
  179.  
  180. rotation:
  181.     // This routine handles stuff common to both rotating left and right.
  182.     if (playit == 0)
  183.         {
  184.         dwPlayCammySpeech(16022, "M4ca020.wav", 10, 0);        //I can hear the mirrror turning up there.
  185.         playit = 1;
  186.         }
  187.     active = 1;
  188.     vec_ang = 0;
  189.     pulsemode = 1;
  190.     setpulse(0.09);
  191.     return;
  192.  
  193. timer:
  194.     // Used to set a delay between the mirror turning off and rotation of the mirror. 
  195.     call rotate_mirror;
  196.     return;
  197.     
  198.  
  199. pulse:
  200.     // Controls cycling of the numbers. 
  201.     if (pulsemode == 1)
  202.         {
  203.         mirrorang = mirrorang + add_ang;
  204.         call displayang;
  205.         if (mirrorang == dest_ang) 
  206.             {
  207.             setpulse(0);
  208.             vec_ang = 1;
  209.             arrive_flag = arrive_flag + 1;
  210.             call check_buffer;
  211.             }
  212.         }
  213.     else if (pulsemode == 2)
  214.         {
  215.         pulsecount = 0;
  216.         pulsemode = 3;
  217.         }
  218.     if (pulsemode == 3)
  219.         {
  220.         // Random angle mode, "Calculating..."
  221.         //set = ((rand()*9));
  222.         //set = (set * 10) + (rand()*9);
  223.         zang = (rand()*999);
  224.         call disp_ref_ang;
  225.         pulsecount = pulsecount + 1;
  226.         if (pulsecount == 13)        // If it's calculated long enough
  227.             {
  228.             pulsemode = 0;
  229.             call displayang;            // show the real angle. 
  230.             if (sounder >0) {stopsound(sounder,0.1); sounder = -1;}
  231.             setpulse(0);
  232.             }
  233.         }
  234.     return;
  235.         
  236. arrived:
  237.     //call displayang;
  238.     active = 0;
  239.     setwallcel(left_s,0);
  240.     setwallcel(right_s,0);
  241.     // The following lines control "snapping" the mirrors to the correct angle when they reach their desitination.
  242.     // This is because rotatepivot is not accurate enough for the needed angles. 
  243.     if (dest_ang == 0)
  244.         {
  245.         print("Reset angle at key 0");
  246.         jumptoframe(mirror_o,0,getthingsector(mirror_o));
  247.         }
  248.     else if ((dest_ang == key2_ang) && (key2_ang != 0) )
  249.         {
  250.         print("Reset angle at key 2");
  251.         jumptoframe(mirror_o,2,getthingsector(mirror_o));
  252.         }
  253.     else if ((dest_ang == key3_ang) && (key3_ang != 0)  )
  254.         {
  255.         print("Reset angle at key 3");
  256.         jumptoframe(mirror_o,3,getthingsector(mirror_o));
  257.         }
  258.     else if ((dest_ang == key4_ang) && (key4_ang != 0)  )
  259.         {
  260.         print("Reset angle at key 4");
  261.         jumptoframe(mirror_o,4,getthingsector(mirror_o));
  262.         }
  263.     else if ((dest_ang == key5_ang) && (key5_ang != 0)  )
  264.         {
  265.         print("Reset angle at key 5");
  266.         jumptoframe(mirror_o,5,getthingsector(mirror_o));
  267.         }
  268.     call cue_angle;
  269.     arrive_flag = arrive_flag + 1;
  270.     call check_buffer;
  271.     return;
  272.     
  273. check_buffer:
  274.     if (arrive_flag == 2)
  275.     {
  276.         // ==============================  Buffer stuff
  277.         if ( buffer > 0 ) //If there's  Left commands in the buffer
  278.             {
  279.             selection = left_s;
  280.             buffer = buffer - 1;
  281.             call rotate_mirror;
  282.             }
  283.         else if ( buffer < 0 ) // If there's Right commands in the buffer 
  284.             {
  285.             selection = right_s;
  286.             buffer = buffer + 1;
  287.             call rotate_mirror;
  288.             }
  289.         else        //Else there's nothing left for it to do.
  290.             {
  291.             // Start up the randomizer
  292.             pulsemode = 2;
  293.             setpulse(0.025);
  294.             sounder = playsoundthing(compute_snd,mirror_o,1.0,-1,-1,0);
  295.             }
  296.     }
  297.     return;
  298.             
  299. cue_angle:
  300.     // This routine is used to set the correct global variable to the proper value. 
  301.     // Since this cog is used in many locations in the level, this routine is needed 
  302.     // to set the correct global variable.
  303.             if (mirror_id == 0) global0 = mirrorang;
  304.     else     if (mirror_id == 1) global1 = mirrorang;
  305.     else     if (mirror_id == 2) global2 = mirrorang;
  306.     else     if (mirror_id == 3) global3 = mirrorang;
  307.     else     if (mirror_id == 4) global4 = mirrorang;
  308.     else     if (mirror_id == 5) global5 = mirrorang;
  309.     else     if (mirror_id == 6) global6 = mirrorang;
  310.     else     if (mirror_id == 7) global7 = mirrorang;
  311.     else     if (mirror_id == 8) global8 = mirrorang;
  312.     
  313.     //print("G0:");
  314.     //printint(global0);
  315.     //print("G1:");
  316.     //printint(global1);
  317.     //print("G2:");
  318.     //printint(global2);
  319.     //print("G3:");
  320.     //printint(global3);
  321.     //print("G4:");
  322.     //printint(global4);
  323.     //print("G5:");
  324.     //printint(global5);
  325.     //print("G6:");
  326.     //printint(global6);
  327.     //print("G7:");
  328.     //printint(global7);
  329.     //print("G8:");
  330.     //printint(global8);
  331.     //print("G9:");
  332.     //printint(global9);
  333.  
  334.     return;
  335.     
  336.  
  337.  
  338. displayang:
  339.     // This routine handles the display of angles. 
  340.     if (mirrorang < 0)        //if the mirror is rotated in the negitive   
  341.         {
  342.         disp_ang = 0-mirrorang;        // Reverse the display number
  343.         setwallcel(ang_lr_s,1);        // Set the left/right indicator to right
  344.         }
  345.     else 
  346.         {
  347.         disp_ang = mirrorang;         //use the correct diaply number 
  348.         setwallcel(ang_lr_s,2);        // set the left/right indicator to left
  349.         }
  350.     if (mirrorang == 0) setwallcel(ang_lr_s,0); // If the mirror's at 0 set the left right indicator to nothing.     
  351.  
  352.    // Set the angle  of mirror 
  353.    SetWallCel(ang_one_s,      disp_ang %  10);
  354.    SetWallCel(ang_ten_s,     (disp_ang / 10) % 10);
  355.    SetWallCel(ang_hund_s,     (disp_ang / 100) % 10);
  356.    
  357.  
  358.     // set the angle of relfection 
  359.     if (vec_ang == 0) 
  360.         {
  361.         zang = 0;
  362.         SetWallCel(vec_one_s,      10);
  363.         SetWallCel(vec_ten_s,      10);
  364.         SetWallCel(vec_hund_s,      10);
  365.         }
  366.     else 
  367.         {
  368.         zang = disp_ang *    2;
  369.         call disp_ref_ang;
  370.          }
  371.   return;
  372.   disp_ref_ang:
  373.    // Subroutine that displays the reflection angle. 
  374.    SetWallCel(vec_one_s,      Zang %  10);
  375.    SetWallCel(vec_ten_s,     (Zang / 10) % 10);
  376.    SetWallCel(vec_hund_s,     (Zang / 100) % 10);
  377.    return;
  378.  
  379. end
  380.  
  381.