Advertisement
Guest User

MTD_FoeState_MovingAroundBlockade.h

a guest
Oct 11th, 2023
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.75 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "FiniteStateMachine/MachineStateData.h"
  4. #include "Gameplay/Foes/AI/States/MTD_FoeState.h"
  5. #include "NativeGameplayTags.h"
  6.  
  7. #include "MTD_FoeState_MovingAroundBlockade.generated.h"
  8.  
  9. DECLARE_LOG_CATEGORY_EXTERN(MTD_LogFoe_MoveAroundBlockade, Log, All);
  10. UE_DECLARE_GAMEPLAY_TAG_EXTERN(TAG_StateMachine_Label_MoveAround);
  11.  
  12. UCLASS()
  13. class UMTD_FoeStateData_MovingAroundBlockade
  14.     : public UMachineStateData
  15. {
  16.     GENERATED_BODY()
  17.  
  18. public:
  19.     UPROPERTY(EditDefaultsOnly)
  20.     bool bIgnoreMoveAroundBlockade = false;
  21.  
  22.     UPROPERTY(EditDefaultsOnly)
  23.     float MoveAroundSomethingMaximumSpeed = 40.f;
  24.  
  25.     FVector StartMovingAroundBlockadeLocation = FVector::ZeroVector;
  26.     FVector MovingAroundBlockadePoint = FVector::ZeroVector;
  27.  
  28.     /** It's either +1 or -1. Means right of left. */
  29.     float MovingAroundBlockadeSide = 1.f;
  30.  
  31.     float LastBlockadeCheckTime = 0.f;
  32.     float LastMovingAroundBlockadeTime = 0.f;
  33.     float LastBlockadeWidth = 0.f;
  34.     FVector LastBlockadeHitNormal = FVector::ZeroVector;
  35.     TWeakObjectPtr<AActor> LastMovingAroundBlockadeActor = nullptr;
  36. };
  37.  
  38. /**
  39.  *
  40.  */
  41. UCLASS()
  42. class UMTD_FoeState_MovingAroundBlockade
  43.     : public UMTD_FoeState
  44. {
  45.     GENERATED_BODY()
  46.  
  47. public:
  48.     UMTD_FoeState_MovingAroundBlockade();
  49.  
  50.     /**
  51.      * Called we collide with a blockade, or even other enemies, to tell us to move around them on our way
  52.      * to a destination.
  53.      *
  54.      * Subject to a variety of logical checks before we accept moving around the "blockade".
  55.      *
  56.      *
  57.      * Debug information:
  58.      * - Red sphere - TraceThroughBlockadePosition
  59.      * - Green sphere - OurPosition
  60.      * - White line - OurPosition -> TraceThroughBlockadePosition
  61.      * - Red line - BlockadePosition -> BlockadePosition + HitNormal * 150
  62.      * - Cyan sphere - MovingAroundBlockadePoint
  63.      */
  64.     static bool MoveAroundBlockade(UFiniteStateMachine* StateMachineContext, AActor* BlockadeActor, float BlockadeWidth,
  65.         FVector HitNormal, bool bSkipBlockingCheck = false);
  66.  
  67.     /**
  68.      * Check if a movement point around a blockade is valid, currently just whether it has ground underneath it!
  69.      */
  70.     static bool CheckMoveAroundBlockadePoint(const UFiniteStateMachine* StateMachineContext,
  71.         const FVector& MoveToPoint);
  72.  
  73. protected:
  74.     //~UMTD_FoeState Interface
  75.     virtual void Begin(TSubclassOf<UMachineState> PreviousState) override;
  76.     virtual void Tick(float DeltaSeconds) override;
  77.     virtual void End(TSubclassOf<UMachineState> NewState) override;
  78.     //~End of UMTD_FoeState Interface
  79.  
  80. private:
  81.     //~Labels
  82.     void MoveAroundBlockade(float DeltaSeconds);
  83.     //~End of Labels
  84.  
  85.     void CancelMoveAround();
  86.     void TryOtherBlockadeDirection();
  87.  
  88. protected:
  89.     TWeakObjectPtr<UMTD_FoeStateData_MovingAroundBlockade> StateData = nullptr;
  90.  
  91.     FTimerHandle CancelMoveAroundTimer;
  92.     FTimerHandle TryOtherBlockadeDirectionTimer;
  93. };
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement