NML - a Newgrf Meta Language

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

Moderator: Graphics Moderators

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

Re: NML - a Newgrf Meta Language

Post by Alberth »

The other way around, you need to state in the industry that you want to check the location.

Code: Select all

item(FEAT_INDUSTRIES, ....) {
 ...
 graphics {
   ...
   location_check: build_distance_check;
   ...
 }
}
See http://newgrf-specs.tt-wiki.net/wiki/NM ... _callbacks for a list of callbacks for industries
Being a retired OpenTTD developer does not mean I know what I am doing.
User avatar
GarryG
Tycoon
Tycoon
Posts: 5892
Joined: 14 Feb 2015 00:44
Location: Newcastle, Australia

Re: NML - a Newgrf Meta Language

Post by GarryG »

Not having any luck .. maybe it past my bedtime and a sleep will help. (Old bloke like me need his beauty sleep .. not that it helps much)

Am I suppose to use both

Code: Select all

"  switch (FEAT_INDUSTRIES, SELF, freight_depot_build_distance_check, town_zone(0, 0)) { 5 .. 20: CB_RESULT_LOCATION_ALLOW; return CB_RESULT_LOCATION_DISALLOW;  "
and

Code: Select all

" location_check: freight_depot_build_distance_check; "
I've had it work once but when test in a scenario to place the industry it say no suitable site found no matter how close or far I try to place it from the town.

Any other settings I've tried keeps coming up with ERROR messages.
Soot Happens
Screenshot Of The Month Winner March 2020
All my projects are GPLv2 License unless stated.
Auz Road Sets: viewtopic.php?f=29&t=87335
Auz Project Releases: viewtopic.php?f=67&t=84725
Auz Trains: http://www.tt-forums.net/viewtopic.php?f=26&t=74193
Auz Industry Sets: http://www.tt-forums.net/viewtopic.php?f=26&t=74471
Auz Objects: viewtopic.php?f=26&t=75657
Auz Bridges: viewtopic.php?f=26&t=75248
Auz Stations: viewtopic.php?f=26&t=76390
Auz Tracks: viewtopic.php?f=26&t=82691
Auz Subway Stations: viewtopic.php?f=26&t=85335
Auz Eyecandy TramTracks: viewtopic.php?t=89908
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: NML - a Newgrf Meta Language

Post by Transportman »

That is because the return of town_zone is not 5..20, but something else, so your switch always disallows. The values to check for are listed here.

If you want to check the actual distance to the town center, you should look at town_manhattan_dist and town_euclidean_dist.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML - a Newgrf Meta Language

Post by planetmaker »

Transportman wrote:That is because the return of town_zone is not 5..20, but something else, so your switch always disallows. The values to check for are listed here.

If you want to check the actual distance to the town center, you should look at town_manhattan_dist and town_euclidean_dist.
Oh indeed! Townzone has only very descrete values. The distance to the town centre is something different than town zone.
User avatar
GarryG
Tycoon
Tycoon
Posts: 5892
Joined: 14 Feb 2015 00:44
Location: Newcastle, Australia

Re: NML - a Newgrf Meta Language

Post by GarryG »

Thanks every one for trying to help me with this problem, but it just not clicking.

I tried what I think everyone means and what they say on the links to websites, but having no luck at all.

I get the message: is not referenced, ignoring.

I'm sorry to inconvenience you all.

I on a disability pension due to brain damage I suffered when I worked on the railways. I fell off the top of a wagon loaded with wool, fracturing my skull and breaking my ankles. It not easy for me these days to remember what I read and understand something's. Ask 3IFF he been helping me a lot with doing town names and started me with doing Industries. I've often asked him many questions to understand one answer. Old age might not be helping too .. wonder if I oldest person on these forums .. I turn 62 soon.

I wonder if I can send someone part of my NML file of the industry I trying to make it build near towns, but not too close.

The Industry Set I working on is great for those who want to use it when building their own scenarios. But not for those who like random made maps, as there are a few industried I made that designed to be close to towns.

This command: spec_flags: bitmask(IND_FLAG_BUILT_NEAR_TOWN); is ok for some, but it places Industry within 10 squares of the town centre. Like some of them to be a bit further away so they easier to build rail to without bulldozing houses.

Thanks again fellas for all the help.
Soot Happens
Screenshot Of The Month Winner March 2020
All my projects are GPLv2 License unless stated.
Auz Road Sets: viewtopic.php?f=29&t=87335
Auz Project Releases: viewtopic.php?f=67&t=84725
Auz Trains: http://www.tt-forums.net/viewtopic.php?f=26&t=74193
Auz Industry Sets: http://www.tt-forums.net/viewtopic.php?f=26&t=74471
Auz Objects: viewtopic.php?f=26&t=75657
Auz Bridges: viewtopic.php?f=26&t=75248
Auz Stations: viewtopic.php?f=26&t=76390
Auz Tracks: viewtopic.php?f=26&t=82691
Auz Subway Stations: viewtopic.php?f=26&t=85335
Auz Eyecandy TramTracks: viewtopic.php?t=89908
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

