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

  1. # Droids Cog Script
  2. #
  3. # 00_Door_switch.cog
  4. #
  5. # Generic Door Script
  6. #
  7. #         [IS]
  8. # 01/30/98    [DGS]    Added the switch
  9. # ========================================================================================
  10.  
  11. symbols
  12.     message    startup        
  13.     message    activate    
  14.     message    arrived        
  15.     message    timer        
  16.     message    blocked        
  17.     message    pulse
  18.     
  19.     thing        door0        linkid=0 mask=0x405
  20.     thing        door1        linkid=1 mask=0x405
  21.     thing        door2        linkid=2 mask=0x405
  22.     thing        door3        linkid=3 mask=0x405
  23.  
  24.     float        moveSpeed=8.0
  25.     float        sleepTime=2.0
  26.     float        lightValue=0.5
  27.  
  28.     surface        button0    linkid=5
  29.     surface        button1    linkid=5
  30.     
  31.     sector    doorSector    local
  32.     
  33.     int        numDoors=0    local
  34.     int        doorStatus    local
  35.     int        moveStatus    local
  36.     int        i                local
  37.  
  38.         sound     act_snd=SWT00DrSwtch.WAV        local
  39. end
  40.  
  41. # ========================================================================================
  42.  
  43. code
  44.  
  45. startup:
  46.         setwallcel(button0,1);
  47.         setwallcel(button1,1);
  48.     for (i=0; i<=3; i=i+1)
  49.         if (door0[i] >= 0) numDoors = numDoors + 1;
  50.  
  51.     doorSector = GetThingSector(door0);
  52.     SetSectorAdjoins(doorSector, 0);
  53.     SetSectorLight(doorSector, lightValue, 0.0);        // add some light to door sector
  54.     return;
  55.  
  56. # ........................................................................................
  57.  
  58. activate:
  59.     if (getsenderid() == 5)
  60.         {
  61.         call CheckStatus;
  62.         if (moveStatus) return;
  63.         if (doorStatus == 0) 
  64.             {                    // all pieces are at frame 0
  65.             garbage = playsoundpos(act_snd,getsurfacecenter(button0),0.5,-1,-1,0);
  66.             garbage = playsoundpos(act_snd,getsurfacecenter(button1),0.5,-1,-1,0);
  67.             SetSectorAdjoins(doorSector, 1);
  68.             setwallcel(button0,2);
  69.             setwallcel(button1,2);
  70.             call OpenDoors;
  71.             }
  72.         }
  73.     return;
  74.  
  75. # ........................................................................................
  76. pulse:
  77.         setwallcel(button0,2-getwallcel(button0));
  78.     setwallcel(button1,2-getwallcel(button1));
  79.     return;
  80. arrived:
  81.     call CheckStatus;
  82.     if (moveStatus) return;
  83.         if (doorStatus == numDoors) 
  84.         {                // all pieces are at frame 1
  85.         SetTimer(sleepTime);
  86.         setpulse(0.4);
  87.         } 
  88.     else if (doorStatus == 0) 
  89.         {                // all pieces are at frame 0
  90.         SetSectorAdjoins(doorSector, 0);
  91.                 setwallcel(button0,1);
  92.         setwallcel(button1,1);
  93.         }
  94.     return;
  95.  
  96. # ........................................................................................
  97.  
  98. blocked:
  99.     call OpenDoors;
  100.     return;
  101.  
  102. # ........................................................................................
  103.  
  104. timer:
  105.     setpulse(0);
  106.         setwallcel(button0,2);
  107.     setwallcel(button1,2);
  108.     call CloseDoors;
  109.     return;
  110.  
  111. # ........................................................................................
  112.  
  113. OpenDoors:
  114.     for (i=0; i<=3; i=i+1)
  115.         if (door0[i] >= 0) MoveToFrame(door0[i], 1, moveSpeed);
  116.     return;
  117.  
  118. # ........................................................................................
  119.  
  120. CloseDoors:
  121.     for (i=0; i<=3; i=i+1)
  122.         if (door0[i] >= 0) MoveToFrame(door0[i], 0, moveSpeed);
  123.     return;
  124.  
  125. # ........................................................................................
  126.  
  127. CheckStatus:
  128.     moveStatus = 0;
  129.     doorStatus = 0;
  130.  
  131.     for (i=0; i<=3; i=i+1) {
  132.         if (door0[i] >= 0) {
  133.             moveStatus = moveStatus + IsThingMoving(door0[i]);
  134.             doorStatus = doorStatus + GetCurFrame(door0[i]);
  135.         }
  136.     }
  137.     return;
  138.  
  139. end
  140.  
  141.