/*

	The Pigcop
	by 3D Realms
	From the Duke Nukem HRP
	Converted by Bondo

*/

void () pigcop_fire = {

   local vector dir;
   local entity en;

   ai_face ();
   sound (self,CHAN_WEAPON,"pigcop/pigshoot.wav",TRUE,ATTN_NORM);
   en = self.enemy;
   dir = (en.origin - (en.velocity * 0.200));
   dir = normalize ((dir - self.origin));
   FireBullets (1,dir,'0.060 0.060 0.000');
   //LaunchTracer((self.origin + '0 0 16' + v_forward*8 + v_right*8),dir,'0.1 0.1 1');

};

void () pigcop_stand1 =[0,pigcop_stand1] {ai_stand();};

void()	pigcop_walk1	=[	0,	pigcop_walk2	] {
if (random() < 0.2)
	sound (self, CHAN_VOICE, "pigcop/pigidle2.wav", 1, ATTN_IDLE);
ai_walk(1);};
void()	pigcop_walk2	=[	1,	pigcop_walk3	] {ai_walk(1);};
void()	pigcop_walk3	=[	2,	pigcop_walk4	] {ai_walk(1);};
void()	pigcop_walk4	=[	3,	pigcop_walk5	] {ai_walk(1);};
void()	pigcop_walk5	=[	4,	pigcop_walk6	] {ai_walk(2);};
void()	pigcop_walk6	=[	5,	pigcop_walk7	] {ai_walk(3);};
void()	pigcop_walk7	=[	6,	pigcop_walk8	] {ai_walk(4);};
void()	pigcop_walk8	=[	7,	pigcop_walk9	] {ai_walk(4);};
void()	pigcop_walk9	=[	8,	pigcop_walk10	] {ai_walk(2);};
void()	pigcop_walk10	=[	9,	pigcop_walk11	] {ai_walk(2);};
void()	pigcop_walk11	=[	10,	pigcop_walk12	] {ai_walk(2);};
void()	pigcop_walk12	=[	11,	pigcop_walk13	] {ai_walk(1);};
void()	pigcop_walk13	=[	12,	pigcop_walk14	] {ai_walk(3);};
void()	pigcop_walk14	=[	13,	pigcop_walk15	] {ai_walk(1);};
void()	pigcop_walk15	=[	14,	pigcop_walk16	] {ai_walk(1);};
void()	pigcop_walk16	=[	15,	pigcop_walk17	] {ai_walk(1);};
void()	pigcop_walk17	=[	16,	pigcop_walk1	] {ai_walk(3);};

void()	pigcop_run1	=[	0,	pigcop_run2	] {
if (random() < 0.2)
	sound (self, CHAN_VOICE, "pigcop/pigidle2.wav", 1, ATTN_IDLE);
ai_run(1);
self.nextthink = time + 0.05;};
void()	pigcop_run2	=[	1,	pigcop_run3	] {self.nextthink = time + 0.07; ai_run(10);};
void()	pigcop_run3	=[	2,	pigcop_run4	] { self.nextthink = time + 0.07; ai_run(10);};
void()	pigcop_run4	=[	3,	pigcop_run5	] { self.nextthink = time + 0.07; ai_run(10);};
void()	pigcop_run5	=[	4,	pigcop_run6	] { self.nextthink = time + 0.07; ai_run(9);};
void()	pigcop_run6	=[	5,	pigcop_run7	] { self.nextthink = time + 0.07; ai_run(8);};
void()	pigcop_run7	=[	6,	pigcop_run8	] { self.nextthink = time + 0.07; ai_run(10);};
void()	pigcop_run8	=[	7,	pigcop_run9	] { self.nextthink = time + 0.07; ai_run(8);};
void()	pigcop_run9	=[	8,	pigcop_run10	] { self.nextthink = time + 0.07; ai_run(9);};
void()	pigcop_run10	=[	9,	pigcop_run11	] { self.nextthink = time + 0.07; ai_run(8);};
void()	pigcop_run11	=[	10,	pigcop_run12	] { self.nextthink = time + 0.07; ai_run(8);};
void()	pigcop_run12	=[	11,	pigcop_run13	] { self.nextthink = time + 0.07; ai_run(8);};
void()	pigcop_run13	=[	12,	pigcop_run14	] { self.nextthink = time + 0.07; ai_run(8);};
void()	pigcop_run14	=[	13,	pigcop_run15	] { self.nextthink = time + 0.07; ai_run(8);};
void()	pigcop_run15	=[	14,	pigcop_run16	] { self.nextthink = time + 0.07; ai_run(8);};
void()	pigcop_run16	=[	15,	pigcop_run17	] { self.nextthink = time + 0.07; ai_run(7);};
void()	pigcop_run17	=[	16,	pigcop_run1	] { self.nextthink = time + 0.07; ai_run(8);};

