void (vector org, vector vec) LaunchRocket1;
void (vector here) BoomIt;
void () ManExplode;
void () MNExplosion;
void () enforcer_rocket;
//void () bigrobot_rocket;

void () robot_stand1 = [ 20.000, robot_stand2 ] {  ai_stand ();};
void () robot_stand2 = [ 20.000, robot_stand1 ] {   ai_stand ();};

void () robot_walk1 = [ 1.000, robot_walk2 ] {   ai_walk (8);};
void () robot_walk2 = [ 2.000, robot_walk3 ] {   ai_walk (9);};
void () robot_walk3 = [ 3.000, robot_walk4 ] {

   ai_walk (8);

};

void () robot_walk4 = [ 4.000, robot_walk5 ] {

   ai_walk (10);

};

void () robot_walk5 = [ 5.000, robot_walk6 ] {

   ai_walk (8);

};

void () robot_walk6 = [ 6.000, robot_walk7 ] {

   ai_walk (8);

};

void () robot_walk7 = [ 7.000, robot_walk8 ] {

   ai_walk (8);

};

void () robot_walk8 = [ 8.000, robot_walk9 ] {

   ai_walk (9);

};

void () robot_walk9 = [ 9.000, robot_walk10 ] {

   ai_walk (10);

};

void () robot_walk10 = [ 10.000, robot_walk11 ] {

   ai_walk (8);

};

void () robot_walk11 = [ 11.000, robot_walk12 ] {

   ai_walk (8);

};

void () robot_walk12 = [ 12.000, robot_walk13 ] {

   ai_walk (8);

};

void () robot_walk13 = [ 13.000, robot_walk14 ] {

   ai_walk (MOVETYPE_FLYMISSILE);

};

void () robot_walk14 = [ 14.000, robot_walk15 ] {

   ai_walk (10);

};

void () robot_walk15 = [ 15.000, robot_walk16 ] {

   ai_walk (10);

};

void () robot_walk16 = [ 16.000, robot_walk17 ] {

   ai_walk (12.000);

};

void () robot_walk17 = [ 17.000, robot_walk18 ] {

   ai_walk (9);

};

void () robot_walk18 = [ 18.000, robot_walk19 ] {

   ai_walk (10);

};

void () robot_walk19 = [ 19.000, robot_walk20 ] {

   ai_walk (13.000);

};

void () robot_walk20 = [ 20.000, robot_walk1 ] {

   ai_walk (10);

};


void () robot_run1 = [ 1.000, robot_run2 ] {

	local float n
	n = random();
	if (random() < 0.3)
	{
		if (n < 0.5)
			sound (self,CHAN_WEAPON,"robot/ed20secs.wav",TRUE,ATTN_NORM);
		else
			sound (self,CHAN_WEAPON,"robot/edputdwn.wav",TRUE,ATTN_NORM);
		
	}
	
	if (self.owner.health <= 0 && self.owner.classname == "player") 
	{
		self.owner.numpets = self.owner.numpets - 1; 
		spawn_tfog();
		SUB_Remove();
	}

   ai_run (MOVETYPE_BOUNCE);

};

void () robot_run2 = [ 2.000, robot_run3 ] {

   ai_run (MOVETYPE_FLYMISSILE);

};

void () robot_run3 = [ 3.000, robot_run4 ] {

   ai_run (MOVETYPE_FLYMISSILE);

};

void () robot_run4 = [ 4.000, robot_run5 ] {

   ai_run (MOVETYPE_FLY);

};

void () robot_run5 = [ 5.000, robot_run6 ] {

   ai_run (MOVETYPE_TOSS);

};

void () robot_run6 = [ 6.000, robot_run7 ] {

   ai_run (12.000);

};

void () robot_run7 = [ 7.000, robot_run8 ] {

   ai_run (FL_CLIENT);

};

void () robot_run8 = [ 8.000, robot_run9 ] {

   ai_run (MOVETYPE_WALK);

};

void () robot_run9 = [ 9.000, robot_run10 ] {

   ai_run (13.000);

};

