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

KNIGHT

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


$cd /raid/UNTITLED-GAME//id1/models/knight
$origin 0 0 24
$base base
$skin badass3

$frame knightc
$frame knightd

void() knight_stand1=[  $knightc,        knight_stand2   ] {ai_stand();};
void() knight_stand2=[  $knightc,        knight_stand3   ] {ai_stand();};
void() knight_stand3=[  $knightc,        knight_stand4   ] {ai_stand();};
void() knight_stand4=[  $knightc,        knight_stand5   ] {ai_stand();};
void() knight_stand5=[  $knightc,        knight_stand6   ] {ai_stand();};
void() knight_stand6=[  $knightc,        knight_stand7   ] {ai_stand();};
void() knight_stand7=[  $knightc,        knight_stand8   ] {ai_stand();};
void() knight_stand8=[  $knightc,        knight_stand9   ] {ai_stand();};
void() knight_stand9=[  $knightc,        knight_stand1   ] {ai_stand();};

void() knight_walk1=[   $knightc,         knight_walk2    ] {
if (random() < 0.2)
        sound (self, CHAN_VOICE, "knight/idle.wav", 1,  ATTN_IDLE);
ai_walk(3);};
void() knight_walk2=[   $knightc,         knight_walk3    ] {ai_walk(2);};
void() knight_walk3=[   $knightc,         knight_walk4    ] {ai_walk(3);};
void() knight_walk4=[   $knightc,         knight_walk5    ] {ai_walk(4);};
void() knight_walk5=[   $knightc,         knight_walk6    ] {ai_walk(3);};
void() knight_walk6=[   $knightc,         knight_walk7    ] {ai_walk(3);};
void() knight_walk7=[   $knightc,         knight_walk8    ] {ai_walk(3);};
void() knight_walk8=[   $knightc,         knight_walk9    ] {ai_walk(4);};
void() knight_walk9=[   $knightc,         knight_walk10   ] {ai_walk(3);};
void() knight_walk10=[  $knightc,        knight_walk11   ] {ai_walk(3);};
void() knight_walk11=[  $knightc,        knight_walk12   ] {ai_walk(2);};
void() knight_walk12=[  $knightc,        knight_walk13   ] {ai_walk(3);};
void() knight_walk13=[  $knightc,        knight_walk14   ] {ai_walk(4);};
void() knight_walk14=[  $knightc,        knight_walk1    ] {ai_walk(3);};


void() knight_run1=[    $knightc,         knight_run2     ] {
if (random() < 0.2)
        sound (self, CHAN_VOICE, "knight/idle.wav", 1,  ATTN_IDLE);
ai_run(16);};
void() knight_run2=[    $knightc,         knight_run3     ] {ai_run(20);};
void() knight_run3=[    $knightc,         knight_run4     ] {ai_run(13);};
void() knight_run4=[    $knightc,         knight_run5     ] {ai_run(7);};
void() knight_run5=[    $knightc,         knight_run6     ] {ai_run(16);};
void() knight_run6=[    $knightc,         knight_run7     ] {ai_run(20);};
void() knight_run7=[    $knightc,         knight_run8     ] {ai_run(14);};
void() knight_run8=[    $knightc,         knight_run1     ] {ai_run(6);};


void() knight_runatk1=[ $knightc,            knight_runatk2  ]
{
if (random() > 0.5)
        sound (self, CHAN_WEAPON, "knight/sword2.wav", 1, ATTN_NORM);
else
        sound (self, CHAN_WEAPON, "knight/sword1.wav", 1, ATTN_NORM);
ai_charge(20);
};
void() knight_runatk2=[ $knightc,    knight_runatk3  ] {ai_charge_side();};
void() knight_runatk3=[ $knightc,    knight_runatk4  ] {ai_charge_side();};
void() knight_runatk4=[ $knightc,    knight_runatk5  ] {ai_charge_side();};
void() knight_runatk5=[ $knightc,    knight_runatk6  ] {ai_melee_side();};
void() knight_runatk6=[ $knightc,    knight_runatk7  ] {ai_melee_side();};
void() knight_runatk7=[ $knightc,    knight_runatk8  ] {ai_melee_side();};
void() knight_runatk8=[ $knightc,    knight_runatk9  ] {ai_melee_side();};
void() knight_runatk9=[ $knightc,    knight_runatk10 ] {ai_melee_side();};
void() knight_runatk10=[        $knightc,   knight_runatk11 ] {ai_charge_side();};
void() knight_runatk11=[        $knightc,   knight_run1     ] {ai_charge(10);};

void() knight_atk1=[    $knightc,              knight_atk2     ]
{
sound (self, CHAN_WEAPON, "knight/sword1.wav", 1, ATTN_NORM);
ai_charge(0);};
void() knight_atk2=[    $knightc,              knight_atk3     ] {ai_charge(7);};
void() knight_atk3=[    $knightc,              knight_atk4     ] {ai_charge(4);};
void() knight_atk4=[    $knightc,              knight_atk5     ] {ai_charge(0);};
void() knight_atk5=[    $knightc,              knight_atk6     ] {ai_charge(3);};
void() knight_atk6=[    $knightc,              knight_atk7     ] {ai_charge(4); ai_melee();};
void() knight_atk7=[    $knightc,              knight_atk8     ] {ai_charge(1); ai_melee();};
void() knight_atk8=[    $knightc,              knight_atk9     ] {ai_charge(3);
ai_melee();};
void() knight_atk9=[    $knightc,              knight_atk10] {ai_charge(1);};
void() knight_atk10=[   $knightc,             knight_run1     ] {ai_charge(5);};

