It is currently 15 Aug 2018, 09:52

WELCOME TO SIMUSCAPE!


Please Sign in or Register to enable all features, remove restrictions and gain additional access!
For information on how to bypass the CAPTCHA or to contact Team Simuscape, Continue Here!


Forum lockedPost a reply Page 1 of 1   [ 9 posts ]
Author Message
PostPosted: 04 Aug 2016, 08:52 
Master Mentor
User avatar

Joined: 27 Feb 2012, 22:45
Posts: 1646
Location: Canada
Recently cirdan added bridges to his New Map Features (NMF) fork of OpenTTD, extending the number of bridges to the maximum of 16 bridges as well as allowing bridges over stations. This encouraged me to get into the bridge building business.

GarryG saw a need for an Australian bridge set and I agreed to code it for him. His first bridge was a lesson for both of us and that prompted a need for a tutorial in case others would like to follow in his steps.

This tutorial is in three parts:
1. Overview: The basic structure of a bridge set.
2. Graphics: Developing a bridge sprite sheet.
3. Coding: How to code a bridge in NFO. (i)(ii)

(i) Currently NML does not support bridges.
(ii) Michael Blunck has included bridge support with tutorial in his m4nfo upper level language.

Reference: NewGRF Specifications

While this tutorial topic is locked there will be a companion topic for comments and questions and answers as soon as part 2 is completed.


Top
 Offline Profile  
 
PostPosted: 04 Aug 2016, 18:16 
Master Mentor
User avatar

Joined: 27 Feb 2012, 22:45
Posts: 1646
Location: Canada
1. Overview: The basic structure of a bridge set.

The Transport Tycoon game code structure can support 16 bridges in 4 types (rail, road, monorail, maglev) each, for a total of 64 bridges.

T - Transport Tycoon accesses only 11 bridges.
O - OpenTTD adds two bridges for 13.
N - New Map Features adds the final 3 slots for 16.

ID (dec) ID (hex) Description Platform Year
0 00 Wooden Bridge T,O,N 1920
1 01 Concrete Bridge T,O,N 1920
2 02 Girder, Steel Bridge T,O,N 1930
3 03 Suspension, Concrete Bridge (1) T,O,N 1920
4 04 Suspension, Steel (Bronze) Bridge T,O,N 1930
5 05 Suspension, Steel (Golden) Bridge (1) T,O,N 1930
6 06 Cantilever, Steel (Bronze) Bridge T,O,N 1930
7 07 Cantilever, Steel (Brown) Bridge (2) T,O,N 1930
8 08 Cantilever, Steel (Red) Bridge (2) T,O,N 1930
9 09 Girder, Steel Bridge T,O,N 1930
10 0A Tubular, Steel (Bronze) Bridge T,O,N 1995
11 0B Tubular, Steel (Golden) Bridge (3) O,N 2005
12 0C Tubular, Silicon Bridge (3) O,N 2010
13 0D To be drawn N Open
14 0E To be drawn N Open
15 0F To be drawn N Open

(1) Recolour of Suspension, Steel (Bronze) Bridge
(2) Recolour of Cantilever, Steel (Bronze) Bridge
(3) Recolour of Tubular, Steel (Bronze) Bridge
There are no sprites for the recolour bridges, nor for bridges 13, 14 or 15.

A bridge is an assembly of tiles arrayed North to South in the X or Y directions.
There are four tile types: Rail; Road; Monorail; MagLev.
The first and last tiles of the assembly are flat or sloped ramp (bridgehead) sprites.
Between the ramps we have an odd or even number of flat deck tiles.
Each deck tile is made up of three sprites: Back/Floor; Front; Pillars.
The tiles are grouped into sieven tables (8 rows x 4 columns) numbered 0 (00h) through 6 (06h).
Tables 0 through 5 are for the deck tiles with table 6 for the ramp tiles.

Each table, 0 through 5:
Rail X direction: Back/Floor; Front; Pillars; Empty Cell;
Rail Y direction: Back/Floor; Front; Pillars; Empty Cell;
Road X direction: Back/Floor; Front; Pillars; Empty Cell;
Road Y direction: Back/Floor; Front; Pillars; Empty Cell;
Mono X direction: Back/Floor; Front; Pillars; Empty Cell;
Mono Y direction: Back/Floor; Front; Pillars; Empty Cell;
MagL X direction: Back/Floor; Front; Pillars; Empty Cell;
MagL Y direction: Back/Floor; Front; Pillars; Empty Cell;
Table 6:
Rail Flat: North X; North Y; South X; South Y;
Rail Sloped: North X; North Y; South X; South Y;
Road Flat: North X; North Y; South X; South Y;
Road Sloped: North X; North Y; South X; South Y;
Mono Flat: North X; North Y; South X; South Y;
Mono Sloped: North X; North Y; South X; South Y;
MagL Flat: North X; North Y; South X; South Y;
MagL Sloped: North X; North Y; South X; South Y;

The empty cells are always void and never used.

