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

OGRE

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

$cd UG/models/ogre_c
$origin 0 0 24
$base base		
$skin base

$frame ogrec

$frame ogred


//=============================================================================


void() OgreGrenadeExplode =
{
	T_RadiusDamage (self, self.owner, 40, world);
	sound (self, CHAN_VOICE, "weapons/r_exp3.wav", 1, ATTN_NORM);


	self.velocity = '0 0 0';
	self.touch = SUB_Null;

	self.solid = SOLID_NOT;
	s_explode1 ();
};

void() OgreGrenadeTouch =
{
	if (other == self.owner)
		return;		// don't explode on owner
	if (other.takedamage == DAMAGE_AIM)
	{
		OgreGrenadeExplode();
		return;
	}
	sound (self, CHAN_VOICE, "weapons/bounce.wav", 1, ATTN_NORM);	// bounce sound
	if (self.velocity == '0 0 0')
		self.avelocity = '0 0 0';
};

/*
================
OgreFireGrenade
================
*/
void() OgreFireGrenade =
{
	local	entity missile, mpuff;
	

	sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);

	missile = spawn ();
	missile.owner = self;
	missile.movetype = MOVETYPE_BOUNCE;
	missile.solid = SOLID_BBOX;
		
// set missile speed	

	makevectors (self.angles);

	missile.velocity = normalize(self.enemy.origin - self.origin);
	missile.velocity = missile.velocity * 600;
	missile.velocity_z = 200;

	missile.avelocity = '300 300 300';

	missile.angles = vectoangles(missile.velocity);
	
	missile.touch = OgreGrenadeTouch;
	
// set missile duration
	missile.nextthink = time + 2.5;
	missile.think = OgreGrenadeExplode;

//	setmodel (missile, "progs/grenade.mdl");
	setsize (missile, '0 0 0', '0 0 0');		
	setorigin (missile, self.origin);
};


//=============================================================================

/*
================
chainsaw

FIXME
================
*/
void(float side) chainsaw =
{
local vector	delta;
local float 	ldmg;

	if (!self.enemy)
		return;
	if (!CanDamage (self.enemy, self))
		return;

	ai_charge(10);

	delta = self.enemy.origin - self.origin;

	if (vlen(delta) > 100)
		return;
		
	ldmg = (random() + random() + random()) * 4;
	T_Damage (self.enemy, self, self, ldmg);
	
	if (side)
	{
		makevectors (self.angles);
		if (side == 1)
return;
//			SpawnMeatSpray (self.origin + v_forward*16, crandom() * 100 * v_right);
		else
return;
//			SpawnMeatSpray (self.origin + v_forward*16, side * v_right);
	}
};


void() ogre_stand1	=[	$ogrec,	ogre_stand2	] {ai_stand();};
void() ogre_stand2	=[	$ogrec,	ogre_stand3	] {ai_stand();};
void() ogre_stand3	=[	$ogrec,	ogre_stand4	] {ai_stand();};
void() ogre_stand4	=[	$ogrec,	ogre_stand5	] {ai_stand();};
void() ogre_stand5	=[	$ogrec,	ogre_stand6	] {
if (random() < 0.2)
	sound (self, CHAN_VOICE, "ogre/ogidle.wav", 1, ATTN_IDLE);
ai_stand();
};
void() ogre_stand6	=[	$ogrec,	ogre_stand7	] {ai_stand();};
void() ogre_stand7	=[	$ogrec,	ogre_stand8	] {ai_stand();};
void() ogre_stand8	=[	$ogrec,	ogre_stand9	] {ai_stand();};
void() ogre_stand9	=[	$ogrec,	ogre_stand1	] {ai_stand();};

void() ogre_walk1	=[	$ogrec,		ogre_walk2	] {ai_walk(3);};
void() ogre_walk2	=[	$ogrec,		ogre_walk3	] {ai_walk(2);};
void() ogre_walk3	=[	$ogrec,		ogre_walk4	] {
ai_walk(2);
if (random() < 0.2)
	sound (self, CHAN_VOICE, "ogre/ogidle.wav", 1, ATTN_IDLE);
};
void() ogre_walk4	=[	$ogrec,		ogre_walk5	] {ai_walk(2);};
void() ogre_walk5	=[	$ogrec,		ogre_walk6	] {ai_walk(2);};
void() ogre_walk6	=[	$ogrec,		ogre_walk7	] {
ai_walk(5);
if (random() < 0.1)
	sound (self, CHAN_VOICE, "ogre/ogdrag.wav", 1, ATTN_IDLE);
};
void() ogre_walk7	=[	$ogrec,		ogre_walk8	] {ai_walk(3);};
void() ogre_walk8	=[	$ogrec,		ogre_walk9	] {ai_walk(2);};
void() ogre_walk9	=[	$ogrec,		ogre_walk10	] {ai_walk(3);};
void() ogre_walk10	=[	$ogrec, 	ogre_walk11	] {ai_walk(1);};
void() ogre_walk11	=[	$ogrec, 	ogre_walk12	] {ai_walk(2);};
void() ogre_walk12	=[	$ogrec, 	ogre_walk13	] {ai_walk(3);};
void() ogre_walk13	=[	$ogrec,	    ogre_walk14	] {ai_walk(3);};
void() ogre_walk14	=[	$ogrec,  	ogre_walk15	] {ai_walk(3);};
void() ogre_walk15	=[	$ogrec,	    ogre_walk16	] {ai_walk(3);};
void() ogre_walk16	=[	$ogrec, 	ogre_walk1	] {ai_walk(4);};