//void()        knight_atk9     =[      $knightc,               knight_atk10    ] {};
//void()        knight_atk10    =[      $knightc,              knight_atk11    ] {};
//void()        knight_atk11    =[      $knightc,              knight_run1     ] {};

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

void() knight_pain1=[   $knightc,         knight_pain2    ] {};
void() knight_pain2=[   $knightc,         knight_pain3    ] {};
void() knight_pain3=[   $knightc,         knight_run1     ] {};

void() knight_painb1=[  $knightc,        knight_painb2   ] {ai_painforward(0);};
void() knight_painb2=[  $knightc,        knight_painb3   ] {ai_painforward(3);};
void() knight_painb3=[  $knightc,        knight_painb4   ] {};
void() knight_painb4=[  $knightc,        knight_painb5   ] {};
void() knight_painb5=[  $knightc,        knight_painb6   ] {ai_painforward(2);};
void() knight_painb6=[  $knightc,        knight_painb7   ] {ai_painforward(4);};
void() knight_painb7=[  $knightc,        knight_painb8   ] {ai_painforward(2);};
void() knight_painb8=[  $knightc,        knight_painb9   ] {ai_painforward(5);};
void() knight_painb9=[  $knightc,        knight_painb10  ] {ai_painforward(5);};
void() knight_painb10=[ $knightc,       knight_painb11  ] {ai_painforward(0);};
void() knight_painb11=[ $knightc,       knight_run1     ] {};

void(entity attacker, float damage) knight_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)
        {
                knight_pain1 ();
                self.pain_finished = time + 1;
        }
        else
        {
                knight_painb1 ();
                self.pain_finished = time + 1;
        }
        
};

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

void() knight_bow1=[    $knightc,                knight_bow2     ] {ai_turn();};
void() knight_bow2=[    $knightc,                knight_bow3     ] {ai_turn();};
void() knight_bow3=[    $knightc,                knight_bow4     ] {ai_turn();};
void() knight_bow4=[    $knightc,                knight_bow5     ] {ai_turn();};

void() knight_bow5=[    $knightc,                knight_bow5     ] {ai_turn();};

void() knight_bow6=[    $knightc,                knight_bow7     ] {ai_turn();};
void() knight_bow7=[    $knightc,                knight_bow8     ] {ai_turn();};
void() knight_bow8=[    $knightc,                knight_bow9     ] {ai_turn();};
void() knight_bow9=[    $knightc,                knight_bow10    ] {ai_turn();};
void() knight_bow10=[   $knightc,         knight_walk1    ] {ai_turn();};



void() knight_die1=[    $knightd,        knight_die2     ] {};
void() knight_die2=[    $knightd,        knight_die3     ] {};
void() knight_die3=[    $knightd,        knight_die4     ] 
{self.solid = SOLID_NOT;};
void() knight_die4=[    $knightd,        knight_die5     ] {};
void() knight_die5=[    $knightd,        knight_die6     ] {};
void() knight_die6=[    $knightd,        knight_die7     ] {};
void() knight_die7=[    $knightd,        knight_die8     ] {};
void() knight_die8=[    $knightd,        knight_die9     ] {};
void() knight_die9=[    $knightd,        knight_die10] {};
void() knight_die10=[   $knightd,       knight_die10] {};


void() knight_dieb1=[   $knightd,       knight_dieb2    ] {};
void() knight_dieb2=[   $knightd,       knight_dieb3    ] {};
void() knight_dieb3=[   $knightd,       knight_dieb4    ]       
{self.solid = SOLID_NOT;};
void() knight_dieb4=[   $knightd,       knight_dieb5    ] {};
void() knight_dieb5=[   $knightd,       knight_dieb6    ] {};
void() knight_dieb6=[   $knightd,       knight_dieb7    ] {};
void() knight_dieb7=[   $knightd,       knight_dieb8    ] {};
void() knight_dieb8=[   $knightd,       knight_dieb9    ] {};
void() knight_dieb9=[   $knightd,       knight_dieb10] {};
void() knight_dieb10= [ $knightd,      knight_dieb11] {};
void() knight_dieb11= [ $knightd,      knight_dieb11] {};


void() knight_die=
{
// check for gib
        if (self.health < -40)
        {
                sound (self, CHAN_VOICE, "player/udeath.wav", 1, ATTN_NORM);
                ThrowHead ("progs/h_knight.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)
                knight_die1 ();
        else
                knight_dieb1 ();
};


/*UNTITLED-GAME/D monster_knight (1 0 0) (-16 -16 -24) (16 16 40) Ambush
*/

void() monster_knight=
{
        if (deathmatch)
        {
                remove(self);
                return;
        }
        precache_model ("progs/knight.mdl");
        precache_model ("progs/h_knight.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");

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

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

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

        self.th_stand = knight_stand1;
        self.th_walk = knight_walk1;
        self.th_run = knight_run1;
        self.th_melee = knight_atk1;
        self.th_pain = knight_pain;
        self.th_die = knight_die;
        
        walkmonster_start ();
};