diff --git a/AdventurePlayerController.cpp b/AdventurePlayerController.cpp index 07de042..d085210 100644 --- a/AdventurePlayerController.cpp +++ b/AdventurePlayerController.cpp @@ -112,15 +112,16 @@ void AAdventurePlayerController::FitOnGrid(AMapObject* MapObject) 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 MapObjClass, AHexTile* OnHex) +// To-Do: factor out core functionality to a seperate (more neutral) class like AdventureMap. +void AAdventurePlayerController::PlaceObject(TSubclassOf MapObjClass, AHexTile* HoveredTile) { - AMapObject* SpawnedObj = World->SpawnActor(MapObjClass, FTransform(OnHex->GetActorTransform().GetLocation())); - SpawnedObj->Origin = OnHex; - OnHex->bFree = false; + AMapObject* SpawnedObj = World->SpawnActor(MapObjClass, FTransform(HoveredTile->GetActorTransform().GetLocation())); + SpawnedObj->Origin = HoveredTile; + HoveredTile->bFree = false; + HoveredTile->MapObject = SpawnedObj; SpawnedObj->Occupy(); - MapRef->MapObjects.Add(OnHex, SpawnedObj); + MapRef->MapObjects.Add(HoveredTile, SpawnedObj); MapRef->IncID++; SpawnedObj->ID = MapRef->IncID; MapRef->MapObjectsByID.Add(MapRef->IncID, SpawnedObj); diff --git a/HexTile.h b/HexTile.h index 8679d78..81fc8e2 100644 --- a/HexTile.h +++ b/HexTile.h @@ -8,6 +8,7 @@ class USceneComponent; class UStaticMeshComponent; class AAdventureMap; +class AMapObject; class AStarFog; class AAdventurePlayerController; @@ -61,10 +62,12 @@ public: // MapObject Placement UPROPERTY(BlueprintReadWrite, VisibleAnywhere) bool bFree = true; + UPROPERTY(BlueprintReadOnly, VisibleInstanceOnly) + AMapObject* MapObject; UPROPERTY(BlueprintReadWrite, EditDefaultsOnly) - bool bTouchable = false; + bool bCanActivate = false; UPROPERTY(BlueprintReadWrite, EditDefaultsOnly) - bool bSteptivatable = false; + bool bEvent = false; FORCEINLINE bool operator == (const AHexTile &Other) { diff --git a/MapObject.cpp b/MapObject.cpp index eaed6ed..9782467 100644 --- a/MapObject.cpp +++ b/MapObject.cpp @@ -38,9 +38,12 @@ 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) { - MapRef->Grid[MapRef->GridIndex(Origin->Q + V.Q, Origin->R + V.R)]->bFree = false; + AHexTile* OccupiedHex = MapRef->Grid[MapRef->GridIndex(Origin->Q + V.Q, Origin->R + V.R)]; + OccupiedHex->bFree = false; + OccupiedHex->MapObject = this; } }