To assemble a bridge, the game code references the tables in a manner consistent with the length of the bridge:
Layout Description
__ Bridge without middle part
_0_ Bridge of length 3
_0(23)1_ Bridge of even length
_0(23)4(23)1_ Bridge of (uneven) lengths 5, 9, 13, 17 etc.
_0(23)253(23)1_ Bridge of (uneven) lengths 7, 11, 15, 19 etc.

_ is used as a symbol to indicate ramps (bridgeheads) (as defined in table 6).
Part 0 is always at the farthest end from the viewer.
Parts (23) are repeated n times as necessary, where n is any number equal or greater than 0.


Top
 Offline Profile  
 
PostPosted: 06 Aug 2016, 06:32 
Master Mentor
User avatar

Joined: 27 Feb 2012, 22:45
Posts: 1646
Location: Canada
2. Graphics: Developing a bridge sprite sheet.

Now that we have our basics we can begin to develop our first sprite sheet.

References:
trg1r.grf - This is the Transport Tycoon basic graphics file. Transport Tycoon is proprietary and the game's CD is required to copy it in order to extract the pcx/png graphics and nfo code for reference purposes.
infra08.png - This is the OpenGFX infrastructure sprite sheet. It is GPL and is available here.
defaultbridges.png - This is a typical bridge sprite sheet. It was assembled from the Transport Tycoon trg1r file and is proprietary and is for reference only. It shows the sprite numbers used by NFO ActionA for simple sprite replacement. OTTD's sprite numbers are different but the OTTD code knows how to translate them. It is available in the attached zip file.
Attachment:
defaultbridges.zip [226.67 KiB]
Downloaded 52 times

Tile Grids - TTDX and OTTD share 19 tile shapes. This file contains a PCX graphics sheet as well as the newobject grf. It is available here.

Bridges use only the following five tile shapes:
Attachment:
BridgesTutorial01.png
BridgesTutorial01.png [ 1.52 KiB | Viewed 2192 times ]


Top
 Offline Profile  
 
PostPosted: 06 Aug 2016, 07:12 
Master Mentor
User avatar

Joined: 27 Feb 2012, 22:45
Posts: 1646
Location: Canada
This part of the tutorial demonstrates how to make a template for a road bridge.
Rail, Monorail, and MagLev templates would follow a similar process.

For consistency and alignment we derive our templates from the game's road tiles.
First we compare road/grass, road/sidewalk and rail tiles to see where we can get the best definition:
Attachment:
BridgesTutorial02.png
BridgesTutorial02.png [ 17.79 KiB | Viewed 2192 times ]

Attachment:
BridgesTutorial03.png
BridgesTutorial03.png [ 21.06 KiB | Viewed 2192 times ]

It appears that the road/sidewalk tiles give us what we need.
So, let's compare TTDX to OGFX:
Attachment:
BridgesTutorial04.png
BridgesTutorial04.png [ 6.61 KiB | Viewed 2192 times ]

Let's add some yellow lines to see where we get the best fit:
Attachment:
BridgesTutorial05.png
BridgesTutorial05.png [ 7.73 KiB | Viewed 2192 times ]

We see that the OGFX road is narrower and should give the best universal fit.
We will use OGFX.
Attachment:
BridgesTutorial06.png
BridgesTutorial06.png [ 6.42 KiB | Viewed 2192 times ]

Just to be sure, let's add TTDX and OGFX road/grass tiles.
Attachment:
BridgesTutorial07.png
BridgesTutorial07.png [ 6.06 KiB | Viewed 2192 times ]

Attachment:
BridgesTutorial08.png
BridgesTutorial08.png [ 6.06 KiB | Viewed 2192 times ]

In the next post we will begin to work on the template.


Top
 Offline Profile  
 
PostPosted: 06 Aug 2016, 14:33 
Master Mentor
User avatar

Joined: 27 Feb 2012, 22:45
Posts: 1646
Location: Canada
Beginning work on the template ...
We add grids in line with the road tiles and extend the yellow lines into the grids:
Attachment:
BridgesTutorial09.png
BridgesTutorial09.png [ 4.99 KiB | Viewed 2188 times ]

Now we fill in the space between the yellow lines and add colour to the margins:
Attachment:
BridgesTutorial10.png
BridgesTutorial10.png [ 2.52 KiB | Viewed 2188 times ]

We now have a workable template for the road bridge floor/deck.
Just to be sure, let's line them up and see what we get:
Attachment:
BridgesTutorial11.png
BridgesTutorial11.png [ 1.9 KiB | Viewed 2188 times ]


Top
 Offline Profile  
 
PostPosted: 06 Aug 2016, 20:37 
Master Mentor
User avatar

Joined: 27 Feb 2012, 22:45
Posts: 1646
Location: Canada
Similarly we create a template for a Rail bridge:
Attachment:
BridgesTutorial12.png
BridgesTutorial12.png [ 3.88 KiB | Viewed 2184 times ]


When you add colour and texture and shadows and sleepers/ties and replace the remaining light gray with transparent blue you will be able to look between the rails and see the water or whatever is below.