void () robot_run10 = [ 10.000, robot_run11 ] {

   ai_run (MOVETYPE_FLYMISSILE);

};

void () robot_run11 = [ 11.000, robot_run12 ] {

   ai_run (8);

};

void () robot_run12 = [ 12.000, robot_run13 ] {

   ai_run (MOVETYPE_PUSH);

};

void () robot_run13 = [ 13.000, robot_run14 ] {

   ai_run (MOVETYPE_FLYMISSILE);

};

void () robot_run14 = [ 14.000, robot_run15 ] {

   ai_run (MOVETYPE_FLY);

};

void () robot_run15 = [ 15.000, robot_run16 ] {

   ai_run (MOVETYPE_TOSS);

};

void () robot_run16 = [ 16.000, robot_run17 ] {

   ai_run (12.000);

};

void () robot_run17 = [ 17.000, robot_run18 ] {

   ai_run (FL_CLIENT);

};

void () robot_run18 = [ 18.000, robot_run19 ] {

   ai_run (MOVETYPE_WALK);

};

void () robot_run19 = [ 19.000, robot_run20 ] {

   ai_run (13.000);

};

void () robot_run20 = [ 20.000, robot_run1 ] {

   ai_run (MOVETYPE_FLYMISSILE);

};


void () muzzle_think1 = [ 0.000, muzzle_think2 ] {

   self.nextthink = (time + 0.050);
   self.effects = (self.effects | EF_MUZZLEFLASH);
   self.angles = self.owner.angles;

};

void () muzzle_think2 = [ 1.000, muzzle_think3 ] {

   self.nextthink = (time + 0.050);
   self.effects = 0.000;
   self.angles = self.owner.angles;

};

void () muzzle_think3 = [ 2.000, SUB_Remove ] {

   self.nextthink = (time + 0.050);
   self.angles = self.owner.angles;

};

void () robot_rocket = {

   local vector org;

   self.effects = (self.effects | EF_MUZZLEFLASH);
   sound (self,CHAN_WEAPON,"weapons/sgun1.wav",TRUE,ATTN_NORM);
   makevectors (self.angles);
   org = (((self.origin + (v_forward * 12)) + (v_right * -24.00)) + '0.000 0.000 40.000');
   LaunchRocket1 (org,(self.enemy.origin - org));

};
/*

void() robot_fire2 = {

         local vector   dir;
         local entity   en;

         ai_face ();

         en = self.enemy;

         dir = en.origin - self.origin;
         dir = normalize (dir);

         self.v_angle = vectoangles (dir);

         if (self.v_angle_x > 180)
            self.v_angle_x = self.v_angle_x - 360; // corrects an ID mistake

         self.v_angle_x = self.v_angle_x * -1;     // corrects an ID mistake

         if (self.v_angle_x > 80)
            self.v_angle_x = 80;

         if (self.v_angle_x < -80)
            self.v_angle_x = -80;


         if (vlen (self.enemy.origin - self.origin) > 256 && self.enemy.health > 0)
         {
            makevectors (self.v_angle);
            robot_rocket();
         }

      };

void () Muzzle = {

   local entity muzzle;

   muzzle = spawn ();
   muzzle.owner = self;
   muzzle.movetype = MOVETYPE_FLYMISSILE;
   muzzle.velocity = self.velocity;
   muzzle.angles = self.angles;
   muzzle.solid = SOLID_NOT;
   muzzle.nextthink = (time + 0.000);
   muzzle.think = muzzle_think1;
   setmodel (muzzle,"progs/muzzle.mdl");
   setsize (muzzle,'0.000 0.000 0.000','0.000 0.000 0.000');
	makevectors (self.v_angle);
	//muzzle.origin = (((self.origin + (v_forward * 30.000)) + (v_right * 32.000)) + '0.000 0.000 22.000');
	setorigin(muzzle,(self.origin + v_forward * 16 + v_right * 16.000 + '0.000 0.000 16.000'));

};
*/

