/*
==============================================================================

BLOB

==============================================================================
*/

$cd UG/models/tarbaby
$origin 0 0 24
$base base		

$skin skin

$frame tarbabyc
$frame tarbabyd

void()	tbaby_stand1	=[	$tarbabyc,		tbaby_stand1	] {ai_stand();};

void()	tbaby_hang1		=[	$tarbabyc,		tbaby_hang1	] {ai_stand();};

void()	tbaby_walk1	=[	$tarbabyc,		tbaby_walk2	] {ai_turn();};
void()	tbaby_walk2	=[	$tarbabyc,		tbaby_walk3	] {ai_turn();};
void()	tbaby_walk3	=[	$tarbabyc,		tbaby_walk4	] {ai_turn();};
void()	tbaby_walk4	=[	$tarbabyc,		tbaby_walk5	] {ai_turn();};
void()	tbaby_walk5	=[	$tarbabyc,		tbaby_walk6	] {ai_turn();};
void()	tbaby_walk6	=[	$tarbabyc,		tbaby_walk7	] {ai_turn();};
void()	tbaby_walk7	=[	$tarbabyc,		tbaby_walk8	] {ai_turn();};
void()	tbaby_walk8	=[	$tarbabyc,		tbaby_walk9	] {ai_turn();};
void()	tbaby_walk9	=[	$tarbabyc,		tbaby_walk10	] {ai_turn();};
void()	tbaby_walk10	=[	$tarbabyc,		tbaby_walk11	] {ai_turn();};
void()	tbaby_walk11	=[	$tarbabyc,		tbaby_walk12	] {ai_walk(2);};
void()	tbaby_walk12	=[	$tarbabyc,		tbaby_walk13	] {ai_walk(2);};
void()	tbaby_walk13	=[	$tarbabyc,		tbaby_walk14	] {ai_walk(2);};
void()	tbaby_walk14	=[	$tarbabyc,		tbaby_walk15	] {ai_walk(2);};
void()	tbaby_walk15	=[	$tarbabyc,		tbaby_walk16	] {ai_walk(2);};
void()	tbaby_walk16	=[	$tarbabyc,		tbaby_walk17	] {ai_walk(2);};
void()	tbaby_walk17	=[	$tarbabyc,		tbaby_walk18	] {ai_walk(2);};
void()	tbaby_walk18	=[	$tarbabyc,		tbaby_walk19	] {ai_walk(2);};
void()	tbaby_walk19	=[	$tarbabyc,		tbaby_walk20	] {ai_walk(2);};
void()	tbaby_walk20	=[	$tarbabyc,		tbaby_walk21	] {ai_walk(2);};
void()	tbaby_walk21	=[	$tarbabyc,		tbaby_walk22	] {ai_walk(2);};
void()	tbaby_walk22	=[	$tarbabyc,		tbaby_walk23	] {ai_walk(2);};
void()	tbaby_walk23	=[	$tarbabyc,		tbaby_walk24	] {ai_walk(2);};
void()	tbaby_walk24	=[	$tarbabyc,		tbaby_walk25	] {ai_walk(2);};
void()	tbaby_walk25	=[	$tarbabyc,		tbaby_walk1	] {ai_walk(2);};

void()	tbaby_run1	=[	$tarbabyc,		tbaby_run2	] {ai_face();};
void()	tbaby_run2	=[	$tarbabyc,		tbaby_run3	] {ai_face();};
void()	tbaby_run3	=[	$tarbabyc,		tbaby_run4	] {ai_face();};
void()	tbaby_run4	=[	$tarbabyc,		tbaby_run5	] {ai_face();};
void()	tbaby_run5	=[	$tarbabyc,		tbaby_run6	] {ai_face();};
void()	tbaby_run6	=[	$tarbabyc,		tbaby_run7	] {ai_face();};
void()	tbaby_run7	=[	$tarbabyc,		tbaby_run8	] {ai_face();};
void()	tbaby_run8	=[	$tarbabyc,		tbaby_run9	] {ai_face();};
void()	tbaby_run9	=[	$tarbabyc,		tbaby_run10	] {ai_face();};
void()	tbaby_run10	=[	$tarbabyc,		tbaby_run11	] {ai_face();};
void()	tbaby_run11	=[	$tarbabyc,		tbaby_run12	] {ai_run(2);};
void()	tbaby_run12	=[	$tarbabyc,		tbaby_run13	] {ai_run(2);};
void()	tbaby_run13	=[	$tarbabyc,		tbaby_run14	] {ai_run(2);};
void()	tbaby_run14	=[	$tarbabyc,		tbaby_run15	] {ai_run(2);};
void()	tbaby_run15	=[	$tarbabyc,		tbaby_run16	] {ai_run(2);};
void()	tbaby_run16	=[	$tarbabyc,		tbaby_run17	] {ai_run(2);};
void()	tbaby_run17	=[	$tarbabyc,		tbaby_run18	] {ai_run(2);};
void()	tbaby_run18	=[	$tarbabyc,		tbaby_run19	] {ai_run(2);};
void()	tbaby_run19	=[	$tarbabyc,		tbaby_run20	] {ai_run(2);};
void()	tbaby_run20	=[	$tarbabyc,		tbaby_run21	] {ai_run(2);};
void()	tbaby_run21	=[	$tarbabyc,		tbaby_run22	] {ai_run(2);};
void()	tbaby_run22	=[	$tarbabyc,		tbaby_run23	] {ai_run(2);};
void()	tbaby_run23	=[	$tarbabyc,		tbaby_run24	] {ai_run(2);};
void()	tbaby_run24	=[	$tarbabyc,		tbaby_run25	] {ai_run(2);};
void()	tbaby_run25	=[	$tarbabyc,		tbaby_run1	] {ai_run(2);};


