/*
==============================================================================

OLD OGRE

==============================================================================
*/

// by Madfox
//
// gb, preliminary RMQ version 05/10
//
// needs to be assimilated, tweaked to RMQ needs and the shield reflect projectiles thing added

$cd /raid/quake/id1/models/xogre
$origin 0 0 24
$base base
$skin badass3

$frame stand1 stand2 stand3 stand4 stand5 stand6 stand7 stand8 stand9

$frame walk1 walk2 walk3 walk4 walk5 walk6 walk7 walk8 walk9 walk10
$frame walk11 walk12 walk13 walk14 walk15 walk16 

$frame run1 run2 run3 run4 run5 run6 run7 run8

$frame lash1 lash2 lash3 lash4 lash5 lash6 lash7 lash8 lash9 lash10 lash11 

$frame throw1 throw2 throw3 throw4 throw5 throw6 throw7 throw8 throw9
$frame throw10 throw11 throw12 

$frame shield1 shield2 shield3 shield4 shield5 shield6 shield7 shield8

$frame pain1 pain2 pain3 pain4 pain5 pain6 pain7 pain8 
 
$frame paina1 paina2 paina3 paina4 

$frame die1 die2 die3 die4 die5 die6 die7 die8 die9 die10
$frame die11 die12 die13 die14 die15 die16 die17 die18

$frame dieb1 dieb2 dieb3 dieb4 dieb5 dieb6 dieb7 dieb8 dieb9 dieb10
$frame dieb11 dieb12 dieb13 dieb14 dieb15 dieb16 dieb17 dieb18 dieb19

void() xogre_face =
{
// go for another player if multi player
	if (self.enemy.health <= 0 || random() < 0.02)
	{
		self.enemy = find(self.enemy, classname, "player");
		if (!self.enemy)
			self.enemy = find(self.enemy, classname, "player");
	}
	ai_face();
};

void() Taxe_Touch =
{
	local vector org;
	
	if (other == self.owner)
		return;		// don't explode on owner

	if (pointcontents(self.origin) == CONTENT_SKY)
	{
		remove(self);
		return;
	}
	
	sound (self, CHAN_WEAPON, "enforcer/enfstop.wav", 1, ATTN_STATIC);
	org = self.origin - 8*normalize(self.velocity);

	if (other.health)
	{
		SpawnBlood (org, self.velocity*0.2, 15, other.nobleed, FALSE);		// gb, this is different in rmq
		T_Damage (other, self, self.owner, 15, DTH_OLDOGRE_THROWAXE, FALSE, 1);	// gb, same
	}
	else
	{
		WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
		WriteByte (MSG_BROADCAST, TE_GUNSHOT);
		WriteCoord (MSG_BROADCAST, org_x);
		WriteCoord (MSG_BROADCAST, org_y);
		WriteCoord (MSG_BROADCAST, org_z);
	}
	
	remove(self);	
};
void(vector org, vector vec) LaunchTaxe =
{
//	local	vector	vec;
		
	if (self.classname == "monster_enforcer")
		sound (self, CHAN_WEAPON, "enforcer/enfire.wav", 1, ATTN_NORM);

	vec = normalize(vec);
	
	newmis = spawn();
	newmis.owner = self;
	newmis.movetype = MOVETYPE_FLY;
	newmis.solid = SOLID_BBOX;
  
	setmodel (newmis, "progs/taxe.mdl");
	setsize (newmis, '0 0 0', '0 0 0');		

 	setorigin (newmis, org);
        newmis.velocity = vec * 400;
	newmis.angles = vectoangles(newmis.velocity);
	newmis.nextthink = time + 5;
	newmis.think = SUB_Remove;
	newmis.touch = Taxe_Touch;

};

// throw axe attack
void() xogre_fire =
{
	local vector org;

	self.effects = self.effects | EF_MUZZLEFLASH;
	makevectors (self.angles);
	
	org = self.origin + v_forward * 30 + v_right * 8.5 + '0 0 16';

	LaunchTaxe(org, self.enemy.origin - self.origin);
};


