Difference between revisions of "NMLTutorial/Base graphics replacement"

From TTWiki
Jump to navigationJump to search
(intermediate save)
(intermediate save)
Line 6: Line 6:
   
 
== Replace TTD sprites ==
 
== 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 [[:File:Ogfx1 base.png|here]] (choose to view the full resolution version below the thumbnail).
+
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 (OpenGFX). 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 [[:File:Ogfx1 base.png|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 <code>replace</code>. The general syntax is as follows:
 
Once you have the sprites you want to replace and know their sprite numbers, you can start writing your <code>replace</code>. The general syntax is as follows:
   
 
<pre class="pseudo">
 
<pre class="pseudo">
replace [<identifier>] (<sprite-id> [, <image-file>]) {
+
replace [<identifier>] (<sprite-id> [, <image-file>] ) {
 
<list_of_realsprites>
 
<list_of_realsprites>
 
}
 
}
Line 47: Line 47:
 
</pre>
 
</pre>
   
  +
In case you want to replace sprites of the other trg*.grf or ogfx*.grf files, you have to do that in the same way as above. Furthermore you cannot use the sprite numbers of those files directly, but you need to look up the equivalent sprite numbers of trg1(r).grf or ogfx1_base.grf. In most cases you can easily find the equivalents just by comparing the type of sprites. There also used to be a calculator for this, but I cannot find that any more.
== Replace OpenGFX sprites ==
 
   
 
== Replace OpenTTD sprites ==
  +
Replacing sprites that were not originally in TTD works in a similar way, but slightly different. A <code>replacenew</code> block replaces the sprites supplied by openttd.grf. The general syntax is as follows:
   
  +
<pre class="pseudo">
  +
replacenew [<identifier>] (<type> [, <image-file> [, <offset>] ] ) {
  +
<list_of_realsprites>
  +
}
  +
</pre>
  +
  +
Instead of a sprite number you now have to specify the <code><type></code> type of sprites to replace. The available types can be looked up in the [http://newgrf-specs.tt-wiki.net/wiki/NML:Replace_new_sprites NML documentation].
  +
  +
For some types you need to provide exactly as much sprites as indicated in the documentation. If you don't want to provide all sprites of the type, then you're allowed to do that in most cases. This is where the <code><offset></code> comes in handy. Say you only want to replace the tenth and eleventh sprite of a certain type, then first of all you only provide two realsprites inside the block and second of all set the <code><offset></code> to in this case 9. Counting from 0, this will replace just the tenth and eleventh sprite. If there are gaps, simply use more than one <code>replacenew</code> block.
  +
  +
Also here you may make a climate distinction via <code>if</code>-statements, as explained above for the <code>replace</code> block.
   
   

Revision as of 16:05, 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 (OpenGFX). 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)
	}
}

In case you want to replace sprites of the other trg*.grf or ogfx*.grf files, you have to do that in the same way as above. Furthermore you cannot use the sprite numbers of those files directly, but you need to look up the equivalent sprite numbers of trg1(r).grf or ogfx1_base.grf. In most cases you can easily find the equivalents just by comparing the type of sprites. There also used to be a calculator for this, but I cannot find that any more.

Replace OpenTTD sprites

Replacing sprites that were not originally in TTD works in a similar way, but slightly different. A replacenew block replaces the sprites supplied by openttd.grf. The general syntax is as follows:

replacenew [<identifier>] (<type> [, <image-file> [, <offset>] ] ) {
	<list_of_realsprites>
}

Instead of a sprite number you now have to specify the <type> type of sprites to replace. The available types can be looked up in the NML documentation.

For some types you need to provide exactly as much sprites as indicated in the documentation. If you don't want to provide all sprites of the type, then you're allowed to do that in most cases. This is where the <offset> comes in handy. Say you only want to replace the tenth and eleventh sprite of a certain type, then first of all you only provide two realsprites inside the block and second of all set the <offset> to in this case 9. Counting from 0, this will replace just the tenth and eleventh sprite. If there are gaps, simply use more than one replacenew block.

Also here you may make a climate distinction via if-statements, as explained above for the replace block.




NML Tutorial: Base graphics replacement