new algorithm draft for diag moves; committed missing files

This commit is contained in:
2022-02-03 01:11:06 +01:00
parent 2bf072e3c6
commit 1573598c2a
11 changed files with 316 additions and 85 deletions
+9 -13
View File
@@ -45,10 +45,12 @@ void AAdventurePlayerController::LeftClick()
if (bInPlacementMode) { PlaceObject(PlaceObjClass, HoveredHex); }
}
TArray<AHexTile*> AAdventurePlayerController::Vision()
TArray<AHexTile*> AAdventurePlayerController::Vision(int32 Radius)
{
TArray<AHexTile*> Results;
TSet<AHexTile*> Visible = MapRef->BreadthFirstSearch(CurrentHex, 4);
TSet<AHexTile*> Visible;
if (CurrentHex->bDiagMove) { Radius = FMath::FloorToInt(float(Radius) * (2.f / 3.f)); }
Visible = MapRef->BreadthFirstSearch(CurrentHex, Radius);
for (auto& Hex : Visible) {
if (ExploredHexes.Contains(Hex)) { continue; }
Results.Add(Hex);
@@ -60,31 +62,25 @@ TArray<AHexTile*> AAdventurePlayerController::Vision()
void AAdventurePlayerController::TogglePlacing()
{
bInPlacementMode = !bInPlacementMode;
if (bInPlacementMode) {
PlaceObj = World->SpawnActor<AMapObject>(PlaceObjClass, FTransform());
}
if (bInPlacementMode) { PlaceObj = World->SpawnActor<AMapObject>(PlaceObjClass, FTransform()); }
else { if (IsValid(PlaceObj)) { PlaceObj->Destroy(); } }
}
void AAdventurePlayerController::FitOnGrid(AMapObject* MapObject)
{
if (!IsValid(HoveredHex)) { return; }
if (HoveredHex->bFree) {
MapObject->SetActorLocation(FVector(HoveredHex->GetActorLocation()));
}
if (HoveredHex->bFree) { MapObject->SetActorLocation(FVector(HoveredHex->GetActorLocation())); }
}
// called from BP; generally takes the Hex under the player cursor as argument
void AAdventurePlayerController::PlaceObject(TSubclassOf<AMapObject> MapObjClass, AHexTile* OnHex)
{
// spawn this Actor at World location of Origin Hex;
AMapObject* SpawnedObj = World->SpawnActor<AMapObject>(MapObjClass, FTransform(OnHex->GetActorTransform().GetLocation()));
SpawnedObj->Origin = OnHex;
OnHex->bFree = false;
SpawnedObj->Occupy();
// set Hexes to bOccupied according to BlockVectors;
OnHex->bFree = false; // exact Hexes are eventually to be determined by MapObjectClass's BlockingVectors
MapRef->MapObjects.Add(OnHex, SpawnedObj); // maybe this as well
MapRef->MapObjects.Add(OnHex, SpawnedObj);
MapRef->IncID++;
SpawnedObj->ID = MapRef->IncID;
MapRef->MapObjectsByID.Add(MapRef->IncID, SpawnedObj);