void()	xogre_stand1	=[	$stand1,	xogre_stand2	] {ai_stand();};
void()	xogre_stand2	=[	$stand2,	xogre_stand3	] {ai_stand();};
void()	xogre_stand3	=[	$stand3,	xogre_stand4	] {ai_stand();};
void()	xogre_stand4	=[	$stand4,	xogre_stand5	] {ai_stand();};
void()	xogre_stand5	=[	$stand5,	xogre_stand6	] {ai_stand();};
void()	xogre_stand6	=[	$stand6,	xogre_stand7	] {ai_stand();};
void()	xogre_stand7	=[	$stand7,	xogre_stand8	] {ai_stand();};
void()	xogre_stand8	=[	$stand8,	xogre_stand9	] {ai_stand();};
void()	xogre_stand9	=[	$stand9,	xogre_stand1	] {ai_stand();};

void()	xogre_walk1	=[	$walk1,		xogre_walk2	] {
if (random() < 0.2)
	sound (self, CHAN_VOICE, "knight/idle.wav", 1,  ATTN_IDLE);
ai_walk(3);};
void()	xogre_walk2	=[	$walk2,		xogre_walk3	] {ai_walk(2);};
void()	xogre_walk3	=[	$walk3,		xogre_walk4	] {ai_walk(3);};
void()	xogre_walk4	=[	$walk4,		xogre_walk5	] {ai_walk(4);};
void()	xogre_walk5	=[	$walk5,		xogre_walk6	] {ai_walk(3);};
void()	xogre_walk6	=[	$walk6,		xogre_walk7	] {ai_walk(3);};
void()	xogre_walk7	=[	$walk7,		xogre_walk8	] {ai_walk(3);};
void()	xogre_walk8	=[	$walk8,		xogre_walk9	] {ai_walk(4);};
void()	xogre_walk9	=[	$walk9,		xogre_walk10	] {ai_walk(3);};
void()	xogre_walk10	=[	$walk10,	xogre_walk11	] {ai_walk(3);};
void()	xogre_walk11	=[	$walk11,	xogre_walk12	] {ai_walk(3);};
void()	xogre_walk12	=[	$walk12,	xogre_walk13	] {ai_walk(3);};
void()	xogre_walk13	=[	$walk13,	xogre_walk14	] {ai_walk(3);};
void()	xogre_walk14	=[	$walk14,	xogre_walk15	] {ai_walk(4);};
void()	xogre_walk15	=[	$walk15,	xogre_walk16	] {ai_walk(3);};
void()	xogre_walk16	=[	$walk16,	xogre_walk1	] {ai_walk(3);};

void()	xogre_run1	=[	$run1,		xogre_run2	] {
if (random() < 0.2)
	sound (self, CHAN_VOICE, "knight/idle.wav", 1,  ATTN_IDLE);
ai_run(16);};
void()	xogre_run2	=[	$run2,		xogre_run3	] {ai_run(20);};
void()	xogre_run3	=[	$run3,		xogre_run4	] {ai_run(13);};
void()	xogre_run4	=[	$run4,		xogre_run5	] {ai_run(7);};
void()	xogre_run5	=[	$run5,		xogre_run6	] {ai_run(16);};
void()	xogre_run6	=[	$run6,		xogre_run7	] {ai_run(20);};
void()	xogre_run7	=[	$run7,		xogre_run8	] {ai_run(14);};
void()	xogre_run8	=[	$run8,		xogre_run1	] {ai_run(6);};

void()	xogre_atk1	=[	$lash1,		xogre_atk2	]
{sound (self, CHAN_WEAPON, "knight/sword1.wav", 1, ATTN_NORM);
ai_charge(0);};
void()	xogre_atk2	=[	$lash2,		xogre_atk3	] {ai_charge(7);};
void()	xogre_atk3	=[	$lash3,		xogre_atk4	] {ai_charge(4);};
void()	xogre_atk4	=[	$lash4,		xogre_atk5	] {ai_charge(0);};
void()	xogre_atk5	=[	$lash5,		xogre_atk6	] {ai_charge(3);};
void()	xogre_atk6	=[	$lash6,		xogre_atk7	] {ai_charge(4); ai_melee(DTH_OLDOGRE_AXE, FALSE, 1.5);};
void()	xogre_atk7	=[	$lash7,		xogre_atk8	] {ai_charge(1); ai_melee(DTH_OLDOGRE_AXE, FALSE, 1.5);};
void()	xogre_atk8	=[	$lash8,		xogre_atk9	] {ai_charge(3); ai_melee(DTH_OLDOGRE_AXE, FALSE, 1.5);};
void()	xogre_atk9	=[	$lash9,		xogre_atk10     ] {ai_charge(1);};
void()	xogre_atk10    =[	$lash10,	xogre_atk11	] {ai_charge(5);};
void()	xogre_atk11	=[	$lash11,	xogre_run1	] {};

