void () zmaster_char_a1;
void () zmaster_run1;

void () hk_idle_sound;

void (float offset) zmaster_shot = {

   local vector offang;
   local vector org;
   local vector vec;

   offang = vectoangles ((self.enemy.origin - self.origin));
   offang_y = (offang_y + (offset * MOVETYPE_TOSS));
   makevectors (offang);
   org = (((self.origin + self.mins) + (self.size * 0.500)) + (v_forward * 20.000) + '0 0 16');
   //vec = normalize (v_forward);
   vec = normalize (self.enemy.origin - self.origin);
   vec_z = ((FALSE - vec_z) + ((random () - 0.500) * 0.100));
   launch_spike (org,vec);
   newmis.classname = "missile";
   //setmodel (newmis,"progs/k_spike.mdl");
	setmodel (newmis,"progs/flame2.mdl"); //new
   setsize (newmis,VEC_ORIGIN,VEC_ORIGIN);
   newmis.velocity = (vec * 1000.000);
   newmis.frame = 1;
   newmis.owner = self;
	
	//added
	newmis.angles = vectoangles(newmis.velocity); //original code
	// turn the flame on it's side, widest end away from player
	newmis.angles_x = newmis.angles_x + 90;
   newmis.touch = T_MissileTouch2;
   //end
   
   sound (self,CHAN_WEAPON,"hknight/attack1.wav",TRUE,ATTN_NORM);

};

//93-105
//100 fire

void () CheckForCharge2 = {

   if ( !enemy_vis ) {

      return ;

   }
   if ( (time < self.attack_finished) ) {

      return ;

   }
   if ( (fabs ((self.origin_z - self.enemy.origin_z)) > 50.000) ) {

      return ;

   }
   if ( (vlen ((self.origin - self.enemy.origin)) < 200.000) ) {

      return ;

   }
   SUB_AttackFinished (FL_SWIM);
  	zmaster_char_a1 ();

};

void () CheckContinueCharge2 = {

   if ( (time > self.attack_finished) ) {

      SUB_AttackFinished (MOVETYPE_WALK);
	zmaster_run1 ();
      return ;

   }
   	if (random () > 0.500) sound (self,CHAN_WEAPON,"knight/sword2.wav",TRUE,ATTN_NORM);
		else sound (self,CHAN_WEAPON,"knight/sword1.wav",TRUE,ATTN_NORM);

};


void () zmaster_walk1 = [ 9.000, zmaster_walk2 ] { hk_idle_sound (); ai_walk (8);};
void () zmaster_walk2 = [ 10.000, zmaster_walk3 ] { ai_walk (6);};
void () zmaster_walk3 = [ 11.000, zmaster_walk4 ] { ai_walk (8);};
void () zmaster_walk4 = [ 12.000, zmaster_walk5 ] { ai_walk (6);};
void () zmaster_walk5 = [ 13.000, zmaster_walk6 ] { ai_walk (8);};
void () zmaster_walk6 = [ 14.000, zmaster_walk7 ] { ai_walk (6);};
void () zmaster_walk7 = [ 15.000, zmaster_walk8 ] { ai_walk (8);};
void () zmaster_walk8 = [ 16.000, zmaster_walk9 ] { ai_walk (6);};
void () zmaster_walk9 = [ 17.000, zmaster_walk10 ] { ai_walk (8);};
void () zmaster_walk10 = [ 18.000, zmaster_walk11 ] {  ai_walk (6);};
void () zmaster_walk11 = [ 19.000, zmaster_walk12 ] {  ai_walk (8);};
void () zmaster_walk12 = [ 20.000, zmaster_walk13 ] {  ai_walk (6);};
void () zmaster_walk13 = [ 21.000, zmaster_walk14 ] {   ai_walk (8);};
void () zmaster_walk14 = [ 22.000, zmaster_walk15 ] {   ai_walk (6);};
void () zmaster_walk15 = [ 23.000, zmaster_walk16 ] {   ai_walk (8);};
void () zmaster_walk16 = [ 24.000, zmaster_walk17 ] {   ai_walk (6);};
void () zmaster_walk17 = [ 25.000, zmaster_walk18 ] {   ai_walk (8);};
void () zmaster_walk18 = [ 26.000, zmaster_walk19 ] {   ai_walk (6);};
void () zmaster_walk19 = [ 27.000, zmaster_walk20 ] {   ai_walk (8);};
void () zmaster_walk20 = [ 28.000, zmaster_walk1 ] {   ai_walk (6);};