void () robot_fire = {

   local vector dir;
   local entity en;

	ai_face ();
	sound (self,CHAN_WEAPON,"weapons/armor/gun.wav",(0.800 + (random () * 0.200)),ATTN_NORM);
	en = self.enemy;
	dir = (en.origin - (en.velocity * 0.200));
	dir = normalize ((dir - self.origin));
	if (self.classname == "pet_mini_robot")
		FireBullets (5,dir,'0.01 0.01 0.000');
	else
		FireBullets (1,dir,'0.100 0.100 0.000');
   
   //if (self.classname == "pet_mini_robot") Muzzle ();

};

void () robot_rocket1 = [24, robot_rocket2] {ai_face(); robot_rocket();};
void () robot_rocket2 = [25, robot_rocket3] {};
void () robot_rocket3 = [26, robot_rocket4] {ai_face(); };
void () robot_rocket4 = [27, robot_run1] {};

void () robot_atk1 = [21, robot_atk2] {ai_face(); robot_fire();self.nextthink = time + 0.05; };
void () robot_atk2 = [22, robot_atk3] {ai_face(); robot_fire();self.nextthink = time + 0.05; };
void () robot_atk3 = [23, robot_atk4] {ai_face(); robot_fire();self.nextthink = time + 0.05; };
void () robot_atk4 = [20, robot_run1] {
	
	self.nextthink = time + 0.05;
	if((visible(self.enemy)) && (self.enemy.health > 0) && (random() < 0.7))
	{
		self.think = robot_atk1;
	}
	else
	{
		self.think = robot_run1;
	}
};

void () robot_pain = {

   if ( (random () > 0.500) ) {

      sound (self,CHAN_VOICE,"weapons/armor/pain1.wav",1.000,ATTN_NORM);

   } else {

      if ( (random () > 0.500) ) {

         sound (self,CHAN_VOICE,"weapons/armor/pain2.wav",1.000,ATTN_NORM);

      } else {

         sound (self,CHAN_VOICE,"weapons/armor/pain3.wav",1.000,ATTN_NORM);

      }

   }

   if (self.classname == "monster_test_hunter") self.health = M5HEALTH;
};


void () robot_pain1 = [ 6.000, robot_pain2 ] {

	robot_pain();

};

void () robot_pain2 = [ 12.000, robot_pain3 ] {


};

void () robot_pain3 = [ 20.000, robot_pain4 ] {

	robot_pain();

};

void () robot_pain4 = [ 6.000, robot_pain5 ] {


};

void () robot_pain5 = [ 12.000, robot_run1 ] {


};


//experimental robot death throe
void () robot_die1 = [ 20.000, robot_die2 ] {

	self.nextthink = time + 0.5;

};

void () robot_die2 = [ 20.000, robot_die3 ] {

	BoomIt(self.origin);
	self.flags = self.flags - FL_ONGROUND;
	self.velocity = self.velocity + v_up*200 + v_right*crandom()*100 + v_forward*crandom()*100;
	self.nextthink = time + 1 + random()*2;
};

void () robot_die3 = [ 20.000, robot_die4 ] {
	self.nextthink = time + 0.1;


};

void () robot_die4 = [ 20.000, robot_die5 ] {
	self.nextthink = time + 1 + random()*2;
	BoomIt(self.origin);
	self.velocity = self.velocity + v_up*200 + v_right*crandom()*100 + v_forward*crandom()*100;


};

void () robot_die5 = [ 20.000, robot_die5 ] {

	BoomIt(self.origin);
   ThrowGib("progs/rgib3.mdl",random() * -100, self);
   ThrowGib("progs/rgib2.mdl",random() * -100, self);
   ThrowGib("progs/rgib2.mdl",random() * -100, self);
   monster_gib("progs/rgib4.mdl");

};

void () robot_attack =
{
	local float n
	n = random();
	if (random() < 0.2)
	{
		if (n < 0.5)
			sound (self,CHAN_WEAPON,"robot/ed20secs.wav",TRUE,ATTN_NORM);
		else
			sound (self,CHAN_WEAPON,"robot/edputdwn.wav",TRUE,ATTN_NORM);
	}

   if (vlen(self.enemy.origin - self.origin) > 512) 
      robot_rocket1();
   else
      robot_atk1();

};

