void () armagonbody_think;
/*
crafty
0
1-39 stand
40-45 run
46-53 fire 46
54-57 paina
58-67 jump
68-71 painb
72-77 diea
78-83 dieb
*/


void () crafty_stand1 = [3, crafty_stand2] {ai_stand();};
void () crafty_stand2 = [6, crafty_stand3] {ai_stand();};
void () crafty_stand3 = [9, crafty_stand4] {ai_stand();};
void () crafty_stand4 = [12, crafty_stand5] {ai_stand();};
void () crafty_stand5 = [15, crafty_stand6] {ai_stand();};
void () crafty_stand6 = [18, crafty_stand7] {ai_stand();};
void () crafty_stand7 = [21, crafty_stand8] {ai_stand();};
void () crafty_stand8 = [24, crafty_stand9] {ai_stand();};
void () crafty_stand9 = [27, crafty_stand10] {ai_stand();};
void () crafty_stand10 = [30, crafty_stand11] {ai_stand();};
void () crafty_stand11 = [33, crafty_stand12] {ai_stand();};
void () crafty_stand12 = [36, crafty_stand13] {ai_stand();};
void () crafty_stand13 = [39, crafty_stand1] {ai_stand();};

void () crafty_walk1 = [40, crafty_walk2] {ai_walk(8);};
void () crafty_walk2 = [41, crafty_walk3] {ai_walk(10);};
void () crafty_walk3 = [42, crafty_walk4] {ai_walk(8);};
void () crafty_walk4 = [43, crafty_walk5] {ai_walk(10);};
void () crafty_walk5 = [44, crafty_walk6] {ai_walk(8);};
void () crafty_walk6 = [45, crafty_walk1] {ai_walk(10);};

void () crafty_run1 = [40, crafty_run2] {ai_run(20);};
void () crafty_run2 = [41, crafty_run3] {ai_run(25);};
void () crafty_run3 = [42, crafty_run4] {ai_run(20);};
void () crafty_run4 = [43, crafty_run5] {ai_run(25);};
void () crafty_run5 = [44, crafty_run6] {ai_run(20);};
void () crafty_run6 = [45, crafty_run1] {ai_run(25);};

void () crafty_shotgun = {

   local vector dir;
   local entity en;

   ai_face ();
   sound (self,CHAN_WEAPON,"erifle/fire.wav",TRUE,ATTN_NORM);
   en = self.enemy;
   dir = (en.origin - (en.velocity * 0.200));
   dir = normalize ((dir - self.origin));
   FireBullets (3,dir,'0.100 0.080 0.000');

};

void () crafty_fire1 = [46, crafty_fire2] {ai_face(); crafty_shotgun();};
void () crafty_fire2 = [47, crafty_fire3] {};
void () crafty_fire3 = [48, crafty_fire4] {ai_face();};
void () crafty_fire4 = [49, crafty_fire5] {};
void () crafty_fire5 = [50, crafty_fire6] {ai_face();};
void () crafty_fire6 = [51, crafty_fire7] {};
void () crafty_fire7 = [52, crafty_fire8] {ai_face();};
void () crafty_fire8 = [53, crafty_run1] {SUB_CheckRefire(crafty_fire1);};

void () crafty_die1 = [173, crafty_die2] {};
void () crafty_die2 = [174, crafty_die3] {};
void () crafty_die3 = [175, crafty_die4] {};
void () crafty_die4 = [176, crafty_die5] {};
void () crafty_die5 = [177, crafty_die5] {remove_monster();};

void () crafty_diea1 = [178, crafty_diea2] {};
void () crafty_diea2 = [179, crafty_diea3] {};
void () crafty_diea3 = [180, crafty_diea4] {};
void () crafty_diea4 = [181, crafty_diea5] {};
void () crafty_diea5 = [182, crafty_diea6] {};
void () crafty_diea6 = [183, crafty_diea6] {remove_monster();};