void()	bigpigcop_run1	=[	0,	bigpigcop_run2	] {
if (random() < 0.2)
	sound (self, CHAN_VOICE, "pigcop/pigidle2.wav", 1, ATTN_IDLE);
ai_run(1);
self.nextthink = time + 0.05;};
void()	bigpigcop_run2	=[	1,	bigpigcop_run3	] {self.nextthink = time + 0.07; ai_run(10);};
void()	bigpigcop_run3	=[	2,	bigpigcop_run4	] { self.nextthink = time + 0.07; ai_run(10);};
void()	bigpigcop_run4	=[	3,	bigpigcop_run5	] { self.nextthink = time + 0.07; ai_run(10);};
void()	bigpigcop_run5	=[	4,	bigpigcop_run6	] { self.nextthink = time + 0.07; ai_run(9);};
void()	bigpigcop_run6	=[	5,	bigpigcop_run7	] { self.nextthink = time + 0.07; ai_run(8);};
void()	bigpigcop_run7	=[	6,	bigpigcop_run8	] { self.nextthink = time + 0.07; ai_run(10);};
void()	bigpigcop_run8	=[	7,	bigpigcop_run9	] { self.nextthink = time + 0.07; ai_run(8);};
void()	bigpigcop_run9	=[	8,	bigpigcop_run10	] { self.nextthink = time + 0.07; ai_run(9);};
void()	bigpigcop_run10	=[	9,	bigpigcop_run11	] { self.nextthink = time + 0.07; ai_run(8);};
void()	bigpigcop_run11	=[	10,	bigpigcop_run12	] { self.nextthink = time + 0.07; ai_run(8);};
void()	bigpigcop_run12	=[	11,	bigpigcop_run13	] { self.nextthink = time + 0.07; ai_run(8);};
void()	bigpigcop_run13	=[	12,	bigpigcop_run14	] { self.nextthink = time + 0.07; ai_run(8);};
void()	bigpigcop_run14	=[	13,	bigpigcop_run15	] { self.nextthink = time + 0.07; ai_run(8);};
void()	bigpigcop_run15	=[	14,	bigpigcop_run16	] { self.nextthink = time + 0.07; ai_run(8);};
void()	bigpigcop_run16	=[	15,	bigpigcop_run17	] { self.nextthink = time + 0.07; ai_run(7);};
void()	bigpigcop_run17	=[	16,	bigpigcop_run1	] { self.nextthink = time + 0.07; ai_run(8);};

void()	pigcop_atka1	=[	17,	pigcop_atka2	] {self.nextthink = time + 0.05; ai_face();};
void()	pigcop_atka2	=[	18,	pigcop_atka3	] {self.nextthink = time + 0.05; ai_face();};
void()	pigcop_atka3	=[	19,	pigcop_atka4	] {self.nextthink = time + 0.05; ai_face(); pigcop_fire();
self.effects = self.effects | EF_MUZZLEFLASH;};
void()	pigcop_atka4	=[	20,	pigcop_atka5	] {self.nextthink = time + 0.05; ai_face();};
void()	pigcop_atka5	=[	21,	pigcop_atka6	] {self.nextthink = time + 0.05; ai_face();};
void()	pigcop_atka6	=[	22,	pigcop_atka7	] {self.nextthink = time + 0.05; ai_face();};
void()	pigcop_atka7	=[	23,	pigcop_atka8	] {self.nextthink = time + 0.05; ai_face();};
void()	pigcop_atka8	=[	24,	pigcop_atka9	] {self.nextthink = time + 0.05; ai_face();};
void()	pigcop_atka9	=[	25,	pigcop_atka10	] {self.nextthink = time + 0.05; ai_face();};
void()	pigcop_atka10	=[	26,	pigcop_atka11	] {self.nextthink = time + 0.05; ai_face();};
void()	pigcop_atka11	=[	27,	pigcop_atka12	] {self.nextthink = time + 0.05; ai_face();};
void()	pigcop_atka12	=[	28,	pigcop_run1	] {self.nextthink = time + 0.05; ai_face();
if (skill > 1 && visible(self.enemy) && (random() < 0.7)) self.think = pigcop_atka1;};

