This page is part of a series giving an Overview of Simutrans Code.
CHAPTER 2: WAYS (AND ROADS)
One of the things that we can find on a grund_t are ways (abstract weg_t in /obj/way/weg.h ). In fact, ways are a subclass of a subclass of obj_t (via the abstract class obj_no_info_t in obj/simobj.h, which includes objects that don't have description windows). An example of a way is a tile of asphalt road.
A weg_t may have one or more of these flags ( uint8 flags ) activated:
- 1
weg_t::HAS_SIDEWALK(void set_gehweg(bool),bool hat_gehweg()) - 2
weg_t::IS_ELECTRIFIED(bool is_electrified()) - 4
weg_t::HAS_SIGN(bool has_sign()) - 8
weg_t::HAS_SIGNAL(bool has_signal()) - 16
weg_t::HAS_WAYOBJ(has_wayobj()) - 32
weg_t::HAS_CROSSING(bool is_crossing()) - 64
weg_t::IS_DIAGONAL(bool is_diagonal(), if there is a curve in one direction followed by another curve in the opposite direction, the diagonal image is used if available) - 128
weg_t::IS_SNOW(bool is_snow())
Besides, a
weg_t may belong to one of these system types:
- 0
weg_t::systemtype_t::type_flat - 1
weg_t::systemtype_t::type_elevated - 1
weg_t::systemtype_t::type_runway - 7
weg_t::systemtype_t::type_tram - 64
weg_t::systemtype_t::type_undergroundunused - 255
weg_t::systemtype_t::type_river - 255
weg_t::systemtype_t::type_all(Also used for canals [withwater_wt] and fences. With this system type a way will by only listed in the extension menu by convention. Ways, whose description do not return an icon, will not be listed at all.)
To get the way type, use:
virtual waytype_t get_waytype(). Although the type of the obj_t is always obj_t::way, of course:
typ get_typ() const { return obj_t::way; }
One can imagine that each way tile is like a city with four invisible walls: northern, southern, eastern and western. There may be a wall or a connection to the adjacent way tiles. This is marked by the ribis (Richtungsbits) of bits of allowed directions. weg_t::ribi is a 4-bit long bitfield;, each bit is 1 if that direction is allowed. The order is WSEN. To retrieve this information, use: ribi_t::ribi get_ribi_unmasked().
Even if there is a connection to an adjacent tile, it is possible that a certain direction is forbidden for vehicles. This is marked with the ribi mask (-+ribi_maske+-). It is another 4-bit long bit field. This time, a 1 means that the corresponding direction is forbidden. To retrieve or set this information, use: void set_ribi_maske(ribi) or ribi_t::ribi get_ribi_maske(). To retrieve the combined final effect of ribi and ribi mask, use ribi_t::ribi get_ribi().
Because a weg_t is an obj_t, it has an associated image. However, that image depends on the ribi, the slope, the climate, etc. There is a method to calculate the image used ( void calc_image() , previously calc_bild()). This method is to be called each time we modify the ribi values with: void ribi_add(ribi_t::ribi), void ribi_rem(ribi_t::ribi ribi), void set_ribi(ribi_t::ribi ribi).
The weg_t has a description (Beschreibung), or simply desc (besch) when it is hanging out with friends ( way_desc_t, previously weg_besch_t, in /descriptor/way_desc.h ). Those descriptions come from the paksets. The information includes everything pak-dependent: introduction date, maximum speed, etc. You can retrieve/set the description with these two methods: void set_desc(way_desc_t *) and way_desc_t *get_desc(). The maximum speed is not taken directly from the description only, since it may be altered by other objects in the grund_t. For instance, a 80km/h tramway might have a maximum speed of 50km/h inside a city .
Inside way_desc_t, we only find these properties relevant to the problem in hand: uint8 wtyp (type of way), uint8 styp (system type).
Known subclasses of weg_t are: strasse_t "road" ( /obj/way/strasse.h ), kanal_t ( /obj/way/kanal.h ), and schiene_t "track" ( /obj/way/schiene.h).
Another objects that may appear in a grund_t in connection with ways are way objects ( wayobj_t in /obj/wayobj.h ). These are objects whose images change depending on the configuration (ribis) of the way tile. The most typical of these are catenary and the like.
At this point of our travel, we have to choose among the different subclasses of weg_t. strasse_t (in /obj/way/strasse.h ) is chosen, since we are dealing with roads.
strasse_t is a boring class, though. It only returns its type if asked, allows for the inclusion of sidewalks, or does domestic chores... It has no known subclasses either (a bachelor, one might say).