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())); }
|
if (HoveredHex->bFree) { MapObject->SetActorLocation(FVector(HoveredHex->GetActorLocation())); }
|
||||||
}
|
}
|
||||||
|
|
||||||
// called from BP; generally takes the Hex under the player cursor as argument
|
// To-Do: factor out core functionality to a seperate (more neutral) class like AdventureMap.
|
||||||
void AAdventurePlayerController::PlaceObject(TSubclassOf<AMapObject> MapObjClass, AHexTile* OnHex)
|
void AAdventurePlayerController::PlaceObject(TSubclassOf<AMapObject> MapObjClass, AHexTile* HoveredTile)
|
||||||
{
|
{
|
||||||
AMapObject* SpawnedObj = World->SpawnActor<AMapObject>(MapObjClass, FTransform(OnHex->GetActorTransform().GetLocation()));
|
AMapObject* SpawnedObj = World->SpawnActor<AMapObject>(MapObjClass, FTransform(HoveredTile->GetActorTransform().GetLocation()));
|
||||||
SpawnedObj->Origin = OnHex;
|
SpawnedObj->Origin = HoveredTile;
|
||||||
OnHex->bFree = false;
|
HoveredTile->bFree = false;
|
||||||
|
HoveredTile->MapObject = SpawnedObj;
|
||||||
SpawnedObj->Occupy();
|
SpawnedObj->Occupy();
|
||||||
|
|
||||||
MapRef->MapObjects.Add(OnHex, SpawnedObj);
|
MapRef->MapObjects.Add(HoveredTile, SpawnedObj);
|
||||||
MapRef->IncID++;
|
MapRef->IncID++;
|
||||||
SpawnedObj->ID = MapRef->IncID;
|
SpawnedObj->ID = MapRef->IncID;
|
||||||
MapRef->MapObjectsByID.Add(MapRef->IncID, SpawnedObj);
|
MapRef->MapObjectsByID.Add(MapRef->IncID, SpawnedObj);
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
class USceneComponent;
|
class USceneComponent;
|
||||||
class UStaticMeshComponent;
|
class UStaticMeshComponent;
|
||||||
class AAdventureMap;
|
class AAdventureMap;
|
||||||
|
class AMapObject;
|
||||||
class AStarFog;
|
class AStarFog;
|
||||||
class AAdventurePlayerController;
|
class AAdventurePlayerController;
|
||||||
|
|
||||||
@ -61,10 +62,12 @@ public:
|
|||||||
// MapObject Placement
|
// MapObject Placement
|
||||||
UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
|
UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
|
||||||
bool bFree = true;
|
bool bFree = true;
|
||||||
|
UPROPERTY(BlueprintReadOnly, VisibleInstanceOnly)
|
||||||
|
AMapObject* MapObject;
|
||||||
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
|
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
|
||||||
bool bTouchable = false;
|
bool bCanActivate = false;
|
||||||
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
|
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
|
||||||
bool bSteptivatable = false;
|
bool bEvent = false;
|
||||||
|
|
||||||
FORCEINLINE bool operator == (const AHexTile &Other)
|
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()
|
void AMapObject::Occupy()
|
||||||
{
|
{
|
||||||
for (auto& V : Occupying) {
|
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