changeset 15162:c5ccb53c4985 draft

(svn r19791) -Change: use the typed FOR_EACH_SET_BIT for RoadTypes (adf88)
author rubidium <rubidium@openttd.org>
date Tue, 11 May 2010 21:01:57 +0000
parents 4b00526d0be8
children 5fa5a4d1f409
files src/road_cmd.cpp src/road_func.h
diffstat 2 files changed, 16 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -944,14 +944,12 @@
 
 			/* Clear the road if only one piece is on the tile OR we are not using the DC_AUTO flag */
 			if ((HasExactlyOneBit(b) && GetRoadBits(tile, ROADTYPE_TRAM) == ROAD_NONE) || !(flags & DC_AUTO)) {
-				RoadTypes rts = GetRoadTypes(tile);
 				CommandCost ret(EXPENSES_CONSTRUCTION);
-				for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
-					if (HasBit(rts, rt)) {
-						CommandCost tmp_ret = RemoveRoad(tile, flags, GetRoadBits(tile, rt), rt, true);
-						if (tmp_ret.Failed()) return tmp_ret;
-						ret.AddCost(tmp_ret);
-					}
+				RoadType rt;
+				FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
+					CommandCost tmp_ret = RemoveRoad(tile, flags, GetRoadBits(tile, rt), rt, true);
+					if (tmp_ret.Failed()) return tmp_ret;
+					ret.AddCost(tmp_ret);
 				}
 				return ret;
 			}
--- a/src/road_func.h
+++ b/src/road_func.h
@@ -19,6 +19,17 @@
 #include "tile_type.h"
 
 /**
+ * Iterate through each set RoadType in a RoadTypes value.
+ * For more informations see FOR_EACH_SET_BIT_EX.
+ *
+ * @param var Loop index variable that stores fallowing set road type. Must be of type RoadType.
+ * @param road_types The value to iterate through (any expression).
+ *
+ * @see FOR_EACH_SET_BIT_EX
+ */
+#define FOR_EACH_SET_ROADTYPE(var, road_types) FOR_EACH_SET_BIT_EX(RoadType, var, RoadTypes, road_types)
+
+/**
  * Whether the given roadtype is valid.
  * @param rt the roadtype to check for validness
  * @return true if and only if valid