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