void () robot_die = {

	if (self.classname == "pet_mini_robot")
		self.owner.numpets = self.owner.numpets - 1;
		
	DropBackpack();

   if (self.health < -50.000) {

      //sound (self,CHAN_VOICE,"player/udeath.wav",TRUE,ATTN_NORM);
      monster_gib("progs/rgib4.mdl");
      ThrowGib("progs/rgib3.mdl",self.health, self);
      ThrowGib("progs/rgib2.mdl",self.health, self);
      ThrowGib("progs/rgib2.mdl",self.health, self);
      return ;

   }
	else robot_die1();

   sound (self,CHAN_VOICE,"weapons/armor/death.wav",TRUE,ATTN_NORM);


};



void () monster_robot = {

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

   self.solid = SOLID_SLIDEBOX;
   self.movetype = MOVETYPE_STEP;
   //setmodel (self,"progs/plrobot.mdl");
   setmodel (self,"progs/robotbig.mdl");
   setsize (self,VEC_HULL2_MIN,VEC_HULL2_MAX);
   self.health = self.max_health = M4HEALTH;	//was 600
   if (self.owner) 
   {
   	self.health = self.health * 20;
   }
   self.armortype = 0.75;
   self.armorvalue = 1000;
   self.th_stand = robot_stand1;
   self.th_walk = robot_walk1;
   self.th_run = robot_run1;
   self.th_die = robot_die;
   self.th_missile = robot_attack;
   self.th_pain = robot_pain;
   self.classname = "monster_robot";
	self.netname = "Enforcer Droid";
	self.bondoflag = TECH;

   walkmonster_start ();

};

void () pet_mini_robot = {

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

	self.solid = SOLID_SLIDEBOX;
	self.movetype = MOVETYPE_STEP;
	setmodel (self,"progs/robotsm.mdl");
	setsize (self,VEC_HULL_MIN,'16 16 24');
	self.health = self.max_health = M4HEALTH;	//was 600
	self.th_stand = robot_stand1;
	self.th_walk = robot_walk1;
	self.th_run = robot_run1;
	self.th_die = robot_die;
	self.th_missile = robot_attack;
	self.th_pain = robot_pain;
	self.classname = "pet_mini_robot";
	self.bondoflag = TECH;

   walkpet_start ();

};

/*
void () robotgun_atk1 = [21, robotgun_atk2] {ai_face(); robot_fire(); self.nextthink = time + 0.05;};
void () robotgun_atk2 = [21, robotgun_atk3] {robot_fire(); self.nextthink = time + 0.05;};
void () robotgun_atk3 = [22, robotgun_atk4] {ai_face(); robot_fire(); self.nextthink = time + 0.05;};
void () robotgun_atk4 = [23, robotgun_atk5] {self.nextthink = time + 0.05;};
void () robotgun_atk5 = [25, robotgun_atk6] {ai_face(); robot_fire(); self.nextthink = time + 0.05;};
void () robotgun_atk6 = [25, robotgun_atk7] {robot_fire(); self.nextthink = time + 0.05;};
void () robotgun_atk7 = [26, robotgun_atk8] {ai_face(); robot_fire(); self.nextthink = time + 0.05;};
void () robotgun_atk8 = [27, robot_run1] {self.nextthink = time + 0.05; SUB_CheckRefire(robotgun_atk1);};

void () monster_robot_gun = {

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

   self.solid = SOLID_SLIDEBOX;
   self.movetype = MOVETYPE_STEP;
   setmodel (self,"progs/robotgun.mdl");
   setsize (self,VEC_HULL2_MIN,VEC_HULL2_MAX);
   self.health = self.max_health = M4HEALTH;	//was 600
   self.skin = 2;
   self.th_stand = robot_stand1;
   self.th_walk = robot_walk1;
   self.th_run = robot_run1;
   self.th_die = robot_die;
   self.th_missile = robotgun_atk1;
   self.th_pain = robot_pain;
   self.classname = "monster_robot";
   self.netname = "Enforcer Droid";
	self.bondoflag = TECH;

   walkmonster_start ();

};
*/
