diff --git a/AdventureMap.cpp b/AdventureMap.cpp index 6893e45..c202e73 100644 --- a/AdventureMap.cpp +++ b/AdventureMap.cpp @@ -8,7 +8,7 @@ #include "Kismet/GameplayStatics.h" #include "Algo/Reverse.h" #include "Util/IndexPriorityQueue.h" -#include +#include // Sets default values AAdventureMap::AAdventureMap() @@ -106,13 +106,10 @@ FHexVector AAdventureMap::AxialRound(float qf, float rf) return FHexVector(q, r); } -float AAdventureMap::Lerp(int32 a, int32 b, int32 t) +float AAdventureMap::Lerp(int32 a, int32 b, float t) { return float(a + (b - a) * t); } -// FHexVector SampleHex = MapRef->AxialRound(Lerpl(a, b, t), Lerp(x, y, z)); -// - TArray AAdventureMap::Neighbors(AHexTile* OfHex, bool bFreeOnly = false) { diff --git a/AdventureMap.h b/AdventureMap.h index 8239a1a..95f1b8b 100644 --- a/AdventureMap.h +++ b/AdventureMap.h @@ -81,9 +81,9 @@ public: bool DiagIsReachable(AHexTile* InStart, FHexVector InDiagUnitVec); UFUNCTION(BlueprintCallable, Category = "Utility") - float Lerp(int32 a, int32 b, int32 t); + float Lerp(int32 a, int32 b, float t); UFUNCTION(BlueprintCallable, Category = "Utility") - FHexVector AxialRound(float q, float r) + FHexVector AxialRound(float q, float r); UFUNCTION(BlueprintCallable, Category = "Utility") TArray Neighbors(AHexTile* OfHex, bool bFreeOnly); diff --git a/AdventurePlayerController.cpp b/AdventurePlayerController.cpp index d3b4e83..12bc72a 100644 --- a/AdventurePlayerController.cpp +++ b/AdventurePlayerController.cpp @@ -55,15 +55,14 @@ void AAdventurePlayerController::LeftClick() else { return; } } -TSet AAdventurePlayerController::Vision(int32 Radius) +TArray AAdventurePlayerController::Vision(int32 Radius) { TSet InRange = MapRef->BreadthFirstSearch(CurrentHex, Radius); - TSet Results; + TArray Results; for (auto& Hex : InRange) { if (Hex->Distance(CurrentHex) == Radius) { - AHexTile* Target; for (int32 i = 1; i <= Radius; i++) { float t = 1.0f / Radius * i; @@ -73,9 +72,11 @@ TSet AAdventurePlayerController::Vision(int32 Radius) AHexTile* SampleHex = MapRef->Grid[MapRef->GridIndex(Sample.Q, Sample.R)]; Results.Add(SampleHex); - ExploredHexes.Add(Hex); - if (!SampleHex->bFree || ExploredHexes.Contains(SampleHex)) + if (!ExploredHexes.Contains(SampleHex)) + { ExploredHexes.Add(Hex); } + + if (!SampleHex->bFree) { break; } } } @@ -131,13 +132,15 @@ void AAdventurePlayerController::FitOnGrid(AMapObject* MapObject) void AAdventurePlayerController::PlaceObject(TSubclassOf MapObjClass, AHexTile* HoveredTile) { AMapObject* SpawnedObj = World->SpawnActor(MapObjClass, FTransform(HoveredTile->GetActorTransform().GetLocation())); + SpawnedObj->MapRef = MapRef; SpawnedObj->Origin = HoveredTile; + SpawnedObj->bPlaced = true; HoveredTile->bFree = false; HoveredTile->MapObject = SpawnedObj; - SpawnedObj->Occupy(); MapRef->MapObjects.Add(HoveredTile, SpawnedObj); MapRef->IncID++; SpawnedObj->ID = MapRef->IncID; MapRef->MapObjectsByID.Add(MapRef->IncID, SpawnedObj); + SpawnedObj->Occupy(); } \ No newline at end of file diff --git a/AdventurePlayerController.h b/AdventurePlayerController.h index 8ac4964..a1bb6b4 100644 --- a/AdventurePlayerController.h +++ b/AdventurePlayerController.h @@ -57,7 +57,7 @@ public: UPROPERTY(EditAnywhere, BlueprintReadWrite) int32 VisionRadius = 6; UFUNCTION(BlueprintCallable) - TSet Vision(int32 Radius); + TArray Vision(int32 Radius); UPROPERTY(EditAnywhere, BlueprintReadWrite) TSet ExploredHexes; diff --git a/HexTile.h b/HexTile.h index 81fc8e2..5c67a60 100644 --- a/HexTile.h +++ b/HexTile.h @@ -62,7 +62,7 @@ public: // MapObject Placement UPROPERTY(BlueprintReadWrite, VisibleAnywhere) bool bFree = true; - UPROPERTY(BlueprintReadOnly, VisibleInstanceOnly) + UPROPERTY(BlueprintReadWrite, VisibleAnywhere) AMapObject* MapObject; UPROPERTY(BlueprintReadWrite, EditDefaultsOnly) bool bCanActivate = false; diff --git a/MapObject.cpp b/MapObject.cpp index 9782467..7dcf8af 100644 --- a/MapObject.cpp +++ b/MapObject.cpp @@ -21,7 +21,6 @@ AMapObject::AMapObject() void AMapObject::BeginPlay() { Super::BeginPlay(); - Occupy(); } // Called every frame @@ -39,11 +38,10 @@ void AMapObject::Activate() } // Any subclass of MapObject has a defined array of Vectors relative to its origin which has to occupy() upon being placed on the map. -void AMapObject::Occupy() -{ - for (auto& V : Occupying) { - AHexTile* OccupiedHex = MapRef->Grid[MapRef->GridIndex(Origin->Q + V.Q, Origin->R + V.R)]; - OccupiedHex->bFree = false; - OccupiedHex->MapObject = this; - } -} +//void AMapObject::Occupy(int32 Q, int32 R) +//{ +// AHexTile* OccupiedHex = MapRef->Grid[MapRef->GridIndex(Q, R)]; +// +// OccupiedHex->bFree = false; +// OccupiedHex->MapObject = this; +//} diff --git a/MapObject.h b/MapObject.h index a1db784..dfcf42e 100644 --- a/MapObject.h +++ b/MapObject.h @@ -35,6 +35,8 @@ public: int32 ID; UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "Generation") class AHexTile* Origin; // very important + UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "Generation") + bool bPlaced; UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Generation") TArray Occupying; @@ -54,6 +56,7 @@ public: // Called every frame virtual void Tick(float DeltaTime) override; + UFUNCTION(BlueprintImplementableEvent) void Occupy(); };