74 lines
1.4 KiB
C++
Executable File
74 lines
1.4 KiB
C++
Executable File
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "LevelLocation.h"
|
|
#include "EngineUtils.h"
|
|
#include "Util.h"
|
|
|
|
#define LogError(Msg) Util::log_error(TEXT("LevelLocation"), Msg)
|
|
|
|
LevelLocation::LevelLocation()
|
|
{
|
|
}
|
|
|
|
LevelLocation::~LevelLocation()
|
|
{
|
|
}
|
|
|
|
bool LevelLocation::is_initialized() const
|
|
{
|
|
return initialized;
|
|
}
|
|
|
|
/**
|
|
* Initialize this class with a list of locations derived from the current world.
|
|
*/
|
|
void LevelLocation::initialize(UWorld *world, const UClass *marker_class)
|
|
{
|
|
initialized = true;
|
|
|
|
/*
|
|
* Find all the markers in the world.
|
|
*/
|
|
for (TActorIterator<AActor> iterator(world); iterator; ++iterator)
|
|
{
|
|
AActor* actor = *iterator;
|
|
if (actor)
|
|
{
|
|
UClass* actor_class = actor->GetClass();
|
|
|
|
if (actor_class == marker_class)
|
|
{
|
|
locations.Add(actor->GetActorLocation());
|
|
}
|
|
}
|
|
}
|
|
|
|
if (locations.Num() == 0)
|
|
{
|
|
LogError("No markers");
|
|
}
|
|
|
|
/*
|
|
* Initialize random stream.
|
|
*/
|
|
random.Initialize(FMath::Rand());
|
|
}
|
|
|
|
/**
|
|
* Get world location of randomly selected mark.
|
|
*
|
|
* @return World location vector of mark.
|
|
*/
|
|
FVector LevelLocation::get_random_mark() const
|
|
{
|
|
if (locations.Num() == 0)
|
|
{
|
|
LogError("No markers");
|
|
return FVector();
|
|
}
|
|
|
|
const int index = random.RandRange(0, locations.Num() - 1);
|
|
return locations[index];
|
|
}
|