NML: Articulated Engine only for GUI

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

Moderator: Graphics Moderators

Post Reply
MarkSheppard
Engineer
Engineer
Posts: 58
Joined: 08 Nov 2004 12:56

NML: Articulated Engine only for GUI

Post by MarkSheppard »

OK, I've figured out (I think) how NARS and (maybe other nGRFs) get their extra-long engines showing up properly in GUI views and such in the depots and train lists -- they basically have the engines articulated in the GUI views only and use repeating sprites -- GUISprite1 and GUISprite2 are the exact same graphic; just with different offsets.

I'm just wondering how to do this in NML, as I am not the world's best coder (I never got past typing games in from magazines in BASIC, lol).
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML: Articulated Engine only for GUI

Post by planetmaker »

They have a separate sprites for the GUI which shows there what they want to show.

http://newgrf-specs.tt-wiki.net/wiki/NM ... tes_in_GUI explains it a bit. Basically you need to provide a switch for the default callback of your vehicle:

Code: Select all

switch (FEAT_TRAINS, SELF, myvehicle_graphics_gui_switch, extra_callback_info1) {
  0: myvehicle_map_view;
  default: myvehicle_gui_view;
}

item (FEAT_TRAINS, myvehicle) {
(...)
  graphics {
    default: myvehicle_graphics_gui_switch;
  }
}
MarkSheppard
Engineer
Engineer
Posts: 58
Joined: 08 Nov 2004 12:56

Re: NML: Articulated Engine only for GUI

Post by MarkSheppard »

planetmaker, I already figured out how to code GUI-only sprites; this is my current code:

Code: Select all

/////////////////////////////////////////////////////////////////////////////////////
//////GRF Definition Block
/////////////////////////////////////////////////////////////////////////////////////

grf 
{
   grfid : "RC\01\01"; 
   name : string(STR_GRF_NAME);
   desc : string(STR_GRF_DESCRIPTION);
   version: 0;
   min_compatible_version: 0;
}

//////* Adjust depot view of trains *///////

traininfo_y_offset = 2;
train_width_32_px = 1;

///////* defining railtype table *///////

railtypetable
{
	RAIL, ELRL, MONO, MGLV,
}

///////* Increase base cost to provide a greater range for running costs *///////

//basecost 
//{
//	PR_RUNNING_TRAIN_ELECTRIC: 2;
//}

/////////////////////////////////////////////////////////////////////////////////////
///EMD DD40A-X Locomotive Block
////////////////////////////////////////////////////////////////////////////////////

////////////////////////
//Purchase menu sprite//
////////////////////////

spriteset (spriteset_DD40AX_Purchase, "gfx/DD40AX.png")
{
    //left_x, upper_y, width, height, offset_x, offset_y
    [ 0,    108,        50,   12,      -24,       -8]
}

//////////////
//GUI sprite One//
//////////////

spriteset (spriteset_DD40AX_GUI_One, "gfx/DD40AX.png")
{
    //left_x, upper_y, width, height, offset_x, offset_y
    [ 48,    81,        40,   12,      -16,       -8] //Sprite 7
}

//////////////
//GUI sprite Two//
//////////////

spriteset (spriteset_DD40AX_GUI_Two, "gfx/DD40AX.png")
{
    //left_x, upper_y, width, height, offset_x, offset_y
    [ 48,    81,        40,   12,      -16,       -8] //Sprite 7
}

///////////////////
//Vehicle sprites//
///////////////////

spriteset (spriteset_DD40AX, "gfx/DD40AX.png")
{
    //left_x, upper_y, width, height, offset_x, offset_y
    [ 1,     19,        8,    27,      -3,       -15] //Sprite 1
    [ 20,    28,        26,   18,      -12,       -11] //Sprite 2
    [ 48,    34,        40,   12,      -16,       -8] //Sprite 3
    [ 90,    28,        26,   18,      -4,       -7] //Sprite 4
	/* Vehicle Sprites Flip Over */
    [ 1,     66,        8,    27,      -3,       -8] //Sprite 5
    [ 20,    75,        26,   18,      -20,       -7] //Sprite 6
    [ 48,    81,        40,   12,      -24,       -8] //Sprite 7
    [ 90,    75,        26,   18,      -12,       -11] //Sprite 8
}

//////////////////////
//vehicle properties//
//////////////////////

switch(FEAT_TRAINS, SELF, DD40AX_Switch, (extra_callback_info1 & 0xFF)) 
{
	0x10: spriteset_DD40AX_GUI_One; // Drawn in Depot GUI
    0x11: spriteset_DD40AX_GUI_One; // Drawn in Vehicle Details/Refit GUI
	0x12: spriteset_DD40AX_GUI_One; // Drawn in Vehicle List
    0x00: spriteset_DD40AX; // Vehicle Drawn in Viewport (on Map)
}
	
