Newgrf Bridges suggestions

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

Moderator: Graphics Moderators

User avatar
eis_os
TTDPatch Developer
TTDPatch Developer
Posts: 3603
Joined: 07 Mar 2003 13:10
Location: Germany
Contact:

Re: Newgrf Bridges suggestions

Post by eis_os »

Looking at "pilar chopping.png", these won't solve all combinations

Considering some sleep combinations, and track foundations under bridges, there are a lot combinations.

If we only consider only TTDs original possible combinations, we have two possible basic states:
- nothing under bridge
- something under bridge

Then we have can cut the tile in two zones.

So you have the left zone pillar, and the right zone pillar.

Each of this pillar zones have 3 basic states: flat, higher or lower in the middle of bridge. (more if you allow steep slopes)
uni657
Engineer
Engineer
Posts: 20
Joined: 30 Sep 2010 23:38

Re: Newgrf Bridges suggestions

Post by uni657 »

eis_os
This is much easier. Tile has 4 corners, 2 for the front side of the bridge, and 2 for the back side, about which we will temporarily forget.
So we have 2 front corners.
1. Draw default sprite from the height of the highest corner (including foundation) up to the bridge.
2. Then we draw half-sprite for the lowest corner only. (Of course, if both corners are at the same level, then we don't draw half-sprite at all.)
Repeat this two steps for the back side and we are done, all 4 pillars have correct height. We don't care about steep slope, because max height difference for the each side of the tile is only one height level.
Last edited by uni657 on 14 Oct 2010 18:12, edited 1 time in total.
User avatar
thgergo
Route Supervisor
Route Supervisor
Posts: 391
Joined: 29 Mar 2005 12:44
Location: Hungary

Re: Newgrf Bridges suggestions

Post by thgergo »

I have checked your modified ottd build. It works very well with the original bridges, but it fails with TBRS as you said, and it fails with the TTRS bridges too. It looks like the for me, the height detecting for halftiles is failing. "HasBit(image, 0)" shouldnt be an issue anymore doesnt it? After looking your patch, still the "hasbit will be the problem":

Code: Select all

switch(type) {
+		case 0: case 1: case 2: case 9: // wooden, girder and concrete bridges
+			draw_odd_pillar = true;
+			break;
+		case 3: case 4: case 5: // suspension bridges, different pillars for each bridge part
+			if (image == SPR_BTSUS_X_PILLAR_TILE_E || image == SPR_BTSUS_Y_PILLAR_TILE_E) {
+				draw_odd_pillar = true;
+			} else {
+				p = tileh_bits[HasBit(image, 0) * 2 + axis];
+			}
+			break;
Is this switch requied? Halftiles method cant solve this? At least this should be disabled if that bridgeslot have been modified by newgrf? I havent explored further the sources, or the available sprites in ttrg.grf, so I might be wrong.
Attachments
TTRS.png
TTRS.png (43.42 KiB) Viewed 5827 times
Image
Image
User avatar
eis_os
TTDPatch Developer
TTDPatch Developer
Posts: 3603
Joined: 07 Mar 2003 13:10
Location: Germany
Contact:

Re: Newgrf Bridges suggestions

Post by eis_os »

uni657 wrote:eis_os
This is much easier. Tile has 4 corners, 2 for the front side of the bridge, and 2 for the back side, about which we will temporarily forget.
So we have 2 front corners.
1. Draw default sprite from the height of the highest corner (including foundation) up to the bridge.
2. Then we draw half-sprite for the lowest corner only. (Of course, if both corners are at the same level, then we don't draw half-sprite at all.)
Repeat this two steps for the back side and we are done, all 4 pillars have correct height. We don't care about steep slope, because max height difference for the each side of the tile is only one height level.

Sorry, I forgot to write that archive in my previous post contains OpenTTD binary with this patch.
As soon as you have heavier pillars, you system won't work, as you get visually distortion if you half pillar doesn't fit the right slope...

(Like a Brick Viaduct grf)
uni657
Engineer
Engineer
Posts: 20
Joined: 30 Sep 2010 23:38

Re: Newgrf Bridges suggestions

Post by uni657 »

thgergo
Removed half of that switch, now TBRS pillars are drawn correctly.
eis_os wrote:As soon as you have heavier pillars, you system won't work, as you get visually distortion if you half pillar doesn't fit the right slope... (Like a Brick Viaduct grf)
Nothing wrong with the pillars of the brick viaduct.
Attachments
brick_viaduct.png
brick_viaduct.png (65.37 KiB) Viewed 5762 times
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: Newgrf Bridges suggestions

Post by michael blunck »

uni657 wrote:Nothing wrong with the pillars of the brick viaduct.
Shouldn´t them be centered on the tile borders?

regards
Michael
Image
User avatar
thgergo
Route Supervisor
Route Supervisor
Posts: 391
Joined: 29 Mar 2005 12:44
Location: Hungary

Re: Newgrf Bridges suggestions

Post by thgergo »

michael blunck wrote:
uni657 wrote:Nothing wrong with the pillars of the brick viaduct.
Shouldn´t them be centered on the tile borders?

regards
Michael
This is just for an optical illusion for the viaduct, it looks higher than the real "z" height could allow that.
Image
Image
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: Newgrf Bridges suggestions

Post by michael blunck »

thgergo wrote: This is just for an optical illusion for the viaduct, it looks higher than the real "z" height could allow that.
Well, no. As the track (and the whole bridge) is centred on its ground tiles, so should the foot of the pillars.

regards
Michael
Image
User avatar
eis_os
TTDPatch Developer
TTDPatch Developer
Posts: 3603
Joined: 07 Mar 2003 13:10
Location: Germany
Contact:

Re: Newgrf Bridges suggestions

Post by eis_os »

uni657 wrote:thgergo
Removed half of that switch, now TBRS pillars are drawn correctly.
eis_os wrote:As soon as you have heavier pillars, you system won't work, as you get visually distortion if you half pillar doesn't fit the right slope... (Like a Brick Viaduct grf)
Nothing wrong with the pillars of the brick viaduct.

The bridge pillars in the valley are totally wrong...
TTDPatch dev in retirement ... Search a grf, try Grf Crawler 0.9 - now with even faster details view and new features...
Image
uni657
Engineer
Engineer
Posts: 20
Joined: 30 Sep 2010 23:38

Re: Newgrf Bridges suggestions

Post by uni657 »

eis_os wrote:The bridge pillars in the valley are totally wrong...
How should they look then? Compared to unmodified OpenTTD this is exact pillar length, that author of the grf wanted.

By the way, how pillars are drawn in TTDPatch? I tried to look, but unfortunately, I don't understand assembler.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Newgrf Bridges suggestions

Post by planetmaker »

The pillars have the correct length. But look at how off-centre from the tile centre they are with respect to the / direction of the tiles. The bridge must be oblique.
User avatar
AndersI
Tycoon
Tycoon
Posts: 1732
Joined: 19 Apr 2004 20:09
Location: Sweden
Contact:

Re: Newgrf Bridges suggestions

Post by AndersI »

As the bridge is 20 pixels wide, and the pillar seems to be flat to the side of the bridge, the pillar should also be 20 px wide, with the current width it should be drawn in the middle of the lower red line:
Attachments
tt10.png
tt10.png (11.6 KiB) Viewed 5664 times
User avatar
eis_os
TTDPatch Developer
TTDPatch Developer
Posts: 3603
Joined: 07 Mar 2003 13:10
Location: Germany
Contact:

Re: Newgrf Bridges suggestions

Post by eis_os »

It's all about optical illusion and trying to fix newgrfs.
Technical there is no correct way to fix drawing bridge pillars for newgrfs without adding new additions to newgrf. And as soon as people change trg*.grf to add new bridges there isn't a correct way for TTD default bridges either...
TTDPatch dev in retirement ... Search a grf, try Grf Crawler 0.9 - now with even faster details view and new features...
Image
User avatar
vasatko
Engineer
Engineer
Posts: 15
Joined: 01 Feb 2018 12:36
Location: Czech Republic, Ostrava

Re: Newgrf Bridges suggestions

Post by vasatko »

Hi,

what about custom spritenumber? Have you solution for custom spritenumbers or you still replacing toyland sprites?

I need other front bridge sprites for road and other for rails. But i dont know how to add custom spritenumbers or which spritenumbers is free.
Image
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: Newgrf Bridges suggestions

Post by wallyweb »

vasatko wrote:Hi,

what about custom spritenumber? Have you solution for custom spritenumbers or you still replacing toyland sprites?

I need other front bridge sprites for road and other for rails. But i dont know how to add custom spritenumbers or which spritenumbers is free.
This can be done via Action D GRF Resource Management. If you have the TBRS NFO code, you can see how it is done.
User avatar
vasatko
Engineer
Engineer
Posts: 15
Joined: 01 Feb 2018 12:36
Location: Czech Republic, Ostrava

Re: Newgrf Bridges suggestions

Post by vasatko »

Hi, thx, but I saw to WiKi and to TBRS code and i dont know what is it. Can you give me quick lection how to GRFRecourceManagement use? Or exist some tutorial, manual etc?

Im looking to your link for GRM and Action6 and to your code.
Image
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: Newgrf Bridges suggestions

Post by wallyweb »

vasatko wrote:Hi, thx, but I saw to WiKi and to TBRS code and i dont know what is it. Can you give me quick lection how to GRFRecourceManagement use? Or exist some tutorial, manual etc?

Im looking to your link for GRM and Action6 and to your code.
I can send you an example of the code that I use, but I am still working on it for a tutorial that I will be posting some time in the next several weeks. I will post a link here when it is ready, probably near the end of March.
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: Newgrf Bridges suggestions

Post by michael blunck »

vasatko wrote: Hi, thx, but I saw to WiKi and to TBRS code and i dont know what is it. Can you give me quick lection how to GRFRecourceManagement use? Or exist some tutorial, manual etc?

Im looking to your link for GRM and Action6 and to your code.
You could use m4nfo instead of plain nfo for coding bridges.
There´s also a tutorial how to use allocated sprites rather than overwriting TTD sprites.

regard
Michael
Image
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: Newgrf Bridges suggestions

Post by michael blunck »

Since 2014, it is possible to code bridges by using m4nfo. Thanks to our Czech collegues, it has brought to my attention that, due to recent changes in m4nfo core routines, this was no longer possible. After fixing that bug, I took the chance to revisit the way how to efficiently code bridges using m4nfo.

Here, I´d like to show code and graphics for a small test set which re-models one of the TBRS bridges by th_gergo.

The test set makes use of both original TTD and custom sprites, for real
sprites and recolour sprites. These may be mixed freely.

In addition, this set makes use of M4´s macro capabilities, to show how to
easily reduce repetitive code for the bridge "tables". In fact, the code restricts itself to a single macro/function to model every bridge table (-> b_seg()), which is then called for every bridge segment with different parameters.

The set also shows how to divide bridge code into single layouts, if needed/wanted.

regards
Michael
test_bridge.png
test_bridge.png (16.93 KiB) Viewed 4503 times

Code: Select all

define(GRF_NBRIDGES, xx xx xx xx) // put valid GRF-ID here
define(SUSPENSION,5)

setfeature(_BRIDGE)
setpath(xxxxxx/sprites) // put valid $PATH here

// exit if toyland
skipif(EXIT,CLIMATE,==,TOYLAND)

//------------------------------------------------------------------
// bridge test with custom sprite and recolour sprite allocation
// re-coding th_gergo´s suspension bridge from the TBR Set
//------------------------------------------------------------------

textmode_on()

grfinit(GRF_NBRIDGES,
	grfname(ALL,"NewBridge v0.2 (test) 14.02.2018")
	grfdescription(ALL,UTF8 CRLF T_LGRAY "NewBridge © 2018 by Michael Blunck. All rights reserved." CRLF
	"Bridge graphics by th_gergo" CRLF
	"Visit www.ttdpatch.de")  	
	grfurl(ALL,"http://www.ttdpatch.de")
	grfpalette(DOS)
	grfversion(0)
	grfminversion(0)
)

textmode_off()

deftxt(_mybridge,
	ALL,"Test bridges",
	D, UTF8 "Brückentest",
	F, "Test de pontages",
	E, "Prueba de puentes",
	I, "Test dei ponti",
	NL, "Test van de bruggen"
)

// rebuilt original suspension steel (golden) bridge (ID 05)
definebridge(SUSPENSION,
	intro(1950)
	minlength(2)
	maxlength(9)
	price(50)
	maxspeed(80 km/h)
	flags(NOFARPILLARS)
	purchasetext(_mybridge)
)

spriteblock(ALLOCATE,
	set(
// [0] b_front
		sprite(test_bridge.png 2 40 01 47 47 -44 -35)
		sprite(test_bridge.png 66 40 01 42 52 -49 -30)
		sprite(test_bridge.png 130 40 01 47 52 -49 -35)
		sprite(test_bridge.png 194 40 01 42 47 -44 -29)
		sprite(test_bridge.png 258 40 01 47 47 1 -34)
		sprite(test_bridge.png 322 40 01 42 52 1 -29)
		sprite(test_bridge.png 386 40 01 47 52 1 -34)
		sprite(test_bridge.png 450 40 01 42 47 0 -29)
// [8] b_rail
		sprite(test_bridge.png 514 40 01 47 50 -23 -24)
		sprite(test_bridge.png 578 40 01 41 50 -23 -18)
		sprite(test_bridge.png 642 40 01 47 50 -23 -24)
		sprite(test_bridge.png 706 40 01 41 50 -24 -17)
		sprite(test_bridge.png 2 104 01 47 50 -23 -23)
		sprite(test_bridge.png 66 104 01 41 50 -23 -17)
		sprite(test_bridge.png 130 104 01 47 50 -23 -23)
		sprite(test_bridge.png 194 104 01 41 50 -23 -17)
// [16] b_road
		sprite(test_bridge.png 258 104 01 47 50 -23 -24)
		sprite(test_bridge.png 322 104 01 41 50 -23 -18)
		sprite(test_bridge.png 386 104 01 47 50 -23 -24)
		sprite(test_bridge.png 450 104 01 41 50 -23 -17)
		sprite(test_bridge.png 514 104 01 47 50 -23 -23)
		sprite(test_bridge.png 578 104 01 41 50 -23 -17)
		sprite(test_bridge.png 642 104 01 47 50 -23 -23)
		sprite(test_bridge.png 706 104 01 41 50 -23 -17)
// [24] b_mono
		sprite(test_bridge.png 2 168 01 47 50 -23 -24)
		sprite(test_bridge.png 66 168 01 41 50 -23 -18)
		sprite(test_bridge.png 130 168 01 47 50 -23 -24)
		sprite(test_bridge.png 194 168 01 41 50 -23 -17)
		sprite(test_bridge.png 258 168 01 47 50 -23 -23)
		sprite(test_bridge.png 322 168 01 41 50 -23 -17)
		sprite(test_bridge.png 386 168 01 47 50 -23 -23)
		sprite(test_bridge.png 450 168 01 41 50 -23 -17)
// [32] b_maglev
		sprite(test_bridge.png 514 168 01 47 50 -23 -24)
		sprite(test_bridge.png 578 168 01 41 50 -23 -18)
		sprite(test_bridge.png 642 168 01 47 50 -23 -24)
		sprite(test_bridge.png 706 168 01 41 50 -23 -17)
		sprite(test_bridge.png 2 232 01 47 50 -23 -23)
		sprite(test_bridge.png 66 232 01 41 50 -23 -17)
		sprite(test_bridge.png 130 232 01 47 50 -23 -23)
		sprite(test_bridge.png 194 232 01 41 50 -23 -17)
// [40] b_pillar
		sprite(test_bridge.png 258 232 01 13 12 -5 -7)
		sprite(test_bridge.png 290 232 01 13 12 -5 -7)
// [42] b_pillar_s (shifted pillars)
 		sprite(test_bridge.png 258 232 01 13 12 -37 9)
		sprite(test_bridge.png 290 232 01 13 12  27 9)
// b_pal (recolour tables)
		// [44] blue grey, rail
		colourtable(DOSMAP,
			47 .. 48, D7 .. D8,
			49 .. 4F, 10 .. 16
		)
		// [45] ocean blue, road
		colourtable(DOSMAP,
			47 .. 48, D7 .. D8,
			49 .. 4F, 9A .. A0
		)
		// [46] golden, mono + maglev
		colourtable(DOSMAP,
			47 .. 4F, 3C .. 44,
		)
	)
)

spriteset(0)

// make entry points for sprites
define(b_base,0)
define(b_front,{eval(b_base+$1)})
define(b_rail,{eval(b_front(8)+$1)})
define(b_road,{eval(b_rail(8)+$1)})
define(b_mono,{eval(b_road(8)+$1)})
define(b_mlev,{eval(b_mono(8)+$1)})
define(b_pillar,{eval(b_mlev(8)+$1)})
define(b_pillar_s,{eval(b_pillar(2)+$1)})
define(b_pal,{eval((b_pillar_s(2)+$1) << 16)})

// general bridge segment
define(b_seg,{
	segment(
		railbridge(front(b_front($1)+b_pal(0), b_front($2)+b_pal(0)), back(b_rail($1)+b_pal(0), b_rail($2)+b_pal(0)), pillar($3, $4))
		roadbridge(front(b_front($1)+b_pal(1), b_front($2)+b_pal(1)), back(b_road($1)+b_pal(1), b_road($2)+b_pal(1)), pillar($3, $4))
		monobridge(front(b_front($1)+b_pal(2), b_front($2)+b_pal(2)), back(b_mono($1)+b_pal(2), b_mono($2)+b_pal(2)), pillar($3, $4))
		mlevbridge(front(b_front($1)+b_pal(2), b_front($2)+b_pal(2)), back(b_mlev($1)+b_pal(2), b_mlev($2)+b_pal(2)), pillar($3, $4))
	)}
)

// filling in the bridge segments:
//
// segment entry
// bridge entry gate
// segment exit
// segment body
// segment connector

define(b_segentr,{b_seg(0,4, NONE, NONE)})			 // this is '/', without pillar
define(b_segent0,{b_seg(0,4, b_pillar_s(0), b_pillar_s(1))}) // this is '/', with front pillar
define(b_segexit,{b_seg(1,5, b_pillar(0), b_pillar(1))})   	 // this is '\', with pillar
define(b_segbody,{b_seg(2,6, NONE, NONE)})			 // this is '=', without pillar
define(b_segconn,{b_seg(3,7, b_pillar(0), b_pillar(1))})	 // this is '^', with pillar

// make all 6 bridge elements
layout(SUSPENSION,0,
	b_segexit()
	b_segent0()
	b_segentr()
	b_segexit()
	b_segbody()
	b_segconn()
)

// bridge ramps - use original TTD sprites but recolor them
define(RAIL, 0x985)
define(ROAD, 0x98D)
define(MONO, 0x10E6)
define(MLEV, 0x110E)

layout(SUSPENSION,6,
	segment(
		railbridge(flat(front(RAIL, RAIL+2), back(RAIL+1, RAIL+3)),
			ramp(front(RAIL+4, RAIL+6), back(RAIL+5, RAIL+7)))
		roadbridge(flat(front(ROAD+b_pal(1), ROAD+2+b_pal(1)), back(ROAD+1+b_pal(1), ROAD+3+b_pal(1))),
			ramp(front(ROAD+4+b_pal(1), ROAD+6+b_pal(1)), back(ROAD+5+b_pal(1),ROAD+7+b_pal(1))))
		monobridge(flat(front(MONO+_BYELLOW, MONO+2+_BYELLOW), back(MONO+1+_BYELLOW, MONO+3+_BYELLOW)),
			ramp(front(MONO+4+_BYELLOW, MONO+6+_BYELLOW), back(MONO+5+_BYELLOW,MONO+7+_BYELLOW)))
		mlevbridge(flat(front(MLEV+_BWHITE, MLEV+2+_BWHITE), back(MLEV+1+_BWHITE, MLEV+3+_BWHITE)),
			ramp(front(MLEV+4+_BWHITE, MLEV+6+_BWHITE), back(MLEV+5+_BWHITE, MLEV+7+_BWHITE)))
	)
)
Image
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 2 guests