station_cmd.c
changeset 5103 fbd04229cae3
parent 5098 7de23befaee4
child 5116 3c0c3da214ca
equal deleted inserted replaced
5102:8a79d76e0a64 5103:fbd04229cae3
   232 		}
   232 		}
   233 	END_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
   233 	END_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
   234 	return (closest_station == INVALID_STATION) ? NULL : GetStation(closest_station);
   234 	return (closest_station == INVALID_STATION) ? NULL : GetStation(closest_station);
   235 }
   235 }
   236 
   236 
   237 
       
   238 static bool CheckStationSpreadOut(Station *st, TileIndex tile, int w, int h)
       
   239 {
       
   240 	StationID station_index = st->index;
       
   241 	uint i;
       
   242 	uint x1 = TileX(tile);
       
   243 	uint y1 = TileY(tile);
       
   244 	uint x2 = x1 + w - 1;
       
   245 	uint y2 = y1 + h - 1;
       
   246 	uint t;
       
   247 
       
   248 	for (i = 0; i != MapSize(); i++) {
       
   249 		if (IsTileType(i, MP_STATION) && GetStationIndex(i) == station_index) {
       
   250 			t = TileX(i);
       
   251 			if (t < x1) x1 = t;
       
   252 			if (t > x2) x2 = t;
       
   253 
       
   254 			t = TileY(i);
       
   255 			if (t < y1) y1 = t;
       
   256 			if (t > y2) y2 = t;
       
   257 		}
       
   258 	}
       
   259 
       
   260 	if (y2 - y1 >= _patches.station_spread || x2 - x1 >= _patches.station_spread) {
       
   261 		_error_message = STR_306C_STATION_TOO_SPREAD_OUT;
       
   262 		return false;
       
   263 	}
       
   264 
       
   265 	return true;
       
   266 }
       
   267 
       
   268 static Station *AllocateStation(void)
   237 static Station *AllocateStation(void)
   269 {
   238 {
   270 	Station *st = NULL;
   239 	Station *st = NULL;
   271 
   240 
   272 	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
   241 	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
   650 	uint min_y;
   619 	uint min_y;
   651 	uint max_x;
   620 	uint max_x;
   652 	uint max_y;
   621 	uint max_y;
   653 } ottd_Rectangle;
   622 } ottd_Rectangle;
   654 
   623 
   655 static void MergePoint(ottd_Rectangle* rect, TileIndex tile)
   624 static inline void MergePoint(ottd_Rectangle* rect, TileIndex tile)
   656 {
   625 {
   657 	uint x = TileX(tile);
   626 	uint x = TileX(tile);
   658 	uint y = TileY(tile);
   627 	uint y = TileY(tile);
   659 
   628 
   660 	if (rect->min_x > x) rect->min_x = x;
   629 	if (rect->min_x > x) rect->min_x = x;
   761 
   730 
   762 	// redraw the station view since acceptance changed
   731 	// redraw the station view since acceptance changed
   763 	InvalidateWindowWidget(WC_STATION_VIEW, st->index, 4);
   732 	InvalidateWindowWidget(WC_STATION_VIEW, st->index, 4);
   764 }
   733 }
   765 
   734 
       
   735 static bool CheckStationSpreadOut(Station *st, TileIndex tile, int w, int h)
       
   736 {
       
   737 	StationID station_index = st->index;
       
   738 	uint x1 = TileX(tile);
       
   739 	uint y1 = TileY(tile);
       
   740 	ottd_Rectangle r = {x1, y1, x1 + w - 1, y1 + h - 1};
       
   741 	// get station bounding rect
       
   742 	for (tile = 0; tile < MapSize(); tile++) {
       
   743 		if (IsTileType(tile, MP_STATION) && GetStationIndex(tile) == station_index) MergePoint(&r, tile);
       
   744 	}
       
   745 	// check if bounding rect doesn't exceed the maximum station spread
       
   746 	if (r.max_x - r.min_x >= _patches.station_spread || r.max_y - r.min_y >= _patches.station_spread) {
       
   747 		_error_message = STR_306C_STATION_TOO_SPREAD_OUT;
       
   748 		return false;
       
   749 	}
       
   750 	return true;
       
   751 }
   766 
   752 
   767 static void UpdateStationSignCoord(Station *st)
   753 static void UpdateStationSignCoord(Station *st)
   768 {
   754 {
   769 	ottd_Rectangle r = {MapSizeX(), MapSizeY(), 0, 0};
   755 	ottd_Rectangle r = {MapSizeX(), MapSizeY(), 0, 0};
   770 	TileIndex tile;
   756 	TileIndex tile;