Skip to content

Commit

Permalink
FIX: (THLeaderH) crossings upgrade in ways are upgraded
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@11016 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
prissi committed Dec 8, 2023
1 parent 35e28a8 commit 0227dfc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion simutrans/history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 13 additions & 2 deletions src/simutrans/builder/wegbauer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<crossing_t>();
if( !gr->ist_uebergang() || !crossing ) {
// A crossing does not exist on the given tile.
return;
}
crossing->finish_rd();
}
2 changes: 2 additions & 0 deletions src/simutrans/builder/wegbauer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/simutrans/obj/way/weg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) {
Expand Down
17 changes: 17 additions & 0 deletions tests/tests/test_way_road.nut
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0227dfc

Please sign in to comment.