//----------------------------------------------------------------------------- // Purpose: Forces an update //----------------------------------------------------------------------------- void CBuildMenu::OnThink() { // CBasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( BaseClass::IsVisible() == false ) return; CalculateButtonState(); for (int i = 0; i < TYPE_TOTAL; i++) { if ((spawnbuttons[i] && spawnbuttons[i]->IsCursorOver()) || (spawnfives[i] && spawnfives[i]->IsCursorOver())) { ShowZombieInfo(i); } } //TGB: force close if not ZM C_HL2MP_Player *pPlayer = C_HL2MP_Player::GetLocalHL2MPPlayer(); if (pPlayer && pPlayer->IsZM() == false) { //prevent edge cases with roundrestarts while panel is open DoClose(); } }
virtual void PostDataUpdate( DataUpdateType_t updateType ) { // Create the effect. C_HL2MP_Player *pPlayer = dynamic_cast< C_HL2MP_Player* >( m_hPlayer.Get() ); if ( pPlayer && !pPlayer->IsDormant() ) { pPlayer->DoAnimationEvent( (PlayerAnimEvent_t)m_iEvent.Get(), m_nData ); } }
//-------------------------------------------------------------- // Helper that closes the menu //-------------------------------------------------------------- void CBuildMenu::DoClose() { Close(); SetVisible( false ); SetMouseInputEnabled( false ); //bring viewport back up C_HL2MP_Player *pPlayer = C_HL2MP_Player::GetLocalHL2MPPlayer(); if (pPlayer && pPlayer->IsZM()) { //prevent edge cases with roundrestarts while panel is open m_pViewPort->ShowPanel( PANEL_VIEWPORT, true ); } gViewPortInterface->ShowBackGround( false ); }
// CODE DUPLICATION BELOW. FIXME! C_BaseEntity *ProcessTarget() { C_HL2MP_Player *pPlayer = C_HL2MP_Player::GetLocalHL2MPPlayer(); if ( !pPlayer ) return NULL; // Get our target's ent index int iEntIndex = pPlayer->GetIDTarget(); // Didn't find one? if ( !iEntIndex ) { return NULL; } if ( iEntIndex ) { // set up the vectors and traceline trace_t tr; Vector vecStart, vecStop, vecDir; // get the angles AngleVectors( pPlayer->EyeAngles( ), &vecDir ); // get the vectors vecStart = pPlayer->EyePosition(); vecStop = vecStart + vecDir * 1024; // do the traceline UTIL_TraceLine( vecStart, vecStop, MASK_ALL, pPlayer, COLLISION_GROUP_NPC, &tr ); C_BaseEntity *pEntity = tr.m_pEnt; // check to see if we found a block if ( !pEntity ) return NULL; return pEntity; } return NULL; }
//----------------------------------------------------------------------------- // Purpose: called to update the menu with new information //----------------------------------------------------------------------------- void CSDKTeamMenu::Update( void ) { BaseClass::Update(); const ConVar *allowspecs = cvar->FindVar( "mp_allowspectators" ); C_HL2MP_Player *pPlayer = C_HL2MP_Player::GetLocalHL2MPPlayer(); if ( !pPlayer || !HL2MPRules() ) return; if ( allowspecs && allowspecs->GetBool() ) { if ( pPlayer->GetTeamNumber() == TEAM_UNASSIGNED || ( pPlayer && pPlayer->IsPlayerDead() ) ) { SetVisibleButton("specbutton", true); } else { SetVisibleButton("specbutton", false); } } else { SetVisibleButton("specbutton", false ); } if( pPlayer->GetTeamNumber() == TEAM_UNASSIGNED ) // we aren't on a team yet { SetVisibleButton("CancelButton", false); } else { SetVisibleButton("CancelButton", true); } MoveToCenterOfScreen(); }
void C_HL2MPRagdoll::CreateHL2MPRagdoll( void ) { // First, initialize all our data. If we have the player's entity on our client, // then we can make ourselves start out exactly where the player is. C_HL2MP_Player *pPlayer = dynamic_cast< C_HL2MP_Player* >( m_hPlayer.Get() ); if ( pPlayer && !pPlayer->IsDormant() ) { // move my current model instance to the ragdoll's so decals are preserved. pPlayer->SnatchModelInstance( this ); VarMapping_t *varMap = GetVarMapping(); // Copy all the interpolated vars from the player entity. // The entity uses the interpolated history to get bone velocity. bool bRemotePlayer = (pPlayer != C_BasePlayer::GetLocalPlayer()); if ( bRemotePlayer ) { Interp_Copy( pPlayer ); SetAbsAngles( pPlayer->GetRenderAngles() ); GetRotationInterpolator().Reset(); m_flAnimTime = pPlayer->m_flAnimTime; SetSequence( pPlayer->GetSequence() ); m_flPlaybackRate = pPlayer->GetPlaybackRate(); } else { // This is the local player, so set them in a default // pose and slam their velocity, angles and origin SetAbsOrigin( m_vecRagdollOrigin ); SetAbsAngles( pPlayer->GetRenderAngles() ); SetAbsVelocity( m_vecRagdollVelocity ); int iSeq = pPlayer->GetSequence(); if ( iSeq == -1 ) { Assert( false ); // missing walk_lower? iSeq = 0; } SetSequence( iSeq ); // walk_lower, basic pose SetCycle( 0.0 ); Interp_Reset( varMap ); } } else { // overwrite network origin so later interpolation will // use this position SetNetworkOrigin( m_vecRagdollOrigin ); SetAbsOrigin( m_vecRagdollOrigin ); SetAbsVelocity( m_vecRagdollVelocity ); Interp_Reset( GetVarMapping() ); } SetModelIndex( m_nModelIndex ); // Make us a ragdoll.. m_nRenderFX = kRenderFxRagdoll; matrix3x4_t boneDelta0[MAXSTUDIOBONES]; matrix3x4_t boneDelta1[MAXSTUDIOBONES]; matrix3x4_t currentBones[MAXSTUDIOBONES]; const float boneDt = 0.05f; if ( pPlayer && !pPlayer->IsDormant() ) { pPlayer->GetRagdollInitBoneArrays( boneDelta0, boneDelta1, currentBones, boneDt ); } else { GetRagdollInitBoneArrays( boneDelta0, boneDelta1, currentBones, boneDt ); } InitAsClientRagdoll( boneDelta0, boneDelta1, currentBones, boneDt ); }
void C_HL2MP_Player::AvoidPlayers( CUserCmd *pCmd ) { // This is only used in team play. if ( !HL2MPRules()->IsTeamplay() ) return; // Don't test if the player doesn't exist or is dead. if ( IsAlive() == false ) return; C_Team *pTeam = ( C_Team * )GetTeam(); if ( !pTeam ) return; // Up vector. static Vector vecUp( 0.0f, 0.0f, 1.0f ); Vector vecHL2MPPlayerCenter = GetAbsOrigin(); Vector vecHL2MPPlayerMin = GetPlayerMins(); Vector vecHL2MPPlayerMax = GetPlayerMaxs(); float flZHeight = vecHL2MPPlayerMax.z - vecHL2MPPlayerMin.z; vecHL2MPPlayerCenter.z += 0.5f * flZHeight; VectorAdd( vecHL2MPPlayerMin, vecHL2MPPlayerCenter, vecHL2MPPlayerMin ); VectorAdd( vecHL2MPPlayerMax, vecHL2MPPlayerCenter, vecHL2MPPlayerMax ); // Find an intersecting player or object. int nAvoidPlayerCount = 0; C_HL2MP_Player *pAvoidPlayerList[MAX_PLAYERS]; C_HL2MP_Player *pIntersectPlayer = NULL; float flAvoidRadius = 0.0f; Vector vecAvoidCenter, vecAvoidMin, vecAvoidMax; for ( int i = 0; i < pTeam->GetNumPlayers(); ++i ) { C_HL2MP_Player *pAvoidPlayer = static_cast< C_HL2MP_Player * >( pTeam->GetPlayer( i ) ); if ( pAvoidPlayer == NULL ) continue; // Is the avoid player me? if ( pAvoidPlayer == this ) continue; // Save as list to check against for objects. pAvoidPlayerList[nAvoidPlayerCount] = pAvoidPlayer; ++nAvoidPlayerCount; // Check to see if the avoid player is dormant. if ( pAvoidPlayer->IsDormant() ) continue; // Is the avoid player solid? if ( pAvoidPlayer->IsSolidFlagSet( FSOLID_NOT_SOLID ) ) continue; Vector t1, t2; vecAvoidCenter = pAvoidPlayer->GetAbsOrigin(); vecAvoidMin = pAvoidPlayer->GetPlayerMins(); vecAvoidMax = pAvoidPlayer->GetPlayerMaxs(); flZHeight = vecAvoidMax.z - vecAvoidMin.z; vecAvoidCenter.z += 0.5f * flZHeight; VectorAdd( vecAvoidMin, vecAvoidCenter, vecAvoidMin ); VectorAdd( vecAvoidMax, vecAvoidCenter, vecAvoidMax ); if ( IsBoxIntersectingBox( vecHL2MPPlayerMin, vecHL2MPPlayerMax, vecAvoidMin, vecAvoidMax ) ) { // Need to avoid this player. if ( !pIntersectPlayer ) { pIntersectPlayer = pAvoidPlayer; break; } } } // Anything to avoid? if ( !pIntersectPlayer ) return; // Calculate the push strength and direction. Vector vecDelta; // Avoid a player - they have precedence. if ( pIntersectPlayer ) { VectorSubtract( pIntersectPlayer->WorldSpaceCenter(), vecHL2MPPlayerCenter, vecDelta ); Vector vRad = pIntersectPlayer->WorldAlignMaxs() - pIntersectPlayer->WorldAlignMins(); vRad.z = 0; flAvoidRadius = vRad.Length(); } float flPushStrength = RemapValClamped( vecDelta.Length(), flAvoidRadius, 0, 0, hl2mp_max_separation_force.GetInt() ); //flPushScale; //Msg( "PushScale = %f\n", flPushStrength ); // Check to see if we have enough push strength to make a difference. if ( flPushStrength < 0.01f ) return; Vector vecPush; if ( GetAbsVelocity().Length2DSqr() > 0.1f ) { Vector vecVelocity = GetAbsVelocity(); vecVelocity.z = 0.0f; CrossProduct( vecUp, vecVelocity, vecPush ); VectorNormalize( vecPush ); } else { // We are not moving, but we're still intersecting. QAngle angView = pCmd->viewangles; angView.x = 0.0f; AngleVectors( angView, NULL, &vecPush, NULL ); } // Move away from the other player/object. Vector vecSeparationVelocity; if ( vecDelta.Dot( vecPush ) < 0 ) { vecSeparationVelocity = vecPush * flPushStrength; } else { vecSeparationVelocity = vecPush * -flPushStrength; } // Don't allow the max push speed to be greater than the max player speed. float flMaxPlayerSpeed = MaxSpeed(); float flCropFraction = 1.33333333f; if ( ( GetFlags() & FL_DUCKING ) && ( GetGroundEntity() != NULL ) ) { flMaxPlayerSpeed *= flCropFraction; } float flMaxPlayerSpeedSqr = flMaxPlayerSpeed * flMaxPlayerSpeed; if ( vecSeparationVelocity.LengthSqr() > flMaxPlayerSpeedSqr ) { vecSeparationVelocity.NormalizeInPlace(); VectorScale( vecSeparationVelocity, flMaxPlayerSpeed, vecSeparationVelocity ); } QAngle vAngles = pCmd->viewangles; vAngles.x = 0; Vector currentdir; Vector rightdir; AngleVectors( vAngles, ¤tdir, &rightdir, NULL ); Vector vDirection = vecSeparationVelocity; VectorNormalize( vDirection ); float fwd = currentdir.Dot( vDirection ); float rt = rightdir.Dot( vDirection ); float forward = fwd * flPushStrength; float side = rt * flPushStrength; //Msg( "fwd: %f - rt: %f - forward: %f - side: %f\n", fwd, rt, forward, side ); pCmd->forwardmove += forward; pCmd->sidemove += side; // Clamp the move to within legal limits, preserving direction. This is a little // complicated because we have different limits for forward, back, and side //Msg( "PRECLAMP: forwardmove=%f, sidemove=%f\n", pCmd->forwardmove, pCmd->sidemove ); float flForwardScale = 1.0f; if ( pCmd->forwardmove > fabs( cl_forwardspeed.GetFloat() ) ) { flForwardScale = fabs( cl_forwardspeed.GetFloat() ) / pCmd->forwardmove; } else if ( pCmd->forwardmove < -fabs( cl_backspeed.GetFloat() ) ) { flForwardScale = fabs( cl_backspeed.GetFloat() ) / fabs( pCmd->forwardmove ); } float flSideScale = 1.0f; if ( fabs( pCmd->sidemove ) > fabs( cl_sidespeed.GetFloat() ) ) { flSideScale = fabs( cl_sidespeed.GetFloat() ) / fabs( pCmd->sidemove ); } float flScale = min( flForwardScale, flSideScale ); pCmd->forwardmove *= flScale; pCmd->sidemove *= flScale; //Msg( "Pforwardmove=%f, sidemove=%f\n", pCmd->forwardmove, pCmd->sidemove ); }
//----------------------------------------------------------------------------- // Purpose: Draw function for the element //----------------------------------------------------------------------------- void CTargetID::Paint() { #define MAX_ID_STRING 256 wchar_t sIDString[ MAX_ID_STRING ]; sIDString[0] = 0; C_HL2MP_Player *pPlayer = C_HL2MP_Player::GetLocalHL2MPPlayer(); if ( !pPlayer ) return; Color c; // Get our target's ent index int iEntIndex = pPlayer->GetIDTarget(); // Didn't find one? if ( !iEntIndex ) { // Check to see if we should clear our ID if ( m_flLastChangeTime && (gpGlobals->curtime > (m_flLastChangeTime + 0.5)) ) { m_flLastChangeTime = 0; sIDString[0] = 0; m_iLastEntIndex = 0; } else { // Keep re-using the old one iEntIndex = m_iLastEntIndex; } } else { m_flLastChangeTime = gpGlobals->curtime; } // Is this an entindex sent by the server? if ( iEntIndex ) { C_BasePlayer *pPlayer = static_cast<C_BasePlayer*>(cl_entitylist->GetEnt( iEntIndex )); C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer(); const char *printFormatString = NULL; wchar_t wszPlayerName[ MAX_PLAYER_NAME_LENGTH ]; wchar_t wszHealthText[ 10 ]; bool bShowHealth = false; bool bShowPlayerName = false; // Some entities we always want to check, cause the text may change // even while we're looking at it // Is it a player? if ( IsPlayerIndex( iEntIndex ) ) { c = GetColorForTargetTeam( pPlayer->GetTeamNumber() ); bShowPlayerName = true; g_pVGuiLocalize->ConvertANSIToUnicode( pPlayer->GetPlayerName(), wszPlayerName, sizeof(wszPlayerName) ); if ( pPlayer->InSameTeam(pLocalPlayer) ) { printFormatString = "#Playerid_sameteam"; bShowHealth = true; } else { printFormatString = "#Playerid_diffteam"; } if ( bShowHealth ) { _snwprintf( wszHealthText, ARRAYSIZE(wszHealthText) - 1, L"%.0f%%", ((float)pPlayer->GetHealth() / (float)pPlayer->GetMaxHealth() ) ); wszHealthText[ ARRAYSIZE(wszHealthText)-1 ] = '\0'; } } if ( printFormatString ) { if ( bShowPlayerName && bShowHealth ) { g_pVGuiLocalize->ConstructString( sIDString, sizeof(sIDString), g_pVGuiLocalize->Find(printFormatString), 2, wszPlayerName, wszHealthText ); } else if ( bShowPlayerName ) { g_pVGuiLocalize->ConstructString( sIDString, sizeof(sIDString), g_pVGuiLocalize->Find(printFormatString), 1, wszPlayerName ); } else if ( bShowHealth ) { g_pVGuiLocalize->ConstructString( sIDString, sizeof(sIDString), g_pVGuiLocalize->Find(printFormatString), 1, wszHealthText ); } else { g_pVGuiLocalize->ConstructString( sIDString, sizeof(sIDString), g_pVGuiLocalize->Find(printFormatString), 0 ); } } if ( sIDString[0] ) { int wide, tall; int ypos = YRES(260); int xpos = XRES(10); vgui::surface()->GetTextSize( m_hFont, sIDString, wide, tall ); if( hud_centerid.GetInt() == 0 ) { ypos = YRES(420); } else { xpos = (ScreenWidth() - wide) / 2; } vgui::surface()->DrawSetTextFont( m_hFont ); vgui::surface()->DrawSetTextPos( xpos, ypos ); vgui::surface()->DrawSetTextColor( c ); vgui::surface()->DrawPrintText( sIDString, wcslen(sIDString) ); } } }
//----------------------------------------------------------------------------- // Purpose: shows the build menu //----------------------------------------------------------------------------- void CBuildMenu::ShowPanel(bool bShow) { // CBasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( BaseClass::IsVisible() == bShow ) return; if ( bShow ) { //TGB: manipmenu cannot be open open as it will conflict m_pViewPort->ShowPanel( PANEL_MANIPULATE, false ); //viewport has to go too, or the build menu can sometimes become unresponsive to commands m_pViewPort->ShowPanel( PANEL_VIEWPORT, false ); //TGB: update costs if necessary /*we print these live from the cvar now if (NeedCostsUpdate()) { LoadControlSettings("Resource/UI/BuildMenu.res"); PrintAllCosts(); //it would be nice to save away the original unprinted strings for easy cost updating without reloading the .res //however, a change of zombiecosts should not happen often at all, at most once for each time you join a server DevMsg("Reloaded buildmenu\n"); }*/ //LAWYER: ZombieFlags stuff CalculateButtonState(); Activate(); SetMouseInputEnabled( true ); SetKeyBoardInputEnabled( zm_menus_use_keyboard.GetBool() ); //// get key bindings if shown if( m_iJumpKey < 0 ) // you need to lookup the jump key AFTER the engine has loaded { m_iJumpKey = gameuifuncs->GetEngineKeyCodeForBind( "jump" ); } //if ( m_iScoreBoardKey < 0 ) //{ // m_iScoreBoardKey = gameuifuncs->GetEngineKeyCodeForBind( "showscores" ); //} } else { SetVisible( false ); SetMouseInputEnabled( false ); //bring viewport back up C_HL2MP_Player *pPlayer = C_HL2MP_Player::GetLocalHL2MPPlayer(); if (pPlayer && pPlayer->IsZM()) { //prevent edge cases with roundrestarts while panel is open m_pViewPort->ShowPanel( PANEL_VIEWPORT, true ); } } //m_pViewPort->ShowBackGround( bShow ); }