changeset 5027:ef34a6dbef98 draft

(svn r7068) if () cascades -> switch ()
author tron <tron@openttd.org>
date Sun, 05 Nov 2006 12:22:46 +0000
parents 99a35b49d8e2
children 43d379025dc8
files viewport.c
diffstat 1 files changed, 147 insertions(+), 130 deletions(-) [+]
line wrap: on
line diff
--- a/viewport.c
+++ b/viewport.c
@@ -768,48 +768,51 @@
 	right = left + dpi->width;
 	bottom = top + dpi->height;
 
-	if (dpi->zoom < 1) {
-		FOR_ALL_TOWNS(t) {
-			if (bottom > t->sign.top &&
-					top < t->sign.top + 12 &&
-					right > t->sign.left &&
-					left < t->sign.left + t->sign.width_1) {
-
-				AddStringToDraw(t->sign.left + 1, t->sign.top + 1,
-					_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL,
-					t->index, t->population);
+	switch (dpi->zoom) {
+		case 0:
+			FOR_ALL_TOWNS(t) {
+				if (bottom > t->sign.top &&
+						top    < t->sign.top + 12 &&
+						right  > t->sign.left &&
+						left   < t->sign.left + t->sign.width_1) {
+					AddStringToDraw(t->sign.left + 1, t->sign.top + 1,
+						_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL,
+						t->index, t->population);
+				}
 			}
-		}
-	} else if (dpi->zoom == 1) {
-		right += 2;
-		bottom += 2;
-
-		FOR_ALL_TOWNS(t) {
-			if (bottom > t->sign.top &&
-					top < t->sign.top + 24 &&
-					right > t->sign.left &&
-					left < t->sign.left + t->sign.width_1*2) {
-
-				AddStringToDraw(t->sign.left + 1, t->sign.top + 1,
-					_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL,
-					t->index, t->population);
+			break;
+
+		case 1:
+			right += 2;
+			bottom += 2;
+
+			FOR_ALL_TOWNS(t) {
+				if (bottom > t->sign.top &&
+						top    < t->sign.top + 24 &&
+						right  > t->sign.left &&
+						left   < t->sign.left + t->sign.width_1*2) {
+					AddStringToDraw(t->sign.left + 1, t->sign.top + 1,
+						_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL,
+						t->index, t->population);
+				}
 			}
-		}
-	} else {
-		right += 4;
-		bottom += 5;
-
-		assert(dpi->zoom == 2);
-		FOR_ALL_TOWNS(t) {
-			if (bottom > t->sign.top &&
-					top < t->sign.top + 24 &&
-					right > t->sign.left &&
-					left < t->sign.left + t->sign.width_2*4) {
-
-				AddStringToDraw(t->sign.left + 5, t->sign.top + 1, STR_TOWN_LABEL_TINY_BLACK, t->index, 0);
-				AddStringToDraw(t->sign.left + 1, t->sign.top - 3, STR_TOWN_LABEL_TINY_WHITE, t->index, 0);
+			break;
+
+		default: NOT_REACHED();
+		case 2:
+			right += 4;
+			bottom += 5;
+
+			FOR_ALL_TOWNS(t) {
+				if (bottom > t->sign.top &&
+						top    < t->sign.top + 24 &&
+						right  > t->sign.left &&
+						left   < t->sign.left + t->sign.width_2*4) {
+					AddStringToDraw(t->sign.left + 5, t->sign.top + 1, STR_TOWN_LABEL_TINY_BLACK, t->index, 0);
+					AddStringToDraw(t->sign.left + 1, t->sign.top - 3, STR_TOWN_LABEL_TINY_WHITE, t->index, 0);
+				}
 			}
-		}
+			break;
 	}
 }
 
@@ -839,42 +842,44 @@
 	right = left + dpi->width;
 	bottom = top + dpi->height;
 
-	if (dpi->zoom < 1) {
-		FOR_ALL_STATIONS(st) {
-			if (bottom > st->sign.top &&
-					top < st->sign.top + 12 &&
-					right > st->sign.left &&
-					left < st->sign.left + st->sign.width_1) {
-				AddStation(st, STR_305C_0, st->sign.width_1);
+	switch (dpi->zoom) {
+		case 0:
+			FOR_ALL_STATIONS(st) {
+				if (bottom > st->sign.top &&
+						top    < st->sign.top + 12 &&
+						right  > st->sign.left &&
+						left   < st->sign.left + st->sign.width_1) {
+					AddStation(st, STR_305C_0, st->sign.width_1);
+				}
 			}
-		}
-	} else if (dpi->zoom == 1) {
-		right += 2;
-		bottom += 2;
-
-		FOR_ALL_STATIONS(st) {
-			if (bottom > st->sign.top &&
-					top < st->sign.top + 24 &&
-					right > st->sign.left &&
-					left < st->sign.left + st->sign.width_1*2) {
-				AddStation(st, STR_305C_0, st->sign.width_1);
+			break;
+
+		case 1:
+			right += 2;
+			bottom += 2;
+			FOR_ALL_STATIONS(st) {
+				if (bottom > st->sign.top &&
+						top    < st->sign.top + 24 &&
+						right  > st->sign.left &&
+						left   < st->sign.left + st->sign.width_1*2) {
+					AddStation(st, STR_305C_0, st->sign.width_1);
+				}
 			}
-		}
-
-	} else {
-		assert(dpi->zoom == 2);
-
-		right += 4;
-		bottom += 5;
-
-		FOR_ALL_STATIONS(st) {
-			if (bottom > st->sign.top &&
-					top < st->sign.top + 24 &&
-					right > st->sign.left &&
-					left < st->sign.left + st->sign.width_2*4) {
-				AddStation(st, STR_STATION_SIGN_TINY, st->sign.width_2 | 0x8000);
+			break;
+
+		default: NOT_REACHED();
+		case 2:
+			right += 4;
+			bottom += 5;
+			FOR_ALL_STATIONS(st) {
+				if (bottom > st->sign.top &&
+						top    < st->sign.top + 24 &&
+						right  > st->sign.left &&
+						left   < st->sign.left + st->sign.width_2*4) {
+					AddStation(st, STR_STATION_SIGN_TINY, st->sign.width_2 | 0x8000);
+				}
 			}
-		}
+			break;
 	}
 }
 
@@ -904,38 +909,44 @@
 	right = left + dpi->width;
 	bottom = top + dpi->height;
 
-	if (dpi->zoom < 1) {
-		FOR_ALL_SIGNS(si) {
-			if (bottom > si->sign.top &&
-					top < si->sign.top + 12 &&
-					right > si->sign.left &&
-					left < si->sign.left + si->sign.width_1) {
-				AddSign(si, STR_2806, si->sign.width_1);
+	switch (dpi->zoom) {
+		case 0:
+			FOR_ALL_SIGNS(si) {
+				if (bottom > si->sign.top &&
+						top    < si->sign.top + 12 &&
+						right  > si->sign.left &&
+						left   < si->sign.left + si->sign.width_1) {
+					AddSign(si, STR_2806, si->sign.width_1);
+				}
 			}
-		}
-	} else if (dpi->zoom == 1) {
-		right += 2;
-		bottom += 2;
-		FOR_ALL_SIGNS(si) {
-			if (bottom > si->sign.top &&
-					top < si->sign.top + 24 &&
-					right > si->sign.left &&
-					left < si->sign.left + si->sign.width_1 * 2) {
-				AddSign(si, STR_2806, si->sign.width_1);
+			break;
+
+		case 1:
+			right += 2;
+			bottom += 2;
+			FOR_ALL_SIGNS(si) {
+				if (bottom > si->sign.top &&
+						top    < si->sign.top + 24 &&
+						right  > si->sign.left &&
+						left   < si->sign.left + si->sign.width_1 * 2) {
+					AddSign(si, STR_2806, si->sign.width_1);
+				}
 			}
-		}
-	} else {
-		right += 4;
-		bottom += 5;
-
-		FOR_ALL_SIGNS(si) {
-			if (bottom > si->sign.top &&
-					top < si->sign.top + 24 &&
-					right > si->sign.left &&
-					left < si->sign.left + si->sign.width_2 * 4) {
-				AddSign(si, STR_2002, si->sign.width_2 | 0x8000);
+			break;
+
+		default: NOT_REACHED();
+		case 2:
+			right += 4;
+			bottom += 5;
+			FOR_ALL_SIGNS(si) {
+				if (bottom > si->sign.top &&
+						top    < si->sign.top + 24 &&
+						right  > si->sign.left &&
+						left   < si->sign.left + si->sign.width_2 * 4) {
+					AddSign(si, STR_2002, si->sign.width_2 | 0x8000);
+				}
 			}
-		}
+			break;
 	}
 }
 
@@ -965,38 +976,44 @@
 	right = left + dpi->width;
 	bottom = top + dpi->height;
 
-	if (dpi->zoom < 1) {
-		FOR_ALL_WAYPOINTS(wp) {
-			if (bottom > wp->sign.top &&
-					top < wp->sign.top + 12 &&
-					right > wp->sign.left &&
-					left < wp->sign.left + wp->sign.width_1) {
-				AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1);
+	switch (dpi->zoom) {
+		case 0:
+			FOR_ALL_WAYPOINTS(wp) {
+				if (bottom > wp->sign.top &&
+						top    < wp->sign.top + 12 &&
+						right  > wp->sign.left &&
+						left   < wp->sign.left + wp->sign.width_1) {
+					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1);
+				}
 			}
-		}
-	} else if (dpi->zoom == 1) {
-		right += 2;
-		bottom += 2;
-		FOR_ALL_WAYPOINTS(wp) {
-			if (bottom > wp->sign.top &&
-					top < wp->sign.top + 24 &&
-					right > wp->sign.left &&
-					left < wp->sign.left + wp->sign.width_1*2) {
-				AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1);
+			break;
+
+		case 1:
+			right += 2;
+			bottom += 2;
+			FOR_ALL_WAYPOINTS(wp) {
+				if (bottom > wp->sign.top &&
+						top    < wp->sign.top + 24 &&
+						right  > wp->sign.left &&
+						left   < wp->sign.left + wp->sign.width_1*2) {
+					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1);
+				}
 			}
-		}
-	} else {
-		right += 4;
-		bottom += 5;
-
-		FOR_ALL_WAYPOINTS(wp) {
-			if (bottom > wp->sign.top &&
-					top < wp->sign.top + 24 &&
-					right > wp->sign.left &&
-					left < wp->sign.left + wp->sign.width_2*4) {
-				AddWaypoint(wp, STR_WAYPOINT_VIEWPORT_TINY, wp->sign.width_2 | 0x8000);
+			break;
+
+		default: NOT_REACHED();
+		case 2:
+			right += 4;
+			bottom += 5;
+			FOR_ALL_WAYPOINTS(wp) {
+				if (bottom > wp->sign.top &&
+						top    < wp->sign.top + 24 &&
+						right  > wp->sign.left &&
+						left   < wp->sign.left + wp->sign.width_2*4) {
+					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT_TINY, wp->sign.width_2 | 0x8000);
+				}
 			}
-		}
+			break;
 	}
 }