(svn r12897) -Codechange: some coding style in station_cmd.cpp.

This commit is contained in:
rubidium 2008-04-25 15:22:32 +00:00
parent 9d7181abd7
commit 1aa7d9faff

View File

@ -238,7 +238,7 @@ enum StationNaming {
STATIONNAMING_HELIPORT, STATIONNAMING_HELIPORT,
}; };
static void GenerateStationName(Station *st, TileIndex tile, int flag) static StringID GenerateStationName(Station *st, TileIndex tile, int flag)
{ {
static const uint32 _gen_station_name_bits[] = { static const uint32 _gen_station_name_bits[] = {
0, /* 0 */ 0, /* 0 */
@ -252,9 +252,7 @@ static void GenerateStationName(Station *st, TileIndex tile, int flag)
const Town *t = st->town; const Town *t = st->town;
uint32 free_names = UINT32_MAX; uint32 free_names = UINT32_MAX;
{
const Station *s; const Station *s;
FOR_ALL_STATIONS(s) { FOR_ALL_STATIONS(s) {
if (s != st && s->town == t) { if (s != st && s->town == t) {
uint str = M(s->string_id); uint str = M(s->string_id);
@ -266,39 +264,30 @@ static void GenerateStationName(Station *st, TileIndex tile, int flag)
} }
} }
} }
}
/* check default names */ /* check default names */
uint32 tmp = free_names & _gen_station_name_bits[flag]; uint32 tmp = free_names & _gen_station_name_bits[flag];
int found; if (tmp != 0) return STR_SV_STNAME + FindFirstBit(tmp);
if (tmp != 0) {
found = FindFirstBit(tmp);
goto done;
}
/* check mine? */ /* check mine? */
if (HasBit(free_names, M(STR_SV_STNAME_MINES))) { if (HasBit(free_names, M(STR_SV_STNAME_MINES))) {
if (CountMapSquareAround(tile, CMSAMine) >= 2) { if (CountMapSquareAround(tile, CMSAMine) >= 2) {
found = M(STR_SV_STNAME_MINES); return STR_SV_STNAME_MINES;
goto done;
} }
} }
/* check close enough to town to get central as name? */ /* check close enough to town to get central as name? */
if (DistanceMax(tile, t->xy) < 8) { if (DistanceMax(tile, t->xy) < 8) {
found = M(STR_SV_STNAME); if (HasBit(free_names, M(STR_SV_STNAME))) return STR_SV_STNAME;
if (HasBit(free_names, M(STR_SV_STNAME))) goto done;
found = M(STR_SV_STNAME_CENTRAL); if (HasBit(free_names, M(STR_SV_STNAME_CENTRAL))) return STR_SV_STNAME_CENTRAL;
if (HasBit(free_names, M(STR_SV_STNAME_CENTRAL))) goto done;
} }
/* Check lakeside */ /* Check lakeside */
if (HasBit(free_names, M(STR_SV_STNAME_LAKESIDE)) && if (HasBit(free_names, M(STR_SV_STNAME_LAKESIDE)) &&
DistanceFromEdge(tile) < 20 && DistanceFromEdge(tile) < 20 &&
CountMapSquareAround(tile, CMSAWater) >= 5) { CountMapSquareAround(tile, CMSAWater) >= 5) {
found = M(STR_SV_STNAME_LAKESIDE); return STR_SV_STNAME_LAKESIDE;
goto done;
} }
/* Check woods */ /* Check woods */
@ -306,26 +295,19 @@ static void GenerateStationName(Station *st, TileIndex tile, int flag)
CountMapSquareAround(tile, CMSATree) >= 8 || CountMapSquareAround(tile, CMSATree) >= 8 ||
CountMapSquareAround(tile, CMSAForest) >= 2) CountMapSquareAround(tile, CMSAForest) >= 2)
) { ) {
found = _opt.landscape == LT_TROPIC ? return _opt.landscape == LT_TROPIC ? STR_SV_STNAME_FOREST : STR_SV_STNAME_WOODS;
M(STR_SV_STNAME_FOREST) : M(STR_SV_STNAME_WOODS);
goto done;
} }
/* check elevation compared to town */ /* check elevation compared to town */
{
uint z = GetTileZ(tile); uint z = GetTileZ(tile);
uint z2 = GetTileZ(t->xy); uint z2 = GetTileZ(t->xy);
if (z < z2) { if (z < z2) {
found = M(STR_SV_STNAME_VALLEY); if (HasBit(free_names, M(STR_SV_STNAME_VALLEY))) return STR_SV_STNAME_VALLEY;
if (HasBit(free_names, M(STR_SV_STNAME_VALLEY))) goto done;
} else if (z > z2) { } else if (z > z2) {
found = M(STR_SV_STNAME_HEIGHTS); if (HasBit(free_names, M(STR_SV_STNAME_HEIGHTS))) return STR_SV_STNAME_HEIGHTS;
if (HasBit(free_names, M(STR_SV_STNAME_HEIGHTS))) goto done;
}
} }
/* check direction compared to town */ /* check direction compared to town */
{
static const int8 _direction_and_table[] = { static const int8 _direction_and_table[] = {
~( (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_EAST)) | (1 << M(STR_SV_STNAME_NORTH)) ), ~( (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_EAST)) | (1 << M(STR_SV_STNAME_NORTH)) ),
~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_NORTH)) ), ~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_NORTH)) ),
@ -336,13 +318,9 @@ static void GenerateStationName(Station *st, TileIndex tile, int flag)
free_names &= _direction_and_table[ free_names &= _direction_and_table[
(TileX(tile) < TileX(t->xy)) + (TileX(tile) < TileX(t->xy)) +
(TileY(tile) < TileY(t->xy)) * 2]; (TileY(tile) < TileY(t->xy)) * 2];
}
tmp = free_names & ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 6) | (1 << 7) | (1 << 12) | (1 << 26) | (1 << 27) | (1 << 28) | (1 << 29) | (1 << 30)); tmp = free_names & ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 6) | (1 << 7) | (1 << 12) | (1 << 26) | (1 << 27) | (1 << 28) | (1 << 29) | (1 << 30));
found = (tmp == 0) ? M(STR_SV_STNAME_FALLBACK) : FindFirstBit(tmp); return (tmp == 0) ? STR_SV_STNAME_FALLBACK : (STR_SV_STNAME + FindFirstBit(tmp));
done:
st->string_id = found + STR_SV_STNAME;
} }
#undef M #undef M
@ -524,22 +502,15 @@ void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile,
} }
} }
struct ottd_Rectangle { static inline void MergePoint(Rect *rect, TileIndex tile)
uint min_x;
uint min_y;
uint max_x;
uint max_y;
};
static inline void MergePoint(ottd_Rectangle *rect, TileIndex tile)
{ {
uint x = TileX(tile); int x = TileX(tile);
uint y = TileY(tile); int y = TileY(tile);
if (rect->min_x > x) rect->min_x = x; if (rect->left > x) rect->left = x;
if (rect->min_y > y) rect->min_y = y; if (rect->bottom > y) rect->bottom = y;
if (rect->max_x < x) rect->max_x = x; if (rect->right < x) rect->right = x;
if (rect->max_y < y) rect->max_y = y; if (rect->top < y) rect->top = y;
} }
/** Update the acceptance for a station. /** Update the acceptance for a station.
@ -551,11 +522,11 @@ static void UpdateStationAcceptance(Station *st, bool show_msg)
/* Don't update acceptance for a buoy */ /* Don't update acceptance for a buoy */
if (st->IsBuoy()) return; if (st->IsBuoy()) return;
ottd_Rectangle rect; Rect rect;
rect.min_x = MapSizeX(); rect.left = MapSizeX();
rect.min_y = MapSizeY(); rect.bottom = MapSizeY();
rect.max_x = 0; rect.right = 0;
rect.max_y = 0; rect.top = 0;
/* old accepted goods types */ /* old accepted goods types */
uint old_acc = GetAcceptanceMask(st); uint old_acc = GetAcceptanceMask(st);
@ -585,12 +556,12 @@ static void UpdateStationAcceptance(Station *st, bool show_msg)
/* And retrieve the acceptance. */ /* And retrieve the acceptance. */
AcceptedCargo accepts; AcceptedCargo accepts;
if (rect.max_x >= rect.min_x) { if (rect.right >= rect.left) {
GetAcceptanceAroundTiles( GetAcceptanceAroundTiles(
accepts, accepts,
TileXY(rect.min_x, rect.min_y), TileXY(rect.left, rect.bottom),
rect.max_x - rect.min_x + 1, rect.right - rect.left + 1,
rect.max_y - rect.min_y + 1, rect.top - rect.bottom + 1,
_patches.modified_catchment ? FindCatchmentRadius(st) : (uint)CA_UNMODIFIED _patches.modified_catchment ? FindCatchmentRadius(st) : (uint)CA_UNMODIFIED
); );
} else { } else {
@ -983,7 +954,7 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1,
st = new Station(); st = new Station();
st->town = ClosestTownFromTile(tile_org, UINT_MAX); st->town = ClosestTownFromTile(tile_org, UINT_MAX);
GenerateStationName(st, tile_org, STATIONNAMING_RAIL); st->string_id = GenerateStationName(st, tile_org, STATIONNAMING_RAIL);
if (IsValidPlayer(_current_player)) { if (IsValidPlayer(_current_player)) {
SetBit(st->town->have_ratings, _current_player); SetBit(st->town->have_ratings, _current_player);
@ -1407,7 +1378,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
st = new Station(); st = new Station();
st->town = ClosestTownFromTile(tile, UINT_MAX); st->town = ClosestTownFromTile(tile, UINT_MAX);
GenerateStationName(st, tile, STATIONNAMING_ROAD); st->string_id = GenerateStationName(st, tile, STATIONNAMING_ROAD);
if (IsValidPlayer(_current_player)) { if (IsValidPlayer(_current_player)) {
SetBit(st->town->have_ratings, _current_player); SetBit(st->town->have_ratings, _current_player);
@ -1715,7 +1686,7 @@ CommandCost CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
st = new Station(); st = new Station();
st->town = t; st->town = t;
GenerateStationName(st, tile, !(afc->flags & AirportFTAClass::AIRPLANES) ? STATIONNAMING_HELIPORT : STATIONNAMING_AIRPORT); st->string_id = GenerateStationName(st, tile, !(afc->flags & AirportFTAClass::AIRPLANES) ? STATIONNAMING_HELIPORT : STATIONNAMING_AIRPORT);
if (IsValidPlayer(_current_player)) { if (IsValidPlayer(_current_player)) {
SetBit(st->town->have_ratings, _current_player); SetBit(st->town->have_ratings, _current_player);
@ -1832,7 +1803,7 @@ CommandCost CmdBuildBuoy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
Station *st = new Station(); Station *st = new Station();
st->town = ClosestTownFromTile(tile, UINT_MAX); st->town = ClosestTownFromTile(tile, UINT_MAX);
GenerateStationName(st, tile, STATIONNAMING_BUOY); st->string_id = GenerateStationName(st, tile, STATIONNAMING_BUOY);
if (IsValidPlayer(_current_player)) { if (IsValidPlayer(_current_player)) {
SetBit(st->town->have_ratings, _current_player); SetBit(st->town->have_ratings, _current_player);
@ -1992,7 +1963,7 @@ CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
st = new Station(); st = new Station();
st->town = ClosestTownFromTile(tile, UINT_MAX); st->town = ClosestTownFromTile(tile, UINT_MAX);
GenerateStationName(st, tile, STATIONNAMING_DOCK); st->string_id = GenerateStationName(st, tile, STATIONNAMING_DOCK);
if (IsValidPlayer(_current_player)) { if (IsValidPlayer(_current_player)) {
SetBit(st->town->have_ratings, _current_player); SetBit(st->town->have_ratings, _current_player);
@ -2479,8 +2450,8 @@ static void UpdateStationRating(Station *st)
int rating = 0; int rating = 0;
{ {
int b = ge->last_speed; int b = ge->last_speed - 85;
if ((b -= 85) >= 0) if (b >= 0)
rating += b >> 2; rating += b >> 2;
} }
@ -2833,7 +2804,7 @@ void BuildOilRig(TileIndex tile)
st->town = ClosestTownFromTile(tile, UINT_MAX); st->town = ClosestTownFromTile(tile, UINT_MAX);
st->sign.width_1 = 0; st->sign.width_1 = 0;
GenerateStationName(st, tile, STATIONNAMING_OILRIG); st->string_id = GenerateStationName(st, tile, STATIONNAMING_OILRIG);
MakeOilrig(tile, st->index); MakeOilrig(tile, st->index);