Allow planting trees on diagonal areas

pull/474/head
Jonathan G Rennison 1 year ago
parent 160dcc345a
commit b1a1760bcc

@ -538,7 +538,9 @@ void GenerateTrees()
* Plant a tree.
* @param tile end tile of area-drag
* @param flags type of operation
* @param p1 tree type, TREE_INVALID means random.
* @param p1 various bitstuffed data.
* - p1 = (bit 0 - 7) - tree type, TREE_INVALID means random.
* - p1 = (bit 8) - whether to use the Orthogonal (0) or Diagonal (1) iterator.
* @param p2 start tile of area-drag of tree plantation
* @param text unused
* @return the cost of this operation or an error
@ -556,8 +558,9 @@ CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
Company *c = (_game_mode != GM_EDITOR) ? Company::GetIfValid(_current_company) : nullptr;
int limit = (c == nullptr ? INT32_MAX : GB(c->tree_limit, 16, 16));
TileArea ta(tile, p2);
for (TileIndex tile : ta) {
OrthogonalOrDiagonalTileIterator iter(tile, p2, HasBit(p1, 8));
for (; *iter != INVALID_TILE; ++iter) {
TileIndex tile = *iter;
switch (GetTileType(tile)) {
case MP_TREES: {
bool grow_existing_tree_instead = false;

@ -90,7 +90,7 @@ class BuildTreesWindow : public Window
if (this->tree_to_plant >= 0) {
/* Activate placement */
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
} else {
/* Deactivate placement */
@ -234,7 +234,7 @@ public:
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) {
DoCommandP(end_tile, this->tree_to_plant, start_tile, CMD_PLANT_TREE | CMD_MSG(STR_ERROR_CAN_T_PLANT_TREE_HERE));
DoCommandP(end_tile, this->tree_to_plant | ((_ctrl_pressed ? 1 : 0) << 8), start_tile, CMD_PLANT_TREE | CMD_MSG(STR_ERROR_CAN_T_PLANT_TREE_HERE));
}
}

Loading…
Cancel
Save