(svn r132) -Fix: [1014278] TileAddWrap() gave wrong results. Fixed now.
This commit is contained in:
		@@ -28,7 +28,7 @@ void ClickTile(uint tile);
 | 
			
		||||
void GetTileDesc(uint tile, TileDesc *td);
 | 
			
		||||
void DrawTile(TileInfo *ti);
 | 
			
		||||
 | 
			
		||||
uint TileAddWrap(TileIndex tile, int add);
 | 
			
		||||
uint TileAddWrap(TileIndex tile, int addx, int addy);
 | 
			
		||||
enum {
 | 
			
		||||
	TILE_WRAPPED = (uint)-1
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -969,7 +969,7 @@ static void MaybePlantFarmField(Industry *i)
 | 
			
		||||
{
 | 
			
		||||
	uint tile;
 | 
			
		||||
	if (CHANCE16(1,8)) {
 | 
			
		||||
		tile = TileAddWrap(i->xy, TILE_XY(i->width>>1, i->height>>1) + (Random()&TILE_XY(31,31))-TILE_XY(16,16));
 | 
			
		||||
		tile = TileAddWrap(i->xy, ((i->width>>1) + Random() % 31 - 16), ((i->height>>1) + Random() % 31 - 16));
 | 
			
		||||
		if (tile != TILE_WRAPPED)
 | 
			
		||||
			PlantFarmField(tile);
 | 
			
		||||
	}	
 | 
			
		||||
@@ -1473,7 +1473,7 @@ static void DoCreateNewIndustry(Industry *i, uint tile, int type, const Industry
 | 
			
		||||
	if (i->type == IT_FARM || i->type == IT_FARM_2) {
 | 
			
		||||
		tile = i->xy + TILE_XY((i->width >> 1), (i->height >> 1));
 | 
			
		||||
		for(j=0; j!=50; j++) {
 | 
			
		||||
			uint new_tile = TileAddWrap(tile, (Random() & TILE_XY(31,31)) - TILE_XY(16,16));
 | 
			
		||||
			uint new_tile = TileAddWrap(tile, Random() % 31 - 16, Random() % 31 - 16);
 | 
			
		||||
			if (new_tile != TILE_WRAPPED)
 | 
			
		||||
				PlantFarmField(new_tile);
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										19
									
								
								landscape.c
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								landscape.c
									
									
									
									
									
								
							@@ -742,11 +742,22 @@ TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng)
 | 
			
		||||
	);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint TileAddWrap(TileIndex tile, int add)
 | 
			
		||||
// This function checks if we add addx/addy to tile, if we
 | 
			
		||||
//  do wrap around the edges. For example, tile = (10,2) and
 | 
			
		||||
//  addx = +3 and addy = -4. This function will now return
 | 
			
		||||
//  TILE_WRAPPED, because the y is wrapped. This is needed in
 | 
			
		||||
//  for example, farmland. When the tile is not wrapped,
 | 
			
		||||
//  the result will be tile + TILE_XY(addx, addy)
 | 
			
		||||
uint TileAddWrap(TileIndex tile, int addx, int addy)
 | 
			
		||||
{
 | 
			
		||||
	uint t = tile + add;
 | 
			
		||||
	if (t < TILES_X * TILE_Y_MAX && GET_TILE_X(t) != TILE_X_MAX)
 | 
			
		||||
		return t;
 | 
			
		||||
	int x, y;
 | 
			
		||||
	x = GET_TILE_X(tile) + addx;
 | 
			
		||||
	y = GET_TILE_Y(tile) + addy;
 | 
			
		||||
	
 | 
			
		||||
	// Are we about to wrap?
 | 
			
		||||
	if (x > 0 && x < TILE_X_MAX && y > 0 && y < TILE_Y_MAX)
 | 
			
		||||
		return tile + TILE_XY(addx, addy);
 | 
			
		||||
 | 
			
		||||
	return TILE_WRAPPED;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user