From 0227dfc468806abfa8dc3dfe267aabf177002f9f Mon Sep 17 00:00:00 2001 From: Markus Pristovsek Date: Fri, 8 Dec 2023 11:43:30 +0000 Subject: [PATCH] FIX: (THLeaderH) crossings upgrade in ways are upgraded git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@11016 8aca7d54-2c30-db11-9de9-000461428c89 --- simutrans/history.txt | 3 ++- src/simutrans/builder/wegbauer.cc | 15 +++++++++++++-- src/simutrans/builder/wegbauer.h | 2 ++ src/simutrans/obj/way/weg.cc | 1 + tests/tests/test_way_road.nut | 17 +++++++++++++++++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/simutrans/history.txt b/simutrans/history.txt index 31a96d6bca8..c5fd803dfd2 100644 --- a/simutrans/history.txt +++ b/simutrans/history.txt @@ -19,7 +19,8 @@ FIX: Makeobj ignored switch images for tracks with no seasons (e.g. image[new2]=...) FIX: massive swallowing of touch event to keep the game responsive despite SDL2's denial of service flooding FIX: airplane convois do no longer crash the game (but are not working perfect yet ...) - FIX: Graphical glitches when road convois change direction in some cases + FIX: graphical glitches when road convois change direction in some cases and on overtaking with drive on left + FIX: (THLeaderH) crossings upgrade when ways are upgraded Release of 123.0.1 (r10421 on 29-Jan-2022): diff --git a/src/simutrans/builder/wegbauer.cc b/src/simutrans/builder/wegbauer.cc index 5da50a1e4b4..f401d277151 100644 --- a/src/simutrans/builder/wegbauer.cc +++ b/src/simutrans/builder/wegbauer.cc @@ -2617,8 +2617,7 @@ void way_builder_t::build_road() weg->set_gehweg(add_sidewalk); player_t::add_maintenance( player_builder, weg->get_desc()->get_maintenance(), weg->get_desc()->get_finance_waytype()); weg->set_owner(player_builder); - // respect speed limit of crossing - weg->count_sign(); + upgrade_crossing_if_needed(gr); } } else { @@ -2712,6 +2711,7 @@ void way_builder_t::build_track() weg->set_owner(player_builder); // respect speed limit of crossing weg->count_sign(); + upgrade_crossing_if_needed(gr); } } else { @@ -3074,3 +3074,14 @@ uint32 way_builder_t::calc_distance( const koord3d &pos, const koord3d &mini, co } return dist; } + + +void way_builder_t::upgrade_crossing_if_needed( const grund_t* gr ) +{ + crossing_t* crossing = gr->find(); + if( !gr->ist_uebergang() || !crossing ) { + // A crossing does not exist on the given tile. + return; + } + crossing->finish_rd(); +} diff --git a/src/simutrans/builder/wegbauer.h b/src/simutrans/builder/wegbauer.h index 15789dc56b9..934cb434547 100644 --- a/src/simutrans/builder/wegbauer.h +++ b/src/simutrans/builder/wegbauer.h @@ -173,6 +173,8 @@ class way_builder_t void build_powerline(); void build_river(); + void upgrade_crossing_if_needed(const grund_t*); + uint32 calc_distance( const koord3d &pos, const koord3d &mini, const koord3d &maxi ); public: diff --git a/src/simutrans/obj/way/weg.cc b/src/simutrans/obj/way/weg.cc index 007be94fad3..dac8160da9c 100644 --- a/src/simutrans/obj/way/weg.cc +++ b/src/simutrans/obj/way/weg.cc @@ -266,6 +266,7 @@ void weg_t::count_sign() flags &= ~(HAS_SIGN|HAS_SIGNAL|HAS_CROSSING); const grund_t *gr=welt->lookup(get_pos()); if(gr) { + max_speed = desc->get_topspeed(); // reset max_speed uint8 i = 1; // if there is a crossing, the start index is at least three ... if( gr->ist_uebergang() ) { diff --git a/tests/tests/test_way_road.nut b/tests/tests/test_way_road.nut index c94a781e0b1..33c821b8424 100644 --- a/tests/tests/test_way_road.nut +++ b/tests/tests/test_way_road.nut @@ -755,6 +755,23 @@ function test_way_road_upgrade_crossing() ASSERT_EQUAL(tile_x(3, 2, 0).get_way(wt_rail).get_max_speed(), min(crossing_rail_speed, rail.get_topspeed())) } + // clean up + ASSERT_EQUAL(remover.work(pl, coord3d(3, 1, 0), coord3d(3, 3, 0), "" + wt_rail), null) + ASSERT_EQUAL(remover.work(pl, coord3d(2, 2, 0), coord3d(4, 2, 0), "" + wt_road), null) + + // upgrade rail with crossing; the crossing is upgraded + { + local fast_rail = way_desc_x("wooden_sleeper_track") + ASSERT_EQUAL(command_x.build_way(pl, coord3d(2, 2, 0), coord3d(4, 2, 0), slow_road, true), null) + // The crossing whose speed limit for rail is 80kph is built here. + ASSERT_EQUAL(command_x.build_way(pl, coord3d(3, 1, 0), coord3d(3, 3, 0), rail, true), null) + // upgrade rail. The crossing should be upgraded to the one whose speed limit for rail is 160kph. + ASSERT_EQUAL(command_x.build_way(pl, coord3d(3, 1, 0), coord3d(3, 3, 0), fast_rail, true), null) + + ASSERT_EQUAL(tile_x(3, 2, 0).get_way(wt_road).get_max_speed(), min(crossing_road_speed, slow_road.get_topspeed())) + ASSERT_EQUAL(tile_x(3, 2, 0).get_way(wt_rail).get_max_speed(), min(crossing_rail_speed, fast_rail.get_topspeed())) + } + // clean up ASSERT_EQUAL(remover.work(pl, coord3d(3, 1, 0), coord3d(3, 3, 0), "" + wt_rail), null) ASSERT_EQUAL(remover.work(pl, coord3d(2, 2, 0), coord3d(4, 2, 0), "" + wt_road), null)