NMLTutorial/Tram articulation

From TTWiki
< NMLTutorial
Revision as of 18:47, 24 August 2011 by FooBar (talk | contribs) (first page contents, intermediate save, will continue later)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

The example used here is the HTM 4001 from the Dutch Tram Set. The original code and graphics for this are by FooBar. Code and graphics are both licensed according to the GPL v2 or later. The code has been modified for the purpose of this tutorial.

This continues the first part of the tram example. Here we'll define the tram's item block and make it articulated.


Item block

The item block is not that different from that of a regular road vehicle. A tram is still a road vehicle, so the http://newgrf-specs.tt-wiki.net/wiki/NML:Features feature] will again be FEAT_ROADVEHS. Give the item an identifier (here item_tram_htm_4001), add a property sub-block and fill it like you did with the road vehicle.

One important thing to know is that the cargo_capacity property applies to a single part of the articulated vehicle. So the total capacity will be that what you have set for cargo_capacity multiplied by the number of vehicle parts. This means that the capacity can only be a multiple of the number of vehicle parts. The other properties apply to the vehicle as a whole.

Again you need to look all the available properties up in the NML Documentation and whey you do you may arrive at an item block something like this:

item (FEAT_ROADVEHS, item_tram_htm_4001) {
    property {
        name:                        string(STR_NAME_HTM_4001);
        introduction_date:           date(2006,1,1);
        model_life:                  VEHICLE_NEVER_EXPIRES;
        retire_early:                0;
        vehicle_life:                25;
        loading_speed:               25;
        cost_factor:                 224;
        running_cost_factor:         112;
        speed:                       81 km/h;
        power:                       966 hp;
        weight:                      58 ton;
        cargo_capacity:              (38*2+26)/3;
        tractive_effort_coefficient: 0.5;
        air_drag_coefficient:        0;
        //sound_effect:              no sound
        //visual_effect:             use default (none)
        
        //callback_flags:            no need to set this
        reliability_decay:           20;
        climates_available:          ALL_CLIMATES;
        refittable_cargo_classes:    bitmask(CC_PASSENGERS);
        sprite_id:                   SPRITE_ID_NEW_ROADVEH; //use custom sprites
        misc_flags:                  bitmask(ROADVEH_FLAG_TRAM); //make this a tram
        refit_cost:                  0; //refits are free
        running_cost_base:           RUNNING_COST_ROADVEH;
    }
    
    graphics {
        //this will be added next
    }
}


Adding callbacks

As you may have guessed, making the vehicle articulated has something to do with callbacks. These will be referenced from the graphics block within the item block. We'll also be adding a second callback that makes the capacity different for each vehicle part. The middle part of the vehicle (as you will see on the next page) is somewhat shorter and thus can carry less passengers. We can show this in the vehicle details window using a callback.

Articulated vehicle callback

Cargo capacity callback

Total code so far

If you put everything in the correct order, you should now have this:


Because we haven't added graphics, you cannot compile this into a NewGRF just yet. So we'll look into the graphics next.


NML Tutorial: Tram articulation