Skip to content

Commit

Permalink
Fixed several test cases (but stuck with starnge error)
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@11609 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
prissi committed Jan 25, 2025
1 parent 7cc3198 commit 8d9c519
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 50 deletions.
1 change: 1 addition & 0 deletions simutrans/history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
CHG: tram system type way can be laid over other tracks as well (like pak192 narrowgauge over normal rails)
CHG: bridge builder is now only a two click tool (total reneval) Can not again connect to complex ramps on elevated ways or cross rivers automatically


Release of 124.3 (r11590 on 10-Jan-2025):
FIX: open schedule get applied during rw (reload, quit, change language), line window crashes
CHG: no way foreground drawn inside stations and depots (and other buildings)
Expand Down
87 changes: 52 additions & 35 deletions src/simutrans/builder/brueckenbauer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ const char* bridge_builder_t::check_start_tile(const player_t* player, const gru
const char *bridge_builder_t::can_span_bridge(const player_t* player, koord3d start_pos, koord3d end_pos, sint8 height, const bridge_desc_t* desc)
{
sint16 length = koord_distance(end_pos,start_pos);
const sint8 clearance = welt->get_settings().get_way_height_clearance();

// test max length
if (desc->get_max_length() > 0 && length-1 > desc->get_max_length()) {
Expand All @@ -435,7 +436,7 @@ const char *bridge_builder_t::can_span_bridge(const player_t* player, koord3d st
// something is the way
return "";
}
for (int i = 1; i <= welt->get_settings().get_way_height_clearance(); i++) {
for (int i = 1; i <= clearance; i++) {
if (pl->get_boden_in_hoehe(height + i)) {
// something is the way
return "";
Expand Down Expand Up @@ -472,7 +473,7 @@ const char *bridge_builder_t::can_span_bridge(const player_t* player, koord3d st
return error_msg;
}

for (int i = 0; i < welt->get_settings().get_way_height_clearance(); i++) {
for (int i = 0; i < clearance; i++) {
if (pl->get_boden_in_hoehe(height + i)) {
// something is the way
return "";
Expand All @@ -494,36 +495,21 @@ const char *bridge_builder_t::can_span_bridge(const player_t* player, koord3d st
return "No bridges over runways!";
}

if (grund_t* gr = pl->get_boden_in_hoehe(height - 1)) {
if (gr->find<leitung_t>()) {
// not enough clearance for powerline
return "";
}
if (slope_t::type sl = gr->get_grund_hang()) {
if (slope_t::max_diff(sl) + gr->get_hoehe() >= height) {
// slope in the way
return "";
for (int h = -clearance - 2; h <= -1; h++) {
// check for slope and way clearance
if (grund_t* grcheck = pl->get_boden_in_hoehe(height + h)) {
sint8 delta_h = slope_t::max_diff(gr->get_grund_hang());
if (grcheck->hat_wege()) {
if (delta_h == 0) {
delta_h += slope_t::max_diff(gr->get_weg_hang());
}
delta_h += clearance-1;
}
}
if (welt->get_settings().get_way_height_clearance() > 1) {
// special checks for paks needing more clearance
if (gr->is_water() || (gr->hat_wege() && gr->get_weg_nr(0)->get_max_speed() > 0) || gr->find<leitung_t>()) {
if (h + delta_h >= 0) {
// not enough clearance
return "";
}

}

// slope two down
if (grund_t* gr = pl->get_boden_in_hoehe(height - 2)) {
if (slope_t::type sl = gr->get_grund_hang()) {
if (slope_t::max_diff(sl) + gr->get_hoehe() >= height) {
// slope in the way
return "";
}
}
}

}
}
return NULL;
Expand Down Expand Up @@ -561,6 +547,7 @@ const char* bridge_builder_t::can_build_bridge(const player_t* pl, koord3d start
// now the tiles are in priciple ok = find out the bridge height
const sint8 max_ramp = 1 + desc->has_double_ramp(); // on flat tile
const sint8 max_slope = 1 + desc->has_double_ramp(); // on sloped tile
const sint8 clearance = welt->get_settings().get_way_height_clearance();

if (max(start_pos.z, end_pos.z)-min(start_pos.z, end_pos.z) > max_ramp) {
// too big height difference
Expand All @@ -580,8 +567,16 @@ const char* bridge_builder_t::can_build_bridge(const player_t* pl, koord3d start
heights.append(start_pos.z);
}
else {
// start on flat tile => may need a ramp
for (sint8 i = 0; i <= max_ramp; i++) {
// start on flat tile => may need a ramp => need clearance
sint8 max_z = max_ramp+clearance;
while(welt->lookup(start_pos + koord3d(0, 0, max_z))) {
if (max_z == clearance) {
break;
}
max_z--;
}
max_z -= clearance; // maximum possible height for a ramp
for (sint8 i = 0; i <= max_z; i++) {
heights.append(start_pos.z+i);
}
}
Expand All @@ -605,9 +600,18 @@ const char* bridge_builder_t::can_build_bridge(const player_t* pl, koord3d start
}
}
else {
// start on flat tile => may need a ramp => need clearance
sint8 max_z = max_ramp + clearance;
while (welt->lookup(start_pos + koord3d(0, 0, max_z))) {
if (max_z == clearance) {
break;
}
max_z--;
}
max_z -= clearance; // maximum possible height for a ramp
// end of flat tile => may need a ramp
for (int i = heights.get_count()-1; i >= 0; i--) {
if (heights[i] > end_pos.z+max_ramp || heights[i] < end_pos.z) {
if (heights[i] > end_pos.z+max_z || heights[i] < end_pos.z) {
// not matching height
heights.remove_at(i);
}
Expand Down Expand Up @@ -645,19 +649,32 @@ koord3d bridge_builder_t::find_end_pos(player_t* player, koord3d pos, const koor
return koord3d::invalid;
}

// first find slope in my direction
for (uint8 i = min_length; i <= max_length && i <= welt->get_settings().way_max_bridge_len; i++) {
const grund_t* gr_end = welt->lookup_kartenboden(pos.get_2d() + zv * i);
if (!gr_end) {
// not on map any more
max_length = i-1; // try shorter bridge then
break;
}
if (gr_end->get_grund_hang()) {
// try to connect
koord3d end = gr_end->get_pos();
const char* error = bridge_builder_t::can_build_bridge(player, pos, end, bridge_height, desc, false);
if (!error) {
return end;
}
max_length = i-1; // try shorter bridge then
break;
}
}


// now try shorter bridge
for (uint8 i = min_length; i <= max_length; i++) {
const grund_t* gr_end = welt->lookup_kartenboden(pos.get_2d() + zv * i); // must succeed, we tested above
koord3d end = gr_end->get_pos();
const char* error = bridge_builder_t::can_build_bridge(player, pos, end, bridge_height, desc, false);
if (error) {
// no valid end point found
continue;
}
return end;
}
return koord3d::invalid;
}
Expand Down
14 changes: 8 additions & 6 deletions src/simutrans/builder/wegbauer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,9 @@ bool way_builder_t::is_allowed_step(const grund_t *from, const grund_t *to, sint
if( to2 && (((bautyp&bautyp_mask)!=leitung && to2->get_weg_nr(0) && to2->get_weg_nr(0)->get_desc()->get_topspeed()>0) || to2->get_leitung()) ) {
return false;
}
// tile above cannot have way unless we are a way (not powerline) with a maximum speed of 0, or be surface if we are underground
// tiles directly above cannot have way unless it is a powerline bridge
to2 = welt->lookup( to->get_pos() + koord3d(0, 0, 1) );
if( to2 && ((to2->get_weg_nr(0) && (desc->get_topspeed()>0 || (bautyp&bautyp_mask)==leitung)) || (bautyp & tunnel_flag) != 0) ) {
if( to2 && (to2->find<leitung_t>() == NULL || to2->get_typ() != grund_t::brueckenboden) ) {
return false;
}
}
Expand Down Expand Up @@ -699,10 +699,10 @@ bool way_builder_t::is_allowed_step(const grund_t *from, const grund_t *to, sint
}

// universal check: do not switch to tunnel through cliffs!
if( from->get_typ()==grund_t::tunnelboden && to->get_typ() != grund_t::tunnelboden && !from->ist_karten_boden() ) {
if( from->get_typ() == grund_t::tunnelboden && to->get_typ() != grund_t::tunnelboden && !from->ist_karten_boden() ) {
return false;
}
if( to->get_typ()==grund_t::tunnelboden && from->get_typ() != grund_t::tunnelboden && !to->ist_karten_boden() ) {
if( to->get_typ() == grund_t::tunnelboden && from->get_typ() != grund_t::tunnelboden && !to->ist_karten_boden() ) {
return false;
}

Expand Down Expand Up @@ -897,8 +897,10 @@ bool way_builder_t::is_allowed_step(const grund_t *from, const grund_t *to, sint
if(to->get_typ()==grund_t::fundament) {
ok &= to->find<field_t>()!=NULL;
}
// no bridges and monorails here in the air
ok &= (welt->access(to_pos)->get_boden_in_hoehe(to->get_pos().z+1)==NULL);
// no bridges and monorails here in the air apart from another powerline bridge
if (grund_t* to2 = welt->lookup(to->get_pos() + koord3d(0,0,1))) {
ok &= to->find<leitung_t>() && to->get_typ() == grund_t::brueckenboden;
}
}

// calculate costs
Expand Down
3 changes: 3 additions & 0 deletions src/simutrans/gui/scenario_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ void scenario_info_t::update_scenario_texts()
{
// we only update the current tab ...
scenario_t *scen = welt->get_scenario();
if (!scen->active()) {
return;
}
scr_size border_size = get_client_windowsize() - info.get_pos() - scr_size(D_MARGIN_RIGHT + D_SCROLLBAR_WIDTH, D_MARGIN_BOTTOM + D_SCROLLBAR_HEIGHT);
int active = tabs.get_active_tab_index();
gui_flowtext_t* ft = dynamic_cast<gui_flowtext_t*>(tabs.get_aktives_tab());
Expand Down
12 changes: 10 additions & 2 deletions src/simutrans/script/api/api_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#include "../api_param.h"
#include "../api_class.h"
#include "../api_function.h"
#include "../../tool/simmenu.h"
#include "../../builder/brueckenbauer.h"
#include "../../ground/grund.h"
#include "../../tool/simtool.h"
#include "../../world/simworld.h"
#include "../../dataobj/environment.h"
Expand Down Expand Up @@ -387,7 +388,14 @@ call_tool_work build_bridge_at(player_t* pl, koord3d start, const bridge_desc_t*
if (const char* err = is_available(bridge)) {
return call_tool_work(err);
}
return call_tool_work(TOOL_BUILD_BRIDGE | GENERAL_TOOL, bridge->get_name(), 0, pl, start);
if (grund_t *gr = world()->lookup(start)) {
sint8 height;
koord3d end = bridge_builder_t::find_end_pos(pl, start, -koord(gr->get_weg_hang()), height, bridge, 1, 10);
if (end != koord3d::invalid) {
return call_tool_work(TOOL_BUILD_BRIDGE | GENERAL_TOOL, bridge->get_name(), 0, pl, start, end);
}
}
return call_tool_work("Bridge is too long for this type!\n"); // to keep compatibility with old error message
}

call_tool_work set_slope(player_t* pl, koord3d start, my_slope_t slope)
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/test_depot.nut
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ function test_depot_build_on_bridge_end()
ASSERT_EQUAL(setslope(pl, coord3d(4, 2, 0), slope.south), null)
ASSERT_EQUAL(setslope(pl, coord3d(4, 4, 0), slope.north), null)

ASSERT_EQUAL(command_x(tool_build_bridge).work(pl, coord3d(4, 2, 0), rail_bridge.get_name()), null)
ASSERT_EQUAL(command_x.build_bridge_at(pl, coord3d(4, 2, 0), rail_bridge), null)
ASSERT_EQUAL(command_x.build_depot(pl, coord3d(4, 2, 0), get_depot_by_wt(wt_rail)), null)
ASSERT_EQUAL(command_x.build_depot(pl, coord3d(4, 4, 0), get_depot_by_wt(wt_rail)), null)
ASSERT_EQUAL(command_x(tool_remover).work(pl, coord3d(4, 2, 0)), null)
Expand All @@ -473,7 +473,7 @@ function test_depot_build_on_bridge_end()
ASSERT_EQUAL(setslope(pl, coord3d(3, 3, 0), slope.east), null)
ASSERT_EQUAL(setslope(pl, coord3d(5, 3, 0), slope.west), null)

ASSERT_EQUAL(command_x(tool_build_bridge).work(pl, coord3d(3, 3, 0), rail_bridge.get_name()), null)
ASSERT_EQUAL(command_x.build_bridge_at(pl, coord3d(3, 3, 0), rail_bridge), null)
ASSERT_EQUAL(command_x.build_depot(pl, coord3d(3, 3, 0), get_depot_by_wt(wt_rail)), null)
ASSERT_EQUAL(command_x.build_depot(pl, coord3d(5, 3, 0), get_depot_by_wt(wt_rail)), null)
ASSERT_EQUAL(command_x(tool_remover).work(pl, coord3d(3, 3, 0)), null)
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/test_halt.nut
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function test_halt_build_rail_single_tile()
{
ASSERT_EQUAL(setslope(pl, coord3d(3, 2, 0), slope.south), null)
ASSERT_EQUAL(setslope(pl, coord3d(3, 4, 0), slope.north), null)
ASSERT_EQUAL(command_x(tool_build_bridge).work(pl, coord3d(3, 2, 0), bridge_desc.get_name()), null)
ASSERT_EQUAL(command_x.build_bridge_at(pl, coord3d(3, 2, 0), bridge_desc), null)

local old_maintenance = pl.get_current_maintenance()

Expand Down Expand Up @@ -250,7 +250,7 @@ function test_halt_build_flat_dock_on_bridge()
{
ASSERT_EQUAL(command_x.set_slope(player_x(0), coord3d(4, 2, 0), slope.south), null)
ASSERT_EQUAL(command_x.set_slope(player_x(0), coord3d(4, 4, 0), slope.north), null)
ASSERT_EQUAL(command_x(tool_build_bridge).work(player_x(0), coord3d(4, 2, 0), "Schiffhebewerk"), null)
ASSERT_EQUAL(command_x(tool_build_bridge).work(player_x(0), coord3d(4, 2, 0), coord3d(4, 4, 0), "Schiffhebewerk"), null)

{
ASSERT_EQUAL(command_x(tool_build_station).work(player_x(0), coord3d(4, 3, 1), "LakeShipStop"), "")
Expand Down Expand Up @@ -691,7 +691,7 @@ function test_halt_build_on_bridge_end()
ASSERT_EQUAL(setslope(pl, coord3d(4, 2, 0), slope.south), null)
ASSERT_EQUAL(setslope(pl, coord3d(4, 4, 0), slope.north), null)

ASSERT_EQUAL(command_x(tool_build_bridge).work(pl, coord3d(4, 2, 0), rail_bridge.get_name()), null)
ASSERT_EQUAL(command_x.build_bridge_at(pl, coord3d(4, 2, 0), rail_bridge), null)
ASSERT_EQUAL(command_x.build_station(pl, coord3d(4, 2, 0), station_desc), null)
ASSERT_EQUAL(command_x.build_station(pl, coord3d(4, 4, 0), station_desc), null)

Expand All @@ -709,7 +709,7 @@ function test_halt_build_on_bridge_end()
ASSERT_EQUAL(setslope(pl, coord3d(3, 3, 0), slope.east), null)
ASSERT_EQUAL(setslope(pl, coord3d(5, 3, 0), slope.west), null)

ASSERT_EQUAL(command_x(tool_build_bridge).work(pl, coord3d(3, 3, 0), rail_bridge.get_name()), null)
ASSERT_EQUAL(command_x.build_bridge_at(pl, coord3d(3, 3, 0), rail_bridge), null)
ASSERT_EQUAL(command_x.build_depot(pl, coord3d(3, 3, 0), get_depot_by_wt(wt_rail)), null)
ASSERT_EQUAL(command_x.build_depot(pl, coord3d(5, 3, 0), get_depot_by_wt(wt_rail)), null)
ASSERT_EQUAL(command_x(tool_remover).work(pl, coord3d(3, 3, 0)), null)
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test_slope.nut
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function test_slope_restore_on_bridge()

ASSERT_EQUAL(command_x.set_slope(pl, coord3d(4, 2, 0), slope.south), null)
ASSERT_EQUAL(command_x.set_slope(pl, coord3d(4, 4, 0), slope.north), null)
ASSERT_EQUAL(command_x(tool_build_bridge).work(pl, coord3d(4, 2, 0), rail_bridge.get_name()), null)
ASSERT_EQUAL(command_x.build_bridge_at(pl, coord3d(4, 2, 0), rail_bridge), null)

{
ASSERT_EQUAL(command_x(tool_restoreslope).work(pl, coord3d(4, 2, 0)), "No suitable ground!")
Expand Down

0 comments on commit 8d9c519

Please sign in to comment.