void () zmaster_run1 = [ 29.000, zmaster_run2 ] {

   hk_idle_sound ();
	ai_get_angry();
	ai_run (40);
   CheckForCharge2 ();

};

void () zmaster_run2 = [ 30.000, zmaster_run3 ] {

	ai_get_angry();
	ai_run (32);

};

void () zmaster_run3 = [ 31.000, zmaster_run4 ] {

	ai_get_angry();
	ai_run (40);

};

void () zmaster_run4 = [ 32.000, zmaster_run5 ] {

	ai_get_angry();
	ai_run (32);

};

void () zmaster_run5 = [ 33.000, zmaster_run6 ] {

	ai_get_angry();
	ai_run (40);

};

void () zmaster_run6 = [ 34.000, zmaster_run7 ] {

	ai_get_angry();
	ai_run (32);

};

void () zmaster_run7 = [ 35.000, zmaster_run8 ] {

	ai_get_angry();
	ai_run (40);

};

void () zmaster_run8 = [ 36.000, zmaster_run1 ] {

	ai_get_angry();
	ai_run (32);

};

void () zmaster_magica1 = [ 79.000, zmaster_magica2 ] {

   ai_face ();
	
};

void () zmaster_magica2 = [ 80.000, zmaster_magica3 ] {

   ai_face ();
	
};

void () zmaster_magica3 = [ 81.000, zmaster_magica4 ] {

   ai_face ();
	
};

void () zmaster_magica4 = [ 82.000, zmaster_magica5 ] {

   ai_face ();
	
};

void () zmaster_magica5 = [ 83.000, zmaster_magica6 ] {

   ai_face ();
	
};

void () zmaster_magica6 = [ 84.000, zmaster_magica7 ] {

   ai_face ();
	
};

void () zmaster_magica7 = [ 85.000, zmaster_magica8 ] {

   zmaster_shot (-2);
	
};

void () zmaster_magica8 = [ 86.000, zmaster_magica9 ] {

   zmaster_shot (-1);
	
};

void () zmaster_magica9 = [ 87.000, zmaster_magica10 ] {

   zmaster_shot (0);
	
};

void () zmaster_magica10 = [ 88.000, zmaster_magica11 ] {

   zmaster_shot (1);
	
};

void () zmaster_magica11 = [ 89.000, zmaster_magica12 ] {

   zmaster_shot (2);
	
};

void () zmaster_magica12 = [ 90.000, zmaster_magica13 ] {

   zmaster_shot (3);
	
};

void () zmaster_magica13 = [ 91.000, zmaster_magica14 ] {

   ai_face ();
	
};

void () zmaster_magica14 = [ 92.000, zmaster_run1 ] {

   ai_face ();
   SUB_CheckRefire(zmaster_magica1);
	
};

void () zmaster_firebolt = {

   local vector org;

   self.effects = (self.effects | EF_MUZZLEFLASH);
   makevectors (self.angles);
   org = (((self.origin + (v_forward * 32)) + (v_right * 12.00)) + '0 0 80');
   LaunchFirebolt (org,self.enemy.origin);

};

void () zmaster_magicb1 = [ 93.000, zmaster_magicb2 ] {  ai_face ();};
void () zmaster_magicb2 = [ 94.000, zmaster_magicb3 ] {  ai_face ();};
void () zmaster_magicb3 = [ 95.000, zmaster_magicb4 ] {  ai_face ();};
void () zmaster_magicb4 = [ 96.000, zmaster_magicb5 ] {  ai_face ();};
void () zmaster_magicb5 = [ 97.000, zmaster_magicb6 ] {  ai_face ();};
void () zmaster_magicb6 = [ 98.000, zmaster_magicb7 ] {  ai_face ();};
void () zmaster_magicb7 = [ 99.000, zmaster_magicb8 ] {  zmaster_firebolt();};
void () zmaster_magicb8 = [ 100.000, zmaster_magicb9 ] {  zmaster_firebolt();};
void () zmaster_magicb9 = [ 101.000, zmaster_magicb10 ] {  zmaster_firebolt();};
void () zmaster_magicb10 = [ 102.000, zmaster_magicb11 ] {SUB_CheckRefire(zmaster_magicb7); };
void () zmaster_magicb11 = [ 103.000, zmaster_magicb12 ] {};
void () zmaster_magicb12 = [ 104.000, zmaster_magicb13 ] {};
void () zmaster_magicb13 = [ 105.000, zmaster_run1 ] { ai_face (); };

