src/town_gui.cpp
branchNewGRF_ports
changeset 6871 5a9dc001e1ad
parent 6870 ca3fd1fbe311
child 6872 1c4a4a609f85
--- a/src/town_gui.cpp	Sat Oct 06 21:16:00 2007 +0000
+++ b/src/town_gui.cpp	Mon Dec 03 23:39:38 2007 +0000
@@ -95,7 +95,7 @@
 				continue;
 
 			/* Is the player not able to build a statue ? */
-			if (cur == TACT_BUILD_STATUE && HASBIT(t->statues, pid))
+			if (cur == TACT_BUILD_STATUE && HasBit(t->statues, pid))
 				continue;
 
 			if (avail >= _town_action_costs[i] * ref) {
@@ -109,15 +109,23 @@
 	return buttons;
 }
 
+/**
+ * Get the position of the Nth set bit.
+ *
+ * If there is no Nth bit set return -1
+ *
+ * @param bits The value to search in
+ * @param n The Nth set bit from which we want to know the position
+ * @return The position of the Nth set bit
+ */
 static int GetNthSetBit(uint32 bits, int n)
 {
-	int i = 0;
-
 	if (n >= 0) {
-		do {
-			if (bits & 1 && --n < 0) return i;
-			i++;
-		} while (bits >>= 1);
+		uint i;
+		FOR_EACH_SET_BIT(i, bits) {
+			n--;
+			if (n < 0) return i;
+		}
 	}
 	return -1;
 }
@@ -132,10 +140,10 @@
 
 		SetVScrollCount(w, numact + 1);
 
-		if (WP(w,def_d).data_1 != -1 && !HASBIT(buttons, WP(w,def_d).data_1))
+		if (WP(w,def_d).data_1 != -1 && !HasBit(buttons, WP(w,def_d).data_1))
 			WP(w,def_d).data_1 = -1;
 
-		SetWindowWidgetDisabledState(w, 6, WP(w, def_d).data_1 == -1);
+		w->SetWidgetDisabledState(6, WP(w, def_d).data_1 == -1);
 
 		{
 			int y;
@@ -146,12 +154,12 @@
 			SetDParam(0, w->window_number);
 			DrawWindowWidgets(w);
 
-			DrawString(2, 15, STR_2023_TRANSPORT_COMPANY_RATINGS, 0);
+			DrawString(2, 15, STR_2023_TRANSPORT_COMPANY_RATINGS, TC_FROMSTRING);
 
 			/* Draw list of players */
 			y = 25;
 			FOR_ALL_PLAYERS(p) {
-				if (p->is_active && (HASBIT(t->have_ratings, p->index) || t->exclusivity == p->index)) {
+				if (p->is_active && (HasBit(t->have_ratings, p->index) || t->exclusivity == p->index)) {
 					DrawPlayerIcon(p->index, 2, y);
 
 					SetDParam(0, p->index);
@@ -172,7 +180,7 @@
 						DrawSprite(SPR_BLOT, PALETTE_TO_RED, 18, y);
 					}
 
-					DrawString(28, y, STR_2024, 0);
+					DrawString(28, y, STR_2024, TC_FROMSTRING);
 					y += 10;
 				}
 			}
@@ -184,14 +192,14 @@
 			int pos = w->vscroll.pos;
 
 			if (--pos < 0) {
-				DrawString(2, y, STR_2045_ACTIONS_AVAILABLE, 0);
+				DrawString(2, y, STR_2045_ACTIONS_AVAILABLE, TC_FROMSTRING);
 				y += 10;
 			}
 			for (i = 0; buttons; i++, buttons >>= 1) {
 				if (pos <= -5) break; ///< Draw only the 5 fitting lines
 
 				if ((buttons & 1) && --pos < 0) {
-					DrawString(3, y, STR_2046_SMALL_ADVERTISING_CAMPAIGN + i, 6);
+					DrawString(3, y, STR_2046_SMALL_ADVERTISING_CAMPAIGN + i, TC_ORANGE);
 					y += 10;
 				}
 			}
@@ -216,7 +224,7 @@
 			const Town *t = GetTown(w->window_number);
 			int y = (e->we.click.pt.y - 0x6B) / 10;
 
-			if (!IS_INT_INSIDE(y, 0, 5)) return;
+			if (!IsInsideMM(y, 0, 5)) return;
 
 			y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_player, t), y + w->vscroll.pos - 1);
 			if (y >= 0) {
@@ -265,22 +273,22 @@
 	switch (e->event) {
 	case WE_PAINT:
 		/* disable renaming town in network games if you are not the server */
-		SetWindowWidgetDisabledState(w, 8, _networking && !_network_server);
+		w->SetWidgetDisabledState(8, _networking && !_network_server);
 
 		SetDParam(0, t->index);
 		DrawWindowWidgets(w);
 
 		SetDParam(0, t->population);
 		SetDParam(1, t->num_houses);
-		DrawString(2, 107, STR_2006_POPULATION, 0);
+		DrawString(2, 107, STR_2006_POPULATION, TC_FROMSTRING);
 
 		SetDParam(0, t->act_pass);
 		SetDParam(1, t->max_pass);
-		DrawString(2, 117, STR_200D_PASSENGERS_LAST_MONTH_MAX, 0);
+		DrawString(2, 117, STR_200D_PASSENGERS_LAST_MONTH_MAX, TC_FROMSTRING);
 
 		SetDParam(0, t->act_mail);
 		SetDParam(1, t->max_mail);
-		DrawString(2, 127, STR_200E_MAIL_LAST_MONTH_MAX, 0);
+		DrawString(2, 127, STR_200E_MAIL_LAST_MONTH_MAX, TC_FROMSTRING);
 
 		DrawWindowViewport(w);
 		break;
@@ -466,7 +474,7 @@
 		SetVScrollCount(w, _num_town_sort);
 
 		DrawWindowWidgets(w);
-		DoDrawString(_town_sort_order & 1 ? DOWNARROW : UPARROW, (_town_sort_order <= 1) ? 88 : 187, 15, 0x10);
+		DoDrawString(_town_sort_order & 1 ? DOWNARROW : UPARROW, (_town_sort_order <= 1) ? 88 : 187, 15, TC_BLACK);
 
 		{
 			int n = 0;
@@ -480,14 +488,14 @@
 
 				SetDParam(0, t->index);
 				SetDParam(1, t->population);
-				DrawString(2, y, STR_2057, 0);
+				DrawString(2, y, STR_2057, TC_FROMSTRING);
 
 				y += 10;
 				i++;
 				if (++n == w->vscroll.cap) break; // max number of towns in 1 window
 			}
 			SetDParam(0, GetWorldPopulation());
-			DrawString(3, w->height - 12 + 2, STR_TOWN_POPULATION, 0);
+			DrawString(3, w->height - 12 + 2, STR_TOWN_POPULATION, TC_FROMSTRING);
 		}
 	} break;