Skip to content

Commit c4bbd41

Browse files
committed
use tiny rand
1 parent 1d6b31f commit c4bbd41

7 files changed

Lines changed: 15 additions & 19 deletions

File tree

src/classes/Rand.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ namespace horrible {
99
public:
1010
// Get a number between 0 and 100
1111
static int fast();
12+
13+
// Get a number between 0 and 2500, recommended to balance chances when firing every frame
14+
static int tiny();
1215
};
1316
};

src/classes/src/Rand.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@ using namespace geode::prelude;
1010
using namespace horrible;
1111

1212
int Rand::fast() {
13-
return static_cast<int>(GameToolbox::fast_rand()) % 200;
13+
return static_cast<int>(GameToolbox::fast_rand()) % 100;
14+
};
15+
16+
int Rand::tiny() {
17+
return static_cast<int>(GameToolbox::fast_rand()) % 2500;
1418
};

src/hooks/Gravity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class $modify(GravityPlayerObject, PlayerObject) {
1818
};
1919

2020
void updateJump(float p0) {
21-
auto rnd = Rand::fast();
21+
auto rnd = Rand::tiny();
2222

2323
if (m_fields->enabled) {
2424
float newGrav = std::round((static_cast<float>(rnd) / 100.f) * (2.5f) * 100.0f) / 100.0f;

src/hooks/Pause.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,20 @@
77
using namespace geode::prelude;
88
using namespace horrible;
99

10-
11-
1210
class $modify(RandomPausePlayerObject, PlayerObject) {
1311
struct Fields {
1412
bool enabled = horribleMod->getSavedValue<bool>("pauses", false);
15-
int chance = 0;
16-
};
17-
18-
bool init(int player, int ship, GJBaseGameLayer * gameLayer, CCLayer * layer, bool playLayer) {
19-
if (!PlayerObject::init(player, ship, gameLayer, layer, playLayer)) return false;
20-
21-
m_fields->chance = static_cast<int>(horribleMod->getSettingValue<int64_t>("pauses-chance"));
22-
log::debug("Random pause chance set to {}", m_fields->chance);
23-
24-
return true;
13+
int chance = static_cast<int>(horribleMod->getSettingValue<int64_t>("pauses-chance"));
2514
};
2615

2716
void update(float p0) {
2817
if (auto playLayer = PlayLayer::get()) {
2918
if (m_fields->enabled) {
30-
auto rnd = Rand::fast();
19+
auto rnd = Rand::tiny();
3120

3221
// if the rng is lower than the chance, pause the game
3322
if (rnd <= m_fields->chance) {
34-
log::debug("Pausing the game randomly");
23+
log::debug("Pausing the game randomly ({}/2500 < {})", rnd, m_fields->chance);
3524
playLayer->pauseGame(true); // pause the game randomly
3625
};
3726
};

src/hooks/RandomMirror.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class $modify(RandomMirrorGJBaseGameLayer, GJBaseGameLayer) {
2424
};
2525

2626
void update(float p0) {
27-
auto rnd = Rand::fast();
27+
auto rnd = Rand::tiny();
2828
// log::debug("gjbasegamelayer update chance {}", rnd);
2929

3030
if (m_fields->enabled) {

src/hooks/RandomSpeed.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class $modify(RandomSpeedPlayerObject, PlayerObject) {
1818
void update(float p0) {
1919
if (auto playLayer = PlayLayer::get()) {
2020
if (m_fields->enabled) {
21-
auto rnd = Rand::fast();
21+
auto rnd = Rand::tiny();
2222

2323
// if the rng is lower than the chance, change the speed
2424
if (rnd <= m_fields->chance) {

src/hooks/Sleepy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class $modify(SleepyPlayerObject, PlayerObject) {
5656
if (m_fields->enabled) {
5757
// player sleepy if not already in any stage
5858
if (!m_fields->sleepy && !m_fields->waking) {
59-
auto rnd = Rand::fast();
59+
auto rnd = Rand::tiny();
6060

6161
// if the rng is lower than the chance, make the player sleepy
6262
if (rnd <= m_fields->chance) {

0 commit comments

Comments
 (0)