finalization

This commit is contained in:
Oleg Petruny 2024-11-22 19:47:34 +01:00
parent 6da4620dc5
commit 8c01cab7c8
14 changed files with 134 additions and 28 deletions

View File

@ -139,7 +139,8 @@ ManualIPAddress=
+Profiles=(Name="Vehicle",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Vehicle",CustomResponses=,HelpMessage="Vehicle object that blocks Vehicle, WorldStatic, and WorldDynamic. All other channels will be set to default.")
+Profiles=(Name="UI",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility"),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ")
+Profiles=(Name="Interactable",CollisionEnabled=QueryAndPhysics,bCanModify=True,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Interactable")),HelpMessage="WorldDynamic objects derived from AInteractable.")
+Profiles=(Name="AgeOfWarUnit",CollisionEnabled=QueryOnly,bCanModify=True,ObjectTypeName="Vehicle",CustomResponses=((Channel="WorldStatic",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore)),HelpMessage="Minigame object")
+Profiles=(Name="AgeOfWarUnitPlayer",CollisionEnabled=QueryOnly,bCanModify=True,ObjectTypeName="Vehicle",CustomResponses=((Channel="WorldStatic",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Interactable")),HelpMessage="Minigame object")
+Profiles=(Name="AgeOfWarUnitComputer",CollisionEnabled=QueryOnly,bCanModify=True,ObjectTypeName="Destructible",CustomResponses=((Channel="WorldStatic",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore),(Channel="Interactable")),HelpMessage="Minigame object")
+DefaultChannelResponses=(Channel=ECC_GameTraceChannel1,DefaultResponse=ECR_Ignore,bTraceType=True,bStaticObject=False,Name="Interactable")
-ProfileRedirects=(OldName="BlockingVolume",NewName="InvisibleWall")
-ProfileRedirects=(OldName="InterpActor",NewName="IgnoreOnlyPawn")
@ -151,6 +152,9 @@ ManualIPAddress=
+ProfileRedirects=(OldName="StaticMeshComponent",NewName="BlockAllDynamic")
+ProfileRedirects=(OldName="SkeletalMeshActor",NewName="PhysicsActor")
+ProfileRedirects=(OldName="InvisibleActor",NewName="InvisibleWallDynamic")
+ProfileRedirects=(OldName="AgeOfWarUnitComputer",NewName="AgeOfWarUnitPlayerZone")
+ProfileRedirects=(OldName="AgeOfWarUnit",NewName="AgeOfWarUnitPlayer")
+ProfileRedirects=(OldName="AgeOfWarUnitPlayerZone",NewName="AgeOfWarUnitComputer")
-CollisionChannelRedirects=(OldName="Static",NewName="WorldStatic")
-CollisionChannelRedirects=(OldName="Dynamic",NewName="WorldDynamic")
-CollisionChannelRedirects=(OldName="VehicleMovement",NewName="Vehicle")

Binary file not shown.

View File

@ -39,6 +39,18 @@ void UCommonFunctions::DestroyActorRecursively(AActor* actor)
actor->Destroy();
}
TArray<int32> UCommonFunctions::GetRandomIntArray(int32 size, int32 min, int32 max)
{
if(size <= 0)
return {};
TArray<int32> arr;
arr.Reserve(size);
for(int32 i = 0; i < size; ++i)
arr.Add(FMath::RandRange(min, max));
return arr;
}
ALevelBase* UCommonFunctions::GetCurrentLevelScript(UObject* obj)

View File

@ -21,6 +21,8 @@ public:
UFUNCTION(BlueprintCallable, Category = Actor)
static void DestroyActorRecursively(class AActor* actor);
UFUNCTION(BlueprintPure)
static TArray<int32> GetRandomIntArray(int32 size = 16, int32 min = 0, int32 max = 16);
UFUNCTION(BlueprintCallable, Category = Level)

View File

@ -15,6 +15,11 @@ TMap<UClass*, FAgeOfWarUnitStats> AAgeOfWarManager::unitStats = {};
const FAgeOfWarUnitStats& AAgeOfWarManager::UnitGetStats(TSubclassOf<AAgeOfWarUnit> unitClass)
{
check(unitStats.Contains(*unitClass));
//if(!unitStats.Contains(*unitClass))
//{
// static FAgeOfWarUnitStats empty;
// return empty;
//}
return unitStats[unitClass];
}
@ -52,6 +57,10 @@ void AAgeOfWarManager::Start(APlayerBase* playerPawn, FMinigameEndCallback deleg
void AAgeOfWarManager::End()
{
for(auto& unit : spawnedUnits)
unit->Destroy();
spawnedUnits.Empty();
unitStats.Empty();
player->ReturnPlayerView();
@ -60,6 +69,12 @@ void AAgeOfWarManager::End()
AMinigame::End();
}
void AAgeOfWarManager::UnitKill(AAgeOfWarUnit* unit)
{
OnUnitKill(unit);
spawnedUnits.Remove(unit);
}
void AAgeOfWarManager::AddUnitStats(TSubclassOf<AAgeOfWarUnit> unitClass, FAgeOfWarUnitStats stats)
{
unitStats.Add(unitClass, stats);
@ -77,4 +92,6 @@ void AAgeOfWarManager::SpawnUnit(TSubclassOf<AAgeOfWarUnit> unitClass, FTransfor
auto unit = GetWorld()->SpawnActor<AAgeOfWarUnit>(*unitClass, transform, spawnParams);
unit->team = computer ? UnitTeam::AI : UnitTeam::Player;
unit->manager = this;
unit->UpdateStats();
spawnedUnits.Add(unit);
}

View File

@ -19,6 +19,7 @@ public:
virtual void Start(class APlayerBase* playerPawn, FMinigameEndCallback delegate) override;
virtual void End() override;
void UnitKill(class AAgeOfWarUnit* unit);
UFUNCTION(BlueprintImplementableEvent)
void OnUnitKill(class AAgeOfWarUnit* unit);
@ -38,4 +39,5 @@ protected:
UPROPERTY(EditAnywhere)
class UCameraComponent* camera;
TSet<AAgeOfWarUnit*> spawnedUnits;
};

View File

@ -8,6 +8,13 @@
#include "AgeOfWarManager.h"
#include <Components/BoxComponent.h>
namespace
{
constexpr auto PlayerCollision = TEXT("AgeOfWarUnitPlayer");
constexpr auto ComputerCollision = TEXT("AgeOfWarUnitComputer");
constexpr auto TagNoAuto = TEXT("NoAuto");
}
const FAgeOfWarUnitStats& AAgeOfWarUnit::GetStats()
{
if(!stats)
@ -19,6 +26,25 @@ const FAgeOfWarUnitStats& AAgeOfWarUnit::GetStats()
void AAgeOfWarUnit::UpdateStats()
{
health = GetStats().health;
attackStartRange = GetStats().attackStartRange;
switch(team)
{
case UnitTeam::AI:
root->SetCollisionProfileName(ComputerCollision);
allyblocker->SetCollisionProfileName(PlayerCollision);
break;
case UnitTeam::Player:
root->SetCollisionProfileName(PlayerCollision);
allyblocker->SetCollisionProfileName(ComputerCollision);
break;
default:
break;
}
allyblocker->SetBoxExtent(root->GetUnscaledBoxExtent(), false);
allyblocker->SetCollisionEnabled(ECollisionEnabled::NoCollision);
OnUpdateStats();
}
void AAgeOfWarUnit::BeginPlay()
@ -29,6 +55,8 @@ void AAgeOfWarUnit::BeginPlay()
}
Super::BeginPlay();
world = GetWorld();
}
void AAgeOfWarUnit::EndPlay(const EEndPlayReason::Type EndPlayReason)
@ -38,10 +66,12 @@ void AAgeOfWarUnit::EndPlay(const EEndPlayReason::Type EndPlayReason)
AAgeOfWarUnit::AAgeOfWarUnit()
{
//auto root = CreateDefaultSubobject<USceneComponent>(TEXT("Scene"));
//
//collision = CreateDefaultSubobject<UBoxComponent>(TEXT("Collision"));
//collision->SetCollisionProfileName(TEXT("AgeOfWarUnit"));
root = CreateDefaultSubobject<UBoxComponent>(TEXT("Collision"));
allyblocker = CreateDefaultSubobject<UBoxComponent>(TEXT("AllyBlocker"));
allyblocker->SetupAttachment(root);
traceStart = CreateDefaultSubobject<USceneComponent>(TEXT("TraceStart"));
traceStart->SetupAttachment(root);
traceStart->AddRelativeLocation(FVector(0, 0, 200));
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bStartWithTickEnabled = true;
@ -54,10 +84,26 @@ void AAgeOfWarUnit::Tick(float deltaTime)
if(!manager || GetStats().moveSpeed <= 0)
return;
// move unit forward
// try move
FHitResult moveHit;
auto moveStep = GetActorForwardVector() * GetStats().moveSpeed;
this->AddActorWorldOffset(moveStep, true, &moveHit, ETeleportType::None);
if(moveHit.bBlockingHit)
allyblocker->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
else
allyblocker->SetCollisionEnabled(ECollisionEnabled::NoCollision);
// look for units forward
FHitResult hit;
this->AddActorWorldOffset(moveStep, true, &hit, ETeleportType::None);
auto startLocation = traceStart->GetComponentLocation();
auto endLocation = startLocation + (GetActorRotation().Vector() * attackStartRange * (moveHit.bBlockingHit ? 5 : 1));
world->LineTraceSingleByChannel(
hit,
startLocation,
endLocation,
ECollisionChannel::ECC_GameTraceChannel1
);
DrawDebugLine(GetWorld(), startLocation, endLocation, FColor::Red, false, deltaTime * 10, 0, 4.0f);
// check if blocked
if(!hit.bBlockingHit)
@ -71,7 +117,7 @@ void AAgeOfWarUnit::Tick(float deltaTime)
}
// iterate to attackable unit
for(int i = 1; forwardUnit->team == team && i < GetStats().attackDistance; i += forwardUnit->GetStats().unitSize)
for(int i = 1; forwardUnit->team == team && i < GetStats().attackUnitDistance; i += forwardUnit->GetStats().unitSize)
forwardUnit = forwardUnit->forwardUnit;
// if forward unit is in the same team skip attack
@ -89,15 +135,24 @@ void AAgeOfWarUnit::Tick(float deltaTime)
void AAgeOfWarUnit::Damage(const int32 damage)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, FString::Printf(TEXT("Damage %d taken by %s"), damage, *GetClass()->GetName()));
if(killed)
return;
GEngine->AddOnScreenDebugMessage((int32)GetClass()->GetUniqueID(), 5.0f, FColor::Yellow, FString::Printf(TEXT("%d"), health));
health -= damage;
if(health > 0)
return;
killed = true;
if(IsValid(manager))
manager->OnUnitKill(this);
{
manager->UnitKill(this);
}
else
{
Destroy();
}
}

View File

@ -27,7 +27,10 @@ struct FAgeOfWarUnitStats
int32 attackDamage = 1;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 attackDistance = 1;
int32 attackUnitDistance = 1;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float attackStartRange = 100;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float attackRate = 1.0f;
@ -69,17 +72,28 @@ protected:
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
UFUNCTION(BlueprintImplementableEvent)
void OnUpdateStats();
void Damage(const int32 damage);
AAgeOfWarUnit* forwardUnit = nullptr;
private:
UPROPERTY(EditAnywhere)
class UBoxComponent* collision;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
class UBoxComponent* root;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
class UBoxComponent* allyblocker;
UPROPERTY(EditAnywhere)
class USceneComponent* traceStart;
private:
int32 health;
float attackStartRange;
FTimerHandle attackTimer;
double lastAttackTimestamp = 0;
UWorld* world;
bool killed = false;
};