Various NML related questions

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

Transportman
Tycoon
Tycoon
Posts: 2729
Joined: 22 Feb 2011 18:34

Re: Various NML related questions

Post by Transportman »

You don't close your cargotable block, so the switch directly after that is considered part of that block, where it is not possible to be.

Also, the code you propose

Code: Select all

cargo_subtype: PRAGA_N_LIVERY_SWITCH;
is not valid, there is no cargo_subtype graphics-property. If you do not want livery overrides, the default: should point to the correct switch or spriteset.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML

User avatar
Greyfur
Engineer
Engineer
Posts: 36
Joined: 31 Oct 2004 12:43
Location: Slovakia - Bratislava
Contact:

Re: Various NML related questions

Post by Greyfur »

On the contrary.

My aim is to have several refits for the same cargo - that is the whole point of the switch.

When I add it to the

Code: Select all

default:
it doesnt allow any refits.

Can someone provide an advice how to create refits for the same cargo?

Two ways I tried:

1st switching through cargotable:
[+] Spoiler

Code: Select all

cargotable {
    PASS, 
    MAIL 
}
switch(FEAT_ROADVEHS, SELF, PRAGA_N_LIVERY_SWITCH, cargo_subtype) {
    0:      PRAGA_N_0;
    1:      PRAGA_N_1;
    2:      PRAGA_N_2;
    3:      PRAGA_N_3;
}

switch(FEAT_ROADVEHS, SELF, sw_PRAGA_N_CARGO_SUBTYPE_TEXT, cargo_subtype) {
    0: return string(STR_NAME_PRAGA_N_0);
    1: return string(STR_NAME_PRAGA_N_1);
    2: return string(STR_NAME_PRAGA_N_2);
    3: return string(STR_NAME_PRAGA_N_3);
    return CB_RESULT_NO_TEXT;
}
 switch(FEAT_ROADVEHS, SELF, PRAGA_N_CAPACITY_SWITCH, cargo_subtype) {
       0: 35;
       1: 40;
       2: 35;
       3: 40;

item (FEAT_ROADVEHS, ITEM_PRAGA_N) {
						property {
        						   name: string(STR_NAME_PRAGA_N);
        						   climates_available: bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL);
       							   introduction_date: date(1915,01,01);
        						   model_life: 11;
        						   vehicle_life: 11;
        						   reliability_decay: 20;
                                  			   refittable_cargo_classes:    bitmask(CC_PASSENGERS);
							   cargo_allow_refit: [PASS];
							   refit_cost: 0; 
						           loading_speed: 5; 
						           cost_factor: 108;
						           running_cost_factor: 90; 
						           sprite_id: SPRITE_ID_NEW_ROADVEH;
						           speed: 40 km/h;
 						           running_cost_base: RUNNING_COST_ROADVEH;
						           power: 45 hp;
							   weight: 4.5 ton;
						           sound_effect: SOUND_BUS_START_PULL_AWAY;
						        }

					       graphics {
        						   default:  PRAGA_N_0;
							   PASS: PRAGA_N_LIVERY_SWITCH;
							   cargo_subtype_text: sw_PRAGA_N_CARGO_SUBTYPE_TEXT;
                                                           cargo_capacity: PRAGA_N_CAPACITY_SWITCH;
							   purchase_cargo_capacity: 25;
							}
					  }

2nd switching through cargo-subtype at default in graphics section:
[+] Spoiler

Code: Select all


switch(FEAT_ROADVEHS, SELF, SKODA_505_LIVERY_SWITCH, cargo_subtype) {
    0:      SKODA_505_0;
    1:      SKODA_505_1;
    2:      SKODA_505_2;
    3:      SKODA_505_3;
    4:      SKODA_505_4;
}

switch(FEAT_ROADVEHS, SELF, SWITCH_SKODA_505_CARGO_SUBTYPE_TEXT, cargo_subtype) {
    0: return string(STR_NAME_SKODA_505_0);
    1: return string(STR_NAME_SKODA_505_1);
    2: return string(STR_NAME_SKODA_505_2);
    3: return string(STR_NAME_SKODA_505_3);
    4: return string(STR_NAME_SKODA_505_4);
    return CB_RESULT_NO_TEXT;
}
switch(FEAT_ROADVEHS, SELF, SKODA_505_CAPACITY_SWITCH, cargo_subtype) {
    0: 32;
    1: 32;
    2: 32;
    3: 32;
    4: 32;
}

