# Jedi Knight Cog Script
#
# This will generate a series of 4 TD's per 'round' when
# the switch is activated. 
# The trap resets in 'delay' seconds afterwards.
#
# Modified for Rbots - Nar Shadaa Loading Terminal by Raynar

symbols

message		activated
message		trigger

surface		switch		desc=switch

thing		tdg1			nolink,desc=tdg1
thing		tdg2			nolink,desc=tdg2
thing		tdg3			nolink,desc=tdg3
thing		tdg4			nolink,desc=tdg4

int			rounds=2		desc=rounds

flex		rate=0.1		desc=rate
flex		delay=3.0		desc=delay

int			firing=0		local
int			cur_round=0		local
int			dummy			local

template	proj_tpl=+grenade2		local

sound		on_snd=set_hi2.wav		local
sound		off_snd=lgclick1.wav	local

thing		rbot	local
flex		dist	local

end

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

code

activated:
	if(firing == 1) Return;

	firing = 1;
	dummy = SetWallCel(switch, 1);
	dummy = PlaySoundPos(on_snd, SurfaceCenter(switch), 1.0, 5.0, 10.0, 0);
	

	cur_round = 0;
	while(cur_round < rounds)
	{
		dummy = CreateThing(proj_tpl, tdg1);
		Sleep(rate);
		dummy = CreateThing(proj_tpl, tdg2);
		Sleep(rate);
		dummy = CreateThing(proj_tpl, tdg3);
		Sleep(rate);
		dummy = CreateThing(proj_tpl, tdg4);
		Sleep(rate);

		cur_round = cur_round + 1;
	}

	Sleep(delay);
	dummy = SetWallCel(switch, 0);
	dummy = PlaySoundPos(off_snd, SurfaceCenter(switch), 1.0, 5.0, 10.0, 0);
	firing = 0;
	Return;

trigger:
	if (getsourceref() == 11030)
	{
		rbot = GetParam(1);
		dist = VectorDist(GetThingPos(rbot), SurfaceCenter(switch));
		if (dist < 0.5) call activated; // if bot is close enough, activate switch
	}
	return;

end

