Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Fri Jan 19, 2018 1:51 pm

All times are UTC




Post new topic  Reply to topic  [ 24 posts ]  Go to page 1 2 Next
Author Message
PostPosted: Wed Nov 29, 2017 6:10 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed May 16, 2007 4:59 pm
Posts: 2817
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...

_________________
GRVTS/eGRVTS --- Generic Tram Set --- UK Town Set --- zBase ---RichardWheeler.net


Last edited by Zephyris on Wed Jan 10, 2018 5:24 pm, edited 1 time in total.

Top
   
PostPosted: Thu Nov 30, 2017 12:53 am 
Offline
Tycoon
Tycoon

Joined: Wed Jan 17, 2007 12:14 am
Posts: 6952
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.

_________________
You might not exactly be interested in Ferion, but if you are, have fun :)


Top
   
PostPosted: Thu Nov 30, 2017 6:45 am 
Offline
Tycoon
Tycoon

Joined: Wed Apr 27, 2005 7:09 am
Posts: 5124
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

_________________
Image


Top
   
PostPosted: Fri Dec 01, 2017 8:46 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed May 16, 2007 4:59 pm
Posts: 2817
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...

_________________
GRVTS/eGRVTS --- Generic Tram Set --- UK Town Set --- zBase ---RichardWheeler.net


Top
   
PostPosted: Fri Dec 01, 2017 10:07 am 
Offline
Tycoon
Tycoon

Joined: Wed Apr 27, 2005 7:09 am
Posts: 5124
Zephyris wrote:
I'm guessing it also sets the animation speed to high to quickly change house orientation...

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?

regards
Michael

_________________
Image


Top
   
PostPosted: Fri Dec 01, 2017 12:42 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed May 16, 2007 4:59 pm
Posts: 2817
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.

_________________
GRVTS/eGRVTS --- Generic Tram Set --- UK Town Set --- zBase ---RichardWheeler.net


Top
   
PostPosted: Fri Dec 01, 2017 1:10 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed May 16, 2007 4:59 pm
Posts: 2817
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.

_________________
GRVTS/eGRVTS --- Generic Tram Set --- UK Town Set --- zBase ---RichardWheeler.net


Top
   
PostPosted: Tue Dec 05, 2017 9:44 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed May 16, 2007 4:59 pm
Posts: 2817
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.

_________________
GRVTS/eGRVTS --- Generic Tram Set --- UK Town Set --- zBase ---RichardWheeler.net


Top
   
PostPosted: Wed Dec 06, 2017 2:30 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Wed Nov 07, 2007 10:44 pm
Posts: 9025
Location: Sol d
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.


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.

_________________
Image
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


Top
   
PostPosted: Fri Dec 08, 2017 1:24 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed May 16, 2007 4:59 pm
Posts: 2817
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...

_________________
GRVTS/eGRVTS --- Generic Tram Set --- UK Town Set --- zBase ---RichardWheeler.net


Top
   
PostPosted: Fri Dec 08, 2017 7:57 pm 
Offline
Tycoon
Tycoon

Joined: Wed Apr 27, 2005 7:09 am
Posts: 5124
Zephyris wrote:
I couldn't work out if town coordinates are accessible as one of the undocumented features...

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.

regards
Michael

_________________
Image


Top
   
PostPosted: Fri Dec 08, 2017 9:17 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Sun Oct 09, 2011 1:51 pm
Posts: 1450
Location: The Netherlands
michael blunck wrote:
Zephyris wrote:
I couldn't work out if town coordinates are accessible as one of the undocumented features...

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.

regards
Michael


A bit offtopic, but related:
Is it also possible to extract that information? For example to a .txt?

_________________
Projects: viewtopic.php?f=26&t=57266
Screenshots: viewtopic.php?f=47&t=56959

Winner of the following screenshot competitions:
sep 2012, jan 2013, apr 2013, aug 2013, mar 2014, mar 2016
All my work is released under GPL-license (either V2 or V3), if not clearly stated otherwise.


Top
   
PostPosted: Sat Dec 09, 2017 11:26 am 
Offline
Tycoon
Tycoon

Joined: Wed Apr 27, 2005 7:09 am
Posts: 5124
Quast65 wrote:
Is it also possible to extract that information? For example to a .txt?

You´re asking about extracting town coordinates from a game? Probably by using a script.

regards
Michael

_________________
Image


Top
   
PostPosted: Sun Dec 10, 2017 7:16 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat Nov 27, 2004 3:05 pm
Posts: 5042
Location: Canada
Quote:
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...

Town co-ordinates ... Sounds like a GPS question.
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 - 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


Top
   
PostPosted: Sun Dec 10, 2017 1:47 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Sun Oct 09, 2011 1:51 pm
Posts: 1450
Location: The Netherlands
Quote:
You´re asking about extracting town coordinates from a game?

Yes
Quote:
Probably by using a script.

Quote:
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.

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!! :mrgreen: )

_________________
Projects: viewtopic.php?f=26&t=57266
Screenshots: viewtopic.php?f=47&t=56959

Winner of the following screenshot competitions:
sep 2012, jan 2013, apr 2013, aug 2013, mar 2014, mar 2016
All my work is released under GPL-license (either V2 or V3), if not clearly stated otherwise.


Top
   
PostPosted: Mon Dec 18, 2017 2:52 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed May 16, 2007 4:59 pm
Posts: 2817
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.

_________________
GRVTS/eGRVTS --- Generic Tram Set --- UK Town Set --- zBase ---RichardWheeler.net


Top
   
PostPosted: Mon Dec 18, 2017 3:20 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat Nov 27, 2004 3:05 pm
Posts: 5042
Location: Canada
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.
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. :twisted:

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. :wink:

The alternative is to plant many trees on treeless lots. :P

_________________
wallyweb on tt-forums: Screenshots - 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


Top
   
PostPosted: Tue Dec 19, 2017 11:11 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed May 16, 2007 4:59 pm
Posts: 2817
Thanks wallyweb :)

New question:
In NML a spritelayout can take parameters for offset in a sprite set, eg:
Code:
spritelayout layout_house_offices(variant_offset) {
   ground {
      sprite: sprites_ground_offices(variant_offset);
   }
   building {
      sprite: sprites_house_offices(variant_offset);
   }
}


I would have thought you could use a similar approach to modify recolouring, eg:
Code:
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;
   }
}

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?

_________________
GRVTS/eGRVTS --- Generic Tram Set --- UK Town Set --- zBase ---RichardWheeler.net


Top
   
PostPosted: Wed Dec 20, 2017 9:58 am 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Sun Sep 09, 2007 5:03 am
Posts: 4535
Location: home
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!

_________________
Being a OpenTTD developer does not mean I know what I am doing.
Also, other OpenTTD developers may have different opinions.


Top
   
PostPosted: Thu Dec 21, 2017 11:05 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed May 16, 2007 4:59 pm
Posts: 2817
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
Code:
//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);
    }
}


The NMLC error
Code:
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


The stack dump
Code:
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

_________________
GRVTS/eGRVTS --- Generic Tram Set --- UK Town Set --- zBase ---RichardWheeler.net


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 24 posts ]  Go to page 1 2 Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2018 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2018.
Hosted by Zernebok Hosting.