Page 1 of 4
Patch to buy an area of land
Posted: 06 Jan 2007 18:55
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
Posted: 06 Jan 2007 21:22
by mexicoshanty
thank you!
This has been needed for a long time.
Posted: 07 Jan 2007 00:40
by Quark
mexicoshanty wrote:This has been needed for a long time.
Doesn't it was in MiniIN all this long time?
Posted: 07 Jan 2007 04:03
by Sacro
Quark wrote:
Doesn't it was in MiniIN all this long time?
Ralf Wiggum wrote:Me fail english? Thats unpossible!
Posted: 07 Jan 2007 05:20
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?
Posted: 07 Jan 2007 05:35
by Sacro
Well... the thing is... im not entirely sure myself
Posted: 07 Jan 2007 09:00
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
Posted: 07 Jan 2007 09:45
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
Posted: 07 Jan 2007 10:56
by Quark
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.
Posted: 07 Jan 2007 11:03
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
Posted: 07 Jan 2007 12:53
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?
Posted: 07 Jan 2007 15:31
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
Posted: 07 Jan 2007 16:12
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;
Posted: 25 Apr 2007 01:29
by micomico
Rediff against trunk r9715.
Posted: 25 Apr 2007 06:27
by DeletedUser21
Wow you are on fire aren't you?
Great work Micomico! Also with the other rediff.
Posted: 28 May 2007 17:33
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
Re: Patch to buy an area of land
Posted: 25 Oct 2007 21:23
by pavel1269
patch dont work for me
can anyone update it please?
Re: Patch to buy an area of land
Posted: 26 Oct 2007 04:03
by DaleStan
How dont[sic] it work?
Re: Patch to buy an area of land
Posted: 26 Oct 2007 10:13
by pavel1269
you can select what area you want to buy, but when you drop left mouse buttom, nothink happend
Re: Patch to buy an area of land
Posted: 26 Oct 2007 16:26
by CMircea
Are you sure you applied it on r10220?