LEAP Documentation 40220
Documentation for the LEAP project
DeployableMarker.h
Go to the documentation of this file.
1// Copyright Blue Isle Studios Inc 2018. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "GameFramework/Actor.h"
7#include "DeployableMarker.generated.h"
8
9UENUM(BlueprintType, meta = (Bitflags))
10enum class EPlacementFailureReason : uint8
11{
12 NONE = 0,
13 Grounded = (1 << 0), //Failed because initial groundedness check did not succeed.
14 Slope = (1 << 1), //Failed because the slope was too steep.
15 ZDiff = (1 << 2), //Failed because the delta Z was too high between points.
16 Sky = (1 << 3), //Failed because something occluded the sky.
17};
18ENUM_CLASS_FLAGS(EPlacementFailureReason)
19
20UENUM(BlueprintType, meta = (Bitflags, UseEnumValuesAsMaskValuesInEditor = "true"))
21enum class EPlacementTests : uint8
22{
23 NONE = 0,
24 GroundCheck = (1 << 0),
25 SlopeCheck = (1 << 1),
26 SkyCheck = (1 << 2),
27};
28ENUM_CLASS_FLAGS(EPlacementTests)
29
30/*
31* Marker used for local client to preview their placement of a deployable.
32*/
33UCLASS(Blueprintable)
34class PROJECTX_API ADeployableMarker : public AActor
35{
36 GENERATED_UCLASS_BODY()
37
38public:
39 UFUNCTION(BlueprintCallable, Category = Marker)
40 FORCEINLINE float GetDeployRadius() const { return DeployRadius; }
41 UFUNCTION(BlueprintCallable, Category = Marker)
42 FORCEINLINE float GetMaxVerticalDelta() const { return MaxDeployVerticalDelta; }
43
44 UFUNCTION(BlueprintCallable, Category = Marker)
45 FORCEINLINE bool IsValidPlacement() const { return PlacementFlags == 0; }
46 UFUNCTION(BlueprintCallable, Category = Marker)
47 FORCEINLINE bool IsNotGrounded() const { return (PlacementFlags & uint8(EPlacementFailureReason::Grounded)) != 0; }
48 UFUNCTION(BlueprintCallable, Category = Marker)
49 FORCEINLINE bool IsTooHighSlope() const { return (PlacementFlags & uint8(EPlacementFailureReason::Slope)) != 0; }
50 UFUNCTION(BlueprintCallable, Category = Marker)
51 FORCEINLINE bool IsTooMuchZDifference() const { return (PlacementFlags & uint8(EPlacementFailureReason::ZDiff)) != 0; }
52 UFUNCTION(BlueprintCallable, Category = Marker)
53 FORCEINLINE bool IsSkyObstructed() const { return (PlacementFlags & uint8(EPlacementFailureReason::Sky)) != 0; }
54 UFUNCTION(BlueprintCallable, Category = Marker)
55 FORCEINLINE bool ShouldTestBeRun(EPlacementTests DataType) const { return ((PlacementTestsToRun & uint8(DataType)) != 0); }
56
57//~ Begin AActor Interface.
58protected:
59 virtual void BeginPlay() override;
60
61public:
62 virtual void Tick(float DeltaTime) override;
63
64//~ End AActor Interface.
65public:
66 /* We'll call this on the client via tick but also from the server via CDO. */
67 bool IsValidPlacement(FTransform& Transform, UWorld* World) const;
68 uint8 TestPlacement(FTransform& Transform, UWorld* World, bool bFullTest = true) const;
69 //Called when this marker has become a valid one.
70 UFUNCTION(BlueprintImplementableEvent, Category = Marker)
71 void OnMarkerSuccess();
72
73 //Called when this marker has become an invalid one.
74 UFUNCTION(BlueprintImplementableEvent, Category = Marker)
75 void OnMarkerFailed(EPlacementFailureReason Reason);
76
77protected:
78 virtual void UpdatePlacementFlags(bool bForceUpdate = false);
79
80 virtual bool GetGroundedTransform(FTransform& Transform, UWorld* World) const;
81 virtual bool PerformTraceTest(const FTransform& Transform, FTransform& CapsuleBaseTransform, UWorld* World) const;
82 virtual bool PerformCapsuleTest(const FTransform& BaseTransform, UWorld* World) const;
83
84protected:
85 /* Used to check placement rule results for clients. A convenient way to store them all together in one variable. */
86 UPROPERTY()
87 uint8 PlacementFlags = MAX_uint8;
88
89 /* Radius around deploy point to check placement validity */
90 UPROPERTY(EditDefaultsOnly, Category = Marker)
91 float DeployRadius = 80.f;
92 /* Number of points to test when performing placement validity checks */
93 UPROPERTY(EditDefaultsOnly, Category = Marker)
94 int32 RadialTestPoints = 8;
95 /* Maximum slope (in degrees) this object can be deployed on */
96 UPROPERTY(EditDefaultsOnly, Category = Marker)
97 float MaxDeploySlope = 30.f;
98 /* Maximum vertical distance that this deployable will allow between tested points */
99 UPROPERTY(EditDefaultsOnly, Category = Marker)
100 float MaxDeployVerticalDelta = 30.f;
101 /* Show Debug Information*/
102 UPROPERTY(EditDefaultsOnly, Category = Marker)
103 bool bDebug = false;
104 /*What tests should this run*/
105 UPROPERTY(EditDefaultsOnly, Category = Marker,meta = (Bitmask, BitmaskEnum = EPlacementTests))
106 uint8 PlacementTestsToRun;
107};
EPlacementTests
Definition: DeployableMarker.h:22
EPlacementFailureReason
Definition: DeployableMarker.h:11
Definition: DeployableMarker.h:35