File diff r10854:9dc46af240e5 → r10855:5a3c2f38f98e
src/landscape.cpp
Show inline comments
 
@@ -645,99 +645,99 @@ CommandCost CmdClearArea(TileIndex tile,
 
					);
 
				}
 
			}
 
			cost.AddCost(ret);
 
		}
 
	}
 

	
 
	return (success) ? cost : CMD_ERROR;
 
}
 

	
 

	
 
TileIndex _cur_tileloop_tile;
 
#define TILELOOP_BITS 4
 
#define TILELOOP_SIZE (1 << TILELOOP_BITS)
 
#define TILELOOP_ASSERTMASK ((TILELOOP_SIZE - 1) + ((TILELOOP_SIZE - 1) << MapLogX()))
 
#define TILELOOP_CHKMASK (((1 << (MapLogX() - TILELOOP_BITS))-1) << TILELOOP_BITS)
 

	
 
void RunTileLoop()
 
{
 
	TileIndex tile = _cur_tileloop_tile;
 

	
 
	assert((tile & ~TILELOOP_ASSERTMASK) == 0);
 
	uint count = (MapSizeX() / TILELOOP_SIZE) * (MapSizeY() / TILELOOP_SIZE);
 
	do {
 
		_tile_type_procs[GetTileType(tile)]->tile_loop_proc(tile);
 

	
 
		if (TileX(tile) < MapSizeX() - TILELOOP_SIZE) {
 
			tile += TILELOOP_SIZE; // no overflow
 
		} else {
 
			tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE - 1) + TileDiffXY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
 
		}
 
	} while (--count != 0);
 
	assert((tile & ~TILELOOP_ASSERTMASK) == 0);
 

	
 
	tile += 9;
 
	if (tile & TILELOOP_CHKMASK) {
 
		tile = (tile + MapSizeX()) & TILELOOP_ASSERTMASK;
 
	}
 
	_cur_tileloop_tile = tile;
 
}
 

	
 
void InitializeLandscape()
 
{
 
	uint maxx = MapMaxX();
 
	uint maxy = MapMaxY();
 
	uint sizex = MapSizeX();
 

	
 
	uint y;
 
	for (y = 0; y < maxy; y++) {
 
	for (y = _settings_game.construction.freeform_edges ? 1 : 0; y < maxy; y++) {
 
		uint x;
 
		for (x = 0; x < maxx; x++) {
 
		for (x = _settings_game.construction.freeform_edges ? 1 : 0; x < maxx; x++) {
 
			MakeClear(sizex * y + x, CLEAR_GRASS, 3);
 
			SetTileHeight(sizex * y + x, 0);
 
			SetTropicZone(sizex * y + x, TROPICZONE_NORMAL);
 
			ClearBridgeMiddle(sizex * y + x);
 
		}
 
		MakeVoid(sizex * y + x);
 
	}
 
	for (uint x = 0; x < sizex; x++) MakeVoid(sizex * y + x);
 
}
 

	
 
static const byte _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4  };
 
static const byte _genterrain_tbl_2[5] = {  0,  0,  0,  0, 33 };
 

	
 
static void GenerateTerrain(int type, uint flag)
 
{
 
	uint32 r = Random();
 

	
 
	const Sprite *templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845, ST_MAPGEN);
 

	
 
	uint x = r & MapMaxX();
 
	uint y = (r >> MapLogX()) & MapMaxY();
 

	
 
	if (x < 2 || y < 2) return;
 

	
 
	DiagDirection direction = (DiagDirection)GB(r, 22, 2);
 
	uint w = templ->width;
 
	uint h = templ->height;
 

	
 
	if (DiagDirToAxis(direction) == AXIS_Y) Swap(w, h);
 

	
 
	const byte *p = templ->data;
 

	
 
	if ((flag & 4) != 0) {
 
		uint xw = x * MapSizeY();
 
		uint yw = y * MapSizeX();
 
		uint bias = (MapSizeX() + MapSizeY()) * 16;
 

	
 
		switch (flag & 3) {
 
			default: NOT_REACHED();
 
			case 0:
 
				if (xw + yw > MapSize() - bias) return;
 
				break;
 

	
 
			case 1:
 
				if (yw < xw + bias) return;
 
				break;
 

	
 
			case 2: