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

SOLDIER / PLAYER

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

$cd id1/models/enforcer
$origin 0 -6 24
$base base		
$skin skin

$frame enforcerc
$frame enforcerd


void() Laser_Touch =
{
	local vector org;
	
	if (other == self.owner)
		return;		// don't explode on owner

	if (pointcontents(self.origin) == CONTENT_SKY)
	{
		remove(self);
		return;
	}
	
	sound (self, CHAN_WEAPON, "enforcer/enfstop.wav", 1, ATTN_STATIC);
	org = self.origin - 8*normalize(self.velocity);

	if (other.health)
	{
//		SpawnBlood (org, self.velocity*0.2, 15);
		T_Damage (other, self, self.owner, 15);
	}
	else
	{
return;
//		WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
//		WriteByte (MSG_BROADCAST, TE_GUNSHOT);
//		WriteCoord (MSG_BROADCAST, org_x);
//		WriteCoord (MSG_BROADCAST, org_y);
//		WriteCoord (MSG_BROADCAST, org_z);
	}
	
	remove(self);	
};

void(vector org, vector vec) LaunchLaser =
{
	local	vector	vec;
		
	if (self.classname == "monster_enforcer")
		sound (self, CHAN_WEAPON, "enforcer/enfire.wav", 1, ATTN_NORM);

	vec = normalize(vec);
	
	newmis = spawn();
	newmis.owner = self;
	newmis.movetype = MOVETYPE_FLY;
	newmis.solid = SOLID_BBOX;
//	newmis.effects = EF_DIMLIGHT;

//	setmodel (newmis, "progs/laser.mdl");
	setsize (newmis, '0 0 0', '0 0 0');		

	setorigin (newmis, org);

	newmis.velocity = vec * 600;
	newmis.angles = vectoangles(newmis.velocity);

	newmis.nextthink = time + 5;
	newmis.think = SUB_Remove;
	newmis.touch = Laser_Touch;
};



void() enforcer_fire =
{
	local vector org;


	makevectors (self.angles);
	
	org = self.origin + v_forward * 30 + v_right * 8.5 + '0 0 16';

	LaunchLaser(org, self.enemy.origin - self.origin);
};

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

void()	enf_stand1	=[	$enforcerc,	enf_stand2	] {ai_stand();};
void()	enf_stand2	=[	$enforcerc,	enf_stand3	] {ai_stand();};
void()	enf_stand3	=[	$enforcerc,	enf_stand4	] {ai_stand();};
void()	enf_stand4	=[	$enforcerc,	enf_stand5	] {ai_stand();};
void()	enf_stand5	=[	$enforcerc,	enf_stand6	] {ai_stand();};
void()	enf_stand6	=[	$enforcerc,	enf_stand7	] {ai_stand();};
void()	enf_stand7	=[	$enforcerc,	enf_stand1	] {ai_stand();};

void()	enf_walk1	=[	$enforcerc ,	enf_walk2	] {
if (random() < 0.2)
	sound (self, CHAN_VOICE, "enforcer/idle1.wav", 1, ATTN_IDLE);
ai_walk(2);};
void()	enf_walk2	=[	$enforcerc ,	enf_walk3	] {ai_walk(4);};
void()	enf_walk3	=[	$enforcerc ,	enf_walk4	] {ai_walk(4);};
void()	enf_walk4	=[	$enforcerc ,	enf_walk5	] {ai_walk(3);};
void()	enf_walk5	=[	$enforcerc ,	enf_walk6	] {ai_walk(1);};
void()	enf_walk6	=[	$enforcerc ,	enf_walk7	] {ai_walk(2);};
void()	enf_walk7	=[	$enforcerc ,	enf_walk8	] {ai_walk(2);};
void()	enf_walk8	=[	$enforcerc ,	enf_walk9	] {ai_walk(1);};
void()	enf_walk9	=[	$enforcerc ,	enf_walk10	] {ai_walk(2);};
void()	enf_walk10	=[	$enforcerc,	enf_walk11	] {ai_walk(4);};
void()	enf_walk11	=[	$enforcerc,	enf_walk12	] {ai_walk(4);};
void()	enf_walk12	=[	$enforcerc,	enf_walk13	] {ai_walk(1);};
void()	enf_walk13	=[	$enforcerc,	enf_walk14	] {ai_walk(2);};
void()	enf_walk14	=[	$enforcerc,	enf_walk15	] {ai_walk(3);};
void()	enf_walk15	=[	$enforcerc,	enf_walk16	] {ai_walk(4);};
void()	enf_walk16	=[	$enforcerc,	enf_walk1	] {ai_walk(2);};

