void () shalrath_pain;
void () TShalMissile;

void () shal_stand = [ 15, shal_stand ]
{
	ai_stand ();
};

void () shal_walk1 = [ 30, shal_walk2 ]
{
	sound (self, CHAN_WEAPON, "tshalrath/step.wav", 1, ATTN_IDLE);
	ai_walk (3);
};

void () shal_walk2 = [ 31, shal_walk3 ]
{
	ai_walk (6);
};

void () shal_walk3 = [ 32, shal_walk4 ]
{
	ai_walk (6);
};

void () shal_walk4 = [ 33, shal_walk5 ]
{
	ai_walk (6);
};

void () shal_walk5 = [ 34, shal_walk6 ]
{
	sound (self, CHAN_WEAPON, "tshalrath/step.wav", 1, ATTN_IDLE);
	ai_walk (3);
};

void () shal_walk6 = [ 35, shal_walk7 ]
{
	ai_walk (6);
};

void () shal_walk7 = [ 36, shal_walk8 ]
{
	ai_walk (6);
};

void () shal_walk8 = [ 37, shal_walk1 ]
{
	ai_walk (6);
};

void () shal_run1 = [ 30, shal_run2 ]
{
	sound (self, CHAN_WEAPON, "tshalrath/step.wav", 1, ATTN_IDLE);
	ai_run (15);
};

void () shal_run2 = [ 31, shal_run3 ]
{
	ai_run (16);
};

void () shal_run3 = [ 32, shal_run4 ]
{
	ai_run (16);
};

void () shal_run4 = [ 33, shal_run5 ]
{
	ai_run (16);
};

void () shal_run5 = [ 34, shal_run6 ]
{
	sound (self, CHAN_WEAPON, "tshalrath/step.wav", 1, ATTN_IDLE);
	ai_run (15);
};

void () shal_run6 = [ 35, shal_run7 ]
{
	ai_run (16);
};

void () shal_run7 = [ 36, shal_run8 ]
{
	ai_run (16);
};

void () shal_run8 = [ 37, shal_run1 ]
{
	ai_run (16);
};

void () shal_bull =
{
	local vector dir;
	local entity en;

	ai_face ();
	sound (self, CHAN_WEAPON, "tshalrath/gunat.wav", 1, ATTN_NORM);
	en = self.enemy;
	
	dir = (en.origin + '0 0 -16' - (en.velocity * 0));
	dir = normalize ((dir - self.origin));
	FireBullets (10, dir, '0.2 0.2 0.2');
};

void () shal_attack1 = [ 16, shal_attack2 ]
{
	sound (self, CHAN_WEAPON, "tshalrath/move.wav", 1, ATTN_NORM);
	ai_face ();
};

void () shal_attack2 = [ 17, shal_attack3 ]
{
	ai_face ();
};

void () shal_attack3 = [ 18, shal_attack4 ]
{
	ai_face ();
};

void () shal_attack4 = [ 18, shal_attack5 ]
{
	ai_face ();
};

void () shal_attack5 = [ 18, shal_attack6 ]
{
	ai_face ();
};

void () shal_attack6 = [ 19, shal_attack7 ]{	shal_bull ();	ai_face ();};
void () shal_attack7 = [ 20, shal_attack8 ]{	shal_bull ();	ai_face ();};
void () shal_attack8 = [ 19, shal_attack9 ]{	shal_bull ();	ai_face ();};
void () shal_attack9 = [ 20, shal_attack10 ]{	shal_bull ();	ai_face ();};
void () shal_attack10 = [ 19, shal_attack11 ]{	shal_bull ();	ai_face ();};
void () shal_attack11 = [ 20, shal_attack12 ]{	shal_bull ();	ai_face ();};

void () shal_attack12 = [ 21, shal_attack13 ]
{
	ai_face ();
	if ((self.enemy.health < 1))
	{
		sound (self, CHAN_VOICE, "tshalrath/victory.wav", 1, ATTN_NORM);
	}
};

void () shal_attack13 = [ 18, shal_attack14 ]
{
	ai_face ();
};

void () shal_attack14 = [ 17, shal_attack15 ]
{
	ai_face ();
};

void () shal_attack15 = [ 16, shal_run1 ]
{
	ai_face ();
};

void () TShalMissile =
{
	local vector org;

	self.effects = (self.effects | EF_MUZZLEFLASH);
	makevectors (self.angles);
	sound (self, CHAN_WEAPON, "tshalrath/misat.wav", 1, ATTN_NORM);
	org = self.origin + v_forward*16 + v_up*64 + v_right * 24;
	LaunchRocket2 (org, (self.enemy.origin - org));
	newmis.think = DrunkRocketThink;
	org = self.origin + v_forward*16 + v_up*64 + v_right * -24;
	LaunchRocket2 (org, (self.enemy.origin - org));
	newmis.think = DrunkRocketThink;
};

void () shal_attackb1 = [ 22, shal_attackb2 ]
{
	sound (self, CHAN_WEAPON, "tshalrath/forc.wav", 1, ATTN_NORM);
	ai_face ();
};

void () shal_attackb2 = [ 23, shal_attackb3 ]
{
	ai_face ();
};

void () shal_attackb3 = [ 23, shal_attackb4 ]
{
	ai_face ();
};

void () shal_attackb4 = [ 24, shal_attackb5 ]
{
	TShalMissile ();
	ai_face ();
};

void () shal_attackb5 = [ 25, shal_attackb6 ]
{
	TShalMissile ();
	ai_face ();
};