item (FEAT_TRAINS, EMD_DD40AX,1) {
   property 
   {
      name: string(STR_NAME_EMD_DD40AX);
	  climates_available: bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL);
	  introduction_date: date(1969,4,01); // Built April 1969 to Sep 1971
	  model_life: 30; // They lasted until 1984 in service
	  vehicle_life: 30;
	  reliability_decay: 20; //placeholder
	  refittable_cargo_classes: bitmask(); //placeholder
	  non_refittable_cargo_classes: bitmask(); //placeholder
	  loading_speed: 0;
	  sprite_id: SPRITE_ID_NEW_TRAIN;
	  speed: 90 mph;
	  misc_flags: bitmask(TRAIN_FLAG_FLIP); //placeholder
	  refit_cost: 0; //placeholder
	  track_type: RAIL; //placeholder
	  ai_special_flag: AI_FLAG_CARGO;
	  power: 6600 hp;
	  cost_factor: 48.999;
	  running_cost_base: RUNNING_COST_DIESEL;
	  running_cost_factor: 255;
	  dual_headed: 0;
	  cargo_capacity: 0;
	  weight: 270 ton;
	  ai_engine_rank: 0; //not used by AI
	  engine_class: ENGINE_CLASS_DIESEL;
	  extra_power_per_wagon: 0 kW;
	  tractive_effort_coefficient: 0.3; //placeholder
	  air_drag_coefficient: 0.06;
	  length: 8; //full length vehicle
	  visual_effect_and_powered: visual_effect_and_powered(VISUAL_EFFECT_DIESEL, 2, DISABLE_WAGON_POWER);
	  extra_weight_per_wagon: 0 ton;
	  bitmask_vehicle_info: 0;
   }
   
   graphics 
   {
		default: DD40AX_Switch;
		purchase: spriteset_DD40AX_Purchase;
   }
}
The problem I'm facing is how do I:

1.) Make this an articulated consist.
2.) Make it so that the articulated consist is ONLY used for the GUI view?

I know that NARS2 uses this trick for the DD40AX (and possibly other super long engines), because when I use the sprite aligner to view the sprites, I find the following:

ON MAP: DD40AX - Single Sprite

New Rail Vehicle List DD40AX - Single Sprite

GUI DD40AX - Two Sprites -- sprite 1 has an offset of x-16, y-8; while sprite 2 has an offset of x-28, y-8.
Eddi
Tycoon
Tycoon
Posts: 8289
Joined: 17 Jan 2007 00:14

Re: NML: Articulated Engine only for GUI

Post by Eddi »

you cannot make an articulation "gui only", articulated vehicles are permanent from the moment you purchase them, they cannot be changed afterwards.

you can, however, provide an invisible sprite (one transparent pixel) for the articulated part.

in the purchase list, only the first part is ever drawn, no articulated parts exist until the vehicle is actually purchased.
MarkSheppard
Engineer
Engineer
Posts: 58
Joined: 08 Nov 2004 12:56

Re: NML: Articulated Engine only for GUI

Post by MarkSheppard »

I think I cracked it now. Need to test it more to be sure, but this works:

Code: Select all

/////////////////////////////////////////////////////////////////////////////////////
///Invisible Articulated Part for DD40AX locomotives
/////////////////////////////////////////////////////////////////////////////////////

//////////////
//GUI sprite Two//
//////////////

spriteset (spriteset_DD40AX_GUI_Two, "gfx/DD40AX.png")
{
    //left_x, upper_y, width, height, offset_x, offset_y
    [ 168,    33,        40,   12,      -48,       -8] //Sprite 7
}

spriteset (spriteset_DD40AX_Invisible, "gfx/DD40AX.png")
{
    //left_x, upper_y, width, height, offset_x, offset_y
    [ 200,    49,        8,   12,      -3,       -5] //Blank Spot
}

switch(FEAT_TRAINS, SELF, switch_DD40AX_Invisible_Part, (extra_callback_info1 & 0xFF)) 
{
	0x10: spriteset_DD40AX_GUI_Two; // Drawn in Depot GUI
    0x11: spriteset_DD40AX_GUI_Two; // Drawn in Vehicle Details/Refit GUI
	0x12: spriteset_DD40AX_GUI_Two; // Drawn in Vehicle List
    0x00: spriteset_DD40AX_Invisible; // Vehicle Drawn in Viewport (on Map)
}

item (FEAT_TRAINS, Invisible_DD40AX,1) {
   property 
   {
      name: string(STR_NAME_EMD_DD40AX);
	  climates_available: bitmask(NO_CLIMATE);
	  introduction_date: date(1969,4,01); // Built April 1969 to Sep 1971
	  model_life: 60; // They lasted until 1984 in service
	  vehicle_life: 60;
	  reliability_decay: 20; //placeholder
	  refittable_cargo_classes: bitmask(); //placeholder
	  non_refittable_cargo_classes: bitmask(); //placeholder
	  loading_speed: 0;
	  sprite_id: SPRITE_ID_NEW_TRAIN;
	  speed: 90 mph;
	  misc_flags: bitmask(TRAIN_FLAG_FLIP); //placeholder
	  refit_cost: 0; //placeholder
	  track_type: RAIL; //placeholder
	  ai_special_flag: AI_FLAG_CARGO;
	  power: 0 hp;
	  cost_factor: 0;
	  running_cost_base: RUNNING_COST_DIESEL;
	  running_cost_factor: 0;
	  dual_headed: 0;
	  cargo_capacity: 0;
	  weight: 0 ton;
	  ai_engine_rank: 0; //not used by AI
	  engine_class: ENGINE_CLASS_DIESEL;
	  extra_power_per_wagon: 0 kW;
	  tractive_effort_coefficient: 0.3; //placeholder
	  air_drag_coefficient: 0.06;
	  length: 2;
	  visual_effect_and_powered: visual_effect_and_powered(VISUAL_EFFECT_DIESEL, 2, DISABLE_WAGON_POWER);
	  extra_weight_per_wagon: 0 ton;
	  bitmask_vehicle_info: 0;
   }
   
   graphics 
   {
		default: switch_DD40AX_Invisible_Part;
   }
}

