funny-prince/Source/FunnyPrince/FunnyPrinceGameMode.cpp

47 lines
988 B
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "FunnyPrinceGameMode.h"
#include "UObject/ConstructorHelpers.h"
#include "EngineUtils.h"
#include "FighterAIController.h"
AFunnyPrinceGameMode::AFunnyPrinceGameMode()
{
}
void AFunnyPrinceGameMode::PawnKilled(APawn* PawnKilled)
{
if (!PawnKilled)
{
return;
}
APlayerController* PlayerController = Cast<APlayerController>(PawnKilled->GetController());
if (PlayerController)
{
PlayerController->GameHasEnded(nullptr, false);
}
// Check for win condition
for (AFighterAIController* Controller : TActorRange<AFighterAIController>(GetWorld()))
{
if (!Controller->IsDead())
{
return;
}
}
// All AI is dead, game is won
EndGame(true);
}
void AFunnyPrinceGameMode::EndGame(bool bIsPlayerWinner)
{
for (AController* Controller : TActorRange<AController>(GetWorld()))
{
bool bWon = (bIsPlayerWinner == Controller->IsPlayerController());
Controller->GameHasEnded(Controller->GetPawn(), bWon);
}
}