News:

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

Distance Finder for Simutrans Suggestion

Started by rdepass, May 10, 2016, 05:31:34 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

rdepass

  Please forgive my very bad C. The following came from an idea I had whilst playing your game. For some reason I can't remember I wanted to know how many Simu-km it was from one town hall to another. Following is a badly written code for applying the pythagorean theorem: a² + b² = c² which would allow me to click on a townhall for example, click another town hall and know that it is x simu-km away. The measurement of moving objects is far too difficult for me to comprehend, and this code is definitely not for that function.
If anyone would like to use this to make the Distance Finder tool, please do so if you think it would be useful and if it is not too much hard work. If you make it into an app for satnav devices and make loads of money, I want half! lol

Distance Finder for Simutrans


*The following code is for adaptation into a version that actually works in the Simutrans environment. My coding skills leave a lot to be desired!


*call libs
void main
include # lib1, lib2, etc. ...;


*define variables
* I don't know if these are all necessary


Mapsize = &Mapsize
Xco = &mouseinput1xcoords
Yco = &mouseinput1ycoords
Xco1 =&mouseinput2ycoords
Yco1 = &mouseinput2ycoords
StartPoint = &StartPoint (&mouseinput1xcoords, &mouseinput1ycoords);
EndPoint = &EndPoint (&mouseinput2ycoords, &mouseinput2ycoords);
Distance = &Distance


printf "Click where are you measuring from?" ;
scanf  &StartPoint
printf "Click where you want to know the distance to?";
scanf  &EndPoint
*I don't know how to say scanf for mouses


For


Distance = StartPoint = (Xco * Xco = Xco²);
         EndPoint = (Yco * Yco = Yco²);
(Xco² + Yco²) = &Distance
* I don't know how to say square root, I imagine it is a function in a maths lib somewhere



printf "Distance is: &Distance Simu-Kilometres


void main
You can check me out on Facebook https://www.facebook.com/Technochi
Looking out to the distant horizon, there is always a brighter day to come...

DrSuperGood

That hard part is making the in game tool and not the underlying calculations. Being software engineers such calculations are trivial to make.

The big question is if distance should be Euclidian or Manhattan? Payment and travel cost between locations follows Manhattan distance, which is basically the sum of X and Y delta. I am unsure if movement is Euclidian or not however.

Ters

Quote from: DrSuperGood on May 10, 2016, 04:41:39 PM
I am unsure if movement is Euclidian or not however.

Since the length of diagonals is up to the pak set and advanced players, it is at most optionally Euclidian.

rdepass

"The hard part is making the in game tool and not the underlying calculations"
I totally agree! I was reading in another post that the code is very convoluted, mixed up and not at all streamlined in terms of most modern programming. If it were, however, where would I go for my 'sheeps'? This game is great!

"The big question is if distance should be Euclidian or Manhattan?"
Euclidian for Distance, Manhattan for Journey Length
You can check me out on Facebook https://www.facebook.com/Technochi
Looking out to the distant horizon, there is always a brighter day to come...

prissi

Such a tool would be very easy to write, since there is the two click tool already there.

But more useful might be such a tool for actual distance for convoys ...

isidoro

Maybe it isn't necessary to program a separate tool.  Now, when using some two click tools, the coordinates of origin (and perhaps destination when hovering the mouse) are printed.  Adding the distance information there could suffice.

Ters

Quote from: prissi on August 04, 2016, 09:09:12 PM
Such a tool would be very easy to write, since there is the two click tool already there.

But more useful might be such a tool for actual distance for convoys ...

Isn't that also mostly done already in two-click tools like add/remove electrification and remove track?

Quote from: isidoro on August 04, 2016, 11:37:47 PM
Maybe it isn't necessary to program a separate tool.  Now, when using some two click tools, the coordinates of origin (and perhaps destination when hovering the mouse) are printed.  Adding the distance information there could suffice.

Players may not be too happy about accidentally doings stuff if they fail to cancel the tool.

Ves

I would find it usefull to find the distance my vehicle would have to travel as well as the actual distance between two points. This way, you can see how efficient your infrastructure is constructed in terms of detours.

Isaac Eiland-Hall

Quote from: Ves on August 05, 2016, 09:19:57 PM
I would find it usefull to find the distance my vehicle would have to travel as well as the actual distance between two points. This way, you can see how efficient your infrastructure is constructed in terms of detours.

That sounds extremely handy. Also to see how Simutrans would route it in case of surprises. :)

DrSuperGood

It would also be useful if all distance moved by a convoy cost money. You get free distance moved when convoys turns around or are displaced, especially visible with long trains at terminal stations. This makes through stops less efficient for multi-tile convoys as the convoy has to travel what is potentially free distance at a cost.

Blacksmoker

As far as I can tell from the source code that I found for routing, some kind of track keeping of the total length of the route is already done internally. Sadly, I'm not really that good with C++, but it seems like it should be not too complicated to make a tool which can be told what kind of waytype I want to use and to set a start and endpoint so it searches for a route in the same manner as it would for a vehicle.
Of course it may also be that I am completely mistaken there, I haven't spend that much time looking at this code, but I really would like to have such a tool as well.

Another good reason for this tool would also be to optimize the transport capacity on a certain line, since one can match the number of vehicles on a line depending on their speed, loading capacity and the distance they actually travel to get from some factory to their destination. For that purpose a result in tiles would be best, as the productivity is given in units/month and the speed can easily be calculated for tiles/month.