Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trees GUI improvements #8234

Merged
merged 3 commits into from
Dec 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/lang/english.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2542,13 +2542,19 @@ STR_OBJECT_BUILD_SIZE :{BLACK}Size: {G
STR_OBJECT_CLASS_LTHS :Lighthouses
STR_OBJECT_CLASS_TRNS :Transmitters

# Tree planting window (last two for SE only)
# Tree planting window (last eight for SE only)
STR_PLANT_TREE_CAPTION :{WHITE}Trees
STR_PLANT_TREE_TOOLTIP :{BLACK}Select tree type to plant. If the tile already has a tree, this will add more trees of mixed types independent of the selected type
STR_TREES_RANDOM_TYPE :{BLACK}Trees of random type
STR_TREES_RANDOM_TYPE_TOOLTIP :{BLACK}Place trees of random type. Shift toggles building/showing cost estimate
STR_TREES_RANDOM_TREES_BUTTON :{BLACK}Random Trees
STR_TREES_RANDOM_TREES_TOOLTIP :{BLACK}Plant trees randomly throughout the landscape
STR_TREES_MODE_NORMAL_BUTTON :{BLACK}Normal
STR_TREES_MODE_NORMAL_TOOLTIP :{BLACK}Plant single trees by dragging over the landscape.
STR_TREES_MODE_FOREST_SM_BUTTON :{BLACK}Grove
STR_TREES_MODE_FOREST_SM_TOOLTIP :{BLACK}Plant small forests by dragging over the landscape.
STR_TREES_MODE_FOREST_LG_BUTTON :{BLACK}Forest
STR_TREES_MODE_FOREST_LG_TOOLTIP :{BLACK}Plant large forests by dragging over the landscape.

# Land generation window (SE)
STR_TERRAFORM_TOOLBAR_LAND_GENERATION_CAPTION :{WHITE}Land Generation
Expand Down
1 change: 1 addition & 0 deletions src/tilehighlight_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void SetObjectToPlace(CursorID icon, PaletteID pal, HighLightStyle mode, WindowC
void ResetObjectToPlace();

void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method);
void VpStartDragging(ViewportDragDropSelectionProcess process);
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process);
void VpSetPresizeRange(TileIndex from, TileIndex to);
void VpSetPlaceSizingLimit(int limit);
Expand Down
47 changes: 46 additions & 1 deletion src/tree_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,51 @@ void PlaceTreesRandomly()
}
}

/**
* Place some trees in a radius around a tile.
* The trees are placed in an quasi-normal distribution around the indicated tile, meaning that while
* the radius does define a square, the distribution inside the square will be roughly circular.
* @note This function the interactive RNG and must only be used in editor and map generation.
* @param tile Tile to place trees around.
* @param treetype Type of trees to place. Must be a valid tree type for the climate.
* @param radius Maximum distance (on each axis) from tile to place trees.
* @param count Maximum number of trees to place.
* @return Number of trees actually placed.
*/
uint PlaceTreeGroupAroundTile(TileIndex tile, TreeType treetype, uint radius, uint count)
{
assert(treetype < TREE_TOYLAND + TREE_COUNT_TOYLAND);
const bool allow_desert = treetype == TREE_CACTUS;
uint planted = 0;

for (; count > 0; count--) {
/* Simple quasi-normal distribution with range [-radius; radius) */
auto mkcoord = [&]() -> int32 {
const uint32 rand = InteractiveRandom();
const int32 dist = GB<int32>(rand, 0, 8) + GB<int32>(rand, 8, 8) + GB<int32>(rand, 16, 8) + GB<int32>(rand, 24, 8);
const int32 scu = dist * radius / 512;
return scu - radius;
};
nielsmh marked this conversation as resolved.
Show resolved Hide resolved
const int32 xofs = mkcoord();
const int32 yofs = mkcoord();
const TileIndex tile_to_plant = TileAddWrap(tile, xofs, yofs);
if (tile_to_plant != INVALID_TILE) {
if (IsTileType(tile_to_plant, MP_TREES) && GetTreeCount(tile_to_plant) < 4) {
AddTreeCount(tile_to_plant, 1);
SetTreeGrowth(tile_to_plant, 0);
MarkTileDirtyByTile(tile_to_plant, 0);
planted++;
} else if (CanPlantTreesOnTile(tile_to_plant, allow_desert)) {
PlantTreesOnTile(tile_to_plant, treetype, 0, 3);
MarkTileDirtyByTile(tile_to_plant, 0);
planted++;
}
}
}

return planted;
}

/**
* Place new trees.
*
Expand Down Expand Up @@ -349,7 +394,7 @@ CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
switch (GetTileType(tile)) {
case MP_TREES:
/* no more space for trees? */
if (_game_mode != GM_EDITOR && GetTreeCount(tile) == 4) {
if (GetTreeCount(tile) == 4) {
msg = STR_ERROR_TREE_ALREADY_HERE;
continue;
}
Expand Down
Loading