Added reference to harbored map object to tiles; minor refactoring
This commit is contained in:
parent
26d3289962
commit
18af6a56be
@ -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<AMapObject> MapObjClass, AHexTile* OnHex)
|
||||
// To-Do: factor out core functionality to a seperate (more neutral) class like AdventureMap.
|
||||
void AAdventurePlayerController::PlaceObject(TSubclassOf<AMapObject> MapObjClass, AHexTile* HoveredTile)
|
||||
{
|
||||
AMapObject* SpawnedObj = World->SpawnActor<AMapObject>(MapObjClass, FTransform(OnHex->GetActorTransform().GetLocation()));
|
||||
SpawnedObj->Origin = OnHex;
|
||||
OnHex->bFree = false;
|
||||
AMapObject* SpawnedObj = World->SpawnActor<AMapObject>(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);
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user