mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 18:40:29 +00:00
Feature: Press Ctrl to build a diagonal area of trees (#10342)
This commit is contained in:
parent
b951332def
commit
5c64cdcb79
@ -386,7 +386,7 @@ STR_SCENEDIT_TOOLBAR_TOWN_GENERATION :{BLACK}Town gen
|
|||||||
STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION :{BLACK}Industry generation
|
STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION :{BLACK}Industry generation
|
||||||
STR_SCENEDIT_TOOLBAR_ROAD_CONSTRUCTION :{BLACK}Road construction
|
STR_SCENEDIT_TOOLBAR_ROAD_CONSTRUCTION :{BLACK}Road construction
|
||||||
STR_SCENEDIT_TOOLBAR_TRAM_CONSTRUCTION :{BLACK}Tramway construction
|
STR_SCENEDIT_TOOLBAR_TRAM_CONSTRUCTION :{BLACK}Tramway construction
|
||||||
STR_SCENEDIT_TOOLBAR_PLANT_TREES :{BLACK}Plant trees. Shift toggles building/showing cost estimate
|
STR_SCENEDIT_TOOLBAR_PLANT_TREES :{BLACK}Plant trees. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
|
||||||
STR_SCENEDIT_TOOLBAR_PLACE_SIGN :{BLACK}Place sign
|
STR_SCENEDIT_TOOLBAR_PLACE_SIGN :{BLACK}Place sign
|
||||||
STR_SCENEDIT_TOOLBAR_PLACE_OBJECT :{BLACK}Place object. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
|
STR_SCENEDIT_TOOLBAR_PLACE_OBJECT :{BLACK}Place object. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
|
||||||
|
|
||||||
@ -2819,7 +2819,7 @@ STR_OBJECT_CLASS_TRNS :Transmitters
|
|||||||
STR_PLANT_TREE_CAPTION :{WHITE}Trees
|
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_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 :{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_TYPE_TOOLTIP :{BLACK}Place trees of random type. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
|
||||||
STR_TREES_RANDOM_TREES_BUTTON :{BLACK}Random Trees
|
STR_TREES_RANDOM_TREES_BUTTON :{BLACK}Random Trees
|
||||||
STR_TREES_RANDOM_TREES_TOOLTIP :{BLACK}Plant trees randomly throughout the landscape
|
STR_TREES_RANDOM_TREES_TOOLTIP :{BLACK}Plant trees randomly throughout the landscape
|
||||||
STR_TREES_MODE_NORMAL_BUTTON :{BLACK}Normal
|
STR_TREES_MODE_NORMAL_BUTTON :{BLACK}Normal
|
||||||
|
@ -287,7 +287,7 @@
|
|||||||
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||||
EnforcePrecondition(false, ::IsValidTile(tile));
|
EnforcePrecondition(false, ::IsValidTile(tile));
|
||||||
|
|
||||||
return ScriptObject::Command<CMD_PLANT_TREE>::Do(tile, tile, TREE_INVALID);
|
return ScriptObject::Command<CMD_PLANT_TREE>::Do(tile, tile, TREE_INVALID, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ bool ScriptTile::PlantTreeRectangle(TileIndex tile, uint width, uint height)
|
/* static */ bool ScriptTile::PlantTreeRectangle(TileIndex tile, uint width, uint height)
|
||||||
@ -298,7 +298,7 @@
|
|||||||
EnforcePrecondition(false, height >= 1 && height <= 20);
|
EnforcePrecondition(false, height >= 1 && height <= 20);
|
||||||
TileIndex end_tile = tile + ::TileDiffXY(width - 1, height - 1);
|
TileIndex end_tile = tile + ::TileDiffXY(width - 1, height - 1);
|
||||||
|
|
||||||
return ScriptObject::Command<CMD_PLANT_TREE>::Do(tile, end_tile, TREE_INVALID);
|
return ScriptObject::Command<CMD_PLANT_TREE>::Do(tile, end_tile, TREE_INVALID, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ bool ScriptTile::IsWithinTownInfluence(TileIndex tile, TownID town_id)
|
/* static */ bool ScriptTile::IsWithinTownInfluence(TileIndex tile, TownID town_id)
|
||||||
|
@ -384,9 +384,10 @@ void GenerateTrees()
|
|||||||
* @param tile end tile of area-drag
|
* @param tile end tile of area-drag
|
||||||
* @param start_tile start tile of area-drag of tree plantation
|
* @param start_tile start tile of area-drag of tree plantation
|
||||||
* @param tree_to_plant tree type, TREE_INVALID means random.
|
* @param tree_to_plant tree type, TREE_INVALID means random.
|
||||||
|
* @param diagonal Whether to use the Orthogonal (false) or Diagonal (true) iterator.
|
||||||
* @return the cost of this operation or an error
|
* @return the cost of this operation or an error
|
||||||
*/
|
*/
|
||||||
CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, byte tree_to_plant)
|
CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, byte tree_to_plant, bool diagonal)
|
||||||
{
|
{
|
||||||
StringID msg = INVALID_STRING_ID;
|
StringID msg = INVALID_STRING_ID;
|
||||||
CommandCost cost(EXPENSES_OTHER);
|
CommandCost cost(EXPENSES_OTHER);
|
||||||
@ -398,8 +399,9 @@ CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_ti
|
|||||||
Company *c = (_game_mode != GM_EDITOR) ? Company::GetIfValid(_current_company) : nullptr;
|
Company *c = (_game_mode != GM_EDITOR) ? Company::GetIfValid(_current_company) : nullptr;
|
||||||
int limit = (c == nullptr ? INT32_MAX : GB(c->tree_limit, 16, 16));
|
int limit = (c == nullptr ? INT32_MAX : GB(c->tree_limit, 16, 16));
|
||||||
|
|
||||||
TileArea ta(tile, start_tile);
|
std::unique_ptr<TileIterator> iter = TileIterator::Create(tile, start_tile, diagonal);
|
||||||
for (TileIndex current_tile : ta) {
|
for (; *iter != INVALID_TILE; ++(*iter)) {
|
||||||
|
TileIndex current_tile = *iter;
|
||||||
switch (GetTileType(current_tile)) {
|
switch (GetTileType(current_tile)) {
|
||||||
case MP_TREES:
|
case MP_TREES:
|
||||||
/* no more space for trees? */
|
/* no more space for trees? */
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#include "command_type.h"
|
#include "command_type.h"
|
||||||
|
|
||||||
CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, byte tree_to_plant);
|
CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, byte tree_to_plant, bool diagonal);
|
||||||
|
|
||||||
DEF_CMD_TRAIT(CMD_PLANT_TREE, CmdPlantTree, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION)
|
DEF_CMD_TRAIT(CMD_PLANT_TREE, CmdPlantTree, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION)
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ class BuildTreesWindow : public Window
|
|||||||
if (this->tree_to_plant >= 0) {
|
if (this->tree_to_plant >= 0) {
|
||||||
/* Activate placement */
|
/* Activate placement */
|
||||||
if (_settings_client.sound.confirm) SndPlayFx(SND_15_BEEP);
|
if (_settings_client.sound.confirm) SndPlayFx(SND_15_BEEP);
|
||||||
SetObjectToPlace(SPR_CURSOR_TREE, PAL_NONE, HT_RECT, this->window_class, this->window_number);
|
SetObjectToPlace(SPR_CURSOR_TREE, PAL_NONE, HT_RECT | HT_DIAGONAL, this->window_class, this->window_number);
|
||||||
this->tree_to_plant = current_tree; // SetObjectToPlace may call ResetObjectToPlace which may reset tree_to_plant to -1
|
this->tree_to_plant = current_tree; // SetObjectToPlace may call ResetObjectToPlace which may reset tree_to_plant to -1
|
||||||
} else {
|
} else {
|
||||||
/* Deactivate placement */
|
/* Deactivate placement */
|
||||||
@ -231,7 +231,7 @@ public:
|
|||||||
TileIndex tile = TileVirtXY(pt.x, pt.y);
|
TileIndex tile = TileVirtXY(pt.x, pt.y);
|
||||||
|
|
||||||
if (this->mode == PM_NORMAL) {
|
if (this->mode == PM_NORMAL) {
|
||||||
Command<CMD_PLANT_TREE>::Post(tile, tile, this->tree_to_plant);
|
Command<CMD_PLANT_TREE>::Post(tile, tile, this->tree_to_plant, false);
|
||||||
} else {
|
} else {
|
||||||
this->DoPlantForest(tile);
|
this->DoPlantForest(tile);
|
||||||
}
|
}
|
||||||
@ -241,7 +241,7 @@ public:
|
|||||||
void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
|
void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
|
||||||
{
|
{
|
||||||
if (_game_mode != GM_EDITOR && this->mode == PM_NORMAL && pt.x != -1 && select_proc == DDSP_PLANT_TREES) {
|
if (_game_mode != GM_EDITOR && this->mode == PM_NORMAL && pt.x != -1 && select_proc == DDSP_PLANT_TREES) {
|
||||||
Command<CMD_PLANT_TREE>::Post(STR_ERROR_CAN_T_PLANT_TREE_HERE, end_tile, start_tile, this->tree_to_plant);
|
Command<CMD_PLANT_TREE>::Post(STR_ERROR_CAN_T_PLANT_TREE_HERE, end_tile, start_tile, this->tree_to_plant, _ctrl_pressed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user