Coding bridges

Discuss, get help with, or post new graphics for TTDPatch and OpenTTD, using the NewGRF system, here. Graphics for plain TTD also acceptable here.

Moderator: Graphics Moderators

User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Coding bridges

Post by FooBar »

I just learnt how to code bridges, and I must say it's a royal pain in the behind, because I'm unable to find sufficient information on how the bridge layouts work. "various middle parts", as stated in the wiki isn't actually very informative :P

Is there information available on how the different bridge pieces are ordered behind one another? This would really help me re-encoding most of the default bridges, because I'm only replacing the maglev ones. The default bridge tables might also be useful (if in human readable (NFO) format).

Thanks,
FooBar
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: Coding bridges

Post by michael blunck »

Check this one (or some of the follow-ups): http://lists.ttdpatch.net/ttdpatch/200310/msg00227.html

HTH
regards
Michael
Image
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Coding bridges

Post by FooBar »

Thanks, Michael.

At least this bit of information should prove of any use:
Marcin Grzegorczyk wrote:As far as I can figure out from the code, the bridge layout *internally*
always is like shown below, where numbers are internal 'part' numbers
(L2 bits 3..0) and '-' is an ending:

-- if the length of the mid-part is equal to 0
-0- if the length of the mid-part is equal to 1
-0(23)1- if the length is an even number
-0(23)4(32)1- if the length of the mid-part modulo 4 is 3
-0(23)252(32)1- if the length of the mid-part modulo 4 is 1

(parenthesized parts repeated as many times as needed)

For uniform-looking bridges all parts (or all parts except 0 and 1)
simply look the same.
EDIT:
Actually, the scheme as posted above doesn't make sense on the suspension bridge. In the image below, the last option from the scheme above should apply. The numbers on the bridge refer to the numbers in the scheme. Problem is: equal numbers do not imply equal bridge parts. I guess I have to make some dummy sprites, code it all up and see what happens.
Attachments
Naamloos-6.png
Naamloos-6.png (14.81 KiB) Viewed 5290 times
User avatar
thgergo
Route Supervisor
Route Supervisor
Posts: 391
Joined: 29 Mar 2005 12:44
Location: Hungary

Re: Coding bridges

Post by thgergo »

FooBar wrote:Thanks, Michael.

At least this bit of information should prove of any use:
Marcin Grzegorczyk wrote:As far as I can figure out from the code, the bridge layout *internally*
always is like shown below, where numbers are internal 'part' numbers
(L2 bits 3..0) and '-' is an ending:

-- if the length of the mid-part is equal to 0
-0- if the length of the mid-part is equal to 1
-0(23)1- if the length is an even number
-0(23)4(32)1- if the length of the mid-part modulo 4 is 3
-0(23)252(32)1- if the length of the mid-part modulo 4 is 1

(parenthesized parts repeated as many times as needed)

For uniform-looking bridges all parts (or all parts except 0 and 1)
simply look the same.
EDIT:
Actually, the scheme as posted above doesn't make sense on the suspension bridge. In the image below, the last option from the scheme above should apply. The numbers on the bridge refer to the numbers in the scheme. Problem is: equal numbers do not imply equal bridge parts. I guess I have to make some dummy sprites, code it all up and see what happens.
The correct bridge part order, has gor some errors, the correct one in my understanding is:

-- if the length of the mid-part is equal to 0
-0- if the length of the mid-part is equal to 1
-0(23)1- if the length is an even number
-0(23)4(23)1- if the length of the mid-part modulo 4 is 3
-0(23)253(23)1- if the length of the mid-part modulo 4 is 1
Maybe Marcin Grzegorczyk made a typo...
Image
Image
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: Coding bridges

Post by michael blunck »

thgergo wrote:Maybe Marcin Grzegorczyk made a typo...
AFAIR, it was noticed and corrected already in the follow-ups of Marcin´s original message (from 2003, BTW 8) ) .

regards
Michael
Image
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Coding bridges

Post by FooBar »

michael blunck wrote:AFAIR, it was noticed and corrected already in the follow-ups of Marcin´s original message (from 2003, BTW 8) )
I thought I'd read those, but appearantly missed the one with the real information. Reversing the (32) in (23) would indeed make more sense.

EDIT:
I think I've got it figured out now. Thanks for the help guys! I've got my first transrapid bridge coded now, and the re-enstatement code for the wooden bridge finished. 12 more to go :D

When finisihed, I'll share all code which just rebuilds the default bridges at the wiki. It's just not an actual fun job to write down sprite numbers, convert to hex and put 'em in a different order in the bridge tables.
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Coding bridges

Post by FooBar »

