Various NML related questions

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

Moderator: Graphics Moderators

Post Reply
lukasz1985
Route Supervisor
Route Supervisor
Posts: 429
Joined: 27 Mar 2013 08:58
Location: Strumien

Re: Various NML related questions

Post by lukasz1985 »

Hi, is it possible to change color of the background of GUI elements by NML or in some different way? I mean the defatult gray color. I cant find any information on this in the wiki.

Eddi
Tycoon
Tycoon
Posts: 7479
Joined: 17 Jan 2007 00:14

Re: Various NML related questions

Post by Eddi »

lukasz1985 wrote:Hi, is it possible to change color of the background of GUI elements by NML or in some different way? I mean the defatult gray color. I cant find any information on this in the wiki.
i think that's done by overriding one of the default recolour maps. but don't ask me which one. (may have side effects)
3iff wrote:2. The specified cargo size is halved for goods (40 cargo = 20 goods) but quartered for other cargos. It's implied that this can be overridden but I can't see anything obvious.
there are two types of capacity callbacks, one which follows the multipliers, and one which ignores them. you have to use the right kind. i think nml defaults to the non-multiplier callback, so just using callback instead of property might work (not sure)
You might not exactly be interested in Ferion, but if you are, have fun :)

User avatar
3iff
Tycoon
Tycoon
Posts: 1012
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

I'm trying to use "current_month" in a switch but it seems to be returning zero all the time.

switch (FEAT_INDUSTRIES, SELF, check_month, STORE_PERM(current_month,10)) {
other code
}

I'm temporarily storing it in register 10 so I can see it change...but it stays at zero.
So, either I'm doing something wrong or it isn't working. Any ideas?

=====================

Forget it. I was 100% sure I was actually calling that switch but I had only altered one area that called it and missed the other block completely. It now works as I expected.

