Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetInfo - Support Tile ID #3330

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4080,16 +4080,33 @@ bool Game_Interpreter::CommandManiacGetGameInfo(lcf::rpg::EventCommand const& co

int event_id;
int var = com.parameters[2];

switch (com.parameters[1]) {
case 0: // Get map size
Main_Data::game_variables->Set(var, Game_Map::GetTilesX());
Main_Data::game_variables->Set(var + 1, Game_Map::GetTilesY());
break;
case 1: // Get tile info
// FIXME: figure out how 'Tile Info' works
Output::Warning("GetGameInfo: Option 'Tile Info' not implemented.");
case 1: { // Get tile info

var = com.parameters[7];

auto tile_layer = com.parameters[2]; // 0: Lower || 1: Upper
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.width = ValueOrVariableBitfield(com.parameters[0], 3, com.parameters[5]);
tile_coords.height = ValueOrVariableBitfield(com.parameters[0], 4, com.parameters[6]);

if (tile_coords.width <= 0 || tile_coords.height <= 0) return true;

auto tiles = Game_Map::GetTilesIdAt(tile_coords, tile_layer);

for (int i = 0; i < tile_coords.width * tile_coords.height; i++) {
Main_Data::game_variables->Set(var + i, tiles[i]);
}
break;
}
case 2: // Get window size
Main_Data::game_variables->Set(var, Player::screen_width);
Main_Data::game_variables->Set(var + 1, Player::screen_height);
Expand Down
23 changes: 23 additions & 0 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,29 @@ void Game_Map::ReplaceTileAt(int x, int y, int new_id, int layer) {
layer_vec[pos] = static_cast<int16_t>(new_id);
}

int Game_Map::GetTileIdAt(int x, int y, int layer, bool chipIdOrIndex) {
if (x < 0 || x >= map->width || y < 0 || y >= map->height) {
return 0; // Return 0 for out-of-bounds coordinates
}

auto pos = x + y * map->width;
auto& layer_vec = layer >= 1 ? map->upper_layer : map->lower_layer;

int tile_output = chipIdOrIndex ? layer_vec[pos] : ChipIdToIndex(layer_vec[pos]);
if (layer >= 1) tile_output -= BLOCK_F_INDEX;
return tile_output;
}

std::vector<int> Game_Map::GetTilesIdAt(Rect coords, int layer, bool chipIdOrIndex) {
std::vector<int> tiles_collection;
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;
}

std::string Game_Map::ConstructMapName(int map_id, bool is_easyrpg) {
std::stringstream ss;
ss << "Map" << std::setfill('0') << std::setw(4) << map_id;
Expand Down
3 changes: 3 additions & 0 deletions src/game_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,9 @@ namespace Game_Map {
int SubstituteUp(int old_id, int new_id);
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(Rect coords, int layer, bool chipIdOrIndex = false);

/**
* Checks if its possible to step onto the tile at (x,y)
* The check includes tile graphic events checks.
Expand Down
Loading