//============================================================================


void()	tbaby_jump1;

void()	Tar_JumpTouch =
{
	local	float	ldmg;

	if (other.takedamage && other.classname != self.classname)
	{
		if ( vlen(self.velocity) > 400 )
		{
			ldmg = 10 + 10*random();
			T_Damage (other, self, self, ldmg);	
			sound (self, CHAN_WEAPON, "blob/hit1.wav", 1, ATTN_NORM);
		}
	}
	else
		sound (self, CHAN_WEAPON, "blob/land1.wav", 1, ATTN_NORM);


	if (!checkbottom(self))
	{
		if (self.flags & FL_ONGROUND)
		{	// jump randomly to not get hung up
//dprint ("popjump\n");
	self.touch = SUB_Null;
	self.think = tbaby_run1;
	self.movetype = MOVETYPE_STEP;
	self.nextthink = time + 0.1;

//			self.velocity_x = (random() - 0.5) * 600;
//			self.velocity_y = (random() - 0.5) * 600;
//			self.velocity_z = 200;
//			self.flags = self.flags - FL_ONGROUND;
		}
		return;	// not on ground yet
	}

	self.touch = SUB_Null;
	self.think = tbaby_jump1;
	self.nextthink = time + 0.1;
};

void()	tbaby_jump5;

void()	tbaby_fly1		=[	$tarbabyc,	tbaby_fly2	] {};
void()	tbaby_fly2		=[	$tarbabyc,	tbaby_fly3	] {};
void()	tbaby_fly3		=[	$tarbabyc,	tbaby_fly4	] {};
void()	tbaby_fly4		=[	$tarbabyc,	tbaby_fly1	] {
self.cnt = self.cnt + 1;
if (self.cnt == 4)
{
//dprint ("spawn hop\n");
tbaby_jump5 ();
}
};

void()	tbaby_jump1		=[	$tarbabyc,	tbaby_jump2		] {ai_face();};
void()	tbaby_jump2		=[	$tarbabyc,	tbaby_jump3		] {ai_face();};
void()	tbaby_jump3		=[	$tarbabyc,	tbaby_jump4		] {ai_face();};
void()	tbaby_jump4		=[	$tarbabyc,	tbaby_jump5		] {ai_face();};
void()	tbaby_jump5		=[	$tarbabyc,	tbaby_jump6		]
{	
	self.movetype = MOVETYPE_BOUNCE;
	self.touch = Tar_JumpTouch;
	makevectors (self.angles);
	self.origin_z = self.origin_z + 1;
	self.velocity = v_forward * 600 + '0 0 200';
	self.velocity_z = self.velocity_z + random()*150;
	if (self.flags & FL_ONGROUND)
		self.flags = self.flags - FL_ONGROUND;
	self.cnt = 0;
};
void()	tbaby_jump6	=[	$tarbabyc,tbaby_fly1	] {};



//=============================================================================

void()	tbaby_die1	=[	$tarbabyd,		tbaby_die2	] {
self.takedamage = DAMAGE_NO;
};
void()	tbaby_die2	=[	$tarbabyd,		tbaby_run1	] 
{
	T_RadiusDamage (self, self, 120, world);

	sound (self, CHAN_VOICE, "blob/death1.wav", 1, ATTN_NORM);
	self.origin = self.origin - 8*normalize(self.velocity);

//	WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
//	WriteByte (MSG_BROADCAST, TE_TAREXPLOSION);
//	WriteCoord (MSG_BROADCAST, self.origin_x);
//	WriteCoord (MSG_BROADCAST, self.origin_y);
//	WriteCoord (MSG_BROADCAST, self.origin_z);
	
	BecomeExplosion ();
};

//=============================================================================


/*UNTITLED-GAMED monster_tarbaby (1 0 0) (-16 -16 -24) (16 16 24) Ambush
*/
void() monster_tarbaby =
{
	if (deathmatch)
	{
		remove(self);
		return;
	}
	precache_model2 ("progs/tarbaby.mdl");

	precache_sound2 ("blob/death1.wav");
	precache_sound2 ("blob/hit1.wav");
	precache_sound2 ("blob/land1.wav");
	precache_sound2 ("blob/sight1.wav");
	
	self.solid = SOLID_SLIDEBOX;
	self.movetype = MOVETYPE_STEP;

	setmodel (self, "progs/tarbaby.mdl");

	setsize (self, '-16 -16 -24', '16 16 40');
	self.health = 80;

	self.th_stand = tbaby_stand1;
	self.th_walk = tbaby_walk1;
	self.th_run = tbaby_run1;
	self.th_missile = tbaby_jump1;
	self.th_melee = tbaby_jump1;
	self.th_die = tbaby_die1;
	
	walkmonster_start ();
};