(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
authorDarkvater
Mon, 09 May 2005 13:26:15 +0000
changeset 1781 5e2fef482637
parent 1780 082dfd92c20b
child 1782 48749e4c2dc6
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
- Fix: [ 1197256 ] max station spread patch < 7 does not work. Station spread was not taking into account when not using drag&drop. Fix this up, and add a callback to the settings window to immediately reflect the changes.
bridge_gui.c
command.h
rail_cmd.c
rail_gui.c
settings_gui.c
station_cmd.c
tunnelbridge_cmd.c
--- a/bridge_gui.c	Sun May 08 21:00:56 2005 +0000
+++ b/bridge_gui.c	Mon May 09 13:26:15 2005 +0000
@@ -161,7 +161,6 @@
 		w->vscroll.cap = 4;
 		w->vscroll.count = (byte)j;
 	} else {
-		ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE,
-			TileX(end) * 16, TileY(end) * 16);
+		ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE, TileX(end) * 16, TileY(end) * 16);
 	}
 }
--- a/command.h	Sun May 08 21:00:56 2005 +0000
+++ b/command.h	Mon May 09 13:26:15 2005 +0000
@@ -192,5 +192,5 @@
 int32 GetAvailableMoneyForCommand(void);
 
 /* Validate functions for rail building */
-static inline bool ValParamRailtype(uint32 rail) { return (rail > GetPlayer(_current_player)->max_railtype) ? false : true;}
+static inline bool ValParamRailtype(uint32 rail) { return rail <= GetPlayer(_current_player)->max_railtype;}
 #endif /* COMMAND_H */
--- a/rail_cmd.c	Sun May 08 21:00:56 2005 +0000
+++ b/rail_cmd.c	Mon May 09 13:26:15 2005 +0000
@@ -276,7 +276,7 @@
 }
 
 /* Validate functions for rail building */
-static inline bool ValParamTrackOrientation(uint32 rail) {return (rail > 5) ? false : true;}
+static inline bool ValParamTrackOrientation(uint32 rail) {return rail <= 5;}
 
 /** Build a single piece of rail
  * @param x,y coordinates on where to build
@@ -292,7 +292,7 @@
 	int32 cost = 0;
 	int32 ret;
 
-	if (!(ValParamRailtype(p1) && ValParamTrackOrientation(p2))) return CMD_ERROR;
+	if (!ValParamRailtype(p1) || !ValParamTrackOrientation(p2)) return CMD_ERROR;
 
 	tile = TILE_FROM_XY(x, y);
 	tileh = GetTileSlope(tile, NULL);
@@ -590,7 +590,8 @@
 	byte railbit = (p2 >> 4) & 7;
 	byte mode = HASBIT(p2, 7);
 
-	if (!(ValParamRailtype(p2 & 0x3) && ValParamTrackOrientation(railbit))) return CMD_ERROR;
+	if (!ValParamRailtype(p2 & 0x3) || !ValParamTrackOrientation(railbit)) return CMD_ERROR;
+	if (p1 > MapSize()) return CMD_ERROR;
 
 	/* unpack end point */
 	ex = TileX(p1) * 16;
--- a/rail_gui.c	Sun May 08 21:00:56 2005 +0000
+++ b/rail_gui.c	Mon May 09 13:26:15 2005 +0000
@@ -639,14 +639,14 @@
 		CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
 }
 