void () zmaster_magicc1 = [ 155.000, zmaster_magicc2 ] {

   ai_face ();
	
};

void () zmaster_magicc2 = [ 156.000, zmaster_magicc3 ] {

   ai_face ();
	
};

void () zmaster_magicc3 = [ 157.000, zmaster_magicc4 ] {

   ai_face ();
	
};

void () zmaster_magicc4 = [ 158.000, zmaster_magicc5 ] {

   ai_face ();
	
};

void () zmaster_magicc5 = [ 159.000, zmaster_magicc6 ] {

   ai_face ();

};

void () zmaster_magicc6 = [ 160.000, zmaster_magicc7 ] {

   zmaster_shot (CONTENT_SOLID);
	
};

void () zmaster_magicc7 = [ 161.000, zmaster_magicc8 ] {

   zmaster_shot (CONTENT_EMPTY);
	
};

void () zmaster_magicc8 = [ 162.000, zmaster_magicc9 ] {

   zmaster_shot (FALSE);
	
};

void () zmaster_magicc9 = [ 163.000, zmaster_magicc10 ] {

   zmaster_shot (TRUE);
	
};

void () zmaster_magicc10 = [ 164.000, zmaster_magicc11 ] {

   zmaster_shot (FL_SWIM);
	
};

void () zmaster_magicc11 = [ 165.000, zmaster_run1 ] {

   zmaster_shot (MOVETYPE_WALK);
   SUB_CheckRefire(zmaster_magicc6);
	
};

void () zmaster_char_a1 = [ 63.000, zmaster_char_a2 ] {

			ai_charge (40);

};

void () zmaster_char_a2 = [ 64.000, zmaster_char_a3 ] {

			ai_charge (32);

};

void () zmaster_char_a3 = [ 65.000, zmaster_char_a4 ] {

			ai_charge (40.000);

};

void () zmaster_char_a4 = [ 66.000, zmaster_char_a5 ] {

			ai_charge (32);

};

void () zmaster_char_a5 = [ 67.000, zmaster_char_a6 ] {

			ai_charge (40.000);

};

void () zmaster_char_a6 = [ 68.000, zmaster_char_a7 ] {

			ai_charge (32);
   ai_melee ();

};

void () zmaster_char_a7 = [ 69.000, zmaster_char_a8 ] {

			ai_charge (40.000);
   ai_melee ();

};

void () zmaster_char_a8 = [ 70.000, zmaster_char_a9 ] {

			ai_charge (32);
   ai_melee ();

};

void () zmaster_char_a9 = [ 71.000, zmaster_char_a10 ] {

			ai_charge (40.000);
   ai_melee ();

};

void () zmaster_char_a10 = [ 72.000, zmaster_char_a11 ] {

			ai_charge (32);
   ai_melee ();

};

void () zmaster_char_a11 = [ 73.000, zmaster_char_a12 ] {

			ai_charge (40);
   ai_melee ();

};

void () zmaster_char_a12 = [ 74.000, zmaster_char_a13 ] {

			ai_charge (32);

};

void () zmaster_char_a13 = [ 75.000, zmaster_char_a14 ] {

			ai_charge (40);

};

void () zmaster_char_a14 = [ 76.000, zmaster_char_a15 ] {

			ai_charge (32);

};

void () zmaster_char_a15 = [ 77.000, zmaster_char_a16 ] {

			ai_charge (40);

};

void () zmaster_char_a16 = [ 78.000, zmaster_run1 ] {

			ai_charge (32);

};

void () zmaster_char_b1 = [ 106.000, zmaster_char_b2 ] {

   CheckContinueCharge2 ();
	ai_charge (32);
   ai_melee ();

};

void () zmaster_char_b2 = [ 107.000, zmaster_char_b3 ] {

			ai_charge (40.000);
   ai_melee ();

};

void () zmaster_char_b3 = [ 108.000, zmaster_char_b4 ] {

			ai_charge (32.000);
   ai_melee ();

};

