///////////////////////////////////////////////////////////////////////////////////////////////////////
// copy / overwrite the files inside this folder in your game folder (work if you are using the templates)
// don't forget to include breakglass.wdl in your main game file (office.wdl if you are using the templates)
// create a wmb entity for the glass, place it in the level and attach it the action breakable_glass
///////////////////////////////////////////////////////////////////////////////////////////////////////

string gibglass_mdl = <gibglass.mdl>; // glass gibblet

///////////////////////////////////////////////////////////////////////////////////////////////////////

sound breakglass_snd = <breakglass.wav>;

///////////////////////////////////////////////////////////////////////////////////////////////////////

function glass_pieces();
function gib_glass();

///////////////////////////////////////////////////////////////////////////////////////////////////////

action breakable_glass
{
	my.transparent = on;
	my.enable_impact = on;
	my.enable_entity = on;
	my.enable_shoot = on;
	my.event = glass_pieces;
}

function glass_pieces()
{
	wait (1);
	if (you == player) {player._health -= 20;} // decrease player's health if it breaks the window by passing through it
	my.passable = on;
	snd_play (breakglass_snd, 50, 0);
	my.skill10 = 0;
	my.invisible = on; // we keep the window for now because we want to use its skill10
	while (my.skill10 < 15)
	{
		create (gibglass_mdl, my.pos, gib_glass); // creates 15 glass fragments
		my.skill10 += 1;
		wait (1);
	}
	ent_remove (me); // no need to use skill10 from now on so we remove the window
}

function gib_glass()
{
	my.transparent = on;
	my.skill1 = random(200) - 100; 
	my.skill2 = (random(100) + 25) * sign (my.y - player.y);
	my.skill3 = -random(25) - 10;
	my.skill1 *= time; // all the values (skill1..skill3) are multiplied with time
	my.pan = random(360);
	my.tilt = random(360);
	my.roll = random(360);
	while(my.skill40 < 10) 
	{		
		move_mode = ignore_passable;
		ent_move (nullvector, my.skill1);
		my.skill3 -= 20 * time;
		my.skill40 += time;
		wait(1);
	}
	my.passable = on;
	while (my.alpha > 0)
	{
		my.alpha -= 0.3 * time;
		wait (1);
	}
	ent_remove (me);
}