void () crafty_dieb1 = [184, crafty_dieb2] {};
void () crafty_dieb2 = [185, crafty_dieb3] {};
void () crafty_dieb3 = [186, crafty_dieb4] {};
void () crafty_dieb4 = [187, crafty_dieb5] {};
void () crafty_dieb5 = [188, crafty_dieb6] {};
void () crafty_dieb6 = [189, crafty_dieb6] {remove_monster();};

void () crafty_diec1 = [190, crafty_diec2] {};
void () crafty_diec2 = [191, crafty_diec3] {};
void () crafty_diec3 = [192, crafty_diec4] {};
void () crafty_diec4 = [193, crafty_diec5] {};
void () crafty_diec5 = [194, crafty_diec6] {};
void () crafty_diec6 = [195, crafty_diec7] {};
void () crafty_diec7 = [196, crafty_diec8] {};
void () crafty_diec8 = [197, crafty_diec8] {remove_monster();};

void () crafty_paina1 = [54, crafty_paina2] {ai_pain();};
void () crafty_paina2 = [55, crafty_paina3] {};
void () crafty_paina3 = [56, crafty_paina4] {ai_pain();};
void () crafty_paina4 = [57, crafty_run1] {};

void () crafty_painb1 = [58, crafty_paina2] {ai_pain();};
void () crafty_painb2 = [59, crafty_paina3] {};
void () crafty_painb3 = [60, crafty_paina4] {ai_pain();};
void () crafty_painb4 = [61, crafty_run1] {};

void () crafty_painc1 = [62, crafty_paina2] {ai_pain();};
void () crafty_painc2 = [63, crafty_paina3] {};
void () crafty_painc3 = [64, crafty_paina4] {ai_pain();};
void () crafty_painc4 = [65, crafty_run1] {};

void(entity attacker, float damage) crafty_pain =
{

	// don't make multiple pain sounds right after each other
   if (self.pain_finished > time)
      return;

   if (random() < 0.2)
   {
   	if (random() < 0.5)
			sound (self, CHAN_VOICE, "crafty/pain25_1.wav", 1, ATTN_NORM);    
		else
			sound (self, CHAN_VOICE, "crafty/pain25_2.wav", 1, ATTN_NORM);    
   }

   self.pain_finished = time + 2;
   
   local float n;
   n = ceil(random()*3);
   if (n == 1) crafty_paina1();
   else if (n == 2) crafty_painb1();
   else crafty_painc1();

};

void () crafty_die = {

	remove(self.trigger_field);
	if (random() < 0.7)
	{
		DropBackpack(); 
	}

   if ( (self.health < -50.000 && self.classname != "monster_fuel") ) {

      sound (self,CHAN_VOICE,"player/udeath.wav",TRUE,ATTN_NORM);
      
      ThrowGib ("progs/gib3.mdl",self.health, self);
      ThrowGib ("progs/gib1.mdl",self.health, self);
      ThrowGib ("progs/gib3.mdl",self.health, self);
      ThrowGib ("progs/gib2.mdl",self.health, self);
      
      monster_gib("progs/gib3.mdl");
      return ;

   }
   if (random()  < 0.5)
	   sound (self,CHAN_VOICE,"crafty/death1.wav",TRUE,ATTN_NORM);
   else 
   	sound (self,CHAN_VOICE,"crafty/death2.wav",TRUE,ATTN_NORM);
	self.solid = SOLID_NOT;
	local float n;
	n = ceil (random()*4);
	if (n == 1) 
		crafty_die1(); 
	else if (n == 2)
		crafty_diea1(); 
	else if (n == 3)
		crafty_dieb1(); 
	else 
		crafty_diec1(); 

};

void () monster_crafty =
{

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

   self.solid = SOLID_SLIDEBOX;
   self.movetype = MOVETYPE_STEP;
   setmodel (self,"progs/crafty3.mdl");
   setsize (self, '-16 -16 -24', '16 16 40' );
   self.skin = floor(random()*7);
   self.health = self.max_health = (self.skin + 1)*M1HEALTH;
   self.th_stand = crafty_stand1;
   self.th_walk = crafty_walk1;
   self.th_run = crafty_run1;
   self.th_die = crafty_die;
   self.th_missile = crafty_fire1;
   self.th_pain = crafty_pain;
   self.weapon = IT_SHOTGUN;
   self.ammo_shells = 25;
   self.classname = "monster_crafty";
	//savecritter(); //respawn
   walkmonster_start ();

	local entity gun;
	gun = spawn();
	gun.origin = self.origin;
	gun.solid = SOLID_NOT;
	gun.movetype = MOVETYPE_STEP;
	self.trigger_field = gun;
	gun.classname = "monster_crafty";
	gun.trigger_field = self;
	setmodel(gun,"progs/crftygun.mdl");
	setsize(gun,VEC_ORIGIN,VEC_ORIGIN);
	setorigin(gun,self.origin);
	gun.think = armagonbody_think;
	gun.nextthink = time + 0.1;
};

void () supercrafty_run1 = [40, supercrafty_run2] {ai_run(40);};
void () supercrafty_run2 = [41, supercrafty_run3] {ai_run(32);};
void () supercrafty_run3 = [42, supercrafty_run4] {ai_run(40);};
void () supercrafty_run4 = [43, supercrafty_run5] {ai_run(32);};
void () supercrafty_run5 = [44, supercrafty_run6] {ai_run(40);};
void () supercrafty_run6 = [45, supercrafty_run1] {ai_run(32);};

void () crafty_rocket = {

   local vector org;

   self.effects = (self.effects | EF_MUZZLEFLASH);
   makevectors (self.angles);
   sound (self,CHAN_WEAPON,"weapons/sgun1.wav",TRUE,ATTN_NORM);
   org = (((self.origin + (v_forward * 32)) + (v_right * 32.00)) + '0 0 72');
   LaunchNuke (org,(self.enemy.origin - org));

};

void () supercrafty_fire1 = [46, supercrafty_fire2] {ai_face(); crafty_rocket();};
void () supercrafty_fire2 = [47, supercrafty_fire3] {};
void () supercrafty_fire3 = [48, supercrafty_fire4] {ai_face();};
void () supercrafty_fire4 = [49, supercrafty_fire5] {};
void () supercrafty_fire5 = [50, supercrafty_fire6] {ai_face();};
void () supercrafty_fire6 = [51, supercrafty_fire7] {};
void () supercrafty_fire7 = [52, supercrafty_fire8] {ai_face();};
void () supercrafty_fire8 = [53, supercrafty_run1] {SUB_CheckRefire(supercrafty_fire1);};

void () supercrafty_pain = {return;};

void () supercrafty_die = { 

   if (random()  < 0.5)
	   sound (self,CHAN_VOICE,"crafty/death1.wav",TRUE,ATTN_NORM);
   else 
   	sound (self,CHAN_VOICE,"crafty/death2.wav",TRUE,ATTN_NORM);

	self.solid = SOLID_NOT; 
	self.ammo_cells = 1; 
	DropBackpack(); 
	if (self.health < -50)
		ThrowGib("progs/gib1.mdl",self.health, self);
	if (random() < 0.5) 
		crafty_die1(); 
	else 
		crafty_diea1(); 

};

void () monster_super_crafty = {

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

	self.bondoflag = B_BOSS;
   self.solid = SOLID_SLIDEBOX;
   self.movetype = MOVETYPE_STEP;
   setmodel (self,"progs/crafty.mdl");
   setsize (self, '-32 -32 -24', '32 32 128' );
   self.health = self.max_health = M5HEALTH;	//was 600
   self.skin = floor(random()*9);
   self.health = self.health + 500 * self.skin;
   self.th_stand = crafty_stand1;
   self.th_walk = crafty_walk1;
   self.th_run = supercrafty_run1;
   self.th_die = supercrafty_die;
   self.th_missile = supercrafty_fire1;
   self.th_pain = supercrafty_pain;
   self.classname = "monster_super_crafty";
	self.netname = "Fembot Commander";   
	//savecritter(); //respawn
   walkmonster_start ();

};


