VizKa

Need

Dec 31st, 2023 (edited)
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | Gaming | 0 0
  1. UCLASS(BlueprintType)
  2. class UNeed : public UObject
  3. {
  4.  
  5.     GENERATED_BODY()
  6. public:
  7.     UPROPERTY(EditAnywhere, BlueprintReadWrite)
  8.     ENeedType NeedType;
  9.     UPROPERTY(EditAnywhere, BlueprintReadWrite)
  10.     int MaxValue;
  11.     UPROPERTY(EditAnywhere, BlueprintReadWrite)
  12.     int MinValue;
  13.     UPROPERTY(EditAnywhere, BlueprintReadWrite)
  14.     int TriggerValue;
  15.     /*'2' = vital, '1' = 'non-vital', '0' = utility*/
  16.     UPROPERTY(EditAnywhere, BlueprintReadWrite)
  17.     int Importance;
  18.     UPROPERTY(EditAnywhere, BlueprintReadWrite)
  19.     float CurrentValue;
  20.     UPROPERTY(EditAnywhere, BlueprintReadWrite)
  21.     float RateOfDecay;
  22.     UPROPERTY(EditAnywhere, BlueprintReadWrite)
  23.     bool Triggered;
  24.     UPROPERTY(BlueprintReadOnly)
  25.     float Utility;
  26.  
  27.     UFUNCTION(BlueprintCallable)
  28.     UNeed* Setter(ENeedType CnsrtNeedType, int CnsrtMaxValue, int CnsrtMinValue, int CnsrtTriggerValue,
  29.                   int CnsrtImportance,
  30.                   float CnsrtCurrentValue, float CnsrtRateOfDecay);
  31.     UFUNCTION(BlueprintCallable)
  32.     float DecayNeed();
  33.     UFUNCTION(BlueprintCallable)
  34.     float CalculateUtiliy();
  35.     UFUNCTION(BlueprintCallable)
  36.     void SetCurrentValue(float ValueToSet);
  37. };
  38.  
  39. UNeed* UNeed::Setter(ENeedType CnsrtNeedType, int CnsrtMaxValue, int CnsrtMinValue, int CnsrtTriggerValue,
  40.                      int CnsrtImportance, float CnsrtCurrentValue, float CnsrtRateOfDecay)
  41. {
  42.     NeedType = CnsrtNeedType;
  43.     MaxValue = CnsrtMaxValue;
  44.     MinValue = CnsrtMinValue;
  45.     TriggerValue = CnsrtTriggerValue;
  46.     Importance = CnsrtImportance;
  47.     CurrentValue = CnsrtCurrentValue;
  48.     RateOfDecay = CnsrtRateOfDecay;
  49.     Triggered = false;
  50.     CalculateUtiliy();
  51.     return this;
  52. }
  53.  
  54.  
  55. float UNeed::DecayNeed()
  56. {
  57.     CurrentValue = FMath::Clamp(CurrentValue - RateOfDecay, MinValue, MaxValue);
  58.     return CurrentValue;
  59. }
  60.  
  61. float UNeed::CalculateUtiliy()
  62. {
  63.     Utility = CurrentValue/MaxValue;
  64.     return Utility;
  65. }
  66.  
  67. void UNeed::SetCurrentValue(float ValueToSet)
  68. {
  69.     CurrentValue = FMath::Clamp(CurrentValue + ValueToSet, MinValue, MaxValue);
  70. }
Tags: ai
Advertisement
Add Comment
Please, Sign In to add comment