City Influence Area Patch

OpenTTD is a fully open-sourced reimplementation of TTD, written in C++, boasting improved gameplay and many new features.

Moderator: OpenTTD Developers

Post Reply
User avatar
Dribbel
Engineer
Engineer
Posts: 64
Joined: 11 Jul 2004 16:25
Location: The Netherlands - Grunn

City Influence Area Patch

Post by Dribbel »

Today I started working on my first patch. I thought : let's start with someting easy:

The City Outline, described here.

My first results are promissing, see the attached patch.

Current "features"
A new button in the city window, "Radius", when clicked on it will bulldoze all the tiles in the city influence radius. Be sure to have enough money to do this :) (it could make it "Plant Trees" but the effect is not as clear as with bulldoze)

The reason to bulldoze is simple: I don't know how to outline/select/lightup a set of tiles. Further more the tiles are in a odd shape, for instance if more towns are close together. Any hint are welcome!

--edit: Changed the Bulldoze-action into Farmfences, little less agressive.
Sideaffects: Fence will disappear in desert and snow areas
But keep in mind, not all is done yet :)

--edit 2:
Done!
My first real patch is done! There is now an extra button in the city window. It toggles the display of the influence array of that city. The area is marked with blu squares (like the capture area of stations).
Attachments
CityRadius.diff
This patch adds an extra button in the city radius window, that toggles the display of the city influence array in the map.
(6.55 KiB) Downloaded 295 times
Last edited by Dribbel on 15 Jul 2004 04:04, edited 2 times in total.
Programmeren is makkelijker als je denkt - Dutch pun
[url=callto://zoekdribbel]Image[/url]
Pipian
Engineer
Engineer
Posts: 122
Joined: 10 Jul 2004 02:25
Contact:

Post by Pipian »

Would be nice if someone could fix up this patch to just outline... Bulldozing all tiles would be... rather dangerous you think? Would destroy the city and severly lower your ranking =P

Fromt he sounds of it though, you've got a good idea...
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

please make it just show the tiles instead of doing an action to them. Build farm fences at the boarder or something
I like the idea of getting a quick overview, but bulldozing...... not good
User avatar
minime
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 18 Jan 2004 10:02
Skype: dan.masek
Location: Prague, Czech Republic
Contact:

Post by minime »

He probably had that as an initial step in development, to see if it finds the tiles correctly.

Anyway, how about highlighting them with that red border, similar to how an invalid tile (for example when building tunnel in the wrong place, or when something prevents you from lowering terrain..)?
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

minime wrote:He probably had that as an initial step in development, to see if it finds the tiles correctly.

Anyway, how about highlighting them with that red border, similar to how an invalid tile (for example when building tunnel in the wrong place, or when something prevents you from lowering terrain..)?
red border sounds ok too

btw how can location be "Czech rep./Canada" Did the Czechs conquer Canada? Or did Canada steal the Czech rep.? Since they want to steal a Danish Island, I will expect everything from them :wink:
User avatar
Dribbel
Engineer
Engineer
Posts: 64
Joined: 11 Jul 2004 16:25
Location: The Netherlands - Grunn

Post by Dribbel »

Indeed the bulldozing is to check if i got the right tiles :) More friendly is to place trees, or no action at all. Framfences is a good idea, for now, far less destructive, --> Check the new patch above.

The problem with the red-square is that the current code only suports ONE red-square at the time, as far as i know. The white squares I haven't figured out yet, but the seem only to appear in line/rectangles and not in odd-shaped figures. I have to do some more research (read: code exploration) on that. I can't even make a simple white square appear in or near the city :'(

