(svn r3747) Change HASBIT() to return 0/1 instead of 0/value of tested bit, because the name suggests it does the former and current behavior broke in some places in very subtle ways (for example HASBIT(x, 0) != HASBIT(y, 1) doesn't work, returning a bool after HASBIT(x, 9) neither)
authortron
Fri, 03 Mar 2006 19:42:09 +0000
changeset 3132 724ede39bda9
parent 3131 e856656f99a9
child 3133 341ab7934ab8
(svn r3747) Change HASBIT() to return 0/1 instead of 0/value of tested bit, because the name suggests it does the former and current behavior broke in some places in very subtle ways (for example HASBIT(x, 0) != HASBIT(y, 1) doesn't work, returning a bool after HASBIT(x, 9) neither)
macros.h
pathfind.c
rail.h
rail_gui.c
road_gui.c
vehicle.c
--- a/macros.h	Fri Mar 03 11:27:18 2006 +0000
+++ b/macros.h	Fri Mar 03 19:42:09 2006 +0000
@@ -57,7 +57,7 @@
 #define IS_INSIDE_1D(x, base, size) ( (uint)((x) - (base)) < ((uint)(size)) )
 
 
-#define HASBIT(x,y)    ((x) &   (1 << (y)))
+#define HASBIT(x,y)    (((x) & (1 << (y))) != 0)
 #define SETBIT(x,y)    ((x) |=  (1 << (y)))
 #define CLRBIT(x,y)    ((x) &= ~(1 << (y)))
 #define TOGGLEBIT(x,y) ((x) ^=  (1 << (y)))
--- a/pathfind.c	Fri Mar 03 11:27:18 2006 +0000
+++ b/pathfind.c	Fri Mar 03 19:42:09 2006 +0000
@@ -388,8 +388,8 @@
 
 	tpf.var2 = HASBIT(flags, 15) ? 0x43 : 0xFF; /* 0x8000 */
 
-	tpf.disable_tile_hash = HASBIT(flags, 12) != 0;     /* 0x1000 */
-	tpf.hasbit_13 = HASBIT(flags, 13) != 0;		 /* 0x2000 */
+	tpf.disable_tile_hash = HASBIT(flags, 12);  /* 0x1000 */
+	tpf.hasbit_13         = HASBIT(flags, 13);  /* 0x2000 */
 
 
 	tpf.tracktype = (byte)flags;
--- a/rail.h	Fri Mar 03 11:27:18 2006 +0000
+++ b/rail.h	Fri Mar 03 19:42:09 2006 +0000
@@ -557,7 +557,7 @@
 static inline bool HasSemaphores(TileIndex tile, Track track)
 {
 	assert(IsValidTrack(track));
-	return _m[tile].m4 & SIG_SEMAPHORE_MASK;
+	return (_m[tile].m4 & SIG_SEMAPHORE_MASK) != 0;
 }
 
 /**
--- a/rail_gui.c	Fri Mar 03 11:27:18 2006 +0000
+++ b/rail_gui.c	Fri Mar 03 19:42:09 2006 +0000
@@ -291,8 +291,8 @@
 	SndPlayFx(SND_15_BEEP);
 
 	TOGGLEBIT(w->click_state, 16);
-	_remove_button_clicked = HASBIT(w->click_state, 16) != 0;
-	SetSelectionRed(HASBIT(w->click_state, 16) != 0);
+	_remove_button_clicked = HASBIT(w->click_state, 16);
+	SetSelectionRed(HASBIT(w->click_state, 16));
 
 	// handle station builder
 	if (HASBIT(w->click_state, 16)) {
--- a/road_gui.c	Fri Mar 03 11:27:18 2006 +0000
+++ b/road_gui.c	Fri Mar 03 19:42:09 2006 +0000
@@ -158,7 +158,7 @@
 	SetWindowDirty(w);
 	SndPlayFx(SND_15_BEEP);
 	TOGGLEBIT(w->click_state, 11);
-	SetSelectionRed(HASBIT(w->click_state, 11) != 0);
+	SetSelectionRed(HASBIT(w->click_state, 11));
 }
 
 static void BuildRoadClick_Landscaping(Window *w)
--- a/vehicle.c	Fri Mar 03 11:27:18 2006 +0000
+++ b/vehicle.c	Fri Mar 03 19:42:09 2006 +0000
@@ -688,7 +688,7 @@
 bool CanRefitTo(EngineID engine_type, CargoID cid_to)
 {
 	CargoID cid = _global_cargo_id[_opt_ptr->landscape][cid_to];
-	return HASBIT(_engine_info[engine_type].refit_mask, cid) != 0;
+	return HASBIT(_engine_info[engine_type].refit_mask, cid);
 }
 
 static void DoDrawVehicle(const Vehicle *v)