void()	enf_run1	=[	$enforcerc  ,	enf_run2	] {
if (random() < 0.2)
	sound (self, CHAN_VOICE, "enforcer/idle1.wav", 1, ATTN_IDLE);
ai_run(18);};
void()	enf_run2	=[	$enforcerc  ,	enf_run3	] {ai_run(14);};
void()	enf_run3	=[	$enforcerc  ,	enf_run4	] {ai_run(7);};
void()	enf_run4	=[	$enforcerc  ,	enf_run5	] {ai_run(12);};
void()	enf_run5	=[	$enforcerc  ,	enf_run6	] {ai_run(14);};
void()	enf_run6	=[	$enforcerc  ,	enf_run7	] {ai_run(14);};
void()	enf_run7	=[	$enforcerc  ,	enf_run8	] {ai_run(7);};
void()	enf_run8	=[	$enforcerc  ,	enf_run1	] {ai_run(11);};

void()	enf_atk1	=[	$enforcerc,	enf_atk2	] {ai_face();};
void()	enf_atk2	=[	$enforcerc,	enf_atk3	] {ai_face();};
void()	enf_atk3	=[	$enforcerc,	enf_atk4	] {ai_face();};
void()	enf_atk4	=[	$enforcerc,	enf_atk5	] {ai_face();};
void()	enf_atk5	=[	$enforcerc,	enf_atk6	] {ai_face();};
void()	enf_atk6	=[	$enforcerc,	enf_atk7	] {enforcer_fire();};
void()	enf_atk7	=[	$enforcerc,	enf_atk8	] {ai_face();};
void()	enf_atk8	=[	$enforcerc,	enf_atk9	] {ai_face();};
void()	enf_atk9	=[	$enforcerc,	enf_atk10	] {ai_face();};
void()	enf_atk10	=[	$enforcerc,	enf_atk11	] {enforcer_fire();};
void()	enf_atk11	=[	$enforcerc,	enf_atk12	] {ai_face();};
void()	enf_atk12	=[	$enforcerc,	enf_atk13	] {ai_face();};
void()	enf_atk13	=[	$enforcerc,	enf_atk14	] {ai_face();};
void()	enf_atk14	=[	$enforcerc,	enf_run1	] {ai_face();
SUB_CheckRefire (enf_atk1);
};

void()	enf_paina1	=[	$enforcerc,	enf_paina2	] {};
void()	enf_paina2	=[	$enforcerc,	enf_paina3	] {};
void()	enf_paina3	=[	$enforcerc,	enf_paina4	] {};
void()	enf_paina4	=[	$enforcerc,	enf_run1	] {};

void()	enf_painb1	=[	$enforcerc,	enf_painb2	] {};
void()	enf_painb2	=[	$enforcerc,	enf_painb3	] {};
void()	enf_painb3	=[	$enforcerc,	enf_painb4	] {};
void()	enf_painb4	=[	$enforcerc,	enf_painb5	] {};
void()	enf_painb5	=[	$enforcerc,	enf_run1	] {};

void()	enf_painc1	=[	$enforcerc,	enf_painc2	] {};
void()	enf_painc2	=[	$enforcerc,	enf_painc3	] {};
void()	enf_painc3	=[	$enforcerc,	enf_painc4	] {};
void()	enf_painc4	=[	$enforcerc,	enf_painc5	] {};
void()	enf_painc5	=[	$enforcerc,	enf_painc6	] {};
void()	enf_painc6	=[	$enforcerc,	enf_painc7	] {};
void()	enf_painc7	=[	$enforcerc,	enf_painc8	] {};
void()	enf_painc8	=[	$enforcerc,	enf_run1	] {};

void()	enf_paind1	=[	$enforcerc,	enf_paind2	] {};
void()	enf_paind2	=[	$enforcerc,	enf_paind3	] {};
void()	enf_paind3	=[	$enforcerc,	enf_paind4	] {};
void()	enf_paind4	=[	$enforcerc,	enf_paind5	] {ai_painforward(2);};
void()	enf_paind5	=[	$enforcerc,	enf_paind6	] {ai_painforward(1);};
void()	enf_paind6	=[	$enforcerc,	enf_paind7	] {};
void()	enf_paind7	=[	$enforcerc,	enf_paind8	] {};
void()	enf_paind8	=[	$enforcerc,	enf_paind9	] {};
void()	enf_paind9	=[	$enforcerc,	enf_paind10	] {};
void()	enf_paind10	=[	$enforcerc,	enf_paind11	] {};
void()	enf_paind11	=[	$enforcerc,	enf_paind12	] {ai_painforward(1);};
void()	enf_paind12	=[	$enforcerc,	enf_paind13	] {ai_painforward(1);};
void()	enf_paind13	=[	$enforcerc,	enf_paind14	] {ai_painforward(1);};
void()	enf_paind14	=[	$enforcerc,	enf_paind15	] {};
void()	enf_paind15	=[	$enforcerc,	enf_paind16	] {};
void()	enf_paind16	=[	$enforcerc,	enf_paind17	] {ai_pain(1);};
void()	enf_paind17	=[	$enforcerc,	enf_paind18	] {ai_pain(1);};
void()	enf_paind18	=[	$enforcerc,	enf_paind19	] {};
void()	enf_paind19	=[	$enforcerc,	enf_run1	] {};

