⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 weapon_builder.cpp

📁 hl2 source code. Do not use it illegal.
💻 CPP
📖 第 1 页 / 共 2 页
字号:

					StartBuilding();

					// Should we switch away?
					if ( iFlags & OF_ALLOW_REPEAT_PLACEMENT )
					{
						// Start placing another
						SetCurrentState( BS_PLACING );
						StartPlacement(); 
					}
					else
					{
						pOwner->SwitchToNextBestWeapon( NULL );
					}
				}
			}
		}
		break;

	case BS_PLACING_INVALID:
		{
			WeaponSound( SINGLE_NPC );

			// If there is any associated error text when placing the object, display it
			if( m_hObjectBeingBuilt != NULL )
			{
				if (m_hObjectBeingBuilt->MustBeBuiltInResourceZone())
				{
					ClientPrint( pOwner, HUD_PRINTCENTER, "Only placeable in an empty resource zone.\n" );
				}
				else if (m_hObjectBeingBuilt->MustBeBuiltInConstructionYard())
				{
					ClientPrint( pOwner, HUD_PRINTCENTER, "Only placeable in a construction yard.\n" );
				}
			}
		}
		break;
	}

	m_flNextPrimaryAttack = gpGlobals->curtime + 0.2f;
}

//-----------------------------------------------------------------------------
// Purpose: Set the builder to the specified state
//-----------------------------------------------------------------------------
void CWeaponBuilder::SetCurrentState( int iState )
{
	// Check the current build state... we may need to shut some stuff down...
	switch(m_iBuildState)
	{
	case BS_PLACING:
	case BS_PLACING_INVALID:
		{
			if ((iState != BS_PLACING) && (iState != BS_PLACING_INVALID) && (iState != BS_BUILDING))
			{
				StopPlacement();
				WeaponSound( SPECIAL1 );
			}
		}
		break;
	}

	m_iBuildState = iState;
}

//-----------------------------------------------------------------------------
// Purpose: Set the builder to the specified object
//-----------------------------------------------------------------------------
void CWeaponBuilder::SetCurrentObject( int iObject )
{
	// Fixup for invalid objects
	if (iObject < 0)
		iObject = BUILDER_INVALID_OBJECT;

	CBaseTFPlayer *pOwner = ToBaseTFPlayer( GetOwner() );
	if ( !pOwner )
		return;

	int i;

	// If -1 was passed in, set to our first available object
	if ( iObject == BUILDER_INVALID_OBJECT )
	{
		for ( i = 0; i < OBJ_LAST; i++ )
		{
			if ( m_bObjectValidity[i] )
			{
				iObject = i;
				break;
			}
		}
	}

	// Recalculate the buildability of each object (for propagation to the client)
	for ( i=0; i < m_bObjectBuildability.Count(); i++ )
		m_bObjectBuildability.Set( i, 0 );

	for ( i = 0; i < OBJ_LAST; i++ )
	{
		if ( m_bObjectValidity[i] && pOwner->CanBuild(i) == CB_CAN_BUILD )
		{
			m_bObjectBuildability.Set( i, true );
		}
	}

	m_iCurrentObject = iObject;
	m_iCurrentObjectState = pOwner->CanBuild( m_iCurrentObject );
	m_flStartTime = 0;
	m_flTotalTime = 0;
}

//-----------------------------------------------------------------------------
// Purpose: Idle updates the position of the build placement model
//-----------------------------------------------------------------------------
void CWeaponBuilder::WeaponIdle( void )
{
	CBaseTFPlayer *pOwner = ToBaseTFPlayer( GetOwner() );
	if ( !pOwner )
		return;

	// If we're in placement mode, update the placement model
	switch( m_iBuildState )
	{
	case BS_PLACING:
	case BS_PLACING_INVALID:
		{
			if ( UpdatePlacement() )
			{
				SetCurrentState( BS_PLACING );
			}
			else
			{
				SetCurrentState( BS_PLACING_INVALID );
			}
		}
		break;

	default:
		break;
	}

	if ( HasWeaponIdleTimeElapsed() )
	{
		SendWeaponAnim( ACT_VM_IDLE );
	}
}

