#include "extdll.h"
#include "util.h"

#include "cbase.h"
#include "effects.h"
#include "aura.h"
#include "classes.h"
#include "magicattack.h"
#include "explodingattack.h"
#include "player.h"
#include "nodes.h"
#include "weapons.h"
#include "soundent.h"
#include "monsters.h"
#include "decals.h"
#include "gamerules.h"

CGinyu::CGinyu ( CBasePlayer *player ): CBaseClass(player) 
{	
}

void CGinyu::AddAllAttacks( void )
{	m_pPlayer->GiveNamedItem("weapon_melee");
	m_pPlayer->GiveNamedItem("weapon_kiblast");
	m_pPlayer->GiveNamedItem("weapon_genericbeam");
	m_pPlayer->GiveNamedItem("weapon_purpleball");
	m_pPlayer->GiveNamedItem("weapon_sensu");	
}


CBaseClass* CGinyu::GetAscendedClass(void)
{	return NULL;
}

// ADDED BY IAN
//
// Ginyu does not transform, instead he gets a buddy
// if the class returns false the default StartAscend executes thats why (for ginyu) no matter what we return true 
BOOL CGinyu::StartAscend(void)
{			
	CBasePlayer* ginyu = this->m_pPlayer;
	if (!ginyu) return TRUE;

	// if we already have a buddy we can't have a new one!
	// this will need to be changed so we can get level 2 buddies, etc, etc..
	if (ginyu->m_hBuddy) return TRUE;

	if (FBitSet(ginyu->pev->flags, FL_SPECTATOR))
		return TRUE;	

	//IAN:: A BUDDY CAN COME OUT NO MATTER WHAT YOUR HEALTH
	//can't ascend if your health is too low
	if (ginyu->pev->health<PLDROP_HEALTH)
		return TRUE;

	
	//not doing something special? -- have to convert this so we can ask from outside the CBasePlayer class
	if (ginyu->m_fStrangled || ginyu->m_fBecomeCandy || ginyu->m_fCharging 
		|| ginyu->m_fPowerUp || ginyu->m_fTurbo || ginyu->m_fBlock || ginyu->m_fHoldDisc || 
		ginyu->m_fAscending || ginyu->m_fMelee || ginyu->m_Melee.m_fPowerhit || ginyu->m_fShield || 
		!ginyu->IsAlive() || (ginyu->m_fControl && !ginyu->m_fPowerStruggling) || ginyu->m_fSpawnInvulnerable) //phew
	{	return TRUE;
	}

	//enough ki to ascend?
	if (ginyu->pev->fuser4<ASCEND_KI_COST)
	{	return TRUE;
	}

	float flTransFromPL = this->GetTransFormPowerLevel();
	//float flTransFromPL = 0;


	//only transform if powerlevel is high enough
	if (ginyu->m_iPowerLevel >= flTransFromPL)
	{
		ALERT(at_console,"Creating buddy...\n");
        UTIL_MakeVectors(Vector(0,ginyu->pev->v_angle.y,0));
		ginyu->m_hBuddy = (CBuddy*)ginyu->Create("player_buddy", ginyu->pev->origin + gpGlobals->v_forward * 128 + gpGlobals->v_up * 28, ginyu->pev->angles, ginyu->edict());		

		ginyu->m_flAscendTime += TRANSFORM_TIME + gpGlobals->time;
		ginyu->m_fAscending = true;
		
		// we always use the normal transformation when getting a buddy
		//
		// the buddy will also play his "change_normal" animation
		ginyu->m_iTransformStatus = TRANS_NORM;
	}

	// we handled this!
	return TRUE;

	}
// ADDED BY IAN