Decreased Recurring NPCs

This commit is contained in:
Rafal Swierczek 2024-05-12 21:12:36 +01:00
parent ebafc668b4
commit 9a18446c83
3 changed files with 12 additions and 23 deletions

View File

@ -37,30 +37,19 @@ void ANPC_Manager::BeginPlay()
}
if (NPC_StationClasses.IsEmpty()) return;
FRotator DefaultRot = FRotator(0, 0, 0);
int StationSlots = (StationPoints.Num() / NPC_StationClasses.Num()) + 1;
TArray<int> NumOfUniqueStations;
for (auto UniqueStation : NPC_StationClasses)
{
NumOfUniqueStations.Add(StationSlots);
}
int StationClassIndex = 0;
for (FVector StationPoint : StationPoints)
{
bool FoundRandomFairInt = false;
int RandInt = 0;
while (!FoundRandomFairInt)
{
RandInt = FMath::RandRange(0, NPC_StationClasses.Num() - 1);
if (NumOfUniqueStations[RandInt] > 0)
{
NumOfUniqueStations[RandInt]--;
FoundRandomFairInt = true;
}
}
FVector StationPointWorldLocation = StationPoint + GetActorLocation();
ANPC_Station* NPC_Station = GetWorld()->SpawnActor<ANPC_Station>(NPC_StationClasses[RandInt], StationPointWorldLocation, DefaultRot);
ANPC_Station* NPC_Station = GetWorld()->SpawnActor<ANPC_Station>(NPC_StationClasses[StationClassIndex], StationPointWorldLocation, DefaultRot);
if (IsValid(NPC_Station)) NPC_Stations.Add(NPC_Station);
StationClassIndex++;
if (StationClassIndex >= NPC_StationClasses.Num())
{
StationClassIndex = 0;
}
}
SetActorTickInterval(1);
}