Zephyris' Houses (and other things) in NML questions
Moderator: Graphics Moderators
Zephyris' Houses (and other things) in NML questions
So I'm back (for now) and looking at town houses in NML...
A few little questions to get started, I'll give some code snippets if more info is needed:
1. Random colours in houses.
The NML specs say there is a house property "random colours" which takes an array of four recolours, eg. [COLOUR_DARK_BLUE, COLOUR_DARK_GREEN, COLOUR_BLUE, COLOUR_WHITE]. I tried this with dummy house sprites that are entirely company colour, but it didn't seem to do anything... Always appeared blue. Am I using the right table of recolours?
2. Preferred method for road-facing houses.
I can get a switch detecting nearby roads, and pick appropriate sprites or return an appropriate value, but what's the best way to then handle this data? Directly using the switch to pick sprites works, but allows the building to rotate when you change the neighbouring roads, and the redrawing isn't clean. Using four animation frames and setting the animation frame via anim_control works, but it takes a tile loop to set the house to its correct orientation and is still sensitive to changes to the neighbouring roads. I thought setting the animation frame on changes to construction state via construction_anim might avoid this, by triggering only on construction state changes, but this didn't seem to work.
3. Town index
I'd like to use the town index for some pseudo-random town to town variation. It's listed as a variable for a NFO varaction2, but not as an nml switch variable. Can I access that variable via NML? On a related note, is the coordinates of the town centre accessible via NML or NFO? I thought it was, but can't find it documented...
A few little questions to get started, I'll give some code snippets if more info is needed:
1. Random colours in houses.
The NML specs say there is a house property "random colours" which takes an array of four recolours, eg. [COLOUR_DARK_BLUE, COLOUR_DARK_GREEN, COLOUR_BLUE, COLOUR_WHITE]. I tried this with dummy house sprites that are entirely company colour, but it didn't seem to do anything... Always appeared blue. Am I using the right table of recolours?
2. Preferred method for road-facing houses.
I can get a switch detecting nearby roads, and pick appropriate sprites or return an appropriate value, but what's the best way to then handle this data? Directly using the switch to pick sprites works, but allows the building to rotate when you change the neighbouring roads, and the redrawing isn't clean. Using four animation frames and setting the animation frame via anim_control works, but it takes a tile loop to set the house to its correct orientation and is still sensitive to changes to the neighbouring roads. I thought setting the animation frame on changes to construction state via construction_anim might avoid this, by triggering only on construction state changes, but this didn't seem to work.
3. Town index
I'd like to use the town index for some pseudo-random town to town variation. It's listed as a variable for a NFO varaction2, but not as an nml switch variable. Can I access that variable via NML? On a related note, is the coordinates of the town centre accessible via NML or NFO? I thought it was, but can't find it documented...
Last edited by Zephyris on 10 Jan 2018 17:24, edited 1 time in total.
Re: Zephyris' Houses in NML questions
2) i'm not entirely sure, but there should be a way to "stop" the animation after it ran once, so you shouldn't have to worry about later changes. possibly you need a fifth (or zeroth) animation frame "undecided"
3) unknown variables can be accessed with "var[num, shift, mask]", but you should open a feature request about it.
3) unknown variables can be accessed with "var[num, shift, mask]", but you should open a feature request about it.
-
- Tycoon
- Posts: 5948
- Joined: 27 Apr 2005 07:09
- Contact:
Re: Zephyris' Houses in NML questions
1) You can´t use CC blue for house recolouring. IIRC, you need to use brownish 0x46 .. 0x4F.
2) Take a look into the code for Swedish houses. It is mis-using animation for road-facing.
regards
Michael
2) Take a look into the code for Swedish houses. It is mis-using animation for road-facing.
regards
Michael
Re: Zephyris' Houses in NML questions
Thanks! Swedish towns was very informative. When the animation frame is zero (ie. new buildings) it picks an animation frame (1 and higher) based on neighbouring roads. When the animation frame is more than zero it stops the animation. I'm guessing it also sets the animation speed to high to quickly change house orientation...
-
- Tycoon
- Posts: 5948
- Joined: 27 Apr 2005 07:09
- Contact:
Re: Zephyris' Houses in NML questions
That´s not needed, since the default is already fastest (108 msec). And in fact, it won´t be needed since "speed" is defined as amount of time between switching frames. And house orientation should be set exclusively when building, shouldn´t it?Zephyris wrote: I'm guessing it also sets the animation speed to high to quickly change house orientation...
regards
Michael
Re: Zephyris' Houses in NML questions
The issue I'm seeing is that the house is initially built facing in the default direction (ie. whatever is shown for animation frame 0). It seems the animation frame is then updated on the next tile loop (is that when the next animation frame is triggered?); this setting the building to the correct orientation (ie. animation frame 1 to 4). Adding the animation stop prevents the house from re-orienting when you demolish/add neighboring roads (ie. they are fixed in animation frame 1 to 4). It doesn't help with that initial default orientation (which is always frame 0).
Looking in more detail I think the way Swedish houses handles this is by using two switches: For frame 0 have a direct switch in orientation based on neighbouring roads then 'lock' the orientation using frame 1 to 4 use the orientation based on that animation frame. It just seems a bit inelegant. Or perhaps I've just missed how it works...
I'm wondering if callback triggers other than anim_control (callback 1A) might work better. anim_next_frame and construction_anim (callback 1B and 1C) never seem to trigger though.
Looking in more detail I think the way Swedish houses handles this is by using two switches: For frame 0 have a direct switch in orientation based on neighbouring roads then 'lock' the orientation using frame 1 to 4 use the orientation based on that animation frame. It just seems a bit inelegant. Or perhaps I've just missed how it works...
I'm wondering if callback triggers other than anim_control (callback 1A) might work better. anim_next_frame and construction_anim (callback 1B and 1C) never seem to trigger though.
Re: Zephyris' Houses in NML questions
I think I've solved the random colour problem.
In NFO:
https://newgrf-specs.tt-wiki.net/wiki/A ... ng_sprites
House action2/sprite layout, under sprite definition for ground and building sprites, says:
...
Bits 14-15: 0: draw sprite normally, 1: draw sprite in transparent mode, 2: recolor sprite
Bits 16-29: Colour translation special sprite number
...
If bits 16-29 are set then it just uses that recolouring. If they are not set then, if house callback 1E is returns a value, that palette/colour translation will be used. Otherwise if colours are specified in house action0 property 17 then they will be used.
In NML:
https://newgrf-specs.tt-wiki.net/wiki/N ... ecolouring
Setting a recolour_mode in a spritelayout is presumably equivalent to action2/sprite layout bits 14-15. Similarly setting the palette in a spritelayout is presumably setting bits 16-29.
Not setting a palette (i.e. ommitting the line) is not allowed:
"nmlc ERROR: 'palette' must be set when 'recolour_mode' is not set to RECOLOUR_NONE"
However, setting palette to 0 (i.e. trying to imitate setting bits 16-29 to zero) works.
It looks like an over-stringency in nmlc; if recolour_mode is not set to RECOLOUR_NONE then palette should probably default to zero.
In NFO:
https://newgrf-specs.tt-wiki.net/wiki/A ... ng_sprites
House action2/sprite layout, under sprite definition for ground and building sprites, says:
...
Bits 14-15: 0: draw sprite normally, 1: draw sprite in transparent mode, 2: recolor sprite
Bits 16-29: Colour translation special sprite number
...
If bits 16-29 are set then it just uses that recolouring. If they are not set then, if house callback 1E is returns a value, that palette/colour translation will be used. Otherwise if colours are specified in house action0 property 17 then they will be used.
In NML:
https://newgrf-specs.tt-wiki.net/wiki/N ... ecolouring
Setting a recolour_mode in a spritelayout is presumably equivalent to action2/sprite layout bits 14-15. Similarly setting the palette in a spritelayout is presumably setting bits 16-29.
Not setting a palette (i.e. ommitting the line) is not allowed:
"nmlc ERROR: 'palette' must be set when 'recolour_mode' is not set to RECOLOUR_NONE"
However, setting palette to 0 (i.e. trying to imitate setting bits 16-29 to zero) works.
It looks like an over-stringency in nmlc; if recolour_mode is not set to RECOLOUR_NONE then palette should probably default to zero.
Re: Zephyris' Houses in NML questions
Another question:
Is there a way to get the coordinates of the town for a grf? I'd like to effectively add another town zone right at the town centre. That should be easily possible with a construction callback checking town zone and distance from town centre, assuming town centre coordinates are accessible.
Is there a way to get the coordinates of the town for a grf? I'd like to effectively add another town zone right at the town centre. That should be easily possible with a construction callback checking town zone and distance from town centre, assuming town centre coordinates are accessible.
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: Zephyris' Houses in NML questions
I was about to answer "yes, sure". But seems that houses don't have that information available - opposed to industries which can query their distance from the closest town.Zephyris wrote:Another question:
Is there a way to get the coordinates of the town for a grf? I'd like to effectively add another town zone right at the town centre. That should be easily possible with a construction callback checking town zone and distance from town centre, assuming town centre coordinates are accessible.
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
Re: Zephyris' Houses in NML questions
The house coordinates themselves are accessible right? If the town is accessible too then I could use the difference between the two, but I couldn't work out if town coordinates are accessible as one of the undocumented features...
-
- Tycoon
- Posts: 5948
- Joined: 27 Apr 2005 07:09
- Contact:
Re: Zephyris' Houses in NML questions
Since m4nfo includes a function townlocation() (accessing town var 0x80), I think it should work. At least it did in TTDPatch, never tried it for OTTD.Zephyris wrote: I couldn't work out if town coordinates are accessible as one of the undocumented features...
regards
Michael
Re: Zephyris' Houses in NML questions
A bit offtopic, but related:michael blunck wrote:Since m4nfo includes a function townlocation() (accessing town var 0x80), I think it should work. At least it did in TTDPatch, never tried it for OTTD.Zephyris wrote: I couldn't work out if town coordinates are accessible as one of the undocumented features...
regards
Michael
Is it also possible to extract that information? For example to a .txt?
Projects: http://www.tt-forums.net/viewtopic.php?f=26&t=57266
Screenshots: http://www.tt-forums.net/viewtopic.php?f=47&t=56959
Scenario of The Netherlands: viewtopic.php?f=60&t=87604
Winner of the following screenshot competitions:
sep 2012, jan 2013, apr 2013, aug 2013, mar 2014, mar 2016, oct 2020
All my work is released under GPL-license (either V2 or V3), if not clearly stated otherwise.
Screenshots: http://www.tt-forums.net/viewtopic.php?f=47&t=56959
Scenario of The Netherlands: viewtopic.php?f=60&t=87604
Winner of the following screenshot competitions:
sep 2012, jan 2013, apr 2013, aug 2013, mar 2014, mar 2016, oct 2020
All my work is released under GPL-license (either V2 or V3), if not clearly stated otherwise.
-
- Tycoon
- Posts: 5948
- Joined: 27 Apr 2005 07:09
- Contact:
Re: Zephyris' Houses in NML questions
You´re asking about extracting town coordinates from a game? Probably by using a script.Quast65 wrote: Is it also possible to extract that information? For example to a .txt?
regards
Michael
Re: Zephyris' Houses in NML questions
Town co-ordinates ... Sounds like a GPS question.On a related note, is the coordinates of the town centre accessible via NML or NFO? I thought it was, but can't find it documented...
Opening a town's window and clicking on the Location button centers the map precisely on that location.
Similarly with clicking on a town's name in the Town List menu, which should have those names and co-ordinates all in one convenient [src], no?
I'm not at all a dev or a patch level coder, but I suspect a poke about the appropriate [src] would give up a variable name or an array co-ordinate containing the sought after values.
wallyweb on tt-forums: Screenshots - Wallyweb World - Projects & Releases
wallyweb on Simuscape: Projects - Releases
Other Stuff: TTDPatch 2.6 "Nightly" download - cirdan's OpenTTD branch (New Map Features)
Screenshot Of The Month Contest Winner: August 2015 - Tied May 2016 - January 2018 - December 2018 - May 2019
wallyweb on Simuscape: Projects - Releases
Other Stuff: TTDPatch 2.6 "Nightly" download - cirdan's OpenTTD branch (New Map Features)
Screenshot Of The Month Contest Winner: August 2015 - Tied May 2016 - January 2018 - December 2018 - May 2019
Re: Zephyris' Houses in NML questions
YesYou´re asking about extracting town coordinates from a game?
Probably by using a script.
Well, the first person who figures that out, gets a virtual beer from me (and I tell ya, those will be worth more than Bitcoin!! )but I suspect a poke about the appropriate [src] would give up a variable name or an array co-ordinate containing the sought after values.
Projects: http://www.tt-forums.net/viewtopic.php?f=26&t=57266
Screenshots: http://www.tt-forums.net/viewtopic.php?f=47&t=56959
Scenario of The Netherlands: viewtopic.php?f=60&t=87604
Winner of the following screenshot competitions:
sep 2012, jan 2013, apr 2013, aug 2013, mar 2014, mar 2016, oct 2020
All my work is released under GPL-license (either V2 or V3), if not clearly stated otherwise.
Screenshots: http://www.tt-forums.net/viewtopic.php?f=47&t=56959
Scenario of The Netherlands: viewtopic.php?f=60&t=87604
Winner of the following screenshot competitions:
sep 2012, jan 2013, apr 2013, aug 2013, mar 2014, mar 2016, oct 2020
All my work is released under GPL-license (either V2 or V3), if not clearly stated otherwise.
Re: Zephyris' Houses in NML questions
I'll take a look at accessing those variables, sounds promising.
New question: Is it intentional behaviour to be able to block removal of buildings by setting the local authority rating impact to greater than 1000? I'm not complaining (it would be very useful for landmark-type buildings) but I found it a little surprising.
New question: Is it intentional behaviour to be able to block removal of buildings by setting the local authority rating impact to greater than 1000? I'm not complaining (it would be very useful for landmark-type buildings) but I found it a little surprising.
Re: Zephyris' Houses in NML questions
This goes back to the good old TTDP days. I suspect the rational was that local authorities take a very dim view of megamaniacal industrialists who relish in creating shortcuts to profits.Zephyris wrote:New question: Is it intentional behaviour to be able to block removal of buildings by setting the local authority rating impact to greater than 1000? I'm not complaining (it would be very useful for landmark-type buildings) but I found it a little surprising.
That may be why they hid some extra dynamite in Ctrl+Alt+C where they can also access enormous amounts of money with which to bribe the local authorities.
The alternative is to plant many trees on treeless lots.
wallyweb on tt-forums: Screenshots - Wallyweb World - Projects & Releases
wallyweb on Simuscape: Projects - Releases
Other Stuff: TTDPatch 2.6 "Nightly" download - cirdan's OpenTTD branch (New Map Features)
Screenshot Of The Month Contest Winner: August 2015 - Tied May 2016 - January 2018 - December 2018 - May 2019
wallyweb on Simuscape: Projects - Releases
Other Stuff: TTDPatch 2.6 "Nightly" download - cirdan's OpenTTD branch (New Map Features)
Screenshot Of The Month Contest Winner: August 2015 - Tied May 2016 - January 2018 - December 2018 - May 2019
Re: Zephyris' Houses in NML questions
Thanks wallyweb
New question:
In NML a spritelayout can take parameters for offset in a sprite set, eg:
I would have thought you could use a similar approach to modify recolouring, eg:
However this gives an error in nml\actions\action2var.py, line275, in supported_by_actionD
Does anyone know enough about actionD to know whether you should be able to use it to calculate something like palette offsets?
New question:
In NML a spritelayout can take parameters for offset in a sprite set, eg:
Code: Select all
spritelayout layout_house_offices(variant_offset) {
ground {
sprite: sprites_ground_offices(variant_offset);
}
building {
sprite: sprites_house_offices(variant_offset);
}
}
Code: Select all
spritelayout layout_house_offices(variant_offset) {
ground {
sprite: sprites_ground_offices(1);
}
building {
sprite: sprites_house_offices(1);
recolour_mode: RECOLOUR_REMAP;
palette: variant_offset+795;
}
}
Does anyone know enough about actionD to know whether you should be able to use it to calculate something like palette offsets?
Re: Zephyris' Houses in NML questions
Hi Zephyris!
An error as in a crash?
That would be a bug in the NML compiler.
If so, could you run nml with a '--stack' option to get the full stack dump, and file a bug in the nml project?
https://dev.openttdcoop.org/projects/nml/
A way to reproduce the bug would be splendid!
An error as in a crash?
That would be a bug in the NML compiler.
If so, could you run nml with a '--stack' option to get the full stack dump, and file a bug in the nml project?
https://dev.openttdcoop.org/projects/nml/
A way to reproduce the bug would be splendid!
Being a retired OpenTTD developer does not mean I know what I am doing.
Re: Zephyris' Houses in NML questions
Looks like a crash to me! This are the details... I'll file a bug report when I can grab a bit more time!
A minimal GRF
The NMLC error
The stack dump
A minimal GRF
Code: Select all
//Define the grf
grf {
grfid: "ZDB\02";
name: string(STR_GRF_NAME);
desc: string(STR_GRF_DESC);
version: 0;
min_compatible_version: 0;
}
//Cargoes
cargotable {PASS, GOOD, MAIL}
//Disable all buildings
disable_item(FEAT_HOUSES);
//Debug house
//Sprite layout ***HERIN LIES THE ISSUE***
spritelayout layout_debug_house(palette_offset) {
ground {
sprite: GROUNDSPRITE_NORMAL;
recolour_mode: RECOLOUR_REMAP;
palette: 795+palette_offset;
}
}
//The house itself
item(FEAT_HOUSES, item_house_detached) {
property {
substitute: 24;
population: 12;
mail_multiplier: 3;
accepted_cargos: [[PASS, 2], [MAIL, 1]];
local_authority_impact: 70;
removal_cost_multiplier: 70;
probability: 6;
years_available: [1950, 3000];
availability_mask: [ALL_TOWNZONES, ALL_CLIMATES];
}
graphics {
default: layout_debug_house(1);
}
}
Code: Select all
nmlc ERROR: nmlc: An internal error has occurred:
nmlc-version: 0.4.0.r5397:588fce355f96 from 2014-10-11
Error: (AssertionError) .
Command: ['nmlc', 'ActionDBug.nml']
Location: File "nml\actions\action2var.py", line 275, in supported_by_actionD
Code: Select all
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
File "nmlc", line 6, in <module>
File "nml\main.py", line 342, in run
File "nml\main.py", line 161, in main
File "nml\main.py", line 220, in nml
File "nml\ast\base_statement.py", line 154, in get_action_list
File "nml\ast\spriteblock.py", line 233, in get_action_list
File "nml\actions\action2layout.py", line 438, in get_layout_action2s
File "nml\actions\actionD.py", line 160, in write_action_value
File "nml\actions\actionD.py", line 126, in get_tmp_parameter
File "nml\actions\actionD.py", line 313, in parse_actionD
File "nml\expression\binop.py", line 179, in supported_by_actionD
File "nml\actions\action2var.py", line 275, in supported_by_actionD
AssertionError
Who is online
Users browsing this forum: No registered users and 21 guests