2121
2222#include " ../boden/boden.h"
2323#include " ../boden/brueckenboden.h"
24+ #include " ../boden/wege/strasse.h"
2425
2526#include " ../gui/messagebox.h"
2627#include " ../gui/tool_selector.h"
@@ -105,9 +106,9 @@ bool bridge_builder_t::laden_erfolgreich()
105106}
106107
107108
108- stringhashtable_tpl<bridge_desc_t *> * bridge_builder_t::get_all_bridges ()
109- {
110- return &desc_table;
109+ stringhashtable_tpl<bridge_desc_t *> * bridge_builder_t::get_all_bridges ()
110+ {
111+ return &desc_table;
111112}
112113
113114/* *
@@ -196,7 +197,7 @@ const char *check_tile( const grund_t *gr, const player_t *player, waytype_t wt,
196197 return " Bruecke muss an\n singleem\n Hang beginnen!\n " ;
197198 }
198199
199- if ( gr->is_halt () || gr->get_depot () || gr->get_signalbox () )
200+ if ( gr->is_halt () || gr->get_depot () || gr->get_signalbox () )
200201 {
201202 // something in the way
202203 return NOTICE_TILE_FULL;
@@ -298,7 +299,7 @@ bool bridge_builder_t::is_blocked(koord3d pos, ribi_t::ribi check_ribi, player_t
298299 weg_t *w = gr2->get_weg_nr (0 );
299300 const bool public_service = player ? player->is_public_service () : true ;
300301 const sint8 player_nr = player ? player->get_player_nr () : -1 ;
301- if (w
302+ if (w
302303 && (w->get_max_speed () > 0
303304
304305 && ((w->get_desc ()->get_waytype () != road_wt
@@ -324,9 +325,9 @@ bool bridge_builder_t::is_blocked(koord3d pos, ribi_t::ribi check_ribi, player_t
324325 }
325326 }
326327
327- if (grund_t *gr = welt->lookup_kartenboden (pos.get_2d ()))
328+ if (grund_t *gr = welt->lookup_kartenboden (pos.get_2d ()))
328329 {
329- if (const gebaeude_t * gb = gr->get_building ())
330+ if (const gebaeude_t * gb = gr->get_building ())
330331 {
331332 const uint8 max_level = welt->get_settings ().get_max_elevated_way_building_level ();
332333 if ( gb->get_tile ()->get_desc ()->get_level () > max_level && !haltestelle_t::get_halt (gb->get_pos (), NULL ).is_bound ())
@@ -671,7 +672,7 @@ bool bridge_builder_t::can_place_ramp(player_t *player, const grund_t *gr, wayty
671672}
672673
673674
674- const char *bridge_builder_t ::build( player_t *player, const koord3d pos, const bridge_desc_t *desc)
675+ const char *bridge_builder_t ::build( player_t *player, const koord3d pos, const bridge_desc_t *desc, overtaking_mode_t overtaking_mode )
675676{
676677 const grund_t *gr = welt->lookup (pos);
677678 if ( !(gr && desc) ) {
@@ -771,7 +772,7 @@ DBG_MESSAGE("bridge_builder_t::build()", "end not ok");
771772 }
772773
773774 // Start and end have been checked, we can start to build eventually
774- build_bridge (player, gr->get_pos (), end, zv, bridge_height, desc, way_desc );
775+ build_bridge (player, gr->get_pos (), end, zv, bridge_height, desc, way_desc, overtaking_mode );
775776
776777 if (desc->get_waytype () == road_wt)
777778 {
@@ -781,7 +782,7 @@ DBG_MESSAGE("bridge_builder_t::build()", "end not ok");
781782}
782783
783784
784- void bridge_builder_t::build_bridge (player_t *player, const koord3d start, const koord3d end, koord zv, sint8 bridge_height, const bridge_desc_t *desc, const way_desc_t *way_desc)
785+ void bridge_builder_t::build_bridge (player_t *player, const koord3d start, const koord3d end, koord zv, sint8 bridge_height, const bridge_desc_t *desc, const way_desc_t *way_desc, overtaking_mode_t overtaking_mode )
785786{
786787 ribi_t ::ribi ribi = ribi_type (zv);
787788
@@ -794,7 +795,7 @@ void bridge_builder_t::build_bridge(player_t *player, const koord3d start, const
794795 uint8 add_height = 0 ;
795796
796797 // end tile height depends on whether slope matches direction...
797- grund_t * end_gr = welt->lookup (end);
798+ grund_t * end_gr = welt->lookup (end);
798799 if (!end_gr)
799800 {
800801 dbg->error (" void bridge_builder_t::build_bridge()" , " Cannot find the end of a bridge at %u,%u)" , end.x , end.y );
@@ -822,7 +823,7 @@ void bridge_builder_t::build_bridge(player_t *player, const koord3d start, const
822823 if (slope || bridge_height != 0 ) {
823824 // needs a ramp to start on ground
824825 add_height = slope ? slope_t::max_diff (slope) : bridge_height;
825- build_ramp ( player, start, ribi, slope?0 :slope_type (zv)*add_height, desc, way_desc );
826+ build_ramp ( player, start, ribi, slope?0 :slope_type (zv)*add_height, desc, way_desc, overtaking_mode, true );
826827 if ( desc->get_waytype () != powerline_wt ) {
827828 ribi = welt->lookup (start)->get_weg_ribi_unmasked (desc->get_waytype ());
828829 }
@@ -865,7 +866,7 @@ void bridge_builder_t::build_bridge(player_t *player, const koord3d start, const
865866 weg->clear_way_constraints ();
866867 weg->add_way_constraints (desc->get_way_constraints ());
867868 if (old_way)
868- {
869+ {
869870 if (way_object)
870871 {
871872 weg->add_way_constraints (way_object->get_desc ()->get_way_constraints ());
@@ -884,14 +885,21 @@ void bridge_builder_t::build_bridge(player_t *player, const koord3d start, const
884885 if (desc->get_waytype () != powerline_wt) {
885886 weg_t * const weg = weg_t::alloc (desc->get_waytype ());
886887 weg->set_desc (way_desc);
888+ if ( way_desc->get_waytype ()==road_wt) {
889+ strasse_t * str = (strasse_t *) weg;
890+ str->set_overtaking_mode (overtaking_mode);
891+ if ( overtaking_mode<=oneway_mode ) {
892+ str->set_ribi_mask_oneway (ribi_t::reverse_single (ribi_type (zv)));
893+ }
894+ }
887895 weg->set_bridge_weight_limit (desc->get_max_weight ());
888896 bruecke->neuen_weg_bauen (weg, ribi_t::doubles (ribi), player);
889897 const grund_t * gr = welt->lookup (weg->get_pos ());
890898 const slope_t ::type hang = gr ? gr->get_weg_hang () : slope_t ::flat;
891899 const weg_t * old_way = gr ? gr->get_weg (way_desc->get_wtyp ()) : NULL ;
892900 const wayobj_t * way_object = old_way ? way_object = gr->get_wayobj (desc->get_waytype ()) : NULL ;
893901
894- if (hang != slope_t ::flat)
902+ if (hang != slope_t ::flat)
895903 {
896904 const uint slope_height = (hang & 7 ) ? 1 : 2 ;
897905 if (slope_height == 1 )
@@ -959,7 +967,7 @@ void bridge_builder_t::build_bridge(player_t *player, const koord3d start, const
959967
960968 if ( need_auffahrt ) {
961969 // not ending at a bridge
962- build_ramp (player, end, ribi_type (-zv), gr->get_weg_hang ()?0 :slope_type (-zv)*(pos.z -end.z ), desc, way_desc);
970+ build_ramp (player, end, ribi_type (-zv), gr->get_weg_hang ()?0 :slope_type (-zv)*(pos.z -end.z ), desc, way_desc, overtaking_mode, false );
963971 }
964972 else {
965973 // ending on a slope/elevated way
@@ -970,11 +978,16 @@ void bridge_builder_t::build_bridge(player_t *player, const koord3d start, const
970978 // builds new way
971979 weg_t * const weg = weg_t::alloc ( desc->get_waytype () );
972980 weg->set_desc ( way_desc );
981+ if ( weg->get_waytype ()==road_wt ) {
982+ strasse_t * str = (strasse_t *) weg;
983+ assert (str);
984+ str->set_overtaking_mode (overtaking_mode);
985+ }
973986 weg->set_bridge_weight_limit (desc->get_max_weight ());
974987 const weg_t * old_way = gr ? gr->get_weg (way_desc->get_wtyp ()) : NULL ;
975988 const wayobj_t * way_object = old_way ? way_object = gr->get_wayobj (desc->get_waytype ()) : NULL ;
976989 const slope_t ::type hang = gr ? gr->get_weg_hang () : slope_t ::flat;
977- if (hang != slope_t ::flat)
990+ if (hang != slope_t ::flat)
978991 {
979992 const uint slope_height = (hang & 7 ) ? 1 : 2 ;
980993 if (slope_height == 1 )
@@ -1039,7 +1052,12 @@ void bridge_builder_t::build_bridge(player_t *player, const koord3d start, const
10391052 bauigel.set_keep_city_roads (true );
10401053 bauigel.set_maximum (20 );
10411054 bauigel.init_builder ((way_builder_t ::bautyp_t )desc->get_waytype (), way_desc, NULL , NULL );
1042- bauigel.calc_route (pos, to->get_pos ());
1055+ if ( i==0 ) {
1056+ bauigel.calc_route ( to->get_pos (), pos );
1057+ } else {
1058+ bauigel.calc_route ( pos, to->get_pos () );
1059+ }
1060+ bauigel.set_overtaking_mode (overtaking_mode);
10431061 if (bauigel.get_count () == 2 ) {
10441062 bauigel.build ();
10451063 }
@@ -1050,7 +1068,7 @@ void bridge_builder_t::build_bridge(player_t *player, const koord3d start, const
10501068}
10511069
10521070
1053- void bridge_builder_t::build_ramp (player_t * player, koord3d end, ribi_t ::ribi ribi_neu, slope_t ::type weg_hang, const bridge_desc_t * desc, const way_desc_t *way_desc)
1071+ void bridge_builder_t::build_ramp (player_t * player, koord3d end, ribi_t ::ribi ribi_neu, slope_t ::type weg_hang, const bridge_desc_t * desc, const way_desc_t *way_desc, overtaking_mode_t overtaking_mode, bool beginning )
10541072{
10551073 assert (weg_hang >= 0 );
10561074 assert (weg_hang < 81 );
@@ -1075,13 +1093,13 @@ void bridge_builder_t::build_ramp(player_t* player, koord3d end, ribi_t::ribi ri
10751093 if ( !bruecke->weg_erweitern ( desc->get_waytype (), ribi_neu) ) {
10761094 // needs still one
10771095 weg = weg_t::alloc ( desc->get_waytype () );
1078- weg->set_desc (way_desc);
1096+ weg->set_desc (way_desc);
10791097 weg->set_bridge_weight_limit (desc->get_max_weight ());
10801098 player_t::book_construction_costs (player, -bruecke->neuen_weg_bauen ( weg, ribi_neu, player ), end.get_2d (), desc->get_waytype ());
10811099 }
10821100 const grund_t * gr = welt->lookup (weg->get_pos ());
10831101 const slope_t ::type hang = gr ? gr->get_weg_hang () : slope_t ::flat;
1084- if (hang != slope_t ::flat)
1102+ if (hang != slope_t ::flat)
10851103 {
10861104 const uint slope_height = (hang & 7 ) ? 1 : 2 ;
10871105 if (slope_height == 1 )
@@ -1097,6 +1115,18 @@ void bridge_builder_t::build_ramp(player_t* player, koord3d end, ribi_t::ribi ri
10971115 {
10981116 weg->set_max_speed (min (desc->get_topspeed (), way_desc->get_topspeed ()));
10991117 }
1118+ if ( desc->get_waytype ()==road_wt ) {
1119+ strasse_t * str = (strasse_t *) weg;
1120+ assert (str);
1121+ str->set_overtaking_mode (overtaking_mode);
1122+ if ( overtaking_mode<=oneway_mode ) {
1123+ if ( beginning ) {
1124+ str->set_ribi_mask_oneway (ribi_t::reverse_single (ribi_neu));
1125+ } else {
1126+ str->set_ribi_mask_oneway (ribi_neu);
1127+ }
1128+ }
1129+ }
11001130 // Necessary to avoid the "default" way (which might have constraints) setting the constraints here.
11011131 const weg_t * old_way = gr ? gr->get_weg (weg->get_desc ()->get_wtyp ()) : NULL ;
11021132 weg->clear_way_constraints ();
@@ -1110,7 +1140,6 @@ void bridge_builder_t::build_ramp(player_t* player, koord3d end, ribi_t::ribi ri
11101140 }
11111141 }
11121142 } else {
1113-
11141143 leitung_t *lt = bruecke->get_leitung ();
11151144 if (!lt) {
11161145 lt = new leitung_t (bruecke->get_pos (), player);
@@ -1191,11 +1220,11 @@ const char *bridge_builder_t::remove(player_t *player, koord3d pos_start, waytyp
11911220 if (ribi_t::is_single (dir2)) {
11921221 is_end2 = !from->get_neighbour (to, delete_wegtyp, dir2) || !to->ist_bruecke ();
11931222 }
1194-
1223+
11951224 if (!is_end1 && !is_end2) {
11961225 return " Cannot delete a bridge from its centre" ;
11971226 }
1198-
1227+
11991228 // if one is an end then go towards the other direction
12001229 zv = koord (is_end1 ? dir2 : dir1);
12011230 part_list.insert (pos);
0 commit comments