Patch to buy an area of land

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

rfalke
Engineer
Engineer
Posts: 16
Joined: 06 Jan 2007 18:44

Patch to buy an area of land

Post by rfalke »

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
Attachments
buy_area1.diff
(3.94 KiB) Downloaded 1101 times
User avatar
mexicoshanty
Traffic Manager
Traffic Manager
Posts: 158
Joined: 22 Aug 2006 13:15
Location: Australia
Contact:

Post by mexicoshanty »

thank you!

This has been needed for a long time.
Quark
Transport Coordinator
Transport Coordinator
Posts: 325
Joined: 20 Sep 2006 11:36
Location: Russia, Moscow

Post by Quark »

mexicoshanty wrote:This has been needed for a long time.
Doesn't it was in MiniIN all this long time?
Image
Sacro
Tycoon
Tycoon
Posts: 1145
Joined: 18 Jun 2005 21:08
Location: Here
Contact:

Post by Sacro »

Quark wrote: Doesn't it was in MiniIN all this long time?
Ralf Wiggum wrote:Me fail english? Thats unpossible!
:lol:
We Am De Best

Host of ThroughTheTube site
Quark
Transport Coordinator
Transport Coordinator
Posts: 325
Joined: 20 Sep 2006 11:36
Location: Russia, Moscow

Post by Quark »

Ralf Wiggum wrote:Me fail english? Thats unpossible!
I never studied English, so please don't blame me for improper word connections :) (Better PM me with right sentence form and some notes why I was wrong)
Or you prefer google translation instead? :)
Image
Sacro
Tycoon
Tycoon
Posts: 1145
Joined: 18 Jun 2005 21:08
Location: Here
Contact:

Post by Sacro »

Well... the thing is... im not entirely sure myself :?
We Am De Best

Host of ThroughTheTube site
rfalke
Engineer
Engineer
Posts: 16
Joined: 06 Jan 2007 18:44

Post by rfalke »

Quark wrote:
mexicoshanty wrote:This has been needed for a long time.
Doesn't it was in MiniIN all this long time?
Independent of this: what are the next steps to get this feature into HEAD?

EDIT: Well I just found http://bugs.openttd.org/task/331 :(

Raimar
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post by Wolf01 »

this patch is also included in the eyecandy patch because is needed...
it also is multiplayer-proof, to avoid the purchasing of big areas of terrain in multiplayer... so is futile to continue to make other versions, maybe try to fix and make elegant the code of the one in the eyecandy patch
Quark
Transport Coordinator
Transport Coordinator
Posts: 325
Joined: 20 Sep 2006 11:36
Location: Russia, Moscow

Post by Quark »

rfalke wrote:EDIT: Well I just found http://bugs.openttd.org/task/331 :(
That patch has bug with it

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;
You can see, it returns cost needed to clear area plus purchase cost of one tile.
There was another bug in MiniIN (when I was compiling my build), it returns full cost plus cost of one tile.
Image
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post by Wolf01 »

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
Quark
Transport Coordinator
Transport Coordinator
Posts: 325
Joined: 20 Sep 2006 11:36
Location: Russia, Moscow

Post by Quark »

I can't understand what you say :), but in MiniIN that line is executed before cost calculation

Code: Select all

cost = _price.purchase_land*10; //crashes the game
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 line

Code: Select all

// END DRAG CODE
	return cost; //buy 3 pay 2, why?
See 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?
Image
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post by Wolf01 »

that is because the patch wasn't finished and was merged with miniIN
previously that line contained a formula to calculate the cost based on the advanced town handling, and crashed the game if the advanced town handling was active, i fixed that but i didn't remove the comment
Frostregen
Transport Coordinator
Transport Coordinator
Posts: 340
Joined: 06 Feb 2006 23:58

Post by Frostregen »

Currently it looks something like this.
(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;
micomico
Engineer
Engineer
Posts: 18
Joined: 25 Apr 2007 01:19
Location: Portugal

Post by micomico »

Rediff against trunk r9715.
Attachments
buy-area-r9715.patch
(4.02 KiB) Downloaded 457 times
DeletedUser21
Tycoon
Tycoon
Posts: 11501
Joined: 20 Sep 2004 22:45

Post by DeletedUser21 »

Wow you are on fire aren't you? :P

Great work Micomico! Also with the other rediff. :)
BamBam
Engineer
Engineer
Posts: 34
Joined: 06 May 2007 17:49

Post by BamBam »

There are several changes in the code so the patch doesn't work.
Here an update:

Edit 19. June 2007: update to r10220
Attachments
buy_an_area_r10220.patch
(4.43 KiB) Downloaded 463 times
buy_an_area_r10215.7z
Win32 executable
(904.1 KiB) Downloaded 350 times
User avatar
pavel1269
Route Supervisor
Route Supervisor
Posts: 473
Joined: 03 Dec 2006 13:22
Location: Czech Republic
Contact:

Re: Patch to buy an area of land

Post by pavel1269 »

patch dont work for me :|
can anyone update it please?
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: Patch to buy an area of land

Post by DaleStan »

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
User avatar
pavel1269
Route Supervisor
Route Supervisor
Posts: 473
Joined: 03 Dec 2006 13:22
Location: Czech Republic
Contact:

Re: Patch to buy an area of land

Post by pavel1269 »

you can select what area you want to buy, but when you drop left mouse buttom, nothink happend
User avatar
CMircea
Chairman
Chairman
Posts: 887
Joined: 29 Dec 2006 14:05

Re: Patch to buy an area of land

Post by CMircea »

Are you sure you applied it on r10220?
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 9 guests