void CC_CreatePlayerBall(const CCommand &args) { if (!SDKGameRules()->IsIntermissionState() || SDKGameRules()->IsCeremony()) return; CSDKPlayer *pPl = ToSDKPlayer(UTIL_GetCommandClient()); if (!CSDKPlayer::IsOnField(pPl)) return; if (pPl->GetFlags() & FL_REMOTECONTROLLED) return; trace_t tr; CTraceFilterSkipTwoEntities traceFilter(pPl, pPl->GetPlayerBall(), COLLISION_GROUP_NONE); UTIL_TraceHull( pPl->GetLocalOrigin() + VEC_VIEW, pPl->GetLocalOrigin() + VEC_VIEW + pPl->EyeDirection3D() * 150, -Vector(BALL_PHYS_RADIUS, BALL_PHYS_RADIUS, BALL_PHYS_RADIUS), Vector(BALL_PHYS_RADIUS, BALL_PHYS_RADIUS, BALL_PHYS_RADIUS), MASK_SOLID, &traceFilter, &tr); Vector pos = tr.endpos; if (pPl->GetPlayerBall()) { if (pPl->GetPlayerBall()->GetHoldingPlayer()) { //pPl->GetPlayerBall()->RemoveFromPlayerHands(pPl->GetPlayerBall()->GetHoldingPlayer()); pPl->GetPlayerBall()->State_Transition(BALL_STATE_NORMAL); } if (sv_ball_update_physics.GetBool()) pPl->GetPlayerBall()->CreateVPhysics(); pPl->GetPlayerBall()->SetPos(pos, false); pPl->GetPlayerBall()->RemoveAllTouches(); } else pPl->SetPlayerBall(CreatePlayerBall(pos, pPl)); //pPl->GetPlayerBall()->m_nSkin = pPl->GetPlayerBallSkin() == -1 ? g_IOSRand.RandomInt(0, BALL_SKIN_COUNT - 1) : pPl->GetPlayerBallSkin(); pPl->GetPlayerBall()->SetSkinName(pPl->GetPlayerBallSkinName()); pPl->GetPlayerBall()->SetBallCannonMode(false); pPl->GetPlayerBall()->SaveBallCannonSettings(); pPl->m_Shared.SetStamina(100); }
CSDKPlayer *CKeeperBot::FindClosestPlayerToBall() { float shortestDist = FLT_MAX; CSDKPlayer *pClosest = NULL; for (int i = 1; i <= gpGlobals->maxClients; i++) { CSDKPlayer *pPl = ToSDKPlayer(UTIL_PlayerByIndex(i)); if (!CSDKPlayer::IsOnField(pPl)) continue; float dist = (m_vBallPos - pPl->GetLocalOrigin()).Length2D(); if (dist < shortestDist) { shortestDist = dist; pClosest = pPl; } } return pClosest; }
void CReplayManager::TakeSnapshot() { Snapshot *pSnap = new Snapshot; pSnap->snaptime = gpGlobals->curtime; pSnap->replayCount = 0; BallSnapshot *pBallSnap = new BallSnapshot; GetMatchBall()->VPhysicsGetObject()->GetPosition(&pBallSnap->pos, &pBallSnap->ang); GetMatchBall()->VPhysicsGetObject()->GetVelocity(&pBallSnap->vel, &pBallSnap->rot); pSnap->pBallSnapshot = pBallSnap; for (int i = 0; i < 2; i++) { for (int j = 0; j < 11; j++) { pSnap->pPlayerSnapshot[i][j] = NULL; } } for (int i = 1; i <= gpGlobals->maxClients; i++) { CSDKPlayer *pPl = ToSDKPlayer(UTIL_PlayerByIndex(i)); if (!CSDKPlayer::IsOnField(pPl)) continue; PlayerSnapshot *pPlSnap = new PlayerSnapshot; pPlSnap->pos = pPl->GetLocalOrigin(); pPlSnap->vel = pPl->GetLocalVelocity(); pPlSnap->ang = pPl->GetLocalAngles(); for(int layerIndex = 0; layerIndex < NUM_LAYERS_WANTED; layerIndex++) { const CAnimationLayer *pSourceLayer = pPl->GetAnimOverlay(layerIndex); if(!pSourceLayer) continue; LayerRecord *pTargetLayer = &pPlSnap->layerRecords[layerIndex]; if(!pTargetLayer) continue; pTargetLayer->cycle = pSourceLayer->m_flCycle; pTargetLayer->order = pSourceLayer->m_nOrder; pTargetLayer->sequence = pSourceLayer->m_nSequence; pTargetLayer->weight = pSourceLayer->m_flWeight; pTargetLayer->playbackRate = pSourceLayer->m_flPlaybackRate; pTargetLayer->looping = pSourceLayer->m_bLooping; pTargetLayer->sequenceFinished = pSourceLayer->m_bSequenceFinished; pTargetLayer->flags = pSourceLayer->m_fFlags; pTargetLayer->priority = pSourceLayer->m_nPriority; pTargetLayer->activity = pSourceLayer->m_nActivity; pTargetLayer->layerAnimtime = pSourceLayer->m_flLayerAnimtime; pTargetLayer->blendIn = pSourceLayer->m_flBlendIn; pTargetLayer->blendOut = pSourceLayer->m_flBlendOut; pTargetLayer->prevCycle = pSourceLayer->m_flPrevCycle; pTargetLayer->killDelay = pSourceLayer->m_flKillDelay; pTargetLayer->killRate = pSourceLayer->m_flKillRate; pTargetLayer->lastAccess = pSourceLayer->m_flLastAccess; pTargetLayer->lastEventCheck = pSourceLayer->m_flLastEventCheck; pTargetLayer->layerFadeOuttime = pSourceLayer->m_flLayerFadeOuttime; } pPlSnap->masterSequence = pPl->GetSequence(); pPlSnap->masterCycle = pPl->GetCycle(); pPlSnap->simulationTime = pPl->GetSimulationTime(); pPlSnap->moveX = pPl->GetPoseParameter(4); pPlSnap->moveY = pPl->GetPoseParameter(3); pPlSnap->teamNumber = pPl->GetTeamNumber(); pPlSnap->teamPosIndex = pPl->GetTeamPosIndex(); pPlSnap->isKeeper = pPl->GetTeamPosType() == POS_GK; pPlSnap->shirtNumber = pPl->GetShirtNumber(); pPlSnap->skinIndex = pPl->GetSkinIndex(); pPlSnap->body = pPl->m_nBody; pPlSnap->pPlayerData = pPl->GetPlayerData(); pSnap->pPlayerSnapshot[pPl->GetTeamNumber() - TEAM_HOME][pPl->GetTeamPosIndex()] = pPlSnap; } m_Snapshots.AddToTail(pSnap); // Add the snapshot to existing highlights if their end time hasn't been reached yet for (int i = 0; i < m_MatchEvents.Count(); i++) { if (m_MatchEvents[i]->snapshotEndTime >= gpGlobals->curtime) { m_MatchEvents[i]->snapshots.AddToTail(pSnap); pSnap->replayCount += 1; } } float replayStartTime = GetReplayStartTime(); // Remove old snapshots from the list. Only free a snapshot's memory if it isn't part of any highlight. while (m_Snapshots.Count() >= 2 && m_Snapshots[0]->snaptime < replayStartTime && m_Snapshots[1]->snaptime <= replayStartTime) { if (m_Snapshots[0]->replayCount == 0) delete m_Snapshots[0]; m_Snapshots.Remove(0); } }
void CKeeperBot::BotAdjustPos() { float modifier = KEEPER_MID_COEFF; QAngle ang = m_oldcmd.viewangles; Vector target = GetTeam()->m_vGoalCenter; if (m_vBallVel.Length2D() > 750 && m_flAngToBallVel < 60) { float yDist = GetTeam()->m_vGoalCenter.GetY() - m_vBallPos.y; float vAng = acos(Sign(yDist) * m_vBallDir2D.y); float xDist = Sign(m_vBallDir2D.x) * abs(yDist) * tan(vAng); target.x = clamp(m_vBallPos.x + xDist, GetTeam()->m_vGoalCenter.GetX() - 150, GetTeam()->m_vGoalCenter.GetX() + 150); } if (m_pBall->State_Get() == BALL_STATE_KEEPERHANDS && m_pBall->GetCurrentPlayer() == this) { if (ShotButtonsReleased()) { modifier = KEEPER_CLOSE_COEFF; //m_cmd.buttons |= (IN_ATTACK2 | IN_ATTACK); m_cmd.buttons |= IN_ALT1; CSDKPlayer *pPl = FindClosestPlayerToSelf(true, true); if (!pPl && SDKGameRules()->IsIntermissionState()) pPl = FindClosestPlayerToSelf(false, true); if (pPl) { VectorAngles(pPl->GetLocalOrigin() - GetLocalOrigin(), ang); ang[PITCH] = g_IOSRand.RandomFloat(-40, 0); //m_flBotNextShot = gpGlobals->curtime + 1; } else { VectorAngles(Vector(0, GetTeam()->m_nForward, 0), ang); ang[YAW] += g_IOSRand.RandomFloat(-45, 45); ang[PITCH] = g_IOSRand.RandomFloat(-40, 0); //m_flBotNextShot = gpGlobals->curtime + 1; } } } else// if (gpGlobals->curtime >= m_flBotNextShot) { VectorAngles(m_vDirToBall, ang); float ballDistToGoal = (m_vBallPos - GetTeam()->m_vGoalCenter).Length2D(); CSDKPlayer *pClosest = FindClosestPlayerToBall(); m_cmd.buttons |= IN_ATTACK; if (ballDistToGoal < 750 && m_vDirToBall.Length2D() < 200 && m_vDirToBall.z < 200 && (m_vDirToBall.z < 80 || m_vBallVel.z <= 0)) { modifier = KEEPER_CLOSE_COEFF;// max(0.15f, 1 - ballDistToGoal / 750); VectorAngles(Vector(0, GetTeam()->m_nForward, 0), ang); bool diving = false; if (m_flAngToBallVel < 60 && m_flAngToBallVel > 15) { if (abs(m_vDirToBall.x) > 50 && abs(m_vDirToBall.x) < 200 && m_vDirToBall.z < 150 && abs(m_vDirToBall.x) < 150 && m_vBallVel.Length() > 200) { m_cmd.buttons |= IN_JUMP; m_cmd.buttons |= Sign(m_vDirToBall.x) == GetTeam()->m_nRight ? IN_MOVERIGHT : IN_MOVELEFT; //m_cmd.buttons |= (IN_ATTACK2 | IN_ATTACK); diving = true; } else if (m_vDirToBall.z > 100 && m_vDirToBall.z < 150 && m_vDirToBall.Length2D() < 100) { m_cmd.buttons |= IN_JUMP; //m_cmd.buttons |= (IN_ATTACK2 | IN_ATTACK); diving = true; } else if (abs(m_vDirToBall.y) > 50 && abs(m_vDirToBall.y) < 200 && m_vDirToBall.z < 100 && abs(m_vDirToBall.x) < 50 && m_vBallVel.Length() < 200 && pClosest != this) { m_cmd.buttons |= IN_JUMP; m_cmd.buttons |= Sign(m_vLocalDirToBall.x) == GetTeam()->m_nForward ? IN_FORWARD : IN_BACK; //m_cmd.buttons |= (IN_ATTACK2 | IN_ATTACK); diving = true; } } if (!diving) { if (m_vDirToBall.Length2D() < 50) { modifier = KEEPER_CLOSE_COEFF; //m_cmd.buttons |= (IN_ATTACK2 | IN_ATTACK); CSDKPlayer *pPl = FindClosestPlayerToSelf(true, true); if (!pPl && SDKGameRules()->IsIntermissionState()) pPl = FindClosestPlayerToSelf(false, true); if (pPl) { VectorAngles(pPl->GetLocalOrigin() - GetLocalOrigin(), ang); ang[PITCH] = g_IOSRand.RandomFloat(-40, 0); //m_flBotNextShot = gpGlobals->curtime + 1; } else { VectorAngles(Vector(0, GetTeam()->m_nForward, 0), ang); ang[YAW] += g_IOSRand.RandomFloat(-45, 45); ang[PITCH] = g_IOSRand.RandomFloat(-40, 0); //m_flBotNextShot = gpGlobals->curtime + 1; } } else modifier = KEEPER_CLOSE_COEFF; } } else if (ballDistToGoal < 1250 && m_flAngToBallVel < 60 && m_vBallVel.Length2D() > 300 && (m_vBallVel.z > 100 || m_vDirToBall.z > 100)) { modifier = KEEPER_FAR_COEFF; } else if (ballDistToGoal < 1000 && m_vDirToBall.z < 80 && m_vBallVel.Length2D() < 300 && m_vBallVel.z < 100) { if (pClosest == this) modifier = KEEPER_CLOSE_COEFF; else modifier = max(KEEPER_FAR_COEFF, 1 - pow(min(1, ballDistToGoal / 750.0f), 2)); } else { modifier = KEEPER_MID_COEFF; } m_cmd.viewangles = ang; m_LastAngles = m_cmd.viewangles; SetLocalAngles(m_cmd.viewangles); SnapEyeAngles(ang); Vector targetPosDir = target + modifier * (m_vBallPos - target) - GetLocalOrigin(); targetPosDir.z = 0; float dist = targetPosDir.Length2D(); VectorNormalizeFast(targetPosDir); Vector localDir; VectorIRotate(targetPosDir, EntityToWorldTransform(), localDir); //float speed; //if (dist < 10) // speed = 0; //else if (dist < 100) // speed = mp_runspeed.GetInt(); //else // speed = mp_sprintspeed.GetInt(); //float speed = clamp(dist - 10, 0, mp_runspeed.GetInt()); float speed = 0; if (dist > 30) speed = clamp(5 * dist, 0, mp_sprintspeed.GetInt() * (mp_botkeeperskill.GetInt() / 100.0f)); if (speed > mp_runspeed.GetInt()) m_cmd.buttons |= IN_SPEED; m_cmd.forwardmove = localDir.x * speed; m_cmd.sidemove = -localDir.y * speed; if (m_cmd.forwardmove > 0) m_cmd.buttons |= IN_FORWARD; else if (m_cmd.forwardmove < 0) m_cmd.buttons |= IN_BACK; if (m_cmd.sidemove > 0) m_cmd.buttons |= IN_RIGHT; else if (m_cmd.sidemove < 0) m_cmd.buttons |= IN_MOVELEFT; } m_cmd.viewangles = ang; }