Difference between revisions of "NMLTutorial/Base graphics replacement"
(intermediate save) |
(intermediate save) |
||
Line 21: | Line 21: | ||
=== Climates other than temperate === |
=== Climates other than temperate === |
||
+ | The previous method will provide replacement sprites for all climates at the same time. If you want to provide different sprites for each climate, you'll have to write different <code>replace</code> blocks for each climate. Each of these climate specific blocks are guarded by <code>if</code>-statements as [[NMLTutorial/Version check|introduced earlier]]. In the <code>if</code>-statement you will test the active climate, using the <code>climate</code> [http://newgrf-specs.tt-wiki.net/wiki/NML:General general variable]. Depending on the climate, this variable is equal to one of the following: <code>CLIMATE_TEMPERATE</code>, <code>CLIMATE_ARCTIC</code>, <code>CLIMATE_TROPICAL</code> or <code>CLIMATE_TOYLAND</code>. |
||
+ | This will allow you to write something like the following: |
||
+ | <pre class="example"> |
||
+ | if (climate == CLIMATE_ARCTIC) { |
||
+ | replace replace_roads (1332 , "gfx/roads_arctic.png) { |
||
+ | template_roads(0,0) |
||
+ | } |
||
+ | } |
||
+ | else if (climate == CLIMATE_TROPICAL) { |
||
+ | replace replace_roads (1332 , "gfx/roads_tropical.png) { |
||
+ | template_roads(0,0) |
||
+ | } |
||
+ | } |
||
+ | else if (climate == CLIMATE_TOYLAND) { |
||
+ | replace replace_roads (1332 , "gfx/roads_toyland.png) { |
||
+ | template_roads(0,0) |
||
+ | } |
||
+ | } |
||
+ | else { //in all other cases the climate will be temperate, so we need not test this |
||
+ | replace replace_roads (1332 , "gfx/roads_temperate.png) { |
||
+ | template_roads(0,0) |
||
+ | } |
||
+ | } |
||
+ | </pre> |
||
== Replace OpenGFX sprites == |
== Replace OpenGFX sprites == |
Revision as of 15:48, 26 June 2012
A base graphics set provides the graphics you see when you have no NewGRFs loaded. If you don't want to add any new elements to the game, you can easily replace just these graphics via NewGRF.
There are to distinct types of base graphis: those originating from TTD and those that were added later to TTDPatch and OpenTTD. The first type is replaced by means of the replace
block, the latter by means of the replacenew
block. The way these blocks work are similar to the spriteset block.
Replace TTD sprites
And by this we mean the graphics that originally were in TTD. If you use OpenGFX, this will of course replace OpenGFX sprites and not TTD sprites. But in either case we mean replacements of the sprites in trg1(r).grf (TTD) or ogfx1_base.grf. It's useful to have a decode (grfcodec) of either of those grfs available to look up the sprite numbers. If you don't have that, you can find one here (choose to view the full resolution version below the thumbnail).
Once you have the sprites you want to replace and know their sprite numbers, you can start writing your replace
. The general syntax is as follows:
replace [<identifier>] (<sprite-id> [, <image-file>]) { <list_of_realsprites> }
The <identifier>
is something you choose yourself. It's useful to prefix it with replace_ to avoid confusion with other identifiers in your code. It's optional if you only want to replace regular 8 bit sprites, but required if you also want to provide 32 bit sprites and/or sprites for different zoom levels. The <sprite-id>
is the sprite number of the first sprite you want to replace. You can then place all consecutive replacement sprites in this block. As soon as there is a gap, you start a new replace
block. The <image-file>
is again optional. Like with a spriteset
you can either provide a single filename for all sprites inside the block, or omit the filename here and specify the filename for each realsprite individually.
The <list_of_realsprites>
is the same as for spriteset blocks.
Climates other than temperate
The previous method will provide replacement sprites for all climates at the same time. If you want to provide different sprites for each climate, you'll have to write different replace
blocks for each climate. Each of these climate specific blocks are guarded by if
-statements as introduced earlier. In the if
-statement you will test the active climate, using the climate
general variable. Depending on the climate, this variable is equal to one of the following: CLIMATE_TEMPERATE
, CLIMATE_ARCTIC
, CLIMATE_TROPICAL
or CLIMATE_TOYLAND
.
This will allow you to write something like the following:
if (climate == CLIMATE_ARCTIC) { replace replace_roads (1332 , "gfx/roads_arctic.png) { template_roads(0,0) } } else if (climate == CLIMATE_TROPICAL) { replace replace_roads (1332 , "gfx/roads_tropical.png) { template_roads(0,0) } } else if (climate == CLIMATE_TOYLAND) { replace replace_roads (1332 , "gfx/roads_toyland.png) { template_roads(0,0) } } else { //in all other cases the climate will be temperate, so we need not test this replace replace_roads (1332 , "gfx/roads_temperate.png) { template_roads(0,0) } }
Replace OpenGFX sprites
NML Tutorial: Base graphics replacement