Skip to content

Commit

Permalink
Get Info/Tile ID - Using Rect Class
Browse files Browse the repository at this point in the history
  • Loading branch information
jetrotal committed Jan 8, 2025
1 parent a6f98cb commit 0cc19c1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
16 changes: 6 additions & 10 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1898,11 +1898,11 @@ int Game_Map::GetTileIdAt(int x, int y, int layer, bool chipIdOrIndex) {
return tile_output;
}

std::vector<int> Game_Map::GetTilesIdAt(int x, int y, int width, int height, int layer, bool chipIdOrIndex) {
std::vector<int> Game_Map::GetTilesIdAt(Rect coords, int layer, bool chipIdOrIndex) {
std::vector<int> 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;
Expand Down
2 changes: 1 addition & 1 deletion src/game_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> GetTilesIdAt(int x, int y, int width, int height, int layer, bool chipIdOrIndex = false);
std::vector<int> GetTilesIdAt(Rect coords, int layer, bool chipIdOrIndex = false);

/**
* Checks if its possible to step onto the tile at (x,y)
Expand Down

0 comments on commit 0cc19c1

Please sign in to comment.