//53-72
void () pigcop_atkb1 = [53, pigcop_atkb2] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb2 = [54, pigcop_atkb3] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb3 = [55, pigcop_atkb4] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb4 = [56, pigcop_atkb5] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb5 = [57, pigcop_atkb6] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb6 = [58, pigcop_atkb7] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb7 = [59, pigcop_atkb8] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb8 = [60, pigcop_atkb9] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb9 = [61, pigcop_atkb10] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb10 = [62, pigcop_atkb11] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb11 = [63, pigcop_atkb12] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb12 = [64, pigcop_atkb13] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb13 = [65, pigcop_atkb14] {self.nextthink = time + 0.05; ai_face(); pigcop_fire();self.effects = self.effects | EF_MUZZLEFLASH;};
void () pigcop_atkb14 = [66, pigcop_atkb15] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb15 = [67, pigcop_atkb16] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb16 = [68, pigcop_atkb17] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb17 = [69, pigcop_atkb18] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb18 = [70, pigcop_atkb19] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb19 = [71, pigcop_atkb20] {self.nextthink = time + 0.05; ai_face();};
void () pigcop_atkb20 = [72, pigcop_run1] {self.nextthink = time + 0.05; ai_face(); if (random() < 0.7 && visible(self.enemy)) self.think = pigcop_atkb9;};

void()	pigcop_pain1	=[	29,		pigcop_pain2	] {self.nextthink = time + 0.07;};
void()	pigcop_pain2	=[	30,		pigcop_pain3	] {self.nextthink = time + 0.07;};
void()	pigcop_pain3	=[	31,		pigcop_run1	] {self.nextthink = time + 0.07;ai_pain(1);};

void(entity attacker, float damage)	pigcop_pain =
{
	local float r;
	
	if (self.pain_finished > time)
		return;

	r = random();

	pigcop_pain1 ();
	self.pain_finished = time + 0.5;

	if (r < 0.2)
	{
		sound (self, CHAN_VOICE, "pigcop/pigpain.wav", 1, ATTN_NORM);
	}
	else if (r < 0.6)
	{
		sound (self, CHAN_VOICE, "pigcop/pigsight.wav", 1, ATTN_NORM);
	}
	else
	{
		sound (self, CHAN_VOICE, "pigcop/pigidle1.wav", 1, ATTN_NORM);
	}
};

void () pigcop_atk =
{

	if (random() < 0.5) pigcop_atka1(); else pigcop_atkb1();

};

//29-52
void () pigcop_die1 =[ 29, pigcop_die2] {};
void () pigcop_die2 =[ 30, pigcop_die3] { };
void () pigcop_die3 =[ 31, pigcop_die4] {self.solid = SOLID_NOT;};
void () pigcop_die4 =[ 32, pigcop_die5] {};
void () pigcop_die5 =[ 33, pigcop_die6] {};
void () pigcop_die6 =[ 34, pigcop_die7] {};
void () pigcop_die7 =[ 35, pigcop_die8] {};
void () pigcop_die8 =[ 36, pigcop_die9] {};
void () pigcop_die9 =[ 37, pigcop_die10] {};
void () pigcop_die10 =[ 38, pigcop_die11] {};
void () pigcop_die11 =[ 39, pigcop_die12] {};
void () pigcop_die12 =[ 40, pigcop_die13] {};
void () pigcop_die13 =[ 41, pigcop_die14] {};
void () pigcop_die14 =[ 42, pigcop_die15] {ai_back(5);};
void () pigcop_die15 =[ 43, pigcop_die16] {};
void () pigcop_die16 =[ 44, pigcop_die17] {ai_back(5);};
void () pigcop_die17 =[ 45, pigcop_die18] {};
void () pigcop_die18 =[ 46, pigcop_die19] {};
void () pigcop_die19 =[ 47, pigcop_die20] {};
void () pigcop_die20 =[ 48, pigcop_die21] {};
void () pigcop_die21 =[ 49, pigcop_die22] {};
void () pigcop_die22 =[ 50, pigcop_die23] {};
void () pigcop_die23 =[ 51, pigcop_die24] {};
void () pigcop_die24 =[ 52, pigcop_die24] {remove_monster();};

void() pigcop_die =
{

		if (random() < 0.7) 
		{ 
			self.weapon = IT_SUPER_SHOTGUN;
			self.ammo_shells = 25;
			DropBackpack(); 
		}


// check for gib
	if (self.health < -35)
	{
		monster_gib("progs/gib2.mdl");
		return;
	}

// regular death
	sound (self, CHAN_VOICE, "pigcop/pigdie.wav", 1, ATTN_NORM);
	pigcop_die1();
};

void() monster_pigcop =
{	

	if (deathmatch) {remove(self); return;}

	self.solid = SOLID_SLIDEBOX;
	self.movetype = MOVETYPE_STEP;

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

	setsize (self, '-24 -24 0','24 24 48');
	if (random() < 0.4)
		self.health = self.max_health = M2HEALTH;
	else
		self.health = self.max_health = M1HEALTH;

	self.th_stand = pigcop_stand1;
	self.th_walk = pigcop_walk1;
	self.th_run = pigcop_run1;
	self.th_missile = pigcop_atk;
	self.th_pain = pigcop_pain;
	self.th_die = pigcop_die;
	self.classname = "monster_pigcop";
	walkmonster_start ();
};
