landscape.c
changeset 4300 c7e43c47a2b9
parent 4253 b468db807b66
child 4344 7e123fec5b0b
equal deleted inserted replaced
4299:91f5d2bedcff 4300:c7e43c47a2b9
     1 /* $Id$ */
     1 /* $Id$ */
     2 
     2 
     3 #include "stdafx.h"
     3 #include "stdafx.h"
     4 #include "openttd.h"
     4 #include "openttd.h"
       
     5 #include "heightmap.h"
     5 #include "clear_map.h"
     6 #include "clear_map.h"
     6 #include "functions.h"
     7 #include "functions.h"
     7 #include "map.h"
     8 #include "map.h"
     8 #include "player.h"
     9 #include "player.h"
     9 #include "spritecache.h"
    10 #include "spritecache.h"
    14 #include "command.h"
    15 #include "command.h"
    15 #include "vehicle.h"
    16 #include "vehicle.h"
    16 #include "variables.h"
    17 #include "variables.h"
    17 #include "void_map.h"
    18 #include "void_map.h"
    18 #include "water_map.h"
    19 #include "water_map.h"
       
    20 #include "tgp.h"
       
    21 #include "genworld.h"
       
    22 #include "heightmap.h"
    19 
    23 
    20 extern const TileTypeProcs
    24 extern const TileTypeProcs
    21 	_tile_type_clear_procs,
    25 	_tile_type_clear_procs,
    22 	_tile_type_rail_procs,
    26 	_tile_type_rail_procs,
    23 	_tile_type_road_procs,
    27 	_tile_type_road_procs,
   407 }
   411 }
   408 
   412 
   409 void ConvertGroundTilesIntoWaterTiles(void)
   413 void ConvertGroundTilesIntoWaterTiles(void)
   410 {
   414 {
   411 	TileIndex tile;
   415 	TileIndex tile;
       
   416 	uint z;
       
   417 	Slope slope;
   412 
   418 
   413 	for (tile = 0; tile < MapSize(); ++tile) {
   419 	for (tile = 0; tile < MapSize(); ++tile) {
   414 		if (IsTileType(tile, MP_CLEAR) && GetTileMaxZ(tile) == 0) {
   420 		slope = GetTileSlope(tile, &z);
   415 			MakeWater(tile);
   421 		if (IsTileType(tile, MP_CLEAR) && z == 0) {
       
   422 			/* Make both water for tiles at level 0
       
   423 			 * and make shore, as that looks much better
       
   424 			 * during the generation. */
       
   425 			switch (slope) {
       
   426 				case SLOPE_FLAT:
       
   427 					MakeWater(tile);
       
   428 					break;
       
   429 
       
   430 				case SLOPE_N:
       
   431 				case SLOPE_E:
       
   432 				case SLOPE_S:
       
   433 				case SLOPE_W:
       
   434 				case SLOPE_NW:
       
   435 				case SLOPE_SW:
       
   436 				case SLOPE_SE:
       
   437 				case SLOPE_NE:
       
   438 					MakeShore(tile);
       
   439 					break;
       
   440 
       
   441 				default:
       
   442 					break;
       
   443 			}
   416 		}
   444 		}
   417 	}
   445 	}
   418 }
   446 }
   419 
   447 
   420 static const byte _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4 };
   448 static const byte _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4 };
   545 #include "table/genland.h"
   573 #include "table/genland.h"
   546 
   574 
   547 static void CreateDesertOrRainForest(void)
   575 static void CreateDesertOrRainForest(void)
   548 {
   576 {
   549 	TileIndex tile;
   577 	TileIndex tile;
       
   578 	TileIndex update_freq = MapSize() / 4;
   550 	const TileIndexDiffC *data;
   579 	const TileIndexDiffC *data;
   551 	uint i;
   580 	uint i;
   552 
   581 
   553 	for (tile = 0; tile != MapSize(); ++tile) {
   582 	for (tile = 0; tile != MapSize(); ++tile) {
       
   583 		if ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
       
   584 
   554 		for (data = _make_desert_or_rainforest_data;
   585 		for (data = _make_desert_or_rainforest_data;
   555 				data != endof(_make_desert_or_rainforest_data); ++data) {
   586 				data != endof(_make_desert_or_rainforest_data); ++data) {
   556 			TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
   587 			TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
   557 			if (TileHeight(t) >= 4 || IsTileType(t, MP_WATER)) break;
   588 			if (TileHeight(t) >= 4 || IsTileType(t, MP_WATER)) break;
   558 		}
   589 		}
   559 		if (data == endof(_make_desert_or_rainforest_data))
   590 		if (data == endof(_make_desert_or_rainforest_data))
   560 			SetTropicZone(tile, TROPICZONE_DESERT);
   591 			SetTropicZone(tile, TROPICZONE_DESERT);
   561 	}
   592 	}
   562 
   593 
   563 	for (i = 0; i != 256; i++)
   594 	for (i = 0; i != 256; i++) {
       
   595 		if ((i % 64) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
       
   596 
   564 		RunTileLoop();
   597 		RunTileLoop();
       
   598 	}
   565 
   599 
   566 	for (tile = 0; tile != MapSize(); ++tile) {
   600 	for (tile = 0; tile != MapSize(); ++tile) {
       
   601 		if ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
       
   602 
   567 		for (data = _make_desert_or_rainforest_data;
   603 		for (data = _make_desert_or_rainforest_data;
   568 				data != endof(_make_desert_or_rainforest_data); ++data) {
   604 				data != endof(_make_desert_or_rainforest_data); ++data) {
   569 			TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
   605 			TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
   570 			if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_DESERT)) break;
   606 			if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_DESERT)) break;
   571 		}
   607 		}
   572 		if (data == endof(_make_desert_or_rainforest_data))
   608 		if (data == endof(_make_desert_or_rainforest_data))
   573 			SetTropicZone(tile, TROPICZONE_RAINFOREST);
   609 			SetTropicZone(tile, TROPICZONE_RAINFOREST);
   574 	}
   610 	}
   575 }
   611 }
   576 
   612 
   577 void GenerateLandscape(void)
   613 void GenerateLandscape(byte mode)
   578 {
   614 {
       
   615 	const int gwp_desert_amount = 4 + 8;
   579 	uint i;
   616 	uint i;
   580 	uint flag;
   617 	uint flag;
   581 	uint32 r;
   618 	uint32 r;
   582 
   619 
   583 	switch (_opt.landscape) {
   620 	if (mode == GW_HEIGHTMAP) {
   584 		case LT_HILLY:
   621 		SetGeneratingWorldProgress(GWP_LANDSCAPE, (_opt.landscape == LT_DESERT) ? 1 + gwp_desert_amount : 1);
   585 			for (i = ScaleByMapSize((Random() & 0x7F) + 950); i != 0; --i) {
   622 		LoadHeightmap(_file_to_saveload.name);
   586 				GenerateTerrain(2, 0);
   623 		IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
   587 			}
   624 	} else if (_patches.land_generator == LG_TERRAGENESIS) {
   588 
   625 		SetGeneratingWorldProgress(GWP_LANDSCAPE, (_opt.landscape == LT_DESERT) ? 3 + gwp_desert_amount : 3);
   589 			r = Random();
   626 		GenerateTerrainPerlin();
   590 			flag = GB(r, 0, 2) | 4;
   627 	} else {
   591 			for (i = ScaleByMapSize(GB(r, 16, 7) + 450); i != 0; --i) {
   628 		switch (_opt.landscape) {
   592 				GenerateTerrain(4, flag);
   629 			case LT_HILLY:
   593 			}
   630 				SetGeneratingWorldProgress(GWP_LANDSCAPE, 2);
   594 			break;
   631 
   595 
   632 				for (i = ScaleByMapSize((Random() & 0x7F) + 950); i != 0; --i) {
   596 		case LT_DESERT:
   633 					GenerateTerrain(2, 0);
   597 			for (i = ScaleByMapSize((Random() & 0x7F) + 170); i != 0; --i) {
   634 				}
   598 				GenerateTerrain(0, 0);
   635 				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
   599 			}
   636 
   600 
   637 				r = Random();
   601 			r = Random();
   638 				flag = GB(r, 0, 2) | 4;
   602 			flag = GB(r, 0, 2) | 4;
   639 				for (i = ScaleByMapSize(GB(r, 16, 7) + 450); i != 0; --i) {
   603 			for (i = ScaleByMapSize(GB(r, 16, 8) + 1700); i != 0; --i) {
   640 					GenerateTerrain(4, flag);
   604 				GenerateTerrain(0, flag);
   641 				}
   605 			}
   642 				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
   606 
   643 				break;
   607 			flag ^= 2;
   644 
   608 
   645 			case LT_DESERT:
   609 			for (i = ScaleByMapSize((Random() & 0x7F) + 410); i != 0; --i) {
   646 				SetGeneratingWorldProgress(GWP_LANDSCAPE, 3 + gwp_desert_amount);
   610 				GenerateTerrain(3, flag);
   647 
   611 			}
   648 				for (i = ScaleByMapSize((Random() & 0x7F) + 170); i != 0; --i) {
   612 			break;
   649 					GenerateTerrain(0, 0);
   613 
   650 				}
   614 		default:
   651 				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
   615 			i = ScaleByMapSize((Random() & 0x7F) + (3 - _opt.diff.quantity_sea_lakes) * 256 + 100);
   652 
   616 			for (; i != 0; --i) {
   653 				r = Random();
   617 				GenerateTerrain(_opt.diff.terrain_type, 0);
   654 				flag = GB(r, 0, 2) | 4;
   618 			}
   655 				for (i = ScaleByMapSize(GB(r, 16, 8) + 1700); i != 0; --i) {
   619 			break;
   656 					GenerateTerrain(0, flag);
       
   657 				}
       
   658 				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
       
   659 
       
   660 				flag ^= 2;
       
   661 
       
   662 				for (i = ScaleByMapSize((Random() & 0x7F) + 410); i != 0; --i) {
       
   663 					GenerateTerrain(3, flag);
       
   664 				}
       
   665 				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
       
   666 				break;
       
   667 
       
   668 			default:
       
   669 				SetGeneratingWorldProgress(GWP_LANDSCAPE, 1);
       
   670 
       
   671 				i = ScaleByMapSize((Random() & 0x7F) + (3 - _opt.diff.quantity_sea_lakes) * 256 + 100);
       
   672 				for (; i != 0; --i) {
       
   673 					GenerateTerrain(_opt.diff.terrain_type, 0);
       
   674 				}
       
   675 				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
       
   676 				break;
       
   677 		}
   620 	}
   678 	}
   621 
   679 
   622 	ConvertGroundTilesIntoWaterTiles();
   680 	ConvertGroundTilesIntoWaterTiles();
   623 
   681 
   624 	if (_opt.landscape == LT_DESERT) CreateDesertOrRainForest();
   682 	if (_opt.landscape == LT_DESERT) CreateDesertOrRainForest();