Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Line of Sight (Visibility) system #87

Merged
merged 22 commits into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
dd96cd2
Initial work on hiding tile contents
jonpas Nov 26, 2017
62675d8
Merge branch 'master' into lineOfSight
jonpas Dec 31, 2017
93a8bad
Merge branch 'master' into lineOfSight
jonpas Jan 1, 2018
1699e32
Add Obstacle class, Add SensorRange property to Ship
jonpas Jan 1, 2018
d9a45f0
Merge branch 'master' into lineOfSight
jonpas Jan 3, 2018
72023f3
Merge branch 'master' into lineOfSight
jonpas Jan 3, 2018
6419df7
Merge branch 'master' into lineOfSight
jonpas Jan 15, 2018
be2afb7
Add tiled distance and restrict actions based on maximum distance the…
jonpas Jan 15, 2018
43cb628
Use Vector2D for Tile reference in Actions
jonpas Jan 15, 2018
3a0ed2f
Make direct Getters in GameModeBase in-line const
jonpas Jan 15, 2018
1d90c31
Set board visibility based on ship ranges, Hook actions into changing…
jonpas Jan 15, 2018
9f07837
Block clicking on not visible enemy ships
jonpas Jan 15, 2018
53f680c
Hide enemy ships from ship list, Remove fill on ship list initializat…
jonpas Jan 16, 2018
888e0cc
Allow firing (Laser and Torpedo) through fog, apply damage without lo…
jonpas Jan 16, 2018
409c99b
Increase map size to 50x50, Set all actions to end turn (at least for…
jonpas Jan 16, 2018
135e10f
Add debug toggles for ignoring visibility and showing enemy visibilit…
jonpas Jan 16, 2018
441b7f4
Resize Base grid tile to have 1px border (instead of 2px), Change Hid…
jonpas Jan 16, 2018
3306fc8
Update Game Mode Board with new properties
jonpas Jan 16, 2018
42c3f66
Determine if weapon effect should log internally
jonpas Jan 16, 2018
9348b98
Revert resaved-only Board map
jonpas Jan 17, 2018
957d6c4
Merge branch 'master' into lineOfSight
jonpas Jan 17, 2018
371eb37
Add GetVisibleShips() function, Rename GetVisibleTiles() to UpdateVis…
jonpas Jan 17, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file modified Content/EmptierThanVoid/Art/Board/T_Grid_Simple_A.uasset
Binary file not shown.
Binary file modified Content/EmptierThanVoid/Core/BP_GameMode_Board.uasset
Binary file not shown.
Binary file modified Content/EmptierThanVoid/UI/HUD/WBP_GameUI_ShipStatus.uasset
Binary file not shown.
9 changes: 6 additions & 3 deletions Source/ETV/ETVAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ETVAction.h"
#include "ETVGameModeBase.h" // Not in .h due to circular dependency
#include "ETVShipStatusUIWidget.h"
#include "ETVShip.h"

// Sets default values
UETVAction::UETVAction() : Super()
Expand All @@ -19,8 +20,8 @@ UETVAction::UETVAction() : Super()
// Available
Available = EETVActionAvailability::ActionAvailable;

// Does not end turn
bEndsTurn = false;
// Ends turn after use
bEndsTurn = true;

// Takes at most one turn to complete
MaxPerforms = 1;
Expand Down Expand Up @@ -108,9 +109,11 @@ void UETVAction::OnBeginPerform()

void UETVAction::OnEndPerform()
{
AETVGameModeBase* GameMode = Cast<AETVGameModeBase>(GetWorld()->GetAuthGameMode());
GameMode->UpdateVisibleTiles(EETVShipType::PlayerShip);

if (bEndsTurn)
{
AETVGameModeBase* GameMode = Cast<AETVGameModeBase>(GetWorld()->GetAuthGameMode());
// TODO Delay this until all effects are done
GameMode->EndTurn();
}
Expand Down
4 changes: 2 additions & 2 deletions Source/ETV/ETVAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ class ETV_API UETVAction : public UObject
virtual bool Perform();

UFUNCTION()
virtual void OnBeginPerform();
void OnBeginPerform();

UFUNCTION()
virtual void OnEndPerform();
void OnEndPerform();

UFUNCTION()
virtual void ApplyEffectsSelf() {}
Expand Down
30 changes: 17 additions & 13 deletions Source/ETV/ETVActionTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ UETVActionTarget::UETVActionTarget() : Super()
FailureChance = 0.0f;

SelectedTarget = nullptr;
TileX = -1;
TileY = -1;
Tile = FVector2D(-1, -1);
}

void UETVActionTarget::Init(AETVShip* OwnerShipPtr, AETVWeapon* OwnerWeaponPtr)
Expand All @@ -28,20 +27,13 @@ void UETVActionTarget::Init(AETVShip* OwnerShipPtr, AETVWeapon* OwnerWeaponPtr)
void UETVActionTarget::SetTarget(AActor* Target, int32 X, int32 Y)
{
SelectedTarget = Target;
TileX = X;
TileY = Y;
Tile = FVector2D(X, Y);
}

bool UETVActionTarget::IsTargetValid()
{
// Are required variables set
if (SelectedTarget == nullptr || RequiredTargetType == nullptr)
{
return false;
}

// Is correct type
return SelectedTarget->IsA(RequiredTargetType);
// Are required variables set and is correct type
return SelectedTarget != nullptr && RequiredTargetType != nullptr && SelectedTarget->IsA(RequiredTargetType);
}

bool UETVActionTarget::CanActivate()
Expand All @@ -51,7 +43,19 @@ bool UETVActionTarget::CanActivate()

bool UETVActionTarget::CanPerform()
{
return Super::CanPerform() && IsTargetValid();
if (Super::CanPerform() && IsTargetValid())
{
if (OwnerWeapon != nullptr && Tile.X != -1 && Tile.Y != -1) {
AETVGameModeBase* GameMode = Cast<AETVGameModeBase>(GetWorld()->GetAuthGameMode());
float Distance = GameMode->GetTiledDistance(OwnerShip->GetTilePosition(), Tile);

return Distance <= OwnerWeapon->GetFiringRange();
}

return true;
}

return false;
}

bool UETVActionTarget::Activate()
Expand Down
10 changes: 3 additions & 7 deletions Source/ETV/ETVActionTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ class ETV_API UETVActionTarget : public UETVAction
UPROPERTY(BlueprintReadOnly, Category = "ETV Action|Target")
AActor* SelectedTarget;

// Currently selected tile map X coordinate (-1 if unset)
// Currently selected tile map coordinate ((-1, -1) if unset)
UPROPERTY(BlueprintReadOnly, Category = "ETV Action|Target")
int32 TileX;

// Currently selected tile map Y coordinate (-1 if unset)
UPROPERTY(BlueprintReadOnly, Category = "ETV Action|Target")
int32 TileY;
FVector2D Tile;

// Required type of target
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ETV Action|Target")
Expand All @@ -53,5 +49,5 @@ class ETV_API UETVActionTarget : public UETVAction
bool CanPerform() override;
bool Activate() override;
bool Perform() override;
void OnEndPerform() override;
void OnEndPerform(); // Hides UETVAction member function on purpose
};
50 changes: 48 additions & 2 deletions Source/ETV/ETVActionTarget_Fire.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (C) Team13. All rights reserved.

#include "ETVActionTarget_Fire.h"
#include "ETVGameModeBase.h"
#include "ETVCalculator.h"
#include "PaperTileMapActor.h"

// Sets default values
UETVActionTarget_Fire::UETVActionTarget_Fire() : Super()
Expand All @@ -12,6 +14,31 @@ UETVActionTarget_Fire::UETVActionTarget_Fire() : Super()
RequiredTargetType = AETVShip::StaticClass();
}

bool UETVActionTarget_Fire::IsTargetValid()
{
if (Super::IsTargetValid())
{
return true;
}

// Are required variables set (repeated check from parent due to special condition)
if (SelectedTarget != nullptr && RequiredTargetType != nullptr)
{
// Is target a valid tile
if (SelectedTarget->IsA(APaperTileMapActor::StaticClass()) && Tile.X != -1 && Tile.Y != -1)
{
// Is tile not visible (fog is accessible no matter the content)
AETVGameModeBase* GameMode = Cast<AETVGameModeBase>(GetWorld()->GetAuthGameMode());
if (!GameMode->IsTileVisible(Tile, OwnerShip->GetType()))
{
return true;
}
}
}

return false;
}

bool UETVActionTarget_Fire::CanActivate()
{
// Check if a weapon is set
Expand All @@ -22,6 +49,12 @@ bool UETVActionTarget_Fire::CanPerform()
{
if (Super::CanPerform())
{
// Check if fog
if (SelectedTarget->IsA(APaperTileMapActor::StaticClass()))
{
return true;
}

// Check if enemy
AETVShip* SelectedShip = Cast<AETVShip>(SelectedTarget); // Required type is ship (checked in parent) so casting is safe
return SelectedShip->IsEnemy();
Expand All @@ -36,8 +69,21 @@ void UETVActionTarget_Fire::ApplyEffectsTarget()

// TODO Show explosion animation

AETVShip* SelectedShip = Cast<AETVShip>(SelectedTarget); // Required type is ship (checked in parent) so casting is safe
UETVCalculator::CalculateWeaponEffect(OwnerShip, OwnerWeapon, SelectedShip);
AETVShip* SelectedShip = nullptr;
if (!SelectedTarget->IsA(APaperTileMapActor::StaticClass()))
{
AETVGameModeBase* GameMode = Cast<AETVGameModeBase>(GetWorld()->GetAuthGameMode());
SelectedShip = GameMode->GetShipActor(Tile.X, Tile.Y);
}
else
{
SelectedShip = Cast<AETVShip>(SelectedTarget); // Required type is ship (checked in parent) so casting is safe
}

if (SelectedShip != nullptr)
{
UETVCalculator::CalculateWeaponEffect(OwnerShip, OwnerWeapon, SelectedShip);
}
}

void UETVActionTarget_Fire::ApplyEffectsSelf()
Expand Down
2 changes: 2 additions & 0 deletions Source/ETV/ETVActionTarget_Fire.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class ETV_API UETVActionTarget_Fire : public UETVActionTarget
UETVActionTarget_Fire();

public:
bool IsTargetValid() override;

bool CanActivate() override;
bool CanPerform() override;

Expand Down
14 changes: 11 additions & 3 deletions Source/ETV/ETVActionTarget_Move.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (C) Team13. All rights reserved.

#include "ETVActionTarget_Move.h"
#include "ETVGameModeBase.h"
#include "ETVShip.h"
#include "PaperTileMapActor.h"

Expand All @@ -20,8 +21,15 @@ bool UETVActionTarget_Move::CanActivate()

bool UETVActionTarget_Move::CanPerform()
{
// TODO Check distance (Ship's MoveRange vs distance)
return Super::CanPerform() && TileX != -1 && TileY != -1;
if (Super::CanPerform() && Tile.X != -1 && Tile.Y != -1)
{
AETVGameModeBase* GameMode = Cast<AETVGameModeBase>(GetWorld()->GetAuthGameMode());
float Distance = GameMode->GetTiledDistance(OwnerShip->GetTilePosition(), Tile);

return Distance <= OwnerShip->GetMoveRange();
}

return false;
}

void UETVActionTarget_Move::ApplyEffectsSelf()
Expand All @@ -33,6 +41,6 @@ void UETVActionTarget_Move::ApplyEffectsSelf()
// TODO Do animation

// Move ship
OwnerShip->MoveToTile(TileX, TileY);
OwnerShip->MoveToTile(Tile.X, Tile.Y);
}
}
34 changes: 19 additions & 15 deletions Source/ETV/ETVCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,27 @@ void UETVCalculator::CalculateWeaponEffect(AETVShip *User, AETVWeapon *WeaponUse
UE_LOG(LogTemp, Warning, TEXT("%s"), *Msg2);
/**/

// Add new Message to UETVActionLogWidget by calling event NewLogEntry
// Log if target visible
AETVGameModeBase* GameMode = Cast<AETVGameModeBase>(User->GetWorld()->GetAuthGameMode());
UETVActionLogWidget *LogWidget = GameMode->GetLogWidget();
if (ActionHP != "") {
FString ShipName = User->GetShipName();
FString ChangeValueS = FString::FromInt(ChangeValue);
FString TargetName = Target->GetShipName();
if (GameMode->IsTileVisible(Target->GetTilePosition()))
{
// Add new Message to UETVActionLogWidget by calling event NewLogEntry
UETVActionLogWidget *LogWidget = GameMode->GetLogWidget();
if (ActionHP != "") {
FString ShipName = User->GetShipName();
FString ChangeValueS = FString::FromInt(ChangeValue);
FString TargetName = Target->GetShipName();

FString Message = ShipName + ";" + ActionHP + ";" + ChangeValueS + ";" + TargetName;
LogWidget->NewLogEntry(Message);
}
if (ActionShields != "") {
FString ShipName = User->GetShipName();
FString ChangeValueS = FString::FromInt(ChangeValue);
FString TargetName = Target->GetShipName();
FString Message = ShipName + ";" + ActionHP + ";" + ChangeValueS + ";" + TargetName;
LogWidget->NewLogEntry(Message);
}
if (ActionShields != "") {
FString ShipName = User->GetShipName();
FString ChangeValueS = FString::FromInt(ChangeValue);
FString TargetName = Target->GetShipName();

FString Message = ShipName + ";" + ActionShields + ";" + ChangeValueS + ";" + TargetName;
LogWidget->NewLogEntry(Message);
FString Message = ShipName + ";" + ActionShields + ";" + ChangeValueS + ";" + TargetName;
LogWidget->NewLogEntry(Message);
}
}
}
3 changes: 2 additions & 1 deletion Source/ETV/ETVCalculator.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) Team13. All rights reserved.
// Copyright (C) Team13. All rights reserved.

#pragma once

Expand All @@ -19,6 +19,7 @@ class ETV_API UETVCalculator : public UObject


public:
// Calculates weapon effect, applies it to involved ships/weapons and logs to Combat Log
UFUNCTION(BlueprintCallable)
static void CalculateWeaponEffect(AETVShip *Atacker, AETVWeapon *WeaponUsed, AETVShip *Target);

Expand Down
Loading