The International Simutrans Forum

Simutrans Extended => Simutrans-Extended development => Simutrans-Extended bug reports => Topic started by: Matthew on January 19, 2020, 10:12:53 AM

Title: [BUG] Signalbox range view does not take account of meters_per_tile
Post by: Matthew on January 19, 2020, 10:12:53 AM
Ves kindly added a feature to display the range of signalboxes (using the $ key in pak128.Britain-Ex).

However, it appears to assume that meters_per_tile = 125. This is true for the Bridgewater-Brunel and Stephenson-Siemens games, but mpt is intended to be adjustable by players.

Steps to reproduce:
1. Copy your simuconf.tab to simutrans/addons/yourdesiredpakset/config/simuconf.tab
2. Change meters_per_tile to 235.
3. Start Sim-Ex with your desired pakset and addons loaded.
4. Start a new game in a year where there are signalboxes (1900+?).
5. Build a railway track and a signalbox.
6. Press $.
7. Try to build a stop signal just inside of the circle of black-and-yellow boxes. You will get an error message saying "Cannot build signal this far beyond any signalbox."
Title: Re: [BUG] Signalbox range view does not take account of meters_per_tile
Post by: Phystam on January 19, 2020, 10:37:07 AM
It seems working correctly. I checked it using pak256, which has meters_per_tile=25, but I cannot reproduce the problem.
Title: Re: [BUG] Signalbox range view does not take account of meters_per_tile
Post by: Matthew on January 19, 2020, 10:48:01 AM
Quote from: Phystam on January 19, 2020, 10:37:07 AM
It seems working correctly. I checked it using pak256, which has meters_per_tile=25, but I cannot reproduce the problem.

Hmm. I have seen it on 156, 235, and 625m. So maybe it's only noticeable if mpt > 125 ??

EDIT:
I believe that I have found the bug and how to fix it, thanks to Phystam's comment. It appears to be simple enough that it would be a good learning exercise in C++ for Simutrans. However, I am wary of the Dunning-Kruger effect (https://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect) (ja (https://ja.wikipedia.org/wiki/%E3%83%80%E3%83%8B%E3%83%B3%E3%82%B0%EF%BC%9D%E3%82%AF%E3%83%AB%E3%83%BC%E3%82%AC%E3%83%BC%E5%8A%B9%E6%9E%9C)), so I will try to post the relevant code here as a gobbet (https://en.wiktionary.org/wiki/gobbet) in the next few days.
Title: Re: [BUG] Signalbox range view does not take account of meters_per_tile
Post by: Ranran(retired) on January 19, 2020, 04:51:40 PM
I also tested it with pak128.britain-EX, but it seems to be working properly ...
Did the range display change after changing meters_per_tile? In my case it seems to be changing properly. That is, when meters_per_tile = 250, the size of the circle is halved.
Title: Re: [BUG] Signalbox range view does not take account of meters_per_tile
Post by: jamespetts on January 19, 2020, 04:52:06 PM
Thank you for the report. I should be grateful for the offered more information and suggestion on how this might be fixed. I should note that I generally recommend against meters per tile settings that do not translate to a integral number of tiles for 1km.
Title: Re: [BUG] Signalbox range view does not take account of meters_per_tile
Post by: Ves on January 21, 2020, 09:52:35 PM
The way I made the circle is in simplan.cc from line 673:

(gb = gebaeude = building, AKA the signalbox)


uint32 const radius = gb->get_tile()->get_desc()->get_radius();
uint16 const cov = radius / welt->get_settings().get_meters_per_tile();
if (shortest_distance(gb->get_pos().get_2d(), gr->get_pos().get_2d()) <= cov)
{
// Code that draws the cross and circle
}


Could it be an overflow from some of the uint's? Actually, I dont remember why those specific was used...