Monorail and MagLev are a bit different. The track is layed on a solid deck. Here we get the appropriate sprites from the game's spritesheet and overlay them with the road bridge templates:
Attachment:
BridgesTutorial13.png
BridgesTutorial13.png [ 8.86 KiB | Viewed 2184 times ]

Attachment:
BridgesTutorial14.png
BridgesTutorial14.png [ 8.27 KiB | Viewed 2184 times ]

A little graphical clean-up will rid us of the grassy bits. I'll leave that for you to do. ;)

Up next: Adding superstructure

_________________
Visit SimuSchool - Tutorials, Questions and Answers
TTDPatch Nightlies Downloads are back
Thrive


Top
 Offline Profile  
 
PostPosted: 09 Aug 2016, 23:33 
Master Mentor
User avatar

Joined: 27 Feb 2012, 22:45
Posts: 1646
Location: Canada
Alignments in bridge building is critical.
In preparation for adding superstructure let's add some dimension to what has been done.
We begin by making boxes from our tile shapes.
The boxes are 8 pixels high which is the height of a standard slope and the clearance required to allow a vehicle to pass underneath the bridge.
We then add the road bridge tiles to the boxes and assemble the boxes in yet another test to confirm alignments.
Attachment:
BridgesTutorial15.png
BridgesTutorial15.png [ 6.09 KiB | Viewed 2167 times ]

We do the same for the rail bridges, but just for fun we add a little variation. We'll make the rail bridge narrower.
We'll centre our rail boxes onto standard tile grids and assemble them for another alignment test using an OTTD flat rail tile for reference.
Attachment:
BridgesTutorial16.png
BridgesTutorial16.png [ 15.82 KiB | Viewed 2167 times ]


Now we can move on to the superstructure.

_________________
Visit SimuSchool - Tutorials, Questions and Answers
TTDPatch Nightlies Downloads are back
Thrive


Top
 Offline Profile  
 
PostPosted: 13 Aug 2016, 21:11 
Master Mentor
User avatar

Joined: 27 Feb 2012, 22:45
Posts: 1646
Location: Canada
The ramps do not support superstructure.
Only the spans do this.

student wrote:
But with only one span in X or Y, wouldn't that a very boring bridge?
Yes, it would, but remember this from the second post:
second post wrote:
Each table, 0 through 5:
Rail X direction: Back/Floor; Front; Pillars; Empty Cell;
Rail Y direction: Back/Floor; Front; Pillars; Empty Cell;
Road X direction: Back/Floor; Front; Pillars; Empty Cell;
Road Y direction: Back/Floor; Front; Pillars; Empty Cell;
Mono X direction: Back/Floor; Front; Pillars; Empty Cell;
Mono Y direction: Back/Floor; Front; Pillars; Empty Cell;
MagL X direction: Back/Floor; Front; Pillars; Empty Cell;
MagL Y direction: Back/Floor; Front; Pillars; Empty Cell;
Each bridge can have 6 (yes ... six) different spans to work with, not to mention 4 (yes ... four) road/rail types.

Note that there are two parts to a span: Back/Floor and Front
A vehicle appears in front of the back and above the floor.
That same vehicle will simultaneously appear behind the front and below whatever is attached above the front.
The following image demonstrates how the two parts are drawn by the artist and assembled by the game code:
Attachment:
BridgesTutorial17.png
BridgesTutorial17.png [ 4.1 KiB | Viewed 2152 times ]

Lets do a mockup to see it in pseudo-action:
Attachment:
BridgesTutorial18.png
BridgesTutorial18.png [ 3.74 KiB | Viewed 2152 times ]


Wait a minute! Those don't look very stable. We'd best add some pillars to support the spans and prevent disasters. We'll do that in the next post.

_________________
Visit SimuSchool - Tutorials, Questions and Answers
TTDPatch Nightlies Downloads are back
Thrive


Top
 Offline Profile  
 
PostPosted: 25 May 2018, 15:12 
Master Mentor
User avatar

Joined: 27 Feb 2012, 22:45
Posts: 1646
Location: Canada
The final pieces of the bridge are the pillars.
Each span of a bridge accommodates one pillar positioned under the near end of the span.
The absolute height of a pillar is 8 pixels so that vehicles can pass underneath the bridge.
For higher bridges the game mechanics stacks the pillars one atop the other.
There are three ways to draw a pillar:
1. A single pillar sprite (like a utility pole) towards the near side of the bridge with the game mechanics positioning the far side pillar.
2. Two pillars in one sprite with far pillar positioning turned off.
3. A pier, which is essentially one very wide pillar. Far pillar positioning is turned off.

[Graphic samples will be placed here.]

_________________
Visit SimuSchool - Tutorials, Questions and Answers
TTDPatch Nightlies Downloads are back
Thrive


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Forum lockedPost a reply Page 1 of 1   [ 9 posts ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


Status SimuscapeTerms of UseAbout Simuscape

Design by SAC © 2012-2015, Sweden • Powered by phpBB • Based on twilightBB by Daniel St. Jules