(svn r9582) [0.5] -Backport from trunk (r9425, r9437, r9455, r9519): 0.5
authortruelight
Tue, 10 Apr 2007 09:40:36 +0000
branch0.5
changeset 5481 acf12c0e6f31
parent 5480 497f842b10bf
child 5482 cf9c0b5d3bb3
(svn r9582) [0.5] -Backport from trunk (r9425, r9437, r9455, r9519):
- Fix: housekeeping in convert rail functions (r9425)
- Fix: dedicated server crashed when the y part of the resolution was less than 10 (r9437)
- Fix: values of diff_custom and snow_line in .cfg weren't checked properly (r9455)
- Fix: free the malloc'd variable, not the pointer to that variable (r9519)
fontcache.c
rail_cmd.c
road_cmd.c
settings.c
settings_gui.c
station_cmd.c
texteff.c
tunnelbridge_cmd.c
--- a/fontcache.c	Mon Mar 26 00:20:22 2007 +0000
+++ b/fontcache.c	Tue Apr 10 09:40:36 2007 +0000
@@ -144,10 +144,10 @@
 
 
 folder_error:
+registry_no_font_found:
 #if defined(UNICODE)
-	free(font_path);
+	free(font_namep);
 #endif
-registry_no_font_found:
 	RegCloseKey(hKey);
 	return err;
 }
--- a/rail_cmd.c	Mon Mar 26 00:20:22 2007 +0000
+++ b/rail_cmd.c	Tue Apr 10 09:40:36 2007 +0000
@@ -874,14 +874,23 @@
 
 typedef int32 DoConvertRailProc(TileIndex tile, RailType totype, bool exec);
 
