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

snake

==============================================================================
*/
$cd /raid/quake/id1/models/snakeman
$origin 0 0 -24
$base base
$skin skin
$scale 1

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

$frame attack1 attack2 attack3 attack4 attack5 attack6 attack7 attack8
$frame attack9 attack10

$frame pain1 pain2 pain3 pain4 pain5 pain6 pain7

$frame die die die1 die2 die3 die4 die5 die6 die7 die8 die9 die10 die11

$frame dead2 dead3 dead4 dead5 dead6 dead7

$frame bpain1 bpain2 bpain3 bpain4 bpain5 bpain6 bpain7

void() snake_pain;
void(float offset) SnakeMissile;
void() snake_stand     =[      $walk10,       snake_stand2    ] {ai_stand();};
void() snake_stand2     =[      $walk11,       snake_stand3    ] {ai_turn();};
void() snake_stand3     =[      $walk12,       snake_stand4    ] {ai_stand();};
void() snake_stand4     =[      $walk13,       snake_stand5    ] {ai_turn();};
void() snake_stand5     =[      $walk14,       snake_stand6    ] {ai_stand();};
void() snake_stand6     =[      $walk15,       snake_stand7    ] {ai_turn();};
void() snake_stand7     =[      $walk16,       snake_stand8    ] {ai_turn();};
void() snake_stand8     =[      $walk15,       snake_stand9    ] {ai_turn();};
void() snake_stand9     =[      $walk14,       snake_stand10    ] {ai_stand();};
void() snake_stand10     =[      $walk13,       snake_stand11    ] {ai_turn();};
void() snake_stand11     =[      $walk12,       snake_stand12    ] {ai_stand();};
void() snake_stand12     =[      $walk11,       snake_stand    ] {ai_turn();};

void() snake_walk1     =[      $walk1,       snake_walk2    ] {
if (random() < 0.2)
	sound (self, CHAN_VOICE, "wizard/widle2.wav", 1, ATTN_IDLE);
ai_walk(2);};
void() snake_walk2     =[      $walk2,       snake_walk3    ] {ai_walk(3);};
void() snake_walk3     =[      $walk3,       snake_walk4    ] {ai_walk(3);};
void() snake_walk4     =[      $walk4,       snake_walk5    ] {ai_walk(3);};
void() snake_walk5     =[      $walk5,       snake_walk6    ] {ai_walk(3);};
void() snake_walk6     =[      $walk6,       snake_walk7    ] {ai_walk(3);};
void() snake_walk7     =[      $walk7,       snake_walk8    ] {ai_walk(3);};
void() snake_walk8     =[      $walk8,       snake_walk9    ] {ai_walk(3);};
void() snake_walk9     =[      $walk9,       snake_walk10   ] {ai_walk(3);};
void() snake_walk10    =[      $walk10,      snake_walk11   ] {ai_walk(3);};
void() snake_walk11    =[      $walk11,      snake_walk12   ] {ai_walk(3);};
void() snake_walk12    =[      $walk12,      snake_walk13   ] {ai_walk(2);};
void() snake_walk13    =[      $walk13,      snake_walk14   ] {ai_walk(2);};
void() snake_walk14    =[      $walk14,      snake_walk15   ] {ai_walk(2);};
void() snake_walk15    =[      $walk15,      snake_walk16   ] {ai_walk(1);};
void() snake_walk16    =[      $walk16,      snake_walk1    ] {ai_walk(1);};

void() snake_run1  =[  $walk1,  snake_run2  ] { 
self.attack_state = AS_SLIDING;  //snakeman now strafes 
if (random() < 0.2) 
   sound (self, CHAN_VOICE, "wizard/widle1.wav", 1, ATTN_IDLE); 
ai_run(6);}; 
void() snake_run2  =[  $walk3,  snake_run3  ] {ai_run(9);}; 
void() snake_run3  =[  $walk5,  snake_run4  ] {ai_run(6);}; 
void() snake_run4  =[  $walk7,  snake_run5  ] {ai_run(9);}; 
void() snake_run5  =[  $walk9,  snake_run6  ] {self.attack_state = AS_STRAIGHT;ai_face();}; 
void() snake_run6  =[  $walk11,  snake_run7  ] {ai_run(15);}; 
void() snake_run7  =[  $walk13,  snake_run8  ] {ai_run(12);};        
void() snake_run8  =[  $walk15,  snake_run1  ] {ai_run(15);}; 
 
void() snake_attack1  =[  $attack1,  snake_attack6  ] { 
sound (self, CHAN_VOICE, "wizard/wattack.wav", 1, ATTN_NORM); 
ai_face();}; 
void() snake_attack6  =[  $attack6,  snake_attack7  ] {ai_run(12);ai_run_slide();SnakeMissile(2);SnakeMissile(-2);}; 
void() snake_attack7  =[  $attack7,  snake_attack8  ] {ai_run(12);ai_run_slide();SnakeMissile(1);SnakeMissile(-1);}; 
void() snake_attack8  =[  $attack8,  snake_attack9  ] {ai_run(12);ai_run_slide();SnakeMissile(0);SnakeMissile(0);}; 
void() snake_attack9  =[  $attack9,  snake_attack10  ] {ai_run(12);ai_run_slide();SnakeMissile(0);SnakeMissile(0);}; 
void() snake_attack10  =[  $attack10,  snake_run1  ] {ai_run(12);ai_run_slide();SnakeMissile(0);SnakeMissile(0);SUB_CheckRefire (snake_attack1);}; 

