(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.
This commit is contained in:
		@@ -161,7 +161,6 @@ void ShowBuildBridgeWindow(uint start, uint end, byte bridge_type)
 | 
				
			|||||||
		w->vscroll.cap = 4;
 | 
							w->vscroll.cap = 4;
 | 
				
			||||||
		w->vscroll.count = (byte)j;
 | 
							w->vscroll.count = (byte)j;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE,
 | 
							ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE, TileX(end) * 16, TileY(end) * 16);
 | 
				
			||||||
			TileX(end) * 16, TileY(end) * 16);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -192,5 +192,5 @@ bool IsValidCommand(uint cmd);
 | 
				
			|||||||
int32 GetAvailableMoneyForCommand(void);
 | 
					int32 GetAvailableMoneyForCommand(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Validate functions for rail building */
 | 
					/* 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 */
 | 
					#endif /* COMMAND_H */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -276,7 +276,7 @@ static uint32 CheckRailSlope(uint tileh, uint rail_bits, uint existing, TileInde
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Validate functions for rail building */
 | 
					/* 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
 | 
					/** Build a single piece of rail
 | 
				
			||||||
 * @param x,y coordinates on where to build
 | 
					 * @param x,y coordinates on where to build
 | 
				
			||||||
@@ -292,7 +292,7 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 | 
				
			|||||||
	int32 cost = 0;
 | 
						int32 cost = 0;
 | 
				
			||||||
	int32 ret;
 | 
						int32 ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!(ValParamRailtype(p1) && ValParamTrackOrientation(p2))) return CMD_ERROR;
 | 
						if (!ValParamRailtype(p1) || !ValParamTrackOrientation(p2)) return CMD_ERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tile = TILE_FROM_XY(x, y);
 | 
						tile = TILE_FROM_XY(x, y);
 | 
				
			||||||
	tileh = GetTileSlope(tile, NULL);
 | 
						tileh = GetTileSlope(tile, NULL);
 | 
				
			||||||
@@ -590,7 +590,8 @@ static int32 CmdRailTrackHelper(int x, int y, uint32 flags, uint32 p1, uint32 p2
 | 
				
			|||||||
	byte railbit = (p2 >> 4) & 7;
 | 
						byte railbit = (p2 >> 4) & 7;
 | 
				
			||||||
	byte mode = HASBIT(p2, 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 */
 | 
						/* unpack end point */
 | 
				
			||||||
	ex = TileX(p1) * 16;
 | 
						ex = TileX(p1) * 16;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										19
									
								
								rail_gui.c
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								rail_gui.c
									
									
									
									
									
								
							@@ -639,14 +639,14 @@ static void HandleStationPlacement(uint start, uint end)
 | 
				
			|||||||
		CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
 | 
							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) {
 | 
					static void StationBuildWndProc(Window *w, WindowEvent *e)
 | 
				
			||||||
	int rad;
 | 
					{
 | 
				
			||||||
	switch(e->event) {
 | 
						switch (e->event) {
 | 
				
			||||||
	case WE_PAINT: {
 | 
						case WE_PAINT: {
 | 
				
			||||||
 | 
							int rad;
 | 
				
			||||||
		uint bits;
 | 
							uint bits;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (WP(w,def_d).close)
 | 
							if (WP(w,def_d).close) return;
 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		bits = (1<<3) << ( _railstation.orientation);
 | 
							bits = (1<<3) << ( _railstation.orientation);
 | 
				
			||||||
		if (_railstation.dragdrop) {
 | 
							if (_railstation.dragdrop) {
 | 
				
			||||||
@@ -673,6 +673,13 @@ static void StationBuildWndProc(Window *w, WindowEvent *e) {
 | 
				
			|||||||
		if (_station_show_coverage)
 | 
							if (_station_show_coverage)
 | 
				
			||||||
			SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
 | 
								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);
 | 
							DrawWindowWidgets(w);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		StationPickerDrawSprite(39, 42, _cur_railtype, 2);
 | 
							StationPickerDrawSprite(39, 42, _cur_railtype, 2);
 | 
				
			||||||
@@ -687,7 +694,7 @@ static void StationBuildWndProc(Window *w, WindowEvent *e) {
 | 
				
			|||||||
	} break;
 | 
						} break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	case WE_CLICK: {
 | 
						case WE_CLICK: {
 | 
				
			||||||
		switch(e->click.widget) {
 | 
							switch (e->click.widget) {
 | 
				
			||||||
		case 3:
 | 
							case 3:
 | 
				
			||||||
		case 4:
 | 
							case 4:
 | 
				
			||||||
			_railstation.orientation = e->click.widget - 3;
 | 
								_railstation.orientation = e->click.widget - 3;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -587,6 +587,12 @@ static int32 InValidateDetailsWindow(int32 p1)
 | 
				
			|||||||
	return 0;
 | 
						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 */
 | 
					/* Check service intervals of vehicles, p1 is value of % or day based servicing */
 | 
				
			||||||
static int32 CheckInterval(int32 p1)
 | 
					static int32 CheckInterval(int32 p1)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -704,7 +710,7 @@ static const PatchEntry _patches_stations[] = {
 | 
				
			|||||||
	{PE_BOOL,		0, STR_CONFIG_PATCHES_SELECTGOODS,			"select_goods",  &_patches.selectgoods,							0,  0,  0, NULL},
 | 
						{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_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_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_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},
 | 
						{PE_BOOL, 0, STR_CONFIG_PATCHES_CATCHMENT, "modified_catchment", &_patches.modified_catchment, 0, 0, 0, NULL},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -918,7 +918,7 @@ static void GetStationLayout(byte *layout, int numtracks, int plat_len, StationS
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Build railroad station
 | 
					/** 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
 | 
					 * @param p1 various bitstuffed elements
 | 
				
			||||||
 * - p1 = (bit  0)    - orientation (p1 & 1)
 | 
					 * - p1 = (bit  0)    - orientation (p1 & 1)
 | 
				
			||||||
 * - p1 = (bit  8-15) - number of tracks (p1 >> 8) & 0xFF)
 | 
					 * - p1 = (bit  8-15) - number of tracks (p1 >> 8) & 0xFF)
 | 
				
			||||||
@@ -960,6 +960,8 @@ int32 CmdBuildRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 | 
				
			|||||||
		h_org = numtracks;
 | 
							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
 | 
						// these values are those that will be stored in train_tile and station_platforms
 | 
				
			||||||
	finalvalues[0] = tile_org;
 | 
						finalvalues[0] = tile_org;
 | 
				
			||||||
	finalvalues[1] = w_org;
 | 
						finalvalues[1] = w_org;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -148,15 +148,14 @@ bool CheckBridge_Stuff(byte bridge_type, int bridge_len)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	int max;	// max possible length of a bridge (with patch 100)
 | 
						int max;	// max possible length of a bridge (with patch 100)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (_bridge_available_year[bridge_type] > _cur_year)
 | 
						if (bridge_type >= MAX_BRIDGES) return false;
 | 
				
			||||||
				return false;
 | 
						if (_bridge_available_year[bridge_type] > _cur_year) return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	max = _bridge_maxlen[bridge_type];
 | 
						max = _bridge_maxlen[bridge_type];
 | 
				
			||||||
	if (max >= 16 && _patches.longbridges)
 | 
						if (max >= 16 && _patches.longbridges)
 | 
				
			||||||
		max = 100;
 | 
							max = 100;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (bridge_len < _bridge_minlen[bridge_type] || bridge_len > max)
 | 
						if (bridge_len < _bridge_minlen[bridge_type] || bridge_len > max) return false;
 | 
				
			||||||
		return false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -186,8 +185,7 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 | 
				
			|||||||
	bridge_type = p2 & 0xFF;
 | 
						bridge_type = p2 & 0xFF;
 | 
				
			||||||
	railtype = (byte)(p2 >> 8);
 | 
						railtype = (byte)(p2 >> 8);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Out of bounds bridge */
 | 
						if (p1 > MapSize()) return CMD_ERROR;
 | 
				
			||||||
	if (bridge_type >= MAX_BRIDGES) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// type of bridge
 | 
						// type of bridge
 | 
				
			||||||
	if (HASBIT(railtype, 7)) { // bit 15 of original p2 param
 | 
						if (HASBIT(railtype, 7)) { // bit 15 of original p2 param
 | 
				
			||||||
@@ -220,6 +218,10 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 | 
				
			|||||||
	} else
 | 
						} else
 | 
				
			||||||
		return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN);
 | 
							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 */
 | 
						/* retrieve landscape height and ensure it's on land */
 | 
				
			||||||
	if (
 | 
						if (
 | 
				
			||||||
		((FindLandscapeHeight(&ti_end, sx, sy),
 | 
							((FindLandscapeHeight(&ti_end, sx, sy),
 | 
				
			||||||
@@ -246,8 +248,7 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Towns are not allowed to use bridges on slopes.
 | 
						// Towns are not allowed to use bridges on slopes.
 | 
				
			||||||
	allow_on_slopes = ((!_is_ai_player || _patches.ainew_active)
 | 
						allow_on_slopes = ((!_is_ai_player || _patches.ainew_active)
 | 
				
			||||||
	                   && _current_player != OWNER_TOWN
 | 
						                   && _current_player != OWNER_TOWN && _patches.build_on_slopes);
 | 
				
			||||||
			   && _patches.build_on_slopes);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Try and clear the start landscape */
 | 
						/* Try and clear the start landscape */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -295,17 +296,14 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 | 
				
			|||||||
		);
 | 
							);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* set various params */
 | 
						// position of middle part of the odd bridge (larger than MAX(i) otherwise)
 | 
				
			||||||
	bridge_len = ((sx + sy - x - y) >> 4) - 1;
 | 
						odd_middle_part = (bridge_len % 2) ? (bridge_len / 2) : bridge_len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//position of middle part of the odd bridge (larger than MAX(i) otherwise)
 | 
						for (i = 0; i != bridge_len; i++) {
 | 
				
			||||||
	odd_middle_part=(bridge_len%2)?(bridge_len/2):bridge_len;
 | 
							if (direction != 0) {
 | 
				
			||||||
 | 
								y += 16;
 | 
				
			||||||
	for(i = 0; i != bridge_len; i++) {
 | 
							} else
 | 
				
			||||||
		if (direction != 0)
 | 
								x += 16;
 | 
				
			||||||
			y+=16;
 | 
					 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
			x+=16;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		FindLandscapeHeight(&ti, x, y);
 | 
							FindLandscapeHeight(&ti, x, y);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user