void()  xogre_throw1    =[      $throw1,        xogre_throw2    ] {ai_face();}; 
void()  xogre_throw2    =[      $throw2,        xogre_throw3    ] {};
void()  xogre_throw3    =[      $throw3,        xogre_throw4    ] {ai_face();};
void()  xogre_throw4    =[      $throw4,        xogre_throw5    ] {};
void()  xogre_throw5    =[      $throw5,        xogre_throw6    ] {};
void()  xogre_throw6    =[      $throw6,        xogre_throw7    ] {ai_face();}; 
void()  xogre_throw7    =[      $throw7,        xogre_throw8    ] {xogre_fire();};
void()  xogre_throw8    =[      $throw8,        xogre_throw9    ] {};
void()  xogre_throw9    =[      $throw9,        xogre_throw10   ] {};
void()  xogre_throw10   =[      $throw10,       xogre_throw11   ] {ai_face();};
void()  xogre_throw11   =[      $throw11,       xogre_throw12   ] {};
void()  xogre_throw12   =[      $throw12,       xogre_run1      ] {};

void()	xogre_shield1	=[	$shield1,		xogre_shield2	] {
if (random() < 0.2)
	sound (self, CHAN_VOICE, "knight/idle.wav", 1,  ATTN_IDLE);
ai_run(16);};
void()	xogre_shield2	=[	$shield2,		xogre_shield3	] {};
void()	xogre_shield3	=[	$shield3,		xogre_shield4	] {};
void()	xogre_shield4	=[	$shield4,		xogre_shield5	] {};
void()	xogre_shield5	=[	$shield5,		xogre_shield6	] {};
void()	xogre_shield6	=[	$shield6,		xogre_shield7	] {};
void()	xogre_shield7	=[	$shield7,		xogre_shield8	] {};
void()	xogre_shield8	=[	$shield8,		xogre_run1	] {};


void()	xogre_pain1	=[	$pain1, 	xogre_pain2	] {ai_painforward(0);};
void()	xogre_pain2	=[	$pain2, 	xogre_pain3	] {ai_painforward(3);};
void()	xogre_pain3	=[	$pain3, 	xogre_pain4	] {};
void()	xogre_pain4	=[	$pain4, 	xogre_pain5	] {};
void()	xogre_pain5	=[	$pain5, 	xogre_pain6	] {ai_painforward(2);};
void()	xogre_pain6	=[	$pain6, 	xogre_pain7	] {ai_painforward(4);};
void()	xogre_pain7	=[	$pain7, 	xogre_pain8	] {ai_painforward(2);};
void()	xogre_pain8	=[	$pain8, 	xogre_run1	] {ai_painforward(5);};

void()	xogre_paina1	=[	$paina1, 	xogre_paina2	] {ai_painforward(0);};
void()	xogre_paina2	=[	$paina2, 	xogre_paina3	] {ai_painforward(3);};
void()	xogre_paina3	=[	$paina3, 	xogre_paina4	] {};
void()	xogre_paina4	=[	$paina4, 	xogre_run1	] {};

void(entity attacker, float damage)	xogre_pain =
{
	local float r;

	if (self.pain_finished > time)
		return;

	r = random();
	
	sound (self, CHAN_VOICE, "knight/khurt.wav", 1, ATTN_NORM);
	if (r < 0.85)
	{
		xogre_pain1 ();
		self.pain_finished = time + 1;
	}
	else
	{
		xogre_paina1 ();
		self.pain_finished = time + 1;
	}
	
};

void()	xogre_die1	=[	$die1,  	xogre_die2	] {};
void()	xogre_die2	=[	$die2,  	xogre_die3	] {};
void()	xogre_die3	=[	$die3,  	xogre_die4	] {self.solid = SOLID_NOT;};
void()	xogre_die4	=[	$die4,  	xogre_die5	] {};
void()	xogre_die5	=[	$die5,  	xogre_die6	] {};
void()	xogre_die6	=[	$die6,  	xogre_die7	] {};
void()	xogre_die7	=[	$die7,  	xogre_die8	] {};
void()	xogre_die8	=[	$die8,  	xogre_die9	] {};
void()	xogre_die9	=[	$die9,  	xogre_die10      ] {};
void()	xogre_die10      =[	$die10, 	xogre_die11      ] {};
void()	xogre_die11	=[	$die11,  	xogre_die12	] {};
void()	xogre_die12	=[	$die12,  	xogre_die13	] {};
void()	xogre_die13	=[	$die13,  	xogre_die14	] {};
void()	xogre_die14	=[	$die14,  	xogre_die15	] {};
void()	xogre_die15	=[	$die15,  	xogre_die16	] {};
void()	xogre_die16	=[	$die16,  	xogre_die17	] {};
void()	xogre_die17	=[	$die17,  	xogre_die18	] {};
void()	xogre_die18	=[	$die18,  	xogre_die18	] {};

