Beginner in need of help

Discuss, get help with, or post new graphics for TTDPatch and OpenTTD, using the NewGRF system, here. Graphics for plain TTD also acceptable here.

Moderator: Graphics Moderators

Post Reply
Gafigglethorp
Engineer
Engineer
Posts: 4
Joined: 23 Apr 2017 16:11

Beginner in need of help

Post by Gafigglethorp »

So I've taken to doing my first train NewGRF. But it seems somewhere down the road I screwed up the templates.

The graphics I'm using don't fit into any of the standard templates from the tutorial I'm using, so I've managed to point to some non-existent coordinates, with NML giving me this:

Code: Select all

ERROR: "BR_415.nml", line 23: Read beyond bounds of image file 'gfx/Network_SouthEast_ BR_Class_415.png'
Included from: "BR_415.nml", line 32
Included from: "BR_415.nml", line 51
Included from: "BR_415.nml", line 51
Here is the code of my GRF, and I've attached the sprites (credit to Gwyd for them). Any help would be much appreciated.
[+] Spoiler

Code: Select all

/* Define grf */
grf {
    grfid: "MBG\01";
    /* GRF name and description strings are defined in the lang files */
    name: string(STR_GRF_NAME);
    desc: string(STR_GRF_DESC);
    /* This is the first version, start numbering at 0. */
    version: 0;
    min_compatible_version: 0;
}

/* Define a rail type table,
 * this allows referring to railtypes
 * irrespective of the grfs loaded.
 */
railtypetable {
    RAIL, ELRL, MONO, MGLV,
}

/* Basic template for 4 vehicle views */
template tmpl_vehicle_basic(x, y) {
    // arguments x, y: coordinates of top-left corner of first sprite
    [x,      y,  8, 24,  -3, -12] //xpos ypos xsize ysize xrel yrel
    [x +  9, y, 26, 22, -14, -12]
    [x + 37, y, 32, 13, -16, -12]
    [x + 71, y, 26, 22,  -6, -12]
}

/* Template for a vehicle with only 4 views (symmetric) */
template tmpl_vehicle_4_views(num) {
    // argument num: Index in the graphics file, assuming vertical ordering of vehicles
    tmpl_vehicle_basic(1, 1 + 26 * num)
}

/* Template for a vehicle with 8 views (non-symmetric) */
template tmpl_vehicle_8_views(num, reversed) {
    // argument num: Index in the graphics file, assuming vertical ordering of vehicles
    // argument reversed: Reverse visible orientation of vehicle, if set to 1
    tmpl_vehicle_basic(reversed ? 100 : 1, 1 + 26 * num)
    tmpl_vehicle_basic(reversed ? 1 : 100, 1 + 26 * num)
}

/* Template for a single vehicle sprite */
template tmpl_vehicle_single(num, xsize, ysize, xoff, yoff) {
    [1, 1 + 26 * num, xsize, ysize, xoff, yoff]
}

/* Define the spritesets, these allow referring to these sprites later on */
spriteset (set_br415_nse_front, "gfx/Network_SouthEast_ BR_Class_415.png") { tmpl_vehicle_8_views(0, 0) }
spriteset (set_br415_nse_rear,  "gfx/Network_SouthEast_ BR_Class_415.png") { tmpl_vehicle_8_views(1, 1) }
spriteset (set_br415_nse_middle_1, "gfx/Network_SouthEast_ BR_Class_415.png") { tmpl_vehicle_4_views(4)    }
spriteset (set_br415_nse_middle_2, "gfx/Network_SouthEast_ BR_Class_415.png") { tmpl_vehicle_4_views(4)    }
spriteset (set_br415_nse_invisible,     "gfx/Network_SouthEast_ BR_Class_415.png") { tmpl_vehicle_single(6,  1,  1,   0,   0) }

/* Choose between front, middle and back parts */
switch(FEAT_TRAINS, SELF, sw_br415_nse_graphics, position_in_consist % 4) {
    0:      set_br415_nse_front;
    1:      set_br415_nse_middle_1;
    2:      set_br415_nse_middle_2;
	3:      set_br415_nse_rear;
}

/* --- Articulated part callback  --- */
switch(FEAT_TRAINS, SELF, sw_br415_nse_articulated_part, extra_callback_info1) {
    /* Add three articulated parts, for a total of four */
    1 .. 3: return item_br415_nse;
    return CB_RESULT_NO_MORE_ARTICULATED_PARTS;
}

/* --- Start/stop callback  --- */
switch(FEAT_TRAINS, SELF, sw_br415_nse_start_stop, num_vehs_in_consist) {
    /* Vehicles may be coupled to a maximum of 2 units (8 cars) */
    1 .. 8: return CB_RESULT_NO_TEXT;
    return string(STR_BR415_NSE_CANNOT_START);
}

/* --- Wagon attach callback  --- */
switch(FEAT_TRAINS, SELF, sw_br415_nse_can_attach_wagon, vehicle_type_id) {
    /* SELF refers to the wagon here, check that it's a 415 */
    item_br415_nse: return CB_RESULT_ATTACH_ALLOW;
    return string(STR_BR415_NSE_CANNOT_ATTACH_OTHER);
}

/* Define the actual train */
item(FEAT_TRAINS, item_br415_nse) {
    /* Define properties first, make sure to set all of them */
    property {
        name:                         string(STR_BR415_NSE_NAME);
        // not available in toyland:
        climates_available:           bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL); 
        introduction_date:            date(1951, 1, 1);
        model_life:                   VEHICLE_NEVER_EXPIRES;
        vehicle_life:                 30;
        reliability_decay:            20;
        refittable_cargo_classes:     bitmask(CC_PASSENGERS);
        non_refittable_cargo_classes: bitmask();
        // refitting is done via cargo classes only, no cargo types need explicit enabling/disabling
        loading_speed:                8; 
        cost_factor:                  45;
        running_cost_factor:          100;
        sprite_id:                    SPRITE_ID_NEW_TRAIN;
        speed:                        121 km/h;
        misc_flags:                   bitmask(TRAIN_FLAG_MU);
        refit_cost:                   0; //refit costs don't apply to subcargo display 
        // callback flags are not set manually
        track_type:                   ELRL; // from rail type table
        ai_special_flag:              AI_FLAG_PASSENGER;
        power:                        750 kW;
        running_cost_base:            RUNNING_COST_ELECTRIC;
        dual_headed:                  0;
        cargo_capacity:               98;
        weight:                       60 ton;
        ai_engine_rank:               0; // not intended to be used by the ai
        engine_class:                 ENGINE_CLASS_ELECTRIC;
        extra_power_per_wagon:        0 kW;
        // 4/12 of weight on driving wheels, with a default friction coefficient of 0.3:
        tractive_effort_coefficient:  0.3 / 3;
        air_drag_coefficient:         0.06;
        visual_effect_and_powered:    VISUAL_EFFECT_DISABLE;
        extra_weight_per_wagon:       0 ton;
        bitmask_vehicle_info:         0;
    }
	
    /* Define graphics and callbacks
     * Setting all callbacks is not needed, only define what is used */
    graphics {
        default:                      sw_br415_nse_graphics;
        start_stop:                   sw_br415_nse_start_stop;
        articulated_part:             sw_br415_nse_articulated_part;
        can_attach_wagon:             sw_br415_nse_can_attach_wagon;
    }
}
Last edited by Gafigglethorp on 24 Apr 2017 17:02, edited 1 time in total.
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Beginner in need of help

Post by Alberth »

First step is to go back to the tutorial, and understand how the sprite template works. In particular which sprite is expressed at which NML source code line.

Next, locate the corresponding sprites in your new template.

Now you know which NML source code line must match which sprite in the new template, so adapt the size and position in the NML source line.
Being a retired OpenTTD developer does not mean I know what I am doing.
User avatar
Pyoro
Tycoon
Tycoon
Posts: 2558
Joined: 17 Oct 2008 12:17
Location: Virgo Supercluster

Re: Beginner in need of help

Post by Pyoro »

I might be wrong, but

Code: Select all

tmpl_vehicle_basic(1, 1 + 26 * num)
this should probably be 1+25. purno's second set of sprites starts at 33 (1+32), yours at 26, so 1+25. Might be why NML complains about line 31.
Gafigglethorp
Engineer
Engineer
Posts: 4
Joined: 23 Apr 2017 16:11

Re: Beginner in need of help

Post by Gafigglethorp »

Found the problem. The example had the middle carriages four sprites down, but mine obviously needed 2... :oops:

Code: Select all

/* Define the spritesets, these allow referring to these sprites later on */
spriteset (set_br415_nse_front, "gfx/Network_SouthEast_ BR_Class_415.png") { tmpl_vehicle_8_views(0, 0) }
spriteset (set_br415_nse_rear,  "gfx/Network_SouthEast_ BR_Class_415.png") { tmpl_vehicle_8_views(1, 1) }
spriteset (set_br415_nse_middle_1, "gfx/Network_SouthEast_ BR_Class_415.png") { tmpl_vehicle_4_views(4)    }
spriteset (set_br415_nse_middle_2, "gfx/Network_SouthEast_ BR_Class_415.png") { tmpl_vehicle_4_views(4)    } 
Thanks for the input!
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Beginner in need of help

Post by Alberth »

In hindsight, bugs always seem so simple to spot :)

Great that you found it.
Being a retired OpenTTD developer does not mean I know what I am doing.
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: flogeza, GarryG and 57 guests