/*

	Duke Boss

	inspired by 3DRealms
	model and skin(s) from the Duke Nukem High Resolution Pack: http://hrp.duke4.net
	Quake conversion and code by bondo
	
72-87 swim
60-71 die
56-59 crouch walk
50-55 jump
45-50 kick
29-44 run/walk
12-28 hover
1-11 stand

*/

void () db_stand1 = [0, db_stand2] {ai_stand();};
void () db_stand2 = [2, db_stand2] {ai_stand();};
void () db_stand3 = [4, db_stand3] {ai_stand();};
void () db_stand4 = [6, db_stand4] {ai_stand();};
void () db_stand5 = [8, db_stand5] {ai_stand();};
void () db_stand6 = [10, db_stand1] {ai_stand();};

void () db_walk1 = [28, db_walk2] {ai_walk(12);};
void () db_walk2 = [30, db_walk3] {ai_walk(15);};
void () db_walk3 = [32, db_walk4] {ai_walk(12);};
void () db_walk4 = [34, db_walk5] {ai_walk(15);};
void () db_walk5 = [36, db_walk6] {ai_walk(12);};
void () db_walk6 = [38, db_walk7] {ai_walk(15);};
void () db_walk7 = [40, db_walk8] {ai_walk(12);};
void () db_walk8 = [42, db_walk9] {ai_walk(15);};
void () db_walk9 = [44, db_walk1] {ai_walk(12);};

void () db_run1 = [27, db_run2] {if (random() < 0.2) DukeTaunt(self); ai_get_angry(); ai_run(25);};
void () db_run2 = [29, db_run3] { ai_get_angry(); ai_run(30);};
void () db_run3 = [31, db_run4] { ai_get_angry(); ai_run(25);};
void () db_run4 = [33, db_run5] { ai_get_angry(); ai_run(30);};
void () db_run5 = [35, db_run6] { ai_get_angry(); ai_run(25);};
void () db_run6 = [37, db_run7] { ai_get_angry(); ai_run(30);};
void () db_run7 = [39, db_run8] { ai_get_angry(); ai_run(25);};
void () db_run8 = [41, db_run9] { ai_get_angry(); ai_run(30);};
void () db_run9 = [43, db_run1] { ai_get_angry(); ai_run(25);};

void () dukeboss_nuke = {

   local vector org;

   self.effects = (self.effects | EF_MUZZLEFLASH);
   makevectors (self.angles);
   org = (((self.origin + (v_forward * 32)) + (v_right * 32)) + '0.000 0.000 80.000');
   LaunchNuke (org,(self.enemy.origin - org));

};

void () db_freeze = {

   local vector org;

   self.effects = (self.effects | EF_MUZZLEFLASH);
   makevectors (self.angles);
   org = (((self.origin + (v_forward * 32)) + (v_right * 32)) + '0.000 0.000 80.000');
   LaunchFreeze (org,(self.enemy.origin - org));

};

void () dbj_run1;

void () db_attack1 = [0, db_attack2] {ai_face(); if (self.classname == "monster_dbj") Exhaust(); if (random() < 0.6) DukeTaunt(self); };
void () db_attack2 = [2, db_attack3] {ai_face(); dukeboss_nuke(); };
void () db_attack3 = [4, db_attack4] { ai_face(); if (self.classname == "monster_dbj") Exhaust();};
void () db_attack4 = [6, db_attack5] { ai_face();};
void () db_attack5 = [8, db_attack6] { ai_face(); if (self.classname == "monster_dbj") Exhaust();};
void () db_attack6 = [10, db_run1] {if (self.classname == "monster_dbj") dbj_run1(); };

void () db_attacka1 = [0, db_attacka2] {ai_face(); if (self.classname == "monster_dbj") Exhaust(); if (random() < 0.6) DukeTaunt(self); };
void () db_attacka2 = [2, db_attacka3] {ai_face();db_freeze(); db_freeze(); db_freeze();};
void () db_attacka3 = [4, db_attacka4] { ai_face(); if (self.classname == "monster_dbj") Exhaust();};
void () db_attacka4 = [2, db_attacka3] {ai_face();db_freeze(); db_freeze(); db_freeze();};
void () db_attacka5 = [4, db_attacka4] { ai_face(); if (self.classname == "monster_dbj") Exhaust();};
void () db_attacka6 = [2, db_attacka3] {ai_face();db_freeze(); db_freeze(); db_freeze();};
void () db_attacka7 = [4, db_attacka4] { ai_face(); if (self.classname == "monster_dbj") Exhaust();};
void () db_attacka8 = [6, db_attacka5] { };
void () db_attacka9 = [8, db_attacka6] { ai_face(); if (self.classname == "monster_dbj") Exhaust();};
void () db_attacka10 = [10, db_run1] {if (self.classname == "monster_dbj") dbj_run1(); };

