Skip to content
This repository has been archived by the owner on Aug 1, 2021. It is now read-only.

Commit

Permalink
Exposed most of the Gamemode events to blueprint. Blueprints can now …
Browse files Browse the repository at this point in the history
…control the entire game flow of a game mode. This will be useful for community work on creating Empires game modes as well as mods.
  • Loading branch information
RoyAwesome committed Mar 3, 2015
1 parent 156e413 commit 6b9a7d7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 17 deletions.
49 changes: 34 additions & 15 deletions Source/Empires2/Private/GameMode/Empires2GameMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ AEmpires2GameMode::AEmpires2GameMode(const class FObjectInitializer & ObjectInit

void AEmpires2GameMode::InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage)
{
BPInitGame(MapName, Options, ErrorMessage);
Super::InitGame(MapName, Options, ErrorMessage);
}

Expand All @@ -47,14 +48,20 @@ void AEmpires2GameMode::PostLogin(APlayerController* NewPlayer)
{
Super::PostLogin(NewPlayer);

BPPostLogin(NewPlayer);

//TODO: Get a spawn point for the player
}

AActor* AEmpires2GameMode::ChoosePlayerStart(AController* Player)
{
return Super::ChoosePlayerStart(Player);
AActor* Spawn = BPChoosePlayerStart(Player);
if (Spawn == nullptr)
{
Spawn = Super::ChoosePlayerStart(Player);
}

//Get the spawn point that this player requested.
return Spawn;
}

void AEmpires2GameMode::SetFriendlyFire(bool ShouldFriendlyfire)
Expand All @@ -75,21 +82,26 @@ UClass* AEmpires2GameMode::GetDefaultPawnClassForController(AController* InContr
}