/////////////////////////////////////////////////////////////////////////////////////
///EMD DD40A-X Locomotive Block
////////////////////////////////////////////////////////////////////////////////////

////////////////////////
//Purchase menu sprite//
////////////////////////

spriteset (spriteset_DD40AX_Purchase, "gfx/DD40AX.png")
{
    //left_x, upper_y, width, height, offset_x, offset_y
    [ 168,    33,        40,   12,      -22,       -8] //Sprite 7
}

//////////////
//GUI sprite One//
//////////////

spriteset (spriteset_DD40AX_GUI_One, "gfx/DD40AX.png")
{
    //left_x, upper_y, width, height, offset_x, offset_y
    [ 168,    33,        40,   12,      -16,       -8] //Sprite 7
}

///////////////////
//Vehicle sprites//
///////////////////

spriteset (spriteset_DD40AX, "gfx/DD40AX.png")
{
    //left_x, upper_y, width, height, offset_x, offset_y
    [ 0,     19,        10,    26,      -4,       -14] //Sprite 1--
    [ 20,    19,        26,   26,      -16,       -17] //Sprite 2--
    [ 48,    19,        40,   26,      -24,       -22] //Sprite 3--
    [ 90,    19,        26,   26,      -8,       -17] //Sprite 4--
	/* Vehicle Sprites Flip Over */
    [ 120,    19,        10,    26,      -4,       -11] //Sprite 5--
    [ 140,    19,        26,   26,      -16,       -17] //Sprite 6--
    [ 168,    19,        40,   26,      -16,       -22] //Sprite 7--
    [ 210,    19,        26,   26,      -8,       -17] //Sprite 8--
}

//////////////////////
//vehicle properties//
//////////////////////

switch(FEAT_TRAINS, SELF, switch_spriteset_DD40AX, (extra_callback_info1 & 0xFF)) 
{
	0x10: spriteset_DD40AX_GUI_One; // Drawn in Depot GUI
    0x11: spriteset_DD40AX_GUI_One; // Drawn in Vehicle Details/Refit GUI
	0x12: spriteset_DD40AX_GUI_One; // Drawn in Vehicle List
    0x00: spriteset_DD40AX; // Vehicle Drawn in Viewport (on Map)
}

switch(FEAT_TRAINS, SELF, switch_articulated_DD40AX, (extra_callback_info1)) 
{
	//add one articulated part//
	1: return Invisible_DD40AX;
	return CB_RESULT_NO_MORE_ARTICULATED_PARTS;
}

item (FEAT_TRAINS, EMD_DD40AX,2) {
   property 
   {
      name: string(STR_NAME_EMD_DD40AX);
	  climates_available: bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL);
	  introduction_date: date(1969,4,01); // Built April 1969 to Sep 1971
	  model_life: 30; // They lasted until 1984 in service
	  vehicle_life: 30;
	  reliability_decay: 20; //placeholder
	  refittable_cargo_classes: bitmask(); //placeholder
	  non_refittable_cargo_classes: bitmask(); //placeholder
	  loading_speed: 0;
	  sprite_id: SPRITE_ID_NEW_TRAIN;
	  speed: 90 mph;
	  misc_flags: bitmask(TRAIN_FLAG_FLIP); //placeholder
	  refit_cost: 0; //placeholder
	  track_type: RAIL; //placeholder
	  ai_special_flag: AI_FLAG_CARGO;
	  power: 6600 hp;
	  cost_factor: 49.067;
	  running_cost_base: RUNNING_COST_DIESEL;
	  running_cost_factor: 255;
	  dual_headed: 0;
	  cargo_capacity: 0;
	  weight: 270 ton;
	  ai_engine_rank: 0; //not used by AI
	  engine_class: ENGINE_CLASS_DIESEL;
	  extra_power_per_wagon: 0 kW;
	  tractive_effort_coefficient: 0.3; //placeholder
	  air_drag_coefficient: 0.06;
	  length: 8; //full length vehicle
	  visual_effect_and_powered: visual_effect_and_powered(VISUAL_EFFECT_DIESEL, 2, DISABLE_WAGON_POWER);
	  extra_weight_per_wagon: 0 ton;
	  bitmask_vehicle_info: 0;
   }
   
   graphics 
   {
		purchase: spriteset_DD40AX_Purchase;
		articulated_part: switch_articulated_DD40AX;
		default: switch_spriteset_DD40AX;
   }
}
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 16 guests