/*
+-----+
|Splat|
+-----+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+
| Scratch                                      Http://www.admdev.com/scratch |
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
| Blood splats from Inside3D.com							     |
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
*/

float() crandom; //function prototype for crandom

void() SplatThink =
{
        if ((self.attack_finished <= time) || (self.flags & FL_ONGROUND))
		    remove(self);
        self.velocity_z = random() * -18;
        self.angles = vectoangles(self.velocity);
        self.nextthink = time + 0.2;
};

void() SplatTouch =
{
        if ((other != world) || (pointcontents(self.origin) <= -3) || (self.flags & FL_ONGROUND))
                remove(self);

	  self.velocity = '0 0 0';
        self.movetype = MOVETYPE_FLY;
        self.touch = SUB_Null;
        self.attack_finished = time + 2 + (5*random());

        self.think = SplatThink;
        self.nextthink = time + 0.2;
};

void(vector dir, vector org, entity own) ThrowBloodSplat =
{
        local entity splat;

        if (!((own.flags & FL_MONSTER) || (own.classname == "player")))
                return;

        splat = spawn();
        splat.owner = own;
        splat.movetype = MOVETYPE_TOSS;
        splat.solid = SOLID_BBOX;

        dir = normalize(dir);
        splat.velocity = dir * (450 + 50*random());
        splat.velocity_x = splat.velocity_x + crandom()*40;
        splat.velocity_y = splat.velocity_y + crandom()*40;
        splat.velocity_z = splat.velocity_z + 120 + 50*random();
        splat.touch = SplatTouch;
	
        splat.nextthink = time + 2;
        splat.think = SUB_Remove;

        setmodel (splat, "progs/bldsplt.mdl");
        setsize (splat, '0 0 0', '0 0 0');     
        setorigin (splat, org);
};