void() flare_touch =
{
local float rand;
	if (other == self.owner)
		return;

        if (other.classname == "door" || other.classname == "plat")
                {
                remove(self);
                return;
                }

	if (other.solid == SOLID_TRIGGER)
		return; // trigger field, do nothing

	if (pointcontents(self.origin) == CONTENT_SKY)
	{
		remove(self);
		return;
	}
	
	if (other.takedamage)
	{
		spawn_touchblood (9);
		T_Damage (other, self, self.owner, 1);

	      if (self.velocity != '0 0 0')
			remove(self);
	}
	else
	{
		WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
		WriteByte (MSG_BROADCAST, TE_SPIKE);
		WriteCoord (MSG_BROADCAST, self.origin_x);
		WriteCoord (MSG_BROADCAST, self.origin_y);
		WriteCoord (MSG_BROADCAST, self.origin_z);
	}
	self.movetype = MOVETYPE_NONE;
        self.origin = self.origin - self.velocity * 0.005;
     	self.velocity = '0 0 0';
	self.touch = SUB_Null;
};

void() flare_dim =
{
        self.effects=EF_DIMLIGHT;
	self.nextthink = time + 15;
	self.think = SUB_Remove;
};

void() flare_bright =
{
	local vector    vel;
        self.effects=EF_BRIGHTLIGHT;
	self.nextthink = time + 10;
	self.think = flare_dim;
	sound (self, CHAN_WEAPON, "misc/power.wav", 1, ATTN_NORM);
	vel = '0 0 150';
	particle (self.origin+vel*0.01,vel,111,150);
        vel = '0 0 120';
	particle (self.origin+vel*0.01,vel,73,200);
};

void(vector org, vector dir) launch_flare =
{
	local   entity  missile;

	missile = spawn ();
	missile.owner = self;
	missile.movetype = MOVETYPE_FLYMISSILE;
        missile.classname = "flare";
        missile.health = 3;
        missile.takedamage = DAMAGE_AIM;
        missile.th_die = SUB_Remove;
	missile.solid = SOLID_BBOX;
	missile.angles = vectoangles(dir);
	missile.touch = flare_touch;
	missile.think = flare_bright;
	missile.nextthink = time + 3;
	setmodel (missile, "progs/laser.mdl");
        setsize (missile, VEC_ORIGIN, VEC_ORIGIN);               
	setorigin (missile, org);
	missile.velocity = dir * 1000;
        missile.effects=EF_DIMLIGHT;
};