void () db_attack =
{

	local float d;
	d = vlen(self.origin - self.enemy.origin);
	if (d < 512) db_attacka1(); else db_attack1();

};

void () db_kick1 = [44, db_kick2] {ai_face(); ai_charge(10); if (self.classname == "monster_dbj") Exhaust();};
void () db_kick2 = [45, db_kick3] {ai_face(); ai_charge(10); if (self.classname == "monster_dbj") Exhaust();};
void () db_kick3 = [46, db_kick4] {ai_face(); ai_charge(10); if (self.classname == "monster_dbj") Exhaust();};
void () db_kick4 = [47, db_kick5] {

	ai_face(); 
	ai_charge(10);
   local vector delta;
   local float ldmg;

   if ( !self.enemy ) {

      return ;

   }
   ai_charge (0);
   delta = (self.enemy.origin - self.origin);
   if ( (vlen (delta) > 120.000) ) {

      return ;

   }
   if ( !CanDamage (self.enemy,self) ) {

      return ;

   }
   ldmg = M4DAMAGE;
	ldmg = ldmg * (1 + random()*2);
	if (random() < 0.4) ldmg = ldmg * 3;

   T_Damage (self.enemy,self,self,ldmg);
   T_RadiusDamage(self,self,ldmg,self);
   sound (self,CHAN_VOICE,"duke/kickhit.wav",TRUE,ATTN_NORM);
   SpawnMeatSpray ((self.origin + (v_forward * FL_INWATER)),((crandom () * 100.000) * v_right));
   SpawnMeatSpray ((self.origin + (v_forward * FL_INWATER)),((crandom () * 100.000) * v_right));

if (self.classname == "monster_dbj") Exhaust();
};
void () db_kick5 = [48, db_kick6] {ai_face(); ai_charge(10); if (self.classname == "monster_dbj") Exhaust(); };
void () db_kick6 = [49, db_run1] {ai_face(); ai_charge(10); if (self.classname == "monster_dbj") {Exhaust(); dbj_run1(); } };


void () db_pain1 = [59, db_pain2] {if (self.classname == "monster_dbj") Exhaust();DukePain(self); ai_back(15);};
void () db_pain2 = [60, db_run1] {if (self.classname == "monster_dbj") { Exhaust(); dbj_run1(); } };

void (entity attacker, float damage) db_pain =
{

   if ( (self.health <= FALSE) ) {

      return ;

   }
	if (damage < random() * 800) return;
	
   if ( (self.pain_finished > time) ) {

      return ;

   }
   self.pain_finished = (time + FL_SWIM);
	db_pain1();
	
};

void () db_die1 = [59,db_die2] {
if (self.classname == "monster_dbj")
{
   self.velocity_x = (-200.000 + (400.000 * random ()));
   self.velocity_y = (-200.000 + (400.000 * random ()));
   self.velocity_z = (100.000 + (100.000 * random ()));
   self.flags = (self.flags - (self.flags & FL_ONGROUND));
}
	self.bondoflag = B_BOSS;
	self.ammo_cells = 1; 
	DropBackpack();
};
void () db_die2 = [60,db_die3] {self.solid = SOLID_NOT; };
void () db_die3 = [61,db_die4] {};
void () db_die4 = [62,db_die5] {};
void () db_die5 = [63,db_die6] {};
void () db_die6 = [64,db_die7] {};
void () db_die7 = [65,db_die8] {};
void () db_die8 = [66,db_die9] {};
void () db_die9 = [67,db_die10] {};
void () db_die10 = [68,db_die11] {};
void () db_die11 = [69,db_die12] {};
void () db_die12 = [70,db_die12] {};

void() monster_duke_boss =
{

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

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

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

   setsize (self, '-32 -32 0', '32 32 112');
   self.health = self.max_health = M5HEALTH; 

   self.th_stand   = db_stand1;
   self.th_walk    = db_walk1;
   self.th_run     = db_run1;
   self.th_die     = db_die1;
   self.th_missile = db_attack1;
   self.th_melee = db_kick1;
   self.th_pain    = db_pain;
	self.bondoflag = B_BOSS;
	self.classname = "monster_duke_boss";
	self.netname = "Duke Super Clone";   
   
   walkmonster_start();
};

