Skip to content

Commit 9f35fb8

Browse files
authored
Merge pull request #152 from gymnast86/hint-message-fix
Fix hint messages getting overwritten
2 parents 6d42a4e + af78352 commit 9f35fb8

File tree

6 files changed

+151
-131
lines changed

6 files changed

+151
-131
lines changed

logic/Hints.cpp

Lines changed: 90 additions & 73 deletions
Large diffs are not rendered by default.

logic/Hints.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ enum struct HintType
2323
LOCATION,
2424
};
2525

26+
class Location;
2627
struct Hint
2728
{
2829
// Message for this location (one for each language)
2930
std::unordered_map<std::string, std::u16string> text = {};
31+
Location* location;
3032
HintType type = HintType::NONE;
3133
};
3234

logic/SpoilerLog.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ static std::string getSpoilerFormatLocation(Location* location, const size_t& lo
5151
return location->getName() + locWorldNumber + ":" + spaces + itemName;
5252
}
5353

54-
static std::string getSpoilerFormatHint(Location* location)
54+
static std::string getSpoilerFormatHint(const Hint& hint)
5555
{
5656
// Get rid of commands in the hint text and then convert to UTF-8
57-
std::u16string hintText = location->hint.text["English"];
57+
std::u16string hintText = hint.text.at("English");
5858
for (const std::u16string& eraseText : {TEXT_COLOR_RED, TEXT_COLOR_BLUE, TEXT_COLOR_CYAN, TEXT_COLOR_DEFAULT, TEXT_COLOR_GREEN, TEXT_COLOR_GRAY, TEXT_COLOR_YELLOW})
5959
{
6060
auto pos = std::string::npos;
@@ -238,24 +238,24 @@ void generateSpoilerLog(WorldPool& worlds)
238238
for (auto& world : worlds)
239239
{
240240
// Don't print "Hints" if there are none
241-
if (world.hohoHints.empty() && world.korlHints.empty() && world.bigOctoFairyHintLocation == nullptr && world.kreebHints.empty() && world.korlHyruleHints.empty())
241+
if (world.hohoHints.empty() && world.korlHints.empty() && world.bigOctoFairyHint.location == nullptr && world.kreebHints.empty() && world.korlHyruleHints.empty())
242242
{
243243
continue;
244244
}
245245

246246
spoilerLog << std::endl << (worlds.size() == 1 ? "Hints:" : "Hints for world " + std::to_string(world.getWorldId()) + ":") << std::endl;
247247
if (!world.hohoHints.empty())
248248
{
249-
for (auto& [hohoLocation, hintLocations] : world.hohoHints)
249+
for (auto& [hohoLocation, hints] : world.hohoHints)
250250
{
251251
spoilerLog << " " << hohoLocation->getName() << ":" << std::endl;
252-
for (auto location : hintLocations)
252+
for (auto& hint : hints)
253253
{
254-
spoilerLog << " " << getSpoilerFormatHint(location);
254+
spoilerLog << " " << getSpoilerFormatHint(hint);
255255
// Show what item/location was being referred to with each path hint
256-
if (location->hint.type == HintType::PATH)
256+
if (hint.type == HintType::PATH)
257257
{
258-
spoilerLog << " (" << location->currentItem.getName() << " at " << location->getName() << ")";
258+
spoilerLog << " (" << hint.location->currentItem.getName() << " at " << hint.location->getName() << ")";
259259
}
260260
spoilerLog << std::endl;
261261
}
@@ -265,13 +265,13 @@ void generateSpoilerLog(WorldPool& worlds)
265265
if (!world.korlHints.empty())
266266
{
267267
spoilerLog << " KoRL Hints:" << std::endl;
268-
for (auto location : world.korlHints)
268+
for (auto& hint : world.korlHints)
269269
{
270-
spoilerLog << " " << getSpoilerFormatHint(location);
270+
spoilerLog << " " << getSpoilerFormatHint(hint);
271271
// Show what item/location was being referred to with each path hint
272-
if (location->hint.type == HintType::PATH)
272+
if (hint.type == HintType::PATH && hint.location)
273273
{
274-
spoilerLog << " (" << location->currentItem.getName() << " at " << location->getName() << ")";
274+
spoilerLog << " (" << hint.location->currentItem.getName() << " at " << hint.location->getName() << ")";
275275
}
276276
spoilerLog << std::endl;
277277
}
@@ -280,17 +280,17 @@ void generateSpoilerLog(WorldPool& worlds)
280280
if (!world.korlHyruleHints.empty())
281281
{
282282
spoilerLog << " KoRL Hyrule Hints:" << std::endl;
283-
for (auto location : world.korlHyruleHints)
283+
for (auto& hint : world.korlHyruleHints)
284284
{
285-
spoilerLog << " " << getSpoilerFormatHint(location);
285+
spoilerLog << " " << getSpoilerFormatHint(hint);
286286
spoilerLog << std::endl;
287287
}
288288
}
289289

290-
if (world.bigOctoFairyHintLocation != nullptr)
290+
if (world.bigOctoFairyHint.location != nullptr)
291291
{
292292
spoilerLog << " Big Octo Great Fairy:" << std::endl;
293-
std::u16string hintText = world.bigOctoFairyHintLocation->hint.text["English"];
293+
std::u16string hintText = world.bigOctoFairyHint.text["English"];
294294
for (const std::u16string& eraseText : {TEXT_COLOR_RED, TEXT_COLOR_BLUE, TEXT_COLOR_CYAN, TEXT_COLOR_DEFAULT, TEXT_COLOR_GREEN, TEXT_COLOR_GRAY, TEXT_COLOR_YELLOW})
295295
{
296296
auto pos = std::string::npos;
@@ -305,9 +305,9 @@ void generateSpoilerLog(WorldPool& worlds)
305305
if (!world.kreebHints.empty())
306306
{
307307
spoilerLog << " Kreeb Hints:" << std::endl;
308-
for (auto location : world.kreebHints)
308+
for (auto& hint : world.kreebHints)
309309
{
310-
spoilerLog << " " << getSpoilerFormatHint(location);
310+
spoilerLog << " " << getSpoilerFormatHint(hint);
311311
spoilerLog << std::endl;
312312
}
313313
}

logic/World.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <logic/ItemPool.hpp>
1414
#include <logic/Dungeon.hpp>
1515
#include <logic/Entrance.hpp>
16+
#include <logic/Hints.hpp>
1617
#include <logic/Plandomizer.hpp>
1718
#include <logic/WorldPool.hpp>
1819
#include <utility/text.hpp>
@@ -127,11 +128,11 @@ class World
127128
LocationPool raceModeLocations = {};
128129
std::list<Location*> goalLocations = {};
129130
std::map<std::string, std::unordered_set<Location*>> barrenRegions = {};
130-
std::list<Location*> korlHints = {};
131-
std::list<Location*> korlHyruleHints = {};
132-
std::list<Location*> kreebHints = {};
133-
std::map<Location*, std::unordered_set<Location*>, PointerLess<Location>> hohoHints = {}; // map of Ho Ho Hint Location to hinted locations
134-
Location* bigOctoFairyHintLocation = nullptr;
131+
std::list<Hint> korlHints = {};
132+
std::list<Hint> korlHyruleHints = {};
133+
std::list<Hint> kreebHints = {};
134+
std::map<Location*, std::list<Hint>> hohoHints = {}; // map of Ho Ho Hint Location to hints
135+
Hint bigOctoFairyHint{};
135136
std::list<std::list<Location*>> playthroughSpheres = {};
136137
std::list<std::list<Entrance*>> entranceSpheres = {};
137138
std::map<uint8_t, GameItem> chartMappings = {};

text_replacements.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ TextReplacements generate_text_replacements(World& world)
6161
auto& beedle500 = world.locationTable["Rock Spire Isle - Beedle 500 Rupee Item"]->currentItem;
6262
auto& beedle950 = world.locationTable["Rock Spire Isle - Beedle 950 Rupee Item"]->currentItem;
6363
auto& beedle900 = world.locationTable["Rock Spire Isle - Beedle 900 Rupee Item"]->currentItem;
64-
auto& octoFairyItem = world.bigOctoFairyHintLocation->currentItem;
65-
auto& octoFairyRegion = world.bigOctoFairyHintLocation->hintRegions.front();
64+
auto& octoFairyItem = world.bigOctoFairyHint.location->currentItem;
65+
auto& octoFairyRegion = world.bigOctoFairyHint.location->hintRegions.front();
6666

6767
LOG_TO_DEBUG("Calculating text replacement articles/pronouns");
6868
// Calculate articles for some replacements
@@ -133,9 +133,9 @@ TextReplacements generate_text_replacements(World& world)
133133
auto savageFloor50SpanishImportance = savageFloor50Loc->generateImportanceText("Spanish");
134134
auto savageFloor50FrenchImportance = savageFloor50Loc->generateImportanceText("French");
135135

136-
auto bigOctoFairyEnglishImportance = world.bigOctoFairyHintLocation->generateImportanceText("English");
137-
auto bigOctoFairySpanishImportance = world.bigOctoFairyHintLocation->generateImportanceText("Spanish");
138-
auto bigOctoFairyFrenchImportance = world.bigOctoFairyHintLocation->generateImportanceText("French");
136+
auto bigOctoFairyEnglishImportance = world.bigOctoFairyHint.location->generateImportanceText("English");
137+
auto bigOctoFairySpanishImportance = world.bigOctoFairyHint.location->generateImportanceText("Spanish");
138+
auto bigOctoFairyFrenchImportance = world.bigOctoFairyHint.location->generateImportanceText("French");
139139

140140
// Format for text replacements:
141141
// Message Label,

tweaks.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,11 +1194,11 @@ TweakError update_korl_dialog(World& world) {
11941194

11951195
std::vector<std::u16string> hintMessages = {u""};
11961196
size_t curLine = 0;
1197-
for (auto location : world.korlHints) {
1198-
std::u16string hint = location->hint.text[language];
1199-
hint = Text::word_wrap_string(hint, 42); // wrap shorter lines, some edge cases are still too wide with 43
1200-
hint = Text::pad_str_4_lines(hint);
1201-
const size_t numLines = std::count(hint.begin(), hint.end(), u'\n'); // 4 for most hints, 8+ for long hints with multiple textboxes
1197+
for (auto& hint : world.korlHints) {
1198+
std::u16string hintText = hint.text[language];
1199+
hintText = Text::word_wrap_string(hintText, 42); // wrap shorter lines, some edge cases are still too wide with 43
1200+
hintText = Text::pad_str_4_lines(hintText);
1201+
const size_t numLines = std::count(hintText.begin(), hintText.end(), u'\n'); // 4 for most hints, 8+ for long hints with multiple textboxes
12021202

12031203
// if we would have >10 textboxes
12041204
if(curLine + numLines > 40) {
@@ -1207,7 +1207,7 @@ TweakError update_korl_dialog(World& world) {
12071207
curLine = 0; // restart line counter
12081208
}
12091209

1210-
hintMessages.back() += hint; // add hint to back of current message
1210+
hintMessages.back() += hintText; // add hint to back of current message
12111211
curLine += numLines; // add hint lines to count
12121212
}
12131213

@@ -1253,13 +1253,13 @@ TweakError update_korl_dialog(World& world) {
12531253
for (const auto& language : Text::supported_languages) {
12541254
std::u16string hintLines = u"";
12551255
size_t i = 0; // counter to know when to add null terminator
1256-
for (auto location : world.korlHyruleHints) {
1257-
std::u16string hint = Text::word_wrap_string(location->hint.text[language], 43);
1256+
for (auto& hint : world.korlHyruleHints) {
1257+
std::u16string hintText = Text::word_wrap_string(hint.text[language], 43);
12581258
++i;
12591259
if (i == world.korlHyruleHints.size()) {
1260-
hint += u'\0'; // add null terminator on last hint before padding
1260+
hintText += u'\0'; // add null terminator on last hint before padding
12611261
}
1262-
hintLines += Text::pad_str_4_lines(hint);
1262+
hintLines += Text::pad_str_4_lines(hintText);
12631263
}
12641264

12651265
RandoSession::CacheEntry& entry = g_session.openGameFile("content/Common/Pack/permanent_2d_Us" + language + ".pack@SARC@message2_msbt.szs@YAZ0@SARC@message2.msbt@MSBT");
@@ -1288,22 +1288,22 @@ TweakError update_ho_ho_dialog(World& world) {
12881288
RandoSession::CacheEntry& entry = g_session.openGameFile("content/Common/Pack/permanent_2d_Us" + language + ".pack@SARC@message4_msbt.szs@YAZ0@SARC@message4.msbt@MSBT");
12891289

12901290
entry.addAction([=, &world](RandoSession* session, FileType* data) -> int {
1291-
for (auto& [hohoLocation, hintLocations] : world.hohoHints) {
1291+
for (auto& [hohoLocation, hints] : world.hohoHints) {
12921292
std::u16string hintLines = u"";
12931293
size_t i = 0; // counter to know when to add null terminator
1294-
for (auto location : hintLocations) {
1295-
std::u16string hint = u"";
1294+
for (auto& hint : hints) {
1295+
std::u16string hintText = u"";
12961296
if (i == 0) {
1297-
hint += SOUND(0x0103) u"Ho ho! "s;
1297+
hintText += SOUND(0x0103) u"Ho ho! "s;
12981298
}
12991299
i++;
1300-
hint += location->hint.text[language];
1301-
hint = Text::word_wrap_string(hint, 43);
1302-
if (i == hintLocations.size()) {
1303-
hint += u'\0'; // add null terminator on last hint before padding
1300+
hintText += hint.text[language];
1301+
hintText = Text::word_wrap_string(hintText, 43);
1302+
if (i == hints.size()) {
1303+
hintText += u'\0'; // add null terminator on last hint before padding
13041304
}
1305-
hint = Text::pad_str_4_lines(hint);
1306-
hintLines += hint;
1305+
hintText = Text::pad_str_4_lines(hintText);
1306+
hintLines += hintText;
13071307
}
13081308
CAST_ENTRY_TO_FILETYPE(msbt, FileTypes::MSBTFile, data)
13091309

@@ -1327,16 +1327,16 @@ TweakError update_kreeb_dialog(World& world) {
13271327
entry.addAction([=, &world](RandoSession* session, FileType* data) -> int {
13281328
std::u16string hintLines = u"";
13291329
size_t i = 0; // counter to know when to add null terminator
1330-
for (auto location : world.kreebHints) {
1331-
std::u16string hint = u"";
1332-
hint += location->hint.text[language];
1333-
hint = Text::word_wrap_string(hint, 43);
1330+
for (auto& hint : world.kreebHints) {
1331+
std::u16string hintText = u"";
1332+
hintText += hint.text[language];
1333+
hintText = Text::word_wrap_string(hintText, 43);
13341334
++i;
13351335
if (i == world.kreebHints.size()) {
1336-
hint += u'\0'; // add null terminator on last hint before padding
1336+
hintText += u'\0'; // add null terminator on last hint before padding
13371337
}
1338-
hint = Text::pad_str_4_lines(hint);
1339-
hintLines += hint;
1338+
hintText = Text::pad_str_4_lines(hintText);
1339+
hintLines += hintText;
13401340
}
13411341
CAST_ENTRY_TO_FILETYPE(msbt, FileTypes::MSBTFile, data)
13421342

@@ -1354,10 +1354,10 @@ TweakError rotate_ho_ho_to_face_hints(World& world) {
13541354
return TweakError::NONE;
13551355
}
13561356

1357-
for (auto& [hohoLocation, hintLocations] : world.hohoHints) {
1357+
for (auto& [hohoLocation, hints] : world.hohoHints) {
13581358
std::string island = "";
1359-
for (auto location : hintLocations) {
1360-
for (auto region : location->hintRegions) {
1359+
for (auto& hint : hints) {
1360+
for (auto region : hint.location->hintRegions) {
13611361
// If this region is a dungeon, use the dungeon's island instead
13621362
if (world.dungeons.contains(region)) {
13631363
region = world.dungeons[region].islands.front();

0 commit comments

Comments
 (0)