From 0cc19c1c35400a22d4414c80052a257b3e01a105 Mon Sep 17 00:00:00 2001 From: Mauro Junior <45118493+jetrotal@users.noreply.github.com> Date: Wed, 8 Jan 2025 20:45:42 -0300 Subject: [PATCH] Get Info/Tile ID - Using Rect Class --- src/game_interpreter.cpp | 16 ++++++---------- src/game_map.cpp | 8 ++++---- src/game_map.h | 2 +- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 6657dd0250..9ae1070991 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -4080,10 +4080,6 @@ bool Game_Interpreter::CommandManiacGetGameInfo(lcf::rpg::EventCommand const& co int event_id; int var = com.parameters[2]; - - struct rect { - int x, y, w, h; - }; switch (com.parameters[1]) { case 0: // Get map size @@ -4095,18 +4091,18 @@ bool Game_Interpreter::CommandManiacGetGameInfo(lcf::rpg::EventCommand const& co var = com.parameters[7]; auto tile_layer = com.parameters[2]; // 0: Lower || 1: Upper - auto tile_coords = rect{}; + Rect tile_coords; tile_coords.x = ValueOrVariableBitfield(com.parameters[0], 1, com.parameters[3]); tile_coords.y = ValueOrVariableBitfield(com.parameters[0], 2, com.parameters[4]); - tile_coords.w = ValueOrVariableBitfield(com.parameters[0], 3, com.parameters[5]); - tile_coords.h = ValueOrVariableBitfield(com.parameters[0], 4, com.parameters[6]); + tile_coords.width = ValueOrVariableBitfield(com.parameters[0], 3, com.parameters[5]); + tile_coords.height = ValueOrVariableBitfield(com.parameters[0], 4, com.parameters[6]); - if (tile_coords.w <= 0 || tile_coords.h <= 0) return true; + if (tile_coords.width <= 0 || tile_coords.height <= 0) return true; - auto tiles = Game_Map::GetTilesIdAt(tile_coords.x, tile_coords.y, tile_coords.w, tile_coords.h, tile_layer); + auto tiles = Game_Map::GetTilesIdAt(tile_coords, tile_layer); - for (int i = 0; i < tile_coords.w * tile_coords.h; i++) { + for (int i = 0; i < tile_coords.width * tile_coords.height; i++) { Main_Data::game_variables->Set(var + i, tiles[i]); } break; diff --git a/src/game_map.cpp b/src/game_map.cpp index dab3f8354e..23e599ec5a 100644 --- a/src/game_map.cpp +++ b/src/game_map.cpp @@ -1898,11 +1898,11 @@ int Game_Map::GetTileIdAt(int x, int y, int layer, bool chipIdOrIndex) { return tile_output; } -std::vector Game_Map::GetTilesIdAt(int x, int y, int width, int height, int layer, bool chipIdOrIndex) { +std::vector Game_Map::GetTilesIdAt(Rect coords, int layer, bool chipIdOrIndex) { std::vector tiles_collection; - for (int i = 0; i < height; ++i) { - for (int j = 0; j < width; ++j) { - tiles_collection.emplace_back(Game_Map::GetTileIdAt(x + j, y + i, layer, chipIdOrIndex)); + for (int i = 0; i < coords.height; ++i) { + for (int j = 0; j < coords.width; ++j) { + tiles_collection.emplace_back(Game_Map::GetTileIdAt(coords.x + j, coords.y + i, layer, chipIdOrIndex)); } } return tiles_collection; diff --git a/src/game_map.h b/src/game_map.h index fe10028d99..edac9d0cb1 100644 --- a/src/game_map.h +++ b/src/game_map.h @@ -644,7 +644,7 @@ namespace Game_Map { void ReplaceTileAt(int x, int y, int new_id, int layer); int GetTileIdAt(int x, int y, int layer, bool chipIdOrIndex = false); - std::vector GetTilesIdAt(int x, int y, int width, int height, int layer, bool chipIdOrIndex = false); + std::vector GetTilesIdAt(Rect coords, int layer, bool chipIdOrIndex = false); /** * Checks if its possible to step onto the tile at (x,y)