home *** CD-ROM | disk | FTP | other *** search
- # Droids Cog Script
- #
- # b0_Gear.cog
- #
- # Gear Cog controlling movement of the bridge and gears assmebly.
- #
- # Desc:
- # bin 25 Small Gears
- # bin 27 Large Gear
- #
- # This cog is responsible for keeping track of what gears are in the Gear assembly
- # and where. It's also in charge of mocing the bridge either up or down depending on
- # how the gears are in place. There are seperate cogs for the gear pieces themselves
- # when found on the ground. After they've been placed in the gear assembly, they're
- # part of this script.
- #
- #
- # 10/23/97 [DGS] Created
- # 01/19/97 [DGS] Updated for new controls.
- # 01/21/97 [DGS] Rewrote majority of it; added new Used and Taken sections
- # 03/12/98 [JP] Modified to fit the training ground
- # ========================================================================================
-
- symbols
- message used
- message startup
- message arrived
- message user0
- message taken
- message timer
-
-
- thing gear_bot
- surface Button0 linkid=2
- surface gearlarge linkid=3
- surface gearsmall linkid=4
-
- ## Ghost objects
- thing l_spindle_g linkid=30
- thing r_spindle1_g linkid=31
-
- ## Ghost creation integers
- int l_spindle_i=0 linkid=30 local
- int r_spindle1_i=0 local
-
- ## Spin Directon integers
- flex l_spindle_d=0.0 local
- flex r_spindle1_d=0.0 local
-
- ## templates
- template gear_large_t
- template gear_small_t
-
- ## Sectors
- sector L_Sector
- sector R_sector
-
- ## Cogs
- cog button_cog
-
- ## Interal variables
-
- float speed=2.0 local
- int on_button=0 local
- int rotate local
- int l_spindle=0 local
- int r_spindle1=0 local
- int timermode=0 local
- int part_id=0 local
-
- sound gearon=swtt9gearon.wav local
- sound gearoff=swtt9gearoff.wav local
- sound turnfree=mcht9motfree.wav local
- sound turngears=mcht9motstrss.wav local
-
- int show_once=1 local
-
- sound gearstart=MCHt9MotStrt.wav local
- sound gearstop=MCHt9MotStp.wav local
-
- end
-
- # ========================================================================================
-
- code
-
- startup:
-
- return;
-
- # ........................................................................................
- user0:
- // User0 gets called when the player hits the motor switch. See gear_activate.cog
- print("user0");
- //if (rotate == 0)
- call start_motor;
- return;
- used:
- // Section is executed when the user uses an inventory object. Cool.
- print("USED:");
- printint(dwGetActivateBin());
- printint(getsenderid());
- if (rotate == 0)
- {
- if ( getinv(getlocalplayerthing(),dwGetActivateBin()) > 0) //if the bin has more than 0 in it;
- {
- if (GetSenderId() == 3) // It's used on the gearlarge surface
- {
- call handle_l;
- }
- //printint(getthingsector(getlocalplayerthing()));
- //printint(L_sector);
- // The Gear Assembly was activated
- //if (getthingsector(getlocalplayerthing()) == L_sector)
- // {
- //=================== Player is on the Large gear side of the gear assembly
- // print("Activated L sector");
- // call handle_l;
- // }
-
- //if (getthingsector(getlocalplayerthing()) == r_sector)
- // {
- // //=================== Player is on the Small gear side of the gear assembly
- // print("Activated R sector");
- // call handle_r;
- // }
- //}
- if (GetSenderId() == 4) // It's used on the gearsmall surface
- {
- call handle_r;
- }
- //printint(getthingsector(getlocalplayerthing()));
- //printint(R_sector);
- //if (getthingsector(getlocalplayerthing()) == R_sector)
- // {
- // print("Activated R sector");
- // call handle_r;
- // }
- }
- }
-
- return;
-
-
- taken:
- print("taken");
- printint(r_spindle1);
- printint(getsenderid());
-
- // Taken gets called when the user attempts to take a gear from left or right of the gear assembly.
- if (rotate == 0)
- {
- if (GetSenderId() == 3)
- {
- // The Gear Assembly was activated
- if (l_spindle != 0)
- {
- // inc the bin to add it back to the inv, destroy the environment one ans set l_spindle to 0.
- ChangeInv(getlocalplayerthing(), l_spindle, 1);
- destroything(l_spindle_i);
- l_spindle = 0;
- call update_bins;
- }
- else
- {
- // TELL THE PLAYER THERE'S NOTHING TO TAKE
- // //There's nothing to take
- timermode = 2;
- settimer(10);
- }
- }
- if (GetSenderId() == 4)
- {
- //=================== Player is on the Small gear side of the gear assembly
- if (r_spindle1 != 0) //if the top spindle (1) has something on it.
- {
- ChangeInv(getlocalplayerthing(), r_spindle1, 1);
- destroything(r_spindle1_i);
- r_spindle1 = 0;
- call update_bins;
- }
-
-
- else //else there's nothing on this side. Both spindles are empty.
- {
- // //There's nothing to take
- timermode = 2;
- settimer(10);
- }
- }
- }
- return;
- start_motor:
- if ((l_spindle != 27) && (r_spindle != 25))
- { //nothing's on
- l_spindle_d = 0;
- r_spindle1_d = 0;
- call rotate_gears;
- timermode =1;
- settimer(7);
- }
-
- else if ((l_spindle == 27) && (r_spindle1 == 25))
- { // large in left, small in right
- l_spindle_d = -7;
- r_spindle1_d = 7;
- call rotate_gears;
- timermode =1;
- settimer(7);
- }
-
- else if ((l_spindle == 25) && (r_spindle1 != 25))
- { // only small in left
- l_spindle_d = 0;
- r_spindle1_d = 0;
- call rotate_gears;
- timermode =1;
- settimer(7);
- }
-
- else if ((l_spindle == 27) && (r_spindle1 != 25))
- { // only large in left
- l_spindle_d = -7;
- r_spindle1_d = 0;
- call rotate_gears;
- timermode =1;
- settimer(7);
- }
-
- else if ((l_spindle !=27) && (r_spindle1 == 25))
- { // only small in right
- l_spindle_d = 0;
- r_spindle1_d = 0;
- call rotate_gears;
- timermode =1;
- settimer(7);
- }
-
- return;
- rotate_gears:
- //This routine starts the gears a spinnin'. After they're goin', continue_gears is used to keep the thing spinning.
- rotate = 1;
- //RotatePivot(screw0, 1, 1);
- RotatePivot(gear_bot, 1, 7);
- print("Rotates!");
- printint(l_spindle_d);
- if (!(l_spindle_d == 0.0)) RotatePivot(l_spindle_i, 1, l_spindle_d);
- if (!(r_spindle1_d == 0.0)) RotatePivot(r_spindle1_i, 1, r_spindle1_d);
- playsoundlocal(gearstart, 1, 0, 0);
- turngearsi=playsoundthing(turngears, gear_bot, 1, -1, -1, 0x1);
- return;
-
- //continue_gears:
- // printint(getsenderid());
- // if (!(l_spindle_d == 0.0)) RotatePivot(l_spindle_i, 1, l_spindle_d);
- // if (!(r_spindle1_d == 0.0)) RotatePivot(r_spindle1_i, 1, r_spindle1_d);
- // if (getsenderid() == 11) RotatePivot(gear_bot, 1, 3);
- // return;
-
- stop_gears:
- //this routine stops all motion of the gears when it's called. Hopefully. Otherwise, well. Otherwise.
- stopsound(turngearsi, 0.2);
- playsoundlocal(gearstop, 1, 0, 0);
- stopthing(r_spindle1_i);
- stopthing(l_spindle_i);
- stopthing(gear_bot);
- rotate = 0;
- return;
-
- handle_l:
- // handle_l is used to put gears on the left side of the assembly. handle_r is for the right. Taken handles removing gears.
- //playsoundlocal(gearon, 1, 0, 0);
- print("handle_l:");
- if (l_spindle == 0) //if the spindle is empty
- {
- //============ Add whatever you gots to the spindle
- if ((dwGetActivateBin() > 24) && (dwGetActivateBin() < 28)) // if it's one of the gears that's being used
- {
- l_spindle = dwGetActivateBin();
-
- // Next l_spindle is queried to figure out what gear is going to be created. Then it's created
- if (l_spindle == 25)
- {
- print("gear small");
- l_spindle_i = creatething(gear_small_t, l_spindle_g);
- //if (show_once < 2)
- // {
- // dwplaycammyspeech(16153, "TGCA033.wav", 5, 2); //nicely done!
- // if (show_once == 1) show_once = 2;
- // }
- }
-
- else if (l_spindle == 27)
- {
- l_spindle_i = creatething(gear_large_t, l_spindle_g);
- print("gear large");
- if (show_once < 2)
- {
- dwplaycammyspeech(16153, "TGCA033.wav", 5, 2); //nicely done!
- if (show_once == 1) show_once = 2;
- }
- }
- // finally we decrement the bin that was activated.
- ChangeInv(getlocalplayerthing(), l_spindle, -1);
- playsoundlocal(gearon, 1, 0, 0);
- call update_bins;
- }
- }
- else
- {
- // TELL THE PLAYER THERE'S SOMETHING ON THE SPINDLE ALREADY
- //dwsetmissiontext(17304); //There's something on the spindle already!
- timermode = 2;
- settimer(10);
- }
-
- return;
-
- handle_r:
- // handle_r controls putting gears on the right side of the assemebly. handle_l is the left side. Taken controls removing gears for both l and r.
- //playsoundlocal(gearon, 1, 0, 0);
- print("handle_r:");
- // check the top spindle
- if (r_spindle1 == 0) //if the top spindle has something on it
- {
- //============ This section controls the upper spindle only (r_spindle1).
- if (dwGetActivateBin() == 25) // if it's the small gear
- {
- // check the comments from handle_l for info on the creation process of a gear. Then check with Doug
- r_spindle1 = dwGetActivateBin();
- r_spindle1_i = creatething(gear_small_t, r_spindle1_g);
- playsoundlocal(gearon, 1, 0, 0);
- ChangeInv(getlocalplayerthing(), r_spindle1, -1);
- call update_bins;
- }
- }
- return;
- # ............................................... .........................................
-
- timer:
- if (timermode == 1) //Will turn off the gears.
- {
- call stop_gears;
- rotate = 0;
- }
- else if (timermode == 2) //will clear Cammy's text
- {
- //dwsetmissiontext(00000); //clear Cammy's text
- }
- return;
-
- update_bins:
- // this is a utility routine used to turn on and off availability of items. Just until Jon adds it into DW for reals.
- //playsoundlocal(gearoff, 1, 0, 0);
- if ( getinv(getlocalplayerthing(),25) > 0)
- {
- SetInvAvailable(getlocalplayerthing(), 25, 1); //if the sm. bin has more than 0 turn on the inv icon;
- playsoundlocal(gearoff, 1, 0, 0);
- }
-
- else
- {
- SetInvAvailable(getlocalplayerthing(), 25, 0); // else turn it off;
- }
-
- if ( getinv(getlocalplayerthing(),27) > 0)
- {
- SetInvAvailable(getlocalplayerthing(), 27, 1); //if the lg. bin has more than 0 turn on the inv icon;
- playsoundlocal(gearoff, 1, 0, 0);
- }
-
- else
- {
- SetInvAvailable(getlocalplayerthing(), 27, 0); // else turn it off;
- }
-
- return;
- end
-
-