CBaseEntity* CASW_Spawn_Manager::SpawnAlienAt(const char* szAlienClass, const Vector& vecPos, const QAngle &angle)
{	
	CBaseEntity	*pEntity = NULL;	
	pEntity = CreateEntityByName( szAlienClass );
	CAI_BaseNPC	*pNPC = dynamic_cast<CAI_BaseNPC*>(pEntity);

	if ( pNPC )
	{
		pNPC->AddSpawnFlags( SF_NPC_FALL_TO_GROUND );		
	}

	// Strip pitch and roll from the spawner's angles. Pass only yaw to the spawned NPC.
	QAngle angles = angle;
	angles.x = 0.0;
	angles.z = 0.0;	
	pEntity->SetAbsOrigin( vecPos );	
	pEntity->SetAbsAngles( angles );

	IASW_Spawnable_NPC* pSpawnable = dynamic_cast<IASW_Spawnable_NPC*>(pEntity);
	ASSERT(pSpawnable);	
	if ( !pSpawnable )
	{
		Warning("NULL Spawnable Ent in CASW_Spawn_Manager::SpawnAlienAt! AlienClass = %s\n", szAlienClass);
		UTIL_Remove(pEntity);
		return NULL;
	}

	// have drones unburrow by default, so we don't worry so much about them spawning onscreen
	if ( !Q_strcmp( szAlienClass, "asw_drone" ) )
	{			
		pSpawnable->StartBurrowed();
		pSpawnable->SetUnburrowIdleActivity( NULL_STRING );
		pSpawnable->SetUnburrowActivity( NULL_STRING );
	}

	DispatchSpawn( pEntity );	
	pEntity->Activate();	

	// give our aliens the orders
	pSpawnable->SetAlienOrders(AOT_MoveToNearestMarine, vec3_origin, NULL);

	// reactivedrop: fixed horde aliens falling through floor and stuck in walls
	// by moving this function call to the bottom of SpawnAlienAt()
	
	// riflemod: temporary comment to test whether parasites fall throught floor 
	//UTIL_DropToFloor(pEntity, MASK_SOLID);

	return pEntity;
}
IASW_Spawnable_NPC* CASW_Base_Spawner::SpawnAlien( const char *szAlienClassName, const Vector &vecHullMins, const Vector &vecHullMaxs )
{
	if ( !IsValidOnThisSkillLevel() )
	{
		UTIL_Remove(this);		// delete ourself if this spawner isn't valid on this difficulty level
		return NULL;
	}

	if ( !CanSpawn( vecHullMins, vecHullMaxs ) )	// this may turn off m_bCurrentlySpawningUber if there's no room
		return NULL;

	CBaseEntity	*pEntity = CreateEntityByName( szAlienClassName );
	if ( !pEntity )
	{
		Msg( "Failed to spawn %s\n", szAlienClassName );
		return NULL;
	}

	CAI_BaseNPC	*pNPC = pEntity->MyNPCPointer();
	if ( pNPC )
	{
		pNPC->AddSpawnFlags( SF_NPC_FALL_TO_GROUND );		
	}

	// check if he can see far
	if ( m_bLongRangeNPC )
		pEntity->AddSpawnFlags( SF_NPC_LONG_RANGE );

	if ( HasSpawnFlags( ASW_SF_NEVER_SLEEP ) )
		pEntity->AddSpawnFlags( SF_NPC_ALWAYSTHINK );

	// Strip pitch and roll from the spawner's angles. Pass only yaw to the spawned NPC.
	QAngle angles = GetAbsAngles();
	angles.x = 0.0;
	angles.z = 0.0;	
	pEntity->SetAbsOrigin( GetAbsOrigin() );	
	pEntity->SetAbsAngles( angles );

	IASW_Spawnable_NPC* pSpawnable = dynamic_cast<IASW_Spawnable_NPC*>(pEntity);
	Assert( pSpawnable );	
	if ( !pSpawnable )
	{
		Warning( "NULL Spawnable Ent in asw_spawner! AlienClass = %s\n", szAlienClassName );
		UTIL_Remove( pEntity );
		return NULL;
	}
	m_flLastSpawnTime = gpGlobals->curtime;
	if ( m_bStartBurrowed )
	{
		pSpawnable->StartBurrowed();
	}

	if ( m_bStartBurrowed )
	{
		pSpawnable->SetUnburrowIdleActivity( m_UnburrowIdleActivity );
		pSpawnable->SetUnburrowActivity( m_UnburrowActivity );
	}

	DispatchSpawn( pEntity );	

	pEntity->SetOwnerEntity( this );
	pEntity->Activate();

	if ( m_AlienName != NULL_STRING )
	{
		pEntity->SetName( m_AlienName );
	}
	
	pSpawnable->SetSpawner( this );

	RemoveObstructingProps( pEntity );	
	
	// give our aliens the orders
	pSpawnable->SetAlienOrders( m_AlienOrders, vec3_origin, GetOrderTarget() );

	m_OnSpawned.FireOutput(pEntity, this);

	return pSpawnable;
}