*DISCLAIMER*There are many ways (and probably better ways) to draw, code and compile a railtype-GRF, I do NOT claim that my way is the best or simplest or tidiest, but it works for me and hopefully also for others.
*/DISCLAIMER*Discussion-thread can be found here:
http://www.simuscape.net/simutalk/viewtopic.php?f=84&t=899A very kind gentleman called GarryG has helped me out with trying to understand railtypes.
This now has come so far that I have been able to make templates for graphics, NML-code and a language-file that I want to share with the community:
Latest version is: Version 004Attachment:
File comment: Version 004
RAILTYPE_TEMPLATES_v004.rar [599.88 KiB]
Downloaded 459 times
It also includes a GRF for testing
In the gfx-folder you will find graphics-templates for 4 railtypes:
RTU1 (Rail Type Unelectrified 1)
RTU2 (Rail Type Unelectrified 2)
RTE1 (Rail Type Electrified 1)
RTE2 (Rail Type Electrified 2)
These all have in their own gfx-subfolder custom graphics for:
- Tracks (regular tracks, tracks for tunnels, tracks for bridges)
- Catenary (wires and pylons separately,
only in electrified railtype gfx-folder)
- Fences
- Depots
- Signals (semaphores and light-signals separately)
- Level Crossings
- Tunnels
- Gui
If needed, also with templates for the snow-versions (snow not included
)
Each graphic-file has the name of the railtype in it, so when adding more railtypes you can copy/paste the graphics, but make sure you rename the folder and the names of the graphic-files accordingly!!In the gfx-mainfolder you will also find two other graphics-files:
- nofences.png (needed for nofences-parameter)
- notracklesstunnels.png (needed to remove the trackless tunnelgraphics from OpenGFX-extra, that way nothing strange pokes out for example when you draw a custom tunnel that starts far into the slope)
The code is made up basically from 3 sections:
*Section-1Code:
/**********************************************
* DEFINE THE NEWGRF AND PARAMETERS
**********************************************/
In here you have to change the grf-ID ofcourse
It also includes the parameters, in this case I added 4 that I think can be universally used:
- param_fences (To disable fences when "all details" is turned on in the game-settings
- param_original_signals (to disable custom signals, vanilla signals will then be used, or custom signals provided by a signals-replacement-grf)
- param_original_catenarypylons (to disable custom pylons separately from the wires, vanilla pylons will then be used, or custom pylons provided by a catenary-replacement-grf)
- param_original_catenarywires (to disable custom wires separately from the pylons, vanilla wires will then be used, or custom wires provided by a catenary-replacement-grf)
If needed, more parameters can be placed here.
No other changes have to be made to this section anymore then when adding more railtypes to the GRF.*Section-2Code:
/**********************************************
* GENERAL TEMPLATES
**********************************************/
In here all the position, size and offsets information of the graphics can be found.
The only things that may need a change are the paths to:
- nofences.png
- notracklesstunnels.png
Depending on the way you have setup your NML-compiler and how it finds its way to the gfx-folder.
No other paths to graphics are defined in this section.
It is all optimised for the graphics-templates, so no other changes have to be made to the code in this section. I have made the graphics-templates in such a way that there should be enough room for larger/smaller things and you can then get the actual placement by moving around the item in the graphic (rather than making offset-changes in the code).
This way I have created universal position/size/offset-information-templates in this section, that can be used for (and will be referenced to from) every railtype you add.
*Section-3Code:
/**********************************************
* RAILTYPE SECTION (RTU1, RTU2, RTE1 and RTE2)
**********************************************/
The fun part
Here we define everything for the actual railtypes.
These sections are what you can copy/paste to add a new railtype.
The railtypes show up in the order you have put them in the code (
Except for the ones with label RAIL and ELRL, more on that later)
Changes that must be made:
- The name of the railtype (so RTU1, RTU2, etc) to the name you want to give to the railtype
- The paths to the graphicsfiles (Depending on the way you have setup your NML-compiler and how it finds its way to the gfx-folder.)
Optional changes:
- Changes to the Railtype Properties, like speedlimits, costs, etc.
More info about those can be found here:
https://newgrf-specs.tt-wiki.net/wiki/NML:Railtypes#Railtype_propertiesFinally, for this section, something important!!
Label RAIL and ELRLI am not too certain about this all, but I will try to explain it as I understand it (and hopefully I am right, feel free to correct me)If you are making a stand-alone railtype-set that is usable with the vanilla-trains and/or other major trainsets, then for the
first unelectrified railtype you make, you have to set the Label in the Railtype Properties to
RAIL and for the
first electrified railtype you make, you have to set the Label in the Railtype Properties to
ELRL.
That way the trains should show up in the depots so they can be bought.
So in this case:
RTU1 has label RAIL
RTE1 has label ELRL
The two others have their own label, that is the same to their name (RTU2, RTE2).
These labels we are going to need to also get trains buyable in their depots and also allow that trains can run over the various tracktypes.
You do that this way:
- In the section of the first unelectrified railtype (RTU1, with label RAIL) you add powered_railtype_list to the Railtype Properties, like this:
Code:
powered_railtype_list: ["RTU2", "RTE2"];
Now the unelectrified trains can also be bought in railtype RTU2 and RTE2.
And the unelectrified trains can run on ALL tracktypes (also RTE1, as that is ELRL and is standard compatible with RAIL)
For each new railtype you add (be it unelectrified or electrified), you have to add that label to the powered-railtype-list of RTU1!!- In the section of the first electrified railtype (RTE1, with label ELRL) you add powered_railtype_list to the Railtype Properties, like this:
Code:
powered_railtype_list: ["RTE2"];
Now the electrified trains can also be bought in railtype RTE2 (along the unelectrified ones).
And the electrified trains can run on all of the electrified tracktypes.
For each new electrified railtype you add, you have to add that label to the powered-railtype-list of RTE1!!It all shows up in the game as this:
Attachment:
Example510.png [ 5.73 KiB | Viewed 8585 times ]
RTU1 is always the first one (as it replaces the vanilla unelectrified tracks)
RTE1 is always the second one (as it replaces the vanilla electrified tracks)
All other railtypes will show up in the order they are coded in the code.
(you could also add the sort_order property to the Railtype Properties to change that order, but I want to keep it simple for this
)
So, if you want to add more railtypes, then copy/paste (but rename ofcourse) the codeblocks and graphics of RTU2 for unelectrified and RTE2 for electrified.
And make sure you
ALWAYS add the labels of those to the powered_railtype_list of the first unelectrified tracktype (label RAIL), so all unelectrified trains can be bought everywhere and run on all tracks.
And in case the tracktype is electrified
also add those in the powered_railtype_list of the first electrified tracktype (label ELRL), so all electrified trains can be bought in all electrified depots and those trains can run on all electrified tracks.
There are some other properties you can set in the Railtype Properties, like:
Code:
compatible_railtype_list
alternative_railtype_list
To be honest, I dont really know what those do or can be used for.
I believe they are handy for example if you have various gauges or electrical power in your trackset.
Also I think if you want to introduce railtype specific vehicles (like in the Metro, Wired or Pipe-grfs) you need these.
This code-template is aimed at regular tracks only, so I am not using those, however if anyone can explain these clearly, then that would be appreciated
*Some remarks regarding Tunnels:
- In this case all tunnels are custom tunnels and basically that means that you dont have to draw anything in the TunnelTrack_XXXX.png and the TunnelTrack_XXXX_snow.png
As these are now not used, the track-graphics are already provided in your custom tunnel graphics anyway.
- If you dont want to work with custom tunnels and want to use the vanilla tunnels (or tunnels from a tunnel-replacement-grf), but with your own tracks, then you do have to draw those in TunnelTrack_XXXX.png and the TunnelTrack_XXXX_snow.png
You then also have to make the following changes to the code:
* In the railtype-section of that particular railtype (so XXXX is ofcourse the name of that railtype), replace:
Code:
//*Custom Tunnels
spriteset(tunnel_tracks_XXXX, "RAILTYPE_TEMPLATES/gfx/XXXX/Tunnel_XXXX.png") {
tmpl_tunnel_overlaytracks()
}
spriteset(tunnel_tracks_XXXX_snow, "RAILTYPE_TEMPLATES/gfx/XXXX/Tunnel_XXXX_snow.png") {
tmpl_tunnel_overlaytracks()
}
spriteset(tunnel_overlay_XXXX, "RAILTYPE_TEMPLATES/gfx/XXXX/Tunnel_XXXX.png") {
tmpl_tunnel_overlays()
}
spriteset(tunnel_overlay_XXXX_snow, "RAILTYPE_TEMPLATES/gfx/XXXX/Tunnel_XXXX_snow.png") {
tmpl_tunnel_overlays()
}
switch(FEAT_RAILTYPES, SELF, tunnel_track_XXXX_switch, terrain_type) {
TILETYPE_SNOW: tunnel_tracks_XXXX_snow;
tunnel_tracks_XXXX;
}
switch(FEAT_RAILTYPES, SELF, tunnel_overlay_XXXX_switch, terrain_type) {
TILETYPE_SNOW: tunnel_overlay_XXXX_snow;
tunnel_overlay_XXXX;
}
with
Code:
spriteset(tunnel_tracks_XXXX, "RAILTYPE_TEMPLATES/gfx/XXXX/TunnelTrack_XXXX.png") {
template_tunneltracks()
}
spriteset(tunnel_tracks_XXXX_snow, "RAILTYPE_TEMPLATES/gfx/XXXX/TunnelTrack_XXXX_snow.png") {
template_tunneltracks()
}
switch(FEAT_RAILTYPES, SELF, tunnel_track_XXXX_switch, terrain_type) {
TILETYPE_SNOW: tunnel_tracks_XXXX_snow;
tunnel_tracks_XXXX;
}
And delete:
Code:
tunnel_overlay: tunnel_overlay_XXXX_switch;
Further down in the graphics-section of the particular railtype.
- In the custom tunnelgraphics you may notice that I also have drawn part of the far wall into the section with the roof (a small red triangle shape).
This is because you can get some graphical issues if you place something on the slope next to the tunnels, as the foundations then can be partly visible.
Drawing in the far end in the roof-section eliminates that issue (also its far enough away so trains wont get obstructed).
It all depends on your tunneldesign, so just draw a custom tunnel, see if it gets issues with foundations if something is placed on the slope next to it, if so, draw what is needed to cover up the foundations in the roof-section.
- Depending on your tunnel-design the catenary-wires may be too long or too short.
In that case dont forget to make them shorter/longer in the wire-graphics.png
Those have separate graphics for tunnelwires.
*A remark about the Underlay-graphics:
- I have kept 5 tiles transparent blue. Those can be used to draw in ground for under switches (with gravel for example).
The shapes normally used for that are drawn underneath those tiles (the lightgreen colored ones), so its stays clear for what switch, what groundtile is used.
*Remarks regarding catenarypylon-graphics:
- The one with an arrow going down, under it is the pylon that is on the far side of a horizontal track
- The one with an arrow going up, under it is the pylon that is on the near side of a horizontal track
*Remarks regarding fences:
- GarryG has made the fence-graphics wider and added a dirt road, templates can be found here:
http://www.simuscape.net/simutalk/viewtopic.php?f=84&t=899#p13552*Changelog:
Version 002- Changes to graphics-templates and code for two different fences at either side of the track (each side also has its own offsets in the code, so they all can be moved around separately).
Works only for (patched) versions of OpenTTD r27343 and newer!- Made easily customizable graphics (full-tile ones) that replace the base tunnelgraphics supplied by OpenGFX-extra (in place of the single blue pixel one).
With only slopes at the sides, but can be altered to fit best with the general design of your custom tunnels.
Fully climate-aware, also with extra parameter for Alpine-tunnels.
Next to the graphics I also have put in the various landscape-tiles and also the original base-tunnel-graphics, so they are easy to find if needed
If you dont want to use these graphics at all, then just make all of the 6 spritegroups transparent blue boxes. But make sure you then supply full-tile graphics in your custom tunnel graphics!!
Version 003- Better graphics-templates for tracks on far slopes and far bridge-ramps (old version looked a bit wobbly, these are nice and straight now)
Version 004- Signals/Semaphores did not change appearance when train approached/passes.
*CREDITS:
- GarryG, for his great help in making me understand railtypes a bit more
- Developers of NU-tracks (Looking at their code and graphics helped a lot)
- Developers of Dutch-tracks (Looking at their code and graphics helped a lot)
- Developers of WIRED-tracks (Looking at their code and graphics helped a lot)
- Developers of Metro-trackset (Looking at their code and graphics helped a lot)
- Developers of OpenGFX-extra (Original base tunnel graphics)
- Developers of OpenGFX+Landscape (Original landscape graphics)
Well, thats it
Hope this helps for creating nice railtypes, remarks/suggestions/additions/corrections are very welcome