FS#730 - Diagonal demolish / level land patch

Attached to Project: OpenTTD
Opened by Chris (l_blue_l) - Thursday, 12 April 2007, 07:16 GMT
Last edited by Remko Bijker (Rubidium) - Monday, 13 December 2010, 15:15 GMT
Type Patch
Category Core
Status Closed
Assigned To No-one
Operating System All
Severity Low
Priority Normal
Reported Version 0.5.0
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 12
Private No


What this patch does is it lets you demolish or level land diagonally when you use the control key.

This discussion first start on OpenTTD development forum here but will now be discussed on Flyspray.

I did my best to try and complete all the developers comments.

I have changed the #define DO_LEVEL_AREA to a function "int32 LevelLand(....)" but this has coursed a strange bug that courses the GetAvailableMoneyForCommand(); function as this continually returns the original value without updating itself. This means you can spend more money then you have available going into the red. If you could help explain whats happening, a way to fix or different (acceptable) approach that i could take it would really help. Once this bug is resolved i will also change DO_CLEAR_AREA.
This task depends upon

Closed by  Remko Bijker (Rubidium)
Monday, 13 December 2010, 15:15 GMT
Reason for closing:  Implemented
Additional comments about closing:  In r21500
Comment by Chris (l_blue_l) - Thursday, 12 April 2007, 07:29 GMT
For some reason i forgot to update the coding style for the viewport.h file but this will be included when i upload the next version

Also there is a typo in the first section it is meant to read "courses the GetAvailableMoneyForCommand(); function to* continually returns the original value"
Comment by NukeBuster (NukeBuster) - Thursday, 05 July 2007, 21:29 GMT
The bug mentioned in the details part of this task, is fixed. I would like to know, what changes are needed for this patch to be included into the trunk.

The updated patch is attached to this comment.
Comment by NukeBuster (NukeBuster) - Friday, 20 July 2007, 20:11 GMT
Comment by bove027 (bove027) - Monday, 12 November 2007, 22:40 GMT
Is this patch already included in the nightlies? If not, will it be added? This is an option I'm missing very much
Comment by Zdeněk Sojka (SmatZ) - Sunday, 28 September 2008, 23:24 GMT
 FS#2320  is another patch doing the same (in a bit different way)
Comment by fonsinchen (fonsinchen) - Monday, 29 September 2008, 09:58 GMT
The patches in  FS#2320  are up to date, don't change unrelated files and propose an elegant way to iterate over tiles in rectangular areas. There is a different thread in tt-forums for these, as the original thread has been locked:

To reiterate it: I will happily change whatever is needed to get the functionality into trunk. Please comment.
Comment by fonsinchen (fonsinchen) - Saturday, 14 March 2009, 18:38 GMT
So these are the updated versions of the patches linked to in the last comment.
Comment by fonsinchen (fonsinchen) - Saturday, 28 March 2009, 21:26 GMT
Another update for the java style patch. I had accidentally removed a range check there which made the game freeze when trying to lower below sea level.
Comment by fonsinchen (fonsinchen) - Tuesday, 16 June 2009, 21:58 GMT
Another update to current trunk. As in the forum thread only the C++ style is maintained and the patch has been split in two for easier review. tileiter provides the general tile iteration functionality which should be reusable in many places. diaglvl is to be applied on top of tileiter.
Comment by fonsinchen (fonsinchen) - Wednesday, 14 October 2009, 11:48 GMT
You can pull these patches from my git repository at The branches are named "tileiter" and "diaglvl".
You can also always download up-to-date versions of these patches from and The latter is to be applied on top of tileiter. They apply to the version of trunk recorded in
Comment by fonsinchen (fonsinchen) - Sunday, 06 December 2009, 00:35 GMT
I have changed the patch to not use the invalid iterator. The syntax was very verbose and you couldn't use diagonal and orthogonal iterators polymorphically. Now there is a method "IsValid" which can be called to see if an iterator is still valid. This is basically the same as checking for inequality with the invalid iterator, but greatly reduces the code size and allows polymorphic usage (as can be seen in CmdClearArea in the diaglvl patch).
Comment by fonsinchen (fonsinchen) - Thursday, 10 June 2010, 21:10 GMT
The repository has moved to git://
An up-to-date patch can now be found at
The tileiter patch can be found at
The trunk version they to can be found at

Unfortunately trunk development has taken a different direction (TileArea) which is incompatible with my approach. I'm still keeping this open as it's a very popular feature and I might reimplement it based on TileArea some time.