# Rbots auto-elevator
# makes life easier for both bots and player
# Note: mask=0x404 allows both players and actors to send messages
#
# Created by Raynar

symbols

message	blocked
message	touched
message	entered
message	activated
message	arrived

thing	elevator	mask=0x404	linkid=1
sector	top_sector	mask=0x404	linkid=2
sector	bot_sector	mask=0x404	linkid=3
surface	callbutton0	linkid=4
surface callbutton1	linkid=4
surface callbutton2	linkid=4
surface callbutton3	linkid=4

flex	start_wait=0.25
flex	sleeptime=2.0
flex	speed=4.0
sound	wav0=lvrclik1.wav
end

# ========================================================================================

code

arrived:
	if (getsenderid()!=1) return;
	setwallcel(callbutton0,0);
	setwallcel(callbutton1,0);
	setwallcel(callbutton2,0);
	setwallcel(callbutton3,0);
	return;

activated:
print("activated");
	if (getsenderid()==4 && !IsThingMoving(elevator))
	{
		PlaySoundPos(wav0, SurfaceCenter(GetSenderRef()), 1, -1, -1, 0);
		setwallcel(callbutton0,1);
		setwallcel(callbutton1,1);
		setwallcel(callbutton2,1);
		setwallcel(callbutton3,1);
		MoveToFrame(elevator, 1-GetCurFrame(elevator), speed);
	}
	return;

entered:
	if (getsenderid()==2 && GetCurFrame(elevator)==0 && !IsThingMoving(elevator))
	{
		MoveToFrame(elevator, 1, speed*2);
		return;
	}
	else if (getsenderid()==3 && GetCurFrame(elevator)==1 && !IsThingMoving(elevator))
	{
		MoveToFrame(elevator, 0, speed*2);
		return;
	}
	else if (getsenderid()==1) call touched;
	return;

touched:
	sleep(start_wait);
	if (GetCurFrame(elevator)==0  && !IsThingMoving(elevator))
	{
		MoveToFrame(elevator, 1, speed);
	}
	if (GetCurFrame(elevator)==1  && !IsThingMoving(elevator))
	{
		MoveToFrame(elevator, 0, speed);
	}
	return;

blocked:
print("blocked");
	MoveToFrame(elevator, 1-GetGoalFrame(elevator), speed);
	return;

end

