From 22d3de8b67a40ea008ee24ce8ebce061015384ee Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sat, 21 Jan 2023 10:57:29 +0100 Subject: [PATCH] Codechange: use ScriptMap size functions instead of global functions --- src/script/api/script_rail.cpp | 16 ++++++++-------- src/script/api/script_tile.cpp | 8 ++++---- src/script/api/script_vehicle.cpp | 5 +++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/script/api/script_rail.cpp b/src/script/api/script_rail.cpp index 76eda79f4d..bc60617609 100644 --- a/src/script/api/script_rail.cpp +++ b/src/script/api/script_rail.cpp @@ -276,11 +276,11 @@ if (tile - from == 1) { if (to - tile == 1) return (GetRailTracks(tile) & RAILTRACK_NE_SW) != 0; - if (to - tile == ::MapSizeX()) return (GetRailTracks(tile) & RAILTRACK_NE_SE) != 0; - } else if (tile - from == ::MapSizeX()) { + if (to - tile == ScriptMap::GetMapSizeX()) return (GetRailTracks(tile) & RAILTRACK_NE_SE) != 0; + } else if (tile - from == ScriptMap::GetMapSizeX()) { if (tile - to == 1) return (GetRailTracks(tile) & RAILTRACK_NW_NE) != 0; if (to - tile == 1) return (GetRailTracks(tile) & RAILTRACK_NW_SW) != 0; - if (to - tile == ::MapSizeX()) return (GetRailTracks(tile) & RAILTRACK_NW_SE) != 0; + if (to - tile == ScriptMap::GetMapSizeX()) return (GetRailTracks(tile) & RAILTRACK_NW_SE) != 0; } else { return (GetRailTracks(tile) & RAILTRACK_SW_SE) != 0; } @@ -301,7 +301,7 @@ static Track SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to) *to -= Clamp((int)::TileX(*to) - (int)::TileX(tile), -1, 1); } else if (::TileX(from) == ::TileX(*to)) { track = TRACK_Y; - *to -= ::MapSizeX() * Clamp((int)::TileY(*to) - (int)::TileY(tile), -1, 1); + *to -= ScriptMap::GetMapSizeX() * Clamp((int)::TileY(*to) - (int)::TileY(tile), -1, 1); } else if (::TileY(from) < ::TileY(tile)) { if (::TileX(*to) < ::TileX(tile)) { track = TRACK_UPPER; @@ -311,7 +311,7 @@ static Track SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to) if (diag_offset != 0) { *to -= Clamp((int)::TileX(*to) - (int)::TileX(tile), -1, 1); } else { - *to -= ::MapSizeX() * Clamp((int)::TileY(*to) - (int)::TileY(tile), -1, 1); + *to -= ScriptMap::GetMapSizeX() * Clamp((int)::TileY(*to) - (int)::TileY(tile), -1, 1); } } else if (::TileY(from) > ::TileY(tile)) { if (::TileX(*to) < ::TileX(tile)) { @@ -322,7 +322,7 @@ static Track SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to) if (diag_offset != 0) { *to -= Clamp((int)::TileX(*to) - (int)::TileX(tile), -1, 1); } else { - *to -= ::MapSizeX() * Clamp((int)::TileY(*to) - (int)::TileY(tile), -1, 1); + *to -= ScriptMap::GetMapSizeX() * Clamp((int)::TileY(*to) - (int)::TileY(tile), -1, 1); } } else if (::TileX(from) < ::TileX(tile)) { if (::TileY(*to) < ::TileY(tile)) { @@ -333,7 +333,7 @@ static Track SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to) if (diag_offset == 0) { *to -= Clamp((int)::TileX(*to) - (int)::TileX(tile), -1, 1); } else { - *to -= ::MapSizeX() * Clamp((int)::TileY(*to) - (int)::TileY(tile), -1, 1); + *to -= ScriptMap::GetMapSizeX() * Clamp((int)::TileY(*to) - (int)::TileY(tile), -1, 1); } } else if (::TileX(from) > ::TileX(tile)) { if (::TileY(*to) < ::TileY(tile)) { @@ -344,7 +344,7 @@ static Track SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to) if (diag_offset == 0) { *to -= Clamp((int)::TileX(*to) - (int)::TileX(tile), -1, 1); } else { - *to -= ::MapSizeX() * Clamp((int)::TileY(*to) - (int)::TileY(tile), -1, 1); + *to -= ScriptMap::GetMapSizeX() * Clamp((int)::TileY(*to) - (int)::TileY(tile), -1, 1); } } return track; diff --git a/src/script/api/script_tile.cpp b/src/script/api/script_tile.cpp index ed7b1300cd..b187c39317 100644 --- a/src/script/api/script_tile.cpp +++ b/src/script/api/script_tile.cpp @@ -253,7 +253,7 @@ /* static */ bool ScriptTile::RaiseTile(TileIndex tile, int32 slope) { EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY); - EnforcePrecondition(false, tile < ::MapSize()); + EnforcePrecondition(false, tile < ScriptMap::GetMapSize()); return ScriptObject::Command::Do(tile, (::Slope)slope, true); } @@ -261,7 +261,7 @@ /* static */ bool ScriptTile::LowerTile(TileIndex tile, int32 slope) { EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY); - EnforcePrecondition(false, tile < ::MapSize()); + EnforcePrecondition(false, tile < ScriptMap::GetMapSize()); return ScriptObject::Command::Do(tile, (::Slope)slope, false); } @@ -269,8 +269,8 @@ /* static */ bool ScriptTile::LevelTiles(TileIndex start_tile, TileIndex end_tile) { EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY); - EnforcePrecondition(false, start_tile < ::MapSize()); - EnforcePrecondition(false, end_tile < ::MapSize()); + EnforcePrecondition(false, start_tile < ScriptMap::GetMapSize()); + EnforcePrecondition(false, end_tile < ScriptMap::GetMapSize()); return ScriptObject::Command::Do(end_tile, start_tile, false, LM_LEVEL); } diff --git a/src/script/api/script_vehicle.cpp b/src/script/api/script_vehicle.cpp index 3ff05d9ba6..851d72f3b8 100644 --- a/src/script/api/script_vehicle.cpp +++ b/src/script/api/script_vehicle.cpp @@ -12,6 +12,7 @@ #include "script_cargo.hpp" #include "script_gamesettings.hpp" #include "script_group.hpp" +#include "script_map.hpp" #include "../script_instance.hpp" #include "../../string_func.h" #include "../../strings_func.h" @@ -256,8 +257,8 @@ const Vehicle *v = ::Vehicle::Get(vehicle_id); if (v->type == VEH_AIRCRAFT) { - uint x = Clamp(v->x_pos / TILE_SIZE, 0, ::MapSizeX() - 2); - uint y = Clamp(v->y_pos / TILE_SIZE, 0, ::MapSizeY() - 2); + uint x = Clamp(v->x_pos / TILE_SIZE, 0, ScriptMap::GetMapSizeX() - 2); + uint y = Clamp(v->y_pos / TILE_SIZE, 0, ScriptMap::GetMapSizeY() - 2); return ::TileXY(x, y); }