//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CPropCrane::Think(void)
{
	SetNextThink( gpGlobals->curtime + 0.1 );

	if ( GetDriver() )
	{
		BaseClass::Think();
		
		if ( m_hNPCDriver )
		{
			GetServerVehicle()->NPC_DriveVehicle();
		}

		// play enter animation
		StudioFrameAdvance();

		// If the enter or exit animation has finished, tell the server vehicle
		if ( IsSequenceFinished() && (m_bExitAnimOn || m_bEnterAnimOn) )
		{
			if ( m_bEnterAnimOn )
			{
				// Finished entering, display the hint for using the crane
				UTIL_HudHintText( m_hPlayer, "#Valve_Hint_CraneKeys" );
			}
			
			GetServerVehicle()->HandleEntryExitFinish( m_bExitAnimOn, true );
		}
	}
	else
	{
		// Run the crane's movement
		RunCraneMovement( 0.1 );
	}

	// Update follower bones
	m_BoneFollowerManager.UpdateBoneFollowers(this);
}
Exemple #2
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CASW_PropJeep::Think(void)
{
	m_VehiclePhysics.Think();

	// Derived classes of CPropVehicle have their own code to determine how frequently to think.
	// But the prop_vehicle entity native to this class will only think one time, so this flag
	// was added to allow prop_vehicle to always think without affecting the derived classes.
	if( HasSpawnFlags(SF_PROP_VEHICLE_ALWAYSTHINK) )
	{
		SetNextThink(gpGlobals->curtime);
	}

	if ( ShouldThink() )
	{
		SetNextThink( gpGlobals->curtime );
	}

	// If we have an NPC Driver, tell him to drive
	if ( m_hNPCDriver )
	{
		GetServerVehicle()->NPC_DriveVehicle();
	}

	// Keep thinking while we're waiting to turn off the keep upright
	if ( m_flTurnOffKeepUpright )
	{
		SetNextThink( gpGlobals->curtime );

		// Time up?
		if ( m_hKeepUpright != NULL && m_flTurnOffKeepUpright < gpGlobals->curtime )
		{
			variant_t emptyVariant;
			m_hKeepUpright->AcceptInput( "TurnOff", this, this, emptyVariant, USE_TOGGLE );
			m_flTurnOffKeepUpright = 0;

			UTIL_Remove( m_hKeepUpright );
		}
	}
	/*
	CBasePlayer	*pPlayer = UTIL_GetLocalPlayer();

	if ( m_bEngineLocked )
	{
		m_bUnableToFire = true;
		
		if ( pPlayer != NULL )
		{
			pPlayer->m_Local.m_iHideHUD |= HIDEHUD_VEHICLE_CROSSHAIR;
		}
	}
	else if ( m_bHasGun )
	{
		// Start this as false and update it again each frame
		m_bUnableToFire = false;

		if ( pPlayer != NULL )
		{
			pPlayer->m_Local.m_iHideHUD &= ~HIDEHUD_VEHICLE_CROSSHAIR;
		}
	}*/

	// Water!?
	HandleWater();

	SetSimulationTime( gpGlobals->curtime );
	
	SetNextThink( gpGlobals->curtime );
	SetAnimatedEveryTick( true );

    if ( !m_bInitialHandbrake )	// after initial timer expires, set the handbrake
	{
		m_bInitialHandbrake = true;
		m_VehiclePhysics.SetHandbrake( true );
		m_VehiclePhysics.Think();
	}

	// Check overturned status.
	if ( !IsOverturned() )
	{
		m_flOverturnedTime = 0.0f;
	}
	else
	{
		m_flOverturnedTime += gpGlobals->frametime;
	}

	// spin gun if charging cannon
	//FIXME: Don't bother for E3
	if ( m_bCannonCharging )
	{
		m_nSpinPos += JEEP_GUN_SPIN_RATE;
		SetPoseParameter( JEEP_GUN_SPIN, m_nSpinPos );
	}

	// Aim gun based on the player view direction.
	if ( m_hPlayer && !m_bExitAnimOn && !m_bEnterAnimOn )
	{
		Vector vecEyeDir, vecEyePos;
		m_hPlayer->EyePositionAndVectors( &vecEyePos, &vecEyeDir, NULL, NULL );

		// Trace out from the player's eye point.
		Vector	vecEndPos = vecEyePos + ( vecEyeDir * MAX_TRACE_LENGTH );
		trace_t	trace;
		UTIL_TraceLine( vecEyePos, vecEndPos, MASK_SHOT, this, COLLISION_GROUP_NONE, &trace );

		// See if we hit something, if so, adjust end position to hit location.
		if ( trace.fraction < 1.0 )
		{
   			vecEndPos = vecEyePos + ( vecEyeDir * MAX_TRACE_LENGTH * trace.fraction );
		}

		//m_vecLookCrosshair = vecEndPos;
		AimGunAt( &vecEndPos, 0.1f );
	}

	StudioFrameAdvance();

	// If the enter or exit animation has finished, tell the server vehicle
	if ( IsSequenceFinished() && (m_bExitAnimOn || m_bEnterAnimOn) )
	{
		if ( m_bEnterAnimOn )
		{
			m_VehiclePhysics.ReleaseHandbrake();
			StartEngine();

			// HACKHACK: This forces the jeep to play a sound when it gets entered underwater
			if ( m_VehiclePhysics.IsEngineDisabled() )
			{
				CBaseServerVehicle *pServerVehicle = dynamic_cast<CBaseServerVehicle *>(GetServerVehicle());
				if ( pServerVehicle )
				{
					pServerVehicle->SoundStartDisabled();
				}
			}

			// The first few time we get into the jeep, print the jeep help
			if ( m_iNumberOfEntries < asw_hud_jeephint_numentries.GetInt() )
			{
				UTIL_HudHintText( m_hPlayer, "#Valve_Hint_JeepKeys" );
				m_iNumberOfEntries++;
			}
		}
		
		// If we're exiting and have had the tau cannon removed, we don't want to reset the animation
		GetServerVehicle()->HandleEntryExitFinish( m_bExitAnimOn, !(m_bExitAnimOn && TauCannonHasBeenCutOff()) );
	}

	// See if the ammo crate needs to close
	if ( ( m_flAmmoCrateCloseTime < gpGlobals->curtime ) && ( GetSequence() == LookupSequence( "ammo_open" ) ) )
	{
		m_flAnimTime = gpGlobals->curtime;
		m_flPlaybackRate = 0.0;
		SetCycle( 0 );
		ResetSequence( LookupSequence( "ammo_close" ) );
	}
	else if ( ( GetSequence() == LookupSequence( "ammo_close" ) ) && IsSequenceFinished() )
	{
		m_flAnimTime = gpGlobals->curtime;
		m_flPlaybackRate = 0.0;
		SetCycle( 0 );
		ResetSequence( LookupSequence( "idle" ) );

		CPASAttenuationFilter sndFilter( this, "PropJeep.AmmoClose" );
		EmitSound( sndFilter, entindex(), "PropJeep.AmmoClose" );
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CPropJeep::Think(void)
{
	BaseClass::Think();

/*
	CBasePlayer	*pPlayer = UTIL_GetLocalPlayer();

	if ( m_bEngineLocked )
	{
		m_bUnableToFire = true;
		
		if ( pPlayer != NULL )
		{
			pPlayer->m_Local.m_iHideHUD |= HIDEHUD_VEHICLE_CROSSHAIR;
		}
	}
	else
	{
		// Start this as false and update it again each frame
		m_bUnableToFire = false;

		if ( pPlayer != NULL )
		{
			pPlayer->m_Local.m_iHideHUD &= ~HIDEHUD_VEHICLE_CROSSHAIR;
		}
	}
*/

	// Water!?
	HandleWater();

	SetSimulationTime( gpGlobals->curtime );
	
	SetNextThink( gpGlobals->curtime );
	SetAnimatedEveryTick( true );

    if ( !m_bInitialHandbrake )	// after initial timer expires, set the handbrake
	{
		m_bInitialHandbrake = true;
		m_VehiclePhysics.SetHandbrake( true );
		m_VehiclePhysics.Think();
	}

	// Check overturned status.
	if ( !IsOverturned() )
	{
		m_flOverturnedTime = 0.0f;
	}
	else
	{
		m_flOverturnedTime += gpGlobals->frametime;
	}

	// spin gun if charging cannon
	//FIXME: Don't bother for E3
	if ( m_bCannonCharging )
	{
		m_nSpinPos += JEEP_GUN_SPIN_RATE;
		SetPoseParameter( JEEP_GUN_SPIN, m_nSpinPos );
	}

	// Aim gun based on the player view direction.
	if ( m_hPlayer && !m_bExitAnimOn && !m_bEnterAnimOn )
	{
		Vector vecEyeDir, vecEyePos;
		m_hPlayer->EyePositionAndVectors( &vecEyePos, &vecEyeDir, NULL, NULL );

		// Trace out from the player's eye point.
		Vector	vecEndPos = vecEyePos + ( vecEyeDir * MAX_TRACE_LENGTH );
		trace_t	trace;
		UTIL_TraceLine( vecEyePos, vecEndPos, MASK_SHOT, this, COLLISION_GROUP_NONE, &trace );

		// See if we hit something, if so, adjust end position to hit location.
		if ( trace.fraction < 1.0 )
		{
   			vecEndPos = vecEyePos + ( vecEyeDir * MAX_TRACE_LENGTH * trace.fraction );
		}

		//m_vecLookCrosshair = vecEndPos;
		AimGunAt( &vecEndPos, 0.1f );
	}

	StudioFrameAdvance();

	// If the enter or exit animation has finished, tell the server vehicle
	if ( IsSequenceFinished() && (m_bExitAnimOn || m_bEnterAnimOn) )
	{
		if ( m_bEnterAnimOn )
		{
			m_VehiclePhysics.ReleaseHandbrake();
			StartEngine();

			// HACKHACK: This forces the jeep to play a sound when it gets entered underwater
			if ( m_VehiclePhysics.IsEngineDisabled() )
			{
				CBaseServerVehicle *pServerVehicle = dynamic_cast<CBaseServerVehicle *>(GetServerVehicle());
				if ( pServerVehicle )
				{
					pServerVehicle->SoundStartDisabled();
				}
			}

			// The first few time we get into the jeep, print the jeep help
			if ( m_iNumberOfEntries < hud_jeephint_numentries.GetInt() )
			{
				UTIL_HudHintText( m_hPlayer, "#Valve_Hint_JeepKeys" );
				m_iNumberOfEntries++;
			}
		}
		
		// If we're exiting and have had the tau cannon removed, we don't want to reset the animation
		GetServerVehicle()->HandleEntryExitFinish( m_bExitAnimOn, true );
	}

	// See if the ammo crate needs to close
	if ( ( m_flAmmoCrateCloseTime < gpGlobals->curtime ) && ( GetSequence() == LookupSequence( "ammo_open" ) ) )
	{
		m_flAnimTime = gpGlobals->curtime;
		m_flPlaybackRate = 0.0;
		SetCycle( 0 );
		ResetSequence( LookupSequence( "ammo_close" ) );
	}
	else if ( ( GetSequence() == LookupSequence( "ammo_close" ) ) && IsSequenceFinished() )
	{
		m_flAnimTime = gpGlobals->curtime;
		m_flPlaybackRate = 0.0;
		SetCycle( 0 );
		ResetSequence( LookupSequence( "idle" ) );

		CPASAttenuationFilter sndFilter( this, "PropJeep.AmmoClose" );
		EmitSound( sndFilter, entindex(), "PropJeep.AmmoClose" );
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//    NOTE: Doesn't call the base call enter vehicle on purpose!
//-----------------------------------------------------------------------------
void CPropVehicleManhack::EnterVehicle( CBaseCombatCharacter *pPassenger )
{
	if ( pPassenger == NULL )
		return;

	DevMsg("CPropVehicleManhack: EnterVehicl(...)\n");

	CBasePlayer *pPlayer = ToBasePlayer( pPassenger );
	if ( pPlayer != NULL )
	{
		// Remove any player who may be in the vehicle at the moment
		if ( m_hPlayer )
		{
			ExitVehicle( VEHICLE_ROLE_DRIVER );
		}

		m_hPlayer = pPlayer;
		m_bHadDriver = true;

		if (GetNumberOfHacks(false)>1 && m_iHintTimesShown < 2)
		{
			m_iHintTimesShown++;
			m_iHintNoSwapTimesShown++;
			UTIL_HudHintText( pPlayer, "#HLSS_Hint_ManhackSwap" );
		} else if (m_iHintNoSwapTimesShown < 2)
		{
			m_iHintNoSwapTimesShown++;
			UTIL_HudHintText( pPlayer, "#HLSS_Hint_ManhackExit" );
		}
		else UTIL_HudHintText( pPlayer, "" );
	

		pPlayer->SetViewOffset( vec3_origin );
		pPlayer->ShowCrosshair( false );


		CHL2_Player *pHL2Player = dynamic_cast<CHL2_Player*>( pPlayer );
		if ( pHL2Player )
		{
			if ( pHL2Player->IsSprinting() )
			{
				pHL2Player->StopSprinting();
			}

			if ( pHL2Player->FlashlightIsOn() )
			{
				pHL2Player->FlashlightTurnOff();
			}
		}

		CNPC_Manhack *pManhack = dynamic_cast<CNPC_Manhack*>((CBaseEntity*)m_hManhack);
		if (pManhack!=NULL)
		{
			pManhack->SetControllable(true);

			if (manhack_dont_draw.GetBool())
			{
				pManhack->AddEffects( EF_NODRAW );
				pManhack->ShowRedGlow(false);
			}

			m_vecLastEyeTarget = pManhack->GetManhackView();
			m_vecLastEyePos    = pManhack->GetManhackView();
			m_vecTargetSpeed   = pManhack->GetAbsVelocity();

			m_vecFlyingDirection = pManhack->GetAbsVelocity();
		}

		//We want to see and feel the "vehicle" in manhack mode
		//SetRenderMode(kRenderNormal);
		RemoveEffects( EF_NODRAW );
		SetSolid(SOLID_BBOX);
		RemoveSolidFlags( FSOLID_NOT_SOLID );

		if (m_bDriverDucked) 
		{
			SetCollisionBounds( Vector(-16,-16,0), Vector(16,16,45) );

			int nSequence = LookupSequence( "crouch" );

			DevMsg("Player is ducking\n");

			// Set to the desired anim, or default anim if the desired is not present
			if ( nSequence > ACTIVITY_NOT_AVAILABLE )
			{
				SetCycle( 0 );
				m_flAnimTime = gpGlobals->curtime;
				ResetSequence( nSequence );
				ResetClientsideFrame();
			}
			else 
			{
				// Not available try to get default anim
				Msg( "Manhack Controller %s: missing crouch sequence\n", GetDebugName() );
				SetSequence( 0 );
			}
		}
		else
		{
			SetCollisionBounds( Vector(-16,-16,0), Vector(16,16,72) );

			int nSequence = LookupSequence( "idle" );

			// Set to the desired anim, or default anim if the desired is not present
			if ( nSequence > ACTIVITY_NOT_AVAILABLE )
			{
				SetCycle( 0 );
				m_flAnimTime = gpGlobals->curtime;
				ResetSequence( nSequence );
				ResetClientsideFrame();
			}
		}

		// Start Thinking
		SetNextThink( gpGlobals->curtime );

	}
	else
	{
		// NPCs not yet supported - jdw
		Assert( 0 );
	}


}
void CWeapon_Manhack::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator )
{
	CBasePlayer *pOwner = ToBasePlayer( GetOwner() );

	switch( pEvent->event )
	{
		case EVENT_WEAPON_SEQUENCE_FINISHED:
			m_bIsDrawing = false;
			m_bIsDoingShit = false;
			m_bIsDoingShitToo = false;

			if (m_bRedraw)
			{
				m_bRedraw=false;
				Deploy();
			}
			break;

		case EVENT_WEAPON_THROW:
			if (CPropVehicleManhack::GetManhackVehicle()!=NULL)
			{
				if (m_bHasFreeSlot)	
				{
					if (CreateControllableNPCManhack( pOwner))
					{
						DecrementAmmo( pOwner );
						EnableManhackSubModel(false);
						m_bRedraw=true;

						CBasePlayer *pPlayer = ToBasePlayer( pOwner );
						if ( pPlayer != NULL && m_iManhackHintTimeShown < 2)
						{
							if (GlobalEntity_GetState("manhacks_not_controllable") == GLOBAL_ON )
								UTIL_HudHintText( pPlayer, "#HLSS_Hint_ManhackSend" );
							else
								UTIL_HudHintText( pPlayer, "#HLSS_Hint_ManhackControl" );

							m_iManhackHintTimeShown++;
						}
//						fSpawnedManhack = true;
					}
				}
			}
			else if (CreateControllableVehicleManhack( pOwner))
			{
				DecrementAmmo( pOwner );	
				EnableManhackSubModel(false);	
				m_bRedraw=true;
//				fSpawnedManhack = true;

				//CBasePlayer *pPlayer = ToBasePlayer( pOwner );
				if ( pOwner != NULL && m_iManhackHintTimeShown <2)
				{
					if (GlobalEntity_GetState("manhacks_not_controllable") == GLOBAL_ON )
						UTIL_HudHintText( pOwner, "#HLSS_Hint_ManhackSend" );
					else
						UTIL_HudHintText( pOwner, "#HLSS_Hint_ManhackControl" );

					m_iManhackHintTimeShown++;
				}
			}

			m_bToggleCallback = true;

			if (!m_bHoldingSpawn)
			{
				m_bSpawnSomeMore = false;
				m_bIsDoingController = true;
			}
			else
			{
				m_bSpawnSomeMore = true;
				m_bIsDoingController = false;
				m_bRedraw = true;
			}

			break;
		case EVENT_WEAPON_THROW2:
			if ( pOwner != NULL && pOwner->GetFlags() & FL_ONGROUND )
			{
				if (CPropVehicleManhack::GetManhackVehicle() != NULL) 
				{
					if (GlobalEntity_GetState("manhacks_not_controllable") == GLOBAL_OFF)
					{
						m_bShouldShowPanel = false;
						DriveControllableManhack();
					}
					else
					{
						if (m_bToggleCallback)
						{
							TellManhacksToGoThere();
							m_bToggleCallback = false;
						}
						else
						{
							CallManhacksBack();
							m_bToggleCallback = true;
						}

					}
				}
				else
				{
					//TERO: Lets do an error sound
				}
			}
			break;
		case EVENT_WEAPON_THROW3:
			if (m_bToggleCallback)
			{
				TellManhacksToGoThere();
				m_bToggleCallback = false;
			}
			else
			{
				CallManhacksBack();
				m_bToggleCallback = true;
			}
			break;
		default:
			BaseClass::Operator_HandleAnimEvent( pEvent, pOperator );
			break;
	}

#define RETHROW_DELAY	0.5
/*	if( fSpawnedManhack )
	{
		m_flNextPrimaryAttack	= gpGlobals->curtime + RETHROW_DELAY;
		m_flNextSecondaryAttack	= gpGlobals->curtime + RETHROW_DELAY;
		m_flTimeWeaponIdle = FLT_MAX; //NOTE: This is set once the animation has finished up!

	}
	*/
}
bool CWeapon_Manhack::Deploy( void )
{
	CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
	if ( !pOwner )
	{
		return false;
	}

	// ------------------------------
	// Pick the right draw animation
	// ------------------------------
	int iActivity;

	m_bHasFreeSlot = HasFreeSlot();

	bool bNoDrivable = true;

	CPropVehicleManhack *pManhack = CPropVehicleManhack::GetManhackVehicle();

	if (pManhack) //m_hManhack)
	{
		// = dynamic_cast<CPropVehicleManhack*>((CBaseEntity*)m_hManhack);

		if (pManhack->HasDrivableManhack(pOwner))
		{
			bNoDrivable = false;
		}
	}

	if ( m_bHasAmmo && m_bHasFreeSlot && (!m_bIsDoingController || bNoDrivable))
	{
		iActivity = ACT_VM_DRAW;
		//EnableManhackSubModel(true);

		CBasePlayer *pPlayer = ToBasePlayer( pOwner );
			if ( pPlayer != NULL)

		m_bIsDoingController = false;
		m_bSpawnSomeMore = true; //TERO: not sure about this
	} 
	else
	{
		m_bIsDoingController = true;
		m_bSpawnSomeMore = false;
		iActivity = ACT_SLAM_DETONATOR_DRAW;
	}

	m_bIsDrawing=true;

	m_bShouldShowPanel = true;


	//TERO: this next bit is to make sure the player gets the right hint message if the controllable state has changed
	if (GlobalEntity_GetState("manhacks_not_controllable") == GLOBAL_ON )
	{
		if (m_bHadControllable)
		{
			m_iManhackHintTimeShown=0;
			CBasePlayer *pPlayer = ToBasePlayer( pOwner );
			if ( pPlayer != NULL && (CPropVehicleManhack::GetManhackVehicle() != NULL) )
			{
				UTIL_HudHintText( pPlayer, "#HLSS_Hint_ManhackSend" );
				m_iManhackHintTimeShown++;
			}
		}

		m_bHadControllable = false;
	} 
	else
	{
		if (!m_bHadControllable)
		{
			m_iManhackHintTimeShown=0;
			CBasePlayer *pPlayer = ToBasePlayer( pOwner );
			if ( pPlayer != NULL && (CPropVehicleManhack::GetManhackVehicle() != NULL) )
			{
				UTIL_HudHintText( pPlayer, "#HLSS_Hint_ManhackControl" );
				m_iManhackHintTimeShown++;
			}
		}
		m_bHadControllable = true;
	}

	if (!m_hScreen)
	{
		/*CBaseViewModel *vm = pOwner->GetViewModel( m_nViewModelIndex );
		if (vm)
		{

			//vm->SpawnControlPanels();
			int nLLAttachmentIndex = vm->LookupAttachment("controlpanel0_ll");
			int nURAttachmentIndex = vm->LookupAttachment("controlpanel0_ur");

			matrix3x4_t	panelToWorld;
			vm->GetAttachment( nLLAttachmentIndex, panelToWorld );

			matrix3x4_t	worldToPanel;
			MatrixInvert( panelToWorld, worldToPanel );

			// Now get the lower right position + transform into panel space
			Vector lr, lrlocal;
			vm->GetAttachment( nURAttachmentIndex, panelToWorld );
			MatrixGetColumn( panelToWorld, 3, lr );
			VectorTransform( lr, worldToPanel, lrlocal );

			float flWidth = lrlocal.x;
			float flHeight = lrlocal.y;

			CVGuiScreen *pScreen = CreateVGuiScreen( "vgui_screen", "manhack_screen", this, this, 0 );
			pScreen->ChangeTeam( 69 );
			pScreen->SetActualSize( 128, 64 );
			pScreen->SetActive( true );
			pScreen->MakeVisibleOnlyToTeammates( true );
			pScreen->SetAttachedToViewModel(true);
			m_hScreen.Set( pScreen );
		}*/

		CVGuiScreen *pScreen = CreateVGuiScreen( "vgui_screen", "manhack_screen", this, this, 0 );
		//pScreen->SetActualSize( 128, 64 );
		pScreen->SetActive( true );
		pScreen->MakeVisibleOnlyToTeammates( true );
		pScreen->SetAttachedToViewModel(true);
		m_hScreen.Set( pScreen );

	}

	return DefaultDeploy( (char*)GetViewModel(), (char*)GetWorldModel(), iActivity, (char*)GetAnimPrefix() );
}