GarryG wrote:I get the message: is not referenced, ignoring.
so, you defined a switch, but you did not use it in industry block to attach it to a callback.
User avatar
GarryG
Tycoon
Tycoon
Posts: 5892
Joined: 14 Feb 2015 00:44
Location: Newcastle, Australia

Re: NML - a Newgrf Meta Language

Post by GarryG »

Not sure if this what you mean. I been using the NML from FIRS 1.4.3 and SPI 1.1 to try learn somethings.

I copied this from the Grain Mill in FIRS 1.4.3 and changed the Industry names:

switch (FEAT_INDUSTRIES, SELF, freight_depot_town_distance, town_euclidean_dist(0, 0)) { 0 .. 30: return CB_RESULT_LOCATION_DISALLOW; }
switch (FEAT_INDUSTRIES, SELF, freight_depot_check_location, ( (extra_callback_info2 == IND_CREATION_FUND) || (extra_callback_info2 == IND_CREATION_PROSPECT) ) ) { 1: return CB_RESULT_LOCATION_ALLOW; freight_depot_town_distance; }

All lines it gives the same message "is not referenced, ignoring"

Are they the callbacks you mentioned?
Soot Happens
Screenshot Of The Month Winner March 2020
All my projects are GPLv2 License unless stated.
Auz Road Sets: viewtopic.php?f=29&t=87335
Auz Project Releases: viewtopic.php?f=67&t=84725
Auz Trains: http://www.tt-forums.net/viewtopic.php?f=26&t=74193
Auz Industry Sets: http://www.tt-forums.net/viewtopic.php?f=26&t=74471
Auz Objects: viewtopic.php?f=26&t=75657
Auz Bridges: viewtopic.php?f=26&t=75248
Auz Stations: viewtopic.php?f=26&t=76390
Auz Tracks: viewtopic.php?f=26&t=82691
Auz Subway Stations: viewtopic.php?f=26&t=85335
Auz Eyecandy TramTracks: viewtopic.php?t=89908
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: NML - a Newgrf Meta Language

Post by Transportman »

Those are indeed the callbacks. As Alberth mentioned in an earlier post, you need to add a line of code to the industry to make it work, a call to the switch freight_depot_check_location.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
User avatar
GarryG
Tycoon
Tycoon
Posts: 5892
Joined: 14 Feb 2015 00:44
Location: Newcastle, Australia

Re: NML - a Newgrf Meta Language

Post by GarryG »

I tried what Alberth said and get the message "Unrecognized identifier".

I tried

Code: Select all

item(FEAT_INDUSTRIES, freight_depot, 62) {
  graphics {
    location_check: build_distance_check;
  }
} 
and also tried the line location_check: freight_depot_build_distance_check

If I put the line location_check: freight_depot_check_location .. it works but doesn't restrict the building of this industry with the radius I like from a town.

What I doing wrong this time?
Last edited by planetmaker on 19 Oct 2015 10:30, edited 1 time in total.
Reason: added code tags around code for readability
Soot Happens
Screenshot Of The Month Winner March 2020
All my projects are GPLv2 License unless stated.
Auz Road Sets: viewtopic.php?f=29&t=87335
Auz Project Releases: viewtopic.php?f=67&t=84725
Auz Trains: http://www.tt-forums.net/viewtopic.php?f=26&t=74193
Auz Industry Sets: http://www.tt-forums.net/viewtopic.php?f=26&t=74471
Auz Objects: viewtopic.php?f=26&t=75657
Auz Bridges: viewtopic.php?f=26&t=75248
Auz Stations: viewtopic.php?f=26&t=76390
Auz Tracks: viewtopic.php?f=26&t=82691
Auz Subway Stations: viewtopic.php?f=26&t=85335
Auz Eyecandy TramTracks: viewtopic.php?t=89908
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML - a Newgrf Meta Language

Post by planetmaker »

In your code, is the switch placed *above* the item declaration where the switch is referenced?
User avatar
3iff
Tycoon
Tycoon
Posts: 1094
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: NML - a Newgrf Meta Language

Post by 3iff »

I've had a look at his code and think I've fixed it. The 'location_disallow' build bit was missing and the switch called didn't actually exist (a simple rename to the switch actually called was all it needed).

I decided to use the town_manhattan_dist call as it looks to give better results (well, results I think are better) but it's up to GarryG.
User avatar
GarryG
Tycoon
Tycoon
Posts: 5892
Joined: 14 Feb 2015 00:44
Location: Newcastle, Australia

