(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
authortron
Tue, 15 Nov 2005 09:47:25 +0000
changeset 2645 964bd8fe3ce2
parent 2644 6f699b15c531
child 2646 a91fd482fce5
(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
command.c
gfx.c
newgrf.c
order_cmd.c
rail_cmd.c
--- a/command.c	Tue Nov 15 09:05:16 2005 +0000
+++ b/command.c	Tue Nov 15 09:47:25 2005 +0000
@@ -309,12 +309,11 @@
 /* This function range-checks a cmd, and checks if the cmd is not NULL */
 bool IsValidCommand(uint cmd)
 {
-	cmd = cmd & 0xFF;
+	cmd &= 0xFF;
 
-	if (cmd >= lengthof(_command_proc_table) || _command_proc_table[cmd].proc == NULL)
-		return false;
-
-	return true;
+	return
+		cmd < lengthof(_command_proc_table) &&
+		_command_proc_table[cmd].proc != NULL;
 }
 
 byte GetCommandFlags(uint cmd) {return _command_proc_table[cmd & 0xFF].flags;}
--- a/gfx.c	Tue Nov 15 09:05:16 2005 +0000
+++ b/gfx.c	Tue Nov 15 09:47:25 2005 +0000
@@ -1970,10 +1970,9 @@
 
 bool ChangeResInGame(int w, int h)
 {
-	if ((_screen.width != w || _screen.height != h) && !_video_driver->change_resolution(w, h))
-		return false;
-
-	return true;
+	return
+		(_screen.width == w && _screen.height == h) ||
+		_video_driver->change_resolution(w, h);
 }
 
 void ToggleFullScreen(bool fs) {_video_driver->toggle_fullscreen(fs);}
--- a/newgrf.c	Tue Nov 15 09:05:16 2005 +0000
+++ b/newgrf.c	Tue Nov 15 09:47:25 2005 +0000
@@ -2572,24 +2572,14 @@
 
 	if (action >= lengthof(handlers)) {
 		DEBUG(grf, 7) ("Skipping unknown action 0x%02X", action);
-		free(buf);
-		return;
-	}
-
-	if (!HASBIT(action_mask, action)) {
+	} else if (!HASBIT(action_mask, action)) {
 		DEBUG(grf, 7) ("Skipping action 0x%02X in stage %d", action, stage);
-		free(buf);
-		return;
+	} else if (handlers[action] == NULL) {
+		DEBUG(grf, 7) ("Skipping unsupported Action 0x%02X", action);
+	} else {
+		DEBUG(grf, 7) ("Handling action 0x%02X in stage %d", action, stage);
+		handlers[action](buf, num);
 	}
-
-	if (handlers[action] == NULL) {
-		DEBUG(grf, 7) ("Skipping unsupported Action 0x%02X", action);
-		free(buf);
-		return;
-	}
-
-	DEBUG(grf, 7) ("Handling action 0x%02X in stage %d", action, stage);
-	handlers[action](buf, num);
 	free(buf);
 }
 
--- a/order_cmd.c	Tue Nov 15 09:05:16 2005 +0000
+++ b/order_cmd.c	Tue Nov 15 09:47:25 2005 +0000
@@ -1077,13 +1077,7 @@
  */
 bool IsOrderListShared(const Vehicle *v)
 {
-	if (v->next_shared != NULL)
-		return true;
-
-	if (v->prev_shared != NULL)
-		return true;
-
-	return false;
+	return v->next_shared != NULL || v->prev_shared != NULL;
 }
 
 /**
--- a/rail_cmd.c	Tue Nov 15 09:05:16 2005 +0000
+++ b/rail_cmd.c	Tue Nov 15 09:47:25 2005 +0000
@@ -1225,12 +1225,7 @@
 static void DrawTrackFence_NW(const TileInfo *ti)
 {
 	uint32 image = 0x515;
-	if (ti->tileh != 0) {
-		image = 0x519;
-		if (!(ti->tileh & 2)) {
-			image = 0x51B;
-		}
-	}
+	if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x519 : 0x51B;
 	AddSortableSpriteToDraw(image | _drawtile_track_palette,
 		ti->x, ti->y+1, 16, 1, 4, ti->z);
 }
@@ -1238,12 +1233,7 @@
 static void DrawTrackFence_SE(const TileInfo *ti)
 {
 	uint32 image = 0x515;
-	if (ti->tileh != 0) {
-		image = 0x519;
-		if (!(ti->tileh & 2)) {
-			image = 0x51B;
-		}
-	}
+	if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x519 : 0x51B;
 	AddSortableSpriteToDraw(image | _drawtile_track_palette,
 		ti->x, ti->y+15, 16, 1, 4, ti->z);
 }
@@ -1257,12 +1247,7 @@
 static void DrawTrackFence_NE(const TileInfo *ti)
 {
 	uint32 image = 0x516;
-	if (ti->tileh != 0) {
-		image = 0x51A;
-		if (!(ti->tileh & 2)) {
-			image = 0x51C;
-		}
-	}
+	if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x51A : 0x51C;
 	AddSortableSpriteToDraw(image | _drawtile_track_palette,
 		ti->x+1, ti->y, 1, 16, 4, ti->z);
 }
@@ -1270,12 +1255,7 @@
 static void DrawTrackFence_SW(const TileInfo *ti)
 {
 	uint32 image = 0x516;
-	if (ti->tileh != 0) {
-		image = 0x51A;
-		if (!(ti->tileh & 2)) {
-			image = 0x51C;
-		}
-	}
+	if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x51A : 0x51C;
 	AddSortableSpriteToDraw(image | _drawtile_track_palette,
 		ti->x+15, ti->y, 1, 16, 4, ti->z);
 }