If any one has any (coding) ideas on the white squares, please tell me :)
Last edited by Dribbel on 13 Jul 2004 01:55, edited 1 time in total.
Programmeren is makkelijker als je denkt - Dutch pun
[url=callto://zoekdribbel]Image[/url]
User avatar
minime
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 18 Jan 2004 10:02
Skype: dan.masek
Location: Prague, Czech Republic
Contact:

Post by minime »

I suppose we could nip a little piece of their land, it's not like they don't have enough :lol:

The truth is, I'm from the first, did my uni at the second (which is when I made this account) and am going back shortly, so either one can apply, depending on the time of the year. And I couldn't really be bothered to change it. :D
User avatar
Dribbel
Engineer
Engineer
Posts: 64
Joined: 11 Jul 2004 16:25
Location: The Netherlands - Grunn

Post by Dribbel »

It seems that the white/red square are linked to mouse events. Decoupling them is a hell of a job.

An other solution is to create an overlay data structure. This is also lots of work, but when done properly, it can be used for many more cool yet-to-be-thought-of features!

I'll see if i can pull this one off. I'ts quite a challenge :D But what the heck it's summer holidays and the weather is Terrible :'( (note the capital T)
Programmeren is makkelijker als je denkt - Dutch pun
[url=callto://zoekdribbel]Image[/url]
User avatar
Dribbel
Engineer
Engineer
Posts: 64
Joined: 11 Jul 2004 16:25
Location: The Netherlands - Grunn

Post by Dribbel »

I'm done!!!!

And I learned a great deal about the code!

See the opening post for the patch! (against 917)
Programmeren is makkelijker als je denkt - Dutch pun
[url=callto://zoekdribbel]Image[/url]
User avatar
mdhowe
Route Supervisor
Route Supervisor
Posts: 446
Joined: 09 Jul 2004 07:12
Location: Hobart, Australia

Post by mdhowe »

Is this patch going to be merged into SVN?
"Set fashion, not follow. Spit vitriol, not swallow" - Marilyn Manson
User avatar
Mad Dog McKill
President
President
Posts: 911
Joined: 13 Nov 2002 10:24
Location: Singapore but originally Moscow

Post by Mad Dog McKill »

I hope so.. but its a pity that many patches are put aside or are forgot about... :cry:

I am sure that there many more such small and useful patches :(
OT: By FIREMARK: "Limitation disturbs me very sprites. Goes it throw out limitation?"
My Last.fm Profile
My Facebook Profile
User avatar
Doc Oc
Engineer
Engineer
Posts: 58
Joined: 23 Aug 2004 00:48
Location: The Netherlands

Post by Doc Oc »

Thanks Dribble, I like this patch a lot, its very useful. Clearly, the performance problem in your for-loop had to be fixed, so I took a moment (a lot longer than I had anticipated) and did.

Change this bit...

Code: Select all

//Check all the tiles, hmm could be more efficient:
	// Look up all the tiles in all directions with
	// distance < _patches.dist_local_authority and check those
	for(tile=0; tile!=TILES_X*TILES_Y; tile++) {
		found = ClosestTownFromTile(tile, _patches.dist_local_authority);
		if (found != NULL && found->index == index){
			// Now to create an overlay for all tiles...
			SetMapExtraBits2(tile, on);
			MarkTileDirtyByTile(tile);
		}
	}
...into this:

Code: Select all

int pdla = _patches.dist_local_authority;

	int x = max(0, GET_TILE_X(t->xy) - pdla);  // town_center x - authority radius
	int y = max(0, GET_TILE_Y(t->xy) - pdla);  // town_center y - authority radius

	// loop from (town_center - radius) to (town_center + radius)
	BEGIN_TILE_LOOP(tile, 2*pdla, 2*pdla, TILE_XY(x,y))
		found = ClosestTownFromTile(tile, pdla);
		if (found != NULL && found->index == index)
		{
			SetMapExtraBits2(tile,on);
			MarkTileDirtyByTile(tile);
		}
	END_TILE_LOOP(tile, 2*pdla, 2*pdla, TILE_XY(x,y))
and it's all snappy!


Glad I found those xx_TILE_LOOP macro's. I had been doing a lot of unnecessary work up to then.

Image


I'm completely new to TortoiseSVN and patch/diff, but I'll try and make a new patch out of this.

edit That wasn't too hard. Patch against revision 120 is attached.
Attachments
CityRadius.diff
Patch against SVN rev120, adding the CityRadius patch with the improved algorithm.
(7.35 KiB) Downloaded 246 times
CSL
Engineer
Engineer
Posts: 41
Joined: 18 Aug 2004 15:02

Post by CSL »

Wow that's really nice :)
Would someone please compile the nightly build with this patch and upload the compiled version here?

Many thanks...I am using Windows...can't apply this patch :)
User avatar
Doc Oc
Engineer
Engineer
Posts: 58
Joined: 23 Aug 2004 00:48
Location: The Netherlands

Post by Doc Oc »

CSL wrote:Wow that's really nice :)
Would someone please compile the nightly build with this patch and upload the compiled version here?

Many thanks...I am using Windows...can't apply this patch :)
I'm on windows... I made the patch ;). Seriously though, I'd send you an exe but it'd be of no use to you. I can't compile with ZLIB support (long story), can't address that problem (same story) and therefore none of my builds support the savegame format.

The patch needs to be rewritten anyway. It should run right in the map tile rendering loop, saving lots of memory and quite a bit of CPU time as well. It's not fit to be merged into the main branch as it is.
User avatar
mdhowe
Route Supervisor
Route Supervisor
Posts: 446
Joined: 09 Jul 2004 07:12
Location: Hobart, Australia

Post by mdhowe »

CSL wrote:Would someone please compile the nightly build with this patch and upload the compiled version here?
You can learn how to do that on the wiki:
http://openttd.rulez.org/wiki2/index.ph ... evelopment
"Set fashion, not follow. Spit vitriol, not swallow" - Marilyn Manson
User avatar
teeone
Transport Coordinator
Transport Coordinator
Posts: 307
Joined: 05 Aug 2004 20:54
Location: Oregon, USA

Post by teeone »

Any chance for this to be in the NEXT nightly build? I'd appreciate it much and there's a lot of steps to "patch" my openttd...(download the source, install TortoiseSVN, follow the steps to patch it, install cygwin/msvs, follow the steps to compile it)...It's just A LOT to ask newbies to do who dont know anything about programming or compiling....
I don't see why this WOULDN'T be included in a nightly, it would be great to use this instead of using the query tool in the dark lol
User avatar
dominik81
OpenTTD Developer
OpenTTD Developer
Posts: 768
Joined: 16 Aug 2003 12:55
Location: Bonn, Germany

Post by dominik81 »

No chance for the next nightly, no. Like Doc Oc said, it's not ready to be added to SVN. It is still too complicated implemented and eats up too much memory and CPU cycles. But I'm confident that it will make it into SVN eventually.
"There's a readme that comes with the source. I suggest you read it."
- Korenn
CSL
Engineer
Engineer
Posts: 41
Joined: 18 Aug 2004 15:02

Post by CSL »

mdhowe wrote:
CSL wrote:Would someone please compile the nightly build with this patch and upload the compiled version here?
You can learn how to do that on the wiki:
http://openttd.rulez.org/wiki2/index.ph ... evelopment
Wow many thanks!
Post Reply

Return to “General OpenTTD”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 20 guests