void(entity attacker, float damage)	enf_pain =
{
	local float r;

	r = random ();
	if (self.pain_finished > time)
		return;

	
	if (r < 0.5)
		sound (self, CHAN_VOICE, "enforcer/pain1.wav", 1, ATTN_NORM);
	else
		sound (self, CHAN_VOICE, "enforcer/pain2.wav", 1, ATTN_NORM);

	if (r < 0.2)
	{
		self.pain_finished = time + 1;
		enf_paina1 ();
	}
	else if (r < 0.4)
	{
		self.pain_finished = time + 1;
		enf_painb1 ();
	}
	else if (r < 0.7)
	{
		self.pain_finished = time + 1;
		enf_painc1 ();
	}
	else
	{
		self.pain_finished = time + 2;
		enf_paind1 ();
	}
};

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




void()	enf_die1	=[	$enforcerd,	enf_die2	] {};
void()	enf_die2	=[	$enforcerd,	enf_die3	] {};
void()	enf_die3	=[	$enforcerd,	enf_die4	]
{self.solid = SOLID_NOT;self.ammo_cells = 5;DropBackpack();};
void()	enf_die4	=[	$enforcerd,	enf_die5	] {ai_forward(14);};
void()	enf_die5	=[	$enforcerd,	enf_die6	] {ai_forward(2);};
void()	enf_die6	=[	$enforcerd,	enf_die7	] {};
void()	enf_die7	=[	$enforcerd,	enf_die8	] {};
void()	enf_die8	=[	$enforcerd,	enf_die9	] {};
void()	enf_die9	=[	$enforcerd,	enf_die10	] {ai_forward(3);};
void()	enf_die10	=[	$enforcerd,	enf_die11	] {ai_forward(5);};
void()	enf_die11	=[	$enforcerd,	enf_die12	] {ai_forward(5);};
void()	enf_die12	=[	$enforcerd,	enf_die13	] {ai_forward(5);};
void()	enf_die13	=[	$enforcerd,	enf_die14	] {};
void()	enf_die14	=[	$enforcerd,	enf_die14	] {};

void()	enf_fdie1	=[	$enforcerd,	enf_fdie2	] {

};
void()	enf_fdie2	=[	$enforcerd,	enf_fdie3	] {};
void()	enf_fdie3	=[	$enforcerd,	enf_fdie4	] 
{self.solid = SOLID_NOT;self.ammo_cells = 5;DropBackpack();};
void()	enf_fdie4	=[	$enforcerd,	enf_fdie5	] {};
void()	enf_fdie5	=[	$enforcerd,	enf_fdie6	] {};
void()	enf_fdie6	=[	$enforcerd,	enf_fdie7	] {};
void()	enf_fdie7	=[	$enforcerd,	enf_fdie8	] {};
void()	enf_fdie8	=[	$enforcerd,	enf_fdie9	] {};
void()	enf_fdie9	=[	$enforcerd,	enf_fdie10	] {};
void()	enf_fdie10	=[	$enforcerd,	enf_fdie11	] {};
void()	enf_fdie11	=[	$enforcerd,	enf_fdie11	] {};


void() enf_die =
{
// check for gib
	if (self.health < -35)
	{
		sound (self, CHAN_VOICE, "player/udeath.wav", 1, ATTN_NORM);
		ThrowHead ("progs/h_mega.mdl", self.health);
		ThrowGib ("progs/gib1.mdl", self.health);
		ThrowGib ("progs/gib2.mdl", self.health);
		ThrowGib ("progs/gib3.mdl", self.health);
		return;
	}

// regular death
	sound (self, CHAN_VOICE, "enforcer/death1.wav", 1, ATTN_NORM);
	if (random() > 0.5)
		enf_die1 ();
	else
		enf_fdie1 ();
};


/*UNTITLED-GAME/D monster_enforcer (1 0 0) (-16 -16 -24) (16 16 40) Ambush

*/
void() monster_enforcer =
{
	if (deathmatch)
	{
		remove(self);
		return;
	}
	precache_model2 ("progs/enforcer.mdl");
	precache_model2 ("progs/h_mega.mdl");
	precache_model2 ("progs/laser.mdl");

	precache_sound2 ("enforcer/death1.wav");
	precache_sound2 ("enforcer/enfire.wav");
	precache_sound2 ("enforcer/enfstop.wav");
	precache_sound2 ("enforcer/idle1.wav");
	precache_sound2 ("enforcer/pain1.wav");
	precache_sound2 ("enforcer/pain2.wav");
	precache_sound2 ("enforcer/sight1.wav");
	precache_sound2 ("enforcer/sight2.wav");
	precache_sound2 ("enforcer/sight3.wav");
	precache_sound2 ("enforcer/sight4.wav");
	
	self.solid = SOLID_SLIDEBOX;
	self.movetype = MOVETYPE_STEP;

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

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

	self.th_stand = enf_stand1;
	self.th_walk = enf_walk1;
	self.th_run = enf_run1;
	self.th_pain = enf_pain;
	self.th_die = enf_die;
	self.th_missile = enf_atk1;

	walkmonster_start();
};