Mercurial > hg > openttd
changeset 8308:e9042729a5c5 draft
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
author | belugas <belugas@openttd.org> |
---|---|
date | Wed, 16 Jan 2008 02:53:55 +0000 |
parents | 820c6cc79cf4 |
children | 132c40a27dfb |
files | src/road_cmd.cpp src/town.h src/town_cmd.cpp |
diffstat | 3 files changed, 31 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -1203,14 +1203,14 @@ const Town* t = ClosestTownFromTile(tile, (uint)-1); if (!HasRoadWorks(tile)) { - int grp = 0; + HouseZonesBits grp = HZB_TOWN_EDGE; if (t != NULL) { grp = GetTownRadiusGroup(t, tile); /* Show an animation to indicate road work */ if (t->road_build_months != 0 && - (DistanceManhattan(t->xy, tile) < 8 || grp != 0) && + (DistanceManhattan(t->xy, tile) < 8 || grp != HZB_TOWN_EDGE) && GetRoadTileType(tile) == ROAD_TILE_NORMAL && CountBits(GetAllRoadBits(tile)) > 1 ) { if (GetTileSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicleOnGround(tile) && Chance16(1, 40)) { StartRoadWorks(tile);
--- a/src/town.h +++ b/src/town.h @@ -44,13 +44,21 @@ DECLARE_ENUM_AS_BIT_SET(BuildingFlags) +enum HouseZonesBits { + HZB_TOWN_EDGE = 0, + HZB_TOWN_OUTSKIRT, + HZB_TOWN_OUTER_SUBURB, + HZB_TOWN_INNER_SUBURB, + HZB_TOWN_CENTRE, +}; + enum HouseZones { ///< Bit Value Meaning HZ_NOZNS = 0x0000, ///< 0 This is just to get rid of zeros, meaning none - HZ_ZON1 = 0x0001, ///< 0..4 1,2,4,8,10 which town zones the building can be built in, Zone1 been the further suburb - HZ_ZON2 = 0x0002, - HZ_ZON3 = 0x0004, - HZ_ZON4 = 0x0008, - HZ_ZON5 = 0x0010, ///< center of town + HZ_ZON1 = 1U << HZB_TOWN_EDGE, ///< 0..4 1,2,4,8,10 which town zones the building can be built in, Zone1 been the further suburb + HZ_ZON2 = 1U << HZB_TOWN_OUTSKIRT, + HZ_ZON3 = 1U << HZB_TOWN_OUTER_SUBURB, + HZ_ZON4 = 1U << HZB_TOWN_INNER_SUBURB, + HZ_ZON5 = 1U << HZB_TOWN_CENTRE, ///< center of town HZ_ZONALL = 0x001F, ///< 1F This is just to englobe all above types at once HZ_SUBARTC_ABOVE = 0x0800, ///< 11 800 can appear in sub-arctic climate above the snow line HZ_TEMP = 0x1000, ///< 12 1000 can appear in temperate climate @@ -315,7 +323,7 @@ bool CheckIfAuthorityAllows(TileIndex tile); Town *ClosestTownFromTile(TileIndex tile, uint threshold); void ChangeTownRating(Town *t, int add, int max); -uint GetTownRadiusGroup(const Town* t, TileIndex tile); +HouseZonesBits GetTownRadiusGroup(const Town* t, TileIndex tile); void SetTownRatingTestMode(bool mode); #endif /* TOWN_H */
--- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1622,18 +1622,22 @@ return CmdSucceeded(DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR)); } - -uint GetTownRadiusGroup(const Town* t, TileIndex tile) +/** Returns the bit corresponding to the town zone of the specified tile + * @param t Town on which radius is to be found + * @param tile TileIndex where radius needs to be found + * @return the bit position of the given zone, as defined in HouseZones + */ +HouseZonesBits GetTownRadiusGroup(const Town* t, TileIndex tile) { uint dist = DistanceSquare(tile, t->xy); - uint smallest; + HouseZonesBits smallest; uint i; - if (t->fund_buildings_months && dist <= 25) return 4; - - smallest = 0; + if (t->fund_buildings_months && dist <= 25) return HZB_TOWN_CENTRE; + + smallest = HZB_TOWN_EDGE; for (i = 0; i != lengthof(t->radius); i++) { - if (dist < t->radius[i]) smallest = i; + if (dist < t->radius[i]) smallest = (HouseZonesBits)i; } return smallest; @@ -1677,9 +1681,10 @@ /* Above snow? */ slope = GetTileSlope(tile, &z); - /* Get the town zone type */ + /* Get the town zone type of the current tile, as well as the climate. + * This will allow to easily compare with the specs of the new house to build */ { - uint rad = GetTownRadiusGroup(t, tile); + HouseZonesBits rad = GetTownRadiusGroup(t, tile); int land = _opt.landscape; if (land == LT_ARCTIC && z >= _opt.snow_line) land = -1; @@ -1699,6 +1704,7 @@ /* Generate a list of all possible houses that can be built. */ for (i = 0; i < HOUSE_MAX; i++) { hs = GetHouseSpecs(i); + /* Verify that the candidate house spec matches the current tile status */ if ((~hs->building_availability & bitmask) == 0 && hs->enabled) { if (_loaded_newgrf_features.has_newhouses) { probability_max += hs->probability;