I updated the wiki page and added information on the layouts and a piece of example code on how the suspension bridge is coded.
User avatar
thgergo
Route Supervisor
Route Supervisor
Posts: 391
Joined: 29 Mar 2005 12:44
Location: Hungary

Re: Coding bridges

Post by thgergo »

FooBar wrote:I updated the wiki page and added information on the layouts and a piece of example code on how the suspension bridge is coded.
That wiki page looks nice by now:) Great work :wink: And readable, understandable, than the previsious version.
Image
Image
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Coding bridges

Post by FooBar »

Thanks, thgergo!

I think I'll also add a list of bridge IDs. The ID order isn't difficult, but a list is always easier than figuring stuff out yourself, especially if one only wants to replace just one bridge. Or the stats of just one bridge for that matter.

As soon as I've figured out the recolour stuff, I'll probably add some more on that too. I already found some information in 'your' bridge renewal topic which might be useful.
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Coding bridges

Post by FooBar »

FINALLY!
I just finished recoding all default bridges. I was quite the ordeal putting everything together, but I'm willing to share the NFO code with whoever likes to use it. The file attached below contains every bridge, every tracktype and every recolouring as necessary.

The NFO code is licensed under the Creative Commons Attribution-Noncommercial 3.0 Netherlands license
http://creativecommons.org/licenses/by- ... nl/deed.en

EDIT:
Since 2010/07/29, the code attached below is also available under GNU GPL v2 licence
http://www.gnu.org/licenses/gpl-2.0.html

EDIT2:
As of 2011/06/15 you may also use this code in your GNU GPL v3 projects.
Attachments
default_bridges.txt
Licensed under CC BY-NC NL or GNU GPL v2.0/v3.0
(72.74 KiB) Downloaded 246 times
Last edited by FooBar on 15 Jun 2011 09:17, edited 2 times in total.
User avatar
minime
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 18 Jan 2004 10:02
Skype: dan.masek
Location: Prague, Czech Republic
Contact:

Re: Coding bridges

Post by minime »

This would have been much easier to read had you used escape sequences:

Code: Select all

\dx000009F2 \dx000009F6 \dx000009F8 \d0
or even

Code: Select all

\dx9F2 \dx9F6 \dx9F8 \d0
instead of

Code: Select all

F2 09 00 00  F6 09 00 00  F8 09 00 00  00 00 00 00
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. --Albert Einstein
Image Image Image
User avatar
DJ Nekkid
Tycoon
Tycoon
Posts: 2141
Joined: 30 Nov 2006 20:33

Re: Coding bridges

Post by DJ Nekkid »

well foobar, or someone ... if i (or purno/mark)provide you with the sprites, could you make/replace the monorail sprites/bridges for the 2cc set? ;)
Member of the
ImageImage
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Coding bridges

Post by FooBar »

minime wrote:This would have been much easier to read ...
Somehow I managed to learn how to think in hex and little endian. For me F2 09 00 00 is as easy to read as \dx000009F2.

But yes, I have to agree that adding 03208000 to 000009F2 is copy/paste wise a lot more easy than adding 00 80 20 03 to F2 09 00 00 :mrgreen:

And, in case of NFORenum, I probably should have used \d(2546 52461568 +), where 2546 is just the plain decimal sprite number, and 52461568 the value to add for colour translation.

Come to think of it, out of all options, I picked the most difficult one :lol:


DJ Nekkid wrote:well foobar, or someone ... if i (or purno/mark)provide you with the sprites, could you make/replace the monorail sprites/bridges for the 2cc set? ;)
It should be adviced that you'll break compatibility with the Transrapid Track Set if replacement monorail bridges if not all replacement bridges are included in one set. So I recommend creating one big track set containing the transrapid tracks, monorail tracks and metro tracks. In that case, one can do whatever you like with bridges and such.
Then your question: I'm currently short in time, but still willing to help you with the bridge code. If either one of you could supply the physical sprites and the real sprite NFO data (just the realsprites with sizes and offsets set correctly are fine, I'll ActionA/GRM them myself), I can do the bridge code relatively quickly, after which I pass the code back and either one of you can do the final alignment (which is as any alingment controlled through the realsprites, so not a difficult task, but it takes a lot of time).
I'm also willing to do everyting, but then you'll have to wait until I'm finished with the TTDPatch release of the Dutch tramset.
User avatar
Purno
Tycoon
Tycoon
Posts: 16659
Joined: 30 Mar 2004 12:30
Location: Almere, The Netherlands

Re: Coding bridges

Post by Purno »

