/*********************************************************************//**
*	Zombie monster
*	zelena kvetina ke sberu.
*	
*	author: Michal Jirous
*	date: 23.04.2009
*	file: ent_monster_zombie.cpp
**********************************************************************/

#include "ent_basemonster.h"

enum animations
{
	ANIM_IDLE = 0,
	ANIM_TURN_LEFT,
	ANIM_TURN_RIGHT,
	ANIM_FLINCH_SMALL,
	ANIM_FLINCH,
	ANIM_BIGFLINCH,
	ANIM_GETUP,
	ANIM_FALLING,
	ANIM_ATTACK1,
	ANIM_ATTACK2,
	ANIM_WALK,
	ANIM_X,
	ANIM_XY,
	ANIM_XZ,
	ANIM_XX,
	ANIM_XYZ,
	ANIM_XYZs,
	ANIM_DIE_SIMPLE,
	ANIM_DIE_BACKWARD,
	ANIM_DIE_FORWARD
};


const std::string ZOMBIE_FIGHT_SOUNDS[FIGHT_SOUND_COUNT] = { 
	"zombie/claw_miss1.wav",
	"zombie/claw_miss2.wav",
	"zombie/claw_strike1.wav",
	"zombie/claw_strike2.wav",
	"zombie/claw_strike3.wav",
};


MonsterZombie::MonsterZombie()
{
	m_sClassName = "monster_zombie";
	m_sModelName = "Zombie/zombie_barney.mdl";
	m_iHealth = 100;

	for( int i = 0; i < FIGHT_SOUND_COUNT; ++i )
		m_FightSoundsPool.addSound( ZOMBIE_FIGHT_SOUNDS[i] );

	m_FightSound.setSourceRelative( AL_FALSE );
	m_iDefaultDeathSequence = ANIM_DIE_SIMPLE;
	DefaultRaisingSequence = ANIM_GETUP;
}

void MonsterZombie::update( float seconds )
{
	CBaseMonster::update( seconds );
	m_FightSound.setPosition( origin.x, origin.y, origin.z );

}
void MonsterZombie::compile()
{
	CBaseMonster::compile();


	m_fMaxSpeed = 2.0f;
}
void MonsterZombie::onIdle()
{
	playAnimation( ANIM_IDLE, NULL, NULL );
}

void MonsterZombie::onReachingAngle()
{
	CBaseMonster::onReachingAngle();
	playAnimation( ANIM_IDLE, NULL, NULL );

	/*if( m_fTargetAngle > 0.0f )
		playAnimation( ANIM_TURN_RIGHT, &CBaseMonster::onAngleReachAnimEnd, this );
	else
		playAnimation( ANIM_TURN_LEFT, &CBaseMonster::onAngleReachAnimEnd, this );*/
}

void MonsterZombie::onReachingTarget()
{
	CBaseMonster::onReachingTarget();
	playAnimation( ANIM_WALK, NULL, NULL );
}

void MonsterZombie::onAttack()
{
	if( m_iCurrentAnimation == ANIM_ATTACK1 || m_iCurrentAnimation == ANIM_ATTACK2 )
		return;


	int type = rand() % 2;

	if( type == 0 )
	{
		if( playAnimation( ANIM_ATTACK1, &CBaseMonster::onAttackEnd, this ) )
		{
			insertCallBack( 600, (void(CBaseMonster::*)(void)) (&MonsterZombie::onAttack1Finnish), this );
			insertCallBack( 1200, (void(CBaseMonster::*)(void)) (&MonsterZombie::onAttack1Finnish), this );
		}
	}
	else
	{
		if( playAnimation( ANIM_ATTACK2, &CBaseMonster::onAttackEnd, this ) )
			insertCallBack( 400, (void(CBaseMonster::*)(void)) (&MonsterZombie::onAttack2Finnish), this );
	}
	
}

void MonsterZombie::onDying()
{
	playAnimation( ANIM_DIE_BACKWARD, NULL, NULL );
}

void MonsterZombie::custom()
{
	CBaseMonster::custom();
}

#include "level_collision.h"
#include "game.h"
void MonsterZombie::onAttack2Finnish()
{
	fight( 10 );
}

bool MonsterZombie::fight( int damage )
{
	AttackInfo attackInfo;
	if( basic_combat( damage, attackInfo, 72.0f, dmg::SLASH ) )
	{
		m_FightSoundsPool.use( rand() % 3 + CLAW_STRIKE1, m_FightSound );
		m_FightSound.play();
		return true;
	}
	else
	{
		m_FightSoundsPool.use( rand() % 2 + CLAW_MISS1, m_FightSound );
		m_FightSound.play();
		return false;
	}

}


void MonsterZombie::onAttack1Finnish()
{
	fight( 5 );
}
