Loading

Paste #p9aqp8gte

  1. /*
  2.  * This file is aimed to provide an example on how to code a roadtype in NML.
  3.  * To keep the code readable, not every property or variable is documented in
  4.  * detail, refer to the object-specific reference in the documentation.
  5.  *
  6.  
  7. /**********************************************
  8.  * Header, containing some general stuff:
  9.  **********************************************/
  10.  
  11.  /*
  12.  * First, define a grf block. This defines some basic properties of the grf,
  13.  * which are required for the grf to be valid and loadable.
  14.  */
  15. grf {
  16.     /* This grf is part of NML, therefore "NML" is chosen as the first three
  17.      * characters of the GRFID. It is the fifth real grf defined as part of
  18.      * NML, therefore the last character is set to 4. Successive grfs will
  19.      * have 5, 6, etc. there, to make sure each example grf has a unique GRFID.
  20.      */
  21.     grfid : "NML\04";
  22.     name : string(STR_GRF_NAME);
  23.     desc : string(STR_GRF_DESCRIPTION);
  24.     version : 0; // must be numeric
  25.     min_compatible_version : 0;
  26. }
  27.  
  28. /* Default ground tile template (re-use as needed) */
  29. template ground_tile(x, y) { [x, y, 64, 31, -31, 0] }
  30.  
  31. /**********************************************
  32.  * Road underlays (tracks + ballast):
  33.  **********************************************/
  34. /* Underlays (single track bits with ballast)\
  35.  * Used for bridge surfaces also, therefore the template is split */
  36. template tmpl_underlay_straight() {
  37.     ground_tile(75, 0)
  38.     ground_tile( 0, 0)
  39. }
  40. template tmpl_underlay_slope() {
  41.     [ 75, 40, 64,39, -31, -8]
  42.     [150, 40, 64,23, -31,  0]
  43.     [225, 40, 64,23, -31,  0]
  44.     [300, 40, 64,39, -30, -9]
  45. }
  46. template tmpl_underlay_diagonal() {
  47.     ground_tile(150,  0)
  48.     ground_tile(225,  0)
  49.     ground_tile(  0, 40)
  50.     ground_tile(300,  0)
  51. }
  52.  
  53. template tmpl_underlay_roadtypes() {
  54.     tmpl_underlay_straight()
  55.     tmpl_underlay_diagonal()
  56.     tmpl_underlay_slope()
  57.  
  58.     /* X-crossing */
  59.     ground_tile(0, 120)
  60.  
  61.     /* underlay for crossings w/o tracks */
  62.     ground_tile(  0, 80)
  63.     ground_tile(225, 80)
  64.     ground_tile(150, 80)
  65.     ground_tile( 75, 80)
  66.     ground_tile(300, 80)
  67. }
  68. /* Spriteset containing all underlays */
  69. spriteset(track_underlays, "gfx/rails_overlays.png") {
  70.     tmpl_underlay_roadtypes()
  71. }
  72.  
  73. /**********************************************
  74.  * Track overlays (tracks without ballast):
  75.  **********************************************/
  76.  
  77. /* Template for overlays; 2x straight track, 4x diagonal track, 4x slope */
  78. template tmpl_overlay_roadtypes() {
  79.     [  0,155, 40,21, -19,  5]
  80.     [ 50,155, 40,21, -19,  5]
  81.  
  82.     [100,155, 40, 7, -19,  4]
  83.     [150,155, 40, 7, -21, 20]
  84.     [200,155, 12,19,  11,  6]
  85.     [250,155, 12,19, -21,  6]
  86.  
  87.     [  0,195, 64,39, -33, -8]
  88.     [ 75,195, 64,23, -31,  0]
  89.     [150,195, 64,23, -31,  0]
  90.     [225,195, 64,39, -32, -9]
  91. }
  92. /* Spriteset for overlays */
  93. spriteset(track_overlays, "gfx/rails_overlays.png") {
  94.  tmpl_overlay_roadtypes()
  95. }
  96.  
  97. /**********************************************
  98.  * Tracks in tunnels:
  99.  **********************************************/
  100. /* Template for tunnel track overlays */
  101. template tmpl_tunnel_tracks() {
  102.     ground_tile(75,  0)
  103.     ground_tile( 0,  0)
  104.     ground_tile(75, 50)
  105.     ground_tile( 0, 50)
  106. }
  107. spriteset(tunnel_overlays, "gfx/tunnel_track.png") {
  108.     tmpl_tunnel_tracks()
  109. }
  110.  
  111. /**********************************************
  112.  * Depots:
  113.  **********************************************/
  114. /* Template for depot sprites */
  115. template tmpl_depot() {
  116.     [200, 10, 16,  8,  17,   7]
  117.     [118,  8, 64, 47,  -9, -31]
  118.     [  0, 10, 16,  8, -31,   7]
  119.     [ 37,  8, 64, 47, -53, -31]
  120.     [ 37, 63, 64, 47, -53, -31]
  121.     [118, 63, 64, 47,  -9, -31]
  122. }
  123.  
  124. /* Depots */
  125. spriteset(depot_normal_road, "gfx/depot_normal.png") {
  126.     tmpl_depot()
  127. }
  128.  
  129.  
  130. /**********************************************
  131.  * Bridge surfaces:
  132.  **********************************************/
  133. /* Bridge surface, uses the same sprites as track underlays, but in a different order */
  134. template tmpl_bridges_underlay() {
  135.     tmpl_underlay_straight()
  136.     tmpl_underlay_slope()
  137.     tmpl_underlay_diagonal()
  138. }
  139. /* Spriteset for bridge surfaces */
  140. spriteset(bridge_underlay, "gfx/rails_overlays.png") {
  141.     tmpl_bridges_underlay()
  142. }
  143.  
  144. /**********************************************
  145.  * GUI sprites:
  146.  **********************************************/
  147.  
  148. /* Template for a single icon sprite */
  149. template tmpl_gui_icon(x, y) {
  150.     [x, y, 20, 20, 0, 0]
  151. }
  152.  
  153. /* Template for a single cursor sprite */
  154. template tmpl_gui_cursor(x, y) {
  155.     [x, y, 32, 32, 0, 0]
  156. }
  157. /* Template for all the GUI sprites (8 icons + 8 cursors) */
  158. template tmpl_gui() {
  159.     tmpl_gui_icon(  0, 0)
  160.     tmpl_gui_icon( 25, 0)
  161.     tmpl_gui_icon( 50, 0)
  162.     tmpl_gui_icon( 75, 0)
  163.     tmpl_gui_icon(100, 0)
  164.     tmpl_gui_icon(125, 0)
  165.     tmpl_gui_icon(150, 0)
  166.     tmpl_gui_icon(175, 0)
  167.  
  168.     tmpl_gui_cursor(200, 0)
  169.     tmpl_gui_cursor(250, 0)
  170.     tmpl_gui_cursor(300, 0)
  171.     tmpl_gui_cursor(350, 0)
  172.     tmpl_gui_cursor(400, 0)
  173.     tmpl_gui_cursor(450, 0)
  174.     tmpl_gui_cursor(500, 0)
  175.     tmpl_gui_cursor(550, 0)
  176. }
  177.  
  178. /* Spritesets for the normal and electric GUI */
  179. spriteset(gui_normal, "gfx/gui_rail.png") {
  180.     tmpl_gui()
  181. }
  182.  
  183. /**********************************************
  184.  * Roadtype definitions:
  185.  **********************************************/
  186.  
  187. /* Define the normal roads */
  188. item(FEAT_ROADTYPES, road) {
  189.     /* Set only the most essential properties,
  190.      * Few compatible roadtypes are defined as there are no other sets out there yet */
  191.     property {
  192.         name: string(STR_ROAD_NAME);
  193.         label: "ROAD"; // Let this roadtype replace the default normal roads
  194.         compatible_roadtype_list: ["ROAD"];
  195.         powered_roadtype_list: ["ROAD"];
  196.     }
  197.  
  198.     /* Associate graphics with this roadtype */
  199.     graphics {
  200.         track_overlay: track_overlays;
  201.         underlay: track_underlays;
  202.         tunnels: tunnel_overlays;
  203.         depots: depot_normal_road;
  204.         bridge_surfaces: bridge_underlay;
  205.         gui: gui_normal;
  206.         /* Catenary is not not implemented here, use the default */
  207.     }
  208. }
  209.  
  210.  
  211. /* Define an additional roadtype */
  212. item(FEAT_ROADTYPES, wolf_road) {
  213.     /* Set only the most essential properties,
  214.      * Few compatible roadtypes are defined as there are no other sets out there yet */
  215.     property {
  216.         name: string(STR_ROAD_NAME);
  217.         label: "WOLF"; // Let this roadtype replace the default normal roads
  218.         compatible_roadtype_list: ["ROAD"];
  219.         powered_roadtype_list: ["WOLF"];
  220.         roadtype_flags: bitmask(ROADTYPE_FLAG_CATENARY);
  221.     }
  222.  
  223.     /* Associate graphics with this roadtype */
  224.     graphics {
  225.         track_overlay: track_overlays;
  226.         underlay: track_underlays;
  227.         tunnels: tunnel_overlays;
  228.         depots: depot_normal_road;
  229.         bridge_surfaces: bridge_underlay;
  230.         gui: gui_normal;
  231.         /* Catenary is not not implemented here, use the default */
  232.     }
  233. }

Comments