I once drew a concrete metro bridge, but it looks fugly. Sorry for the topic chance, but perhaps I can create a competition for a bridge which looks like ordinary elevated rail used in several big cities? No need to have different bridges for metro I think. Same applies to transrapid tracks. Question is, can we code a metro and transrapid bridge while leaving all ordinary rail bridges alone?
Contributor to the The 2cc Set and Dutch Trainset. Inventor of the Metro concept. Retired Graphics Artist.
Image Image
Download TT | Latest TTDPatch | OpenTTD | OpenTTDCoop | BaNaNaS: OpenTTD content system | 2048² OTTD scenario of the Netherlands
GRF Codec | GRF Crawler | GRF Maker | Usefull graphics & tools sites | NML Documentation Wiki | NFO Documentation Wiki
All my graphics are licensed under GPL. "Always remember you're unique, just like everyone else."
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Coding bridges

Post by FooBar »

Purno wrote:Question is, can we code a metro and transrapid bridge while leaving all ordinary rail bridges alone?
Yes, as long as all custom bridges are contained in one GRF.
User avatar
Purno
Tycoon
Tycoon
Posts: 16659
Joined: 30 Mar 2004 12:30
Location: Almere, The Netherlands

Re: Coding bridges

Post by Purno »

But can multiple bridge GRFs be combined? These days barely anybody uses the default TT bridges...
Contributor to the The 2cc Set and Dutch Trainset. Inventor of the Metro concept. Retired Graphics Artist.
Image Image
Download TT | Latest TTDPatch | OpenTTD | OpenTTDCoop | BaNaNaS: OpenTTD content system | 2048² OTTD scenario of the Netherlands
GRF Codec | GRF Crawler | GRF Maker | Usefull graphics & tools sites | NML Documentation Wiki | NFO Documentation Wiki
All my graphics are licensed under GPL. "Always remember you're unique, just like everyone else."
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Coding bridges

Post by FooBar »

Purno wrote:But can multiple bridge GRFs be combined?
Unfortunately no.

One can replace bridges on a per bridge basis, but has to replace ALL different track types of that bridge simultaneously.
Let's say you want to replace the tubular maglev bridge only. In the NFO, you can replace that particular bridge easily, but have to recode the other three tracktypes. Without the recode, the tubular bridge does not have graphics any more for the other tracktypes.
Now let's load our new grf over, lets say, the total bridge replacement set. Now we end up with our new maglev bridge, the default tubular bridge for the other tracktypes and all other bridges from the total bridge set.
Imagine what would happen if you replace all maglev bridges and load those over the total bridge set[0]. The last bridge set must contain ALL bridges you would like to use in your games.

[0] You end up with you new maglev bridges, all other default bridges and no total bridge renewal set bridge at all.
User avatar
Purno
Tycoon
Tycoon
Posts: 16659
Joined: 30 Mar 2004 12:30
Location: Almere, The Netherlands

Re: Coding bridges

Post by Purno »

Sounds complicated. But if I understand correctly we're stuck with two options:
- Or we make our own complete bridgeset
- Or we ask an exisiting bridge set to support our metro and transrapid tracks
Is'nt it?
Contributor to the The 2cc Set and Dutch Trainset. Inventor of the Metro concept. Retired Graphics Artist.
Image Image
Download TT | Latest TTDPatch | OpenTTD | OpenTTDCoop | BaNaNaS: OpenTTD content system | 2048² OTTD scenario of the Netherlands
GRF Codec | GRF Crawler | GRF Maker | Usefull graphics & tools sites | NML Documentation Wiki | NFO Documentation Wiki
All my graphics are licensed under GPL. "Always remember you're unique, just like everyone else."
User avatar
eis_os
TTDPatch Developer
TTDPatch Developer
Posts: 3603
Joined: 07 Mar 2003 13:10
Location: Germany
Contact:

Re: Coding bridges

Post by eis_os »

I try still hard to allowing set allocation for bridges like stations, but my current code doesn't work yet...
User avatar
Purno
Tycoon
Tycoon
Posts: 16659
Joined: 30 Mar 2004 12:30
Location: Almere, The Netherlands

Re: Coding bridges

Post by Purno »

Do you advice to wait with trying to code a workaround GRF till you got a working feature, or do you expect it'll take long enough a (temporary) workaround is useful?
Contributor to the The 2cc Set and Dutch Trainset. Inventor of the Metro concept. Retired Graphics Artist.
Image Image
Download TT | Latest TTDPatch | OpenTTD | OpenTTDCoop | BaNaNaS: OpenTTD content system | 2048² OTTD scenario of the Netherlands
GRF Codec | GRF Crawler | GRF Maker | Usefull graphics & tools sites | NML Documentation Wiki | NFO Documentation Wiki
All my graphics are licensed under GPL. "Always remember you're unique, just like everyone else."
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: Google Adsense [Bot] and 77 guests