(svn r12565) -Cleanup: variable scope in misc\*.cpp
authorsmatz
Fri, 04 Apr 2008 17:27:38 +0000
changeset 9315 336e6518acb3
parent 9314 9e5264b5e470
child 9316 788721007cfd
(svn r12565) -Cleanup: variable scope in misc\*.cpp
src/misc.cpp
src/misc_cmd.cpp
src/misc_gui.cpp
--- a/src/misc.cpp	Fri Apr 04 16:52:29 2008 +0000
+++ b/src/misc.cpp	Fri Apr 04 17:27:38 2008 +0000
@@ -481,9 +481,8 @@
 {
 	Cheat* cht = (Cheat*)&_cheats;
 	uint count = SlGetFieldLength() / 2;
-	uint i;
 
-	for (i = 0; i < count; i++) {
+	for (uint i = 0; i < count; i++) {
 		cht[i].been_used = (SlReadByte() != 0);
 		cht[i].value     = (SlReadByte() != 0);
 	}
--- a/src/misc_cmd.cpp	Fri Apr 04 16:52:29 2008 +0000
+++ b/src/misc_cmd.cpp	Fri Apr 04 17:27:38 2008 +0000
@@ -54,20 +54,20 @@
  */
 CommandCost CmdSetPlayerColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
-	Player *p, *pp;
-	byte colour;
+	if (p2 >= 16) return CMD_ERROR; // max 16 colours
+
+	byte colour = p2;
+
 	LiveryScheme scheme = (LiveryScheme)GB(p1, 0, 8);
 	byte state = GB(p1, 8, 2);
 
-	if (p2 >= 16) return CMD_ERROR; // max 16 colours
-	colour = p2;
-
 	if (scheme >= LS_END || state >= 3) return CMD_ERROR;
 
-	p = GetPlayer(_current_player);
+	Player *p = GetPlayer(_current_player);
 
 	/* Ensure no two companies have the same primary colour */
 	if (scheme == LS_DEFAULT && state == 0) {
+		const Player *pp;
 		FOR_ALL_PLAYERS(pp) {
 			if (pp->is_active && pp != p && pp->player_color == colour) return CMD_ERROR;
 		}
@@ -225,14 +225,12 @@
  */
 CommandCost CmdChangeCompanyName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
-	Player *p;
-
 	if (StrEmpty(_cmd_text)) return CMD_ERROR;
 
 	if (!IsUniqueCompanyName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
 	if (flags & DC_EXEC) {
-		p = GetPlayer(_current_player);
+		Player *p = GetPlayer(_current_player);
 		free(p->name);
 		p->name = strdup(_cmd_text);
 		MarkWholeScreenDirty();
@@ -264,14 +262,12 @@
  */
 CommandCost CmdChangePresidentName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
-	Player *p;
-
 	if (StrEmpty(_cmd_text)) return CMD_ERROR;
 
 	if (!IsUniquePresidentName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
 	if (flags & DC_EXEC) {
-		p = GetPlayer(_current_player);
+		Player *p = GetPlayer(_current_player);
 		free(p->president_name);
 		p->president_name = strdup(_cmd_text);
 
@@ -409,8 +405,9 @@
 		/* If we are a network-client, update the difficult setting (if it is open).
 		 * Use this instead of just dirtying the window because we need to load in
 		 * the new difficulty settings */
-		if (_networking && !_network_server && FindWindowById(WC_GAME_OPTIONS, 0) != NULL)
+		if (_networking && !_network_server && FindWindowById(WC_GAME_OPTIONS, 0) != NULL) {
 			ShowGameDifficulty();
+		}
 	}
 	return CommandCost();
 }
--- a/src/misc_gui.cpp	Fri Apr 04 16:52:29 2008 +0000
+++ b/src/misc_gui.cpp	Fri Apr 04 17:27:38 2008 +0000
@@ -94,9 +94,6 @@
 
 static void Place_LandInfo(TileIndex tile)
 {
-	AcceptedCargo ac;
-	TileDesc td;
-
 	DeleteWindowById(WC_LAND_INFO, 0);
 
 	Window *w = AllocateWindowDesc(&_land_info_desc);
@@ -111,6 +108,9 @@
 	p->player_money = old_money;
 
 	/* Because build_date is not set yet in every TileDesc, we make sure it is empty */
+	TileDesc td;
+	AcceptedCargo ac;
+
 	td.build_date = 0;
 	GetAcceptedCargo(tile, ac);
 	GetTileDesc(tile, &td);
@@ -338,12 +338,10 @@
 {
 	switch (e->event) {
 		case WE_PAINT: {
-			int i, count;
-
 			DrawWindowWidgets(w);
 
-			WP(w, tree_d).base = i = _tree_base_by_landscape[_opt.landscape];
-			WP(w, tree_d).count = count = _tree_count_by_landscape[_opt.landscape];
+			int i = WP(w, tree_d).base = _tree_base_by_landscape[_opt.landscape];
+			int count = WP(w, tree_d).count = _tree_count_by_landscape[_opt.landscape];
 
 			int x = 18;
 			int y = 54;
@@ -361,7 +359,7 @@
 			int wid = e->we.click.widget;
 
 			switch (wid) {
-			case 0:
+				case 0:
 					ResetObjectToPlace();
 					break;
 
@@ -579,10 +577,6 @@
 
 void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y)
 {
-	Window *w;
-	const ViewPort *vp;
-	Point pt;
-
 	DeleteWindowById(WC_ERRMSG, 0);
 
 	if (msg_2 == STR_NULL) msg_2 = STR_EMPTY;
@@ -593,6 +587,10 @@
 	_errmsg_duration = _patches.errmsg_duration;
 	if (!_errmsg_duration) return;
 
+	Point pt;
+	const ViewPort *vp;
+	Window *w;
+
 	if (_errmsg_message_1 != STR_013B_OWNED_BY || GetDParamX(_errmsg_decode_params,2) >= 8) {
 		if ((x | y) != 0) {
 			pt = RemapCoords2(x, y);
@@ -642,10 +640,9 @@
 
 void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost)
 {
-	StringID msg;
 	Point pt = RemapCoords(x,y,z);
+	StringID msg = STR_0801_COST;
 
-	msg = STR_0801_COST;
 	if (cost < 0) {
 		cost = -cost;
 		msg = STR_0803_INCOME;
@@ -765,10 +762,9 @@
 static int DrawStationCoverageText(const AcceptedCargo accepts,
 	int str_x, int str_y, StationCoverageType sct)
 {
-	char *b = _userstring;
 	bool first = true;
 
-	b = InlineString(b, STR_000D_ACCEPTS);
+	char *b = InlineString(_userstring, STR_000D_ACCEPTS);
 
 	for (CargoID i = 0; i < NUM_CARGO; i++) {
 		if (b >= lastof(_userstring) - (1 + 2 * 4)) break; // ',' or ' ' and two calls to Utf8Encode()
@@ -967,6 +963,9 @@
 			tb->caretpos = tb->length;
 			tb->caretxoffs = tb->width;
 			return true;
+
+		default:
+			break;
 	}
 
 	return false;
@@ -1069,15 +1068,15 @@
 
 void DrawEditBox(Window *w, querystr_d *string, int wid)
 {
-	DrawPixelInfo dpi, *old_dpi;
-	int delta;
 	const Widget *wi = &w->widget[wid];
-	const Textbuf *tb = &string->text;
 
 	assert((wi->type & WWT_MASK) == WWT_EDITBOX);
 
 	GfxFillRect(wi->left + 1, wi->top + 1, wi->right - 1, wi->bottom - 1, 215);
 
+	DrawPixelInfo dpi;
+	int delta;
+
 	/* Limit the drawing of the string inside the widget boundaries */
 	if (!FillDrawPixelInfo(&dpi,
 			wi->left + 4,
@@ -1087,11 +1086,13 @@
 		return;
 	}
 
-	old_dpi = _cur_dpi;
+	DrawPixelInfo *old_dpi = _cur_dpi;
 	_cur_dpi = &dpi;
 
 	/* We will take the current widget length as maximum width, with a small
 	 * space reserved at the end for the caret to show */
+	const Textbuf *tb = &string->text;
+
 	delta = (wi->right - wi->left) - tb->width - 10;
 	if (delta > 0) delta = 0;
 
@@ -1425,14 +1426,12 @@
 {
 	uint sort_start = 0;
 	uint sort_end = 0;
-	uint s_amount;
-	int i;
 
 	/* Directories are always above the files (FIOS_TYPE_DIR)
 	 * Drives (A:\ (windows only) are always under the files (FIOS_TYPE_DRIVE)
 	 * Only sort savegames/scenarios, not directories
 	 */
-	for (i = 0; i < _fios_num; i++) {
+	for (int i = 0; i < _fios_num; i++) {
 		switch (_fios_list[i].type) {
 			case FIOS_TYPE_DIR:    sort_start++; break;
 			case FIOS_TYPE_PARENT: sort_start++; break;
@@ -1440,9 +1439,10 @@
 		}
 	}
 
-	s_amount = _fios_num - sort_start - sort_end;
-	if (s_amount > 0)
+	uint s_amount = _fios_num - sort_start - sort_end;
+	if (s_amount > 0) {
 		qsort(_fios_list + sort_start, s_amount, sizeof(FiosItem), compare_FiosItems);
+	}
 }
 
 static void GenerateFileName()
@@ -1700,10 +1700,8 @@
 		STR_LOAD_HEIGHTMAP,
 	};
 
-	Window *w;
 	const WindowDesc *sld = &_save_dialog_desc;
 
-
 	SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, VHM_NONE, WC_MAIN_WINDOW, 0);
 	DeleteWindowById(WC_QUERY_STRING, 0);
 	DeleteWindowById(WC_SAVELOAD, 0);
@@ -1721,7 +1719,8 @@
 	}
 
 	assert((uint)mode < lengthof(saveload_captions));
-	w = AllocateWindowDesc(sld);
+
+	Window *w = AllocateWindowDesc(sld);
 	w->widget[1].data = saveload_captions[mode];
 	w->LowerWidget(7);