//-----------------------------------------------------------------------------
// Purpose: The player holding this weapon has just gained new technology.
//			Check to see if it affects the medikit
//-----------------------------------------------------------------------------
void CWeaponBuilder::GainedNewTechnology( CBaseTechnology *pTechnology )
{
	CBaseTFPlayer *pPlayer = ToBaseTFPlayer( GetOwner() );
	if ( pPlayer )
	{
		// Force a recalculation of the state for this object
		SetCurrentObject( m_iCurrentObject );
	}
}

//-----------------------------------------------------------------------------
// Purpose: Start placing the object
//-----------------------------------------------------------------------------
void CWeaponBuilder::StartPlacement( void )
{
	StopPlacement();

	// Create the slab
	m_hObjectBeingBuilt = (CBaseObject*)CreateEntityByName( GetObjectInfo( m_iCurrentObject )->m_pClassName );
	if ( m_hObjectBeingBuilt )
	{
		m_hObjectBeingBuilt->Spawn();
		m_hObjectBeingBuilt->StartPlacement( ToBaseTFPlayer( GetOwner() ) );
		UpdatePlacement();

		// Stomp this here in the same frame we make the object, so prevent clientside warnings that it's under attack
		m_hObjectBeingBuilt->m_iHealth = OBJECT_CONSTRUCTION_STARTINGHEALTH;
	}
}

//-----------------------------------------------------------------------------
// Purpose: Set the viewmodel according to the type of object we're placing
//-----------------------------------------------------------------------------
const char *CWeaponBuilder::GetViewModel( int viewmodelindex /*=0*/ )  const
{
	if ( m_hObjectBeingBuilt.Get() && m_hObjectBeingBuilt->IsAnUpgrade() )
		return "models/weapons/v_slam.mdl";

	return BaseClass::GetViewModel( viewmodelindex );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CWeaponBuilder::StopPlacement( void )
{
	if ( m_hObjectBeingBuilt )
	{
		m_hObjectBeingBuilt->StopPlacement();
		m_hObjectBeingBuilt = NULL;
	}
}

//-----------------------------------------------------------------------------
// Purpose: Move the placement model to the current position. Return false if it's an invalid position
//-----------------------------------------------------------------------------
bool CWeaponBuilder::UpdatePlacement( void )
{
	if ( !m_hObjectBeingBuilt )
		return false;

	return m_hObjectBeingBuilt->UpdatePlacement( ToBaseTFPlayer(GetOwner()) );
}

//-----------------------------------------------------------------------------
// Purpose: Player holding this weapon has started building something
//-----------------------------------------------------------------------------
void CWeaponBuilder::StartBuilding( void )
{
	if ( m_hObjectBeingBuilt.Get() && UpdatePlacement() )
	{
		SetCurrentState( BS_BUILDING );
		m_hObjectBeingBuilt->StartBuilding( GetOwner() );
	}
}

//-----------------------------------------------------------------------------
// Purpose: Player holding this weapon has aborted the build of an object
//-----------------------------------------------------------------------------
void CWeaponBuilder::StoppedBuilding( int iObjectType )
{
	CBaseTFPlayer *pPlayer = ToBaseTFPlayer( GetOwner() );
	if ( pPlayer )
	{
		// Force a recalculation of the state for this object
		SetCurrentObject( m_iCurrentObject );
		SetCurrentState( BS_IDLE );

		WeaponSound( SPECIAL2 );
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CWeaponBuilder::IsBuilding( void )
{
	return ( m_iBuildState == BS_BUILDING );
}

//-----------------------------------------------------------------------------
// Purpose: The player holding this weapon has just finished building an object
//-----------------------------------------------------------------------------
void CWeaponBuilder::FinishedObject( void )
{
	CBaseTFPlayer *pPlayer = ToBaseTFPlayer( GetOwner() );
	if ( pPlayer )
	{
		// We're no longer building anything...
		m_hObjectBeingBuilt = NULL;

		// Force a recalculation of the state for this object
		SetCurrentObject( m_iCurrentObject );
		SetCurrentState( BS_IDLE );
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -