LEAP Documentation 40220
Documentation for the LEAP project
CapturePoint.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 "ProjectX.h"
6#include "CoreMinimal.h"
7#include "GameFramework/Actor.h"
8#include "Components/CapsuleComponent.h"
9#include "Engine/DataTable.h"
11#include "ReactsToMatchEvents.h"
12#include "TeamInterface.h"
13#include "PlayerStats.h"
14#include "TrackableInterface.h"
15#include "CapturePoint.generated.h"
16
17#define NUMBER_OF_DECAYS_UNTIL_AWARD_RESET 2
18
22class UAfflictionComponent;
23class UAfflictionInstance;
25
26UENUM()
27enum class ECaptureType : uint8
28{
29 CaptureFull = 0,
33};
34
35USTRUCT(Blueprintable)
37{
38 GENERATED_USTRUCT_BODY()
39
40public:
41 //what team has progress towards this capture point
42 UPROPERTY(BlueprintReadWrite, Category = "Capture")
43 int32 Team = -1;
44 //players is positive if it's being captured for Team specified, negative if being taken away from Team specified
45 UPROPERTY(BlueprintReadWrite, Category = "Capture")
46 int32 NumPlayers = 0;
47 UPROPERTY(BlueprintReadWrite, Category = "Capture")
48 float Progress = 0.f;
49 UPROPERTY(BlueprintReadWrite, Category = "Capture")
50 int32 CurrentCheckPoint = 0;
51 UPROPERTY(BlueprintReadOnly, Category = "Capture")
52 int32 LastAwardedCheckPoint = -1;
53 UPROPERTY(BlueprintReadOnly, Category = "Capture")
54 int32 DecayCounter = 0;
55 /* Describes if the current capture info is a point being taken over. True if an opposing team is capturing */
56 UPROPERTY(BlueprintReadWrite, Category = "Capture")
57 bool bBeingTaken = false;
58};
59
60USTRUCT(Blueprintable)
61struct FBaseControlEventTableRow : public FTableRowBase
62{
63 GENERATED_USTRUCT_BODY()
64
65 UPROPERTY(EditDefaultsOnly, Category = "Sound")
66 FString AllySound;
67 UPROPERTY(EditDefaultsOnly, Category = "Sound")
68 FString EnemySound;
69};
70
71DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FControlPointOwnerChangedSignature, int32, TeamOwner, ACapturePoint*, Point);
72DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FCaptureInfoChanged, const FCaptureInfo&, CaptureInfo);
73DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FCapturePointLockChangedSignature,ACapturePoint*, CapturePoint, bool, bLocked);
74
75UCLASS(BlueprintType, Blueprintable)
76class PROJECTX_API ACapturePoint : public AActor, public ISpawnTargetInterface, public IReactsToMatchEvents, public ITeamInterface, public ITrackableInterface
77{
78 GENERATED_UCLASS_BODY()
79
80protected:
81 virtual void BeginPlay() override;
82 virtual void CollectPlayerStartList();
83
84public:
85 virtual void Tick(float DeltaTime) override;
86
87 virtual void TickCapture(float DeltaTime);
88
89 virtual int32 GetActorTeam(AActor* Target) const;
90
91 virtual int32 GetTeam() const override { return TeamOwner; }
92 virtual int32 SetTeam(int32 NewTeam) override;
93 virtual float GetRadarIconSize() const { return GetCaptureRadius(); }
94 virtual TSoftObjectPtr<UTexture2D> GetRadarIcon() const override { return RadarIcon; }
95 virtual float GetRadarIconOpacity() const override { return RadarIconOpacity; }
96 virtual const FText& GetRadarLabel() const { return PointName; }
97 virtual void SetRadarIconOpacity(float Opacity) override { RadarIconOpacity = Opacity; }
98 virtual bool RegisterOnStart() const override { return bRegisterOnBeginPlay; }
99 virtual FStopTrackingActorSignature& GetStopTrackingEvent() override { return StopTrackingCapturePointEvent; }
100 UFUNCTION(BlueprintCallable, Category = CapturePoint)
101 int32 GetSortOrder() const { return SortOrder; }
102
103 UFUNCTION(BlueprintCallable, Category = CapturePoint)
104 FText GetPointName() const { return PointName; }
105
106 UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly, Category = CapturePoint)
107 virtual void SetLocked(bool bNewLocked);
108 UFUNCTION(BlueprintCallable, Category = CapturePoint)
109 virtual bool GetIsLocked() const { return bLocked; }
110
111 UFUNCTION(BlueprintCallable, Category = CapturePoint)
112 const FCaptureInfo& GetCaptureInfo() const { return CaptureInfo; }
113 UFUNCTION(BlueprintCallable, Category = CapturePoint)
114 FORCEINLINE float GetCaptureRadius() const { return CapsuleComponent ? CapsuleComponent->GetScaledCapsuleRadius() : -1.f; }
115
116 virtual void Initialize(int32 NumberOfCheckPointsOverride = INDEX_NONE, float PerPlayerCaptureRateOverride = INDEX_NONE);
117
118//~ Begin ISpawnTargetInterface Interface.
119 virtual bool CanSpawnPlayer(const AProjectXPlayerState* Instigator) const override;
120 virtual float GetSpawnScoreForInstigator(const AActor* const QueryInstigator, FVector& TargetLocation, bool bUseDistanceToTargetLocation = false) const override;
121 virtual bool GetSpawnLocation(AProjectXPlayerState* Instigator, FTransform& Transform) const override;
122//~ End ISpawnTargetInterface Interface.
123
124 void TriggerDelayedActivation();
125
126 virtual AActor* GetPlayerStart(class AController* Player) const;
127 virtual AActor* GetTrackableInterfaceActor() override { return this; }
128
129 virtual void MatchEnded() override;
130
131public:
132 UPROPERTY(BlueprintAssignable)
133 FControlPointOwnerChangedSignature OnControlPointOwnerChanged;
134 UPROPERTY(BlueprintAssignable)
135 FCaptureInfoChanged OnCaptureInfoChanged;
136 UPROPERTY(BlueprintAssignable)
137 FCapturePointLockChangedSignature OnCapturePointLockChangedEvent;
138 UPROPERTY(BlueprintAssignable)
139 FControlPointOwnerChangedSignature OnPointBeingClaimedEvent;
140 UPROPERTY(BlueprintAssignable)
141 FStopTrackingActorSignature StopTrackingCapturePointEvent;
142
143protected:
144 UFUNCTION()
145 void OnOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
146
147 UFUNCTION()
148 void OnOverlapEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
149
150 UFUNCTION()
151 void UpdateProcessedOccupants();
152
153 UFUNCTION()
154 void CollectInitialOverlaps();
155
156 UFUNCTION()
157 void OnVehiclePassengerChanged(AProjectXVehicle* Vehicle, UVehicleSeatComponent* Seat = NULL, AProjectXCharacter* PreviousPassenger = NULL);
158
159 bool DoesOccupantHaveAnInvalidAffliction(UAfflictionComponent* AfflictionComponent);
160
161 UFUNCTION()
162 void OnRep_Locked();
163
164 UFUNCTION()
165 void OnRep_TeamOwner();
166
167 UFUNCTION()
168 void OnRep_CaptureInfo();
169
170 UFUNCTION(BlueprintImplementableEvent, BlueprintAuthorityOnly, Category = CapturePoint)
171 void OnPointOwnerChanged(int LastOwner);
172
173 UFUNCTION(BlueprintImplementableEvent, BlueprintAuthorityOnly, Category = CapturePoint)
174 void OnCaptureComplete();
175
176 UFUNCTION(BlueprintImplementableEvent, Category = CapturePoint)
177 void OnCapturePointLockChanged(bool bIsLock);
178
179 UFUNCTION(BlueprintCallable)
180 void ResetPoint();
181
182 UFUNCTION(BlueprintCallable)
183 void ChangeCaptureProgress(float Amount);
184 UFUNCTION(BlueprintCallable, Category = CapturePoint)
185 int32 GetTopCapturingTeam() const
186 {
187 int32 TopTeam = INDEX_NONE;
188 if (TeamStandings.Num() >= 1)
189 {
190 TopTeam = TeamStandings[0];
191 }
192
193
194 return TopTeam;
195 }
197 {
198 if (TeamStandings.Num() > 1)
199 {
200 return TeamStandings[1];
201 }
202 else
203 {
204 return INDEX_NONE;
205 }
206 }
207 UFUNCTION(BlueprintCallable)
208 void UpdateCheckPoint();
209
210 void SetCaptureInfo(int32& NumberOfPlayers, int32& Direction);
211 void AwardCapture(ECaptureType Type, int32 AwardingTeam);
212 const TSubclassOf<UExperienceEvent> GetExpEventOverride(EXPEventType Type) const;
213
214 /* The team this capture point defaults to. If -1 this capture point will be neutral */
215 UPROPERTY(EditInstanceOnly, Category = "Capture Point", meta = (AllowPrivateAccess = true))
216 int32 DefaultTeam = INDEX_NONE;
217 /* The icon used for this capture point on the radar*/
218 UPROPERTY(EditDefaultsOnly, Category = "Capture Point", meta = (AllowPrivateAccess = true))
219 TSoftObjectPtr<UTexture2D> RadarIcon = nullptr;
220 /* Use this to make the radar icon semi-transparent */
221 UPROPERTY(EditDefaultsOnly, Category = "Capture Point", meta = (AllowPrivateAccess = true))
222 float RadarIconOpacity = 0.3f;
223 /* should this call to register itself as trackable at game start*/
224 UPROPERTY(EditDefaultsOnly, Category = "Capture Point", meta = (AllowPrivateAccess = true))
225 bool bRegisterOnBeginPlay = true;
226 /* is this trackable when it is locked*/
227 UPROPERTY(EditDefaultsOnly, Category = "Capture Point", meta = (AllowPrivateAccess = true))
228 bool bIsTrackableWhenLocked = true;
229 /*valid teams that can capture the objective*/
230 UPROPERTY(EditDefaultsOnly, Category = "Capture Point", meta = (AllowPrivateAccess = true))
231 TSet<uint8> ValidCaptureTeams = TSet<uint8>({0,1});
232 /* How much score is awarded for spawn logics control point is locked and cannot be capture? */
233 UPROPERTY(EditDefaultsOnly, Category = "Spawn Scoring", meta = (AllowPrivateAccess = true))
234 float LockedScoringWeight = 0.5f;
235 /* The maximum distance considered for awarding a score increment, every distance bigger than this value will award 0 score. Value needs to be > 0*/
236 UPROPERTY(EditDefaultsOnly, Category = "Spawn Scoring", meta = (AllowPrivateAccess = true))
237 float ControlPointDistanceScoringWeight = 10000.f;
238 UPROPERTY(EditInstanceOnly, Category = "Capture Point", meta = (AllowPrivateAccess = true))
239 float CaptureDecayRate = 0.05f;
240 /* max distance you can spawn at */
241 UPROPERTY(EditInstanceOnly, Category = "Capture Point", meta = (AllowPrivateAccess = true))
242 float MaxSpawnPointSearchDistance = 10000.0f;
243 /* minimum distance you can spawn at*/
244 UPROPERTY(EditInstanceOnly, Category = "Capture Point", meta = (AllowPrivateAccess = true))
245 float MinSpawnPointSearchDistance = 3000.0f;
246 /* Determines what order the points will display on the HUD */
247 UPROPERTY(EditInstanceOnly, Category = "Capture Point", meta = (AllowPrivateAccess = true))
248 int32 SortOrder = INDEX_NONE;
249 UPROPERTY(EditInstanceOnly, Category = "Capture Point", meta = (AllowPrivateAccess = true))
250 UCapsuleComponent* CapsuleComponent = NULL;
251 UPROPERTY(EditInstanceOnly, Category = "Capture Point Spawns")
252 TArray<class AStartPointVolume*> StartPointVolumes;
253 /*Name of the point*/
254 UPROPERTY(EditInstanceOnly, Category = "Capture Point", meta = (AllowPrivateAccess = true))
255 FText PointName = FText::FromString("X");
256 /*afflictions that prevent capture of the point*/
257 UPROPERTY(EditDefaultsOnly, Category = "Capture Point")
258 TArray<TSubclassOf<UAfflictionInstance>> InvalidAfflictionClasses;
259 /*Can you spawn on the point regardless of team*/
260 UPROPERTY(EditDefaultsOnly)
261 bool bIgnoreTeamWhenSpawning = false;
262 /* Does the point reset when locked*/
263 UPROPERTY(EditDefaultsOnly)
264 bool bResetOnLocked = false;
265 /* Delay before unlocking */
266 UPROPERTY(EditDefaultsOnly)
267 float DelayActivationTime = 0.0f;
268 /*Optional override events to the default exp events*/
269 UPROPERTY(EditDefaultsOnly)
270 TMap<EXPEventType,TSubclassOf<UExperienceEvent>> ExperienceEventOverrides;
271 /* If true this capture point cannot be captured after its initialization */
272 UPROPERTY(ReplicatedUsing = OnRep_Locked, EditInstanceOnly, Category = "Capture Point", meta = (AllowPrivateAccess = true))
273 bool bLocked = false;
274 UPROPERTY(ReplicatedUsing = OnRep_TeamOwner)
275 int32 TeamOwner = INDEX_NONE;
276 //Hold information about the current capture
277 UPROPERTY(ReplicatedUsing = OnRep_CaptureInfo)
278 FCaptureInfo CaptureInfo;
279
280 UPROPERTY()
281 TArray<TWeakObjectPtr<AProjectXCharacter>> PlayerOccupants;
282 /* Privately collected using the spawning volume. */
283 UPROPERTY()
284 TArray<AActor*> PlayerStartList;
285
286 /* both of these are managed by UpdateProcessedOccupants and are used to move capture calculations to event-driven systems */
287 TMap<int32, int32> NumberOfOccupantsByTeam;
288 TArray<int32> TeamStandings;
289 TArray<float>CaptureCheckPoints;
290 int32 CapturingTeam = INDEX_NONE;
291 float PerPlayerCaptureRate = 0.1f;
292 int32 NumberOfCheckPoints;
293 FTimerHandle DelayedUnlockHandle;
294
295public:
296 UFUNCTION(BlueprintCallable)
297 static void GetAllControlPoints(const UObject* WorldContextObject, TArray<class ACapturePoint*>& CapturePointList);
298 UFUNCTION(BlueprintPure)
299 static void GetBaseControlEventTableRow(const FBaseControlEventTableRow& TableRow, FString& AllySound, FString& EnemySound);
300
301};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FControlPointOwnerChangedSignature, int32, TeamOwner, ACapturePoint *, Point)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FCaptureInfoChanged, const FCaptureInfo &, CaptureInfo)
ECaptureType
Definition: CapturePoint.h:28
EXPEventType
Definition: PlayerStats.h:13
Definition: CapturePoint.h:77
virtual void SetRadarIconOpacity(float Opacity) override
Definition: CapturePoint.h:97
virtual float GetRadarIconSize() const
Definition: CapturePoint.h:93
virtual float GetRadarIconOpacity() const override
Definition: CapturePoint.h:95
virtual AActor * GetTrackableInterfaceActor() override
Definition: CapturePoint.h:127
int32 GetSecondCapturingTeam() const
Definition: CapturePoint.h:196
virtual int32 GetTeam() const override
Definition: CapturePoint.h:91
virtual const FText & GetRadarLabel() const
Definition: CapturePoint.h:96
virtual TSoftObjectPtr< UTexture2D > GetRadarIcon() const override
Definition: CapturePoint.h:94
virtual bool RegisterOnStart() const override
Definition: CapturePoint.h:98
virtual FStopTrackingActorSignature & GetStopTrackingEvent() override
Definition: CapturePoint.h:99
void SetCaptureInfo(int32 &NumberOfPlayers, int32 &Direction)
Definition: ProjectXCharacter.h:128
Definition: ProjectXGameModeBaseControl.h:14
Definition: ProjectXPlayerState.h:238
Definition: ProjectXVehicle.h:56
Definition: StartPointVolume.h:14
Definition: ReactsToMatchEvents.h:16
Definition: SpawnTargetInterface.h:18
Definition: TeamInterface.h:26
Definition: TrackableInterface.h:22
Definition: ExperienceEvent.h:18
class USoundBase * Sound
Definition: ExperienceEvent.h:46
Definition: CapturePoint.h:62
Definition: CapturePoint.h:37