item (FEAT_ROADVEHS, ITEM_SKODA_505) {
						property {

        						   /* Properties common to all vehicle types */
        						   name: string(STR_NAME_SKODA_505);
        						   climates_available: bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL);
       							   introduction_date: date(1923,01,01);
        						   model_life: 7;
        						   vehicle_life: 25;
        						   reliability_decay: 20;
						           loading_speed: 5; //                    STRING***********
						           cost_factor: 108; //				     **********POZRIET*********
						           running_cost_factor: 90; //				     **********POZRIET*********
						        /* cargo_age_period is left at default */
						           /* RV-specific properties */
						           sprite_id: SPRITE_ID_NEW_ROADVEH;
						           speed: 40 km/h;
							//        misc_flags: bitmask(ROADVEH_FLAG_2CC); //    **********POZRIET*********
 						           running_cost_base: RUNNING_COST_ROADVEH;
						           power: 35 hp;
							   weight: 3.6 ton;
						        /* TE and air drag coefficient is left at default */
                                   refittable_cargo_classes:    bitmask(CC_PASSENGERS);
						           

						        sound_effect: SOUND_BUS_START_PULL_AWAY;
						        }

					       graphics {
        						   default:  SKODA_505_LIVERY_SWITCH;
							   cargo_subtype_text: SWITCH_SKODA_505_CARGO_SUBTYPE_TEXT;
							   cargo_capacity: SKODA_505_CAPACITY_SWITCH;
							   purchase_cargo_capacity: 32;
							}
					  }
					  
I get NO error messages when compiling the grf, all vehicles are there and are running, but none from them has an available refit.

Do I miss anything or is there some mistake I, with my minimal experience simply do not see?
Woof !

User avatar
Gwyd
Chief Executive
Chief Executive
Posts: 701
Joined: 17 Apr 2017 16:52
Location: Western Ile-de-France Region

Re: Various NML related questions

Post by Gwyd »

So the way I've done it in the past is

Code: Select all

spriteset(spriteset_Example_Purchase, "gfx/Example.png") {
	template_purchase(237, 488)
}

spriteset(spriteset_Example_Livery2, "gfx/Example.png") {
	template_electrostar(0, 468)
}

spriteset(spriteset_Example_Livery, "gfx/Example.png") {
	template_electrostar(0, 546)
}

spriteset(spriteset_Example_Livery3, "gfx/Example.png") {
	template_electrostar(0, 0)
}


switch(FEAT_TRAINS,SELF, sw_Example,cargo_subtype){
	0:spriteset_Example_Livery;
	1:spriteset_Example_Livery2;
	2:spriteset_Example_Livery3;
	}

switch(FEAT_TRAINS,SELF,sw_Example_cargo_subtype_text,cargo_subtype){
    0:	return string(str_Livery2);
    1:	return string(str_Livery);
    2:	return string(str_Livery3);
       return CB_RESULT_NO_TEXT;
}

item (FEAT_TRAINS, item_Example, xxx) {
	property {
		name: 							string(STR_NAME_Example);
		climates_available: 			ALL_CLIMATES;
		introduction_date:				date(1987,4,21);
		model_life:						15;
		retire_early:					1;
		vehicle_life:					50;
		reliability_decay:				7;
		refittable_cargo_classes:		0;
		cargo_allow_refit:				[PASS];
		loading_speed:					25;
		cost_factor:					61;
		running_cost_factor:			37;
		sprite_id:						SPRITE_ID_NEW_TRAIN;
		speed:							161 km/h;
		misc_flags:						TRAIN_FLAG_MU;
		refit_cost:						0;
		track_type:						BR_3RDC;
		ai_special_flag:				AI_FLAG_CARGO;
		power:							1438 hp;
		running_cost_base:				RUNNING_COST_ELECTRIC;
		dual_headed:					0;
		default_cargo_type:				PASS;
		cargo_capacity:					82;
		weight:							168 ton;
		engine_class:					ENGINE_CLASS_ELECTRIC;
		tractive_effort_coefficient:	0.03;
		air_drag_coefficient:			0.05;
		length:							8;
		effect_spawn_model_and_powered:	EFFECT_SPAWN_MODEL_ELECTRIC;
		extra_weight_per_wagon:			0;
		bitmask_vehicle_info:			0;
	}
	graphics {
	additional_text:					return(str_purchase_text);
	can_attach_wagon:					CB_RESULT_ATTACH_ALLOW;
	cargo_subtype_text:					sw_Example_cargo_subtype_text;
	articulated_part:        			switch_articulated_Example;
	default: 							sw_Example;
	purchase:							spriteset_Example_Purchase;
}
}