-static void StationBuildWndProc(Window *w, WindowEvent *e) {
-	int rad;
-	switch(e->event) {
+static void StationBuildWndProc(Window *w, WindowEvent *e)
+{
+	switch (e->event) {
 	case WE_PAINT: {
+		int rad;
 		uint bits;
 
-		if (WP(w,def_d).close)
-			return;
+		if (WP(w,def_d).close) return;
 
 		bits = (1<<3) << ( _railstation.orientation);
 		if (_railstation.dragdrop) {
@@ -673,6 +673,13 @@
 		if (_station_show_coverage)
 			SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
 
+		/* Update buttons for correct spread value */
+		w->disabled_state = 0;
+		for (bits = _patches.station_spread; bits < 7; bits++) {
+			SETBIT(w->disabled_state, bits + 5);
+			SETBIT(w->disabled_state, bits + 12);
+		}
+
 		DrawWindowWidgets(w);
 
 		StationPickerDrawSprite(39, 42, _cur_railtype, 2);
@@ -687,7 +694,7 @@
 	} break;
 
 	case WE_CLICK: {
-		switch(e->click.widget) {
+		switch (e->click.widget) {
 		case 3:
 		case 4:
 			_railstation.orientation = e->click.widget - 3;
--- a/settings_gui.c	Sun May 08 21:00:56 2005 +0000
+++ b/settings_gui.c	Mon May 09 13:26:15 2005 +0000
@@ -587,6 +587,12 @@
 	return 0;
 }
 
+static int32 InvalidateStationBuildWindow(int32 p1)
+{
+	InvalidateWindow(WC_BUILD_STATION, 0);
+	return 0;
+}
+
 /* Check service intervals of vehicles, p1 is value of % or day based servicing */
 static int32 CheckInterval(int32 p1)
 {
@@ -704,7 +710,7 @@
 	{PE_BOOL,		0, STR_CONFIG_PATCHES_SELECTGOODS,			"select_goods",  &_patches.selectgoods,							0,  0,  0, NULL},
 	{PE_BOOL,		0, STR_CONFIG_PATCHES_NEW_NONSTOP,			"new_nonstop", &_patches.new_nonstop,							0,  0,  0, NULL},
 	{PE_BOOL,		0, STR_CONFIG_PATCHES_NONUNIFORM_STATIONS, "nonuniform_stations", &_patches.nonuniform_stations,		0,  0,  0, NULL},
-	{PE_UINT8,	0, STR_CONFIG_PATCHES_STATION_SPREAD,		"station_spread", &_patches.station_spread,						4, 64,  1, NULL},
+	{PE_UINT8,	0, STR_CONFIG_PATCHES_STATION_SPREAD,		"station_spread", &_patches.station_spread,						4, 64,  1, &InvalidateStationBuildWindow},
 	{PE_BOOL,		0, STR_CONFIG_PATCHES_SERVICEATHELIPAD, "service_at_helipad", &_patches.serviceathelipad,					0,  0,  0, NULL},
 	{PE_BOOL, 0, STR_CONFIG_PATCHES_CATCHMENT, "modified_catchment", &_patches.modified_catchment, 0, 0, 0, NULL},
 
--- a/station_cmd.c	Sun May 08 21:00:56 2005 +0000
+++ b/station_cmd.c	Mon May 09 13:26:15 2005 +0000
@@ -918,7 +918,7 @@
 }
 
 /** Build railroad station
- * @param x_org,y_org starting position of station dragging/placement
+ * @param x,y starting position of station dragging/placement
  * @param p1 various bitstuffed elements
  * - p1 = (bit  0)    - orientation (p1 & 1)
  * - p1 = (bit  8-15) - number of tracks (p1 >> 8) & 0xFF)
@@ -960,6 +960,8 @@
 		h_org = numtracks;
 	}
 
+	if (h_org > _patches.station_spread || w_org > _patches.station_spread) return CMD_ERROR;
+
 	// these values are those that will be stored in train_tile and station_platforms
 	finalvalues[0] = tile_org;
 	finalvalues[1] = w_org;
--- a/tunnelbridge_cmd.c	Sun May 08 21:00:56 2005 +0000
+++ b/tunnelbridge_cmd.c	Mon May 09 13:26:15 2005 +0000
@@ -148,15 +148,14 @@
 {
 	int max;	// max possible length of a bridge (with patch 100)
 
-	if (_bridge_available_year[bridge_type] > _cur_year)
-				return false;
+	if (bridge_type >= MAX_BRIDGES) return false;
+	if (_bridge_available_year[bridge_type] > _cur_year) return false;
 
 	max = _bridge_maxlen[bridge_type];
 	if (max >= 16 && _patches.longbridges)
 		max = 100;
 
-	if (bridge_len < _bridge_minlen[bridge_type] || bridge_len > max)
-		return false;
+	if (bridge_len < _bridge_minlen[bridge_type] || bridge_len > max) return false;
 
 	return true;
 }
@@ -186,8 +185,7 @@
 	bridge_type = p2 & 0xFF;
 	railtype = (byte)(p2 >> 8);
 
-	/* Out of bounds bridge */
-	if (bridge_type >= MAX_BRIDGES) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE);
+	if (p1 > MapSize()) return CMD_ERROR;
 
 	// type of bridge
 	if (HASBIT(railtype, 7)) { // bit 15 of original p2 param
@@ -220,6 +218,10 @@
 	} else
 		return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN);
 
+	/* set and test bridge length, availability */
+	bridge_len = ((sx + sy - x - y) >> 4) - 1;
+	if (!CheckBridge_Stuff(bridge_type, bridge_len)) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE);
+
 	/* retrieve landscape height and ensure it's on land */
 	if (
 		((FindLandscapeHeight(&ti_end, sx, sy),
@@ -246,8 +248,7 @@
 
 	// Towns are not allowed to use bridges on slopes.
 	allow_on_slopes = ((!_is_ai_player || _patches.ainew_active)
-	                   && _current_player != OWNER_TOWN
-			   && _patches.build_on_slopes);
+	                   && _current_player != OWNER_TOWN && _patches.build_on_slopes);
 
 	/* Try and clear the start landscape */
 
@@ -295,17 +296,14 @@
 		);
 	}
 
-	/* set various params */
-	bridge_len = ((sx + sy - x - y) >> 4) - 1;
+	// position of middle part of the odd bridge (larger than MAX(i) otherwise)
+	odd_middle_part = (bridge_len % 2) ? (bridge_len / 2) : bridge_len;
 
-	//position of middle part of the odd bridge (larger than MAX(i) otherwise)
-	odd_middle_part=(bridge_len%2)?(bridge_len/2):bridge_len;
-
-	for(i = 0; i != bridge_len; i++) {
-		if (direction != 0)
-			y+=16;
-		else
-			x+=16;
+	for (i = 0; i != bridge_len; i++) {
+		if (direction != 0) {
+			y += 16;
+		} else
+			x += 16;
 
 		FindLandscapeHeight(&ti, x, y);