+/**
+ * Switches the rail type.
+ * Railtypes are stored on a per-tile basis, not on a per-track basis, so
+ * all the tracks in the given tile will be converted.
+ * @param tile        The tile on which the railtype is to be convert.
+ * @param totype      The railtype we want to convert to
+ * @param exec        Switches between test and execute mode
+ * @return            The cost and state of the operation
+ * @retval CMD_ERROR  An error occured during the operation.
+ */
 static int32 DoConvertRail(TileIndex tile, RailType totype, bool exec)
 {
 	if (!CheckTileOwnership(tile)) return CMD_ERROR;
 
-	if (!EnsureNoVehicle(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR;
+	if (GetRailType(tile) == totype) return CMD_ERROR;
 
-	// tile is already of requested type?
-	if (GetRailType(tile) == totype) return CMD_ERROR;
+	if (!EnsureNoVehicle(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR;
 
 	// 'hidden' elrails can't be downgraded to normal rail when elrails are disabled
 	if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR;
--- a/road_cmd.c	Mon Mar 26 00:20:22 2007 +0000
+++ b/road_cmd.c	Tue Apr 10 09:40:36 2007 +0000
@@ -422,6 +422,14 @@
 	return cost;
 }
 
+/**
+ * Switches the rail type on a level crossing.
+ * @param tile        The tile on which the railtype is to be convert.
+ * @param totype      The railtype we want to convert to
+ * @param exec        Switches between test and execute mode
+ * @return            The cost and state of the operation
+ * @retval CMD_ERROR  An error occured during the operation.
+ */
 int32 DoConvertStreetRail(TileIndex tile, RailType totype, bool exec)
 {
 	// not a railroad crossing?
@@ -441,7 +449,7 @@
 		YapfNotifyTrackLayoutChange(tile, FIND_FIRST_BIT(GetCrossingRailBits(tile)));
 	}
 
-	return _price.build_rail >> 1;
+	return _price.build_rail / 2;
 }
 
 
--- a/settings.c	Mon Mar 26 00:20:22 2007 +0000
+++ b/settings.c	Tue Apr 10 09:40:36 2007 +0000
@@ -1241,12 +1241,12 @@
 	 * and why not byte for example? */
 	SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, (SLE_FILE_I16 | SLE_VAR_I32), 0, 0, GameOptions, diff, 17, 0, 0, 0, 0, NULL, STR_NULL, NULL, 0, 3),
 	SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, (SLE_FILE_I16 | SLE_VAR_I32), 0, 0, GameOptions, diff, 18, 0, 0, 0, 0, NULL, STR_NULL, NULL, 4, SL_MAX_VERSION),
-	    SDT_VAR(GameOptions, diff_level,SLE_UINT8, 0, 0, 9, 0,  9, 0, STR_NULL, NULL),
+	    SDT_VAR(GameOptions, diff_level,SLE_UINT8, 0, 0, 0, 0,  3, 0, STR_NULL, NULL),
 	  SDT_OMANY(GameOptions, currency,  SLE_UINT8, N, 0, 0, CUSTOM_CURRENCY_ID, "GBP|USD|EUR|YEN|ATS|BEF|CHF|CZK|DEM|DKK|ESP|FIM|FRF|GRD|HUF|ISK|ITL|NLG|NOK|PLN|ROL|RUR|SIT|SEK|YTL|SKK|BRR|custom", STR_NULL, NULL),
 	  SDT_OMANY(GameOptions, units,     SLE_UINT8, N, 0, 1,     2, "imperial|metric|si", STR_NULL, NULL),
 	  SDT_OMANY(GameOptions, town_name, SLE_UINT8, 0, 0, 0,    20, "english|french|german|american|latin|silly|swedish|dutch|finnish|polish|slovakish|norwegian|hungarian|austrian|romanian|czech|swiss|danish|turkish|italian|catalan", STR_NULL, NULL),
 	  SDT_OMANY(GameOptions, landscape, SLE_UINT8, 0, 0, 0,     3, "normal|hilly|desert|candy", STR_NULL, NULL),
-	    SDT_VAR(GameOptions, snow_line, SLE_UINT8, 0, 0, 1, 0, 56, 0, STR_NULL, NULL),
+	    SDT_VAR(GameOptions, snow_line, SLE_UINT8, 0, 0, 7 * TILE_HEIGHT, 2 * TILE_HEIGHT, 13 * TILE_HEIGHT, 0, STR_NULL, NULL),
 	SDT_CONDOMANY(GameOptions,autosave, SLE_UINT8, 0, 22,             N, 0, 0, 0, "", STR_NULL, NULL),
 	SDT_CONDOMANY(GameOptions,autosave, SLE_UINT8,23, SL_MAX_VERSION, S, 0, 1, 4, "off|monthly|quarterly|half year|yearly", STR_NULL, NULL),
 	  SDT_OMANY(GameOptions, road_side, SLE_UINT8, 0, 0, 1,   1, "left|right", STR_NULL, NULL),
@@ -1650,6 +1650,8 @@
 #endif /* ENABLE_NETWORK */
 }
 
+extern void CheckDifficultyLevels(void);
+
 /** Load the values from the configuration files */
 void LoadFromConfig(void)
 {
@@ -1659,6 +1661,7 @@
 	_grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
 	_grfconfig_static  = GRFLoadConfig(ini, "newgrf-static", true);
 	_news_display_opt  = NewsDisplayLoadConfig(ini, "news_display");
+	CheckDifficultyLevels();
 	ini_free(ini);
 }
 
--- a/settings_gui.c	Mon Mar 26 00:20:22 2007 +0000
+++ b/settings_gui.c	Tue Apr 10 09:40:36 2007 +0000
@@ -368,6 +368,24 @@
 	}
 }
 
+/**
+ * Checks the difficulty levels read from the configuration and
+ * forces them to be correct when invalid.
+ */
+void CheckDifficultyLevels(void)
+{
+	if (_opt_newgame.diff_level != 3) {
+		SetDifficultyLevel(_opt_newgame.diff_level, &_opt_newgame);
+	} else {
+		uint i;
+		for (i = 0; i < GAME_DIFFICULTY_NUM; i++) {
+			int *diff = ((int*)&_opt_newgame.diff) + i;
+			*diff = clamp(*diff, _game_setting_info[i].min, _game_setting_info[i].max);
+			*diff -= *diff % _game_setting_info[i].step;
+		}
+	}
+}
+
 extern void StartupEconomy(void);
 
 enum {
--- a/station_cmd.c	Mon Mar 26 00:20:22 2007 +0000
+++ b/station_cmd.c	Tue Apr 10 09:40:36 2007 +0000
@@ -1337,6 +1337,14 @@
 	return cost;
 }
 