User avatar
Gwyd
Chief Executive
Chief Executive
Posts: 701
Joined: 17 Apr 2017 16:52
Location: Western Ile-de-France Region

Re: Various NML related questions

Post by Gwyd »

Just to let y'all know I updated my previous post

User avatar
Greyfur
Engineer
Engineer
Posts: 36
Joined: 31 Oct 2004 12:43
Location: Slovakia - Bratislava
Contact:

Re: Various NML related questions

Post by Greyfur »

Thank you!

I was able to make it work. However I was not able to set any other properties of the refitted vehicle - is it possible to have cargo capacity, speed, runing costs or others changed for the refitted vehicle, when the refit is based on cargo subtype?
Woof !

User avatar
TrainLover
Engineer
Engineer
Posts: 107
Joined: 01 Jul 2015 15:03

Re: Various NML related questions

Post by TrainLover »

Can you get spritesets and liveries from different graphics files? I'm working on basically an extremely large livery set, which basically includes the liveries of the major Class I railroads of North America and I would like to use the 2cc template. I would not want to make hundreds of different purchase files for each individual railroad, I would just want someone to be able to refit for the desired livery.

Transportman
Tycoon
Tycoon
Posts: 2729
Joined: 22 Feb 2011 18:34

Re: Various NML related questions

Post by Transportman »

Greyfur wrote:Thank you!

I was able to make it work. However I was not able to set any other properties of the refitted vehicle - is it possible to have cargo capacity, speed, runing costs or others changed for the refitted vehicle, when the refit is based on cargo subtype?
I expect that will be possible, for each property you would have one switch based on the cargo_type_in_veh variable, and that switch then points to additional switches that set the value based on the cargo_subtype.

Question is, how playable that will be, if you have too many changes it might get confusing.
TrainLover wrote:Can you get spritesets and liveries from different graphics files? I'm working on basically an extremely large livery set, which basically includes the liveries of the major Class I railroads of North America and I would like to use the 2cc template. I would not want to make hundreds of different purchase files for each individual railroad, I would just want someone to be able to refit for the desired livery.
Each sprite can be in a separate file if you want to, but you can also put all sprites in 1 file, and everything in between.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML

User avatar
Gwyd
Chief Executive
Chief Executive
Posts: 701
Joined: 17 Apr 2017 16:52
Location: Western Ile-de-France Region

Re: Various NML related questions

Post by Gwyd »

Switches relating to livery are done through