Re: NML - a Newgrf Meta Language

Post by GarryG »

Thank you too all who have helped me.

What 3IFF has done for me works .. at least no more error messages.

When tested in Scenario Editor it still allows building the industry outside the limit I hoped 10 .. 30.

But now no errors< I can play around some more and see what I come up with.

Again thank you to all.
Soot Happens
Screenshot Of The Month Winner March 2020
All my projects are GPLv2 License unless stated.
Auz Road Sets: viewtopic.php?f=29&t=87335
Auz Project Releases: viewtopic.php?f=67&t=84725
Auz Trains: http://www.tt-forums.net/viewtopic.php?f=26&t=74193
Auz Industry Sets: http://www.tt-forums.net/viewtopic.php?f=26&t=74471
Auz Objects: viewtopic.php?f=26&t=75657
Auz Bridges: viewtopic.php?f=26&t=75248
Auz Stations: viewtopic.php?f=26&t=76390
Auz Tracks: viewtopic.php?f=26&t=82691
Auz Subway Stations: viewtopic.php?f=26&t=85335
Auz Eyecandy TramTracks: viewtopic.php?t=89908
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

the scenario editor does not usually follow these restrictions, try in a game.
User avatar
GarryG
Tycoon
Tycoon
Posts: 5892
Joined: 14 Feb 2015 00:44
Location: Newcastle, Australia

Re: NML - a Newgrf Meta Language

Post by GarryG »

Hi all, finally got it working and it works it scenario editing too.

For those who interested the codes needed are:

Code: Select all

switch (FEAT_INDUSTRIES, SELF, freight_depot_town_distance, town_manhattan_dist(0, 0)) {
 10 .. 20: return CB_RESULT_LOCATION_ALLOW;
           return CB_RESULT_LOCATION_DISALLOW;
}
and

Code: Select all

      item(FEAT_INDUSTRIES, freight_depot, 62) {
 	graphics {

		location_check: freight_depot_town_distance;
}
}
freight_depot is the name of the industry. 10 .. 20 choses the closest and furthest distance from a town.

I think it a great code where can make a Industry either close to a town or further away depending on the type of industry.

Wish to offer my many thanks and appreciation to all who answered my plea to help me solve this problem. Thank you all so kindly.
Soot Happens
Screenshot Of The Month Winner March 2020
All my projects are GPLv2 License unless stated.
Auz Road Sets: viewtopic.php?f=29&t=87335
Auz Project Releases: viewtopic.php?f=67&t=84725
Auz Trains: http://www.tt-forums.net/viewtopic.php?f=26&t=74193
Auz Industry Sets: http://www.tt-forums.net/viewtopic.php?f=26&t=74471
Auz Objects: viewtopic.php?f=26&t=75657
Auz Bridges: viewtopic.php?f=26&t=75248
Auz Stations: viewtopic.php?f=26&t=76390
Auz Tracks: viewtopic.php?f=26&t=82691
Auz Subway Stations: viewtopic.php?f=26&t=85335
Auz Eyecandy TramTracks: viewtopic.php?t=89908
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: NML - a Newgrf Meta Language

Post by Wahazar »

How to assign company colour to industry? I have png painted with 1cc blue colours, and switch

Code: Select all

switch (FEAT_INDUSTRIES, SELF, set_company_colour, founder_colour1)
{
     2: return founder_colour2;
     return founder_colour1;
}
//... in graphic section: 
		colour:			set_company_colour;
but building is still blue...
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML - a Newgrf Meta Language

Post by planetmaker »

Do you have set to allow recolouring in the spritelayout?

Code: Select all

spritelayout building1 {
  	(...)
  	building {
  	  	(...)
  		recolour_mode: RECOLOUR_REMAP;
 		palette: PALETTE_USE_DEFAULT;
  	}
}
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: NML - a Newgrf Meta Language

Post by Wahazar »

Thanks, didn't know that it should be defined in spritelayout (I checked only industry tiles).
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML - a Newgrf Meta Language

Post by planetmaker »

McZapkie wrote:Thanks, didn't know that it should be defined in spritelayout (I checked only industry tiles).
Well, it's two things:
* you define at sprite level which sprites are subject to recolouring
* you define at industry level via the callback which colour shall be used as 'company colour' for those sprites subject to recolouring.
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: NML - a Newgrf Meta Language

Post by Wahazar »

If recolours are defined, and callback not, random colours would appears? I observed something like it.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML - a Newgrf Meta Language

Post by planetmaker »

McZapkie wrote:If recolours are defined, and callback not, random colours would appears? I observed something like it.
Yes. From the callback documentation: " Called after constructing the industry. The colour variable is set to a random value at this point, you can use this callback to change this. "
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 20 guests