diff --git a/GravityStomp/Content/Core/BP_GSDefaultGameMode.uasset b/GravityStomp/Content/Core/BP_GSDefaultGameMode.uasset index c9251e6..a3471cf 100644 --- a/GravityStomp/Content/Core/BP_GSDefaultGameMode.uasset +++ b/GravityStomp/Content/Core/BP_GSDefaultGameMode.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ffffdea16c899e1fc46add4fc5bd8a2ed1afbd22b95550f025d87561c75b9a14 -size 56466 +oid sha256:6b335fa1dc56a0cae495e5340c5e4b751437b7370cfbb165c405444a86d2bebd +size 55782 diff --git a/GravityStomp/Source/GravityStompGame/GameModes/GSGameModeBase.cpp b/GravityStomp/Source/GravityStompGame/GameModes/GSGameModeBase.cpp index 765b73b..6bd0b71 100644 --- a/GravityStomp/Source/GravityStompGame/GameModes/GSGameModeBase.cpp +++ b/GravityStomp/Source/GravityStompGame/GameModes/GSGameModeBase.cpp @@ -90,7 +90,7 @@ void AGSGameModeBase::RestartPlayer(AController* NewPlayer) // inform player controller that game has started using client RPC AGSPlayerController* PC = Cast(NewPlayer); - if(PC) + if(PC && IsMatchInProgress()) { PC->Client_GameStarted(); } @@ -113,37 +113,6 @@ bool AGSGameModeBase::CanDamagePlayer(AGSPlayerController* Damager, AGSPlayerCon void AGSGameModeBase::PickTeam(AGSPlayerState* PlayerState) { - /* - // place player on the team with the fewest players, or on the first team if all teams have the same number of players - TArray NumTeamPlayers; - AGSGameState* GS = GetGameState(); - NumTeamPlayers.AddZeroed(GS->GetNumTeams()); - - check(NumTeamPlayers.Num() > 0); - - for(int32 PlayerIdx = 0; PlayerIdx < GS->PlayerArray.Num(); ++PlayerIdx) - { - AGSPlayerState* CurrPS = Cast(GS->PlayerArray[PlayerIdx]); - if(CurrPS && CurrPS->GetTeamNum() >= 0 && CurrPS->GetTeamNum() < NumTeamPlayers.Num()) - { - NumTeamPlayers[CurrPS->GetTeamNum()]++; - } - else - { - UE_LOG(LogTemp, Error, TEXT("Player %s is on team number %d but only %d teams exist"), *CurrPS->GetPlayerName(), CurrPS->GetTeamNum(), NumTeamPlayers.Num()) - } - } - - int32 LowestTeamIdx = 0; - for(int32 TeamIdx = 0; TeamIdx < NumTeamPlayers.Num(); TeamIdx++) - { - if(NumTeamPlayers[TeamIdx] < NumTeamPlayers[LowestTeamIdx]) - { - LowestTeamIdx = TeamIdx; - } - } - */ - PlayerState->SetTeamNum(PlayerState->GetPlayerController()->GetLocalPlayer()->GetControllerId()); } @@ -245,6 +214,28 @@ void AGSGameModeBase::FinishMatch() } } +void AGSGameModeBase::HandleStartingNewPlayer_Implementation(APlayerController* NewPlayer) +{ + // If players should start as spectators, leave them in the spectator state + if (!bStartPlayersAsSpectators && !MustSpectate(NewPlayer)) + { + // If match is in progress, start the player + if ((GetMatchState() == MatchState::WaitingToStart || IsMatchInProgress()) && PlayerCanRestart(NewPlayer)) + { + RestartPlayer(NewPlayer); + } + // Check to see if we should start right away, avoids a one frame lag in single player games + else if (GetMatchState() == MatchState::WaitingToStart) + { + // Check to see if we should start the match + if (ReadyToStartMatch()) + { + StartMatch(); + } + } + } +} + void AGSGameModeBase::HandleMatchIsWaitingToStart() { @@ -266,6 +257,7 @@ void AGSGameModeBase::HandleMatchIsWaitingToStart() AGSPlayerController* PC = Cast(*It); if(PC) { + RestartPlayer(PC); PC->Client_WarmupStarted(); } } diff --git a/GravityStomp/Source/GravityStompGame/GameModes/GSGameModeBase.h b/GravityStomp/Source/GravityStompGame/GameModes/GSGameModeBase.h index 6f3318e..5448c06 100644 --- a/GravityStomp/Source/GravityStompGame/GameModes/GSGameModeBase.h +++ b/GravityStomp/Source/GravityStompGame/GameModes/GSGameModeBase.h @@ -80,6 +80,8 @@ public: */ void FinishMatch(); + virtual void HandleStartingNewPlayer_Implementation(APlayerController* NewPlayer) override; + /** * Sets up match warmup timer */ diff --git a/GravityStomp/Source/GravityStompGame/Player/GSPlayerController.cpp b/GravityStomp/Source/GravityStompGame/Player/GSPlayerController.cpp index 1bf9a76..1e5f0a3 100644 --- a/GravityStomp/Source/GravityStompGame/Player/GSPlayerController.cpp +++ b/GravityStomp/Source/GravityStompGame/Player/GSPlayerController.cpp @@ -30,6 +30,9 @@ void AGSPlayerController::Client_OnDeath_Implementation(AGSPlayerState* KillerPl void AGSPlayerController::Client_WarmupStarted_Implementation() { + // wait for server to tell us we can move + SetIgnoreMoveInput(true); + OnWarmupStarted(); }