void() ogre_run1	=[	$ogrec,		ogre_run2	] {ai_run(9);
if (random() < 0.2)
	sound (self, CHAN_VOICE, "ogre/ogidle2.wav", 1, ATTN_IDLE);
};
void() ogre_run2	=[	$ogrec,		ogre_run3	] {ai_run(12);};
void() ogre_run3	=[	$ogrec,		ogre_run4	] {ai_run(8);};
void() ogre_run4	=[	$ogrec,		ogre_run5	] {ai_run(22);};
void() ogre_run5	=[	$ogrec,		ogre_run6	] {ai_run(16);};
void() ogre_run6	=[	$ogrec,		ogre_run7	] {ai_run(4);};
void() ogre_run7	=[	$ogrec,		ogre_run8	] {ai_run(13);};
void() ogre_run8	=[	$ogrec,		ogre_run1	] {ai_run(24);};

void() ogre_swing1	=[	$ogrec,		ogre_swing2	] {ai_charge(11);
sound (self, CHAN_WEAPON, "ogre/ogsawatk.wav", 1, ATTN_NORM);
};
void() ogre_swing2	=[	$ogrec,		ogre_swing3	] {ai_charge(1);};
void() ogre_swing3	=[	$ogrec,		ogre_swing4	] {ai_charge(4);};
void() ogre_swing4	=[	$ogrec,		ogre_swing5	] {ai_charge(13);};
void() ogre_swing5	=[	$ogrec,		ogre_swing6	] {ai_charge(9); chainsaw(0);self.angles_y = self.angles_y + random()*25;};
void() ogre_swing6	=[	$ogrec,		ogre_swing7	] {chainsaw(200);self.angles_y = self.angles_y + random()* 25;};
void() ogre_swing7	=[	$ogrec,		ogre_swing8	] {chainsaw(0);self.angles_y = self.angles_y + random()* 25;};
void() ogre_swing8	=[	$ogrec,		ogre_swing9	] {chainsaw(0);self.angles_y = self.angles_y + random()* 25;};
void() ogre_swing9	=[	$ogrec,		ogre_swing10 ] {chainsaw(0);self.angles_y = self.angles_y + random()* 25;};
void() ogre_swing10	=[	$ogrec,		ogre_swing11 ] {chainsaw(-200);self.angles_y = self.angles_y + random()* 25;};
void() ogre_swing11	=[	$ogrec,		ogre_swing12 ] {chainsaw(0);self.angles_y = self.angles_y + random()* 25;};
void() ogre_swing12	=[	$ogrec,		ogre_swing13 ] {ai_charge(3);};
void() ogre_swing13	=[	$ogrec,		ogre_swing14 ] {ai_charge(8);};
void() ogre_swing14	=[	$ogrec,		ogre_run1	] {ai_charge(9);};

void() ogre_smash1	=[	$ogrec,		ogre_smash2	] {ai_charge(6);
sound (self, CHAN_WEAPON, "ogre/ogsawatk.wav", 1, ATTN_NORM);
};
void() ogre_smash2	=[	$ogrec,		ogre_smash3	] {ai_charge(0);};
void() ogre_smash3	=[	$ogrec,		ogre_smash4	] {ai_charge(0);};
void() ogre_smash4	=[	$ogrec,		ogre_smash5	] {ai_charge(1);};
void() ogre_smash5	=[	$ogrec,		ogre_smash6	] {ai_charge(4);};
void() ogre_smash6	=[	$ogrec,		ogre_smash7	] {ai_charge(4); chainsaw(0);};
void() ogre_smash7	=[	$ogrec,		ogre_smash8	] {ai_charge(4); chainsaw(0);};
void() ogre_smash8	=[	$ogrec,		ogre_smash9	] {ai_charge(10); chainsaw(0);};
void() ogre_smash9	=[	$ogrec,		ogre_smash10 ] {ai_charge(13); chainsaw(0);};
void() ogre_smash10	=[	$ogrec,		ogre_smash11 ] {chainsaw(1);};
void() ogre_smash11	=[	$ogrec,		ogre_smash12 ] {ai_charge(2); chainsaw(0);
self.nextthink = self.nextthink + random()*0.2;};	// slight variation
void() ogre_smash12	=[	$ogrec,		ogre_smash13 ] {ai_charge();};
void() ogre_smash13	=[	$ogrec,		ogre_smash14 ] {ai_charge(4);};
void() ogre_smash14	=[	$ogrec,		ogre_run1	] {ai_charge(12);};

