Skip to content

Commit

Permalink
random_chance opcode added
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC committed Nov 27, 2024
1 parent eb1ec85 commit 04bef74
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
- new opcode **2705 ([pick_random_int](https://library.sannybuilder.com/#/sa/math/2705))**
- new opcode **2706 ([pick_random_float](https://library.sannybuilder.com/#/sa/math/2706))**
- new opcode **2707 ([pick_random_text](https://library.sannybuilder.com/#/sa/math/2707))**
- new opcode **2708 ([random_chance](https://library.sannybuilder.com/#/sa/math/2708))**
- new [MemoryOperations](https://github.com/cleolibrary/CLEO5/tree/master/cleo_plugins/MemoryOperations) plugin
- memory related opcodes moved from CLEO core into separated plugin
- validation of input and output parameters for all opcodes
Expand Down
15 changes: 15 additions & 0 deletions cleo_plugins/Math/Math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Math
CLEO_RegisterOpcode(0x2705, opcode_2705); // pick_random_int
CLEO_RegisterOpcode(0x2706, opcode_2706); // pick_random_float
CLEO_RegisterOpcode(0x2707, opcode_2707); // pick_random_text
CLEO_RegisterOpcode(0x2708, opcode_2708); // random_chance
}

//0098=1,generate_random_float
Expand Down Expand Up @@ -577,4 +578,18 @@ class Math
CLEO_SkipUnusedVarArgs(thread);
return OR_CONTINUE;
}

//2708=1,random_chance %1d%
static OpcodeResult WINAPI opcode_2708(CRunningScript* thread)
{
auto chance = OPCODE_READ_PARAM_FLOAT();

uniform_real_distribution<float> dist(0.0f, 100.0f); // 0.0 to 99.99(9)
auto random = dist(Instance.randomGenerator);

auto result = random < chance;

OPCODE_CONDITION_RESULT(result);
return OR_CONTINUE;
}
} Instance;

0 comments on commit 04bef74

Please sign in to comment.