void () dbj_stand1 = [12, dbj_stand2] {ai_stand();Exhaust(); };
void () dbj_stand2 = [14, dbj_stand3] {ai_stand(); Exhaust(); };
void () dbj_stand3 = [16, dbj_stand4] {ai_stand();Exhaust(); };
void () dbj_stand4 = [18, dbj_stand5] {ai_stand(); Exhaust(); };
void () dbj_stand5 = [20, dbj_stand6] {ai_stand();Exhaust(); };
void () dbj_stand6 = [22, dbj_stand7] {ai_stand(); Exhaust(); };
void () dbj_stand7 = [24, dbj_stand8] {ai_stand();Exhaust(); };
void () dbj_stand8 = [26, dbj_stand9] {ai_stand(); Exhaust(); };
void () dbj_stand9 = [28, dbj_stand1] {ai_stand();Exhaust(); };

void () dbj_walk1 = [12, dbj_walk2] {ai_walk(12);Exhaust(); };
void () dbj_walk2 = [14, dbj_walk3] {ai_walk(15); Exhaust(); };
void () dbj_walk3 = [16, dbj_walk4] {ai_walk(12);Exhaust(); };
void () dbj_walk4 = [18, dbj_walk5] {ai_walk(15); Exhaust(); };
void () dbj_walk5 = [20, dbj_walk6] {ai_walk(12);Exhaust(); };
void () dbj_walk6 = [22, dbj_walk7] {ai_walk(15); Exhaust(); };
void () dbj_walk7 = [24, dbj_walk8] {ai_walk(12);Exhaust(); };
void () dbj_walk8 = [26, dbj_walk9] {ai_walk(15); Exhaust(); };
void () dbj_walk9 = [28, dbj_walk1] {ai_walk(12);Exhaust(); };

void () dbj_run1 = [12, dbj_run2] {ai_get_angry(); ai_run(30);Exhaust(); };
void () dbj_run2 = [14, dbj_run3] {ai_get_angry(); ai_run(25); Exhaust(); };
void () dbj_run3 = [16, dbj_run4] {ai_get_angry(); ai_run(30);Exhaust(); };
void () dbj_run4 = [18, dbj_run5] {ai_get_angry(); ai_run(25); Exhaust(); };
void () dbj_run5 = [20, dbj_run6] {ai_get_angry(); ai_run(30);Exhaust(); };
void () dbj_run6 = [22, dbj_run7] {ai_get_angry(); ai_run(25); Exhaust(); };
void () dbj_run7 = [24, dbj_run8] {ai_get_angry(); ai_run(30);Exhaust(); };
void () dbj_run8 = [26, dbj_run9] {ai_get_angry(); ai_run(25); Exhaust(); };
void () dbj_run9 = [28, dbj_run1] {ai_get_angry(); ai_run(30);Exhaust(); };

void () dbj_attack1 = [12, dbj_attack2] {Exhaust(); ai_face(); if (random() < 0.6) DukeTaunt(self); };
void () dbj_attack2 = [14, dbj_attack3] {dukeboss_nuke(); Exhaust(); };
void () dbj_attack3 = [16, dbj_attack4] { ai_face(); Exhaust();};
void () dbj_attack4 = [20, dbj_attack5] {dukeboss_nuke(); Exhaust(); };
void () dbj_attack5 = [22, dbj_attack6] { ai_face(); Exhaust();};
void () dbj_attack6 = [24, dbj_run1] {dukeboss_nuke(); Exhaust(); };

void() monster_duke_boss_jetpack =
{

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

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

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

   setsize (self, '-32 -32 0', '32 32 112');
   self.health = self.max_health = M5HEALTH; 

   self.th_stand   = dbj_stand1;
   self.th_walk    = dbj_walk1;
   self.th_run     = dbj_run1;
   self.th_die     = db_die1;
   self.th_missile = dbj_attack1;
   self.th_melee = db_kick1;
   self.th_pain    = db_pain;
	self.bondoflag = B_BOSS;
	self.classname = "monster_dbj";
	self.netname = "Flying Duke Super Clone";   
   flymonster_start();
};