void() ogre_nail1	=[	$ogrec,		ogre_nail2	] {ai_face();};
void() ogre_nail2	=[	$ogrec,		ogre_nail3	] {ai_face();};
void() ogre_nail3	=[	$ogrec,		ogre_nail4	] {ai_face();};
void() ogre_nail4	=[	$ogrec,		ogre_nail5	] {ai_face();OgreFireGrenade();};
void() ogre_nail5	=[	$ogrec,		ogre_nail6	] {ai_face();};
void() ogre_nail6	=[	$ogrec,		ogre_nail7	] {ai_face();};
void() ogre_nail7	=[	$ogrec,		ogre_run1	] {ai_face();};

void()	ogre_pain1	=[	$ogrec,		ogre_pain2	] {};
void()	ogre_pain2	=[	$ogrec,		ogre_pain3	] {};
void()	ogre_pain3	=[	$ogrec,		ogre_pain4	] {};
void()	ogre_pain4	=[	$ogrec,		ogre_pain5	] {};
void()	ogre_pain5	=[	$ogrec,		ogre_run1	] {};


void()	ogre_painb1	=[	$ogrec,	ogre_painb2	] {};
void()	ogre_painb2	=[	$ogrec,	ogre_painb3	] {};
void()	ogre_painb3	=[	$ogrec,	ogre_run1	] {};


void()	ogre_painc1	=[	$ogrec,	ogre_painc2	] {};
void()	ogre_painc2	=[	$ogrec,	ogre_painc3	] {};
void()	ogre_painc3	=[	$ogrec,	ogre_painc4	] {};
void()	ogre_painc4	=[	$ogrec,	ogre_painc5	] {};
void()	ogre_painc5	=[	$ogrec,	ogre_painc6	] {};
void()	ogre_painc6	=[	$ogrec,	ogre_run1	] {};


void()	ogre_paind1	=[	$ogrec,	ogre_paind2	] {};
void()	ogre_paind2	=[	$ogrec,	ogre_paind3	] {ai_pain(10);};
void()	ogre_paind3	=[	$ogrec,	ogre_paind4	] {ai_pain(9);};
void()	ogre_paind4	=[	$ogrec,	ogre_paind5	] {ai_pain(4);};
void()	ogre_paind5	=[	$ogrec,	ogre_paind6	] {};
void()	ogre_paind6	=[	$ogrec,	ogre_paind7	] {};
void()	ogre_paind7	=[	$ogrec,	ogre_paind8	] {};
void()	ogre_paind8	=[	$ogrec,	ogre_paind9	] {};
void()	ogre_paind9	=[	$ogrec,	ogre_paind10	] {};
void()	ogre_paind10=[	$ogrec,	ogre_paind11	] {};
void()	ogre_paind11=[	$ogrec,	ogre_paind12	] {};
void()	ogre_paind12=[	$ogrec,	ogre_paind13	] {};
void()	ogre_paind13=[	$ogrec,	ogre_paind14	] {};
void()	ogre_paind14=[	$ogrec,	ogre_paind15	] {};
void()	ogre_paind15=[	$ogrec,	ogre_paind16	] {};
void()	ogre_paind16=[	$ogrec,	ogre_run1	] {};

void()	ogre_paine1	=[	$ogrec,	ogre_paine2	] {};
void()	ogre_paine2	=[	$ogrec,	ogre_paine3	] {ai_pain(10);};
void()	ogre_paine3	=[	$ogrec,	ogre_paine4	] {ai_pain(9);};
void()	ogre_paine4	=[	$ogrec,	ogre_paine5	] {ai_pain(4);};
void()	ogre_paine5	=[	$ogrec,	ogre_paine6	] {};
void()	ogre_paine6	=[	$ogrec,	ogre_paine7	] {};
void()	ogre_paine7	=[	$ogrec,	ogre_paine8	] {};
void()	ogre_paine8	=[	$ogrec,	ogre_paine9	] {};
void()	ogre_paine9	=[	$ogrec,	ogre_paine10	] {};
void()	ogre_paine10=[	$ogrec,	ogre_paine11	] {};
void()	ogre_paine11=[	$ogrec,	ogre_paine12	] {};
void()	ogre_paine12=[	$ogrec,	ogre_paine13	] {};
void()	ogre_paine13=[	$ogrec,	ogre_paine14	] {};
void()	ogre_paine14=[	$ogrec,	ogre_paine15	] {};
void()	ogre_paine15=[	$ogrec,	ogre_run1	] {};


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

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

	sound (self, CHAN_VOICE, "ogre/ogpain1.wav", 1, ATTN_NORM);		

	r = random();
	
	if (r < 0.25)
	{
		ogre_pain1 ();
		self.pain_finished = time + 1;
	}
	else if (r < 0.5)
	{
		ogre_painb1 ();
		self.pain_finished = time + 1;
	}
	else if (r < 0.75)
	{
		ogre_painc1 ();
		self.pain_finished = time + 1;
	}
	else if (r < 0.88)
	{
		ogre_paind1 ();
		self.pain_finished = time + 2;
	}
	else
	{
		ogre_paine1 ();
		self.pain_finished = time + 2;
	}
};

