Skip to content

Commit

Permalink
Boulder Shuffle - Shuffles all Boulders randomly
Browse files Browse the repository at this point in the history
  • Loading branch information
Caladius committed Nov 19, 2024
1 parent d9d831f commit cdfb359
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 9 deletions.
84 changes: 76 additions & 8 deletions soh/soh/Enhancements/Holiday/Caladius.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Holiday.hpp"
#include "soh/Notification/Notification.h"
#include "soh/Enhancements/gameplaystats.h"
#include "soh/Enhancements/game-interactor/GameInteractor.h"

extern "C" {
#include "macros.h"
Expand All @@ -17,6 +18,8 @@ uint64_t GetUnixTimestamp();
bool isDisabled = false;
float fontScale = 1.0f;

std::vector<ActorID> boulderList = { ACTOR_OBJ_BOMBIWA, ACTOR_BG_ICE_SHELTER, ACTOR_EN_ISHI, ACTOR_OBJ_HAMISHI };

std::string formatTimestampIceTrapFever(uint32_t value) {
uint32_t sec = value / 10;
uint32_t hh = sec / 3600;
Expand All @@ -40,8 +43,66 @@ int32_t calculateRemainingTime() {
return timeRemaining;
}

static void OnConfigurationChanged() {
isDisabled = !CVarGetInteger(CVAR("Enabled"), 0);
s32 ActorSnapToFloor(Actor* refActor, PlayState* play, f32 arg2) {
CollisionPoly* poly;
Vec3f pos;
s32 bgId;
f32 floorY;

pos.x = refActor->world.pos.x;
pos.y = refActor->world.pos.y + 30.0f;
pos.z = refActor->world.pos.z;
floorY = BgCheck_EntityRaycastFloor4(&play->colCtx, &poly, &bgId, refActor, &pos);
if (floorY > BGCHECK_Y_MIN) {
refActor->world.pos.y = floorY + arg2;
Math_Vec3f_Copy(&refActor->home.pos, &refActor->world.pos);
}
return refActor->world.pos.y;
}

void RandomizeBoulder(Actor* refActor) {
Actor* actor = (Actor*) refActor;
int16_t param = actor->params;
int32_t yAdj = 0;
uint32_t roll = rand() % boulderList.size();
if (boulderList[roll] == ACTOR_EN_ISHI) {
param = 3;
}
yAdj = ActorSnapToFloor(actor, gPlayState, 0.0f);
//if (actor->id != ACTOR_EN_ISHI && boulderList[roll] == ACTOR_EN_ISHI) {
// yAdj = 20;
//}
//if (actor->id == ACTOR_EN_ISHI && boulderList[roll] != ACTOR_EN_ISHI) {
// yAdj = -20;
//}

Actor_Spawn(&gPlayState->actorCtx, gPlayState, boulderList[roll], actor->world.pos.x, ActorSnapToFloor(actor, gPlayState, 0.0f),
actor->world.pos.z, 0, 0, 0, param, false);
Actor_Kill(actor);
}

static void OnBlitzChange() {
COND_HOOK(OnSceneSpawnActors, CVarGetInteger(CVAR("Blitz.Enabled"), 0), []() {
if (!gPlayState) {
return;
}
ActorListEntry boulders = gPlayState->actorCtx.actorLists[ACTORCAT_PROP];
Actor* currentActor = boulders.head;
if (currentActor != nullptr) {
while (currentActor != nullptr) {
for (auto& boulderActor : boulderList) {
if (currentActor->id == boulderActor) {
RandomizeBoulder(currentActor);
}
}
currentActor = currentActor->next;
}
}
});
}

static void OnFeverConfigurationChanged() {
isDisabled = !CVarGetInteger(CVAR("Fever.Enabled"), 0);
fontScale = CVarGetFloat(CVAR("FontScale"), 1.0f);
if (fontScale < 1.0f) {
fontScale = 1.0f;
Expand All @@ -55,7 +116,7 @@ static void OnConfigurationChanged() {
}

void CaladiusWindow::Draw() {
if (!CVarGetInteger(CVAR("Enabled"), 0)) {
if (!CVarGetInteger(CVAR("Fever.Enabled"), 0)) {
return;
}

Expand All @@ -80,24 +141,31 @@ void CaladiusWindow::Draw() {

static void DrawMenu() {
ImGui::SeparatorText(AUTHOR);
if (UIWidgets::EnhancementCheckbox("Holiday Fever", CVAR("Enabled"))) {
OnConfigurationChanged();
if (UIWidgets::EnhancementCheckbox("Holiday Fever", CVAR("Fever.Enabled"))) {
OnFeverConfigurationChanged();
}
UIWidgets::Tooltip("Can you beat your objective before the Fever sets in?\n"
UIWidgets::Tooltip("Can you beat your objective before the Fever sets in?/n"
"- Obtaining Ice Traps extends your timer.");
ImGui::Text("Options");
if (UIWidgets::PaddedEnhancementSliderFloat("", "##FontScale", CVAR("FontScale"),
1.0f, 5.0f, "%.1fx", 1.0f, false, false, false, false, isDisabled)) {
OnConfigurationChanged();
OnFeverConfigurationChanged();
}
UIWidgets::PaddedEnhancementSliderInt("Starting Timer: %d minutes", "##StartTime", CVAR("StartTimer"),
5, 30, "", 15, true, true, false, isDisabled);
UIWidgets::PaddedEnhancementSliderInt("Time Extensions: %d minutes", "##ExtendTime", CVAR("ExtendTimer"),
1, 10, "", 5, true, true, false, isDisabled);
UIWidgets::PaddedSeparator();

if (UIWidgets::EnhancementCheckbox("Boulder Blitz", CVAR("Blitz.Enabled"))) {
OnBlitzChange();
}
}


static void RegisterMod() {
OnConfigurationChanged();
OnFeverConfigurationChanged();
OnBlitzChange();
}

static Holiday holiday(DrawMenu, RegisterMod);
2 changes: 1 addition & 1 deletion soh/src/code/z_actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -3297,7 +3297,7 @@ Actor* Actor_Spawn(ActorContext* actorCtx, PlayState* play, s16 actorId, f32 pos

objBankIndex = Object_GetIndex(&gPlayState->objectCtx, dbEntry->objectId);

if (objBankIndex < 0 && (!gMapLoading || CVarGetInteger(CVAR_ENHANCEMENT("RandomizedEnemies"), 0))) {
if (objBankIndex < 0 && (!gMapLoading || CVarGetInteger(CVAR_ENHANCEMENT("RandomizedEnemies"), 0) || CVarGetInteger("gHoliday.Caladius.Blitz.Enabled", 0))) {
objBankIndex = 0;
}

Expand Down

0 comments on commit cdfb359

Please sign in to comment.