[NML]NewObject tile_checkfor multitile objects

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

Moderator: Graphics Moderators

Post Reply
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

[NML]NewObject tile_checkfor multitile objects

Post by Yoshi »

I have a question regarding the tile_check callback.

The object:
Only a mockup!
Only a mockup!
Bergstation.png (66.82 KiB) Viewed 2589 times
It has all four rotations and is 3*1 tiles long (the tile with grass inside the dirt area is not part of the station)

How can I do the tile_check for this hill side?
According to the Wiki, I should combine the extra_callback_info 1 and 2.

Until now I have only a solution for flat tiles.

Code: Select all

tile_check				:((extra_callback_info1 & bitmask(0,1,2,3,4)) == 0) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: [NML]NewObject tile_checkfor multitile objects

Post by planetmaker »

To me is not clear what you aim for. If you want to allow other slopes combine the possible values by or:

Code: Select all

tile_check: ((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_FLAT  || (extra_callback_info & bitsmask(0,1,2,3,4) ==  SLOPE_NW) ?  CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;  
See http://newgrf-specs.tt-wiki.net/wiki/NM ... ile_slopes for a list of slopes.

or a bit more complicated but more readable by using a switch and the named constants for the slopes:

Code: Select all

switch(FEAT_OBJECT, switch_tile_check, extra_callback_info1 & bitmask(0,1,2,3,4)) {
  SLOPE_FLAT: return CB_RESULT_LOCATION_ALLOW;
  SLOPE_NW: return  CB_RESULT_LOCATION_ALLOW;
  return CB_RESULT_LOCATION_DISALLOW;
}

tile_check: switch_tile_check();
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

Re: [NML]NewObject tile_checkfor multitile objects

Post by Yoshi »

I'd like to check the slopes for all three tiles of the object.

tile 0: SLOPE_FLAT
tile 1: SLOPE_NW
tile 2: SLOPE_NW
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: [NML]NewObject tile_checkfor multitile objects

Post by planetmaker »

Code: Select all

tile_check: (
  ((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_FLAT)  && (extra_callback_info2 & 0xFF == 0)) ||
  ((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_NW)  && (extra_callback_info2 & 0xFF == 0x10)) ||
  ((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_NW)  && (extra_callback_info2 & 0xFF == 0x20))
  ) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;  
extra_callback_info2 encodes the location info as YYYYXXXX inside that byte and I specifically ask for positions (0,0), (0,1) and (0,2) respectively (x increases to lower left, y to lower right on the map)
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

Re: [NML]NewObject tile_checkfor multitile objects

Post by Yoshi »

Thanks

I'll try it out.
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: [NML]NewObject tile_checkfor multitile objects

Post by wallyweb »

Multi tile newobjects are drawn from the North tile ... x,y coordinate (0,0).
Have you tried referencing the North tile?
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

Re: [NML]NewObject tile_checkfor multitile objects

Post by Yoshi »

What exactly does this expression:

Code: Select all

extra_callback_info2 & 0xFF == 0x10
User avatar
Sylf
President
President
Posts: 957
Joined: 23 Nov 2010 21:25
Location: ::1

Re: [NML]NewObject tile_checkfor multitile objects

Post by Sylf »

Yoshi wrote:What exactly does this expression:

Code: Select all

extra_callback_info2 & 0xFF == 0x10
It executes a binary AND operation with extra_callback_info2 and integer 0xFF (11111111 in binary), and see if the result equals to 0x10 (00010000 in binary). The AND operation effectively turns extra_callback_info2 from any size integer to 8-bit integer.
Eddi
Tycoon
Tycoon
Posts: 8258
Joined: 17 Jan 2007 00:14

Re: [NML]NewObject tile_checkfor multitile objects

Post by Eddi »

Yoshi wrote:What exactly does this expression:

Code: Select all

extra_callback_info2 & 0xFF == 0x10
it checks:
  • bits 0-3 and 5-7 are 0
  • bit 4 is 1
  • bits 8-31 are ignored
the "& 0xFF" part is responsible for the last line, the "== 0x10" part for the first two.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: [NML]NewObject tile_checkfor multitile objects

Post by frosch »

In the very recent NML 0.4.1 you can rewrite that line to:

Code: Select all

get_bits(extra_callback_info2, 0, 8) == 0x10
or more verbose:

Code: Select all

get_bits(extra_callback_info2, 0, 8) == 16*1 + 0
Put that into context with
NML specs wrote:extra_callback_info2 contains the location of the tile within the object as 16*y + x.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

Re: [NML]NewObject tile_checkfor multitile objects

Post by Yoshi »

Just a few things i might have understand now (Please correct me if I'm wrong):
  • extra_callback_info2 is 4 bytes / 32 bits long.
  • Bits 8-31 are not important, they are masked out with the "& 0xFF" thing.
  • Bits 0-7 contain the location of the tile.
  • The bits are counted from right to left.
  • YYYYXXXX
  • The Y-axis is from upper left to lower right corner and the X-Axis is from upper right to lower left corner.
  • (0|0) is 00000000 or 0
  • (0|1) is 00010000 or 0x10
  • (0|2) is 00100000 or 0x20
  • (1|0) is 00000001 or 1
  • (1|1) is 00010001 or 0x11
  • the tile_check callback is called for every tile of the newobject.
  • If every tile_check returns true, the object can be built.
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

Re: [NML]NewObject tile_checkfor multitile objects

Post by Yoshi »

Anyway :) it works!
Thanks for your advice:

My code:

Code: Select all

switch (FEAT_OBJECTS, SELF, switch_seilbahn_station_1_top_tile_check_a,extra_callback_info2 & 0xFF) {
	0: ((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_FLAT) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;
	0x10: ((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_NW) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;
	0x20: ((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_NW) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;
	((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_FLAT) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;
}	
switch (FEAT_OBJECTS, SELF, switch_seilbahn_station_1_top_tile_check_b,extra_callback_info2 & 0xFF) {
	0: ((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_FLAT) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;
	0x1: ((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_NE) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;
	0x2: ((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_NE) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;
	((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_FLAT) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;
}	
switch (FEAT_OBJECTS, SELF, switch_seilbahn_station_1_top_tile_check_c,extra_callback_info2 & 0xFF) {
	0: ((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_SE) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;
	0x10: ((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_SE) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;
	0x20: ((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_FLAT) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;
	((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_FLAT) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;
}	
switch (FEAT_OBJECTS, SELF, switch_seilbahn_station_1_top_tile_check_d,extra_callback_info2 & 0xFF) {
	0: ((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_SW) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;
	0x1: ((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_SW) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;
	0x2: ((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_FLAT) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;
	((extra_callback_info1 & bitmask(0,1,2,3,4)) ==  SLOPE_FLAT) ? CB_RESULT_LOCATION_ALLOW : CB_RESULT_LOCATION_DISALLOW;
}	
	
switch (FEAT_OBJECTS, SELF, switch_seilbahn_station_1_top_tile_check,view) {
	0: switch_seilbahn_station_1_top_tile_check_a;
	1: switch_seilbahn_station_1_top_tile_check_b;
	2: switch_seilbahn_station_1_top_tile_check_c;
	3: switch_seilbahn_station_1_top_tile_check_d;
	switch_seilbahn_station_1_top_tile_check_a;
}		

item (FEAT_OBJECTS, item_seilbahn_station_1_top) {
	property {
		[..]
	}
	graphics {
		[..]
		tile_check: switch_seilbahn_station_1_top_tile_check;
    }
	
}
Attachments
Bergstation.png
Bergstation.png (64.87 KiB) Viewed 2291 times
User avatar
SwissFan91
Tycoon
Tycoon
Posts: 2395
Joined: 08 Feb 2009 18:36
Location: Alberta, Canada

Re: [NML]NewObject tile_checkfor multitile objects

Post by SwissFan91 »

Wow those graphics look good :P

On a serious note, thank you to everyone who helped. I can't contribute to coding talk whatsoever but I'm grateful to any/all help.
Total Alpine Replacement Set: Industry, Town, Objects
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 8 guests