News:

Simutrans Sites
Know our official sites. Find tools and resources for Simutrans.

r12418 pak64 - new town roads only get the town speed limit after loading

Started by wasname123, Today at 03:08:10 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

wasname123

New town roads run at 70 km/h in the running game, but after a save and load they are at 50 km/h, the town limit in pak64.

set_desc() only applies the town limit if the road already has a sidewalk, and stadt_t::build_road() calls set_desc(city_road) before set_gehweg(true) (in two places), so the limit is never applied. update_city_street() also adds the sidewalk without applying the limit, and on double slopes it then calls set_desc(), which resets the speed and drops a bridge's lower limit. Loading applies both limits (strasse_t::rdwr and bruecke_t::finish_rd), so the speeds change whenever a game is loaded, and in network games on every join.

To reproduce:
  • Start a new pak64 game and let the towns grow for a few months.
  • Check a road a town has just built with the info tool: 70 km/h.
  • Save and load: the same road now shows 50 km/h.

In the attached save (seed 7, r12418) there are 292 town road tiles at 70 km/h, for example (39,1), (42,1) and (34,2). After loading none of them is above 50. In three maps it was 115 to 311 tiles, and in one of them a town road on a bridge went from 50 to 20 km/h.

I know the limit itself is intended (topic 23144). The problem is only that the running game doesn't apply it the way loading does.

Possible patch against r12418 below. With it no road speeds change on loading in the same three maps, except for one case I left alone: on a bridge that is faster than the town limit it goes the other way. Loading applies the town limit in strasse_t::rdwr and then bruecke_t::finish_rd sets the bridge's speed. In one map (seed 23, not the attached one) a town road on a 90 km/h bridge at (87,56) runs at 50 and is at 90 after loading. I didn't change that because I don't know which one would fit.

diff --git a/src/simutrans/world/simcity.cc b/src/simutrans/world/simcity.cc
index 0407e2efd..5d6c2e4b4 100644
--- a/src/simutrans/world/simcity.cc
+++ b/src/simutrans/world/simcity.cc
@@ -38,6 +38,7 @@
 
 #include "../obj/depot.h"
 #include "../obj/gebaeude.h"
+#include "../obj/bruecke.h"
 #include "../obj/way/strasse.h"
 
 #include "../player/simplay.h"
@@ -2964,9 +2965,19 @@ bool update_city_street(koord pos)
  weg->set_owner(NULL); // make public
  }
  weg->set_gehweg(true);
+ // a road with sidewalk has the city road speed limit (as set_desc() and loading a game apply it)
+ if(  weg->get_max_speed() > weg_t::get_cityroad_speedlimit()  ) {
+ weg->set_max_speed(weg_t::get_cityroad_speedlimit());
+ }
  if (slope_t::is_way_double(gr->get_weg_hang(), stadt_t::city_road)) {
  // only set description on double height tiles if we have an image for them
  weg->set_desc(stadt_t::city_road);
+ // set_desc() resets the speed to the road's: a road on a bridge keeps the bridge's limit (as on loading)
+ if(  bruecke_t *br = gr->find<bruecke_t>()  ) {
+ if(  weg->get_max_speed() > br->get_desc()->get_topspeed()  ) {
+ weg->set_max_speed(br->get_desc()->get_topspeed());
+ }
+ }
  }
  gr->calc_image();
  minimap_t::get_instance()->calc_map_pixel(check_pos);
@@ -3947,8 +3958,8 @@ bool stadt_t::build_road(const koord k, player_t* player_, bool forced)
 
  // city roads should not belong to any player => so we can ignore any construction costs ...
  strasse_t* weg = new strasse_t();
+ weg->set_gehweg(true); // before set_desc(), which applies the city road speed limit to roads with sidewalk
  weg->set_desc(city_road);
- weg->set_gehweg(true);
  bd->neuen_weg_bauen(weg, ribi_t::nesw[r], player_);
  bd->calc_image();
  gr->weg_erweitern(road_wt, ribi_t::backward(ribi_t::nesw[r]));
@@ -3981,8 +3992,8 @@ bool stadt_t::build_road(const koord k, player_t* player_, bool forced)
 
  if (!bd->hat_weg(road_wt)  &&  forced) {
  strasse_t* weg = new strasse_t();
+ weg->set_gehweg(true); // before set_desc(), which applies the city road speed limit to roads with sidewalk
  weg->set_desc(city_road);
- weg->set_gehweg(true);
  bd->neuen_weg_bauen(weg, ribi_t::none, player_);
  bd->calc_image();
  return true;