void()	ogre_die1	=[	$ogred,	ogre_die2	] {};
void()	ogre_die2	=[	$ogred,	ogre_die3	] {};
void()	ogre_die3	=[	$ogred,	ogre_die4	]
{self.solid = SOLID_NOT;
self.ammo_rockets = 2;DropBackpack();};
void()	ogre_die4	=[	$ogred,	ogre_die5	] {};
void()	ogre_die5	=[	$ogred,	ogre_die6	] {};
void()	ogre_die6	=[	$ogred,	ogre_die7	] {};
void()	ogre_die7	=[	$ogred,	ogre_die8	] {};
void()	ogre_die8	=[	$ogred,	ogre_die9	] {};
void()	ogre_die9	=[	$ogred,	ogre_die10	] {};
void()	ogre_die10	=[	$ogred,	ogre_die11	] {};
void()	ogre_die11	=[	$ogred,	ogre_die12	] {};
void()	ogre_die12	=[	$ogred,	ogre_die13	] {};
void()	ogre_die13	=[	$ogred,	ogre_die14	] {};
void()	ogre_die14	=[	$ogred,	ogre_die14	] {};

void()	ogre_bdie1	=[	$ogred,	ogre_bdie2	] {};
void()	ogre_bdie2	=[	$ogred,	ogre_bdie3	] {ai_forward(5);};
void()	ogre_bdie3	=[	$ogred,	ogre_bdie4	]
{self.solid = SOLID_NOT;
self.ammo_rockets = 2;DropBackpack();};
void()	ogre_bdie4	=[	$ogred,	ogre_bdie5	] {ai_forward(1);};
void()	ogre_bdie5	=[	$ogred,	ogre_bdie6	] {ai_forward(3);};
void()	ogre_bdie6	=[	$ogred,	ogre_bdie7	] {ai_forward(7);};
void()	ogre_bdie7	=[	$ogred,	ogre_bdie8	] {ai_forward(25);};
void()	ogre_bdie8	=[	$ogred,	ogre_bdie9	] {};
void()	ogre_bdie9	=[	$ogred,	ogre_bdie10	] {};
void()	ogre_bdie10	=[	$ogred,	ogre_bdie10	] {};

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

	sound (self, CHAN_VOICE, "ogre/ogdth.wav", 1, ATTN_NORM);
	
	if (random() < 0.5)
		ogre_die1 ();
	else
		ogre_bdie1 ();
};

void() ogre_melee =
{
	if (random() > 0.5)
		ogre_smash1 ();
	else
		ogre_swing1 ();
};


/*UNTITLED-GAME/D monster_ogre (1 0 0) (-32 -32 -24) (32 32 64) Ambush

*/
void() monster_ogre =
{
	if (deathmatch)
	{
		remove(self);
		return;
	}
	precache_model ("progs/ogre.mdl");
	precache_model ("progs/h_ogre.mdl");
	precache_model ("progs/grenade.mdl");

	precache_sound ("ogre/ogdrag.wav");
	precache_sound ("ogre/ogdth.wav");
	precache_sound ("ogre/ogidle.wav");
	precache_sound ("ogre/ogidle2.wav");
	precache_sound ("ogre/ogpain1.wav");
	precache_sound ("ogre/ogsawatk.wav");
	precache_sound ("ogre/ogwake.wav");

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

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

	setsize (self, VEC_HULL2_MIN, VEC_HULL2_MAX);
	self.health = 200;

	self.th_stand = ogre_stand1;
	self.th_walk = ogre_walk1;
	self.th_run = ogre_run1;
	self.th_die = ogre_die;
	self.th_melee = ogre_melee;
	self.th_missile = ogre_nail1;
	self.th_pain = ogre_pain;
	
	walkmonster_start();
};

void() monster_ogre_marksman =
{
	monster_ogre ();
};