//=========================================================
// Guardar los objetos necesarios en caché.
//=========================================================
void CDirectorSpawn::Precache()
{
	BaseClass::Precache();

	// NPC's
	int pNpcs = ARRAYSIZE(iNpcs) - 1;
	for ( int i = 0; i < pNpcs; ++i )
	{
		if ( iNpcs[i] == NULL_STRING )
			continue;

		// Buscamos si hay una plantilla con este nombre.
		string_t NpcData = Templates_FindByTargetName(STRING(iNpcs[i]));
			
		// No, se trata de una clase.
		if ( NpcData == NULL_STRING )
			UTIL_PrecacheOther(STRING(iNpcs[i]));
		else
		{
			// Guardamos en caché la plantilla.
			CBaseEntity *pEntity = NULL;
			MapEntity_ParseEntity(pEntity, STRING(NpcData), NULL);

			if ( pEntity != NULL )
			{
				pEntity->Precache();
				UTIL_RemoveImmediate(pEntity);
			}
		}
	}

	// JEFES
	int pBoss = ARRAYSIZE(iBoss) - 1;
	for ( int i = 0; i < pBoss; ++i )
	{
		if ( iBoss[i] == NULL_STRING )
			continue;

		// Buscamos si hay una plantilla con este nombre.
		string_t NpcData = Templates_FindByTargetName(STRING(iBoss[i]));
			
		// No, se trata de una clase.
		if ( NpcData == NULL_STRING )
			UTIL_PrecacheOther(STRING(iBoss[i]));
		else
		{
			// Guardamos en caché la plantilla.
			CBaseEntity *pEntity = NULL;
			MapEntity_ParseEntity(pEntity, STRING(NpcData), NULL);

			if ( pEntity != NULL )
			{
				pEntity->Precache();
				UTIL_RemoveImmediate(pEntity);
			}
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: Called after spawning on map load or on a load from save game.
//-----------------------------------------------------------------------------
void CNPC_CombineDropship::Activate( void )
{
	BaseClass::Activate();
	
	// check for valid template
	if (!m_sNPCTemplateData)
	{
		//
		// This must be the first time we're activated, not a load from save game.
		// Look up the template in the template database.
		//
		if (!m_sNPCTemplate)
		{
			Warning( "npc_template_maker %s has no template NPC!\n", GetEntityName() );
			return;
		}
		else
		{
			m_sNPCTemplateData = Templates_FindByTargetName(STRING(m_sNPCTemplate));
			if ( m_sNPCTemplateData == NULL_STRING )
			{
				Warning( "Template NPC %s not found!\n", STRING(m_sNPCTemplate) );
				return;
			}
		}
	}

}
void CTemplateNPCMaker::Precache()
{
	BaseClass::Precache();

	if ( !m_iszTemplateData )
	{
		//
		// This must be the first time we're activated, not a load from save game.
		// Look up the template in the template database.
		//
		if (!m_iszTemplateName)
		{
			Warning( "npc_template_maker %s has no template NPC!\n", STRING(GetEntityName()) );
			UTIL_Remove( this );
			return;
		}
		else
		{
			m_iszTemplateData = Templates_FindByTargetName(STRING(m_iszTemplateName));
			if ( m_iszTemplateData == NULL_STRING )
			{
				DevWarning( "npc_template_maker %s: template NPC %s not found!\n", STRING(GetEntityName()), STRING(m_iszTemplateName) );
				UTIL_Remove( this );
				return;
			}
		}
	}

	Assert( m_iszTemplateData != NULL_STRING );

	// If the mapper marked this as "preload", then instance the entity preache stuff and delete the entity
	//if ( !HasSpawnFlags(SF_NPCMAKER_NOPRELOADMODELS) )
	if ( m_iszTemplateData != NULL_STRING )
	{
		CBaseEntity *pEntity = NULL;
		MapEntity_ParseEntity( pEntity, STRING(m_iszTemplateData), NULL );
		if ( pEntity != NULL )
		{
			PrecacheTemplateEntity( pEntity );
			UTIL_RemoveImmediate( pEntity );
		}
	}
}
//=========================================================
// Devuelve la creación de un NPC desde su clase/plantilla
//=========================================================
CAI_BaseNPC *CDirectorSpawn::VerifyClass(const char *pClass)
{
	// Buscamos si hay una plantilla con este nombre.
	string_t NpcData		= Templates_FindByTargetName(pClass);
	CAI_BaseNPC *pNPC		= NULL;

	// No, se trata de una clase.
	if ( NpcData == NULL_STRING )
	{
		// Creamos al NPC.
		pNPC = (CAI_BaseNPC *)CreateEntityByName(pClass);
	}
	else
	{
		// Creamos al NPC a partir de la plantilla.
		CBaseEntity *pEntity = NULL;
		MapEntity_ParseEntity(pEntity, STRING(NpcData), NULL);

		if ( pEntity != NULL )
			pNPC = (CAI_BaseNPC *)pEntity;
	}

	return pNPC;
}