## News:

Simutrans Wiki Manual
The official on-line manual for Simutrans. Read and contribute.

Started by jamespetts, August 09, 2012, 10:27:00 AM

0 Members and 1 Guest are viewing this topic.

#### jamespetts

Apologies if this is a very basic question, but I never quite worked out how the "Ribi" system worked. I am trying to find a way of simulating the economies of constructing double-track railways and dual-carriageway roads (i.e., that the difference in cost between a single track railway and a double track railway is far less than the cost of a second single track railway, etc.) without any major changes to the code. I thought that the easiest way of doing it would be for the tool for building ways to check whether there are any ways of the same way type owned by the same player in adjacent tiles, and apply a pre-determined discount to the production cost if so. However, the problem with that is that, with a system this simple, "adjacent tiles" will include the immediately previous tile in a line, which is obviously not what is intended, and will give rise to economic anomalies, and a rather tedious exploit in which players can save large amounts of money by building their railways one tile at a time.

The question is, therefore, how would one go about detecting the case where the only adjacent way tile is the previous tile to which this way tile is connecting? I assume that ribis are involved, but I thought that it might be helpful if somebody were to enlighten me on how they work before I start.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

#### Spartanis

I actually asked a question regarding RIBIs a while back.. way way while back.... but i dunno if i can find it.. let alone remember it.. HHope someone replies your query.. be nice to refresh my memory

#### Ters

Ribis are made up of the numbers 1, 2, 4 and 8. 1 means that a way in connected to the tile north of it, 2 means that it is connected to the tile to the east, 4 to the south and 8 west. The value 5 would be a for a road going through a tile in the north-south direction (1+4), while a value of 15 would be a four-way junction (1+2+4+8) and 3 for a bend from east to north and vice versa (1+2). (Technically, it's a bitwise or operation, not addition. In binary, the numbers are 0001, 0010, 0100 and 1000.)

Ribis can also be masked by signals and signs to ensure vehicles can only pass one way, but I think you should stick to the unmasked value. I haven't checked which one is stored where in the code.

Not that I've done much programming with this.

#### Dwachs

Quote from: jamespetts on August 09, 2012, 10:27:00 AM
The question is, therefore, how would one go about detecting the case where the only adjacent way tile is the previous tile to which this way tile is connecting?
Make a loop to iterate to all possible four direction, then query adjacent tiles with
`bool grund_t::get_neighbour(grund_t *&to, waytype_t type, ribi_t::ribi r ) const;`
Then check if to ==prev_tile.
Parsley, sage, rosemary, and maggikraut.

#### jamespetts

Thank you both very much - most helpful!