Mercurial > hg > openttd
changeset 3515:c2be508d40f1 draft
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
author | belugas <belugas@openttd.org> |
---|---|
date | Tue, 11 Apr 2006 22:09:21 +0000 |
parents | e9ec3f0b5f00 |
children | 417f86b10d32 |
files | clear_map.h station_cmd.c |
diffstat | 2 files changed, 48 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/clear_map.h +++ b/clear_map.h @@ -19,6 +19,10 @@ } ClearGround; + + + + static inline ClearGround GetClearGround(TileIndex t) { assert(IsTileType(t, MP_CLEAR));
--- a/station_cmd.c +++ b/station_cmd.c @@ -28,6 +28,7 @@ #include "depot.h" #include "train.h" #include "water_map.h" +#include "industry_map.h" enum { /* Max stations: 64000 (64 * 1000) */ @@ -273,25 +274,44 @@ } -static int CountMapSquareAround(TileIndex tile, byte type, byte min, byte max) +/** + * Counts the numbers of tiles matching a specific type in the area around + * @param tile the center tile of the 'count area' + * @param type the type of tile searched for + * @param industry when type == MP_INDUSTRY, the type of the industry, + * in all other cases this parameter is ignored + * @result the noumber of matching tiles around + */ +static int CountMapSquareAround(TileIndex tile, TileType type, IndustryType industry) { - static const TileIndexDiffC _count_square_table[] = { - {-3, -3}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, - {-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, - {-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, - {-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, - {-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, - {-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, - {-6, 1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0} - }; - const TileIndexDiffC *p; + TileIndex cur_tile; + int dx, dy; int num = 0; - for (p = _count_square_table; p != endof(_count_square_table); ++p) { - tile = TILE_MASK(tile + ToTileIndexDiff(*p)); - - if (IsTileType(tile, type) && _m[tile].m5 >= min && _m[tile].m5 <= max) - num++; + for (dx = -3; dx <= 3; dx++) { + for (dy = -3; dy <= 3; dy++) { + cur_tile = tile + TileDiffXY(dx, dy); + + if (IsTileType(cur_tile, type)) { + switch (type) { + case MP_INDUSTRY: + if (GetIndustryType(cur_tile) == industry) + num++; + break; + + case MP_WATER: + if (!IsWater(cur_tile)) + break; + /* FALL THROUGH WHEN WATER TILE */ + case MP_TREES: + num++; + break; + + default: + break; + } + } + } } return num; @@ -340,11 +360,11 @@ /* check mine? */ if (HASBIT(free_names, M(STR_SV_STNAME_MINES))) { - if (CountMapSquareAround(tile, MP_INDUSTRY, 0, 6) >= 2 || - CountMapSquareAround(tile, MP_INDUSTRY, 0x64, 0x73) >= 2 || - CountMapSquareAround(tile, MP_INDUSTRY, 0x2F, 0x33) >= 2 || - CountMapSquareAround(tile, MP_INDUSTRY, 0x48, 0x58) >= 2 || - CountMapSquareAround(tile, MP_INDUSTRY, 0x5B, 0x63) >= 2) { + if (CountMapSquareAround(tile, MP_INDUSTRY, IT_COAL_MINE) >= 2 || + CountMapSquareAround(tile, MP_INDUSTRY, IT_IRON_MINE) >= 2 || + CountMapSquareAround(tile, MP_INDUSTRY, IT_COPPER_MINE) >= 2 || + CountMapSquareAround(tile, MP_INDUSTRY, IT_GOLD_MINE) >= 2 || + CountMapSquareAround(tile, MP_INDUSTRY, IT_DIAMOND_MINE) >= 2) { found = M(STR_SV_STNAME_MINES); goto done; } @@ -362,15 +382,15 @@ /* Check lakeside */ if (HASBIT(free_names, M(STR_SV_STNAME_LAKESIDE)) && DistanceFromEdge(tile) < 20 && - CountMapSquareAround(tile, MP_WATER, 0, 0) >= 5) { + CountMapSquareAround(tile, MP_WATER, 0) >= 5) { found = M(STR_SV_STNAME_LAKESIDE); goto done; } /* Check woods */ if (HASBIT(free_names, M(STR_SV_STNAME_WOODS)) && ( - CountMapSquareAround(tile, MP_TREES, 0, 255) >= 8 || - CountMapSquareAround(tile, MP_INDUSTRY, 0x10, 0x11) >= 2) + CountMapSquareAround(tile, MP_TREES, 0) >= 8 || + CountMapSquareAround(tile, MP_INDUSTRY, IT_FOREST) >= 2) ) { found = _opt.landscape == LT_DESERT ? M(STR_SV_STNAME_FOREST) : M(STR_SV_STNAME_WOODS);