Patch to buy an area of land
Moderator: OpenTTD Developers
Patch to buy an area of land
Hello
The attached patch allows to buy an area of land via the dragging of
the mouse like bulldozing an area. I find this useful for reserving areas
into which cities should no grow.
Raimar
The attached patch allows to buy an area of land via the dragging of
the mouse like bulldozing an area. I find this useful for reserving areas
into which cities should no grow.
Raimar
- Attachments
-
- buy_area1.diff
- (3.94 KiB) Downloaded 1220 times
- mexicoshanty
- Traffic Manager
- Posts: 158
- Joined: 22 Aug 2006 13:15
- Location: Australia
- Contact:
Independent of this: what are the next steps to get this feature into HEAD?Quark wrote:Doesn't it was in MiniIN all this long time?mexicoshanty wrote:This has been needed for a long time.
EDIT: Well I just found http://bugs.openttd.org/task/331

Raimar
That patch has bug with itrfalke wrote:EDIT: Well I just found http://bugs.openttd.org/task/331
Code: Select all
+ // loop through the affected tiles
+ BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) {
+ if (!EnsureNoVehicle(tile2)) return CMD_ERROR;
+ if (IsOwnedLandTile(tile2) && IsTileOwner(tile2, _current_player)) {
+ return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT);
+ }
+
+ ret = DoCommand(tile2, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
+ if (CmdFailed(ret)) return CMD_ERROR;
+ cost += ret;
+
+ if (flags & DC_EXEC) {
+ if ((money -= ret) < 0) {
+ _additional_cash_required = ret;
+ return cost - ret;
+ }
+ MakeOwnedLand(tile2, _current_player);
+ MarkTileDirtyByTile(tile2);
+ }
+ } END_TILE_LOOP(tile2, size_x, size_y, tile)
+
return cost + _price.purchase_land * 10;
There was another bug in MiniIN (when I was compiling my build), it returns full cost plus cost of one tile.
in miniIN it returned the cost minus the cost of one tile
that because if you buy one tile you get the cost of purchasing 2 tiles, so i thought was better to miss a tile when more than one are purchased instead of buy 2 times a single tile
i'm still thinking an elegant solution with no code duplication
that because if you buy one tile you get the cost of purchasing 2 tiles, so i thought was better to miss a tile when more than one are purchased instead of buy 2 times a single tile
i'm still thinking an elegant solution with no code duplication
I can't understand what you say
, but in MiniIN that line is executed before cost calculation
after cost is only added to itself, so returned price is total+1. So when you buy 3 tiles you pay 4x and when you buy 1 tile you pay 2x, so in end is that lineSee error?
You always pay 2x when you buy one tile and situation is more worse when you buy land with _patches.advanced_town_handling — you pay one tile by price without patch and then all area by price with patch.
P.S. and what that «crashes the game» comment?
P.P.S. To fix it you need to initialize cost to 0 instead of purchase land cost. Maybe cost was «*=» sometime ago?

Code: Select all
cost = _price.purchase_land*10; //crashes the game
Code: Select all
// END DRAG CODE
return cost; //buy 3 pay 2, why?
You always pay 2x when you buy one tile and situation is more worse when you buy land with _patches.advanced_town_handling — you pay one tile by price without patch and then all area by price with patch.
P.S. and what that «crashes the game» comment?
P.P.S. To fix it you need to initialize cost to 0 instead of purchase land cost. Maybe cost was «*=» sometime ago?
-
- Transport Coordinator
- Posts: 340
- Joined: 06 Feb 2006 23:58
Currently it looks something like this.
(Was fixed some time ago)
(Was fixed some time ago)
Code: Select all
cost = 0;
BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) {
tile_count+=1;
//test if is possible to buy the tile
if (!EnsureNoVehicle(tile2)) continue;
if (IsOwnedLandTile(tile2) && IsTileOwner(tile2, _current_player)) {
purchased_count+=1;
continue;
} else {
othercost = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(othercost)) {
unclear_count+=1;
continue;
} else {
cost += othercost;
}
}
if (flags & DC_EXEC) {
MakeOwnedLand(tile2, _current_player, p1);
MarkTileDirtyByTile(tile2);
}
//add cost for tile
cost += _price.purchase_land*10;
} END_TILE_LOOP(tile2, size_x, size_y, tile)
//error handling
if (tile_count == (unclear_count+purchased_count)) {
if (tile_count == purchased_count) {
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT);
} else {
return CMD_ERROR;
}
}
return cost;
-
- Tycoon
- Posts: 11501
- Joined: 20 Sep 2004 22:45
There are several changes in the code so the patch doesn't work.
Here an update:
Edit 19. June 2007: update to r10220
Here an update:
Edit 19. June 2007: update to r10220
- Attachments
-
- buy_an_area_r10220.patch
- (4.43 KiB) Downloaded 538 times
-
- buy_an_area_r10215.7z
- Win32 executable
- (904.1 KiB) Downloaded 443 times
Re: Patch to buy an area of land
patch dont work for me
can anyone update it please?

can anyone update it please?
My patches: Day length (new concept), Conditional loading, Auto separation, Unload all adds Leave empty, Better statue placement (in trunk)
My abandoned patches: Speed limits for RVs, Day length (old concept)
My abandoned patches: Speed limits for RVs, Day length (old concept)
Re: Patch to buy an area of land
How dont[sic] it work?
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
Re: Patch to buy an area of land
you can select what area you want to buy, but when you drop left mouse buttom, nothink happend
My patches: Day length (new concept), Conditional loading, Auto separation, Unload all adds Leave empty, Better statue placement (in trunk)
My abandoned patches: Speed limits for RVs, Day length (old concept)
My abandoned patches: Speed limits for RVs, Day length (old concept)
Re: Patch to buy an area of land
Are you sure you applied it on r10220?
Who is online
Users browsing this forum: No registered users and 18 guests