Пример #1
0
//-----------------------------------------------------------------------------
// Purpose: Creates the NPC.
//-----------------------------------------------------------------------------
void CNPCMaker::MakeNPC( void )
{
	if (!CanMakeNPC())
		return;

	CAI_BaseNPC	*pent = (CAI_BaseNPC*)CreateEntityByName( STRING(m_iszNPCClassname) );

	if ( !pent )
	{
		Warning("NULL Ent in NPCMaker!\n" );
		return;
	}
	
	// ------------------------------------------------
	//  Intialize spawned NPC's relationships
	// ------------------------------------------------
	pent->SetRelationshipString( m_RelationshipString );

	m_OnSpawnNPC.Set( pent, pent, this );

	pent->SetAbsOrigin( GetAbsOrigin() );

	// 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;
	pent->SetAbsAngles( angles );

	pent->AddSpawnFlags( SF_NPC_FALL_TO_GROUND );

	if ( m_spawnflags & SF_NPCMAKER_FADE )
	{
		pent->AddSpawnFlags( SF_NPC_FADE_CORPSE );
	}

	pent->m_spawnEquipment	= m_spawnEquipment;
	pent->SetSquadName( m_SquadName );
	pent->SetHintGroup( m_strHintGroup );

	ChildPreSpawn( pent );

	DispatchSpawn( pent );
	pent->SetOwnerEntity( this );
	DispatchActivate( pent );

	if ( m_ChildTargetName != NULL_STRING )
	{
		// if I have a netname (overloaded), give the child NPC that name as a targetname
		pent->SetName( m_ChildTargetName );
	}

	ChildPostSpawn( pent );

	m_nLiveChildren++;// count this NPC

	if (!(m_spawnflags & SF_NPCMAKER_INF_CHILD))
	{
		m_nMaxNumNPCs--;

		if ( IsDepleted() )
		{
			m_OnAllSpawned.FireOutput( this, this );

			// Disable this forever.  Don't kill it because it still gets death notices
			SetThink( NULL );
			SetUse( NULL );
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: Creates the NPC.
//-----------------------------------------------------------------------------
void CNPCMakerXenInvasion::MakeNPC(void)
{
	if (!CanMakeNPC())
		return;
	
	if (g_pGameRules->bHasRandomized)
	{
		if (g_pGameRules->iRandomGamemode == FIREFIGHT_PRIMARY_XENINVASION)
		{
			int nNPCs = ARRAYSIZE(g_charNPCSXenInvasionSupport);
			int randomChoice = rand() % nNPCs;
			const char *pRandomName = g_charNPCSXenInvasionSupport[randomChoice];

			CAI_BaseNPC	*pent = (CAI_BaseNPC*)CreateEntityByName(pRandomName);

			if (!pent)
			{
				Warning("npc_maker_firefight: Entity classname does not exist in database.\n");
				return;
			}

			// ------------------------------------------------
			//  Intialize spawned NPC's relationships
			// ------------------------------------------------
			pent->SetRelationshipString(m_RelationshipString);

			m_OnSpawnNPC.Set(pent, pent, this);

			pent->SetAbsOrigin(GetAbsOrigin());

			// 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;
			pent->SetAbsAngles(angles);

			pent->AddSpawnFlags(SF_NPC_FALL_TO_GROUND);

			if (m_spawnflags & SF_NPCMAKER_FADE)
			{
				pent->AddSpawnFlags(SF_NPC_FADE_CORPSE);
			}

			pent->m_isRareEntity = false;
			pent->SetSquadName(m_SquadName);
			pent->SetHintGroup(m_strHintGroup);

			ChildPreSpawn(pent);

			DispatchSpawn(pent);
			pent->SetOwnerEntity(this);
			DispatchActivate(pent);

			if (m_ChildTargetName != NULL_STRING)
			{
				// if I have a netname (overloaded), give the child NPC that name as a targetname
				pent->SetName(m_ChildTargetName);
			}

			ChildPostSpawn(pent);
		}
		else
		{
			CAI_BaseNPC	*pent = (CAI_BaseNPC*)CreateEntityByName(STRING(m_iszNPCClassname));

			if (!pent)
			{
				Warning("npc_maker_firefight: Entity classname does not exist in database.\n");
				return;
			}

			// ------------------------------------------------
			//  Intialize spawned NPC's relationships
			// ------------------------------------------------
			pent->SetRelationshipString(m_RelationshipString);

			m_OnSpawnNPC.Set(pent, pent, this);

			pent->SetAbsOrigin(GetAbsOrigin());

			// 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;
			pent->SetAbsAngles(angles);

			pent->AddSpawnFlags(SF_NPC_FALL_TO_GROUND);

			if (m_spawnflags & SF_NPCMAKER_FADE)
			{
				pent->AddSpawnFlags(SF_NPC_FADE_CORPSE);
			}

			pent->m_spawnEquipment = m_spawnEquipment;
			pent->m_isRareEntity = false;
			pent->SetSquadName(m_SquadName);
			pent->SetHintGroup(m_strHintGroup);

			ChildPreSpawn(pent);

			DispatchSpawn(pent);
			pent->SetOwnerEntity(this);
			DispatchActivate(pent);

			if (m_ChildTargetName != NULL_STRING)
			{
				// if I have a netname (overloaded), give the child NPC that name as a targetname
				pent->SetName(m_ChildTargetName);
			}

			ChildPostSpawn(pent);
		}
	}
	else
	{
		if (g_pGameRules->GetGamemode() == FIREFIGHT_PRIMARY_XENINVASION)
		{
			int nNPCs = ARRAYSIZE(g_charNPCSXenInvasionSupport);
			int randomChoice = rand() % nNPCs;
			const char *pRandomName = g_charNPCSXenInvasionSupport[randomChoice];

			CAI_BaseNPC	*pent = (CAI_BaseNPC*)CreateEntityByName(pRandomName);

			if (!pent)
			{
				Warning("npc_maker_firefight: Entity classname does not exist in database.\n");
				return;
			}

			// ------------------------------------------------
			//  Intialize spawned NPC's relationships
			// ------------------------------------------------
			pent->SetRelationshipString(m_RelationshipString);

			m_OnSpawnNPC.Set(pent, pent, this);

			pent->SetAbsOrigin(GetAbsOrigin());

			// 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;
			pent->SetAbsAngles(angles);

			pent->AddSpawnFlags(SF_NPC_FALL_TO_GROUND);

			if (m_spawnflags & SF_NPCMAKER_FADE)
			{
				pent->AddSpawnFlags(SF_NPC_FADE_CORPSE);
			}

			pent->m_isRareEntity = false;
			pent->SetSquadName(m_SquadName);
			pent->SetHintGroup(m_strHintGroup);

			ChildPreSpawn(pent);

			DispatchSpawn(pent);
			pent->SetOwnerEntity(this);
			DispatchActivate(pent);

			if (m_ChildTargetName != NULL_STRING)
			{
				// if I have a netname (overloaded), give the child NPC that name as a targetname
				pent->SetName(m_ChildTargetName);
			}

			ChildPostSpawn(pent);
		}
		else
		{
			CAI_BaseNPC	*pent = (CAI_BaseNPC*)CreateEntityByName(STRING(m_iszNPCClassname));

			if (!pent)
			{
				Warning("npc_maker_firefight: Entity classname does not exist in database.\n");
				return;
			}

			// ------------------------------------------------
			//  Intialize spawned NPC's relationships
			// ------------------------------------------------
			pent->SetRelationshipString(m_RelationshipString);

			m_OnSpawnNPC.Set(pent, pent, this);

			pent->SetAbsOrigin(GetAbsOrigin());

			// 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;
			pent->SetAbsAngles(angles);

			pent->AddSpawnFlags(SF_NPC_FALL_TO_GROUND);

			if (m_spawnflags & SF_NPCMAKER_FADE)
			{
				pent->AddSpawnFlags(SF_NPC_FADE_CORPSE);
			}

			pent->m_spawnEquipment = m_spawnEquipment;
			pent->m_isRareEntity = false;
			pent->SetSquadName(m_SquadName);
			pent->SetHintGroup(m_strHintGroup);

			ChildPreSpawn(pent);

			DispatchSpawn(pent);
			pent->SetOwnerEntity(this);
			DispatchActivate(pent);

			if (m_ChildTargetName != NULL_STRING)
			{
				// if I have a netname (overloaded), give the child NPC that name as a targetname
				pent->SetName(m_ChildTargetName);
			}

			ChildPostSpawn(pent);
		}
	}

	m_nLiveChildren++;// count this NPC
}