Codechange: migrate size related functions to Map structure

This commit is contained in:
Rubidium
2023-01-21 10:43:03 +01:00
committed by rubidium42
parent d481f78b24
commit fe2bcd2a58
56 changed files with 334 additions and 343 deletions

View File

@@ -93,7 +93,7 @@ void SetWaterClassDependingOnSurroundings(TileIndex t, bool include_invalid_wate
/* Mark tile dirty in all cases */
MarkTileDirtyByTile(t);
if (TileX(t) == 0 || TileY(t) == 0 || TileX(t) == MapMaxX() - 1 || TileY(t) == MapMaxY() - 1) {
if (TileX(t) == 0 || TileY(t) == 0 || TileX(t) == Map::MaxX() - 1 || TileY(t) == Map::MaxY() - 1) {
/* tiles at map borders are always WATER_CLASS_SEA */
SetWaterClass(t, WATER_CLASS_SEA);
return;
@@ -150,7 +150,7 @@ void SetWaterClassDependingOnSurroundings(TileIndex t, bool include_invalid_wate
static void ConvertTownOwner()
{
for (TileIndex tile = 0; tile != MapSize(); tile++) {
for (TileIndex tile = 0; tile != Map::Size(); tile++) {
switch (GetTileType(tile)) {
case MP_ROAD:
if (GB(_m[tile].m5, 4, 2) == ROAD_TILE_CROSSING && HasBit(_m[tile].m3, 7)) {
@@ -203,8 +203,8 @@ static void UpdateCurrencies()
*/
static void UpdateVoidTiles()
{
for (uint x = 0; x < MapSizeX(); x++) MakeVoid(TileXY(x, MapMaxY()));
for (uint y = 0; y < MapSizeY(); y++) MakeVoid(TileXY(MapMaxX(), y));
for (uint x = 0; x < Map::SizeX(); x++) MakeVoid(TileXY(x, Map::MaxY()));
for (uint y = 0; y < Map::SizeY(); y++) MakeVoid(TileXY(Map::MaxX(), y));
}
static inline RailType UpdateRailType(RailType rt, RailType min)
@@ -564,7 +564,7 @@ bool AfterLoadGame()
{
SetSignalHandlers();
TileIndex map_size = MapSize();
TileIndex map_size = Map::Size();
extern TileIndex _cur_tileloop_tile; // From landscape.cpp.
/* The LFSR used in RunTileLoop iteration cannot have a zeroed state, make it non-zeroed. */
@@ -838,7 +838,7 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_72)) {
/* Locks in very old savegames had OWNER_WATER as owner */
for (TileIndex t = 0; t < MapSize(); t++) {
for (TileIndex t = 0; t < Map::Size(); t++) {
switch (GetTileType(t)) {
default: break;
@@ -1833,7 +1833,7 @@ bool AfterLoadGame()
for (TileIndex t = 0; t < map_size; t++) {
/* skip oil rigs at borders! */
if ((IsTileType(t, MP_WATER) || IsBuoyTile(t)) &&
(TileX(t) == 0 || TileY(t) == 0 || TileX(t) == MapMaxX() - 1 || TileY(t) == MapMaxY() - 1)) {
(TileX(t) == 0 || TileY(t) == 0 || TileX(t) == Map::MaxX() - 1 || TileY(t) == Map::MaxY() - 1)) {
/* Some version 86 savegames have wrong water class at map borders (under buoy, or after removing buoy).
* This conversion has to be done before buoys with invalid owner are removed. */
SetWaterClass(t, WATER_CLASS_SEA);
@@ -3197,7 +3197,7 @@ bool AfterLoadGame()
}
/* Refresh all level crossings to bar adjacent crossing tiles. */
for (TileIndex tile = 0; tile < MapSize(); tile++) {
for (TileIndex tile = 0; tile < Map::Size(); tile++) {
if (IsLevelCrossingTile(tile)) UpdateLevelCrossing(tile, false, true);
}
}

View File

@@ -106,7 +106,7 @@ void AfterLoadCompanyStats()
}
Company *c;
for (TileIndex tile = 0; tile < MapSize(); tile++) {
for (TileIndex tile = 0; tile < Map::Size(); tile++) {
switch (GetTileType(tile)) {
case MP_RAILWAY:
c = Company::GetIfValid(GetTileOwner(tile));

View File

@@ -52,7 +52,7 @@ void AfterLoadLabelMaps()
railtype_conversion_map.push_back(r);
}
for (TileIndex t = 0; t < MapSize(); t++) {
for (TileIndex t = 0; t < Map::Size(); t++) {
switch (GetTileType(t)) {
case MP_RAILWAY:
SetRailType(t, railtype_conversion_map[GetRailType(t)]);

View File

@@ -34,8 +34,8 @@ struct MAPSChunkHandler : ChunkHandler {
{
SlTableHeader(_map_desc);
_map_dim_x = MapSizeX();
_map_dim_y = MapSizeY();
_map_dim_x = Map::SizeX();
_map_dim_y = Map::SizeY();
SlSetArrayIndex(0);
SlGlobList(_map_desc);
@@ -73,7 +73,7 @@ struct MAPTChunkHandler : ChunkHandler {
void Load() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
@@ -84,7 +84,7 @@ struct MAPTChunkHandler : ChunkHandler {
void Save() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
@@ -100,7 +100,7 @@ struct MAPHChunkHandler : ChunkHandler {
void Load() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
@@ -111,7 +111,7 @@ struct MAPHChunkHandler : ChunkHandler {
void Save() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
@@ -127,7 +127,7 @@ struct MAPOChunkHandler : ChunkHandler {
void Load() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
@@ -138,7 +138,7 @@ struct MAPOChunkHandler : ChunkHandler {
void Save() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
@@ -154,7 +154,7 @@ struct MAP2ChunkHandler : ChunkHandler {
void Load() const override
{
std::array<uint16, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE,
@@ -168,7 +168,7 @@ struct MAP2ChunkHandler : ChunkHandler {
void Save() const override
{
std::array<uint16, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
SlSetLength(size * sizeof(uint16));
for (TileIndex i = 0; i != size;) {
@@ -184,7 +184,7 @@ struct M3LOChunkHandler : ChunkHandler {
void Load() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
@@ -195,7 +195,7 @@ struct M3LOChunkHandler : ChunkHandler {
void Save() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
@@ -211,7 +211,7 @@ struct M3HIChunkHandler : ChunkHandler {
void Load() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
@@ -222,7 +222,7 @@ struct M3HIChunkHandler : ChunkHandler {
void Save() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
@@ -238,7 +238,7 @@ struct MAP5ChunkHandler : ChunkHandler {
void Load() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
@@ -249,7 +249,7 @@ struct MAP5ChunkHandler : ChunkHandler {
void Save() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
@@ -265,7 +265,7 @@ struct MAPEChunkHandler : ChunkHandler {
void Load() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
if (IsSavegameVersionBefore(SLV_42)) {
for (TileIndex i = 0; i != size;) {
@@ -289,7 +289,7 @@ struct MAPEChunkHandler : ChunkHandler {
void Save() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
@@ -305,7 +305,7 @@ struct MAP7ChunkHandler : ChunkHandler {
void Load() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
@@ -316,7 +316,7 @@ struct MAP7ChunkHandler : ChunkHandler {
void Save() const override
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
@@ -332,7 +332,7 @@ struct MAP8ChunkHandler : ChunkHandler {
void Load() const override
{
std::array<uint16, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
for (TileIndex i = 0; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16);
@@ -343,7 +343,7 @@ struct MAP8ChunkHandler : ChunkHandler {
void Save() const override
{
std::array<uint16, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
TileIndex size = Map::Size();
SlSetLength(size * sizeof(uint16));
for (TileIndex i = 0; i != size;) {

View File

@@ -38,7 +38,7 @@ void RebuildTownCaches()
town->cache.num_houses = 0;
}
for (TileIndex t = 0; t < MapSize(); t++) {
for (TileIndex t = 0; t < Map::Size(); t++) {
if (!IsTileType(t, MP_HOUSE)) continue;
HouseID house_id = GetHouseType(t);
@@ -66,7 +66,7 @@ void RebuildTownCaches()
*/
void UpdateHousesAndTowns()
{
for (TileIndex t = 0; t < MapSize(); t++) {
for (TileIndex t = 0; t < Map::Size(); t++) {
if (!IsTileType(t, MP_HOUSE)) continue;
HouseID house_id = GetCleanHouseType(t);
@@ -79,7 +79,7 @@ void UpdateHousesAndTowns()
}
/* Check for cases when a NewGRF has set a wrong house substitute type. */
for (TileIndex t = 0; t < MapSize(); t++) {
for (TileIndex t = 0; t < Map::Size(); t++) {
if (!IsTileType(t, MP_HOUSE)) continue;
HouseID house_type = GetCleanHouseType(t);

View File

@@ -104,14 +104,14 @@ void MoveWaypointsToBaseStations()
* the map array. If this is the case, try to locate the actual location in the map array */
if (!IsTileType(t, MP_RAILWAY) || GetRailTileType(t) != 2 /* RAIL_TILE_WAYPOINT */ || _m[t].m2 != wp.index) {
Debug(sl, 0, "Found waypoint tile {} with invalid position", t);
for (t = 0; t < MapSize(); t++) {
for (t = 0; t < Map::Size(); t++) {
if (IsTileType(t, MP_RAILWAY) && GetRailTileType(t) == 2 /* RAIL_TILE_WAYPOINT */ && _m[t].m2 == wp.index) {
Debug(sl, 0, "Found actual waypoint position at {}", t);
break;
}
}
}
if (t == MapSize()) {
if (t == Map::Size()) {
SlErrorCorrupt("Waypoint with invalid tile");
}