Code: Select all

 switch(FEATURE, [SELF|PARENT], sw_switchname, cargo_subtype){
Not sure if it helps, but there you go

User avatar
Greyfur
Engineer
Engineer
Posts: 36
Joined: 31 Oct 2004 12:43
Location: Slovakia - Bratislava
Contact:

Re: Various NML related questions

Post by Greyfur »

So, the property switch overrides will be located in the item graphics section after the text and graphics switches?
Woof !

User avatar
Leanden
Tycoon
Tycoon
Posts: 2620
Joined: 19 Mar 2009 19:25
Location: Kent

Re: Various NML related questions

Post by Leanden »

The switch itself comes above the item block, but you then reference it in the graphics block
Image

User avatar
Greyfur
Engineer
Engineer
Posts: 36
Joined: 31 Oct 2004 12:43
Location: Slovakia - Bratislava
Contact:

Re: Various NML related questions

Post by Greyfur »

I seem to have a huge issue with the callbacks.

Every time I am doing a callback I receive an error.

Currently with this one:

Code: Select all

switch(FEAT_ROADVEHS, SELF, power_B731yob_switch, build_year) {
    1982..1985:   202;
	1986..1996:     211;
 }	
 
 
item (FEAT_ROADVEHS, ITEM_B731) {
						property {
...
						           power: 211 hp;		
...
}

					       graphics {
								   cargo_subtype_text: sw_B731_CARGO_SUBTYPE_TEXT;
        						           sw_B731_LIVERY_SWITCH;
								   power: power_B731yob_switch hp;
							}
					  }
The Error I am receiving:
nmlc ERROR: "CS_BusSetw05lc735.nml", line 288: Syntax error, unexpected token "power"

The same issue appears even if the "hp" is removed and if I put hp to the switch value, I get an error for that.

I got the same duplicate error with cargo_capacity, when trying to do a callback through a switch based on cargo_subtype.

Anybody having a suggestion what am I doing wrong?
Woof !

User avatar
Leanden
Tycoon
Tycoon
Posts: 2620
Joined: 19 Mar 2009 19:25
Location: Kent

Re: Various NML related questions

Post by Leanden »

You dont need to put the hp at all, just a numerical value.

The units are auto imported from the item block
Image

User avatar
Greyfur
Engineer
Engineer
Posts: 36
Joined: 31 Oct 2004 12:43
Location: Slovakia - Bratislava
Contact:

Re: Various NML related questions

Post by Greyfur »

Ok, good to know!

Any idea on the error?
Woof !

Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Various NML related questions

Post by Alberth »

Greyfur wrote:Ok, good to know!

Any idea on the error?
What does "sw_B731_LIVERY_SWITCH;" do there? I am guessing it needs a callback name prefix?
Being a retired OpenTTD developer does not mean I know what I am doing.

Transportman
Tycoon
Tycoon
Posts: 2729
Joined: 22 Feb 2011 18:34

Re: Various NML related questions

Post by Transportman »

Alberth wrote:
Greyfur wrote:Ok, good to know!

Any idea on the error?
What does "sw_B731_LIVERY_SWITCH;" do there? I am guessing it needs a callback name prefix?
I guess it is the default callback, so I expect that the error happens because the default callback is before the final callback. @Greyfur: Can you move the callback in the graphics-block up, so that the sw_B731_LIVERY_SWITCH is the last one?
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML

Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Various NML related questions

Post by Alberth »

Preferably also label it as default, as in https://newgrf-specs.tt-wiki.net/wiki/N ... hics_block

The switch could also use some additional 'return' keywords for clarity, as in https://newgrf-specs.tt-wiki.net/wiki/NML:Switch
Being a retired OpenTTD developer does not mean I know what I am doing.

User avatar
Greyfur
Engineer
Engineer
Posts: 36
Joined: 31 Oct 2004 12:43
Location: Slovakia - Bratislava
Contact:

Re: Various NML related questions

Post by Greyfur »

I didn't reply as adding the default: callback name did work and I was working on my code! Thank you so much!

There are two more things.

There are two subversions of a type built in the same year. I was able to create a switch that randomly gives you a subtype when buying the bus. One subtype is called C734.00, the other C734.03.

Now I would like to keep that subtype name after a livery refit. Is there a way to load the name into some variable and somehow reuse it after refit?

The other is - is there a way to add two different texts from two different switches one after another?
Woof !

McZapkie
Tycoon
Tycoon
Posts: 1182
Joined: 18 Jan 2014 18:10

Re: Various NML related questions

Post by McZapkie »

Currently I have 600mm gauge track with label NG60.
I want to add some kind of universal dual gauge track, to have possibility of easy autoreplace, or using same platform:

Code: Select all

  item (FEAT_RAILTYPES, NG600RAIL)
  {
    property
    {
      label: "NG6R";
      introduction_date: date(1883, 1, 1);
      name: string(STR_NG6R_NAME);
      toolbar_caption: string(STR_NG6R_TOOLBAR);
      menu_text: string(STR_NG6R_MENU);
      build_window_caption: string(STR_NG60_BUILD_CAPTION);
      autoreplace_text: string(STR_NG60_AUTOREPLACE);
      new_engine_text: string(STR_NG60_NEW_ENGINE);
      compatible_railtype_list: ["NG6R", "NG60", "NAAN", "RAIL", "ELRL"];
      powered_railtype_list: ["NG6R", "NG60", "NAAN", "RAIL"];
      speed_limit: 60 km/h;      
      acceleration_model: ACC_MODEL_RAIL;
      railtype_flags: bitmask();
    }
but neither no engines are available in the shed, nor both 600mm and normal gauge trains can't enter into dual gauge section.
Any ideas, what goes wrong?
My experimental openTTD server: 149.156.194.203:3979 non-standard client, now testing: JGRPP http://tiny.pl/ggnch
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, preindustrial houses, wired, ECS industry extension, V4 CEE train set.
Addicted to freeciv longturn.

Transportman
Tycoon
Tycoon
Posts: 2729
Joined: 22 Feb 2011 18:34

Re: Various NML related questions

Post by Transportman »

Do the other tracks also define that they are compatible with this universal track? I think that might solve the problem.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML

McZapkie
Tycoon
Tycoon
Posts: 1182
Joined: 18 Jan 2014 18:10

Re: Various NML related questions

Post by McZapkie »

Thank you, Transportman, problem solved.
My experimental openTTD server: 149.156.194.203:3979 non-standard client, now testing: JGRPP http://tiny.pl/ggnch
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, preindustrial houses, wired, ECS industry extension, V4 CEE train set.
Addicted to freeciv longturn.

Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 3 guests