Loading

Paste #p0wjbgi2l

  1. /*
  2.  * This file is aimed to provide an example on how to code a vehicle in NML
  3.  * In this case a road vehicle is coded, other vehicle types work in a similar fashion.
  4.  * To keep the code readable, not every property or variable is documented in
  5.  * detail, refer to the vehicle-specific reference in the documentation.
  6.  * The coded vehicle is relatively simple. Apart from the minimum required,
  7.  * it has cargo-specific capacaity and graphics. For a more advanced example,
  8.  * refer to the train example.
  9.  *
  10.  * The vehicle coded here is a first-generation flatbed truck.
  11.  * It is taken from OpenGFX+ Road Vehicles, with some modifications
  12.  * to provide a better example. Original graphics are by DanMack and Zephyris,
  13.  * coding by Terkhen and planetmaker.
  14.  *
  15.  * Apart from this file, you will also need the following
  16.  * - Graphics, found in 'gfx' folder.
  17.  * - Language files, to be placed in the 'lang' folder.
  18.  *      Currently only english.lng is supplied.
  19.  */
  20.  
  21. /*
  22.  * First, define a grf block. This defines some basic properties of the grf,
  23.  * which are required for the grf to be valid and loadable. Additionally,
  24.  * user-configurable parameters are defined here also.
  25.  */
  26. grf {
  27.     /* This grf is part of NML, therefore "NML" is chosen as the first three
  28.      * characters of the GRFID. It is the fourth real grf defined as part of
  29.      * NML, therefore the last character is set to 3 as numbering is zero-based.
  30.      * Successive grfs will have 4, 5, etc., to make sure each example grf has
  31.      * a unique GRFID.
  32.      */
  33.     grfid: "NML\03";
  34.     /* GRF name and description strings are defined in the lang files */
  35.     name: string(STR_GRF_NAME);
  36.     desc: string(STR_GRF_DESC);
  37.     /* This is the first version, start numbering at 0. */
  38.     version: 0;
  39.     min_compatible_version: 0;
  40. }
  41.  
  42. /* Check for engine pool */
  43. if (!dynamic_engines) {
  44.     error(ERROR, USED_WITH, string(STR_ERROR_ENGINE_POOL));
  45. }
  46.  
  47. /* Define a cargo translation table
  48.  * All cargo types that need any special treatment must be included here
  49.  * Add cargos used in the refit mask first, as those are limited to 32 bits
  50.  * so these cargos must be within the first 32 entries */
  51. cargotable {
  52. /* Used in refit mask */
  53.     LVST, // Livestock (piece goods)
  54.     WOOL, // Wool (piece goods, covered)
  55.     SCRP, // Scrap metal (bulk)
  56.     FICR, // Fibre crops (bulk, piece goods)
  57.     PETR, // Petrol / fuel oil (liquid)
  58.     RFPR, // Refined products (liquid)
  59.  
  60. /* Not used in refit mask */
  61.     GOOD, // Goods (express)
  62.     ENSP, // Engineering supplies (express, piece goods)
  63.     FMSP, // Farm supplies (express, piece goods)
  64.     MNSP, // Manufacturing supplies (express, piece goods)
  65.     PAPR, // Paper (piece goods)
  66.     STEL, // Steel (piece goods)
  67.     VEHI, // Vehicles (piece goods, oversized)
  68.     COPR, // Copper (piece goods)
  69.     WOOD, // Wood (piece goods)
  70. }
  71.  
  72. roadtypetable {
  73.     ROAD, BLUE, YELL, RED_TEST: [RED_, BLUE, ROAD]
  74.  }
  75.  
  76. /* Sprite template for a truck */
  77. template tmpl_truck(x) {
  78.     [ 0 + x,   0,  8, 18,  -3, -10]
  79.     [ 16 + x,  0, 20, 16, -14,  -7]
  80.     [ 48 + x,  0, 28, 12, -14,  -6]
  81.     [ 96 + x,  0, 20, 16,  -6,  -7]
  82.     [ 128 + x, 0,  8, 18,  -3, -10]
  83.     [ 144 + x, 0, 20, 16, -14,  -7]
  84.     [ 176 + x, 0, 28, 12, -14,  -6]
  85.     [ 224 + x, 0, 20, 16,  -6,  -7]
  86. }
  87.  
  88. /* Define various cargo-specific graphics */
  89.  
  90. /* Paper */
  91. spriteset(flatbed_truck_1_paper_empty, "gfx/flatbed_truck_1_paper.png") { tmpl_truck(0) }
  92. spriteset(flatbed_truck_1_paper_full, "gfx/flatbed_truck_1_paper.png") { tmpl_truck(260) }
  93. spritegroup flatbed_truck_1_paper {
  94.     loaded: [flatbed_truck_1_paper_empty, flatbed_truck_1_paper_full];
  95.     loading: [flatbed_truck_1_paper_empty, flatbed_truck_1_paper_full];
  96. }
  97.  
  98. /* Steel */
  99. spriteset(flatbed_truck_1_steel_empty, "gfx/flatbed_truck_1_steel.png") { tmpl_truck(0) }
  100. spriteset(flatbed_truck_1_steel_full, "gfx/flatbed_truck_1_steel.png") { tmpl_truck(260) }
  101. spritegroup flatbed_truck_1_steel {
  102.     loaded: [flatbed_truck_1_steel_empty, flatbed_truck_1_steel_full];
  103.     loading: [flatbed_truck_1_steel_empty, flatbed_truck_1_steel_full];
  104. }
  105.  
  106. /* Wood */
  107. spriteset(flatbed_truck_1_wood_empty, "gfx/flatbed_truck_1_wood.png") { tmpl_truck(0) }
  108. spriteset(flatbed_truck_1_wood_full, "gfx/flatbed_truck_1_wood.png") { tmpl_truck(260) }
  109. spritegroup flatbed_truck_1_wood {
  110.     loaded: [flatbed_truck_1_wood_empty, flatbed_truck_1_wood_full];
  111.     loading: [flatbed_truck_1_wood_empty, flatbed_truck_1_wood_full];
  112. }
  113.  
  114. /* Copper */
  115. spriteset(flatbed_truck_1_copper_empty, "gfx/flatbed_truck_1_copper.png") { tmpl_truck(0) }
  116. spriteset(flatbed_truck_1_copper_full, "gfx/flatbed_truck_1_copper.png") { tmpl_truck(260) }
  117. spritegroup flatbed_truck_1_copper {
  118.     loaded: [flatbed_truck_1_copper_empty, flatbed_truck_1_copper_full];
  119.     loading: [flatbed_truck_1_copper_empty, flatbed_truck_1_copper_full];
  120. }
  121.  
  122. /* Goods */
  123. spriteset(flatbed_truck_1_goods_empty, "gfx/flatbed_truck_1_goods.png") { tmpl_truck(0) }
  124. spriteset(flatbed_truck_1_goods_full, "gfx/flatbed_truck_1_goods.png") { tmpl_truck(260) }
  125. spritegroup flatbed_truck_1_goods {
  126.     loaded: [flatbed_truck_1_goods_empty, flatbed_truck_1_goods_full];
  127.     loading: [flatbed_truck_1_goods_empty, flatbed_truck_1_goods_full];
  128. }
  129.  
  130. /* Decide capacity based on cargo type (cargo_capacity callback)
  131.  * cargo_type_in_veh is available in the purchase list also,
  132.  * so a separate CB for in the purchase list is not needed */
  133. switch (FEAT_ROADVEHS, SELF, flatbed_truck_1_capacity_switch, cargo_type_in_veh) {
  134.     GOOD: return 14;
  135.     ENSP: return 14;
  136.     FMSP: return 14;
  137.     MNSP: return 14;
  138.     PAPR: return 15;
  139.     PETR: return 10;
  140.     RFPR: return 10;
  141.     STEL: return 15;
  142.     VEHI: return 12;
  143.     return 20;
  144. }
  145.  
  146. /* Define the road vehicle */
  147. item(FEAT_ROADVEHS, flatbed_truck_1) {
  148.     property {
  149.         /* Properties common to all vehicle types */
  150.         name: string(STR_NAME_FLATBED_TRUCK_1);
  151.         climates_available: bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL);
  152.         road_type: ROAD;
  153.         introduction_date: date(1926,01,01);
  154.         model_life: 65;
  155.         /* retire_early not set, use default retirement behaviour */
  156.         vehicle_life: 15;
  157.         reliability_decay: 20;
  158.         refittable_cargo_classes: bitmask(CC_PIECE_GOODS, CC_EXPRESS);
  159.         non_refittable_cargo_classes: bitmask(CC_PASSENGERS, CC_REFRIGERATED);
  160.         /* Livestock, wool and fibre crops can be transported acc. cargo classes
  161.          * But we don't want that, so disable refitting for them.
  162.          * Scrap metal, petrol and refined products cannot be transported acc. cargo classes
  163.          * We do want to transport those, so enable refitting for them. */
  164.         cargo_allow_refit: [LVST, WOOL, SCRP, FICR, PETR, RFPR];
  165.         cargo_disallow_refit: []; // we allow other cargoes, if class matches
  166.         loading_speed: 5;
  167.         cost_factor: 108;
  168.         running_cost_factor: 90;
  169.         /* cargo_age_period is left at default */
  170.  
  171.         /* RV-specific properties */
  172.         sprite_id: SPRITE_ID_NEW_ROADVEH;
  173.         speed: 48 km/h;
  174.         misc_flags: bitmask(ROADVEH_FLAG_2CC);
  175.         refit_cost: 0; // Refitting is free
  176.         /* callback_flags are not set, no need to manually enable callbacks */
  177.         running_cost_base: RUNNING_COST_ROADVEH;
  178.         power: 120 hp;
  179.         weight: 9.5 ton;
  180.         /* TE and air drag coefficient is left at default */
  181.         cargo_capacity: 20; // Changed by callback
  182.         sound_effect: SOUND_BUS_START_PULL_AWAY;
  183.         /* Visual effect is left at default (no effect) */
  184.     }
  185.  
  186.     /* Define graphics for various cargo types, as well as the capacity callback */
  187.     graphics {
  188.         cargo_capacity: flatbed_truck_1_capacity_switch;
  189.         PAPR: flatbed_truck_1_paper;
  190.         STEL: flatbed_truck_1_steel;
  191.         COPR: flatbed_truck_1_copper;
  192.         WOOD: flatbed_truck_1_wood;
  193.         default: flatbed_truck_1_goods; // Default to Goods.
  194.     }
  195. }
  196.  
  197. /* Define the road vehicle */
  198. item(FEAT_ROADVEHS, flatbed_truck_2) {
  199.     property {
  200.         /* Properties common to all vehicle types */
  201.         name: string(STR_NAME_FLATBED_TRUCK_2);
  202.         climates_available: bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL);
  203.         road_type: BLUE;
  204.         introduction_date: date(1926,01,01);
  205.         model_life: 65;
  206.         /* retire_early not set, use default retirement behaviour */
  207.         vehicle_life: 15;
  208.         reliability_decay: 20;
  209.         refittable_cargo_classes: bitmask(CC_PIECE_GOODS, CC_EXPRESS);
  210.         non_refittable_cargo_classes: bitmask(CC_PASSENGERS, CC_REFRIGERATED);
  211.         /* Livestock, wool and fibre crops can be transported acc. cargo classes
  212.          * But we don't want that, so disable refitting for them.
  213.          * Scrap metal, petrol and refined products cannot be transported acc. cargo classes
  214.          * We do want to transport those, so enable refitting for them. */
  215.         cargo_allow_refit: [LVST, WOOL, SCRP, FICR, PETR, RFPR];
  216.         cargo_disallow_refit: []; // we allow other cargoes, if class matches
  217.         loading_speed: 5;
  218.         cost_factor: 108;
  219.         running_cost_factor: 90;
  220.         /* cargo_age_period is left at default */
  221.  
  222.         /* RV-specific properties */
  223.         sprite_id: SPRITE_ID_NEW_ROADVEH;
  224.         speed: 48 km/h;
  225.         misc_flags: bitmask(ROADVEH_FLAG_2CC);
  226.         refit_cost: 0; // Refitting is free
  227.         /* callback_flags are not set, no need to manually enable callbacks */
  228.         running_cost_base: RUNNING_COST_ROADVEH;
  229.         power: 120 hp;
  230.         weight: 9.5 ton;
  231.         /* TE and air drag coefficient is left at default */
  232.         cargo_capacity: 20; // Changed by callback
  233.         sound_effect: SOUND_BUS_START_PULL_AWAY;
  234.         /* Visual effect is left at default (no effect) */
  235.     }
  236.  
  237.     /* Define graphics for various cargo types, as well as the capacity callback */
  238.     graphics {
  239.         cargo_capacity: flatbed_truck_1_capacity_switch;
  240.         PAPR: flatbed_truck_1_paper;
  241.         STEL: flatbed_truck_1_steel;
  242.         COPR: flatbed_truck_1_copper;
  243.         WOOD: flatbed_truck_1_wood;
  244.         default: flatbed_truck_1_goods; // Default to Goods.
  245.     }
  246. }
  247.  
  248. /* Define the road vehicle */
  249. item(FEAT_ROADVEHS, flatbed_truck_3) {
  250.     property {
  251.         /* Properties common to all vehicle types */
  252.         name: string(STR_NAME_FLATBED_TRUCK_3);
  253.         climates_available: bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL);
  254.         road_type: RED_TEST;
  255.         introduction_date: date(1926,01,01);
  256.         model_life: 65;
  257.         /* retire_early not set, use default retirement behaviour */
  258.         vehicle_life: 15;
  259.         reliability_decay: 20;
  260.         refittable_cargo_classes: bitmask(CC_PIECE_GOODS, CC_EXPRESS);
  261.         non_refittable_cargo_classes: bitmask(CC_PASSENGERS, CC_REFRIGERATED);
  262.         /* Livestock, wool and fibre crops can be transported acc. cargo classes
  263.          * But we don't want that, so disable refitting for them.
  264.          * Scrap metal, petrol and refined products cannot be transported acc. cargo classes
  265.          * We do want to transport those, so enable refitting for them. */
  266.         cargo_allow_refit: [LVST, WOOL, SCRP, FICR, PETR, RFPR];
  267.         cargo_disallow_refit: []; // we allow other cargoes, if class matches
  268.         loading_speed: 5;
  269.         cost_factor: 108;
  270.         running_cost_factor: 90;
  271.         /* cargo_age_period is left at default */
  272.  
  273.         /* RV-specific properties */
  274.         sprite_id: SPRITE_ID_NEW_ROADVEH;
  275.         speed: 48 km/h;
  276.         misc_flags: bitmask(ROADVEH_FLAG_2CC);
  277.         refit_cost: 0; // Refitting is free
  278.         /* callback_flags are not set, no need to manually enable callbacks */
  279.         running_cost_base: RUNNING_COST_ROADVEH;
  280.         power: 120 hp;
  281.         weight: 9.5 ton;
  282.         /* TE and air drag coefficient is left at default */
  283.         cargo_capacity: 20; // Changed by callback
  284.         sound_effect: SOUND_BUS_START_PULL_AWAY;
  285.         /* Visual effect is left at default (no effect) */
  286.     }
  287.  
  288.     /* Define graphics for various cargo types, as well as the capacity callback */
  289.     graphics {
  290.         cargo_capacity: flatbed_truck_1_capacity_switch;
  291.         PAPR: flatbed_truck_1_paper;
  292.         STEL: flatbed_truck_1_steel;
  293.         COPR: flatbed_truck_1_copper;
  294.         WOOD: flatbed_truck_1_wood;
  295.         default: flatbed_truck_1_goods; // Default to Goods.
  296.     }
  297. }

Comments