From 4c16355b637e20ec64622be7b6dd61ed45ade3ff Mon Sep 17 00:00:00 2001 From: Mauro Junior <45118493+jetrotal@users.noreply.github.com> Date: Fri, 12 Apr 2024 03:06:30 -0300 Subject: [PATCH 1/2] Changes to CommandTeleport (10810) - Allow com.string as map filename You can teleport to a custom-named map, by filling `com.string`. It Even considers custom folder structure. --- src/game_interpreter_map.cpp | 2 ++ src/game_map.cpp | 26 +++++++++++++++++++++++--- src/game_map.h | 4 ++++ src/game_player.cpp | 2 +- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/game_interpreter_map.cpp b/src/game_interpreter_map.cpp index 88e5cde25a..05938c3029 100644 --- a/src/game_interpreter_map.cpp +++ b/src/game_interpreter_map.cpp @@ -475,6 +475,8 @@ bool Game_Interpreter_Map::CommandEnterHeroName(lcf::rpg::EventCommand const& co bool Game_Interpreter_Map::CommandTeleport(lcf::rpg::EventCommand const& com) { // Code 10810 // TODO: if in battle return true + if (com.string != "") Game_Map::SetCustomMapName(com.string); + if (Game_Message::IsMessageActive()) { return false; } diff --git a/src/game_map.cpp b/src/game_map.cpp index 29858b3133..24cc783fb3 100644 --- a/src/game_map.cpp +++ b/src/game_map.cpp @@ -57,6 +57,8 @@ #include "feature.h" namespace { + std::string customMapName = ""; + // Intended bad value, Game_Map::Init sets them correctly int screen_width = -1; int screen_height = -1; @@ -327,6 +329,8 @@ std::unique_ptr Game_Map::loadMapFile(int map_id) { } Output::Debug("Loaded Map {}", map_name); + Output::Warning("{}", map_name); + customMapName = ""; if (map.get() == NULL) { Output::ErrorStr(lcf::LcfReader::GetError()); @@ -1281,6 +1285,16 @@ int Game_Map::GetMapId() { return Main_Data::game_player->GetMapId(); } +std::string Game_Map::GetCustomMapName() { + return customMapName; +} + +void Game_Map::SetCustomMapName(lcf::DBString mapName) { + customMapName = mapName.c_str(); + + return; +} + void Game_Map::PrintPathToMap() { const auto* current_info = &GetMapInfo(); std::ostringstream ss; @@ -1682,7 +1696,13 @@ int Game_Map::SubstituteUp(int old_id, int new_id) { std::string Game_Map::ConstructMapName(int map_id, bool is_easyrpg) { std::stringstream ss; - ss << "Map" << std::setfill('0') << std::setw(4) << map_id; + + if (customMapName == "") { + ss << "Map" << std::setfill('0') << std::setw(4) << map_id; + } else { + ss << customMapName; + } + if (is_easyrpg) { return Player::fileext_map.MakeFilename(ss.str(), SUFFIX_EMU); } else { @@ -1694,8 +1714,8 @@ FileRequestAsync* Game_Map::RequestMap(int map_id) { #ifdef EMSCRIPTEN Player::translation.RequestAndAddMap(map_id); #endif - - return AsyncHandler::RequestFile(Game_Map::ConstructMapName(map_id, false)); + auto map_name = Game_Map::ConstructMapName(map_id, false); + return AsyncHandler::RequestFile(map_name); } // Parallax diff --git a/src/game_map.h b/src/game_map.h index 2533347d38..4c4f406b53 100644 --- a/src/game_map.h +++ b/src/game_map.h @@ -381,6 +381,10 @@ namespace Game_Map { */ int GetMapId(); + std::string GetCustomMapName(); + + void SetCustomMapName(lcf::DBString mapName); + /** * Outputs the path in the map tree to reach the current map. */ diff --git a/src/game_player.cpp b/src/game_player.cpp index 71c8694ac1..20585d89ee 100644 --- a/src/game_player.cpp +++ b/src/game_player.cpp @@ -104,7 +104,7 @@ void Game_Player::PerformTeleport() { return; } - if (teleport_target.GetMapId() <= 0) { + if (Game_Map::GetCustomMapName() == "" && teleport_target.GetMapId() <= 0) { Output::Error("Invalid Teleport map id! mapid={} x={} y={} d={}", teleport_target.GetMapId(), teleport_target.GetX(), teleport_target.GetY(), teleport_target.GetDirection()); } From 0785b433d6df26f6f0813efe8655aa1b093f607d Mon Sep 17 00:00:00 2001 From: Mauro Junior <45118493+jetrotal@users.noreply.github.com> Date: Fri, 31 May 2024 21:44:22 -0300 Subject: [PATCH 2/2] Snake case + check if map ID is 0 --- src/game_interpreter_map.cpp | 4 ++-- src/game_map.cpp | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/game_interpreter_map.cpp b/src/game_interpreter_map.cpp index 05938c3029..c1af21cb7e 100644 --- a/src/game_interpreter_map.cpp +++ b/src/game_interpreter_map.cpp @@ -475,8 +475,6 @@ bool Game_Interpreter_Map::CommandEnterHeroName(lcf::rpg::EventCommand const& co bool Game_Interpreter_Map::CommandTeleport(lcf::rpg::EventCommand const& com) { // Code 10810 // TODO: if in battle return true - if (com.string != "") Game_Map::SetCustomMapName(com.string); - if (Game_Message::IsMessageActive()) { return false; } @@ -488,6 +486,8 @@ bool Game_Interpreter_Map::CommandTeleport(lcf::rpg::EventCommand const& com) { int x = com.parameters[1]; int y = com.parameters[2]; + if (map_id == 0 && com.string != "") Game_Map::SetCustomMapName(com.string); + // RPG2k3 feature int direction = -1; if (com.parameters.size() > 3 && Player::IsRPG2k3Commands()) { diff --git a/src/game_map.cpp b/src/game_map.cpp index 24cc783fb3..af1840bce8 100644 --- a/src/game_map.cpp +++ b/src/game_map.cpp @@ -57,7 +57,7 @@ #include "feature.h" namespace { - std::string customMapName = ""; + std::string custom_map_name = ""; // Intended bad value, Game_Map::Init sets them correctly int screen_width = -1; @@ -329,8 +329,7 @@ std::unique_ptr Game_Map::loadMapFile(int map_id) { } Output::Debug("Loaded Map {}", map_name); - Output::Warning("{}", map_name); - customMapName = ""; + custom_map_name = ""; if (map.get() == NULL) { Output::ErrorStr(lcf::LcfReader::GetError()); @@ -1282,15 +1281,16 @@ lcf::rpg::Map const& Game_Map::GetMap() { } int Game_Map::GetMapId() { - return Main_Data::game_player->GetMapId(); + int map_id = Main_Data::game_player->GetMapId(); + return map_id; } std::string Game_Map::GetCustomMapName() { - return customMapName; + return custom_map_name; } void Game_Map::SetCustomMapName(lcf::DBString mapName) { - customMapName = mapName.c_str(); + custom_map_name = mapName.c_str(); return; } @@ -1697,10 +1697,10 @@ int Game_Map::SubstituteUp(int old_id, int new_id) { std::string Game_Map::ConstructMapName(int map_id, bool is_easyrpg) { std::stringstream ss; - if (customMapName == "") { + if (custom_map_name == "") { ss << "Map" << std::setfill('0') << std::setw(4) << map_id; } else { - ss << customMapName; + ss << custom_map_name; } if (is_easyrpg) {