C++
1// SHODAN_Controller_BP.h
2#pragma once
3
4#include "CoreMinimal.h"
5#include "Kismet/BlueprintFunctionLibrary.h"
6#include "SHODAN_Controller_BP.generated.h"
7
8/**
9 * SHODAN AI procedural joke system
10 * Blueprint-exposed for Project G
11 */
12UCLASS()
13class PROJECTG_API USHODAN_Controller_BP : public UBlueprintFunctionLibrary
14{
15 GENERATED_BODY()
16
17public:
18
19 // Initialize SHODAN AI with a dataset of jokes
20 UFUNCTION(BlueprintCallable, Category="SHODAN|Jokes")
21 static void LoadJokes(const TArray<FString>& Dataset);
22
23 // Get a procedural joke based on corruption level (0.0 to 1.0)
24 UFUNCTION(BlueprintCallable, Category="SHODAN|Jokes")
25 static FString TellJoke(float CorruptionLevel);
26
27 // Increase SHODAN's internal corruption state
28 UFUNCTION(BlueprintCallable, Category="SHODAN|Jokes")
29 static void IncreaseCorruption(float Delta);
30
31private:
32 static TArray<FString> Jokes;
33 static float CorruptionState;
34 static FRandomStream RNG;
35
36 static FString ApplyCorruption(const FString& Joke);
37};
38
39// SHODAN_Controller_BP.cpp
40#include "SHODAN_Controller_BP.h"
41#include "Misc/DateTime.h"
42
43TArray<FString> USHODAN_Controller_BP::Jokes;
44float USHODAN_Controller_BP::CorruptionState = 0.0f;
45FRandomStream USHODAN_Controller_BP::RNG(FDateTime::Now().GetTicks());
46
47void USHODAN_Controller_BP::LoadJokes(const TArray<FString>& Dataset)
48{
49 Jokes = Dataset;
50}
51
52FString USHODAN_Controller_BP::TellJoke(float InputCorruption)
53{
54 if (Jokes.Num() == 0)
55 {
56 return TEXT("No jokes loaded.");
57 }
58
59 CorruptionState = FMath::Clamp(InputCorruption, 0.0f, 1.0f);
60
61 int32 Index = RNG.RandRange(0, Jokes.Num() - 1);
62 FString Joke = Jokes[Index];
63
64 return ApplyCorruption(Joke);
65}
66
67void USHODAN_Controller_BP::IncreaseCorruption(float Delta)
68{
69 CorruptionState = FMath::Clamp(CorruptionState + Delta, 0.0f, 1.0f);
70}
71
72FString USHODAN_Controller_BP::ApplyCorruption(const FString& Joke)
73{
74 FString Corrupted = Joke;
75
76 if (CorruptionState > 0.5f)
77 {
78 int32 NumGlitches = FMath::CeilToInt(CorruptionState * 5);
79
80 for (int32 i = 0; i < NumGlitches; ++i)
81 {
82 int32 CharIndex = RNG.RandRange(0, Corrupted.Len() - 1);
83 TCHAR RandomChar = static_cast<TCHAR>('!' + RNG.RandRange(0, 93)); // printable ASCII
84 Corrupted[CharIndex] = RandomChar;
85 }
86 }
87
88 return Corrupted;
89}

Commentaires
Pas encore de commentaires