void () zmaster_char_b4 = [ 109.000, zmaster_char_b5 ] {

			ai_charge (40.000);
   ai_melee ();

};

void () zmaster_char_b5 = [ 110.000, zmaster_char_b6 ] {

			ai_charge (32.000);
   ai_melee ();

};

void () zmaster_char_b6 = [ 111.000, zmaster_char_b1 ] {

			ai_charge (40);
   ai_melee ();

};

void () zmaster_slice1 = [ 112.000, zmaster_slice2 ] {

			ai_charge (32);

};

void () zmaster_slice2 = [ 113.000, zmaster_slice3 ] {

			ai_charge (40);

};

void () zmaster_slice3 = [ 114.000, zmaster_slice4 ] {

			ai_charge (32.000);

};

void () zmaster_slice4 = [ 115.000, zmaster_slice5 ] {

			ai_charge (40);

};

void () zmaster_slice5 = [ 116.000, zmaster_slice6 ] {

			ai_charge (32);
   ai_melee ();

};

void () zmaster_slice6 = [ 117.000, zmaster_slice7 ] {

			ai_charge (40);
   ai_melee ();

};

void () zmaster_slice7 = [ 118.000, zmaster_slice8 ] {

			ai_charge (32);
   ai_melee ();

};

void () zmaster_slice8 = [ 119.000, zmaster_slice9 ] {

			ai_charge (40);
   ai_melee ();

};

void () zmaster_slice9 = [ 120.000, zmaster_slice10 ] {

   ai_melee ();

};

void () zmaster_slice10 = [ 121.000, zmaster_run1 ] {

			ai_charge (40);

};

void () zmaster_smash1 = [ 122.000, zmaster_smash2 ] {

			ai_charge (15);

};

void () zmaster_smash2 = [ 123.000, zmaster_smash3 ] {

			ai_charge (32);

};

void () zmaster_smash3 = [ 124.000, zmaster_smash4 ] {

			ai_charge (40);

};

void () zmaster_smash4 = [ 125.000, zmaster_smash5 ] {

			ai_charge (32);

};

void () zmaster_smash5 = [ 126.000, zmaster_smash6 ] {

			ai_charge (40);
   ai_melee ();

};

void () zmaster_smash6 = [ 127.000, zmaster_smash7 ] {

			ai_charge (32);
   ai_melee ();

};

void () zmaster_smash7 = [ 128.000, zmaster_smash8 ] {

			ai_charge (40.000);
   ai_melee ();

};

void () zmaster_smash8 = [ 129.000, zmaster_smash9 ] {

			ai_charge (15);
   ai_melee ();

};

void () zmaster_smash9 = [ 130.000, zmaster_smash10 ] {

			ai_charge (32);
   ai_melee ();

};

void () zmaster_smash10 = [ 131.000, zmaster_smash11 ] {

			ai_charge (15);

};

void () zmaster_smash11 = [ 132.000, zmaster_run1 ] {

			ai_charge (18);

};

void () zmaster_watk1 = [ 133.000, zmaster_watk2 ] {

			ai_charge (15);

};

void () zmaster_watk2 = [ 134.000, zmaster_watk3 ] {

			ai_charge (15);


};

void () zmaster_watk3 = [ 135.000, zmaster_watk4 ] {

			ai_charge (19);


};

void () zmaster_watk4 = [ 136.000, zmaster_watk5 ] {

	   ai_melee ();


};

void () zmaster_watk5 = [ 137.000, zmaster_watk6 ] {

      ai_melee ();


};

void () zmaster_watk6 = [ 138.000, zmaster_watk7 ] {

	   ai_melee ();


};

void () zmaster_watk7 = [ 139.000, zmaster_watk8 ] {

		ai_charge (18);


};

void () zmaster_watk8 = [ 140.000, zmaster_watk9 ] {

		ai_charge (32);


};

void () zmaster_watk9 = [ 141.000, zmaster_watk10 ] {

		ai_charge (40);


};

void () zmaster_watk10 = [ 142.000, zmaster_watk11 ] {

		ai_charge (32);
   ai_melee ();


};

void () zmaster_watk11 = [ 143.000, zmaster_watk12 ] {

		ai_charge (15);
   ai_melee ();


};

void () zmaster_watk12 = [ 144.000, zmaster_watk13 ] {

		ai_charge (18);
   ai_melee ();


};