float AEmpires2GameMode::ModifyDamage(float Damage, AActor* DamagedActor, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) const
{
return Damage;
{
//Determine if these two people can deal damage to eachother. If they can't, change damage to 0 then pass it to Blueprint to modify.
if (!CanDealDamage(EventInstigator, DamagedActor->GetInstigatorController()))
{
Damage = 0;
}


//TODO: Determine if the people are on the same team. If they are, Prevent that damage. If not allow it
Damage = BPModifyDamage(Damage, DamagedActor, DamageEvent, EventInstigator, DamageCauser);
return Damage;
}

void AEmpires2GameMode::Killed(AController* Killer, AController* KilledPlayer, APawn* KilledPawn, const UDamageType* DamageType)
{

BPKilled(Killer, KilledPlayer, KilledPawn, DamageType);
}

bool AEmpires2GameMode::CanDealDamage(class AEmpiresPlayerState* DamageInstigator, class AEmpiresPlayerState* DamagedPlayer) const
{
//TODO: Friendly Fire?
return true;
bool AEmpires2GameMode::CanDealDamage(AController* DamageInstigator, AController* DamagedPlayer) const
{
return true || BPCanDealDamage(DamageInstigator, DamagedPlayer);
}

bool AEmpires2GameMode::AllowCheats(APlayerController* P)
Expand All @@ -114,17 +126,20 @@ void AEmpires2GameMode::DefaultTimer()

void AEmpires2GameMode::HandleMatchIsWaitingToStart()
{

Super::HandleMatchIsWaitingToStart();
BPHandleMatchIsWaitingToStart();
}

void AEmpires2GameMode::HandleMatchHasStarted()
{
Super::HandleMatchHasStarted();
BPHandleMatchHasStarted();
}

void AEmpires2GameMode::RestartGame()
{
Super::RestartGame();
BPRestartGame();
}

TSubclassOf<AGameSession> AEmpires2GameMode::GetGameSessionClass() const
Expand All @@ -138,6 +153,11 @@ void AEmpires2GameMode::FinishMatch()
}

void AEmpires2GameMode::RespawnPlayer(AEmpiresPlayerController* Controller)
{
BPRespawnPlayer(Controller);
}

void AEmpires2GameMode::BPRespawnPlayer_Implementation(AEmpiresPlayerController* Controller)
{
//Remove the player's original pawn
AEmpires2Character* PlayerCharacter = Cast<AEmpires2Character>(Controller->GetPawn());
Expand All @@ -146,14 +166,13 @@ void AEmpires2GameMode::RespawnPlayer(AEmpiresPlayerController* Controller)


//Create a new pawn for the player
AEmpiresPlayerStart* StartSpot = Controller->WantedSpawn;
AActor* StartSpot = ChoosePlayerStart(Controller);
if (StartSpot == nullptr)
{
StartSpot = Cast<AEmpiresPlayerStart>(ChoosePlayerStart(Controller));
if (StartSpot == nullptr) UE_LOG(EmpiresGameplay, Warning, TEXT("Can't find a spawn for player"));
UE_LOG(EmpiresGameplay, Warning, TEXT("Can't find a spawn for player"));
}

APawn* Pawn = this->SpawnDefaultPawnFor(Controller, (AActor*) StartSpot);
APawn* Pawn = this->SpawnDefaultPawnFor(Controller, StartSpot);

Controller->Possess(Pawn);
Controller->NotifyCharacterSpawned();
Expand Down
41 changes: 39 additions & 2 deletions Source/Empires2/Public/GameMode/Empires2GameMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,27 @@ class AEmpires2GameMode : public AGameMode


/** Initialize the game. This is called before actors' PreInitializeComponents. */

virtual void InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage) override;

UFUNCTION(BlueprintImplementableEvent, Category = "Game Mode", meta=(FriendlyName = "Init Game"))
void BPInitGame(const FString& MapName, const FString& Options, FString& ErrorMessage);

/** Accept or reject a player attempting to join the server. Fails login if you set the ErrorMessage to a non-empty string. */
virtual void PreLogin(const FString& Options, const FString& Address, const TSharedPtr<class FUniqueNetId>& UniqueId, FString& ErrorMessage) override;

/** starts match warmup */
/** starts match warmup */
virtual void PostLogin(APlayerController* NewPlayer) override;
UFUNCTION(BlueprintImplementableEvent, Category = "Game Mode", meta = (FriendlyName = "Post Login"))
void BPPostLogin(APlayerController* NewPlayer);

/** select best spawn point for player */
virtual AActor* ChoosePlayerStart(AController* Player) override;

UFUNCTION(BlueprintImplementableEvent, Category = "Game Mode", meta = (FriendlyName = "Choose Player Start"))
AActor* BPChoosePlayerStart(AController* Player);


/** always pick new random spawn */
virtual bool ShouldSpawnAtStartSpot(AController* Player) override;

Expand All @@ -51,11 +61,23 @@ class AEmpires2GameMode : public AGameMode
/** prevents friendly fire */
virtual float ModifyDamage(float Damage, AActor* DamagedActor, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) const;

UFUNCTION(BlueprintImplementableEvent, Category = "Game Mode", meta = (FriendlyName = "Modify Damage"))
float BPModifyDamage(float Damage, AActor* DamagedActor, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) const;



/** notify about kills */
virtual void Killed(AController* Killer, AController* KilledPlayer, APawn* KilledPawn, const UDamageType* DamageType);

UFUNCTION(BlueprintImplementableEvent, Category = "Game Mode", meta = (FriendlyName = "Killed"))
void BPKilled(AController* Killer, AController* KilledPlayer, APawn* KilledPawn, const UDamageType* DamageType);

/** can players damage each other? */
virtual bool CanDealDamage(class AEmpiresPlayerState* DamageInstigator, class AEmpiresPlayerState* DamagedPlayer) const;
virtual bool CanDealDamage(class AController* DamageInstigator, class AController* DamagedPlayer) const;

UFUNCTION(BlueprintImplementableEvent, Category = "Game Mode", meta = (FriendlyName = "Can Deal Damage"))
bool BPCanDealDamage(class AController* DamageInstigator, class AController* DamagedPlayer) const;


/** always create cheat manager */
virtual bool AllowCheats(APlayerController* P) override;
Expand All @@ -66,15 +88,30 @@ class AEmpires2GameMode : public AGameMode
/** called before startmatch */
virtual void HandleMatchIsWaitingToStart() override;

UFUNCTION(BlueprintImplementableEvent, Category = "Game Mode", meta = (FriendlyName = "Match is Waiting to Start"))
void BPHandleMatchIsWaitingToStart();


/** starts new match */
virtual void HandleMatchHasStarted() override;

UFUNCTION(BlueprintImplementableEvent, Category = "Game Mode", meta = (FriendlyName = "Match Start"))
void BPHandleMatchHasStarted();

/** hides the onscreen hud and restarts the map */
virtual void RestartGame() override;

UFUNCTION(BlueprintImplementableEvent, Category = "Game Mode", meta = (FriendlyName = "Restart match"))
void BPRestartGame();

/* */

virtual void RespawnPlayer(class AEmpiresPlayerController* Controller);

UFUNCTION(BlueprintNativeEvent, Category = "Game Mode", meta = (FriendlyName = "Restart match"))
void BPRespawnPlayer(AEmpiresPlayerController* Controller);
void BPRespawnPlayer_Implementation(AEmpiresPlayerController* Controller);

protected:

/** score for kill */
Expand Down

0 comments on commit 6b9a7d7

Please sign in to comment.