landscape.c
changeset 926 a6d140a6a4de
parent 925 47d7952c6c14
child 927 94fec9843fd3
equal deleted inserted replaced
925:47d7952c6c14 926:a6d140a6a4de
    43 uint GetTileSlope(uint tile, int *h)
    43 uint GetTileSlope(uint tile, int *h)
    44 {
    44 {
    45 	uint a,b,c,d,min;
    45 	uint a,b,c,d,min;
    46 	int r;
    46 	int r;
    47 
    47 
    48 	if (GET_TILE_X(tile) == MapMaxX() || GET_TILE_Y(tile) == MapMaxY()) {
    48 	if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) {
    49 		if (h)
    49 		if (h)
    50 			*h = 0;
    50 			*h = 0;
    51 		return 0;
    51 		return 0;
    52 	}
    52 	}
    53 
    53 
    54 	assert(tile < MapSize() && GET_TILE_X(tile) != MapMaxX() && GET_TILE_Y(tile) != MapMaxY());
    54 	assert(tile < MapSize() && TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY());
    55 
    55 
    56 	min = a = _map_type_and_height[tile] & 0xF;
    56 	min = a = _map_type_and_height[tile] & 0xF;
    57 	b = _map_type_and_height[tile+TILE_XY(1,0)] & 0xF;
    57 	b = _map_type_and_height[tile+TILE_XY(1,0)] & 0xF;
    58 	if (min >= b) min = b;
    58 	if (min >= b) min = b;
    59 	c = _map_type_and_height[tile+TILE_XY(0,1)] & 0xF;
    59 	c = _map_type_and_height[tile+TILE_XY(0,1)] & 0xF;
    80 	return h;
    80 	return h;
    81 }
    81 }
    82 
    82 
    83 void FindLandscapeHeightByTile(TileInfo *ti, uint tile)
    83 void FindLandscapeHeightByTile(TileInfo *ti, uint tile)
    84 {
    84 {
    85 	if (GET_TILE_X(tile) == MapMaxX() || GET_TILE_Y(tile) == MapMaxY()) {
    85 	if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) {
    86 		ti->tileh = 0;
    86 		ti->tileh = 0;
    87 		ti->type = MP_VOID;
    87 		ti->type = MP_VOID;
    88 		ti->tile = 0;
    88 		ti->tile = 0;
    89 		ti->map5 = 0;
    89 		ti->map5 = 0;
    90 		ti->z = 0;
    90 		ti->z = 0;
   352 	bool success = false;
   352 	bool success = false;
   353 
   353 
   354 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   354 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   355 
   355 
   356 	// make sure sx,sy are smaller than ex,ey
   356 	// make sure sx,sy are smaller than ex,ey
   357 	sx = GET_TILE_X(p1)*16;
   357 	sx = TileX(p1) * 16;
   358 	sy = GET_TILE_Y(p1)*16;
   358 	sy = TileY(p1) * 16;
   359 	if (ex < sx) intswap(ex, sx);
   359 	if (ex < sx) intswap(ex, sx);
   360 	if (ey < sy) intswap(ey, sy);
   360 	if (ey < sy) intswap(ey, sy);
   361 
   361 
   362 	money = GetAvailableMoneyForCommand();
   362 	money = GetAvailableMoneyForCommand();
   363 	cost = 0;
   363 	cost = 0;
   443 	_map_extra_bits[tile >> 2] |= (bits&3) << ((tile&3)*2);
   443 	_map_extra_bits[tile >> 2] |= (bits&3) << ((tile&3)*2);
   444 }
   444 }
   445 
   445 
   446 uint GetMapExtraBits(uint tile)
   446 uint GetMapExtraBits(uint tile)
   447 {
   447 {
   448 	if (GET_TILE_X(tile) < MapSizeX() && GET_TILE_Y(tile) < MapSizeY() &&
   448 	if (TileX(tile) < MapSizeX() && TileY(tile) < MapSizeY() &&
   449 			GET_TILE_X(tile) > 0 && GET_TILE_Y(tile) > 0)
   449 			TileX(tile) > 0 && TileY(tile) > 0)
   450 		return (_map_extra_bits[tile >> 2] >> (tile&3)*2)&3;
   450 		return (_map_extra_bits[tile >> 2] >> (tile&3)*2)&3;
   451 	else
   451 	else
   452 		return 0;
   452 		return 0;
   453 }
   453 }
   454 
   454 
   467 	assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
   467 	assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
   468 	count = (MapSizeX() / TILELOOP_SIZE) * (MapSizeY() / TILELOOP_SIZE);
   468 	count = (MapSizeX() / TILELOOP_SIZE) * (MapSizeY() / TILELOOP_SIZE);
   469 	do {
   469 	do {
   470 		_tile_type_procs[GET_TILETYPE(tile)]->tile_loop_proc(tile);
   470 		_tile_type_procs[GET_TILETYPE(tile)]->tile_loop_proc(tile);
   471 
   471 
   472 		if ( GET_TILE_X(tile) < MapSizeX() - TILELOOP_SIZE) {
   472 		if (TileX(tile) < MapSizeX() - TILELOOP_SIZE) {
   473 			tile += TILELOOP_SIZE; /* no overflow */
   473 			tile += TILELOOP_SIZE; /* no overflow */
   474 		} else {
   474 		} else {
   475 			tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE-1) + TILE_XY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
   475 			tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE-1) + TILE_XY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
   476 		}
   476 		}
   477 	} while (--count);
   477 	} while (--count);
   513 			_map_type_and_height[tile] = MP_WATER << 4;
   513 			_map_type_and_height[tile] = MP_WATER << 4;
   514 			_map5[tile] = 0;
   514 			_map5[tile] = 0;
   515 			_map_owner[tile] = OWNER_WATER;
   515 			_map_owner[tile] = OWNER_WATER;
   516 		}
   516 		}
   517 		tile++;
   517 		tile++;
   518 		if (GET_TILE_X(tile) == MapMaxX()) {
   518 		if (TileX(tile) == MapMaxX()) {
   519 			tile += TILE_XY(-(int)MapMaxX(), 1);
   519 			tile += TILE_XY(-(int)MapMaxX(), 1);
   520 			if (GET_TILE_Y(tile) == MapMaxY())
   520 			if (TileY(tile) == MapMaxY())
   521 				break;
   521 				break;
   522 		}
   522 		}
   523 	}
   523 	}
   524 }
   524 }
   525 
   525 
   733 {
   733 {
   734 	int rn = rng;
   734 	int rn = rng;
   735 	uint32 r = Random();
   735 	uint32 r = Random();
   736 
   736 
   737 	return TILE_XY(
   737 	return TILE_XY(
   738 		GET_TILE_X(a) + ((byte)r * rn * 2 >> 8) - rn,
   738 		TileX(a) + ((byte)r * rn * 2 >> 8) - rn,
   739 		GET_TILE_Y(a) + ((byte)(r>>8) * rn * 2 >> 8) - rn
   739 		TileY(a) + ((byte)(r >> 8) * rn * 2 >> 8) - rn
   740 	);
   740 	);
   741 }
   741 }
   742 
   742 
   743 // This function checks if we add addx/addy to tile, if we
   743 // This function checks if we add addx/addy to tile, if we
   744 //  do wrap around the edges. For example, tile = (10,2) and
   744 //  do wrap around the edges. For example, tile = (10,2) and
   747 //  for example, farmland. When the tile is not wrapped,
   747 //  for example, farmland. When the tile is not wrapped,
   748 //  the result will be tile + TILE_XY(addx, addy)
   748 //  the result will be tile + TILE_XY(addx, addy)
   749 uint TileAddWrap(TileIndex tile, int addx, int addy)
   749 uint TileAddWrap(TileIndex tile, int addx, int addy)
   750 {
   750 {
   751 	uint x, y;
   751 	uint x, y;
   752 	x = GET_TILE_X(tile) + addx;
   752 	x = TileX(tile) + addx;
   753 	y = GET_TILE_Y(tile) + addy;
   753 	y = TileY(tile) + addy;
   754 
   754 
   755 	// Are we about to wrap?
   755 	// Are we about to wrap?
   756 	if (x < MapMaxX() && y < MapMaxY())
   756 	if (x < MapMaxX() && y < MapMaxY())
   757 		return tile + TILE_XY(addx, addy);
   757 		return tile + TILE_XY(addx, addy);
   758 
   758 
   759 	return TILE_WRAPPED;
   759 	return TILE_WRAPPED;
   760 }
   760 }
   761 
   761 
   762 bool IsValidTile(uint tile)
   762 bool IsValidTile(uint tile)
   763 {
   763 {
   764 	return (tile < MapSizeX() * MapMaxY() && GET_TILE_X(tile) != MapMaxX());
   764 	return (tile < MapSizeX() * MapMaxY() && TileX(tile) != MapMaxX());
   765 }
   765 }