Codechange: use ScriptMap size functions instead of global functions

This commit is contained in:
Rubidium 2023-01-21 10:57:29 +01:00 committed by rubidium42
parent 953445a5ac
commit 22d3de8b67
3 changed files with 15 additions and 14 deletions

View File

@ -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;

View File

@ -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<CMD_TERRAFORM_LAND>::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<CMD_TERRAFORM_LAND>::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<CMD_LEVEL_LAND>::Do(end_tile, start_tile, false, LM_LEVEL);
}

View File

@ -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);
}