void() snake_pain1       =[      $pain1, snake_pain2      ] {};
void() snake_pain2       =[      $pain2, snake_pain3      ] {};
void() snake_pain3       =[      $pain3, snake_pain4      ] {};
void() snake_pain4       =[      $pain4, snake_pain5      ] {};
void() snake_pain5       =[      $pain5, snake_pain6      ] {};
void() snake_pain6       =[      $pain6, snake_pain7      ] {};
void() snake_pain7       =[      $pain7, snake_run1       ] {};

void() snake_bpain1       =[      $bpain1, snake_bpain2      ] {};
void() snake_bpain2       =[      $bpain2, snake_bpain3      ] {};
void() snake_bpain3       =[      $bpain3, snake_bpain4      ] {};
void() snake_bpain4       =[      $bpain4, snake_bpain5      ] {};
void() snake_bpain5       =[      $bpain5, snake_bpain6      ] {};
void() snake_bpain6       =[      $bpain6, snake_bpain7      ] {};
void() snake_bpain7       =[      $bpain7, snake_run1       ] {};

void() snake_death1      =[      $die2,        snake_death3     ] {};
void() snake_death3      =[      $die3,        snake_death4     ] {};
void() snake_death4      =[      $die4,        snake_death5     ] {};
void() snake_death5      =[      $die5,        snake_death6     ] {};
void() snake_death6      =[      $die6,        snake_death7     ] {};
void() snake_death7      =[      $die7,        snake_death8     ] {};
void() snake_death8      =[      $die8,        snake_death9     ] {};
void() snake_death9      =[      $die9,        snake_death10    ] {self.ammo_nails = 15;DropBackpack();};
void() snake_death10     =[      $die10,        snake_death11    ] {};
void() snake_death11     =[      $die11,        snake_death12    ] {};
void() snake_death12     =[      $die11,        snake_death12    ] {};

void() snake_dead1     =[      $dead2,        snake_dead2    ] {};
void() snake_dead2     =[      $dead3,        snake_dead3    ] {};
void() snake_dead3     =[      $dead4,        snake_dead4    ] {};
void() snake_dead4     =[      $dead5,        snake_dead5    ] {self.ammo_nails = 15;DropBackpack();};
void() snake_dead5     =[      $dead6,        snake_dead6    ] {};
void() snake_dead6     =[      $dead7,        snake_dead6    ] {};

void() snake_pain =
{
	if (self.pain_finished > time)
				return;

				sound (self, CHAN_VOICE, "ogre/ogpain1.wav", 1, ATTN_NORM);
self.velocity_x = -50 - 50 * random();
self.velocity_y = 0;
self.velocity_z = 5 + 2 * random();
self.flags = self.flags - (self.flags & FL_ONGROUND);
	self.pain_finished = time + 3;
	if (random() > 0.5)
		snake_pain1 ();
	else
		snake_bpain1 ();
};

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

	sound (self, CHAN_VOICE, "wizard/wdeath.wav", 1, ATTN_NORM);
self.movetype = MOVETYPE_BOUNCE;
self.velocity_x = -50 + 100*random();
self.velocity_y = -50 + 100*random();
self.velocity_z = 2 + 2*random();
self.avelocity_x = -20 + 40*random();
self.avelocity_y = -200 + 400*random();
self.avelocity_z = 0;
self.flags = self.flags - (self.flags & FL_ONGROUND);
	self.solid = SOLID_NOT;
	// insert death sounds here
	if (random() > 0.5)
		snake_death1 ();
	else
		snake_dead1 ();
};

/*
================
SnakeMissile
================
*/

void(float offset) SnakeMissile =
{ 
    local   vector  offang; 
    local   vector  org, vec; 
        self.effects = self.effects | EF_MUZZLEFLASH;
	offang = vectoangles (self.enemy.origin - self.origin);
	offang_y = offang_y + offset * 6;
	
	makevectors (offang);

	org = self.origin - 30*normalize(self.velocity);

// set missile speed
	vec = normalize (v_forward);
	vec_z = 0 - vec_z + (random() - 0.5)*0.1;
	
	launch_spike (org, vec);
	newmis.classname = "LaunchNails";
	setmodel (newmis, "progs/spike.mdl");
	setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);		
	newmis.velocity = vec*1000;
	sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);

};

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

/*QUAKED monster_snakeman (1 0 0) (-32 -32 -24) (50 50 50) Ambush
*/
void() monster_snakeman =
{
	if (deathmatch)
	{
		remove(self);
		return;
	}
	precache_model2 ("progs/snakeman.mdl");
	precache_model2 ("progs/k_spike.mdl");
	precache_model2 ("progs/uzi.mdl");

	precache_sound2 ("wizard/wattack.wav");
	precache_sound2 ("wizard/widle2.wav");
	precache_sound2 ("wizard/wdeath.wav");
	precache_sound2 ("wizard/widle1.wav");
	precache_sound2 ("ogre/ogpain1.wav");
	precache_sound2 ("wizard/wdeath.wav");
	
	self.solid = SOLID_SLIDEBOX;
	self.movetype = MOVETYPE_STEP;
	
	setmodel (self, "progs/snakeman.mdl");
	setsize (self, VEC_HULL2_MIN, VEC_HULL2_MAX); 
	self.health = 150;

	self.th_stand = snake_stand;
	self.th_walk = snake_walk1;
	self.th_run = snake_run1;
	self.th_die = snake_die;
	self.th_pain = snake_pain;
	self.th_missile = snake_attack1;

	self.think = walkmonster_start;
	self.nextthink = time + 0.1 + random ()*0.1;	
};
 
 
// setsize (self, '-16 -16 -24', '16 16 40');  
