src/tree_cmd.cpp
branchnoai
changeset 9517 be1775555bbd
parent 9505 9711235f5693
child 6719 4cc327ad39d5
child 6918 5589c415e28f
child 9574 698395509d12
equal deleted inserted replaced
9516:defc90b7898a 9517:be1775555bbd
    26 };
    26 };
    27 
    27 
    28 static TreeType GetRandomTreeType(TileIndex tile, uint seed)
    28 static TreeType GetRandomTreeType(TileIndex tile, uint seed)
    29 {
    29 {
    30 	switch (_opt.landscape) {
    30 	switch (_opt.landscape) {
    31 		case LT_NORMAL:
    31 		case LT_TEMPERATE:
    32 			return (TreeType)(seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE);
    32 			return (TreeType)(seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE);
    33 
    33 
    34 		case LT_HILLY:
    34 		case LT_ARCTIC:
    35 			return (TreeType)(seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC);
    35 			return (TreeType)(seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC);
    36 
    36 
    37 		case LT_DESERT:
    37 		case LT_TROPIC:
    38 			switch (GetTropicZone(tile)) {
    38 			switch (GetTropicZone(tile)) {
    39 				case TROPICZONE_INVALID: return (TreeType)(seed * TREE_COUNT_SUB_TROPICAL / 256 + TREE_SUB_TROPICAL);
    39 				case TROPICZONE_INVALID: return (TreeType)(seed * TREE_COUNT_SUB_TROPICAL / 256 + TREE_SUB_TROPICAL);
    40 				case TROPICZONE_DESERT:  return (TreeType)((seed > 12) ? TREE_INVALID : TREE_CACTUS);
    40 				case TROPICZONE_DESERT:  return (TreeType)((seed > 12) ? TREE_INVALID : TREE_CACTUS);
    41 				default:                 return (TreeType)(seed * TREE_COUNT_RAINFOREST / 256 + TREE_RAINFOREST);
    41 				default:                 return (TreeType)(seed * TREE_COUNT_RAINFOREST / 256 + TREE_RAINFOREST);
    42 			}
    42 			}
    52 
    52 
    53 	if (tree != TREE_INVALID) {
    53 	if (tree != TREE_INVALID) {
    54 		MakeTree(tile, tree, GB(r, 22, 2), min(GB(r, 16, 3), 6), TREE_GROUND_GRASS, 0);
    54 		MakeTree(tile, tree, GB(r, 22, 2), min(GB(r, 16, 3), 6), TREE_GROUND_GRASS, 0);
    55 
    55 
    56 		// above snowline?
    56 		// above snowline?
    57 		if (_opt.landscape == LT_HILLY && GetTileZ(tile) > GetSnowLine()) {
    57 		if (_opt.landscape == LT_ARCTIC && GetTileZ(tile) > GetSnowLine()) {
    58 			SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3);
    58 			SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3);
    59 			SetTreeCounter(tile, (TreeGround)GB(r, 24, 3));
    59 			SetTreeCounter(tile, (TreeGround)GB(r, 24, 3));
    60 		} else {
    60 		} else {
    61 			SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 0);
    61 			SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 0);
    62 			SetTreeCounter(tile, (TreeGround)GB(r, 24, 4));
    62 			SetTreeCounter(tile, (TreeGround)GB(r, 24, 4));
   149 			ht = GetTileZ(tile);
   149 			ht = GetTileZ(tile);
   150 			/* The higher we get, the more trees we plant */
   150 			/* The higher we get, the more trees we plant */
   151 			j = GetTileZ(tile) / TILE_HEIGHT * 2;
   151 			j = GetTileZ(tile) / TILE_HEIGHT * 2;
   152 			while (j--) {
   152 			while (j--) {
   153 				/* Above snowline more trees! */
   153 				/* Above snowline more trees! */
   154 				if (_opt.landscape == LT_HILLY && ht > GetSnowLine()) {
   154 				if (_opt.landscape == LT_ARCTIC && ht > GetSnowLine()) {
   155 					PlaceTreeAtSameHeight(tile, ht);
   155 					PlaceTreeAtSameHeight(tile, ht);
   156 					PlaceTreeAtSameHeight(tile, ht);
   156 					PlaceTreeAtSameHeight(tile, ht);
   157 				};
   157 				};
   158 
   158 
   159 				PlaceTreeAtSameHeight(tile, ht);
   159 				PlaceTreeAtSameHeight(tile, ht);
   160 			}
   160 			}
   161 		}
   161 		}
   162 	} while (--i);
   162 	} while (--i);
   163 
   163 
   164 	/* place extra trees at rainforest area */
   164 	/* place extra trees at rainforest area */
   165 	if (_opt.landscape == LT_DESERT) {
   165 	if (_opt.landscape == LT_TROPIC) {
   166 		i = ScaleByMapSize(15000);
   166 		i = ScaleByMapSize(15000);
   167 
   167 
   168 		do {
   168 		do {
   169 			uint32 r = Random();
   169 			uint32 r = Random();
   170 			TileIndex tile = RandomTileSeed(r);
   170 			TileIndex tile = RandomTileSeed(r);
   185 {
   185 {
   186 	uint i, total;
   186 	uint i, total;
   187 
   187 
   188 	if (_patches.tree_placer == TP_NONE) return;
   188 	if (_patches.tree_placer == TP_NONE) return;
   189 
   189 
   190 	if (_opt.landscape != LT_CANDY) PlaceMoreTrees();
   190 	if (_opt.landscape != LT_TOYLAND) PlaceMoreTrees();
   191 
   191 
   192 	switch (_patches.tree_placer) {
   192 	switch (_patches.tree_placer) {
   193 		case TP_ORIGINAL: i = _opt.landscape == LT_HILLY ? 15 : 6; break;
   193 		case TP_ORIGINAL: i = _opt.landscape == LT_ARCTIC ? 15 : 6; break;
   194 		case TP_IMPROVED: i = _opt.landscape == LT_HILLY ?  4 : 2; break;
   194 		case TP_IMPROVED: i = _opt.landscape == LT_ARCTIC ?  4 : 2; break;
   195 		default: NOT_REACHED(); return;
   195 		default: NOT_REACHED(); return;
   196 	}
   196 	}
   197 
   197 
   198 	total = ScaleByMapSize(1000);
   198 	total = ScaleByMapSize(1000);
   199 	if (_opt.landscape == LT_DESERT) total += ScaleByMapSize(15000);
   199 	if (_opt.landscape == LT_TROPIC) total += ScaleByMapSize(15000);
   200 	total *= i;
   200 	total *= i;
   201 	SetGeneratingWorldProgress(GWP_TREE, total);
   201 	SetGeneratingWorldProgress(GWP_TREE, total);
   202 
   202 
   203 	for (; i != 0; i--) {
   203 	for (; i != 0; i--) {
   204 		PlaceTreesRandomly();
   204 		PlaceTreesRandomly();
   522 }
   522 }
   523 
   523 
   524 static void TileLoop_Trees(TileIndex tile)
   524 static void TileLoop_Trees(TileIndex tile)
   525 {
   525 {
   526 	switch (_opt.landscape) {
   526 	switch (_opt.landscape) {
   527 		case LT_DESERT: TileLoopTreesDesert(tile); break;
   527 		case LT_TROPIC: TileLoopTreesDesert(tile); break;
   528 		case LT_HILLY:  TileLoopTreesAlps(tile);   break;
   528 		case LT_ARCTIC: TileLoopTreesAlps(tile);   break;
   529 	}
   529 	}
   530 
   530 
   531 	TileLoopClearHelper(tile);
   531 	TileLoopClearHelper(tile);
   532 
   532 
   533 	if (GetTreeCounter(tile) < 15) {
   533 	if (GetTreeCounter(tile) < 15) {
   536 	}
   536 	}
   537 	SetTreeCounter(tile, 0);
   537 	SetTreeCounter(tile, 0);
   538 
   538 
   539 	switch (GetTreeGrowth(tile)) {
   539 	switch (GetTreeGrowth(tile)) {
   540 		case 3: /* regular sized tree */
   540 		case 3: /* regular sized tree */
   541 			if (_opt.landscape == LT_DESERT &&
   541 			if (_opt.landscape == LT_TROPIC &&
   542 					GetTreeType(tile) != TREE_CACTUS &&
   542 					GetTreeType(tile) != TREE_CACTUS &&
   543 					GetTropicZone(tile) == TROPICZONE_DESERT) {
   543 					GetTropicZone(tile) == TROPICZONE_DESERT) {
   544 				AddTreeGrowth(tile, 1);
   544 				AddTreeGrowth(tile, 1);
   545 			} else {
   545 			} else {
   546 				switch (GB(Random(), 0, 3)) {
   546 				switch (GB(Random(), 0, 3)) {
   611 	TileIndex tile;
   611 	TileIndex tile;
   612 	ClearGround ct;
   612 	ClearGround ct;
   613 	TreeType tree;
   613 	TreeType tree;
   614 
   614 
   615 	/* place a tree at a random rainforest spot */
   615 	/* place a tree at a random rainforest spot */
   616 	if (_opt.landscape == LT_DESERT &&
   616 	if (_opt.landscape == LT_TROPIC &&
   617 			(r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) &&
   617 			(r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) &&
   618 			IsTileType(tile, MP_CLEAR) &&
   618 			IsTileType(tile, MP_CLEAR) &&
   619 			!IsBridgeAbove(tile) &&
   619 			!IsBridgeAbove(tile) &&
   620 			(ct = GetClearGround(tile), ct == CLEAR_GRASS || ct == CLEAR_ROUGH) &&
   620 			(ct = GetClearGround(tile), ct == CLEAR_GRASS || ct == CLEAR_ROUGH) &&
   621 			(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
   621 			(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {