Changeset - r5103:f3744ef57371
[Not reviewed]
master
0 1 0
KUDr - 18 years ago 2006-11-16 17:59:02
kudr@openttd.org
(svn r7174) -CodeChange: CheckStationSpreadOut() now uses MergePoint() for bounding rectangle calculation.
1 file changed with 18 insertions and 32 deletions:
0 comments (0 inline, 0 general)
station_cmd.c
Show inline comments
 
@@ -231,43 +231,12 @@ static Station* GetStationAround(TileInd
 
			}
 
		}
 
	END_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
 
	return (closest_station == INVALID_STATION) ? NULL : GetStation(closest_station);
 
}
 

	
 

	
 
static bool CheckStationSpreadOut(Station *st, TileIndex tile, int w, int h)
 
{
 
	StationID station_index = st->index;
 
	uint i;
 
	uint x1 = TileX(tile);
 
	uint y1 = TileY(tile);
 
	uint x2 = x1 + w - 1;
 
	uint y2 = y1 + h - 1;
 
	uint t;
 

	
 
	for (i = 0; i != MapSize(); i++) {
 
		if (IsTileType(i, MP_STATION) && GetStationIndex(i) == station_index) {
 
			t = TileX(i);
 
			if (t < x1) x1 = t;
 
			if (t > x2) x2 = t;
 

	
 
			t = TileY(i);
 
			if (t < y1) y1 = t;
 
			if (t > y2) y2 = t;
 
		}
 
	}
 

	
 
	if (y2 - y1 >= _patches.station_spread || x2 - x1 >= _patches.station_spread) {
 
		_error_message = STR_306C_STATION_TOO_SPREAD_OUT;
 
		return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
static Station *AllocateStation(void)
 
{
 
	Station *st = NULL;
 

	
 
	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
 
	 * TODO - This is just a temporary stage, this will be removed. */
 
@@ -649,13 +618,13 @@ typedef struct ottd_Rectangle {
 
	uint min_x;
 
	uint min_y;
 
	uint max_x;
 
	uint max_y;
 
} ottd_Rectangle;
 

	
 
static void MergePoint(ottd_Rectangle* rect, TileIndex tile)
 
static inline void MergePoint(ottd_Rectangle* rect, TileIndex tile)
 
{
 
	uint x = TileX(tile);
 
	uint y = TileY(tile);
 

	
 
	if (rect->min_x > x) rect->min_x = x;
 
	if (rect->min_y > y) rect->min_y = y;
 
@@ -760,12 +729,29 @@ static void UpdateStationAcceptance(Stat
 
	}
 

	
 
	// redraw the station view since acceptance changed
 
	InvalidateWindowWidget(WC_STATION_VIEW, st->index, 4);
 
}
 

	
 
static bool CheckStationSpreadOut(Station *st, TileIndex tile, int w, int h)
 
{
 
	StationID station_index = st->index;
 
	uint x1 = TileX(tile);
 
	uint y1 = TileY(tile);
 
	ottd_Rectangle r = {x1, y1, x1 + w - 1, y1 + h - 1};
 
	// get station bounding rect
 
	for (tile = 0; tile < MapSize(); tile++) {
 
		if (IsTileType(tile, MP_STATION) && GetStationIndex(tile) == station_index) MergePoint(&r, tile);
 
	}
 
	// check if bounding rect doesn't exceed the maximum station spread
 
	if (r.max_x - r.min_x >= _patches.station_spread || r.max_y - r.min_y >= _patches.station_spread) {
 
		_error_message = STR_306C_STATION_TOO_SPREAD_OUT;
 
		return false;
 
	}
 
	return true;
 
}
 

	
 
static void UpdateStationSignCoord(Station *st)
 
{
 
	ottd_Rectangle r = {MapSizeX(), MapSizeY(), 0, 0};
 
	TileIndex tile;
 

	
0 comments (0 inline, 0 general)