//================================================================================================= // GLOBAL CLIENT TEAM HANDLING //================================================================================================= // Purpose: Get the C_Team for the local player //----------------------------------------------------------------------------- C_Team *GetLocalTeam( void ) { C_BasePlayer *player = C_BasePlayer::GetLocalPlayer(); if ( !player ) return NULL; return GetPlayersTeam( player->index ); }
//----------------------------------------------------------------------------- // Purpose: Get the team of the specified player //----------------------------------------------------------------------------- C_Team *GetPlayersTeam( C_BasePlayer *pPlayer ) { return GetPlayersTeam( pPlayer->entindex() ); }
//================================================================================================= // GLOBAL CLIENT TEAM HANDLING //================================================================================================= // Purpose: Get the C_Team for the local player //----------------------------------------------------------------------------- C_Team *GetLocalTeam( void ) { if ( !engine ) return NULL; return GetPlayersTeam( engine->GetPlayer() ); }
void CSDKPlayer::CheckBallShield(const Vector &oldPos, Vector &newPos, const Vector &oldVel, Vector &newVel, const QAngle &oldAng, QAngle &newAng) { bool stopPlayer = false; const float border = (GetFlags() & FL_SHIELD_KEEP_IN) ? -mp_shield_border.GetInt() : mp_shield_border.GetInt(); int forward; #ifdef CLIENT_DLL forward = GetPlayersTeam(this)->m_nForward; #else forward = GetTeam()->m_nForward; #endif if (SDKGameRules()->m_nShieldType != SHIELD_NONE) { if (SDKGameRules()->m_nShieldType == SHIELD_GOALKICK || SDKGameRules()->m_nShieldType == SHIELD_PENALTY || SDKGameRules()->m_nShieldType == SHIELD_FREEKICK || (SDKGameRules()->m_nShieldType == SHIELD_KICKOFF && !SDKGameRules()->IsIntermissionState()) || SDKGameRules()->m_nShieldType == SHIELD_CORNER) { const float radius = mp_shield_ball_radius.GetFloat(); Vector dir = newPos - SDKGameRules()->m_vShieldPos; if (dir.Length2DSqr() < pow(radius, 2)) { dir.z = 0; dir.NormalizeInPlace(); newPos = SDKGameRules()->m_vShieldPos + dir * radius; stopPlayer = true; } } if (SDKGameRules()->m_nShieldType == SHIELD_GOALKICK || SDKGameRules()->m_nShieldType == SHIELD_PENALTY || SDKGameRules()->m_nShieldType == SHIELD_KEEPERHANDS) { int side = (SDKGameRules()->m_nShieldType == SHIELD_PENALTY ? GetGlobalTeam(SDKGameRules()->m_nShieldTeam)->GetOppTeamNumber() : SDKGameRules()->m_nShieldTeam); Vector min = GetGlobalTeam(side)->m_vPenBoxMin - border; Vector max = GetGlobalTeam(side)->m_vPenBoxMax + border; if (GetFlags() & FL_SHIELD_KEEP_OUT || SDKGameRules()->m_nShieldType == SHIELD_PENALTY) { if (SDKGameRules()->m_vKickOff.GetY() > min.y) min.y -= 500; else max.y += 500; } bool isInsideBox = newPos.x > min.x && newPos.y > min.y && newPos.x < max.x && newPos.y < max.y; Vector boxCenter = (min + max) / 2; if (GetFlags() & FL_SHIELD_KEEP_OUT && isInsideBox) { bool oldPosInBox = true; if (newPos.x > min.x && oldPos.x <= min.x && newPos.x < boxCenter.x) { newPos.x = min.x; oldPosInBox = false; } else if (newPos.x < max.x && oldPos.x >= max.x && newPos.x > boxCenter.x) { newPos.x = max.x; oldPosInBox = false; } if (newPos.y > min.y && oldPos.y <= min.y && newPos.y < boxCenter.y) { newPos.y = min.y; oldPosInBox = false; } else if (newPos.y < max.y && oldPos.y >= max.y && newPos.y > boxCenter.y) { newPos.y = max.y; oldPosInBox = false; } stopPlayer = true; if (SDKGameRules()->m_nShieldType == SHIELD_KEEPERHANDS && oldPosInBox) { Vector goalCenter = GetGlobalTeam(SDKGameRules()->m_nShieldTeam)->m_vGoalCenter; goalCenter.y -= GetGlobalTeam(SDKGameRules()->m_nShieldTeam)->m_nForward * 500; if ((goalCenter - newPos).Length2DSqr() < (goalCenter - oldPos).Length2DSqr()) { newPos.x = oldPos.x; newPos.y = oldPos.y; stopPlayer = true; } else stopPlayer = false; } } else if (GetFlags() & FL_SHIELD_KEEP_IN && !isInsideBox) { if (newPos.x < min.x) newPos.x = min.x; else if (newPos.x > max.x) newPos.x = max.x; if (newPos.y < min.y) newPos.y = min.y; else if (newPos.y > max.y) newPos.y = max.y; stopPlayer = true; } } if (SDKGameRules()->m_nShieldType == SHIELD_THROWIN && GetFlags() & FL_SHIELD_KEEP_OUT || SDKGameRules()->m_nShieldType == SHIELD_FREEKICK || SDKGameRules()->m_nShieldType == SHIELD_CORNER || SDKGameRules()->m_nShieldType == SHIELD_KICKOFF || SDKGameRules()->m_nShieldType == SHIELD_PENALTY && (GetFlags() & FL_SHIELD_KEEP_OUT)) { float radius = SDKGameRules()->GetShieldRadius(GetTeamNumber(), GetFlags() & FL_SHIELD_KEEP_IN) + border; Vector dir = newPos - SDKGameRules()->m_vShieldPos; if (!SDKGameRules()->IsIntermissionState() && ((GetFlags() & FL_SHIELD_KEEP_OUT) && dir.Length2D() < radius || (GetFlags() & FL_SHIELD_KEEP_IN) && dir.Length2D() > radius)) { dir.z = 0; dir.NormalizeInPlace(); newPos = SDKGameRules()->m_vShieldPos + dir * radius; stopPlayer = true; } if (SDKGameRules()->m_nShieldType == SHIELD_KICKOFF && (GetFlags() & FL_SHIELD_KEEP_OUT) && (!SDKGameRules()->IsIntermissionState() || SDKGameRules()->State_Get() == MATCH_PERIOD_WARMUP && mp_shield_block_opponent_half.GetBool())) { int forward; #ifdef CLIENT_DLL forward = GetPlayersTeam(this)->m_nForward; #else forward = GetTeam()->m_nForward; #endif float yBorder = SDKGameRules()->m_vKickOff.GetY() - abs(border) * forward; if (ZeroSign(newPos.y - yBorder) == forward) { newPos.y = yBorder; stopPlayer = true; } } if (SDKGameRules()->m_nShieldType == SHIELD_FREEKICK && mp_shield_block_sixyardbox.GetBool()) { int teamPosType; #ifdef CLIENT_DLL teamPosType = GameResources()->GetTeamPosType(entindex()); #else teamPosType = GetTeamPosType(); #endif if (teamPosType != POS_GK || GetTeamNumber() != GetGlobalTeam(SDKGameRules()->m_nShieldTeam)->GetOppTeamNumber()) { int side = GetGlobalTeam(SDKGameRules()->m_nShieldTeam)->GetOppTeamNumber(); Vector min = GetGlobalTeam(side)->m_vSixYardBoxMin - border; Vector max = GetGlobalTeam(side)->m_vSixYardBoxMax + border; if (GetGlobalTeam(side)->m_nForward == 1) min.y -= 500; else max.y += 500; bool isInsideBox = newPos.x > min.x && newPos.y > min.y && newPos.x < max.x && newPos.y < max.y; Vector boxCenter = (min + max) / 2; if (isInsideBox) { if (newPos.x > min.x && oldPos.x <= min.x && newPos.x < boxCenter.x) newPos.x = min.x; else if (newPos.x < max.x && oldPos.x >= max.x && newPos.x > boxCenter.x) newPos.x = max.x; if (newPos.y > min.y && oldPos.y <= min.y && newPos.y < boxCenter.y) newPos.y = min.y; else if (newPos.y < max.y && oldPos.y >= max.y && newPos.y > boxCenter.y) newPos.y = max.y; stopPlayer = true; } } } } if (SDKGameRules()->m_nShieldType == SHIELD_THROWIN && GetFlags() & FL_SHIELD_KEEP_IN) { const int xLength = mp_shield_throwin_movement_x.GetInt(); const int yLength = mp_shield_throwin_movement_y.GetInt(); Vector xSign = SDKGameRules()->m_vShieldPos.GetX() > SDKGameRules()->m_vKickOff.GetX() ? 1 : -1; Vector min = SDKGameRules()->m_vShieldPos + Vector(xSign == -1 ? -xLength : 0, -yLength / 2, 0); Vector max = SDKGameRules()->m_vShieldPos + Vector(xSign == -1 ? 0 : xLength, yLength / 2, 0); bool isInsideBox = newPos.x > min.x && newPos.y > min.y && newPos.x < max.x && newPos.y < max.y; if (!isInsideBox) { if (newPos.x < min.x) newPos.x = min.x; else if (newPos.x > max.x) newPos.x = max.x; if (newPos.y < min.y) newPos.y = min.y; else if (newPos.y > max.y) newPos.y = max.y; stopPlayer = true; } } } if (!SDKGameRules()->IsIntermissionState() && mp_field_padding_enabled.GetBool()) { float border = mp_field_padding.GetInt(); Vector min = SDKGameRules()->m_vFieldMin - border; Vector max = SDKGameRules()->m_vFieldMax + border; if (newPos.x < min.x || newPos.y < min.y || newPos.x > max.x || newPos.y > max.y) { if (newPos.x < min.x) newPos.x = min.x; else if (newPos.x > max.x) newPos.x = max.x; if (newPos.y < min.y) newPos.y = min.y; else if (newPos.y > max.y) newPos.y = max.y; stopPlayer = true; } } if (stopPlayer) { //newVel = oldVel; trace_t trace; UTIL_TraceHull(newPos, newPos, GetPlayerMins(), GetPlayerMaxs(), MASK_PLAYERSOLID, this, COLLISION_GROUP_PLAYER, &trace); if (trace.startsolid) { // Stay at the old pos since the new pos is taken newPos = oldPos; } Vector dir = newPos - oldPos; dir.z = 0; float speed = dir.NormalizeInPlace(); newVel = dir * min(speed * 100, mp_runspeed.GetInt()); //newVel.x = (newPos - oldPos).x * 100; //newVel.y = (newPos - oldPos).y * 100; //newPos = pos; } }