void () zmaster_watk13 = [ 145.000, zmaster_watk14 ] {

		ai_charge (15);


};

void () zmaster_watk14 = [ 146.000, zmaster_watk15 ] {

		ai_charge (15);


};

void () zmaster_watk15 = [ 147.000, zmaster_watk16 ] {

		ai_charge (18);


};

void () zmaster_watk16 = [ 148.000, zmaster_watk17 ] {

		ai_charge (15);


};

void () zmaster_watk17 = [ 149.000, zmaster_watk18 ] {

		ai_charge (18);
   ai_melee ();


};

void () zmaster_watk18 = [ 150.000, zmaster_watk19 ] {

		ai_charge (32);
   ai_melee ();


};

void () zmaster_watk19 = [ 151.000, zmaster_watk20 ] {

		ai_charge (32);
   ai_melee ();


};

void () zmaster_watk20 = [ 152.000, zmaster_watk21 ] {

		ai_charge (40);


};

void () zmaster_watk21 = [ 153.000, zmaster_watk22 ] {

		ai_charge (32);


};

void () zmaster_watk22 = [ 154.000, zmaster_run1 ] {

		ai_charge (40);

};

void (entity attacker, float damage) zmaster_pain = {

	if (damage < random()*400) return;

   if ( (self.pain_finished > time) ) {

      return ;

   }
   sound (self,CHAN_VOICE,"hknight/pain1.wav",TRUE,ATTN_NORM);
   if ( ((time - self.pain_finished) > MOVETYPE_FLY) ) {

      hknight_pain1 ();
      self.pain_finished = (time + TRUE);
      return ;

   }
   if ( ((random () * SVC_INTERMISSION) > damage) ) {

      return ;

   }
   self.pain_finished = (time + TRUE);
   hknight_pain1 ();

};

float zmaster_type /* = 0.000 */;

void () zmaster_melee = {

   zmaster_type = (zmaster_type + TRUE);
   sound (self,CHAN_WEAPON,"hknight/slash1.wav",TRUE,ATTN_NORM);
   if (zmaster_type == 1) zmaster_slice1 ();
   else if (zmaster_type == 2) zmaster_smash1 ();
   else if (zmaster_type == 3) zmaster_watk1 ();
   else if (zmaster_type == 4) zmaster_char_a1 ();
   else if (zmaster_type == 5) { zmaster_char_b1 (); zmaster_type = FALSE; }

};

void () zmaster_missile =
{

	local float r;
	r = random();
	//if (r < 0.25) zmaster_magica1();
	if (r < 0.6) zmaster_magicb1();
	else zmaster_magicc1();

};

void () monster_zombie_knight = {


   if ( deathmatch ) {

      remove (self);
      return ;

   }

   self.bondoflag = B_BOSS;
   self.solid = SOLID_SLIDEBOX;
   self.movetype = MOVETYPE_STEP;
   setmodel (self,"progs/zmaster.mdl");
   setsize (self,VEC_HULL2_MIN,'32.000 32.000 96.000');
   self.health = self.max_health = M5HEALTH;
   self.th_stand = hknight_stand1;
   self.th_walk = zmaster_walk1;
   self.th_run = zmaster_run1;
   self.th_melee = zmaster_melee;
   self.th_missile = zmaster_missile;
   self.th_pain = zmaster_pain;
   self.th_die = hknight_die;
   self.classname = "monster_zombie_knight";
	self.netname = "Demon King";   

	//savecritter();

	walkmonster_start ();

};

/*
void () monster_zombie_knight_melee = {


   if ( deathmatch ) {

      remove (self);
      return ;

   }

   self.solid = SOLID_SLIDEBOX;
   self.movetype = MOVETYPE_STEP;
   setmodel (self,"progs/zmaster.mdl");
   setsize (self,'-48 -48 -24,'48.000 48.000 96.000');
   self.health = self.max_health = M5HEALTH;
   self.armorvalue = M4HEALTH;
   self.armortype = 1;
   self.th_stand = hknight_stand1;
   self.th_walk = zmaster_walk1;
   self.th_run = zmaster_run1;
   self.th_melee = zmaster_melee;
   //self.th_missile = zmaster_missile;
   self.th_pain = hknight_pain;
   self.th_die = hknight_die;
   self.classname = "monster_zombie_knight_melee";

	//savecritter();

	walkmonster_start ();

};
*/

