summary refs log tree commit diff stats
path: root/Source/RandomizerCore.cpp
diff options
context:
space:
mode:
authorjbzdarkid <jbzdarkid@gmail.com>2018-11-06 09:59:34 -0800
committerjbzdarkid <jbzdarkid@gmail.com>2018-11-06 09:59:34 -0800
commitfaf617739f53c67f663887de34342f92056ba45d (patch)
treeea7b4d50b00de8d16fa7f76257972faf143d79e1 /Source/RandomizerCore.cpp
parentb54945cf95fa7e4ccc87525d2896901a8f11fe12 (diff)
downloadwitness-tutorializer-faf617739f53c67f663887de34342f92056ba45d.tar.gz
witness-tutorializer-faf617739f53c67f663887de34342f92056ba45d.tar.bz2
witness-tutorializer-faf617739f53c67f663887de34342f92056ba45d.zip
Assorted.
Diffstat (limited to 'Source/RandomizerCore.cpp')
-rw-r--r--Source/RandomizerCore.cpp39
1 files changed, 16 insertions, 23 deletions
diff --git a/Source/RandomizerCore.cpp b/Source/RandomizerCore.cpp index d4aadef..f00dacd 100644 --- a/Source/RandomizerCore.cpp +++ b/Source/RandomizerCore.cpp
@@ -3,17 +3,6 @@
3#include "Random.h" 3#include "Random.h"
4#include <sstream> 4#include <sstream>
5 5
6static int lastKnownFrame = 1 << 30;
7
8RandomizerCore::RandomizerCore() {
9 int currentFrame = _memory.ReadData<int>({SCRIPT_FRAMES}, 1)[0];
10 if (currentFrame < lastKnownFrame) {
11 // Time went backwards, indicates new game
12 WriteMetadata(0);
13 }
14 lastKnownFrame = currentFrame;
15}
16
17void RandomizerCore::Randomize(std::vector<int>& panels, int flags) { 6void RandomizerCore::Randomize(std::vector<int>& panels, int flags) {
18 return RandomizeRange(panels, flags, 0, panels.size()); 7 return RandomizeRange(panels, flags, 0, panels.size());
19} 8}
@@ -47,7 +36,7 @@ void RandomizerCore::SwapPanels(int panel1, int panel2, int flags) {
47 offsets[REFLECTION_PATH_COLOR] = 16; 36 offsets[REFLECTION_PATH_COLOR] = 16;
48 offsets[DOT_COLOR] = 16; 37 offsets[DOT_COLOR] = 16;
49 offsets[ACTIVE_COLOR] = 16; 38 offsets[ACTIVE_COLOR] = 16;
50 offsets[BACKGROUND_REGION_COLOR] = 16; 39 offsets[BACKGROUND_REGION_COLOR] = 12; // Not copying alpha to preserve transparency.
51 offsets[SUCCESS_COLOR_A] = 16; 40 offsets[SUCCESS_COLOR_A] = 16;
52 offsets[SUCCESS_COLOR_B] = 16; 41 offsets[SUCCESS_COLOR_B] = 16;
53 offsets[STROBE_COLOR_A] = 16; 42 offsets[STROBE_COLOR_A] = 16;
@@ -101,10 +90,10 @@ void RandomizerCore::SwapPanels(int panel1, int panel2, int flags) {
101 } 90 }
102 91
103 for (auto const& [offset, size] : offsets) { 92 for (auto const& [offset, size] : offsets) {
104 std::vector<byte> panel1data = _memory.ReadPanelData<byte>(panel1, offset, size); 93 std::vector<byte> panel1data = _memory->ReadPanelData<byte>(panel1, offset, size);
105 std::vector<byte> panel2data = _memory.ReadPanelData<byte>(panel2, offset, size); 94 std::vector<byte> panel2data = _memory->ReadPanelData<byte>(panel2, offset, size);
106 _memory.WritePanelData<byte>(panel2, offset, panel1data); 95 _memory->WritePanelData<byte>(panel2, offset, panel1data);
107 _memory.WritePanelData<byte>(panel1, offset, panel2data); 96 _memory->WritePanelData<byte>(panel1, offset, panel2data);
108 } 97 }
109} 98}
110 99
@@ -114,7 +103,7 @@ void RandomizerCore::ReassignTargets(const std::vector<int>& panels, const std::
114 // The first panel may not have a wire to power it, so we use the panel ID itself. 103 // The first panel may not have a wire to power it, so we use the panel ID itself.
115 targets = {panels[0] + 1}; 104 targets = {panels[0] + 1};
116 for (const int panel : panels) { 105 for (const int panel : panels) {
117 int target = _memory.ReadPanelData<int>(panel, TARGET, 1)[0]; 106 int target = _memory->ReadPanelData<int>(panel, TARGET, 1)[0];
118 targets.push_back(target); 107 targets.push_back(target);
119 } 108 }
120 } 109 }
@@ -122,25 +111,29 @@ void RandomizerCore::ReassignTargets(const std::vector<int>& panels, const std::
122 for (size_t i=0; i<order.size() - 1; i++) { 111 for (size_t i=0; i<order.size() - 1; i++) {
123 // Set the target of order[i] to order[i+1], using the "real" target as determined above. 112 // Set the target of order[i] to order[i+1], using the "real" target as determined above.
124 const int panelTarget = targets[order[i+1]]; 113 const int panelTarget = targets[order[i+1]];
125 _memory.WritePanelData<int>(panels[order[i]], TARGET, {panelTarget}); 114 _memory->WritePanelData<int>(panels[order[i]], TARGET, {panelTarget});
126 } 115 }
127} 116}
128 117
129void RandomizerCore::ReassignNames(const std::vector<int>& panels, const std::vector<int>& order) { 118void RandomizerCore::ReassignNames(const std::vector<int>& panels, const std::vector<int>& order) {
130 std::vector<int64_t> names; 119 std::vector<int64_t> names;
131 for (const int panel : panels) { 120 for (const int panel : panels) {
132 names.push_back(_memory.ReadPanelData<int64_t>(panel, AUDIO_LOG_NAME, 1)[0]); 121 names.push_back(_memory->ReadPanelData<int64_t>(panel, AUDIO_LOG_NAME, 1)[0]);
133 } 122 }
134 123
135 for (int i=0; i<panels.size(); i++) { 124 for (int i=0; i<panels.size(); i++) {
136 _memory.WritePanelData<int64_t>(panels[i], AUDIO_LOG_NAME, {names[order[i]]}); 125 _memory->WritePanelData<int64_t>(panels[i], AUDIO_LOG_NAME, {names[order[i]]});
137 } 126 }
138} 127}
139 128
140short RandomizerCore::ReadMetadata() { 129short RandomizerCore::ReadMetadata() {
141 return _memory.ReadData<short>({GLOBALS + METADATA}, 1)[0]; 130 return _memory->ReadData<short>({GLOBALS + METADATA}, 1)[0];
142} 131}
143 132
144void RandomizerCore::WriteMetadata(short metadata) { 133void RandomizerCore::WriteMetadata(short metadata) {
145 return _memory.WriteData<short>({GLOBALS + METADATA}, {metadata}); 134 return _memory->WriteData<short>({GLOBALS + METADATA}, {metadata});
146} \ No newline at end of file 135}
136
137int RandomizerCore::GetCurrentFrame() {
138 return _memory->ReadData<int>({SCRIPT_FRAMES}, 1)[0];
139}