Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions soh/soh/Enhancements/ExtraModes/EnemyRandomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,9 +947,21 @@ void RegisterEnemyRandomizerWidgets() {
"- Random: Enemies are randomized every time you load a room.\n"
"- Random (Seeded): Enemies are randomized based on the current randomizer seed/file.\n"));

SohGui::mSohMenu->AddWidget(path, "Randomized Enemy Sizes", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_ENHANCEMENT("RandomizedEnemySizes"))
.Options(UIWidgets::CheckboxOptions().Tooltip("Enemies and Bosses spawn with random sizes."));
static const std::map<int32_t, const char*> enemySizeModes = {
{ ENEMY_SIZE_OFF, "Disabled" },
{ ENEMY_SIZE_RANDOM, "Random" },
{ ENEMY_SIZE_RANDOM_SEEDED, "Random (Seeded)" }
};

SohGui::mSohMenu->AddWidget(path, "Randomized Enemy Sizes", WIDGET_CVAR_COMBOBOX)
.CVar(CVAR_ENHANCEMENT("RandomizedEnemySizes"))
.Options(
UIWidgets::ComboboxOptions()
.DefaultIndex(ENEMY_SIZE_OFF)
.ComboMap(enemySizeModes)
.Tooltip("Enemies and bosses spawn with random sizes.\n\n"
"- Random: Sizes are randomized every time you load a room.\n"
"- Random (Seeded): Sizes are consistent based on the current randomizer seed/file.\n"));

SohGui::mSohMenu->AddWidget(path, "Scale Health with Size", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_ENHANCEMENT("EnemySizeScalesHealth"))
Expand Down
65 changes: 48 additions & 17 deletions soh/soh/Enhancements/ExtraModes/RandomizedEnemySizes.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
#include "soh/ObjectExtension/ActorMaximumHealth.h"
#include "soh/ShipInit.hpp"
#include "soh/ShipUtils.h"
#include "soh/Enhancements/enhancementTypes.h"
#include "soh/Enhancements/randomizer/SeedContext.h"

extern "C" {
#include "functions.h"
Expand All @@ -15,6 +18,50 @@ static constexpr int32_t CVAR_ENEMY_SCALE_HEALTH_DEFAULT = 0;
#define CVAR_ENEMY_SCALE_HEALTH_NAME CVAR_ENHANCEMENT("EnemySizeScalesHealth")
#define CVAR_ENEMY_SCALE_HEALTH_VALUE CVarGetInteger(CVAR_ENEMY_SCALE_HEALTH_NAME, CVAR_ENEMY_SCALE_HEALTH_DEFAULT)

static float ComputeRandomScale(Actor* actor, bool isSmallOnly) {
const int32_t mode = CVAR_RANDO_ENEMY_SIZE_VALUE;
float randomNumber = 0.0f;
bool isBigActor = false;
Comment thread
unreference marked this conversation as resolved.
static uint64_t randomState = 0;

if (mode == ENEMY_SIZE_RANDOM_SEEDED) {
// Deterministic seed from actor spawn data + global seed, matching the pattern used by the enemy randomizer
// (EnemyRandomizer.cpp). The salt (0xDEAD) decorrelates the sequence from the enemy replacement RNG so that
// the size and enemy type don't share the same initial state when both systems use the same actor ID and
// position.
const uint32_t seed = gPlayState->sceneNum + actor->id + static_cast<int32_t>(actor->home.pos.x) +
static_cast<int32_t>(actor->home.pos.y) + static_cast<int32_t>(actor->home.pos.z) +
actor->home.rot.x + actor->home.rot.y + actor->home.rot.z + actor->params;

ShipUtils::RandInit(
(seed ^ 0xDEAD) + (IS_RANDO
? Rando::Context::GetInstance()->GetSeed()
: gSaveContext.ship.stats.fileCreatedAt),
&randomState);

isBigActor = !isSmallOnly && ShipUtils::Random(0, 2, &randomState) == 1;
if (isBigActor) {
// Between 100% and 300% size.
randomNumber = static_cast<float>(ShipUtils::Random(0, 200, &randomState));
return 1.0f + randomNumber / 100.0f;
}

// Between 10% and 100% size.
randomNumber = static_cast<float>(ShipUtils::Random(0, 90, &randomState));
return 0.1f + randomNumber / 100.0f;
}

// Unseeded random -- different every room load.
isBigActor = !isSmallOnly && ShipUtils::Random(0, 2, &randomState) == 1;
if (isBigActor) {
randomNumber = ShipUtils::Random(0, 200, &randomState);
return 1.0f + randomNumber / 100.0f;
}

randomNumber = ShipUtils::Random(0, 90, &randomState);
return 0.1f + randomNumber / 100.0f;
}

static void RandomizedEnemySizes(void* refActor) {
// Randomized Enemy Sizes
Actor* actor = static_cast<Actor*>(refActor);
Expand All @@ -30,27 +77,11 @@ static void RandomizedEnemySizes(void* refActor) {
return;
}

float randomNumber;
float randomScale;

// Dodongo, Volvagia and Dead Hand are always smaller because they're impossible when bigger.
bool smallOnlyEnemy = actor->id == ACTOR_BOSS_DODONGO || actor->id == ACTOR_BOSS_FD ||
actor->id == ACTOR_BOSS_FD2 || actor->id == ACTOR_EN_DH;

bool bigActor = !smallOnlyEnemy && (rand() % 2);

// Big actor
if (bigActor) {
randomNumber = rand() % 200;
// Between 100% and 300% size.
randomScale = 1.0f + (randomNumber / 100);
} else {
// Small actor
randomNumber = rand() % 90;
// Between 10% and 100% size.
randomScale = 0.1f + (randomNumber / 100);
}

const float randomScale = ComputeRandomScale(actor, smallOnlyEnemy);
Actor_SetScale(actor, actor->scale.z * randomScale);

if (CVAR_ENEMY_SCALE_HEALTH_VALUE && (actor->category == ACTORCAT_ENEMY)) {
Expand Down
6 changes: 6 additions & 0 deletions soh/soh/Enhancements/enhancementTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ typedef enum {
ENEMY_RANDOMIZER_RANDOM_SEEDED,
} EnemyRandomizerMode;

typedef enum {
ENEMY_SIZE_OFF,
ENEMY_SIZE_RANDOM,
ENEMY_SIZE_RANDOM_SEEDED,
} EnemySizeMode;

typedef enum {
BOOTSEQUENCE_DEFAULT,
BOOTSEQUENCE_AUTHENTIC,
Expand Down