summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbelugas <belugas@openttd.org>2008-01-16 02:53:55 +0000
committerbelugas <belugas@openttd.org>2008-01-16 02:53:55 +0000
commit88206b88080492c5ee8bb66351c546b254414b18 (patch)
tree09c173d8b36aaf573b2aaa27505e66d547cbe189
parent48c2669185f467dcfccafa704890431278efb052 (diff)
downloadopenttd-88206b88080492c5ee8bb66351c546b254414b18.tar.xz
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
-rw-r--r--src/road_cmd.cpp4
-rw-r--r--src/town.h20
-rw-r--r--src/town_cmd.cpp22
3 files changed, 30 insertions, 16 deletions
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 7124a6943..dcb3871c6 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -1203,14 +1203,14 @@ static void TileLoop_Road(TileIndex tile)
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);
diff --git a/src/town.h b/src/town.h
index 084e19bff..62a49653a 100644
--- a/src/town.h
+++ b/src/town.h
@@ -44,13 +44,21 @@ enum BuildingFlags {
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 @@ void UpdateTownMaxPass(Town *t);
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 */
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 3bb6b7d9c..a45928222 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -1622,18 +1622,22 @@ static bool CheckBuildHouseMode(TileIndex tile, Slope tileh, int mode)
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;
+ if (t->fund_buildings_months && dist <= 25) return HZB_TOWN_CENTRE;
- smallest = 0;
+ 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 @@ static void DoBuildTownHouse(Town *t, TileIndex tile)
/* 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 @@ static void DoBuildTownHouse(Town *t, TileIndex tile)
/* 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;