void () shal_attackb6 = [ 24, shal_attackb7 ]
{
	TShalMissile ();
	ai_face ();
};

void () shal_attackb7 = [ 25, shal_attackb8 ]
{
	TShalMissile ();
	ai_face ();
};

void () shal_attackb8 = [ 23, shal_attackb9 ]
{
	ai_face ();
};

void () shal_attackb9 = [ 22, shal_run1 ]
{
	ai_face ();
	if ((self.enemy.health < 1))
	{
		sound (self, CHAN_VOICE, "tshalrath/victory.wav", 1, ATTN_NORM);
	}
};

void () shal_attack =
{

	if (random() < 0.6) shal_attack1(); else shal_attackb1();

};

void () shal_pain1 = [ 26, shal_pain2 ]
{
};

void () shal_pain2 = [ 27, shal_pain3 ]
{
};

void () shal_pain3 = [ 28, shal_pain4 ]
{
};

void () shal_pain4 = [ 29, shal_pain5 ]
{
};

void () shal_pain5 = [ 28, shal_pain6 ]
{
};

void () shal_pain6 = [ 29, shal_pain7 ]
{
};

void () shal_pain7 = [ 28, shal_pain8 ]
{
	sound (self, CHAN_WEAPON, "tshalrath/forc.wav", 1, ATTN_NORM);
};

void () shal_pain8 = [ 29, shal_pain9 ]
{
};

void () shal_pain9 = [ 28, shal_pain10 ]
{
};

void () shal_pain10 = [ 27, shal_pain11 ]
{
};

void () shal_pain11 = [ 26, shal_run1 ]
{
};

void () shal_death1 = [ 8, shal_death2 ]
{
	self.skin = 1;
};

void () shal_death2 = [ 9, shal_death3 ]
{
};

void () shal_death3 = [ 10, shal_death4 ]
{
};

void () shal_death4 = [ 11, shal_death5 ]
{
};

void () shal_death5 = [ 12, shal_death6 ]
{
	sound (self, CHAN_WEAPON, "tshalrath/ong.wav", 1, ATTN_NORM);
};

void () shal_death6 = [ 13, shal_death7 ]
{
};

void () shal_death7 = [ 14, shal_death7 ]
{
remove_monster();
};

void () shal_deathb1 = [ 0, shal_deathb2 ]
{
	self.skin = 1;
};

void () shal_deathb2 = [ 1, shal_deathb3 ]
{
};

void () shal_deathb3 = [ 2, shal_deathb4 ]
{
};

void () shal_deathb4 = [ 3, shal_deathb5 ]
{
};

void () shal_deathb5 = [ 4, shal_deathb6 ]
{
};

void () shal_deathb6 = [ 5, shal_deathb7 ]
{
	sound (self, CHAN_WEAPON, "tshalrath/ong.wav", 1, ATTN_NORM);
};

void () shal_deathb7 = [ 6, shal_deathb8 ]
{
};

void () shal_deathb8 = [ 7, shal_deathb8 ]
{
remove_monster();
};

void () shalrath_pain =
{
	if ((self.pain_finished > time))
	{
		return;
	}
	sound (self, CHAN_VOICE, "tshalrath/pain.wav", 1, ATTN_NORM);
	shal_pain1 ();
	self.pain_finished = (time + 3);
};
void () shalrath_die =
{
	if ((self.health < -50))
	{
	local entity boom;
	boom = spawn();
	boom.owner = self;
	boom.think = MNExplosion;
	boom.classname = "monster_troop_shalrath";
	boom.nextthink = time + 0.1;
	setorigin(boom,self.origin);


		ThrowGib ("progs/dgib.mdl", self.health, self);
		ThrowGib ("progs/dgib.mdl", self.health, self);
		ThrowGib ("progs/mgib2.mdl", self.health, self);
		ThrowGib ("progs/mgib2.mdl", self.health, self);
		ThrowGib ("progs/mgib3.mdl", self.health, self);
		ThrowGib ("progs/mgib4.mdl", self.health, self);
		ThrowHead ("progs/hdr.mdl", self.health, self);
		return;


	}
	if ((random () <= 0.5))
	{
		sound (self, CHAN_VOICE, "tshalrath/death.wav", 1, ATTN_NORM);
	}
	else
	{
		sound (self, CHAN_VOICE, "tshalrath/death2.wav", 1, ATTN_NORM);
	}
	if ((random () < 0.5))
	{
		shal_death1 ();
	}
	else
	{
		shal_deathb1 ();
	}
	self.solid = SOLID_NOT;
};

void () monster_troop_shalrath =
{
	if (deathmatch)
	{
		remove (self);
		return;
	}
	self.solid = SOLID_SLIDEBOX;
	self.movetype = MOVETYPE_STEP;
	setmodel (self, "progs/tshalrath.mdl");
	setsize (self, '-48 -48 -24', '48 48 96');
	self.health = M4HEALTH;
	self.th_stand = shal_stand;
	self.th_walk = shal_walk1;
	self.th_run = shal_run1;
	self.th_die = shalrath_die;
	self.th_pain = shalrath_pain;
	self.th_missile = shal_attack;
	self.th_melee = shal_attack1;
	self.think = walkmonster_start;
	self.classname = "monster_troop_shalrath";
	self.netname = "endroyidd";
	self.bondoflag = TECH;
	self.nextthink = ((time + 0.1) + (random () * 0.1));
};
