/
GhostHouseQueue.h
43 lines (34 loc) · 1.07 KB
/
GhostHouseQueue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
#include "CoreMinimal.h"
#include "GhostAiController.h"
#include "UObject/Object.h"
#include "Utils/RuntimeSet.h"
#include "GhostHouseQueue.generated.h"
class AGhostAiController;
// AGhostHouseQueue is an implementation of the Runtime Set design pattern,
// as described by Ryan Hipple in his talk on ScriptableObjects in Unity.
UCLASS(Blueprintable)
class AGhostHouseQueue : public ARuntimeSet
{
GENERATED_BODY()
UPROPERTY(EditDefaultsOnly, Category = "Custom Settings")
double TimeToForceGhostOutOfHouse = 5.0;
public:
void Add(const AActor* Thing)
{
AddAndSort(Thing, &SortByGhostHousePriority);
}
protected:
AGhostHouseQueue();
virtual void Tick(float DeltaSeconds) override;
private:
static bool SortByGhostHousePriority(const AActor* A, const AActor* B)
{
const auto GhostA = Cast<AGhostAiController>(A);
check(GhostA);
const auto GhostB = Cast<AGhostAiController>(B);
check(GhostB);
// Array will be sorted in ascending order: 1, 10, 100, 1000, 10000
return GhostA->GetLeaveGhostHousePriority() < GhostB->GetLeaveGhostHousePriority();
}
};