# Jedi Knight Cog Script
#
# prl_elevmaster3.cog
# Adapted from 00_elevcall.cog and 00_elev_switch.cog
# Sylvicolus [PRL] 6 August 2001
# http://www.lactarius.com/sylvicolus/jk/
#
# This Cog controls one master elevator servicing 3 floors.
# Start floor is the frame that the elevator is at when the power is off.
# The master switch turns on the elevator and calls it to the master floor frame.
# The first and third floor have only call buttons, cross adjoins to move it.
# The second floor (frame 1) has call button and up and down buttons.
# Remember that the elevator's first frame is 0 even though your
# start floor and master floor can be any of the three frames.
# When the elevator is activated, its sector is fully lit, as well as sector1, sector2.
#
# Not supported by LucasArts Entertainment Co.
symbols
message startup
message activated
message crossed
thing elevator
int startfloor=2 //frame that elevator starts game at
int masterfloor=1 //master floor frame
surface masterswitch //turns power on and off
surface callbutton0 //calls elevator to level 0
surface callbutton1 //calls elevator to level 1
surface callbutton2 //calls elevator to level 2
surface upbutton //sends elevator up
surface dnbutton //sends elevator down
surface lower_adjoin0 linkid=1
surface lower_adjoin1 linkid=1
surface lower_adjoin2 linkid=1
surface upper_adjoin0 linkid=3
surface upper_adjoin1 linkid=3
surface upper_adjoin2 linkid=3
sound callbutt=beep2.wav local
sound updnbutt=beep1.wav local
sound nopower=lgclick1.wav local
sound poweron=set_hi2.wav local
sound poweroff=set_vlo2.wav local
flex speed=5.0 local //speed of elevator
flex start_wait=0.4 local //pause before moving up
int switch local //check variable for cog internal use
int power=0 local
int active=0 local
sector elevSector local //elevator sector
int light=1 local //extra light for sector
int delay=1 local //light delay
sector sector1 //updn switch sectors that also get extra light
sector sector2
end
## -------------------------------------------------------------------
code
startup:
sleep(1.0);
MoveToFrame(elevator,startfloor,speed);
elevSector = GetThingSector(elevator);
return;
activated:
if (active) return;
active=1;
switch = GetSenderRef();
sleep(0.2);
if (!power)
{
if (switch != masterswitch)
{
PlaySoundPos(nopower, SurfaceCenter(switch), 1, -1, -1, 0 );
active=0;
return;
}
else //switch == masterswitch
{
power=1;
PlaySoundPos(poweron, SurfaceCenter(masterswitch), 1, -1, -1, 0 );
SetWallCel(masterswitch,1);
SetSectorLight(elevSector,light,delay);
SetSectorLight(sector1,light,delay);
SetSectorLight(sector2,light,delay);
sleep(0.5);
MoveToFrame(elevator,masterfloor,speed);
WaitForStop(elevator);
active=0;
return;
}
}
else //we have power
{
if (switch == masterswitch) //turn off power
{
power=0;
PlaySoundPos(poweroff, SurfaceCenter(masterswitch), 1, -1, -1, 0 );
SetWallCel(masterswitch,0);
SetSectorLight(elevSector,0,delay);
SetSectorLight(sector1,0,delay);
SetSectorLight(sector2,0,delay);
sleep(0.2);
MoveToFrame(elevator,startfloor,speed);
WaitForStop(elevator);
active=0;
return;
}
else if ((switch == callbutton0) && (GetCurFrame(elevator) != 0))
{
PlaySoundPos(callbutt, SurfaceCenter(callbutton0), 1, -1, -1, 0 );
SetWallCel(callbutton0,1);
MoveToFrame(elevator,0,speed);
WaitForStop(elevator);
SetWallCel(callbutton0,0);
}
else if ((switch == callbutton1) && (GetCurFrame(elevator) != 1))
{
PlaySoundPos(callbutt, SurfaceCenter(callbutton1), 1, -1, -1, 0 );
SetWallCel(callbutton1,1);
MoveToFrame(elevator,1,speed);
WaitForStop(elevator);
SetWallCel(callbutton1,0);
}
else if ((switch == callbutton2) && (GetCurFrame(elevator) != 2))
{
PlaySoundPos(callbutt, SurfaceCenter(callbutton2), 1, -1, -1, 0 );
SetWallCel(callbutton2,1);
MoveToFrame(elevator,2,speed);
WaitForStop(elevator);
SetWallCel(callbutton2,0);
}
else if ((switch == upbutton) && (GetCurFrame(elevator) == 1))
{
PlaySoundPos(updnbutt, SurfaceCenter(upbutton), 1, -1, -1, 0 );
SetWallCel(upbutton,1);
MoveToFrame(elevator,2,speed);
WaitForStop(elevator);
SetWallCel(upbutton,0);
}
else if ((switch == dnbutton) && (GetCurFrame(elevator) == 1))
{
PlaySoundPos(updnbutt, SurfaceCenter(dnbutton), 1, -1, -1, 0 );
SetWallCel(dnbutton,1);
MoveToFrame(elevator,0,speed);
WaitForStop(elevator);
SetWallCel(dnbutton,0);
}
}
active=0;
return;
crossed: // If player crosses adjoin(s)
if ((!power) || (active)) return;
active=1;
Sleep(start_wait); // pause before moving up
if ((GetSenderId() == 1) && (GetCurFrame(elevator) == 0)) // entered from lower floor
{
MoveToFrame(elevator,1,speed);
WaitForStop(elevator);
}
else if ((GetSenderId() == 3) && (GetCurFrame(elevator) == 2)) // entered from upper floor
{
MoveToFrame(elevator,1,speed);
WaitForStop(elevator);
}
active=0;
return;
end
|