void()	xogre_dieb1	=[	$dieb1,  	xogre_dieb2	] {};
void()	xogre_dieb2	=[	$dieb2,  	xogre_dieb3	] {};
void()	xogre_dieb3	=[	$dieb3,  	xogre_dieb4	] {self.solid = SOLID_NOT;};
void()	xogre_dieb4	=[	$dieb4,  	xogre_dieb5	] {};
void()	xogre_dieb5	=[	$dieb5,  	xogre_dieb6	] {};
void()	xogre_dieb6	=[	$dieb6,  	xogre_dieb7	] {};
void()	xogre_dieb7	=[	$dieb7,  	xogre_dieb8	] {};
void()	xogre_dieb8	=[	$dieb8,  	xogre_dieb9	] {};
void()	xogre_dieb9	=[	$dieb9,  	xogre_dieb10     ] {};
void()	xogre_dieb10     =[	$dieb10, 	xogre_dieb11     ] {};
void()	xogre_dieb11	=[	$dieb11,  	xogre_dieb12	] {};
void()	xogre_dieb12	=[	$dieb12,  	xogre_dieb13	] {};
void()	xogre_dieb13	=[	$dieb13,  	xogre_dieb14	] {};
void()	xogre_dieb14	=[	$dieb14,  	xogre_dieb15	] {};
void()	xogre_dieb15	=[	$dieb15,  	xogre_dieb16	] {};
void()	xogre_dieb16	=[	$dieb16,  	xogre_dieb17	] {};
void()	xogre_dieb17	=[	$dieb17,  	xogre_dieb18	] {};
void()	xogre_dieb18	=[	$dieb18,  	xogre_dieb19	] {};
void()	xogre_dieb19	=[	$dieb19,  	xogre_dieb19	] {};

void() xogre_die =
{
// check for gib
	if (self.health < -40)
	{
		sound (self, CHAN_VOICE, "player/udeath.wav", 1, ATTN_NORM);
		ThrowHead ("progs/h_xogre.mdl", self.health);
		ThrowGib ("progs/gib1.mdl", self.health);
		ThrowGib ("progs/gib2.mdl", self.health);
		ThrowGib ("progs/gib3.mdl", self.health);
		return;
	}

// regular death
	sound (self, CHAN_VOICE, "knight/kdeath.wav", 1, ATTN_NORM);
	if (random() < 0.5)
		xogre_die1 ();
	else
		xogre_dieb1 ();
};

void() xogre_melee =
{
	if (random() > 0.5)
		xogre_atk1 ();
	else
		xogre_shield1 ();
};


/*QUAKED monster_xogre (1 0 0) (-16 -16 -24) (16 16 40) Ambush
*/
void() monster_xogre =
{
	if (deathmatch)
	{
		remove(self);
		return;
	}
	precache_model ("progs/xogre.mdl");
	precache_model ("progs/h_xogre.mdl");
	precache_model ("progs/taxe.mdl");

	precache_sound ("knight/kdeath.wav");
	precache_sound ("knight/khurt.wav");
	precache_sound ("knight/ksight.wav");
	precache_sound ("knight/sword1.wav");
	precache_sound ("knight/sword2.wav");
	precache_sound ("knight/idle.wav");
	precache_sound ("enforcer/enfire.wav");
	precache_sound ("enforcer/enfstop.wav");

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

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

	setsize (self, '-16 -16 -24', '16 16 40');
	self.health = 180;

	self.th_stand = xogre_stand1;
	self.th_walk = xogre_walk1;
	self.th_run = xogre_run1;
	self.th_melee = xogre_melee;
	self.th_missile = xogre_throw1;
	self.th_pain = xogre_pain;
	self.th_die = xogre_die;
	
	walkmonster_start ();
};

