From faf617739f53c67f663887de34342f92056ba45d Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Tue, 6 Nov 2018 09:59:34 -0800 Subject: Assorted. --- Source/Randomizer.cpp | 106 +++++++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 52 deletions(-) (limited to 'Source/Randomizer.cpp') diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index 8833078..3cc2712 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp @@ -1,16 +1,13 @@ /* * BUGS: - * Shipwreck vault is solved reversed? - * Swamp <-> symmetry has non-invisible background - * Tutorial sounds don't always play + * Shipwreck vault is solved reversed? -> Not reversed, just "half", you can normally solve orange. Seems to need pattern name. + * Tutorial sounds don't always play -> Unsure. Not controlled by pattern name. * FEATURES: - * Clear "Randomized" button after short delay * Randomize audio logs -- Hard, seem to be unloaded some times? * Swap sounds in jungle (along with panels) -- maybe impossible - * Make orange 7 (all of oranges?) hard. Like big = hard. + * Make orange 7 (all of oranges?) hard. Like big = hard. (See: HARD_MODE) * Start the game if it isn't running? * Stop swapping colors in desert - * Allow users to enter seed after randomly generating seed (aka detect user input in the text box) */ #include "Memory.h" #include "Randomizer.h" @@ -29,15 +26,21 @@ int find(const std::vector &data, T search, size_t startIndex = 0) { exit(-1); } -short Randomizer::Randomize(int seed) -{ - short metadata = _core.ReadMetadata(); - if (metadata & 0x1) { - // Already randomized -- exit. - return metadata; +bool Randomizer::GameIsRandomized() { + int currentFrame = _core.GetCurrentFrame(); + if (currentFrame >= _lastRandomizedFrame) { + // Time went forwards, presumably we're still on the same save + _lastRandomizedFrame = currentFrame; + return true; } - _core.WriteMetadata(metadata | 0x1); - Random::SetSeed(seed); + // Otherwise, time has gone backwards, so assume new game + return false; +} + +void Randomizer::Randomize() +{ + if (GameIsRandomized()) return; // Nice sanity check, but should be unnecessary (since Main checks anyways) + _lastRandomizedFrame = _core.GetCurrentFrame(); // Content swaps -- must happen before squarePanels _core.Randomize(upDownPanels, SWAP_LINES); @@ -61,24 +64,23 @@ short Randomizer::Randomize(int seed) RandomizeMountain(); // RandomizeChallenge(); // RandomizeAudioLogs(); - return metadata; } void Randomizer::AdjustSpeed() { // Desert Surface Final Control - _core._memory.WritePanelData(0x09F95, OPEN_RATE, {0.04f}); // 4x + _core._memory->WritePanelData(0x09F95, OPEN_RATE, {0.04f}); // 4x // Swamp Sliding Bridge - _core._memory.WritePanelData(0x0061A, OPEN_RATE, {0.1f}); // 4x + _core._memory->WritePanelData(0x0061A, OPEN_RATE, {0.1f}); // 4x // Mountain 2 Elevator - _core._memory.WritePanelData(0x09EEC, OPEN_RATE, {0.075f}); // 3x + _core._memory->WritePanelData(0x09EEC, OPEN_RATE, {0.075f}); // 3x } void Randomizer::RandomizeTutorial() { // Disable tutorial cursor speed modifications (not working?) - _core._memory.WritePanelData(0x00295, CURSOR_SPEED_SCALE, {1.0}); - _core._memory.WritePanelData(0x0C373, CURSOR_SPEED_SCALE, {1.0}); - _core._memory.WritePanelData(0x00293, CURSOR_SPEED_SCALE, {1.0}); - _core._memory.WritePanelData(0x002C2, CURSOR_SPEED_SCALE, {1.0}); + _core._memory->WritePanelData(0x00295, CURSOR_SPEED_SCALE, {1.0}); + _core._memory->WritePanelData(0x0C373, CURSOR_SPEED_SCALE, {1.0}); + _core._memory->WritePanelData(0x00293, CURSOR_SPEED_SCALE, {1.0}); + _core._memory->WritePanelData(0x002C2, CURSOR_SPEED_SCALE, {1.0}); } void Randomizer::RandomizeSymmetry() { @@ -88,11 +90,11 @@ void Randomizer::RandomizeDesert() { _core.Randomize(desertPanels, SWAP_LINES); // Turn off desert surface 8 - _core._memory.WritePanelData(0x09F94, POWER, {0.0, 0.0}); + _core._memory->WritePanelData(0x09F94, POWER, {0.0, 0.0}); // Turn off desert flood final - _core._memory.WritePanelData(0x18076, POWER, {0.0, 0.0}); + _core._memory->WritePanelData(0x18076, POWER, {0.0, 0.0}); // Change desert floating target to desert flood final - _core._memory.WritePanelData(0x17ECA, TARGET, {0x18077}); + _core._memory->WritePanelData(0x17ECA, TARGET, {0x18077}); } void Randomizer::RandomizeQuarry() { @@ -100,14 +102,14 @@ void Randomizer::RandomizeQuarry() { void Randomizer::RandomizeTreehouse() { // Ensure that whatever pivot panels we have are flagged as "pivotable" - int panelFlags = _core._memory.ReadPanelData(0x17DD1, STYLE_FLAGS, 1)[0]; - _core._memory.WritePanelData(0x17DD1, STYLE_FLAGS, {panelFlags | 0x8000}); - panelFlags = _core._memory.ReadPanelData(0x17CE3, STYLE_FLAGS, 1)[0]; - _core._memory.WritePanelData(0x17CE3, STYLE_FLAGS, {panelFlags | 0x8000}); - panelFlags = _core._memory.ReadPanelData(0x17DB7, STYLE_FLAGS, 1)[0]; - _core._memory.WritePanelData(0x17DB7, STYLE_FLAGS, {panelFlags | 0x8000}); - panelFlags = _core._memory.ReadPanelData(0x17E52, STYLE_FLAGS, 1)[0]; - _core._memory.WritePanelData(0x17E52, STYLE_FLAGS, {panelFlags | 0x8000}); + int panelFlags = _core._memory->ReadPanelData(0x17DD1, STYLE_FLAGS, 1)[0]; + _core._memory->WritePanelData(0x17DD1, STYLE_FLAGS, {panelFlags | 0x8000}); + panelFlags = _core._memory->ReadPanelData(0x17CE3, STYLE_FLAGS, 1)[0]; + _core._memory->WritePanelData(0x17CE3, STYLE_FLAGS, {panelFlags | 0x8000}); + panelFlags = _core._memory->ReadPanelData(0x17DB7, STYLE_FLAGS, 1)[0]; + _core._memory->WritePanelData(0x17DB7, STYLE_FLAGS, {panelFlags | 0x8000}); + panelFlags = _core._memory->ReadPanelData(0x17E52, STYLE_FLAGS, 1)[0]; + _core._memory->WritePanelData(0x17E52, STYLE_FLAGS, {panelFlags | 0x8000}); } void Randomizer::RandomizeKeep() { @@ -115,11 +117,11 @@ void Randomizer::RandomizeKeep() { void Randomizer::RandomizeShadows() { // Distance-gate shadows laser to prevent sniping through the bars - _core._memory.WritePanelData(0x19650, MAX_BROADCAST_DISTANCE, {2.5}); + _core._memory->WritePanelData(0x19650, MAX_BROADCAST_DISTANCE, {2.5}); // Change the shadows tutorial cable to only activate avoid - _core._memory.WritePanelData(0x319A8, CABLE_TARGET_2, {0}); + _core._memory->WritePanelData(0x319A8, CABLE_TARGET_2, {0}); // Change shadows avoid 8 to power shadows follow - _core._memory.WritePanelData(0x1972F, TARGET, {0x1C34C}); + _core._memory->WritePanelData(0x1972F, TARGET, {0x1C34C}); std::vector randomOrder(shadowsPanels.size(), 0); std::iota(randomOrder.begin(), randomOrder.end(), 0); @@ -128,9 +130,9 @@ void Randomizer::RandomizeShadows() { _core.RandomizeRange(randomOrder, SWAP_NONE, 16, 21); // Follow _core.ReassignTargets(shadowsPanels, randomOrder); // Turn off original starting panel - _core._memory.WritePanelData(shadowsPanels[0], POWER, {0.0f, 0.0f}); + _core._memory->WritePanelData(shadowsPanels[0], POWER, {0.0f, 0.0f}); // Turn on new starting panel - _core._memory.WritePanelData(shadowsPanels[randomOrder[0]], POWER, {1.0f, 1.0f}); + _core._memory->WritePanelData(shadowsPanels[randomOrder[0]], POWER, {1.0f, 1.0f}); } void Randomizer::RandomizeTown() { @@ -167,7 +169,7 @@ void Randomizer::RandomizeJungle() { void Randomizer::RandomizeSwamp() { // Distance-gate swamp snipe 1 to prevent RNG swamp snipe - _core._memory.WritePanelData(0x17C05, MAX_BROADCAST_DISTANCE, {15.0}); + _core._memory->WritePanelData(0x17C05, MAX_BROADCAST_DISTANCE, {15.0}); } void Randomizer::RandomizeMountain() { @@ -178,7 +180,7 @@ void Randomizer::RandomizeMountain() { // Randomize final pillars order std::vector targets = {pillars[0] + 1}; for (const int pillar : pillars) { - int target = _core._memory.ReadPanelData(pillar, TARGET, 1)[0]; + int target = _core._memory->ReadPanelData(pillar, TARGET, 1)[0]; targets.push_back(target); } targets[5] = pillars[5] + 1; @@ -189,27 +191,27 @@ void Randomizer::RandomizeMountain() { _core.RandomizeRange(randomOrder, SWAP_NONE, 5, 9); // Right Pillars 1-4 _core.ReassignTargets(pillars, randomOrder, targets); // Turn off original starting panels - _core._memory.WritePanelData(pillars[0], POWER, {0.0f, 0.0f}); - _core._memory.WritePanelData(pillars[5], POWER, {0.0f, 0.0f}); + _core._memory->WritePanelData(pillars[0], POWER, {0.0f, 0.0f}); + _core._memory->WritePanelData(pillars[5], POWER, {0.0f, 0.0f}); // Turn on new starting panels - _core._memory.WritePanelData(pillars[randomOrder[0]], POWER, {1.0f, 1.0f}); - _core._memory.WritePanelData(pillars[randomOrder[5]], POWER, {1.0f, 1.0f}); + _core._memory->WritePanelData(pillars[randomOrder[0]], POWER, {1.0f, 1.0f}); + _core._memory->WritePanelData(pillars[randomOrder[5]], POWER, {1.0f, 1.0f}); // Read the target of keep front laser, and write it to keep back laser. - std::vector keepFrontLaserTarget = _core._memory.ReadPanelData(0x0360E, TARGET, 1); - _core._memory.WritePanelData(0x03317, TARGET, keepFrontLaserTarget); + std::vector keepFrontLaserTarget = _core._memory->ReadPanelData(0x0360E, TARGET, 1); + _core._memory->WritePanelData(0x03317, TARGET, keepFrontLaserTarget); } void Randomizer::RandomizeChallenge() { std::vector randomOrder(challengePanels.size(), 0); std::iota(randomOrder.begin(), randomOrder.end(), 0); _core.RandomizeRange(randomOrder, SWAP_NONE, 1, 9); // Easy maze - Triple 2 - std::vector triple1Target = _core._memory.ReadPanelData(0x00C80, TARGET, 1); - _core._memory.WritePanelData(0x00CA1, TARGET, triple1Target); - _core._memory.WritePanelData(0x00CB9, TARGET, triple1Target); - std::vector triple2Target = _core._memory.ReadPanelData(0x00C22, TARGET, 1); - _core._memory.WritePanelData(0x00C59, TARGET, triple2Target); - _core._memory.WritePanelData(0x00C68, TARGET, triple2Target); + std::vector triple1Target = _core._memory->ReadPanelData(0x00C80, TARGET, 1); + _core._memory->WritePanelData(0x00CA1, TARGET, triple1Target); + _core._memory->WritePanelData(0x00CB9, TARGET, triple1Target); + std::vector triple2Target = _core._memory->ReadPanelData(0x00C22, TARGET, 1); + _core._memory->WritePanelData(0x00C59, TARGET, triple2Target); + _core._memory->WritePanelData(0x00C68, TARGET, triple2Target); _core.ReassignTargets(challengePanels, randomOrder); } -- cgit 1.4.1