(I thought it might be my fault... :oops:

User avatar
3iff
Tycoon
Tycoon
Posts: 1012
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

A strange effect.
I get the population of a town (it's 700) and I get the following results.

Code: Select all

STORE_TEMP((population - 2000) / 2000 , 2),  = 2147428  !!!
STORE_TEMP(population, 3),                   = 700
STORE_TEMP(population - 2000 , 4),           = -1300
It seems to be the "/ 2000" part that screws it up.
Is this a feature or a bug? Now I know what's happening it's no problem to work around it.

frosch
OpenTTD Developer
OpenTTD Developer
Posts: 980
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Various NML related questions

Post by frosch »

I think that is a bug in OpenTTD.
Can you please retest using todays nightly (>= r27600). It becomes available in about an hour.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁

User avatar
3iff
Tycoon
Tycoon
Posts: 1012
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

Sure. I'll report back when I've tested it.

That looks better. Using v27601.
sum calculated is (1012 - 2000) / 2000 = -0.494 which rounds to 0. Much better than 2million+.

Thanks for the very quick fix.

User avatar
colossal404
Chief Executive
Chief Executive
Posts: 644
Joined: 07 Mar 2009 12:48
Location: Szeged, Hungary

Re: Various NML related questions

Post by colossal404 »

Hi!
I'd like to ask a question about company colours: Is it possible to disable the recolouring? If yes, is it possible to disable it for just certain refits?
I'd like to use the CC2 green for a non-company coloured refit, but in the same vehicle, I'd like to use the second company colour on another refit.
I'm coding in NML.
Image

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

Re: Various NML related questions

Post by Transportman »

colossal404 wrote:Hi!
I'd like to ask a question about company colours: Is it possible to disable the recolouring? If yes, is it possible to disable it for just certain refits?
I'd like to use the CC2 green for a non-company coloured refit, but in the same vehicle, I'd like to use the second company colour on another refit.
I'm coding in NML.
Doesn't the palette have a non-CC green you can use? Otherwise I think you cannot get it working, as the misc_flags that toggles the behavior is not available as callback.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML

User avatar
3iff
Tycoon
Tycoon
Posts: 1012
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

I have an industry I don't want the player to be able to build during the game. How do I block this?
I still want the industry to be available for random placement. Players would be free to build all other industries should they wish.

I can't seem to find a command to block player funding for a specific industry...

-----

Ah, partially there. I can now stop it being built but it still appears in the "fund industry" menu.

frosch
OpenTTD Developer
OpenTTD Developer
Posts: 980
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Various NML related questions

Post by frosch »

colossal404 wrote:Hi!
I'd like to ask a question about company colours: Is it possible to disable the recolouring? If yes, is it possible to disable it for just certain refits?
I'd like to use the CC2 green for a non-company coloured refit, but in the same vehicle, I'd like to use the second company colour on another refit.
I'm coding in NML.
You can do that via the "colour_mapping" callback:
  • Use both CC as normal: "colour_mapping: return CB_FAILED;"
  • Disable both CC: "colour_mapping: return PALETTE_CC_FIRST;"
  • Only use first CC: "colour_mapping: return base_sprite_2cc + company_colour1;"
  • Only use second CC: "colour_mapping: return base_sprite_2cc + 16*company_colour2;"
  • Use the palette colours of the first CC, but using the player's second CC selection: "colour_mapping: return base_sprite_2cc + company_colour2;"
  • Swap CC: "colour_mapping: return base_sprite_2cc + company_colour2 + 16*company_colour1;"
  • Use random colours: "colour_mapping: return base_sprite_2cc + getbits(random_bits , 0, 8 );"
  • Use first CC and random second CC: "colour_mapping: return base_sprite_2cc + company_colour1 + 16*getbits(random_bits , 0, 4);"
  • Use colour depending on build year: "colour_mapping: return base_sprite_2cc + getbits(build_year, 0, 4)"
  • ...
Of course you can also put various conditional switches inbetween.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁

frosch
OpenTTD Developer
OpenTTD Developer
Posts: 980
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Various NML related questions

Post by frosch »

3iff wrote:I have an industry I don't want the player to be able to build during the game. How do I block this?
I still want the industry to be available for random placement. Players would be free to build all other industries should they wish.

I can't seem to find a command to block player funding for a specific industry...

-----

Ah, partially there. I can now stop it being built but it still appears in the "fund industry" menu.
IIRC the callback "construction_probabiilty" is also checked in the fund list, so something like:
  • construction_probabiilty
  • switch of "getbits(extra_callback_info2, 0, 8 )"
  • in case of "IND_CREATION_FUND" return 0
  • otherwise return 255
Other checks like "location_check" depend on the industry location, thus do not affect the fund list.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁

User avatar
3iff
Tycoon
Tycoon
Posts: 1012
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

Thanks. I think I might almost understand that...perhaps.
I'll give it a try.

----------

I'm not having any success. I can block the industry being funded but it still appears in the menu. Not to worry, I can live with that for now.

I did have a switch block that essentially did what you suggested but I must have something slightly wrong.

frosch
OpenTTD Developer
OpenTTD Developer
Posts: 980
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Various NML related questions

Post by frosch »

Ah, I see: OpenTTD only disables the buttons, but it always shows all industries in the list.
You cannot change that via NewGRF.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁

User avatar
3iff
Tycoon
Tycoon
Posts: 1012
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

I guessed as much. Well, I can block player funding of that industry so that's as much as can be done.

Thanks.

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 »

Hi,

how to set several refits for the same cargo type? I would like to add a few livery options and am pretty new to coding on my own.

Is there any example out there?

Thanks!
Woof !

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

Re: Various NML related questions

Post by Gwyd »

This is done by subcargoes. They are done in 2 steps: define subcargo names, then what the subcargo changes via switches

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 am lost in the cargo sub-type. The only reference I found is in the 3/4 parts DMU creation and there the subtype is defined based on the placement of the vehicle. I can't quite get the trick, how to attach the graphics - based on what?

I mean I already attach graphic based on cargotype - Cargotype is PASS and MAIL. Mail is only one refit, buses (for passengers) should have several for livery purposes.

I got this - and I know there are several mistakes, I just simply dont know how to correct them. The basic set when refitting from mail to passengers is easy, but I have idea, how to make the C734.1340.3 available...

Code: Select all

cargotable {
/* Used in refit mask */
    PASS, // C734 & C734.1340.3 
    MAIL // C734 Mail
}

/* C734.00-C734.1340 */
spriteset(KAROSA_C734_1, "gfx/KarosaC734.png") { TMP_KAROSA_C734(0) }
/* C734.1340.3 */
spriteset(KAROSA_C734_3, "gfx/KarosaC734.png") { TMP_KAROSA_C734(29) }
/* C734 mail */
spriteset(KAROSA_C734_M, "gfx/KarosaC734.png") { TMP_KAROSA_C734(58) }

switch(FEAT_ROADVEHS, SELF, sw_C734_cargo_subtype_text, cargo_subtype) {
    0: return string(STR_KAROSA_C734_1);
    1: return string(STR_KAROSA_C734_3);
    return CB_RESULT_NO_TEXT;

switch(FEAT_ROADVEHS, SELF, sw_C734_graphics, cargo_subtype) { 
    0:      KAROSA_C734_1;
    1:      KAROSA_C734_3;
}

item (FEAT_ROADVEHS, ITEM_KAROSA_C734) {
.
.    no issue here with property setting
.
.
    }
    graphics {
        cargo_capacity: KAROSA_C734_capacity_switch;
        PASS: KAROSA_C734_1;
        PASS: KAROSA_C734_3;
        MAIL: KAROSA_C734_M;
        default:  KAROSA_C734_1; // Default to Pass.        
        cargo_subtype_text:           sw_C734_cargo_subtype_text; 
    }
}

Code: Select all

spriteset(KAROSA_C734_3, "gfx/KarosaC734.png") { TMP_KAROSA_C734(29) } 
if this is supposed to be the livery refit of C734.00-C734.1340, should this be in a Spritesetgroup? If so, based on the
cargo-subtype parameter?

Code: Select all

        PASS: KAROSA_C734_3;

double setting - not allowed, but how do I set that the sub-cargo will be transporting pass?[/color]
Woof !

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

Re: Various NML related questions

Post by Transportman »

For PASS you should refer to a switch that makes it's decision based on the cargo_subtype variable to determine which livery to show.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML

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

Re: Various NML related questions

Post by Gwyd »

In this case, the default graphics switch should be sw_C734_graphics, because it will always default to subcargo 0.

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 was able to complete one vehicle to a state that it works like it should. However I seem to have an issue with this one:
grf {
grfid: "GFJ\00";
name: string(STR_GRF_NAME);
desc: string(STR_GRF_DESCRIPTION);
version: 0;
min_compatible_version: 0;
}

/* *****************************************************Start of the graphic part***************************************************** */


template TMP_CS_BUSSET(y) {
[ 4 , 4 + y, 10, 28, -5, -14]
[ 24 , 4 + y, 26, 28, -13, -14]
[ 54 , 4 + y, 36, 28, -18, -14]
[ 94 , 4 + y, 26, 28, -13, -14]
[ 124, 4 + y, 10, 28, -5, -14]
[ 144, 4 + y, 26, 28, -13, -14]
[ 174, 4 + y, 36, 28, -18, -14]
[ 214, 4 + y, 26, 28, -13, -14]

/* Praga N, CS Posta */
spriteset(PRAGA_N_0, "gfx/CS_BusSetw.png") { TMP_CS_BUSSET(37) }

/* Praga N, DP Praha */
spriteset(PRAGA_N_1, "gfx/CS_BusSetw.png") { TMP_CS_BUSSET(70) }

/* Praga N, CC */
spriteset(PRAGA_N_2, "gfx/CS_BusSetw.png") { TMP_CS_BUSSET(103) }

/* Praga N, 2CC */
spriteset(PRAGA_N_3, "gfx/CS_BusSetw.png") { TMP_CS_BUSSET(136) }


/* ************************************Start of the switching part****************************************** */

cargotable {
/* Used in refit mask */
PASS // To set in the graffic override switch

/* =============================== Praga N switches =================================== */

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;
}

/* *****************************************************Start of the properties part***************************************************** */

/* ===========================================Praga N======================================================= */
item (FEAT_ROADVEHS, ITEM_PRAGA_N) {
property {

/* Properties common to all vehicle types */
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;
loading_speed: 5; // SWITCH ***********
cost_factor: 108; // **********Balance*********
running_cost_factor: 90; // **********Balance*********
/* 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); // **********check*********
running_cost_base: RUNNING_COST_ROADVEH;
power: 45 hp;
weight: 4.5 ton;
/* TE and air drag coefficient is left at default */
refittable_cargo_classes: bitmask(CC_PASSENGERS);
cargo_capacity: 25;
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;
}
}
I get "nmlc ERROR: "CS_BusSetw2.nml", line 111: Syntax error, unexpected token "switch"

I do believe it is because of the PASS thing I would like to remove since this is a bus and will not have acargo refit. Should I simply use this:

Code: Select all

cargo_subtype: PRAGA_N_LIVERY_SWITCH;
instead of PASS: PRAGA_N_LIVERY_SWITCH;?

Thank you!
Woof !

Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 1 guest