+/**
+ * Switches the rail type at a railway station tile.
+ * @param tile        The tile on which the railtype is to be convert.
+ * @param totype      The railtype we want to convert to
+ * @param exec        Switches between test and execute mode
+ * @return            The cost and state of the operation
+ * @retval CMD_ERROR  An error occured during the operation.
+ */
 int32 DoConvertStationRail(TileIndex tile, RailType totype, bool exec)
 {
 	const Station* st = GetStationByTile(tile);
@@ -1357,7 +1365,7 @@
 		YapfNotifyTrackLayoutChange(tile, GetRailStationTrack(tile));
 	}
 
-	return _price.build_rail >> 1;
+	return _price.build_rail / 2;
 }
 
 /** Heavy wizardry used to add a roadstop to a station.
--- a/texteff.c	Mon Mar 26 00:20:22 2007 +0000
+++ b/texteff.c	Tue Apr 10 09:40:36 2007 +0000
@@ -152,6 +152,7 @@
 		if (x + width >= _screen.width) {
 			width = _screen.width - x;
 		}
+		if (width <= 0 || height <= 0) return;
 
 		_textmessage_visible = false;
 		// Put our 'shot' back to the screen
@@ -219,6 +220,8 @@
 	if (x + width >= _screen.width) {
 		width = _screen.width - x;
 	}
+	if (width <= 0 || height <= 0) return;
+
 	// Make a copy of the screen as it is before painting (for undraw)
 	memcpy_pitch(
 		_textmessage_backup,
--- a/tunnelbridge_cmd.c	Mon Mar 26 00:20:22 2007 +0000
+++ b/tunnelbridge_cmd.c	Tue Apr 10 09:40:36 2007 +0000
@@ -764,6 +764,16 @@
 	return CMD_ERROR;
 }
 
+/**
+ * Switches the rail type for a tunnel or a bridgehead. As the railtype
+ * on the bridge are determined by the one of the bridgehead, this
+ * functions converts the railtype on the entire bridge.
+ * @param tile        The tile on which the railtype is to be convert.
+ * @param totype      The railtype we want to convert to
+ * @param exec        Switches between test and execute mode
+ * @return            The cost and state of the operation
+ * @retval CMD_ERROR  An error occured during the operation.
+ */
 int32 DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec)
 {
 	TileIndex endtile;
@@ -792,7 +802,7 @@
 			YapfNotifyTrackLayoutChange(tile, track);
 			YapfNotifyTrackLayoutChange(endtile, track);
 		}
-		return (length + 1) * (_price.build_rail >> 1);
+		return (length + 1) * (_price.build_rail / 2);
 	} else if (IsBridge(tile) &&
 			IsBridgeMiddle(tile) &&
 			IsTransportUnderBridge(tile) &&
@@ -809,7 +819,7 @@
 
 			YapfNotifyTrackLayoutChange(tile, GetRailUnderBridge(tile));
 		}
-		return _price.build_rail >> 1;
+		return _price.build_rail / 2;
 	} else if (IsBridge(tile) && IsBridgeRamp(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
 		TileIndexDiff delta;
 		int32 cost;
@@ -837,14 +847,14 @@
 			YapfNotifyTrackLayoutChange(tile, track);
 			YapfNotifyTrackLayoutChange(endtile, track);
 		}
-		cost = 2 * (_price.build_rail >> 1);
+		cost = 2 * (_price.build_rail / 2);
 		delta = TileOffsByDiagDir(GetBridgeRampDirection(tile));
 		for (tile += delta; tile != endtile; tile += delta) {
 			if (exec) {
 				SetRailTypeOnBridge(tile, totype);
 				MarkTileDirtyByTile(tile);
 			}
-			cost += _price.build_rail >> 1;
+			cost += _price.build_rail / 2;
 		}
 
 		return cost;