From 3c4ed3641886ac410f3ca169211a81c2116ce488 Mon Sep 17 00:00:00 2001 From: Dav999 Date: Mon, 4 Sep 2023 15:27:29 +0200 Subject: [PATCH] Translate hardest room at display time instead of at time of death The hardest room used to be stored as a room name in whatever language it was in when you last died enough times to break the record (before localization, that was always English). Even after localization became a thing we could get away with this since we only had a single font, but now we might have actual question marks appearing when the new font doesn't support characters from the old language. Therefore, this commit adds more info about the hardest room to save files - everything that is needed to know in order to do the translation at display time. These are hardestroom_x and hardestroom_y for the room coordinates, as well as hardestroom_specialname to mark special names, in addition to changing the stored room name back to English. I've also added hardestroom_finalstretch in case we later decide to drop the English name as a key and rely on just the coordinates (even though I think that change itself would be more complicated than any simplification it would accomplish, and I don't think it's necessary, but better to have it if we do need it later) --- desktop_version/src/Game.cpp | 74 ++++++++++++++++++++++++++++++++-- desktop_version/src/Game.h | 5 ++- desktop_version/src/Script.cpp | 6 ++- 3 files changed, 79 insertions(+), 6 deletions(-) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 8e80f3d9..552cb059 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -280,6 +280,10 @@ void Game::init(void) totalflips = 0; hardestroom = "Welcome Aboard"; hardestroomdeaths = 0; + hardestroom_x = 13; + hardestroom_y = 5; + hardestroom_specialname = false; + hardestroom_finalstretch = false; currentroomdeaths=0; inertia = 1.1f; @@ -2951,7 +2955,10 @@ void Game::updatestate(void) ); graphics.createtextboxflipme(buffer, -1, 158, TEXT_COLOUR("transparent")); graphics.textboxprintflags(PR_FONT_INTERFACE); - graphics.createtextboxflipme(hardestroom, -1, 170, TEXT_COLOUR("transparent")); + graphics.createtextboxflipme( + loc::gettext_roomname(map.custommode, hardestroom_x, hardestroom_y, hardestroom.c_str(), hardestroom_specialname), + -1, 170, TEXT_COLOUR("transparent") + ); graphics.textboxprintflags(PR_FONT_INTERFACE); break; } @@ -4243,13 +4250,19 @@ void Game::gethardestroom(void) { hardestroomdeaths = currentroomdeaths; + hardestroom_x = roomx; + hardestroom_y = roomy; + hardestroom_finalstretch = map.finalstretch; + if (map.roomname[0] == '\0') { - hardestroom = loc::gettext_roomname_special(map.hiddenname); + hardestroom = map.hiddenname; + hardestroom_specialname = true; } else { - hardestroom = loc::gettext_roomname(map.custommode, roomx, roomy, map.roomname, map.roomname_special); + hardestroom = map.roomname; + hardestroom_specialname = map.roomname_special; } } } @@ -5197,6 +5210,13 @@ void Game::readmaingamesave(const char* savename, tinyxml2::XMLDocument& doc) return; } + /* Even if we want the default hardest room to be Welcome Aboard, there are pre-2.4 + * saves with JUST which should take priority over the coords */ + hardestroom_x = -1; + hardestroom_y = -1; + hardestroom_specialname = false; + hardestroom_finalstretch = false; + for (pElem = hDoc .FirstChildElement() .FirstChildElement("Data") @@ -5309,6 +5329,22 @@ void Game::readmaingamesave(const char* savename, tinyxml2::XMLDocument& doc) { hardestroomdeaths = help.Int(pText); } + else if (SDL_strcmp(pKey, "hardestroom_x") == 0) + { + hardestroom_x = help.Int(pText); + } + else if (SDL_strcmp(pKey, "hardestroom_y") == 0) + { + hardestroom_y = help.Int(pText); + } + else if (SDL_strcmp(pKey, "hardestroom_specialname") == 0) + { + hardestroom_specialname = help.Int(pText); + } + else if (SDL_strcmp(pKey, "hardestroom_finalstretch") == 0) + { + hardestroom_finalstretch = help.Int(pText); + } else if (SDL_strcmp(pKey, "currentsong") == 0) { int song = help.Int(pText); @@ -5379,6 +5415,12 @@ void Game::customloadquick(const std::string& savfile) return; } + // Like readmaingamesave(...), old saves have just + hardestroom_x = -1; + hardestroom_y = -1; + hardestroom_specialname = false; + hardestroom_finalstretch = false; + for (pElem = hDoc .FirstChildElement() .FirstChildElement("Data") @@ -5514,6 +5556,22 @@ void Game::customloadquick(const std::string& savfile) { hardestroomdeaths = help.Int(pText); } + else if (SDL_strcmp(pKey, "hardestroom_x") == 0) + { + hardestroom_x = help.Int(pText); + } + else if (SDL_strcmp(pKey, "hardestroom_y") == 0) + { + hardestroom_y = help.Int(pText); + } + else if (SDL_strcmp(pKey, "hardestroom_specialname") == 0) + { + hardestroom_specialname = help.Int(pText); + } + else if (SDL_strcmp(pKey, "hardestroom_finalstretch") == 0) + { + hardestroom_finalstretch = help.Int(pText); + } else if (SDL_strcmp(pKey, "currentsong") == 0) { int song = help.Int(pText); @@ -5815,6 +5873,10 @@ struct Game::Summary Game::writemaingamesave(tinyxml2::XMLDocument& doc) xml::update_tag(msgs, "hardestroom", hardestroom.c_str()); xml::update_tag(msgs, "hardestroomdeaths", hardestroomdeaths); + xml::update_tag(msgs, "hardestroom_x", hardestroom_x); + xml::update_tag(msgs, "hardestroom_y", hardestroom_y); + xml::update_tag(msgs, "hardestroom_specialname", (int) hardestroom_specialname); + xml::update_tag(msgs, "hardestroom_finalstretch", (int) hardestroom_finalstretch); xml::update_tag(msgs, "finalmode", (int) map.finalmode); xml::update_tag(msgs, "finalstretch", (int) map.finalstretch); @@ -5962,6 +6024,10 @@ bool Game::customsavequick(const std::string& savfile) xml::update_tag(msgs, "hardestroom", hardestroom.c_str()); xml::update_tag(msgs, "hardestroomdeaths", hardestroomdeaths); + xml::update_tag(msgs, "hardestroom_x", hardestroom_x); + xml::update_tag(msgs, "hardestroom_y", hardestroom_y); + xml::update_tag(msgs, "hardestroom_specialname", (int) hardestroom_specialname); + xml::update_tag(msgs, "hardestroom_finalstretch", (int) hardestroom_finalstretch); xml::update_tag(msgs, "showminimap", (int) map.customshowmm); @@ -7391,7 +7457,7 @@ void Game::copyndmresults(void) { ndmresultcrewrescued = crewrescued(); ndmresulttrinkets = trinkets(); - ndmresulthardestroom = hardestroom; + ndmresulthardestroom = loc::gettext_roomname(false, hardestroom_x, hardestroom_y, hardestroom.c_str(), hardestroom_specialname); SDL_memcpy(ndmresultcrewstats, crewstats, sizeof(ndmresultcrewstats)); } diff --git a/desktop_version/src/Game.h b/desktop_version/src/Game.h index 4e9f750e..96ed0e15 100644 --- a/desktop_version/src/Game.h +++ b/desktop_version/src/Game.h @@ -501,8 +501,11 @@ public: //Some stats: int totalflips; - std::string hardestroom; // don't change to C string unless you wanna handle language switches (or make it store coords) + std::string hardestroom; // don't change to C string unless you wanna handle when this string is loaded from the XML int hardestroomdeaths, currentroomdeaths; + int hardestroom_x, hardestroom_y; + bool hardestroom_specialname; + bool hardestroom_finalstretch; bool quickrestartkludge; diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index cd593d1b..4f6f8bfd 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -3187,8 +3187,12 @@ void scriptclass::hardreset(void) game.translator_cutscene_test = false; game.totalflips = 0; - game.hardestroom = loc::gettext_roomname(false, 13, 5, "Welcome Aboard", false); + game.hardestroom = "Welcome Aboard"; game.hardestroomdeaths = 0; + game.hardestroom_x = 13; + game.hardestroom_y = 5; + game.hardestroom_specialname = false; + game.hardestroom_finalstretch = false; game.currentroomdeaths=0; game.swnmode = false;